1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2015 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"
67 #include "fold-const.h"
68 #include "stringpool.h"
69 #include "stor-layout.h"
71 #include "hard-reg-set.h"
78 #include "insn-config.h"
89 #include "dwarf2out.h"
90 #include "dwarf2asm.h"
94 #include "diagnostic.h"
95 #include "tree-pretty-print.h"
98 #include "common/common-target.h"
99 #include "langhooks.h"
101 #include "plugin-api.h"
106 #include "dumpfile.h"
108 #include "tree-dfa.h"
109 #include "gdb/gdb-index.h"
110 #include "rtl-iter.h"
112 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
113 static rtx_insn
*last_var_location_insn
;
114 static rtx_insn
*cached_next_real_insn
;
115 static void dwarf2out_decl (tree
);
117 #ifdef VMS_DEBUGGING_INFO
118 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
120 /* Define this macro to be a nonzero value if the directory specifications
121 which are output in the debug info should end with a separator. */
122 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
123 /* Define this macro to evaluate to a nonzero value if GCC should refrain
124 from generating indirect strings in DWARF2 debug information, for instance
125 if your target is stuck with an old version of GDB that is unable to
126 process them properly or uses VMS Debug. */
127 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
129 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
130 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
133 /* ??? Poison these here until it can be done generically. They've been
134 totally replaced in this file; make sure it stays that way. */
135 #undef DWARF2_UNWIND_INFO
136 #undef DWARF2_FRAME_INFO
137 #if (GCC_VERSION >= 3000)
138 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
141 /* The size of the target's pointer type. */
143 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
146 /* Array of RTXes referenced by the debugging information, which therefore
147 must be kept around forever. */
148 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
150 /* A pointer to the base of a list of incomplete types which might be
151 completed at some later time. incomplete_types_list needs to be a
152 vec<tree, va_gc> *because we want to tell the garbage collector about
154 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
156 /* A pointer to the base of a table of references to declaration
157 scopes. This table is a display which tracks the nesting
158 of declaration scopes at the current scope and containing
159 scopes. This table is used to find the proper place to
160 define type declaration DIE's. */
161 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
163 /* Pointers to various DWARF2 sections. */
164 static GTY(()) section
*debug_info_section
;
165 static GTY(()) section
*debug_skeleton_info_section
;
166 static GTY(()) section
*debug_abbrev_section
;
167 static GTY(()) section
*debug_skeleton_abbrev_section
;
168 static GTY(()) section
*debug_aranges_section
;
169 static GTY(()) section
*debug_addr_section
;
170 static GTY(()) section
*debug_macinfo_section
;
171 static GTY(()) section
*debug_line_section
;
172 static GTY(()) section
*debug_skeleton_line_section
;
173 static GTY(()) section
*debug_loc_section
;
174 static GTY(()) section
*debug_pubnames_section
;
175 static GTY(()) section
*debug_pubtypes_section
;
176 static GTY(()) section
*debug_str_section
;
177 static GTY(()) section
*debug_str_dwo_section
;
178 static GTY(()) section
*debug_str_offsets_section
;
179 static GTY(()) section
*debug_ranges_section
;
180 static GTY(()) section
*debug_frame_section
;
182 /* Maximum size (in bytes) of an artificially generated label. */
183 #define MAX_ARTIFICIAL_LABEL_BYTES 30
185 /* According to the (draft) DWARF 3 specification, the initial length
186 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
187 bytes are 0xffffffff, followed by the length stored in the next 8
190 However, the SGI/MIPS ABI uses an initial length which is equal to
191 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
193 #ifndef DWARF_INITIAL_LENGTH_SIZE
194 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
197 /* Round SIZE up to the nearest BOUNDARY. */
198 #define DWARF_ROUND(SIZE,BOUNDARY) \
199 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 /* CIE identifier. */
202 #if HOST_BITS_PER_WIDE_INT >= 64
203 #define DWARF_CIE_ID \
204 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
206 #define DWARF_CIE_ID DW_CIE_ID
210 /* A vector for a table that contains frame description
211 information for each routine. */
212 #define NOT_INDEXED (-1U)
213 #define NO_INDEX_ASSIGNED (-2U)
215 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
217 struct GTY((for_user
)) indirect_string_node
{
219 unsigned int refcount
;
220 enum dwarf_form form
;
225 struct indirect_string_hasher
: ggc_hasher
<indirect_string_node
*>
227 typedef const char *compare_type
;
229 static hashval_t
hash (indirect_string_node
*);
230 static bool equal (indirect_string_node
*, const char *);
233 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
235 /* With split_debug_info, both the comp_dir and dwo_name go in the
236 main object file, rather than the dwo, similar to the force_direct
237 parameter elsewhere but with additional complications:
239 1) The string is needed in both the main object file and the dwo.
240 That is, the comp_dir and dwo_name will appear in both places.
242 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
243 DW_FORM_GNU_str_index.
245 3) GCC chooses the form to use late, depending on the size and
248 Rather than forcing the all debug string handling functions and
249 callers to deal with these complications, simply use a separate,
250 special-cased string table for any attribute that should go in the
251 main object file. This limits the complexity to just the places
254 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
256 static GTY(()) int dw2_string_counter
;
258 /* True if the compilation unit places functions in more than one section. */
259 static GTY(()) bool have_multiple_function_sections
= false;
261 /* Whether the default text and cold text sections have been used at all. */
263 static GTY(()) bool text_section_used
= false;
264 static GTY(()) bool cold_text_section_used
= false;
266 /* The default cold text section. */
267 static GTY(()) section
*cold_text_section
;
269 /* The DIE for C++14 'auto' in a function return type. */
270 static GTY(()) dw_die_ref auto_die
;
272 /* The DIE for C++14 'decltype(auto)' in a function return type. */
273 static GTY(()) dw_die_ref decltype_auto_die
;
275 /* Forward declarations for functions defined in this file. */
277 static char *stripattributes (const char *);
278 static void output_call_frame_info (int);
279 static void dwarf2out_note_section_used (void);
281 /* Personality decl of current unit. Used only when assembler does not support
283 static GTY(()) rtx current_unit_personality
;
285 /* Data and reference forms for relocatable data. */
286 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
287 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
289 #ifndef DEBUG_FRAME_SECTION
290 #define DEBUG_FRAME_SECTION ".debug_frame"
293 #ifndef FUNC_BEGIN_LABEL
294 #define FUNC_BEGIN_LABEL "LFB"
297 #ifndef FUNC_END_LABEL
298 #define FUNC_END_LABEL "LFE"
301 #ifndef PROLOGUE_END_LABEL
302 #define PROLOGUE_END_LABEL "LPE"
305 #ifndef EPILOGUE_BEGIN_LABEL
306 #define EPILOGUE_BEGIN_LABEL "LEB"
309 #ifndef FRAME_BEGIN_LABEL
310 #define FRAME_BEGIN_LABEL "Lframe"
312 #define CIE_AFTER_SIZE_LABEL "LSCIE"
313 #define CIE_END_LABEL "LECIE"
314 #define FDE_LABEL "LSFDE"
315 #define FDE_AFTER_SIZE_LABEL "LASFDE"
316 #define FDE_END_LABEL "LEFDE"
317 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
318 #define LINE_NUMBER_END_LABEL "LELT"
319 #define LN_PROLOG_AS_LABEL "LASLTP"
320 #define LN_PROLOG_END_LABEL "LELTP"
321 #define DIE_LABEL_PREFIX "DW"
323 /* Match the base name of a file to the base name of a compilation unit. */
326 matches_main_base (const char *path
)
328 /* Cache the last query. */
329 static const char *last_path
= NULL
;
330 static int last_match
= 0;
331 if (path
!= last_path
)
334 int length
= base_of_path (path
, &base
);
336 last_match
= (length
== main_input_baselength
337 && memcmp (base
, main_input_basename
, length
) == 0);
342 #ifdef DEBUG_DEBUG_STRUCT
345 dump_struct_debug (tree type
, enum debug_info_usage usage
,
346 enum debug_struct_file criterion
, int generic
,
347 int matches
, int result
)
349 /* Find the type name. */
350 tree type_decl
= TYPE_STUB_DECL (type
);
352 const char *name
= 0;
353 if (TREE_CODE (t
) == TYPE_DECL
)
356 name
= IDENTIFIER_POINTER (t
);
358 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
360 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
361 matches
? "bas" : "hdr",
362 generic
? "gen" : "ord",
363 usage
== DINFO_USAGE_DFN
? ";" :
364 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
366 (void*) type_decl
, name
);
369 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
370 dump_struct_debug (type, usage, criterion, generic, matches, result)
374 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
379 /* Get the number of HOST_WIDE_INTs needed to represent the precision
383 get_full_len (const wide_int
&op
)
385 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
386 / HOST_BITS_PER_WIDE_INT
);
390 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
392 enum debug_struct_file criterion
;
394 bool generic
= lang_hooks
.types
.generic_p (type
);
397 criterion
= debug_struct_generic
[usage
];
399 criterion
= debug_struct_ordinary
[usage
];
401 if (criterion
== DINFO_STRUCT_FILE_NONE
)
402 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
403 if (criterion
== DINFO_STRUCT_FILE_ANY
)
404 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
406 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
408 if (type_decl
!= NULL
)
410 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
411 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
413 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
414 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
417 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
420 /* Return a pointer to a copy of the section string name S with all
421 attributes stripped off, and an asterisk prepended (for assemble_name). */
424 stripattributes (const char *s
)
426 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
431 while (*s
&& *s
!= ',')
438 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
439 switch to the data section instead, and write out a synthetic start label
440 for collect2 the first time around. */
443 switch_to_eh_frame_section (bool back
)
447 #ifdef EH_FRAME_SECTION_NAME
448 if (eh_frame_section
== 0)
452 if (EH_TABLES_CAN_BE_READ_ONLY
)
458 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
460 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
462 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
465 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
466 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
467 && (per_encoding
& 0x70) != DW_EH_PE_absptr
468 && (per_encoding
& 0x70) != DW_EH_PE_aligned
469 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
470 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
471 ? 0 : SECTION_WRITE
);
474 flags
= SECTION_WRITE
;
475 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
477 #endif /* EH_FRAME_SECTION_NAME */
479 if (eh_frame_section
)
480 switch_to_section (eh_frame_section
);
483 /* We have no special eh_frame section. Put the information in
484 the data section and emit special labels to guide collect2. */
485 switch_to_section (data_section
);
489 label
= get_file_function_name ("F");
490 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
491 targetm
.asm_out
.globalize_label (asm_out_file
,
492 IDENTIFIER_POINTER (label
));
493 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
498 /* Switch [BACK] to the eh or debug frame table section, depending on
502 switch_to_frame_table_section (int for_eh
, bool back
)
505 switch_to_eh_frame_section (back
);
508 if (!debug_frame_section
)
509 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
510 SECTION_DEBUG
, NULL
);
511 switch_to_section (debug_frame_section
);
515 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
517 enum dw_cfi_oprnd_type
518 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
523 case DW_CFA_GNU_window_save
:
524 case DW_CFA_remember_state
:
525 case DW_CFA_restore_state
:
526 return dw_cfi_oprnd_unused
;
529 case DW_CFA_advance_loc1
:
530 case DW_CFA_advance_loc2
:
531 case DW_CFA_advance_loc4
:
532 case DW_CFA_MIPS_advance_loc8
:
533 return dw_cfi_oprnd_addr
;
536 case DW_CFA_offset_extended
:
538 case DW_CFA_offset_extended_sf
:
539 case DW_CFA_def_cfa_sf
:
541 case DW_CFA_restore_extended
:
542 case DW_CFA_undefined
:
543 case DW_CFA_same_value
:
544 case DW_CFA_def_cfa_register
:
545 case DW_CFA_register
:
546 case DW_CFA_expression
:
547 return dw_cfi_oprnd_reg_num
;
549 case DW_CFA_def_cfa_offset
:
550 case DW_CFA_GNU_args_size
:
551 case DW_CFA_def_cfa_offset_sf
:
552 return dw_cfi_oprnd_offset
;
554 case DW_CFA_def_cfa_expression
:
555 return dw_cfi_oprnd_loc
;
562 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
564 enum dw_cfi_oprnd_type
565 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
570 case DW_CFA_def_cfa_sf
:
572 case DW_CFA_offset_extended_sf
:
573 case DW_CFA_offset_extended
:
574 return dw_cfi_oprnd_offset
;
576 case DW_CFA_register
:
577 return dw_cfi_oprnd_reg_num
;
579 case DW_CFA_expression
:
580 return dw_cfi_oprnd_loc
;
583 return dw_cfi_oprnd_unused
;
587 /* Output one FDE. */
590 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
591 char *section_start_label
, int fde_encoding
, char *augmentation
,
592 bool any_lsda_needed
, int lsda_encoding
)
594 const char *begin
, *end
;
595 static unsigned int j
;
598 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
600 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
602 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
603 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
604 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
605 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
606 " indicating 64-bit DWARF extension");
607 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
609 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
612 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
614 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
615 debug_frame_section
, "FDE CIE offset");
617 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
618 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
622 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
623 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
624 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
625 "FDE initial location");
626 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
627 end
, begin
, "FDE address range");
631 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
632 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
639 int size
= size_of_encoded_value (lsda_encoding
);
641 if (lsda_encoding
== DW_EH_PE_aligned
)
643 int offset
= ( 4 /* Length */
645 + 2 * size_of_encoded_value (fde_encoding
)
646 + 1 /* Augmentation size */ );
647 int pad
= -offset
& (PTR_SIZE
- 1);
650 gcc_assert (size_of_uleb128 (size
) == 1);
653 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
655 if (fde
->uses_eh_lsda
)
657 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
658 fde
->funcdef_number
);
659 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
660 gen_rtx_SYMBOL_REF (Pmode
, l1
),
662 "Language Specific Data Area");
666 if (lsda_encoding
== DW_EH_PE_aligned
)
667 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
668 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
669 "Language Specific Data Area (none)");
673 dw2_asm_output_data_uleb128 (0, "Augmentation size");
676 /* Loop through the Call Frame Instructions associated with this FDE. */
677 fde
->dw_fde_current_label
= begin
;
679 size_t from
, until
, i
;
682 until
= vec_safe_length (fde
->dw_fde_cfi
);
684 if (fde
->dw_fde_second_begin
== NULL
)
687 until
= fde
->dw_fde_switch_cfi_index
;
689 from
= fde
->dw_fde_switch_cfi_index
;
691 for (i
= from
; i
< until
; i
++)
692 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
695 /* If we are to emit a ref/link from function bodies to their frame tables,
696 do it now. This is typically performed to make sure that tables
697 associated with functions are dragged with them and not discarded in
698 garbage collecting links. We need to do this on a per function basis to
699 cope with -ffunction-sections. */
701 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
702 /* Switch to the function section, emit the ref to the tables, and
703 switch *back* into the table section. */
704 switch_to_section (function_section (fde
->decl
));
705 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
706 switch_to_frame_table_section (for_eh
, true);
709 /* Pad the FDE out to an address sized boundary. */
710 ASM_OUTPUT_ALIGN (asm_out_file
,
711 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
712 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
717 /* Return true if frame description entry FDE is needed for EH. */
720 fde_needed_for_eh_p (dw_fde_ref fde
)
722 if (flag_asynchronous_unwind_tables
)
725 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
728 if (fde
->uses_eh_lsda
)
731 /* If exceptions are enabled, we have collected nothrow info. */
732 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
738 /* Output the call frame information used to record information
739 that relates to calculating the frame pointer, and records the
740 location of saved registers. */
743 output_call_frame_info (int for_eh
)
748 char l1
[20], l2
[20], section_start_label
[20];
749 bool any_lsda_needed
= false;
750 char augmentation
[6];
751 int augmentation_size
;
752 int fde_encoding
= DW_EH_PE_absptr
;
753 int per_encoding
= DW_EH_PE_absptr
;
754 int lsda_encoding
= DW_EH_PE_absptr
;
756 rtx personality
= NULL
;
759 /* Don't emit a CIE if there won't be any FDEs. */
763 /* Nothing to do if the assembler's doing it all. */
764 if (dwarf2out_do_cfi_asm ())
767 /* If we don't have any functions we'll want to unwind out of, don't emit
768 any EH unwind information. If we make FDEs linkonce, we may have to
769 emit an empty label for an FDE that wouldn't otherwise be emitted. We
770 want to avoid having an FDE kept around when the function it refers to
771 is discarded. Example where this matters: a primary function template
772 in C++ requires EH information, an explicit specialization doesn't. */
775 bool any_eh_needed
= false;
777 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
779 if (fde
->uses_eh_lsda
)
780 any_eh_needed
= any_lsda_needed
= true;
781 else if (fde_needed_for_eh_p (fde
))
782 any_eh_needed
= true;
783 else if (TARGET_USES_WEAK_UNWIND_INFO
)
784 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
791 /* We're going to be generating comments, so turn on app. */
795 /* Switch to the proper frame section, first time. */
796 switch_to_frame_table_section (for_eh
, false);
798 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
799 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
801 /* Output the CIE. */
802 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
803 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
804 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
805 dw2_asm_output_data (4, 0xffffffff,
806 "Initial length escape value indicating 64-bit DWARF extension");
807 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
808 "Length of Common Information Entry");
809 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
811 /* Now that the CIE pointer is PC-relative for EH,
812 use 0 to identify the CIE. */
813 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
814 (for_eh
? 0 : DWARF_CIE_ID
),
815 "CIE Identifier Tag");
817 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
818 use CIE version 1, unless that would produce incorrect results
819 due to overflowing the return register column. */
820 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
822 if (return_reg
>= 256 || dwarf_version
> 2)
824 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
827 augmentation_size
= 0;
829 personality
= current_unit_personality
;
835 z Indicates that a uleb128 is present to size the
836 augmentation section.
837 L Indicates the encoding (and thus presence) of
838 an LSDA pointer in the FDE augmentation.
839 R Indicates a non-default pointer encoding for
841 P Indicates the presence of an encoding + language
842 personality routine in the CIE augmentation. */
844 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
845 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
846 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
848 p
= augmentation
+ 1;
852 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
853 assemble_external_libcall (personality
);
858 augmentation_size
+= 1;
860 if (fde_encoding
!= DW_EH_PE_absptr
)
863 augmentation_size
+= 1;
865 if (p
> augmentation
+ 1)
867 augmentation
[0] = 'z';
871 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
872 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
874 int offset
= ( 4 /* Length */
876 + 1 /* CIE version */
877 + strlen (augmentation
) + 1 /* Augmentation */
878 + size_of_uleb128 (1) /* Code alignment */
879 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
881 + 1 /* Augmentation size */
882 + 1 /* Personality encoding */ );
883 int pad
= -offset
& (PTR_SIZE
- 1);
885 augmentation_size
+= pad
;
887 /* Augmentations should be small, so there's scarce need to
888 iterate for a solution. Die if we exceed one uleb128 byte. */
889 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
893 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
894 if (dw_cie_version
>= 4)
896 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
897 dw2_asm_output_data (1, 0, "CIE Segment Size");
899 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
900 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
901 "CIE Data Alignment Factor");
903 if (dw_cie_version
== 1)
904 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
906 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
910 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
913 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
914 eh_data_format_name (per_encoding
));
915 dw2_asm_output_encoded_addr_rtx (per_encoding
,
921 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
922 eh_data_format_name (lsda_encoding
));
924 if (fde_encoding
!= DW_EH_PE_absptr
)
925 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
926 eh_data_format_name (fde_encoding
));
929 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
930 output_cfi (cfi
, NULL
, for_eh
);
932 /* Pad the CIE out to an address sized boundary. */
933 ASM_OUTPUT_ALIGN (asm_out_file
,
934 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
935 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
937 /* Loop through all of the FDE's. */
938 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
942 /* Don't emit EH unwind info for leaf functions that don't need it. */
943 if (for_eh
&& !fde_needed_for_eh_p (fde
))
946 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
947 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
948 augmentation
, any_lsda_needed
, lsda_encoding
);
951 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
952 dw2_asm_output_data (4, 0, "End of Table");
954 /* Turn off app to make assembly quicker. */
959 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
962 dwarf2out_do_cfi_startproc (bool second
)
966 rtx personality
= get_personality_function (current_function_decl
);
968 fprintf (asm_out_file
, "\t.cfi_startproc\n");
972 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
975 /* ??? The GAS support isn't entirely consistent. We have to
976 handle indirect support ourselves, but PC-relative is done
977 in the assembler. Further, the assembler can't handle any
978 of the weirder relocation types. */
979 if (enc
& DW_EH_PE_indirect
)
980 ref
= dw2_force_const_mem (ref
, true);
982 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
983 output_addr_const (asm_out_file
, ref
);
984 fputc ('\n', asm_out_file
);
987 if (crtl
->uses_eh_lsda
)
991 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
992 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
993 current_function_funcdef_no
);
994 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
995 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
997 if (enc
& DW_EH_PE_indirect
)
998 ref
= dw2_force_const_mem (ref
, true);
1000 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1001 output_addr_const (asm_out_file
, ref
);
1002 fputc ('\n', asm_out_file
);
1006 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1007 this allocation may be done before pass_final. */
1010 dwarf2out_alloc_current_fde (void)
1014 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1015 fde
->decl
= current_function_decl
;
1016 fde
->funcdef_number
= current_function_funcdef_no
;
1017 fde
->fde_index
= vec_safe_length (fde_vec
);
1018 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1019 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1020 fde
->nothrow
= crtl
->nothrow
;
1021 fde
->drap_reg
= INVALID_REGNUM
;
1022 fde
->vdrap_reg
= INVALID_REGNUM
;
1024 /* Record the FDE associated with this function. */
1026 vec_safe_push (fde_vec
, fde
);
1031 /* Output a marker (i.e. a label) for the beginning of a function, before
1035 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1036 const char *file ATTRIBUTE_UNUSED
)
1038 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1044 current_function_func_begin_label
= NULL
;
1046 do_frame
= dwarf2out_do_frame ();
1048 /* ??? current_function_func_begin_label is also used by except.c for
1049 call-site information. We must emit this label if it might be used. */
1051 && (!flag_exceptions
1052 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1055 fnsec
= function_section (current_function_decl
);
1056 switch_to_section (fnsec
);
1057 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1058 current_function_funcdef_no
);
1059 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1060 current_function_funcdef_no
);
1061 dup_label
= xstrdup (label
);
1062 current_function_func_begin_label
= dup_label
;
1064 /* We can elide the fde allocation if we're not emitting debug info. */
1068 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1069 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1070 would include pass_dwarf2_frame. If we've not created the FDE yet,
1074 fde
= dwarf2out_alloc_current_fde ();
1076 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1077 fde
->dw_fde_begin
= dup_label
;
1078 fde
->dw_fde_current_label
= dup_label
;
1079 fde
->in_std_section
= (fnsec
== text_section
1080 || (cold_text_section
&& fnsec
== cold_text_section
));
1082 /* We only want to output line number information for the genuine dwarf2
1083 prologue case, not the eh frame case. */
1084 #ifdef DWARF2_DEBUGGING_INFO
1086 dwarf2out_source_line (line
, file
, 0, true);
1089 if (dwarf2out_do_cfi_asm ())
1090 dwarf2out_do_cfi_startproc (false);
1093 rtx personality
= get_personality_function (current_function_decl
);
1094 if (!current_unit_personality
)
1095 current_unit_personality
= personality
;
1097 /* We cannot keep a current personality per function as without CFI
1098 asm, at the point where we emit the CFI data, there is no current
1099 function anymore. */
1100 if (personality
&& current_unit_personality
!= personality
)
1101 sorry ("multiple EH personalities are supported only with assemblers "
1102 "supporting .cfi_personality directive");
1106 /* Output a marker (i.e. a label) for the end of the generated code
1107 for a function prologue. This gets called *after* the prologue code has
1111 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1112 const char *file ATTRIBUTE_UNUSED
)
1114 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1116 /* Output a label to mark the endpoint of the code generated for this
1118 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1119 current_function_funcdef_no
);
1120 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1121 current_function_funcdef_no
);
1122 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1125 /* Output a marker (i.e. a label) for the beginning of the generated code
1126 for a function epilogue. This gets called *before* the prologue code has
1130 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1131 const char *file ATTRIBUTE_UNUSED
)
1133 dw_fde_ref fde
= cfun
->fde
;
1134 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1136 if (fde
->dw_fde_vms_begin_epilogue
)
1139 /* Output a label to mark the endpoint of the code generated for this
1141 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1142 current_function_funcdef_no
);
1143 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1144 current_function_funcdef_no
);
1145 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1148 /* Output a marker (i.e. a label) for the absolute end of the generated code
1149 for a function definition. This gets called *after* the epilogue code has
1153 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1154 const char *file ATTRIBUTE_UNUSED
)
1157 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1159 last_var_location_insn
= NULL
;
1160 cached_next_real_insn
= NULL
;
1162 if (dwarf2out_do_cfi_asm ())
1163 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1165 /* Output a label to mark the endpoint of the code generated for this
1167 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1168 current_function_funcdef_no
);
1169 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1171 gcc_assert (fde
!= NULL
);
1172 if (fde
->dw_fde_second_begin
== NULL
)
1173 fde
->dw_fde_end
= xstrdup (label
);
1177 dwarf2out_frame_finish (void)
1179 /* Output call frame information. */
1180 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1181 output_call_frame_info (0);
1183 /* Output another copy for the unwinder. */
1184 if ((flag_unwind_tables
|| flag_exceptions
)
1185 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1186 output_call_frame_info (1);
1189 /* Note that the current function section is being used for code. */
1192 dwarf2out_note_section_used (void)
1194 section
*sec
= current_function_section ();
1195 if (sec
== text_section
)
1196 text_section_used
= true;
1197 else if (sec
== cold_text_section
)
1198 cold_text_section_used
= true;
1201 static void var_location_switch_text_section (void);
1202 static void set_cur_line_info_table (section
*);
1205 dwarf2out_switch_text_section (void)
1208 dw_fde_ref fde
= cfun
->fde
;
1210 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1212 if (!in_cold_section_p
)
1214 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1215 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1216 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1220 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1221 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1222 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1224 have_multiple_function_sections
= true;
1226 /* There is no need to mark used sections when not debugging. */
1227 if (cold_text_section
!= NULL
)
1228 dwarf2out_note_section_used ();
1230 if (dwarf2out_do_cfi_asm ())
1231 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1233 /* Now do the real section switch. */
1234 sect
= current_function_section ();
1235 switch_to_section (sect
);
1237 fde
->second_in_std_section
1238 = (sect
== text_section
1239 || (cold_text_section
&& sect
== cold_text_section
));
1241 if (dwarf2out_do_cfi_asm ())
1242 dwarf2out_do_cfi_startproc (true);
1244 var_location_switch_text_section ();
1246 if (cold_text_section
!= NULL
)
1247 set_cur_line_info_table (sect
);
1250 /* And now, the subset of the debugging information support code necessary
1251 for emitting location expressions. */
1253 /* Data about a single source file. */
1254 struct GTY((for_user
)) dwarf_file_data
{
1255 const char * filename
;
1259 /* Describe an entry into the .debug_addr section. */
1263 ate_kind_rtx_dtprel
,
1267 typedef struct GTY((for_user
)) addr_table_entry_struct
{
1269 unsigned int refcount
;
1271 union addr_table_entry_struct_union
1273 rtx
GTY ((tag ("0"))) rtl
;
1274 char * GTY ((tag ("1"))) label
;
1276 GTY ((desc ("%1.kind"))) addr
;
1280 /* Location lists are ranges + location descriptions for that range,
1281 so you can track variables that are in different places over
1282 their entire life. */
1283 typedef struct GTY(()) dw_loc_list_struct
{
1284 dw_loc_list_ref dw_loc_next
;
1285 const char *begin
; /* Label and addr_entry for start of range */
1286 addr_table_entry
*begin_entry
;
1287 const char *end
; /* Label for end of range */
1288 char *ll_symbol
; /* Label for beginning of location list.
1289 Only on head of list */
1290 const char *section
; /* Section this loclist is relative to */
1291 dw_loc_descr_ref expr
;
1293 /* True if all addresses in this and subsequent lists are known to be
1296 /* True if this list has been replaced by dw_loc_next. */
1299 /* True if the range should be emitted even if begin and end
1304 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1306 /* Convert a DWARF stack opcode into its string name. */
1309 dwarf_stack_op_name (unsigned int op
)
1311 const char *name
= get_DW_OP_name (op
);
1316 return "OP_<unknown>";
1319 /* Return a pointer to a newly allocated location description. Location
1320 descriptions are simple expression terms that can be strung
1321 together to form more complicated location (address) descriptions. */
1323 static inline dw_loc_descr_ref
1324 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1325 unsigned HOST_WIDE_INT oprnd2
)
1327 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1329 descr
->dw_loc_opc
= op
;
1330 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1331 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1332 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1333 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1334 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1335 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1340 /* Return a pointer to a newly allocated location description for
1343 static inline dw_loc_descr_ref
1344 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1347 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1350 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1353 /* Add a location description term to a location description expression. */
1356 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1358 dw_loc_descr_ref
*d
;
1360 /* Find the end of the chain. */
1361 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1367 /* Compare two location operands for exact equality. */
1370 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1372 if (a
->val_class
!= b
->val_class
)
1374 switch (a
->val_class
)
1376 case dw_val_class_none
:
1378 case dw_val_class_addr
:
1379 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1381 case dw_val_class_offset
:
1382 case dw_val_class_unsigned_const
:
1383 case dw_val_class_const
:
1384 case dw_val_class_range_list
:
1385 case dw_val_class_lineptr
:
1386 case dw_val_class_macptr
:
1387 /* These are all HOST_WIDE_INT, signed or unsigned. */
1388 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1390 case dw_val_class_loc
:
1391 return a
->v
.val_loc
== b
->v
.val_loc
;
1392 case dw_val_class_loc_list
:
1393 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1394 case dw_val_class_die_ref
:
1395 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1396 case dw_val_class_fde_ref
:
1397 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1398 case dw_val_class_lbl_id
:
1399 case dw_val_class_high_pc
:
1400 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1401 case dw_val_class_str
:
1402 return a
->v
.val_str
== b
->v
.val_str
;
1403 case dw_val_class_flag
:
1404 return a
->v
.val_flag
== b
->v
.val_flag
;
1405 case dw_val_class_file
:
1406 return a
->v
.val_file
== b
->v
.val_file
;
1407 case dw_val_class_decl_ref
:
1408 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1410 case dw_val_class_const_double
:
1411 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1412 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1414 case dw_val_class_wide_int
:
1415 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1417 case dw_val_class_vec
:
1419 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1420 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1422 return (a_len
== b_len
1423 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1426 case dw_val_class_data8
:
1427 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1429 case dw_val_class_vms_delta
:
1430 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1431 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1436 /* Compare two location atoms for exact equality. */
1439 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1441 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1444 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1445 address size, but since we always allocate cleared storage it
1446 should be zero for other types of locations. */
1447 if (a
->dtprel
!= b
->dtprel
)
1450 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1451 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1454 /* Compare two complete location expressions for exact equality. */
1457 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1463 if (a
== NULL
|| b
== NULL
)
1465 if (!loc_descr_equal_p_1 (a
, b
))
1474 /* Add a constant OFFSET to a location expression. */
1477 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1479 dw_loc_descr_ref loc
;
1482 gcc_assert (*list_head
!= NULL
);
1487 /* Find the end of the chain. */
1488 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1492 if (loc
->dw_loc_opc
== DW_OP_fbreg
1493 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1494 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1495 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1496 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1498 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1499 offset. Don't optimize if an signed integer overflow would happen. */
1501 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1502 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1505 else if (offset
> 0)
1506 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1510 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1511 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1515 /* Add a constant OFFSET to a location list. */
1518 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1521 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1522 loc_descr_plus_const (&d
->expr
, offset
);
1525 #define DWARF_REF_SIZE \
1526 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1528 static unsigned long int get_base_type_offset (dw_die_ref
);
1530 /* Return the size of a location descriptor. */
1532 static unsigned long
1533 size_of_loc_descr (dw_loc_descr_ref loc
)
1535 unsigned long size
= 1;
1537 switch (loc
->dw_loc_opc
)
1540 size
+= DWARF2_ADDR_SIZE
;
1542 case DW_OP_GNU_addr_index
:
1543 case DW_OP_GNU_const_index
:
1544 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1545 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1564 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1567 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1572 case DW_OP_plus_uconst
:
1573 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1611 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1614 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1617 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1620 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1621 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1624 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1626 case DW_OP_bit_piece
:
1627 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1628 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1630 case DW_OP_deref_size
:
1631 case DW_OP_xderef_size
:
1640 case DW_OP_call_ref
:
1641 size
+= DWARF_REF_SIZE
;
1643 case DW_OP_implicit_value
:
1644 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1645 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1647 case DW_OP_GNU_implicit_pointer
:
1648 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1650 case DW_OP_GNU_entry_value
:
1652 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1653 size
+= size_of_uleb128 (op_size
) + op_size
;
1656 case DW_OP_GNU_const_type
:
1659 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1660 size
+= size_of_uleb128 (o
) + 1;
1661 switch (loc
->dw_loc_oprnd2
.val_class
)
1663 case dw_val_class_vec
:
1664 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1665 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1667 case dw_val_class_const
:
1668 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1670 case dw_val_class_const_double
:
1671 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1673 case dw_val_class_wide_int
:
1674 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1675 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1682 case DW_OP_GNU_regval_type
:
1685 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1686 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1687 + size_of_uleb128 (o
);
1690 case DW_OP_GNU_deref_type
:
1693 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1694 size
+= 1 + size_of_uleb128 (o
);
1697 case DW_OP_GNU_convert
:
1698 case DW_OP_GNU_reinterpret
:
1699 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1700 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1704 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1705 size
+= size_of_uleb128 (o
);
1708 case DW_OP_GNU_parameter_ref
:
1718 /* Return the size of a series of location descriptors. */
1721 size_of_locs (dw_loc_descr_ref loc
)
1726 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1727 field, to avoid writing to a PCH file. */
1728 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1730 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1732 size
+= size_of_loc_descr (l
);
1737 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1739 l
->dw_loc_addr
= size
;
1740 size
+= size_of_loc_descr (l
);
1746 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1747 static void get_ref_die_offset_label (char *, dw_die_ref
);
1748 static unsigned long int get_ref_die_offset (dw_die_ref
);
1750 /* Output location description stack opcode's operands (if any).
1751 The for_eh_or_skip parameter controls whether register numbers are
1752 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1753 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1754 info). This should be suppressed for the cases that have not been converted
1755 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1758 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1760 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1761 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1763 switch (loc
->dw_loc_opc
)
1765 #ifdef DWARF2_DEBUGGING_INFO
1768 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1773 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1774 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1776 fputc ('\n', asm_out_file
);
1781 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1786 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1787 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1789 fputc ('\n', asm_out_file
);
1794 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1795 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1802 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1803 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1805 dw2_asm_output_data (2, offset
, NULL
);
1808 case DW_OP_implicit_value
:
1809 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1810 switch (val2
->val_class
)
1812 case dw_val_class_const
:
1813 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1815 case dw_val_class_vec
:
1817 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1818 unsigned int len
= val2
->v
.val_vec
.length
;
1822 if (elt_size
> sizeof (HOST_WIDE_INT
))
1827 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1830 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1831 "fp or vector constant word %u", i
);
1834 case dw_val_class_const_double
:
1836 unsigned HOST_WIDE_INT first
, second
;
1838 if (WORDS_BIG_ENDIAN
)
1840 first
= val2
->v
.val_double
.high
;
1841 second
= val2
->v
.val_double
.low
;
1845 first
= val2
->v
.val_double
.low
;
1846 second
= val2
->v
.val_double
.high
;
1848 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1850 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1854 case dw_val_class_wide_int
:
1857 int len
= get_full_len (*val2
->v
.val_wide
);
1858 if (WORDS_BIG_ENDIAN
)
1859 for (i
= len
- 1; i
>= 0; --i
)
1860 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1861 val2
->v
.val_wide
->elt (i
), NULL
);
1863 for (i
= 0; i
< len
; ++i
)
1864 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1865 val2
->v
.val_wide
->elt (i
), NULL
);
1868 case dw_val_class_addr
:
1869 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1870 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1885 case DW_OP_implicit_value
:
1886 /* We currently don't make any attempt to make sure these are
1887 aligned properly like we do for the main unwind info, so
1888 don't support emitting things larger than a byte if we're
1889 only doing unwinding. */
1894 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1897 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1900 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1903 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1905 case DW_OP_plus_uconst
:
1906 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1940 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1944 unsigned r
= val1
->v
.val_unsigned
;
1945 if (for_eh_or_skip
>= 0)
1946 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1947 gcc_assert (size_of_uleb128 (r
)
1948 == size_of_uleb128 (val1
->v
.val_unsigned
));
1949 dw2_asm_output_data_uleb128 (r
, NULL
);
1953 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1957 unsigned r
= val1
->v
.val_unsigned
;
1958 if (for_eh_or_skip
>= 0)
1959 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1960 gcc_assert (size_of_uleb128 (r
)
1961 == size_of_uleb128 (val1
->v
.val_unsigned
));
1962 dw2_asm_output_data_uleb128 (r
, NULL
);
1963 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1967 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1969 case DW_OP_bit_piece
:
1970 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1971 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1973 case DW_OP_deref_size
:
1974 case DW_OP_xderef_size
:
1975 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1981 if (targetm
.asm_out
.output_dwarf_dtprel
)
1983 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1986 fputc ('\n', asm_out_file
);
1993 #ifdef DWARF2_DEBUGGING_INFO
1994 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2001 case DW_OP_GNU_addr_index
:
2002 case DW_OP_GNU_const_index
:
2003 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2004 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2005 "(index into .debug_addr)");
2008 case DW_OP_GNU_implicit_pointer
:
2010 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2011 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2012 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2013 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2014 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2015 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2019 case DW_OP_GNU_entry_value
:
2020 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2021 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2024 case DW_OP_GNU_const_type
:
2026 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2028 dw2_asm_output_data_uleb128 (o
, NULL
);
2029 switch (val2
->val_class
)
2031 case dw_val_class_const
:
2032 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2033 dw2_asm_output_data (1, l
, NULL
);
2034 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2036 case dw_val_class_vec
:
2038 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2039 unsigned int len
= val2
->v
.val_vec
.length
;
2044 dw2_asm_output_data (1, l
, NULL
);
2045 if (elt_size
> sizeof (HOST_WIDE_INT
))
2050 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2053 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2054 "fp or vector constant word %u", i
);
2057 case dw_val_class_const_double
:
2059 unsigned HOST_WIDE_INT first
, second
;
2060 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2062 dw2_asm_output_data (1, 2 * l
, NULL
);
2063 if (WORDS_BIG_ENDIAN
)
2065 first
= val2
->v
.val_double
.high
;
2066 second
= val2
->v
.val_double
.low
;
2070 first
= val2
->v
.val_double
.low
;
2071 second
= val2
->v
.val_double
.high
;
2073 dw2_asm_output_data (l
, first
, NULL
);
2074 dw2_asm_output_data (l
, second
, NULL
);
2077 case dw_val_class_wide_int
:
2080 int len
= get_full_len (*val2
->v
.val_wide
);
2081 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2083 dw2_asm_output_data (1, len
* l
, NULL
);
2084 if (WORDS_BIG_ENDIAN
)
2085 for (i
= len
- 1; i
>= 0; --i
)
2086 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2088 for (i
= 0; i
< len
; ++i
)
2089 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2097 case DW_OP_GNU_regval_type
:
2099 unsigned r
= val1
->v
.val_unsigned
;
2100 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2102 if (for_eh_or_skip
>= 0)
2104 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2105 gcc_assert (size_of_uleb128 (r
)
2106 == size_of_uleb128 (val1
->v
.val_unsigned
));
2108 dw2_asm_output_data_uleb128 (r
, NULL
);
2109 dw2_asm_output_data_uleb128 (o
, NULL
);
2112 case DW_OP_GNU_deref_type
:
2114 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2116 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2117 dw2_asm_output_data_uleb128 (o
, NULL
);
2120 case DW_OP_GNU_convert
:
2121 case DW_OP_GNU_reinterpret
:
2122 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2123 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2126 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2128 dw2_asm_output_data_uleb128 (o
, NULL
);
2132 case DW_OP_GNU_parameter_ref
:
2135 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2136 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2137 dw2_asm_output_data (4, o
, NULL
);
2142 /* Other codes have no operands. */
2147 /* Output a sequence of location operations.
2148 The for_eh_or_skip parameter controls whether register numbers are
2149 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2150 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2151 info). This should be suppressed for the cases that have not been converted
2152 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2155 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2157 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2159 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2160 /* Output the opcode. */
2161 if (for_eh_or_skip
>= 0
2162 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2164 unsigned r
= (opc
- DW_OP_breg0
);
2165 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2166 gcc_assert (r
<= 31);
2167 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2169 else if (for_eh_or_skip
>= 0
2170 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2172 unsigned r
= (opc
- DW_OP_reg0
);
2173 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2174 gcc_assert (r
<= 31);
2175 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2178 dw2_asm_output_data (1, opc
,
2179 "%s", dwarf_stack_op_name (opc
));
2181 /* Output the operand(s) (if any). */
2182 output_loc_operands (loc
, for_eh_or_skip
);
2186 /* Output location description stack opcode's operands (if any).
2187 The output is single bytes on a line, suitable for .cfi_escape. */
2190 output_loc_operands_raw (dw_loc_descr_ref loc
)
2192 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2193 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2195 switch (loc
->dw_loc_opc
)
2198 case DW_OP_GNU_addr_index
:
2199 case DW_OP_GNU_const_index
:
2200 case DW_OP_implicit_value
:
2201 /* We cannot output addresses in .cfi_escape, only bytes. */
2207 case DW_OP_deref_size
:
2208 case DW_OP_xderef_size
:
2209 fputc (',', asm_out_file
);
2210 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2215 fputc (',', asm_out_file
);
2216 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2221 fputc (',', asm_out_file
);
2222 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2227 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2228 fputc (',', asm_out_file
);
2229 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2237 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2238 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2240 fputc (',', asm_out_file
);
2241 dw2_asm_output_data_raw (2, offset
);
2247 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2248 gcc_assert (size_of_uleb128 (r
)
2249 == size_of_uleb128 (val1
->v
.val_unsigned
));
2250 fputc (',', asm_out_file
);
2251 dw2_asm_output_data_uleb128_raw (r
);
2256 case DW_OP_plus_uconst
:
2258 fputc (',', asm_out_file
);
2259 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2262 case DW_OP_bit_piece
:
2263 fputc (',', asm_out_file
);
2264 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2265 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2302 fputc (',', asm_out_file
);
2303 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2308 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2309 gcc_assert (size_of_uleb128 (r
)
2310 == size_of_uleb128 (val1
->v
.val_unsigned
));
2311 fputc (',', asm_out_file
);
2312 dw2_asm_output_data_uleb128_raw (r
);
2313 fputc (',', asm_out_file
);
2314 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2318 case DW_OP_GNU_implicit_pointer
:
2319 case DW_OP_GNU_entry_value
:
2320 case DW_OP_GNU_const_type
:
2321 case DW_OP_GNU_regval_type
:
2322 case DW_OP_GNU_deref_type
:
2323 case DW_OP_GNU_convert
:
2324 case DW_OP_GNU_reinterpret
:
2325 case DW_OP_GNU_parameter_ref
:
2330 /* Other codes have no operands. */
2336 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2340 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2341 /* Output the opcode. */
2342 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2344 unsigned r
= (opc
- DW_OP_breg0
);
2345 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2346 gcc_assert (r
<= 31);
2347 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2349 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2351 unsigned r
= (opc
- DW_OP_reg0
);
2352 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2353 gcc_assert (r
<= 31);
2354 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2356 /* Output the opcode. */
2357 fprintf (asm_out_file
, "%#x", opc
);
2358 output_loc_operands_raw (loc
);
2360 if (!loc
->dw_loc_next
)
2362 loc
= loc
->dw_loc_next
;
2364 fputc (',', asm_out_file
);
2368 /* This function builds a dwarf location descriptor sequence from a
2369 dw_cfa_location, adding the given OFFSET to the result of the
2372 struct dw_loc_descr_node
*
2373 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2375 struct dw_loc_descr_node
*head
, *tmp
;
2377 offset
+= cfa
->offset
;
2381 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2382 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2383 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2384 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2385 add_loc_descr (&head
, tmp
);
2388 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2389 add_loc_descr (&head
, tmp
);
2393 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2398 /* This function builds a dwarf location descriptor sequence for
2399 the address at OFFSET from the CFA when stack is aligned to
2402 struct dw_loc_descr_node
*
2403 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2404 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2406 struct dw_loc_descr_node
*head
;
2407 unsigned int dwarf_fp
2408 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2410 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2411 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2413 head
= new_reg_loc_descr (dwarf_fp
, 0);
2414 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2415 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2416 loc_descr_plus_const (&head
, offset
);
2419 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2423 /* And now, the support for symbolic debugging information. */
2425 /* .debug_str support. */
2427 static void dwarf2out_init (const char *);
2428 static void dwarf2out_finish (const char *);
2429 static void dwarf2out_early_finish (void);
2430 static void dwarf2out_assembly_start (void);
2431 static void dwarf2out_define (unsigned int, const char *);
2432 static void dwarf2out_undef (unsigned int, const char *);
2433 static void dwarf2out_start_source_file (unsigned, const char *);
2434 static void dwarf2out_end_source_file (unsigned);
2435 static void dwarf2out_function_decl (tree
);
2436 static void dwarf2out_begin_block (unsigned, unsigned);
2437 static void dwarf2out_end_block (unsigned, unsigned);
2438 static bool dwarf2out_ignore_block (const_tree
);
2439 static void dwarf2out_early_global_decl (tree
);
2440 static void dwarf2out_late_global_decl (tree
);
2441 static void dwarf2out_type_decl (tree
, int);
2442 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2443 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2445 static void dwarf2out_abstract_function (tree
);
2446 static void dwarf2out_var_location (rtx_insn
*);
2447 static void dwarf2out_begin_function (tree
);
2448 static void dwarf2out_end_function (unsigned int);
2449 static void dwarf2out_register_main_translation_unit (tree unit
);
2450 static void dwarf2out_set_name (tree
, tree
);
2452 /* The debug hooks structure. */
2454 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2458 dwarf2out_early_finish
,
2459 dwarf2out_assembly_start
,
2462 dwarf2out_start_source_file
,
2463 dwarf2out_end_source_file
,
2464 dwarf2out_begin_block
,
2465 dwarf2out_end_block
,
2466 dwarf2out_ignore_block
,
2467 dwarf2out_source_line
,
2468 dwarf2out_begin_prologue
,
2469 #if VMS_DEBUGGING_INFO
2470 dwarf2out_vms_end_prologue
,
2471 dwarf2out_vms_begin_epilogue
,
2473 debug_nothing_int_charstar
,
2474 debug_nothing_int_charstar
,
2476 dwarf2out_end_epilogue
,
2477 dwarf2out_begin_function
,
2478 dwarf2out_end_function
, /* end_function */
2479 dwarf2out_register_main_translation_unit
,
2480 dwarf2out_function_decl
, /* function_decl */
2481 dwarf2out_early_global_decl
,
2482 dwarf2out_late_global_decl
,
2483 dwarf2out_type_decl
, /* type_decl */
2484 dwarf2out_imported_module_or_decl
,
2485 debug_nothing_tree
, /* deferred_inline_function */
2486 /* The DWARF 2 backend tries to reduce debugging bloat by not
2487 emitting the abstract description of inline functions until
2488 something tries to reference them. */
2489 dwarf2out_abstract_function
, /* outlining_inline_function */
2490 debug_nothing_rtx_code_label
, /* label */
2491 debug_nothing_int
, /* handle_pch */
2492 dwarf2out_var_location
,
2493 dwarf2out_switch_text_section
,
2495 1, /* start_end_main_source_file */
2496 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2499 /* NOTE: In the comments in this file, many references are made to
2500 "Debugging Information Entries". This term is abbreviated as `DIE'
2501 throughout the remainder of this file. */
2503 /* An internal representation of the DWARF output is built, and then
2504 walked to generate the DWARF debugging info. The walk of the internal
2505 representation is done after the entire program has been compiled.
2506 The types below are used to describe the internal representation. */
2508 /* Whether to put type DIEs into their own section .debug_types instead
2509 of making them part of the .debug_info section. Only supported for
2510 Dwarf V4 or higher and the user didn't disable them through
2511 -fno-debug-types-section. It is more efficient to put them in a
2512 separate comdat sections since the linker will then be able to
2513 remove duplicates. But not all tools support .debug_types sections
2516 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2518 /* Various DIE's use offsets relative to the beginning of the
2519 .debug_info section to refer to each other. */
2521 typedef long int dw_offset
;
2523 /* Define typedefs here to avoid circular dependencies. */
2525 typedef struct dw_attr_struct
*dw_attr_ref
;
2526 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2527 typedef struct pubname_struct
*pubname_ref
;
2528 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2529 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2530 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2532 /* The entries in the line_info table more-or-less mirror the opcodes
2533 that are used in the real dwarf line table. Arrays of these entries
2534 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2537 enum dw_line_info_opcode
{
2538 /* Emit DW_LNE_set_address; the operand is the label index. */
2541 /* Emit a row to the matrix with the given line. This may be done
2542 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2546 /* Emit a DW_LNS_set_file. */
2549 /* Emit a DW_LNS_set_column. */
2552 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2555 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2556 LI_set_prologue_end
,
2557 LI_set_epilogue_begin
,
2559 /* Emit a DW_LNE_set_discriminator. */
2560 LI_set_discriminator
2563 typedef struct GTY(()) dw_line_info_struct
{
2564 enum dw_line_info_opcode opcode
;
2566 } dw_line_info_entry
;
2569 typedef struct GTY(()) dw_line_info_table_struct
{
2570 /* The label that marks the end of this section. */
2571 const char *end_label
;
2573 /* The values for the last row of the matrix, as collected in the table.
2574 These are used to minimize the changes to the next row. */
2575 unsigned int file_num
;
2576 unsigned int line_num
;
2577 unsigned int column_num
;
2582 vec
<dw_line_info_entry
, va_gc
> *entries
;
2583 } dw_line_info_table
;
2585 typedef dw_line_info_table
*dw_line_info_table_p
;
2588 /* Each DIE attribute has a field specifying the attribute kind,
2589 a link to the next attribute in the chain, and an attribute value.
2590 Attributes are typically linked below the DIE they modify. */
2592 typedef struct GTY(()) dw_attr_struct
{
2593 enum dwarf_attribute dw_attr
;
2594 dw_val_node dw_attr_val
;
2599 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2600 The children of each node form a circular list linked by
2601 die_sib. die_child points to the node *before* the "first" child node. */
2603 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2604 union die_symbol_or_type_node
2606 const char * GTY ((tag ("0"))) die_symbol
;
2607 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2609 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2610 vec
<dw_attr_node
, va_gc
> *die_attr
;
2611 dw_die_ref die_parent
;
2612 dw_die_ref die_child
;
2614 dw_die_ref die_definition
; /* ref from a specification to its definition */
2615 dw_offset die_offset
;
2616 unsigned long die_abbrev
;
2618 unsigned int decl_id
;
2619 enum dwarf_tag die_tag
;
2620 /* Die is used and must not be pruned as unused. */
2621 BOOL_BITFIELD die_perennial_p
: 1;
2622 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2623 /* Lots of spare bits. */
2627 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2628 static bool early_dwarf
;
2629 struct set_early_dwarf
{
2631 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2632 ~set_early_dwarf () { early_dwarf
= saved
; }
2635 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2636 #define FOR_EACH_CHILD(die, c, expr) do { \
2637 c = die->die_child; \
2641 } while (c != die->die_child); \
2644 /* The pubname structure */
2646 typedef struct GTY(()) pubname_struct
{
2653 struct GTY(()) dw_ranges_struct
{
2654 /* If this is positive, it's a block number, otherwise it's a
2655 bitwise-negated index into dw_ranges_by_label. */
2659 /* A structure to hold a macinfo entry. */
2661 typedef struct GTY(()) macinfo_struct
{
2663 unsigned HOST_WIDE_INT lineno
;
2669 struct GTY(()) dw_ranges_by_label_struct
{
2674 /* The comdat type node structure. */
2675 typedef struct GTY(()) comdat_type_struct
2677 dw_die_ref root_die
;
2678 dw_die_ref type_die
;
2679 dw_die_ref skeleton_die
;
2680 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2681 struct comdat_type_struct
*next
;
2685 /* A list of DIEs for which we can't determine ancestry (parent_die
2686 field) just yet. Later in dwarf2out_finish we will fill in the
2688 typedef struct GTY(()) limbo_die_struct
{
2690 /* The tree for which this DIE was created. We use this to
2691 determine ancestry later. */
2693 struct limbo_die_struct
*next
;
2697 typedef struct skeleton_chain_struct
2701 struct skeleton_chain_struct
*parent
;
2703 skeleton_chain_node
;
2705 /* Define a macro which returns nonzero for a TYPE_DECL which was
2706 implicitly generated for a type.
2708 Note that, unlike the C front-end (which generates a NULL named
2709 TYPE_DECL node for each complete tagged type, each array type,
2710 and each function type node created) the C++ front-end generates
2711 a _named_ TYPE_DECL node for each tagged type node created.
2712 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2713 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2714 front-end, but for each type, tagged or not. */
2716 #define TYPE_DECL_IS_STUB(decl) \
2717 (DECL_NAME (decl) == NULL_TREE \
2718 || (DECL_ARTIFICIAL (decl) \
2719 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2720 /* This is necessary for stub decls that \
2721 appear in nested inline functions. */ \
2722 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2723 && (decl_ultimate_origin (decl) \
2724 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2726 /* Information concerning the compilation unit's programming
2727 language, and compiler version. */
2729 /* Fixed size portion of the DWARF compilation unit header. */
2730 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2731 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2733 /* Fixed size portion of the DWARF comdat type unit header. */
2734 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2735 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2736 + DWARF_OFFSET_SIZE)
2738 /* Fixed size portion of public names info. */
2739 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2741 /* Fixed size portion of the address range info. */
2742 #define DWARF_ARANGES_HEADER_SIZE \
2743 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2744 DWARF2_ADDR_SIZE * 2) \
2745 - DWARF_INITIAL_LENGTH_SIZE)
2747 /* Size of padding portion in the address range info. It must be
2748 aligned to twice the pointer size. */
2749 #define DWARF_ARANGES_PAD_SIZE \
2750 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2751 DWARF2_ADDR_SIZE * 2) \
2752 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2754 /* Use assembler line directives if available. */
2755 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2756 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2757 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2759 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2763 /* Minimum line offset in a special line info. opcode.
2764 This value was chosen to give a reasonable range of values. */
2765 #define DWARF_LINE_BASE -10
2767 /* First special line opcode - leave room for the standard opcodes. */
2768 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2770 /* Range of line offsets in a special line info. opcode. */
2771 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2773 /* Flag that indicates the initial value of the is_stmt_start flag.
2774 In the present implementation, we do not mark any lines as
2775 the beginning of a source statement, because that information
2776 is not made available by the GCC front-end. */
2777 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2779 /* Maximum number of operations per instruction bundle. */
2780 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2781 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2784 /* This location is used by calc_die_sizes() to keep track
2785 the offset of each DIE within the .debug_info section. */
2786 static unsigned long next_die_offset
;
2788 /* Record the root of the DIE's built for the current compilation unit. */
2789 static GTY(()) dw_die_ref single_comp_unit_die
;
2791 /* A list of type DIEs that have been separated into comdat sections. */
2792 static GTY(()) comdat_type_node
*comdat_type_list
;
2794 /* A list of DIEs with a NULL parent waiting to be relocated. */
2795 static GTY(()) limbo_die_node
*limbo_die_list
;
2797 /* A list of DIEs for which we may have to generate
2798 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2799 static GTY(()) limbo_die_node
*deferred_asm_name
;
2801 struct dwarf_file_hasher
: ggc_hasher
<dwarf_file_data
*>
2803 typedef const char *compare_type
;
2805 static hashval_t
hash (dwarf_file_data
*);
2806 static bool equal (dwarf_file_data
*, const char *);
2809 /* Filenames referenced by this compilation unit. */
2810 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2812 struct decl_die_hasher
: ggc_hasher
<die_node
*>
2814 typedef tree compare_type
;
2816 static hashval_t
hash (die_node
*);
2817 static bool equal (die_node
*, tree
);
2819 /* A hash table of references to DIE's that describe declarations.
2820 The key is a DECL_UID() which is a unique number identifying each decl. */
2821 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2823 struct block_die_hasher
: ggc_hasher
<die_struct
*>
2825 static hashval_t
hash (die_struct
*);
2826 static bool equal (die_struct
*, die_struct
*);
2829 /* A hash table of references to DIE's that describe COMMON blocks.
2830 The key is DECL_UID() ^ die_parent. */
2831 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2833 typedef struct GTY(()) die_arg_entry_struct
{
2839 /* Node of the variable location list. */
2840 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2841 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2842 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2843 in mode of the EXPR_LIST node and first EXPR_LIST operand
2844 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2845 location or NULL for padding. For larger bitsizes,
2846 mode is 0 and first operand is a CONCAT with bitsize
2847 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2848 NULL as second operand. */
2850 const char * GTY (()) label
;
2851 struct var_loc_node
* GTY (()) next
;
2854 /* Variable location list. */
2855 struct GTY ((for_user
)) var_loc_list_def
{
2856 struct var_loc_node
* GTY (()) first
;
2858 /* Pointer to the last but one or last element of the
2859 chained list. If the list is empty, both first and
2860 last are NULL, if the list contains just one node
2861 or the last node certainly is not redundant, it points
2862 to the last node, otherwise points to the last but one.
2863 Do not mark it for GC because it is marked through the chain. */
2864 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2866 /* Pointer to the last element before section switch,
2867 if NULL, either sections weren't switched or first
2868 is after section switch. */
2869 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2871 /* DECL_UID of the variable decl. */
2872 unsigned int decl_id
;
2874 typedef struct var_loc_list_def var_loc_list
;
2876 /* Call argument location list. */
2877 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2878 rtx
GTY (()) call_arg_loc_note
;
2879 const char * GTY (()) label
;
2880 tree
GTY (()) block
;
2882 rtx
GTY (()) symbol_ref
;
2883 struct call_arg_loc_node
* GTY (()) next
;
2887 struct decl_loc_hasher
: ggc_hasher
<var_loc_list
*>
2889 typedef const_tree compare_type
;
2891 static hashval_t
hash (var_loc_list
*);
2892 static bool equal (var_loc_list
*, const_tree
);
2895 /* Table of decl location linked lists. */
2896 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2898 /* Head and tail of call_arg_loc chain. */
2899 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2900 static struct call_arg_loc_node
*call_arg_loc_last
;
2902 /* Number of call sites in the current function. */
2903 static int call_site_count
= -1;
2904 /* Number of tail call sites in the current function. */
2905 static int tail_call_site_count
= -1;
2907 /* A cached location list. */
2908 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2909 /* The DECL_UID of the decl that this entry describes. */
2910 unsigned int decl_id
;
2912 /* The cached location list. */
2913 dw_loc_list_ref loc_list
;
2915 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2917 struct dw_loc_list_hasher
: ggc_hasher
<cached_dw_loc_list
*>
2920 typedef const_tree compare_type
;
2922 static hashval_t
hash (cached_dw_loc_list
*);
2923 static bool equal (cached_dw_loc_list
*, const_tree
);
2926 /* Table of cached location lists. */
2927 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
2929 /* A pointer to the base of a list of references to DIE's that
2930 are uniquely identified by their tag, presence/absence of
2931 children DIE's, and list of attribute/value pairs. */
2932 static GTY((length ("abbrev_die_table_allocated")))
2933 dw_die_ref
*abbrev_die_table
;
2935 /* Number of elements currently allocated for abbrev_die_table. */
2936 static GTY(()) unsigned abbrev_die_table_allocated
;
2938 /* Number of elements in abbrev_die_table currently in use. */
2939 static GTY(()) unsigned abbrev_die_table_in_use
;
2941 /* Size (in elements) of increments by which we may expand the
2942 abbrev_die_table. */
2943 #define ABBREV_DIE_TABLE_INCREMENT 256
2945 /* A global counter for generating labels for line number data. */
2946 static unsigned int line_info_label_num
;
2948 /* The current table to which we should emit line number information
2949 for the current function. This will be set up at the beginning of
2950 assembly for the function. */
2951 static dw_line_info_table
*cur_line_info_table
;
2953 /* The two default tables of line number info. */
2954 static GTY(()) dw_line_info_table
*text_section_line_info
;
2955 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2957 /* The set of all non-default tables of line number info. */
2958 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2960 /* A flag to tell pubnames/types export if there is an info section to
2962 static bool info_section_emitted
;
2964 /* A pointer to the base of a table that contains a list of publicly
2965 accessible names. */
2966 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2968 /* A pointer to the base of a table that contains a list of publicly
2969 accessible types. */
2970 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2972 /* A pointer to the base of a table that contains a list of macro
2973 defines/undefines (and file start/end markers). */
2974 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2976 /* True if .debug_macinfo or .debug_macros section is going to be
2978 #define have_macinfo \
2979 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2980 && !macinfo_table->is_empty ())
2982 /* Array of dies for which we should generate .debug_ranges info. */
2983 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2985 /* Number of elements currently allocated for ranges_table. */
2986 static GTY(()) unsigned ranges_table_allocated
;
2988 /* Number of elements in ranges_table currently in use. */
2989 static GTY(()) unsigned ranges_table_in_use
;
2991 /* Array of pairs of labels referenced in ranges_table. */
2992 static GTY ((length ("ranges_by_label_allocated")))
2993 dw_ranges_by_label_ref ranges_by_label
;
2995 /* Number of elements currently allocated for ranges_by_label. */
2996 static GTY(()) unsigned ranges_by_label_allocated
;
2998 /* Number of elements in ranges_by_label currently in use. */
2999 static GTY(()) unsigned ranges_by_label_in_use
;
3001 /* Size (in elements) of increments by which we may expand the
3003 #define RANGES_TABLE_INCREMENT 64
3005 /* Whether we have location lists that need outputting */
3006 static GTY(()) bool have_location_lists
;
3008 /* Unique label counter. */
3009 static GTY(()) unsigned int loclabel_num
;
3011 /* Unique label counter for point-of-call tables. */
3012 static GTY(()) unsigned int poc_label_num
;
3014 /* The last file entry emitted by maybe_emit_file(). */
3015 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3017 /* Number of internal labels generated by gen_internal_sym(). */
3018 static GTY(()) int label_num
;
3020 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3022 /* Instances of generic types for which we need to generate debug
3023 info that describe their generic parameters and arguments. That
3024 generation needs to happen once all types are properly laid out so
3025 we do it at the end of compilation. */
3026 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3028 /* Offset from the "steady-state frame pointer" to the frame base,
3029 within the current function. */
3030 static HOST_WIDE_INT frame_pointer_fb_offset
;
3031 static bool frame_pointer_fb_offset_valid
;
3033 static vec
<dw_die_ref
> base_types
;
3035 /* Flags to represent a set of attribute classes for attributes that represent
3036 a scalar value (bounds, pointers, ...). */
3039 dw_scalar_form_constant
= 0x01,
3040 dw_scalar_form_exprloc
= 0x02,
3041 dw_scalar_form_reference
= 0x04
3044 /* Forward declarations for functions defined in this file. */
3046 static int is_pseudo_reg (const_rtx
);
3047 static tree
type_main_variant (tree
);
3048 static int is_tagged_type (const_tree
);
3049 static const char *dwarf_tag_name (unsigned);
3050 static const char *dwarf_attr_name (unsigned);
3051 static const char *dwarf_form_name (unsigned);
3052 static tree
decl_ultimate_origin (const_tree
);
3053 static tree
decl_class_context (tree
);
3054 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3055 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3056 static inline unsigned int AT_index (dw_attr_ref
);
3057 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3058 static inline unsigned AT_flag (dw_attr_ref
);
3059 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3060 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3061 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3062 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3063 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3064 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3065 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3066 unsigned int, unsigned char *);
3067 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3068 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3069 static inline const char *AT_string (dw_attr_ref
);
3070 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3071 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3072 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3073 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3074 static inline int AT_ref_external (dw_attr_ref
);
3075 static inline void set_AT_ref_external (dw_attr_ref
, int);
3076 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3077 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3078 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3079 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3081 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3082 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3083 static void remove_addr_table_entry (addr_table_entry
*);
3084 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3085 static inline rtx
AT_addr (dw_attr_ref
);
3086 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3087 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3088 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3089 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3090 unsigned HOST_WIDE_INT
);
3091 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3092 unsigned long, bool);
3093 static inline const char *AT_lbl (dw_attr_ref
);
3094 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3095 static const char *get_AT_low_pc (dw_die_ref
);
3096 static const char *get_AT_hi_pc (dw_die_ref
);
3097 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3098 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3099 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3100 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3101 static bool is_cxx (void);
3102 static bool is_fortran (void);
3103 static bool is_ada (void);
3104 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3105 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3106 static void add_child_die (dw_die_ref
, dw_die_ref
);
3107 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3108 static dw_die_ref
lookup_type_die (tree
);
3109 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3110 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3111 static void equate_type_number_to_die (tree
, dw_die_ref
);
3112 static dw_die_ref
lookup_decl_die (tree
);
3113 static var_loc_list
*lookup_decl_loc (const_tree
);
3114 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3115 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3116 static void print_spaces (FILE *);
3117 static void print_die (dw_die_ref
, FILE *);
3118 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3119 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3120 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3121 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3122 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3123 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3124 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3125 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3126 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3127 struct md5_ctx
*, int *);
3128 struct checksum_attributes
;
3129 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3130 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3131 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3132 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3133 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3134 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3135 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3136 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3137 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3138 static void compute_section_prefix (dw_die_ref
);
3139 static int is_type_die (dw_die_ref
);
3140 static int is_comdat_die (dw_die_ref
);
3141 static int is_symbol_die (dw_die_ref
);
3142 static inline bool is_template_instantiation (dw_die_ref
);
3143 static void assign_symbol_names (dw_die_ref
);
3144 static void break_out_includes (dw_die_ref
);
3145 static int is_declaration_die (dw_die_ref
);
3146 static int should_move_die_to_comdat (dw_die_ref
);
3147 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3148 static dw_die_ref
clone_die (dw_die_ref
);
3149 static dw_die_ref
clone_tree (dw_die_ref
);
3150 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3151 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3152 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3153 static dw_die_ref
generate_skeleton (dw_die_ref
);
3154 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3157 static void break_out_comdat_types (dw_die_ref
);
3158 static void copy_decls_for_unworthy_types (dw_die_ref
);
3160 static void add_sibling_attributes (dw_die_ref
);
3161 static void output_location_lists (dw_die_ref
);
3162 static int constant_size (unsigned HOST_WIDE_INT
);
3163 static unsigned long size_of_die (dw_die_ref
);
3164 static void calc_die_sizes (dw_die_ref
);
3165 static void calc_base_type_die_sizes (void);
3166 static void mark_dies (dw_die_ref
);
3167 static void unmark_dies (dw_die_ref
);
3168 static void unmark_all_dies (dw_die_ref
);
3169 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3170 static unsigned long size_of_aranges (void);
3171 static enum dwarf_form
value_format (dw_attr_ref
);
3172 static void output_value_format (dw_attr_ref
);
3173 static void output_abbrev_section (void);
3174 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3175 static void output_die_symbol (dw_die_ref
);
3176 static void output_die (dw_die_ref
);
3177 static void output_compilation_unit_header (void);
3178 static void output_comp_unit (dw_die_ref
, int);
3179 static void output_comdat_type_unit (comdat_type_node
*);
3180 static const char *dwarf2_name (tree
, int);
3181 static void add_pubname (tree
, dw_die_ref
);
3182 static void add_enumerator_pubname (const char *, dw_die_ref
);
3183 static void add_pubname_string (const char *, dw_die_ref
);
3184 static void add_pubtype (tree
, dw_die_ref
);
3185 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3186 static void output_aranges (unsigned long);
3187 static unsigned int add_ranges_num (int);
3188 static unsigned int add_ranges (const_tree
);
3189 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3191 static void output_ranges (void);
3192 static dw_line_info_table
*new_line_info_table (void);
3193 static void output_line_info (bool);
3194 static void output_file_names (void);
3195 static dw_die_ref
base_type_die (tree
);
3196 static int is_base_type (tree
);
3197 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3198 static int decl_quals (const_tree
);
3199 static dw_die_ref
modified_type_die (tree
, int, dw_die_ref
);
3200 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3201 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3202 static int type_is_enum (const_tree
);
3203 static unsigned int dbx_reg_number (const_rtx
);
3204 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3205 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3206 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3207 enum var_init_status
);
3208 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3209 enum var_init_status
);
3210 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3211 enum var_init_status
);
3212 static int is_based_loc (const_rtx
);
3213 static bool resolve_one_addr (rtx
*);
3214 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3215 enum var_init_status
);
3216 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3217 enum var_init_status
);
3218 struct loc_descr_context
;
3219 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3220 const struct loc_descr_context
*);
3221 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3222 const struct loc_descr_context
*);
3223 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3224 static tree
field_type (const_tree
);
3225 static unsigned int simple_type_align_in_bits (const_tree
);
3226 static unsigned int simple_decl_align_in_bits (const_tree
);
3227 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3228 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3229 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3231 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3232 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3233 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3234 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3235 static void insert_float (const_rtx
, unsigned char *);
3236 static rtx
rtl_for_decl_location (tree
);
3237 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3238 enum dwarf_attribute
);
3239 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3240 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3241 static void add_name_attribute (dw_die_ref
, const char *);
3242 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3243 static void add_comp_dir_attribute (dw_die_ref
);
3244 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3245 const struct loc_descr_context
*);
3246 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3247 const struct loc_descr_context
*);
3248 static void add_subscript_info (dw_die_ref
, tree
, bool);
3249 static void add_byte_size_attribute (dw_die_ref
, tree
);
3250 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3251 static void add_bit_size_attribute (dw_die_ref
, tree
);
3252 static void add_prototyped_attribute (dw_die_ref
, tree
);
3253 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3254 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3255 static void add_src_coords_attributes (dw_die_ref
, tree
);
3256 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3257 static void push_decl_scope (tree
);
3258 static void pop_decl_scope (void);
3259 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3260 static inline int local_scope_p (dw_die_ref
);
3261 static inline int class_scope_p (dw_die_ref
);
3262 static inline int class_or_namespace_scope_p (dw_die_ref
);
3263 static void add_type_attribute (dw_die_ref
, tree
, int, dw_die_ref
);
3264 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3265 static const char *type_tag (const_tree
);
3266 static tree
member_declared_type (const_tree
);
3268 static const char *decl_start_label (tree
);
3270 static void gen_array_type_die (tree
, dw_die_ref
);
3271 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3273 static void gen_entry_point_die (tree
, dw_die_ref
);
3275 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3276 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3277 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3278 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3279 static void gen_formal_types_die (tree
, dw_die_ref
);
3280 static void gen_subprogram_die (tree
, dw_die_ref
);
3281 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3282 static void gen_const_die (tree
, dw_die_ref
);
3283 static void gen_label_die (tree
, dw_die_ref
);
3284 static void gen_lexical_block_die (tree
, dw_die_ref
);
3285 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3286 static void gen_field_die (tree
, dw_die_ref
);
3287 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3288 static dw_die_ref
gen_compile_unit_die (const char *);
3289 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3290 static void gen_member_die (tree
, dw_die_ref
);
3291 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3292 enum debug_info_usage
);
3293 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3294 static void gen_typedef_die (tree
, dw_die_ref
);
3295 static void gen_type_die (tree
, dw_die_ref
);
3296 static void gen_block_die (tree
, dw_die_ref
);
3297 static void decls_for_scope (tree
, dw_die_ref
);
3298 static inline int is_redundant_typedef (const_tree
);
3299 static bool is_naming_typedef_decl (const_tree
);
3300 static inline dw_die_ref
get_context_die (tree
);
3301 static void gen_namespace_die (tree
, dw_die_ref
);
3302 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3303 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3304 static dw_die_ref
force_decl_die (tree
);
3305 static dw_die_ref
force_type_die (tree
);
3306 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3307 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3308 static struct dwarf_file_data
* lookup_filename (const char *);
3309 static void retry_incomplete_types (void);
3310 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3311 static void gen_generic_params_dies (tree
);
3312 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3313 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3314 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3315 static int file_info_cmp (const void *, const void *);
3316 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3317 const char *, const char *);
3318 static void output_loc_list (dw_loc_list_ref
);
3319 static char *gen_internal_sym (const char *);
3320 static bool want_pubnames (void);
3322 static void prune_unmark_dies (dw_die_ref
);
3323 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3324 static void prune_unused_types_mark (dw_die_ref
, int);
3325 static void prune_unused_types_walk (dw_die_ref
);
3326 static void prune_unused_types_walk_attribs (dw_die_ref
);
3327 static void prune_unused_types_prune (dw_die_ref
);
3328 static void prune_unused_types (void);
3329 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3330 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3331 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3332 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3333 const char *, const char *);
3334 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3335 static void gen_remaining_tmpl_value_param_die_attribute (void);
3336 static bool generic_type_p (tree
);
3337 static void schedule_generic_params_dies_gen (tree t
);
3338 static void gen_scheduled_generic_parms_dies (void);
3340 static const char *comp_dir_string (void);
3342 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3344 /* enum for tracking thread-local variables whose address is really an offset
3345 relative to the TLS pointer, which will need link-time relocation, but will
3346 not need relocation by the DWARF consumer. */
3354 /* Return the operator to use for an address of a variable. For dtprel_true, we
3355 use DW_OP_const*. For regular variables, which need both link-time
3356 relocation and consumer-level relocation (e.g., to account for shared objects
3357 loaded at a random address), we use DW_OP_addr*. */
3359 static inline enum dwarf_location_atom
3360 dw_addr_op (enum dtprel_bool dtprel
)
3362 if (dtprel
== dtprel_true
)
3363 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3364 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3366 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3369 /* Return a pointer to a newly allocated address location description. If
3370 dwarf_split_debug_info is true, then record the address with the appropriate
3372 static inline dw_loc_descr_ref
3373 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3375 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3377 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3378 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3379 ref
->dtprel
= dtprel
;
3380 if (dwarf_split_debug_info
)
3381 ref
->dw_loc_oprnd1
.val_entry
3382 = add_addr_table_entry (addr
,
3383 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3385 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3390 /* Section names used to hold DWARF debugging information. */
3392 #ifndef DEBUG_INFO_SECTION
3393 #define DEBUG_INFO_SECTION ".debug_info"
3395 #ifndef DEBUG_DWO_INFO_SECTION
3396 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3398 #ifndef DEBUG_ABBREV_SECTION
3399 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3401 #ifndef DEBUG_DWO_ABBREV_SECTION
3402 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3404 #ifndef DEBUG_ARANGES_SECTION
3405 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3407 #ifndef DEBUG_ADDR_SECTION
3408 #define DEBUG_ADDR_SECTION ".debug_addr"
3410 #ifndef DEBUG_NORM_MACINFO_SECTION
3411 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3413 #ifndef DEBUG_DWO_MACINFO_SECTION
3414 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3416 #ifndef DEBUG_MACINFO_SECTION
3417 #define DEBUG_MACINFO_SECTION \
3418 (!dwarf_split_debug_info \
3419 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3421 #ifndef DEBUG_NORM_MACRO_SECTION
3422 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3424 #ifndef DEBUG_DWO_MACRO_SECTION
3425 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3427 #ifndef DEBUG_MACRO_SECTION
3428 #define DEBUG_MACRO_SECTION \
3429 (!dwarf_split_debug_info \
3430 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3432 #ifndef DEBUG_LINE_SECTION
3433 #define DEBUG_LINE_SECTION ".debug_line"
3435 #ifndef DEBUG_DWO_LINE_SECTION
3436 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3438 #ifndef DEBUG_LOC_SECTION
3439 #define DEBUG_LOC_SECTION ".debug_loc"
3441 #ifndef DEBUG_DWO_LOC_SECTION
3442 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3444 #ifndef DEBUG_PUBNAMES_SECTION
3445 #define DEBUG_PUBNAMES_SECTION \
3446 ((debug_generate_pub_sections == 2) \
3447 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3449 #ifndef DEBUG_PUBTYPES_SECTION
3450 #define DEBUG_PUBTYPES_SECTION \
3451 ((debug_generate_pub_sections == 2) \
3452 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3454 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3455 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3456 #ifndef DEBUG_STR_OFFSETS_SECTION
3457 #define DEBUG_STR_OFFSETS_SECTION \
3458 (!dwarf_split_debug_info \
3459 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3461 #ifndef DEBUG_STR_DWO_SECTION
3462 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3464 #ifndef DEBUG_STR_SECTION
3465 #define DEBUG_STR_SECTION ".debug_str"
3467 #ifndef DEBUG_RANGES_SECTION
3468 #define DEBUG_RANGES_SECTION ".debug_ranges"
3471 /* Standard ELF section names for compiled code and data. */
3472 #ifndef TEXT_SECTION_NAME
3473 #define TEXT_SECTION_NAME ".text"
3476 /* Section flags for .debug_macinfo/.debug_macro section. */
3477 #define DEBUG_MACRO_SECTION_FLAGS \
3478 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3480 /* Section flags for .debug_str section. */
3481 #define DEBUG_STR_SECTION_FLAGS \
3482 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3483 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3486 /* Section flags for .debug_str.dwo section. */
3487 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3489 /* Labels we insert at beginning sections we can reference instead of
3490 the section names themselves. */
3492 #ifndef TEXT_SECTION_LABEL
3493 #define TEXT_SECTION_LABEL "Ltext"
3495 #ifndef COLD_TEXT_SECTION_LABEL
3496 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3498 #ifndef DEBUG_LINE_SECTION_LABEL
3499 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3501 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3502 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3504 #ifndef DEBUG_INFO_SECTION_LABEL
3505 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3507 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3508 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3510 #ifndef DEBUG_ABBREV_SECTION_LABEL
3511 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3513 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3514 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3516 #ifndef DEBUG_ADDR_SECTION_LABEL
3517 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3519 #ifndef DEBUG_LOC_SECTION_LABEL
3520 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3522 #ifndef DEBUG_RANGES_SECTION_LABEL
3523 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3525 #ifndef DEBUG_MACINFO_SECTION_LABEL
3526 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3528 #ifndef DEBUG_MACRO_SECTION_LABEL
3529 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3531 #define SKELETON_COMP_DIE_ABBREV 1
3532 #define SKELETON_TYPE_DIE_ABBREV 2
3534 /* Definitions of defaults for formats and names of various special
3535 (artificial) labels which may be generated within this file (when the -g
3536 options is used and DWARF2_DEBUGGING_INFO is in effect.
3537 If necessary, these may be overridden from within the tm.h file, but
3538 typically, overriding these defaults is unnecessary. */
3540 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3541 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3542 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3543 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3544 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3545 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3546 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3547 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3548 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3549 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3550 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3551 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3552 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3553 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3555 #ifndef TEXT_END_LABEL
3556 #define TEXT_END_LABEL "Letext"
3558 #ifndef COLD_END_LABEL
3559 #define COLD_END_LABEL "Letext_cold"
3561 #ifndef BLOCK_BEGIN_LABEL
3562 #define BLOCK_BEGIN_LABEL "LBB"
3564 #ifndef BLOCK_END_LABEL
3565 #define BLOCK_END_LABEL "LBE"
3567 #ifndef LINE_CODE_LABEL
3568 #define LINE_CODE_LABEL "LM"
3572 /* Return the root of the DIE's built for the current compilation unit. */
3574 comp_unit_die (void)
3576 if (!single_comp_unit_die
)
3577 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3578 return single_comp_unit_die
;
3581 /* We allow a language front-end to designate a function that is to be
3582 called to "demangle" any name before it is put into a DIE. */
3584 static const char *(*demangle_name_func
) (const char *);
3587 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3589 demangle_name_func
= func
;
3592 /* Test if rtl node points to a pseudo register. */
3595 is_pseudo_reg (const_rtx rtl
)
3597 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3598 || (GET_CODE (rtl
) == SUBREG
3599 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3602 /* Return a reference to a type, with its const and volatile qualifiers
3606 type_main_variant (tree type
)
3608 type
= TYPE_MAIN_VARIANT (type
);
3610 /* ??? There really should be only one main variant among any group of
3611 variants of a given type (and all of the MAIN_VARIANT values for all
3612 members of the group should point to that one type) but sometimes the C
3613 front-end messes this up for array types, so we work around that bug
3615 if (TREE_CODE (type
) == ARRAY_TYPE
)
3616 while (type
!= TYPE_MAIN_VARIANT (type
))
3617 type
= TYPE_MAIN_VARIANT (type
);
3622 /* Return nonzero if the given type node represents a tagged type. */
3625 is_tagged_type (const_tree type
)
3627 enum tree_code code
= TREE_CODE (type
);
3629 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3630 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3633 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3636 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3638 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3641 /* Return die_offset of a DIE reference to a base type. */
3643 static unsigned long int
3644 get_base_type_offset (dw_die_ref ref
)
3646 if (ref
->die_offset
)
3647 return ref
->die_offset
;
3648 if (comp_unit_die ()->die_abbrev
)
3650 calc_base_type_die_sizes ();
3651 gcc_assert (ref
->die_offset
);
3653 return ref
->die_offset
;
3656 /* Return die_offset of a DIE reference other than base type. */
3658 static unsigned long int
3659 get_ref_die_offset (dw_die_ref ref
)
3661 gcc_assert (ref
->die_offset
);
3662 return ref
->die_offset
;
3665 /* Convert a DIE tag into its string name. */
3668 dwarf_tag_name (unsigned int tag
)
3670 const char *name
= get_DW_TAG_name (tag
);
3675 return "DW_TAG_<unknown>";
3678 /* Convert a DWARF attribute code into its string name. */
3681 dwarf_attr_name (unsigned int attr
)
3687 #if VMS_DEBUGGING_INFO
3688 case DW_AT_HP_prologue
:
3689 return "DW_AT_HP_prologue";
3691 case DW_AT_MIPS_loop_unroll_factor
:
3692 return "DW_AT_MIPS_loop_unroll_factor";
3695 #if VMS_DEBUGGING_INFO
3696 case DW_AT_HP_epilogue
:
3697 return "DW_AT_HP_epilogue";
3699 case DW_AT_MIPS_stride
:
3700 return "DW_AT_MIPS_stride";
3704 name
= get_DW_AT_name (attr
);
3709 return "DW_AT_<unknown>";
3712 /* Convert a DWARF value form code into its string name. */
3715 dwarf_form_name (unsigned int form
)
3717 const char *name
= get_DW_FORM_name (form
);
3722 return "DW_FORM_<unknown>";
3725 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3726 instance of an inlined instance of a decl which is local to an inline
3727 function, so we have to trace all of the way back through the origin chain
3728 to find out what sort of node actually served as the original seed for the
3732 decl_ultimate_origin (const_tree decl
)
3734 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3737 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3738 we're trying to output the abstract instance of this function. */
3739 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3742 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3743 most distant ancestor, this should never happen. */
3744 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3746 return DECL_ABSTRACT_ORIGIN (decl
);
3749 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3750 of a virtual function may refer to a base class, so we check the 'this'
3754 decl_class_context (tree decl
)
3756 tree context
= NULL_TREE
;
3758 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3759 context
= DECL_CONTEXT (decl
);
3761 context
= TYPE_MAIN_VARIANT
3762 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3764 if (context
&& !TYPE_P (context
))
3765 context
= NULL_TREE
;
3770 /* Add an attribute/value pair to a DIE. */
3773 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3775 /* Maybe this should be an assert? */
3779 vec_safe_reserve (die
->die_attr
, 1);
3780 vec_safe_push (die
->die_attr
, *attr
);
3783 static inline enum dw_val_class
3784 AT_class (dw_attr_ref a
)
3786 return a
->dw_attr_val
.val_class
;
3789 /* Return the index for any attribute that will be referenced with a
3790 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3791 are stored in dw_attr_val.v.val_str for reference counting
3794 static inline unsigned int
3795 AT_index (dw_attr_ref a
)
3797 if (AT_class (a
) == dw_val_class_str
)
3798 return a
->dw_attr_val
.v
.val_str
->index
;
3799 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3800 return a
->dw_attr_val
.val_entry
->index
;
3804 /* Add a flag value attribute to a DIE. */
3807 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3811 attr
.dw_attr
= attr_kind
;
3812 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3813 attr
.dw_attr_val
.val_entry
= NULL
;
3814 attr
.dw_attr_val
.v
.val_flag
= flag
;
3815 add_dwarf_attr (die
, &attr
);
3818 static inline unsigned
3819 AT_flag (dw_attr_ref a
)
3821 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3822 return a
->dw_attr_val
.v
.val_flag
;
3825 /* Add a signed integer attribute value to a DIE. */
3828 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3832 attr
.dw_attr
= attr_kind
;
3833 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3834 attr
.dw_attr_val
.val_entry
= NULL
;
3835 attr
.dw_attr_val
.v
.val_int
= int_val
;
3836 add_dwarf_attr (die
, &attr
);
3839 static inline HOST_WIDE_INT
3840 AT_int (dw_attr_ref a
)
3842 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3843 return a
->dw_attr_val
.v
.val_int
;
3846 /* Add an unsigned integer attribute value to a DIE. */
3849 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3850 unsigned HOST_WIDE_INT unsigned_val
)
3854 attr
.dw_attr
= attr_kind
;
3855 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3856 attr
.dw_attr_val
.val_entry
= NULL
;
3857 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3858 add_dwarf_attr (die
, &attr
);
3861 static inline unsigned HOST_WIDE_INT
3862 AT_unsigned (dw_attr_ref a
)
3864 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3865 return a
->dw_attr_val
.v
.val_unsigned
;
3868 /* Add an unsigned wide integer attribute value to a DIE. */
3871 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3876 attr
.dw_attr
= attr_kind
;
3877 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3878 attr
.dw_attr_val
.val_entry
= NULL
;
3879 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3880 *attr
.dw_attr_val
.v
.val_wide
= w
;
3881 add_dwarf_attr (die
, &attr
);
3884 /* Add an unsigned double integer attribute value to a DIE. */
3887 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3888 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3892 attr
.dw_attr
= attr_kind
;
3893 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3894 attr
.dw_attr_val
.val_entry
= NULL
;
3895 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3896 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3897 add_dwarf_attr (die
, &attr
);
3900 /* Add a floating point attribute value to a DIE and return it. */
3903 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3904 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3908 attr
.dw_attr
= attr_kind
;
3909 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3910 attr
.dw_attr_val
.val_entry
= NULL
;
3911 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3912 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3913 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3914 add_dwarf_attr (die
, &attr
);
3917 /* Add an 8-byte data attribute value to a DIE. */
3920 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3921 unsigned char data8
[8])
3925 attr
.dw_attr
= attr_kind
;
3926 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3927 attr
.dw_attr_val
.val_entry
= NULL
;
3928 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3929 add_dwarf_attr (die
, &attr
);
3932 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3933 dwarf_split_debug_info, address attributes in dies destined for the
3934 final executable have force_direct set to avoid using indexed
3938 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3944 lbl_id
= xstrdup (lbl_low
);
3945 attr
.dw_attr
= DW_AT_low_pc
;
3946 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3947 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3948 if (dwarf_split_debug_info
&& !force_direct
)
3949 attr
.dw_attr_val
.val_entry
3950 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3952 attr
.dw_attr_val
.val_entry
= NULL
;
3953 add_dwarf_attr (die
, &attr
);
3955 attr
.dw_attr
= DW_AT_high_pc
;
3956 if (dwarf_version
< 4)
3957 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3959 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3960 lbl_id
= xstrdup (lbl_high
);
3961 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3962 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3963 && dwarf_split_debug_info
&& !force_direct
)
3964 attr
.dw_attr_val
.val_entry
3965 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3967 attr
.dw_attr_val
.val_entry
= NULL
;
3968 add_dwarf_attr (die
, &attr
);
3971 /* Hash and equality functions for debug_str_hash. */
3974 indirect_string_hasher::hash (indirect_string_node
*x
)
3976 return htab_hash_string (x
->str
);
3980 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
3982 return strcmp (x1
->str
, x2
) == 0;
3985 /* Add STR to the given string hash table. */
3987 static struct indirect_string_node
*
3988 find_AT_string_in_table (const char *str
,
3989 hash_table
<indirect_string_hasher
> *table
)
3991 struct indirect_string_node
*node
;
3993 indirect_string_node
**slot
3994 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
3997 node
= ggc_cleared_alloc
<indirect_string_node
> ();
3998 node
->str
= ggc_strdup (str
);
4008 /* Add STR to the indirect string hash table. */
4010 static struct indirect_string_node
*
4011 find_AT_string (const char *str
)
4013 if (! debug_str_hash
)
4014 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4016 return find_AT_string_in_table (str
, debug_str_hash
);
4019 /* Add a string attribute value to a DIE. */
4022 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4025 struct indirect_string_node
*node
;
4027 node
= find_AT_string (str
);
4029 attr
.dw_attr
= attr_kind
;
4030 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4031 attr
.dw_attr_val
.val_entry
= NULL
;
4032 attr
.dw_attr_val
.v
.val_str
= node
;
4033 add_dwarf_attr (die
, &attr
);
4036 static inline const char *
4037 AT_string (dw_attr_ref a
)
4039 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4040 return a
->dw_attr_val
.v
.val_str
->str
;
4043 /* Call this function directly to bypass AT_string_form's logic to put
4044 the string inline in the die. */
4047 set_indirect_string (struct indirect_string_node
*node
)
4050 /* Already indirect is a no op. */
4051 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4053 gcc_assert (node
->label
);
4056 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4057 ++dw2_string_counter
;
4058 node
->label
= xstrdup (label
);
4060 if (!dwarf_split_debug_info
)
4062 node
->form
= DW_FORM_strp
;
4063 node
->index
= NOT_INDEXED
;
4067 node
->form
= DW_FORM_GNU_str_index
;
4068 node
->index
= NO_INDEX_ASSIGNED
;
4072 /* Find out whether a string should be output inline in DIE
4073 or out-of-line in .debug_str section. */
4075 static enum dwarf_form
4076 find_string_form (struct indirect_string_node
*node
)
4083 len
= strlen (node
->str
) + 1;
4085 /* If the string is shorter or equal to the size of the reference, it is
4086 always better to put it inline. */
4087 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4088 return node
->form
= DW_FORM_string
;
4090 /* If we cannot expect the linker to merge strings in .debug_str
4091 section, only put it into .debug_str if it is worth even in this
4093 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4094 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4095 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4096 return node
->form
= DW_FORM_string
;
4098 set_indirect_string (node
);
4103 /* Find out whether the string referenced from the attribute should be
4104 output inline in DIE or out-of-line in .debug_str section. */
4106 static enum dwarf_form
4107 AT_string_form (dw_attr_ref a
)
4109 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4110 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4113 /* Add a DIE reference attribute value to a DIE. */
4116 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4120 #ifdef ENABLE_CHECKING
4121 gcc_assert (targ_die
!= NULL
);
4123 /* With LTO we can end up trying to reference something we didn't create
4124 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4125 if (targ_die
== NULL
)
4129 attr
.dw_attr
= attr_kind
;
4130 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4131 attr
.dw_attr_val
.val_entry
= NULL
;
4132 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4133 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4134 add_dwarf_attr (die
, &attr
);
4137 /* Change DIE reference REF to point to NEW_DIE instead. */
4140 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4142 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4143 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4144 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4147 /* Add an AT_specification attribute to a DIE, and also make the back
4148 pointer from the specification to the definition. */
4151 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4153 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4154 gcc_assert (!targ_die
->die_definition
);
4155 targ_die
->die_definition
= die
;
4158 static inline dw_die_ref
4159 AT_ref (dw_attr_ref a
)
4161 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4162 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4166 AT_ref_external (dw_attr_ref a
)
4168 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4169 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4175 set_AT_ref_external (dw_attr_ref a
, int i
)
4177 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4178 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4181 /* Add an FDE reference attribute value to a DIE. */
4184 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4188 attr
.dw_attr
= attr_kind
;
4189 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4190 attr
.dw_attr_val
.val_entry
= NULL
;
4191 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4192 add_dwarf_attr (die
, &attr
);
4195 /* Add a location description attribute value to a DIE. */
4198 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4202 attr
.dw_attr
= attr_kind
;
4203 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4204 attr
.dw_attr_val
.val_entry
= NULL
;
4205 attr
.dw_attr_val
.v
.val_loc
= loc
;
4206 add_dwarf_attr (die
, &attr
);
4209 static inline dw_loc_descr_ref
4210 AT_loc (dw_attr_ref a
)
4212 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4213 return a
->dw_attr_val
.v
.val_loc
;
4217 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4221 attr
.dw_attr
= attr_kind
;
4222 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4223 attr
.dw_attr_val
.val_entry
= NULL
;
4224 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4225 add_dwarf_attr (die
, &attr
);
4226 have_location_lists
= true;
4229 static inline dw_loc_list_ref
4230 AT_loc_list (dw_attr_ref a
)
4232 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4233 return a
->dw_attr_val
.v
.val_loc_list
;
4236 static inline dw_loc_list_ref
*
4237 AT_loc_list_ptr (dw_attr_ref a
)
4239 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4240 return &a
->dw_attr_val
.v
.val_loc_list
;
4243 struct addr_hasher
: ggc_hasher
<addr_table_entry
*>
4245 static hashval_t
hash (addr_table_entry
*);
4246 static bool equal (addr_table_entry
*, addr_table_entry
*);
4249 /* Table of entries into the .debug_addr section. */
4251 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4253 /* Hash an address_table_entry. */
4256 addr_hasher::hash (addr_table_entry
*a
)
4258 inchash::hash hstate
;
4264 case ate_kind_rtx_dtprel
:
4267 case ate_kind_label
:
4268 return htab_hash_string (a
->addr
.label
);
4272 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4273 return hstate
.end ();
4276 /* Determine equality for two address_table_entries. */
4279 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4281 if (a1
->kind
!= a2
->kind
)
4286 case ate_kind_rtx_dtprel
:
4287 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4288 case ate_kind_label
:
4289 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4295 /* Initialize an addr_table_entry. */
4298 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4304 case ate_kind_rtx_dtprel
:
4305 e
->addr
.rtl
= (rtx
) addr
;
4307 case ate_kind_label
:
4308 e
->addr
.label
= (char *) addr
;
4312 e
->index
= NO_INDEX_ASSIGNED
;
4315 /* Add attr to the address table entry to the table. Defer setting an
4316 index until output time. */
4318 static addr_table_entry
*
4319 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4321 addr_table_entry
*node
;
4322 addr_table_entry finder
;
4324 gcc_assert (dwarf_split_debug_info
);
4325 if (! addr_index_table
)
4326 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4327 init_addr_table_entry (&finder
, kind
, addr
);
4328 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4330 if (*slot
== HTAB_EMPTY_ENTRY
)
4332 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4333 init_addr_table_entry (node
, kind
, addr
);
4343 /* Remove an entry from the addr table by decrementing its refcount.
4344 Strictly, decrementing the refcount would be enough, but the
4345 assertion that the entry is actually in the table has found
4349 remove_addr_table_entry (addr_table_entry
*entry
)
4351 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4352 /* After an index is assigned, the table is frozen. */
4353 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4357 /* Given a location list, remove all addresses it refers to from the
4361 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4363 for (; descr
; descr
= descr
->dw_loc_next
)
4364 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4366 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4367 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4371 /* A helper function for dwarf2out_finish called through
4372 htab_traverse. Assign an addr_table_entry its index. All entries
4373 must be collected into the table when this function is called,
4374 because the indexing code relies on htab_traverse to traverse nodes
4375 in the same order for each run. */
4378 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4380 addr_table_entry
*node
= *h
;
4382 /* Don't index unreferenced nodes. */
4383 if (node
->refcount
== 0)
4386 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4387 node
->index
= *index
;
4393 /* Add an address constant attribute value to a DIE. When using
4394 dwarf_split_debug_info, address attributes in dies destined for the
4395 final executable should be direct references--setting the parameter
4396 force_direct ensures this behavior. */
4399 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4404 attr
.dw_attr
= attr_kind
;
4405 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4406 attr
.dw_attr_val
.v
.val_addr
= addr
;
4407 if (dwarf_split_debug_info
&& !force_direct
)
4408 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4410 attr
.dw_attr_val
.val_entry
= NULL
;
4411 add_dwarf_attr (die
, &attr
);
4414 /* Get the RTX from to an address DIE attribute. */
4417 AT_addr (dw_attr_ref a
)
4419 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4420 return a
->dw_attr_val
.v
.val_addr
;
4423 /* Add a file attribute value to a DIE. */
4426 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4427 struct dwarf_file_data
*fd
)
4431 attr
.dw_attr
= attr_kind
;
4432 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4433 attr
.dw_attr_val
.val_entry
= NULL
;
4434 attr
.dw_attr_val
.v
.val_file
= fd
;
4435 add_dwarf_attr (die
, &attr
);
4438 /* Get the dwarf_file_data from a file DIE attribute. */
4440 static inline struct dwarf_file_data
*
4441 AT_file (dw_attr_ref a
)
4443 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4444 return a
->dw_attr_val
.v
.val_file
;
4447 /* Add a vms delta attribute value to a DIE. */
4450 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4451 const char *lbl1
, const char *lbl2
)
4455 attr
.dw_attr
= attr_kind
;
4456 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4457 attr
.dw_attr_val
.val_entry
= NULL
;
4458 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4459 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4460 add_dwarf_attr (die
, &attr
);
4463 /* Add a label identifier attribute value to a DIE. */
4466 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4471 attr
.dw_attr
= attr_kind
;
4472 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4473 attr
.dw_attr_val
.val_entry
= NULL
;
4474 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4475 if (dwarf_split_debug_info
)
4476 attr
.dw_attr_val
.val_entry
4477 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4479 add_dwarf_attr (die
, &attr
);
4482 /* Add a section offset attribute value to a DIE, an offset into the
4483 debug_line section. */
4486 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4491 attr
.dw_attr
= attr_kind
;
4492 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4493 attr
.dw_attr_val
.val_entry
= NULL
;
4494 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4495 add_dwarf_attr (die
, &attr
);
4498 /* Add a section offset attribute value to a DIE, an offset into the
4499 debug_macinfo section. */
4502 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4507 attr
.dw_attr
= attr_kind
;
4508 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4509 attr
.dw_attr_val
.val_entry
= NULL
;
4510 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4511 add_dwarf_attr (die
, &attr
);
4514 /* Add an offset attribute value to a DIE. */
4517 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4518 unsigned HOST_WIDE_INT offset
)
4522 attr
.dw_attr
= attr_kind
;
4523 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4524 attr
.dw_attr_val
.val_entry
= NULL
;
4525 attr
.dw_attr_val
.v
.val_offset
= offset
;
4526 add_dwarf_attr (die
, &attr
);
4529 /* Add a range_list attribute value to a DIE. When using
4530 dwarf_split_debug_info, address attributes in dies destined for the
4531 final executable should be direct references--setting the parameter
4532 force_direct ensures this behavior. */
4534 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4535 #define RELOCATED_OFFSET (NULL)
4538 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4539 long unsigned int offset
, bool force_direct
)
4543 attr
.dw_attr
= attr_kind
;
4544 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4545 /* For the range_list attribute, use val_entry to store whether the
4546 offset should follow split-debug-info or normal semantics. This
4547 value is read in output_range_list_offset. */
4548 if (dwarf_split_debug_info
&& !force_direct
)
4549 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4551 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4552 attr
.dw_attr_val
.v
.val_offset
= offset
;
4553 add_dwarf_attr (die
, &attr
);
4556 /* Return the start label of a delta attribute. */
4558 static inline const char *
4559 AT_vms_delta1 (dw_attr_ref a
)
4561 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4562 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4565 /* Return the end label of a delta attribute. */
4567 static inline const char *
4568 AT_vms_delta2 (dw_attr_ref a
)
4570 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4571 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4574 static inline const char *
4575 AT_lbl (dw_attr_ref a
)
4577 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4578 || AT_class (a
) == dw_val_class_lineptr
4579 || AT_class (a
) == dw_val_class_macptr
4580 || AT_class (a
) == dw_val_class_high_pc
));
4581 return a
->dw_attr_val
.v
.val_lbl_id
;
4584 /* Get the attribute of type attr_kind. */
4587 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4591 dw_die_ref spec
= NULL
;
4596 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4597 if (a
->dw_attr
== attr_kind
)
4599 else if (a
->dw_attr
== DW_AT_specification
4600 || a
->dw_attr
== DW_AT_abstract_origin
)
4604 return get_AT (spec
, attr_kind
);
4609 /* Returns the parent of the declaration of DIE. */
4612 get_die_parent (dw_die_ref die
)
4619 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4620 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4623 return die
->die_parent
;
4626 /* Return the "low pc" attribute value, typically associated with a subprogram
4627 DIE. Return null if the "low pc" attribute is either not present, or if it
4628 cannot be represented as an assembler label identifier. */
4630 static inline const char *
4631 get_AT_low_pc (dw_die_ref die
)
4633 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4635 return a
? AT_lbl (a
) : NULL
;
4638 /* Return the "high pc" attribute value, typically associated with a subprogram
4639 DIE. Return null if the "high pc" attribute is either not present, or if it
4640 cannot be represented as an assembler label identifier. */
4642 static inline const char *
4643 get_AT_hi_pc (dw_die_ref die
)
4645 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4647 return a
? AT_lbl (a
) : NULL
;
4650 /* Return the value of the string attribute designated by ATTR_KIND, or
4651 NULL if it is not present. */
4653 static inline const char *
4654 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4656 dw_attr_ref a
= get_AT (die
, attr_kind
);
4658 return a
? AT_string (a
) : NULL
;
4661 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4662 if it is not present. */
4665 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4667 dw_attr_ref a
= get_AT (die
, attr_kind
);
4669 return a
? AT_flag (a
) : 0;
4672 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4673 if it is not present. */
4675 static inline unsigned
4676 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4678 dw_attr_ref a
= get_AT (die
, attr_kind
);
4680 return a
? AT_unsigned (a
) : 0;
4683 static inline dw_die_ref
4684 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4686 dw_attr_ref a
= get_AT (die
, attr_kind
);
4688 return a
? AT_ref (a
) : NULL
;
4691 static inline struct dwarf_file_data
*
4692 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4694 dw_attr_ref a
= get_AT (die
, attr_kind
);
4696 return a
? AT_file (a
) : NULL
;
4699 /* Return TRUE if the language is C++. */
4704 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4706 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4707 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4710 /* Return TRUE if the language is Java. */
4715 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4717 return lang
== DW_LANG_Java
;
4720 /* Return TRUE if the language is Fortran. */
4725 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4727 return (lang
== DW_LANG_Fortran77
4728 || lang
== DW_LANG_Fortran90
4729 || lang
== DW_LANG_Fortran95
4730 || lang
== DW_LANG_Fortran03
4731 || lang
== DW_LANG_Fortran08
);
4734 /* Return TRUE if the language is Ada. */
4739 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4741 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4744 /* Remove the specified attribute if present. Return TRUE if removal
4748 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4756 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4757 if (a
->dw_attr
== attr_kind
)
4759 if (AT_class (a
) == dw_val_class_str
)
4760 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4761 a
->dw_attr_val
.v
.val_str
->refcount
--;
4763 /* vec::ordered_remove should help reduce the number of abbrevs
4765 die
->die_attr
->ordered_remove (ix
);
4771 /* Remove CHILD from its parent. PREV must have the property that
4772 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4775 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4777 gcc_assert (child
->die_parent
== prev
->die_parent
);
4778 gcc_assert (prev
->die_sib
== child
);
4781 gcc_assert (child
->die_parent
->die_child
== child
);
4785 prev
->die_sib
= child
->die_sib
;
4786 if (child
->die_parent
->die_child
== child
)
4787 child
->die_parent
->die_child
= prev
;
4790 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4791 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4794 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4796 dw_die_ref parent
= old_child
->die_parent
;
4798 gcc_assert (parent
== prev
->die_parent
);
4799 gcc_assert (prev
->die_sib
== old_child
);
4801 new_child
->die_parent
= parent
;
4802 if (prev
== old_child
)
4804 gcc_assert (parent
->die_child
== old_child
);
4805 new_child
->die_sib
= new_child
;
4809 prev
->die_sib
= new_child
;
4810 new_child
->die_sib
= old_child
->die_sib
;
4812 if (old_child
->die_parent
->die_child
== old_child
)
4813 old_child
->die_parent
->die_child
= new_child
;
4816 /* Move all children from OLD_PARENT to NEW_PARENT. */
4819 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4822 new_parent
->die_child
= old_parent
->die_child
;
4823 old_parent
->die_child
= NULL
;
4824 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4827 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4831 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4837 dw_die_ref prev
= c
;
4839 while (c
->die_tag
== tag
)
4841 remove_child_with_prev (c
, prev
);
4842 c
->die_parent
= NULL
;
4843 /* Might have removed every child. */
4844 if (c
== c
->die_sib
)
4848 } while (c
!= die
->die_child
);
4851 /* Add a CHILD_DIE as the last child of DIE. */
4854 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4856 /* FIXME this should probably be an assert. */
4857 if (! die
|| ! child_die
)
4859 gcc_assert (die
!= child_die
);
4861 child_die
->die_parent
= die
;
4864 child_die
->die_sib
= die
->die_child
->die_sib
;
4865 die
->die_child
->die_sib
= child_die
;
4868 child_die
->die_sib
= child_die
;
4869 die
->die_child
= child_die
;
4872 /* Unassociate CHILD from its parent, and make its parent be
4876 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
4878 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4879 if (p
->die_sib
== child
)
4881 remove_child_with_prev (child
, p
);
4884 add_child_die (new_parent
, child
);
4887 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4888 is the specification, to the end of PARENT's list of children.
4889 This is done by removing and re-adding it. */
4892 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4894 /* We want the declaration DIE from inside the class, not the
4895 specification DIE at toplevel. */
4896 if (child
->die_parent
!= parent
)
4898 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4904 gcc_assert (child
->die_parent
== parent
4905 || (child
->die_parent
4906 == get_AT_ref (parent
, DW_AT_specification
)));
4908 reparent_child (child
, parent
);
4911 /* Create and return a new die with a parent of PARENT_DIE. If
4912 PARENT_DIE is NULL, the new DIE is placed in limbo and an
4913 associated tree T must be supplied to determine parenthood
4916 static inline dw_die_ref
4917 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4919 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
4921 die
->die_tag
= tag_value
;
4923 if (parent_die
!= NULL
)
4924 add_child_die (parent_die
, die
);
4927 limbo_die_node
*limbo_node
;
4929 /* No DIEs created after early dwarf should end up in limbo,
4930 because the limbo list should not persist past LTO
4932 if (tag_value
!= DW_TAG_compile_unit
4933 /* These are allowed because they're generated while
4934 breaking out COMDAT units late. */
4935 && tag_value
!= DW_TAG_type_unit
4937 /* Allow nested functions to live in limbo because they will
4938 only temporarily live there, as decls_for_scope will fix
4940 && (TREE_CODE (t
) != FUNCTION_DECL
4941 || !decl_function_context (t
))
4942 /* Same as nested functions above but for types. Types that
4943 are local to a function will be fixed in
4945 && (!RECORD_OR_UNION_TYPE_P (t
)
4946 || !TYPE_CONTEXT (t
)
4947 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
4948 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
4949 especially in the ltrans stage, but once we implement LTO
4950 dwarf streaming, we should remove this exception. */
4953 fprintf (stderr
, "symbol ended up in limbo too late:");
4954 debug_generic_stmt (t
);
4958 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
4959 limbo_node
->die
= die
;
4960 limbo_node
->created_for
= t
;
4961 limbo_node
->next
= limbo_die_list
;
4962 limbo_die_list
= limbo_node
;
4968 /* Return the DIE associated with the given type specifier. */
4970 static inline dw_die_ref
4971 lookup_type_die (tree type
)
4973 return TYPE_SYMTAB_DIE (type
);
4976 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4977 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4978 anonymous type instead the one of the naming typedef. */
4980 static inline dw_die_ref
4981 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4984 && TREE_CODE (type
) == RECORD_TYPE
4986 && type_die
->die_tag
== DW_TAG_typedef
4987 && is_naming_typedef_decl (TYPE_NAME (type
)))
4988 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4992 /* Like lookup_type_die, but if type is an anonymous type named by a
4993 typedef[1], return the DIE of the anonymous type instead the one of
4994 the naming typedef. This is because in gen_typedef_die, we did
4995 equate the anonymous struct named by the typedef with the DIE of
4996 the naming typedef. So by default, lookup_type_die on an anonymous
4997 struct yields the DIE of the naming typedef.
4999 [1]: Read the comment of is_naming_typedef_decl to learn about what
5000 a naming typedef is. */
5002 static inline dw_die_ref
5003 lookup_type_die_strip_naming_typedef (tree type
)
5005 dw_die_ref die
= lookup_type_die (type
);
5006 return strip_naming_typedef (type
, die
);
5009 /* Equate a DIE to a given type specifier. */
5012 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5014 TYPE_SYMTAB_DIE (type
) = type_die
;
5017 /* Returns a hash value for X (which really is a die_struct). */
5020 decl_die_hasher::hash (die_node
*x
)
5022 return (hashval_t
) x
->decl_id
;
5025 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5028 decl_die_hasher::equal (die_node
*x
, tree y
)
5030 return (x
->decl_id
== DECL_UID (y
));
5033 /* Return the DIE associated with a given declaration. */
5035 static inline dw_die_ref
5036 lookup_decl_die (tree decl
)
5038 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5041 /* Returns a hash value for X (which really is a var_loc_list). */
5044 decl_loc_hasher::hash (var_loc_list
*x
)
5046 return (hashval_t
) x
->decl_id
;
5049 /* Return nonzero if decl_id of var_loc_list X is the same as
5053 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5055 return (x
->decl_id
== DECL_UID (y
));
5058 /* Return the var_loc list associated with a given declaration. */
5060 static inline var_loc_list
*
5061 lookup_decl_loc (const_tree decl
)
5063 if (!decl_loc_table
)
5065 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5068 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5071 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5073 return (hashval_t
) x
->decl_id
;
5076 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5080 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5082 return (x
->decl_id
== DECL_UID (y
));
5085 /* Equate a DIE to a particular declaration. */
5088 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5090 unsigned int decl_id
= DECL_UID (decl
);
5092 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5093 decl_die
->decl_id
= decl_id
;
5096 /* Return how many bits covers PIECE EXPR_LIST. */
5098 static HOST_WIDE_INT
5099 decl_piece_bitsize (rtx piece
)
5101 int ret
= (int) GET_MODE (piece
);
5104 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5105 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5106 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5109 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5112 decl_piece_varloc_ptr (rtx piece
)
5114 if ((int) GET_MODE (piece
))
5115 return &XEXP (piece
, 0);
5117 return &XEXP (XEXP (piece
, 0), 1);
5120 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5121 Next is the chain of following piece nodes. */
5123 static rtx_expr_list
*
5124 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5126 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5127 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5129 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5134 /* Return rtx that should be stored into loc field for
5135 LOC_NOTE and BITPOS/BITSIZE. */
5138 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5139 HOST_WIDE_INT bitsize
)
5143 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5145 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5150 /* This function either modifies location piece list *DEST in
5151 place (if SRC and INNER is NULL), or copies location piece list
5152 *SRC to *DEST while modifying it. Location BITPOS is modified
5153 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5154 not copied and if needed some padding around it is added.
5155 When modifying in place, DEST should point to EXPR_LIST where
5156 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5157 to the start of the whole list and INNER points to the EXPR_LIST
5158 where earlier pieces cover PIECE_BITPOS bits. */
5161 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5162 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5163 HOST_WIDE_INT bitsize
, rtx loc_note
)
5166 bool copy
= inner
!= NULL
;
5170 /* First copy all nodes preceding the current bitpos. */
5171 while (src
!= inner
)
5173 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5174 decl_piece_bitsize (*src
), NULL_RTX
);
5175 dest
= &XEXP (*dest
, 1);
5176 src
= &XEXP (*src
, 1);
5179 /* Add padding if needed. */
5180 if (bitpos
!= piece_bitpos
)
5182 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5183 copy
? NULL_RTX
: *dest
);
5184 dest
= &XEXP (*dest
, 1);
5186 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5189 /* A piece with correct bitpos and bitsize already exist,
5190 just update the location for it and return. */
5191 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5194 /* Add the piece that changed. */
5195 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5196 dest
= &XEXP (*dest
, 1);
5197 /* Skip over pieces that overlap it. */
5198 diff
= bitpos
- piece_bitpos
+ bitsize
;
5201 while (diff
> 0 && *src
)
5204 diff
-= decl_piece_bitsize (piece
);
5206 src
= &XEXP (piece
, 1);
5209 *src
= XEXP (piece
, 1);
5210 free_EXPR_LIST_node (piece
);
5213 /* Add padding if needed. */
5214 if (diff
< 0 && *src
)
5218 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5219 dest
= &XEXP (*dest
, 1);
5223 /* Finally copy all nodes following it. */
5226 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5227 decl_piece_bitsize (*src
), NULL_RTX
);
5228 dest
= &XEXP (*dest
, 1);
5229 src
= &XEXP (*src
, 1);
5233 /* Add a variable location node to the linked list for DECL. */
5235 static struct var_loc_node
*
5236 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5238 unsigned int decl_id
;
5240 struct var_loc_node
*loc
= NULL
;
5241 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5243 if (TREE_CODE (decl
) == VAR_DECL
5244 && DECL_HAS_DEBUG_EXPR_P (decl
))
5246 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5247 if (handled_component_p (realdecl
)
5248 || (TREE_CODE (realdecl
) == MEM_REF
5249 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5251 HOST_WIDE_INT maxsize
;
5254 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5255 if (!DECL_P (innerdecl
)
5256 || DECL_IGNORED_P (innerdecl
)
5257 || TREE_STATIC (innerdecl
)
5259 || bitpos
+ bitsize
> 256
5260 || bitsize
!= maxsize
)
5266 decl_id
= DECL_UID (decl
);
5268 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5271 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5272 temp
->decl_id
= decl_id
;
5278 /* For PARM_DECLs try to keep around the original incoming value,
5279 even if that means we'll emit a zero-range .debug_loc entry. */
5281 && temp
->first
== temp
->last
5282 && TREE_CODE (decl
) == PARM_DECL
5283 && NOTE_P (temp
->first
->loc
)
5284 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5285 && DECL_INCOMING_RTL (decl
)
5286 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5287 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5288 == GET_CODE (DECL_INCOMING_RTL (decl
))
5289 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5291 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5292 NOTE_VAR_LOCATION_LOC (loc_note
))
5293 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5294 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5296 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5297 temp
->first
->next
= loc
;
5299 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5301 else if (temp
->last
)
5303 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5304 rtx
*piece_loc
= NULL
, last_loc_note
;
5305 HOST_WIDE_INT piece_bitpos
= 0;
5309 gcc_assert (last
->next
== NULL
);
5311 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5313 piece_loc
= &last
->loc
;
5316 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5317 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5319 piece_bitpos
+= cur_bitsize
;
5320 piece_loc
= &XEXP (*piece_loc
, 1);
5324 /* TEMP->LAST here is either pointer to the last but one or
5325 last element in the chained list, LAST is pointer to the
5327 if (label
&& strcmp (last
->label
, label
) == 0)
5329 /* For SRA optimized variables if there weren't any real
5330 insns since last note, just modify the last node. */
5331 if (piece_loc
!= NULL
)
5333 adjust_piece_list (piece_loc
, NULL
, NULL
,
5334 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5337 /* If the last note doesn't cover any instructions, remove it. */
5338 if (temp
->last
!= last
)
5340 temp
->last
->next
= NULL
;
5343 gcc_assert (strcmp (last
->label
, label
) != 0);
5347 gcc_assert (temp
->first
== temp
->last
5348 || (temp
->first
->next
== temp
->last
5349 && TREE_CODE (decl
) == PARM_DECL
));
5350 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5351 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5355 if (bitsize
== -1 && NOTE_P (last
->loc
))
5356 last_loc_note
= last
->loc
;
5357 else if (piece_loc
!= NULL
5358 && *piece_loc
!= NULL_RTX
5359 && piece_bitpos
== bitpos
5360 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5361 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5363 last_loc_note
= NULL_RTX
;
5364 /* If the current location is the same as the end of the list,
5365 and either both or neither of the locations is uninitialized,
5366 we have nothing to do. */
5367 if (last_loc_note
== NULL_RTX
5368 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5369 NOTE_VAR_LOCATION_LOC (loc_note
)))
5370 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5371 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5372 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5373 == VAR_INIT_STATUS_UNINITIALIZED
)
5374 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5375 == VAR_INIT_STATUS_UNINITIALIZED
))))
5377 /* Add LOC to the end of list and update LAST. If the last
5378 element of the list has been removed above, reuse its
5379 memory for the new node, otherwise allocate a new one. */
5383 memset (loc
, '\0', sizeof (*loc
));
5386 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5387 if (bitsize
== -1 || piece_loc
== NULL
)
5388 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5390 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5391 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5393 /* Ensure TEMP->LAST will point either to the new last but one
5394 element of the chain, or to the last element in it. */
5395 if (last
!= temp
->last
)
5403 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5406 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5411 /* Keep track of the number of spaces used to indent the
5412 output of the debugging routines that print the structure of
5413 the DIE internal representation. */
5414 static int print_indent
;
5416 /* Indent the line the number of spaces given by print_indent. */
5419 print_spaces (FILE *outfile
)
5421 fprintf (outfile
, "%*s", print_indent
, "");
5424 /* Print a type signature in hex. */
5427 print_signature (FILE *outfile
, char *sig
)
5431 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5432 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5435 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5437 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5438 RECURSE, output location descriptor operations. */
5441 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5443 switch (val
->val_class
)
5445 case dw_val_class_addr
:
5446 fprintf (outfile
, "address");
5448 case dw_val_class_offset
:
5449 fprintf (outfile
, "offset");
5451 case dw_val_class_loc
:
5452 fprintf (outfile
, "location descriptor");
5453 if (val
->v
.val_loc
== NULL
)
5454 fprintf (outfile
, " -> <null>\n");
5457 fprintf (outfile
, ":\n");
5459 print_loc_descr (val
->v
.val_loc
, outfile
);
5463 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5465 case dw_val_class_loc_list
:
5466 fprintf (outfile
, "location list -> label:%s",
5467 val
->v
.val_loc_list
->ll_symbol
);
5469 case dw_val_class_range_list
:
5470 fprintf (outfile
, "range list");
5472 case dw_val_class_const
:
5473 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5475 case dw_val_class_unsigned_const
:
5476 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5478 case dw_val_class_const_double
:
5479 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5480 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5481 val
->v
.val_double
.high
,
5482 val
->v
.val_double
.low
);
5484 case dw_val_class_wide_int
:
5486 int i
= val
->v
.val_wide
->get_len ();
5487 fprintf (outfile
, "constant (");
5489 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5490 fprintf (outfile
, "0x");
5491 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5492 val
->v
.val_wide
->elt (--i
));
5494 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5495 val
->v
.val_wide
->elt (i
));
5496 fprintf (outfile
, ")");
5499 case dw_val_class_vec
:
5500 fprintf (outfile
, "floating-point or vector constant");
5502 case dw_val_class_flag
:
5503 fprintf (outfile
, "%u", val
->v
.val_flag
);
5505 case dw_val_class_die_ref
:
5506 if (val
->v
.val_die_ref
.die
!= NULL
)
5508 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5510 if (die
->comdat_type_p
)
5512 fprintf (outfile
, "die -> signature: ");
5513 print_signature (outfile
,
5514 die
->die_id
.die_type_node
->signature
);
5516 else if (die
->die_id
.die_symbol
)
5517 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5519 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5520 fprintf (outfile
, " (%p)", (void *) die
);
5523 fprintf (outfile
, "die -> <null>");
5525 case dw_val_class_vms_delta
:
5526 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5527 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5529 case dw_val_class_lbl_id
:
5530 case dw_val_class_lineptr
:
5531 case dw_val_class_macptr
:
5532 case dw_val_class_high_pc
:
5533 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5535 case dw_val_class_str
:
5536 if (val
->v
.val_str
->str
!= NULL
)
5537 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5539 fprintf (outfile
, "<null>");
5541 case dw_val_class_file
:
5542 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5543 val
->v
.val_file
->emitted_number
);
5545 case dw_val_class_data8
:
5549 for (i
= 0; i
< 8; i
++)
5550 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5558 /* Likewise, for a DIE attribute. */
5561 print_attribute (dw_attr_ref a
, bool recurse
, FILE *outfile
)
5563 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5567 /* Print the list of operands in the LOC location description to OUTFILE. This
5568 routine is a debugging aid only. */
5571 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5573 dw_loc_descr_ref l
= loc
;
5577 print_spaces (outfile
);
5578 fprintf (outfile
, "<null>\n");
5582 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5584 print_spaces (outfile
);
5585 fprintf (outfile
, "(%p) %s",
5587 dwarf_stack_op_name (l
->dw_loc_opc
));
5588 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5590 fprintf (outfile
, " ");
5591 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5593 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5595 fprintf (outfile
, ", ");
5596 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5598 fprintf (outfile
, "\n");
5602 /* Print the information associated with a given DIE, and its children.
5603 This routine is a debugging aid only. */
5606 print_die (dw_die_ref die
, FILE *outfile
)
5612 print_spaces (outfile
);
5613 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5614 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5616 print_spaces (outfile
);
5617 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5618 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5619 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5621 if (die
->comdat_type_p
)
5623 print_spaces (outfile
);
5624 fprintf (outfile
, " signature: ");
5625 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5626 fprintf (outfile
, "\n");
5629 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5631 print_spaces (outfile
);
5632 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5634 print_attribute (a
, true, outfile
);
5635 fprintf (outfile
, "\n");
5638 if (die
->die_child
!= NULL
)
5641 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5644 if (print_indent
== 0)
5645 fprintf (outfile
, "\n");
5648 /* Print the list of operations in the LOC location description. */
5651 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5653 print_loc_descr (loc
, stderr
);
5656 /* Print the information collected for a given DIE. */
5659 debug_dwarf_die (dw_die_ref die
)
5661 print_die (die
, stderr
);
5665 debug (die_struct
&ref
)
5667 print_die (&ref
, stderr
);
5671 debug (die_struct
*ptr
)
5676 fprintf (stderr
, "<nil>\n");
5680 /* Print all DWARF information collected for the compilation unit.
5681 This routine is a debugging aid only. */
5687 print_die (comp_unit_die (), stderr
);
5690 #ifdef ENABLE_CHECKING
5691 /* Sanity checks on DIEs. */
5694 check_die (dw_die_ref die
)
5698 bool inline_found
= false;
5699 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5700 int n_decl_line
= 0, n_decl_file
= 0;
5701 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5706 if (a
->dw_attr_val
.v
.val_unsigned
)
5707 inline_found
= true;
5709 case DW_AT_location
:
5718 case DW_AT_artificial
:
5721 case DW_AT_decl_line
:
5724 case DW_AT_decl_file
:
5731 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5732 || n_decl_line
> 1 || n_decl_file
> 1)
5734 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5735 debug_dwarf_die (die
);
5740 /* A debugging information entry that is a member of an abstract
5741 instance tree [that has DW_AT_inline] should not contain any
5742 attributes which describe aspects of the subroutine which vary
5743 between distinct inlined expansions or distinct out-of-line
5745 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5746 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5747 && a
->dw_attr
!= DW_AT_high_pc
5748 && a
->dw_attr
!= DW_AT_location
5749 && a
->dw_attr
!= DW_AT_frame_base
5750 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5755 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5756 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5757 DIE that marks the start of the DIEs for this include file. */
5760 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5762 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5763 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5765 new_unit
->die_sib
= old_unit
;
5769 /* Close an include-file CU and reopen the enclosing one. */
5772 pop_compile_unit (dw_die_ref old_unit
)
5774 dw_die_ref new_unit
= old_unit
->die_sib
;
5776 old_unit
->die_sib
= NULL
;
5780 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5781 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5782 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5784 /* Calculate the checksum of a location expression. */
5787 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5790 inchash::hash hstate
;
5793 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5795 hash_loc_operands (loc
, hstate
);
5796 hash
= hstate
.end();
5800 /* Calculate the checksum of an attribute. */
5803 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5805 dw_loc_descr_ref loc
;
5808 CHECKSUM (at
->dw_attr
);
5810 /* We don't care that this was compiled with a different compiler
5811 snapshot; if the output is the same, that's what matters. */
5812 if (at
->dw_attr
== DW_AT_producer
)
5815 switch (AT_class (at
))
5817 case dw_val_class_const
:
5818 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5820 case dw_val_class_unsigned_const
:
5821 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5823 case dw_val_class_const_double
:
5824 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5826 case dw_val_class_wide_int
:
5827 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5828 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5829 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5831 case dw_val_class_vec
:
5832 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5833 (at
->dw_attr_val
.v
.val_vec
.length
5834 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5836 case dw_val_class_flag
:
5837 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5839 case dw_val_class_str
:
5840 CHECKSUM_STRING (AT_string (at
));
5843 case dw_val_class_addr
:
5845 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5846 CHECKSUM_STRING (XSTR (r
, 0));
5849 case dw_val_class_offset
:
5850 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5853 case dw_val_class_loc
:
5854 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5855 loc_checksum (loc
, ctx
);
5858 case dw_val_class_die_ref
:
5859 die_checksum (AT_ref (at
), ctx
, mark
);
5862 case dw_val_class_fde_ref
:
5863 case dw_val_class_vms_delta
:
5864 case dw_val_class_lbl_id
:
5865 case dw_val_class_lineptr
:
5866 case dw_val_class_macptr
:
5867 case dw_val_class_high_pc
:
5870 case dw_val_class_file
:
5871 CHECKSUM_STRING (AT_file (at
)->filename
);
5874 case dw_val_class_data8
:
5875 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5883 /* Calculate the checksum of a DIE. */
5886 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5892 /* To avoid infinite recursion. */
5895 CHECKSUM (die
->die_mark
);
5898 die
->die_mark
= ++(*mark
);
5900 CHECKSUM (die
->die_tag
);
5902 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5903 attr_checksum (a
, ctx
, mark
);
5905 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5909 #undef CHECKSUM_BLOCK
5910 #undef CHECKSUM_STRING
5912 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5913 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5914 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5915 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5916 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5917 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5918 #define CHECKSUM_ATTR(FOO) \
5919 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5921 /* Calculate the checksum of a number in signed LEB128 format. */
5924 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5931 byte
= (value
& 0x7f);
5933 more
= !((value
== 0 && (byte
& 0x40) == 0)
5934 || (value
== -1 && (byte
& 0x40) != 0));
5943 /* Calculate the checksum of a number in unsigned LEB128 format. */
5946 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5950 unsigned char byte
= (value
& 0x7f);
5953 /* More bytes to follow. */
5961 /* Checksum the context of the DIE. This adds the names of any
5962 surrounding namespaces or structures to the checksum. */
5965 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5969 int tag
= die
->die_tag
;
5971 if (tag
!= DW_TAG_namespace
5972 && tag
!= DW_TAG_structure_type
5973 && tag
!= DW_TAG_class_type
)
5976 name
= get_AT_string (die
, DW_AT_name
);
5978 spec
= get_AT_ref (die
, DW_AT_specification
);
5982 if (die
->die_parent
!= NULL
)
5983 checksum_die_context (die
->die_parent
, ctx
);
5985 CHECKSUM_ULEB128 ('C');
5986 CHECKSUM_ULEB128 (tag
);
5988 CHECKSUM_STRING (name
);
5991 /* Calculate the checksum of a location expression. */
5994 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5996 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5997 were emitted as a DW_FORM_sdata instead of a location expression. */
5998 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6000 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6001 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6005 /* Otherwise, just checksum the raw location expression. */
6008 inchash::hash hstate
;
6011 CHECKSUM_ULEB128 (loc
->dtprel
);
6012 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6013 hash_loc_operands (loc
, hstate
);
6014 hash
= hstate
.end ();
6016 loc
= loc
->dw_loc_next
;
6020 /* Calculate the checksum of an attribute. */
6023 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
6024 struct md5_ctx
*ctx
, int *mark
)
6026 dw_loc_descr_ref loc
;
6029 if (AT_class (at
) == dw_val_class_die_ref
)
6031 dw_die_ref target_die
= AT_ref (at
);
6033 /* For pointer and reference types, we checksum only the (qualified)
6034 name of the target type (if there is a name). For friend entries,
6035 we checksum only the (qualified) name of the target type or function.
6036 This allows the checksum to remain the same whether the target type
6037 is complete or not. */
6038 if ((at
->dw_attr
== DW_AT_type
6039 && (tag
== DW_TAG_pointer_type
6040 || tag
== DW_TAG_reference_type
6041 || tag
== DW_TAG_rvalue_reference_type
6042 || tag
== DW_TAG_ptr_to_member_type
))
6043 || (at
->dw_attr
== DW_AT_friend
6044 && tag
== DW_TAG_friend
))
6046 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
6048 if (name_attr
!= NULL
)
6050 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6054 CHECKSUM_ULEB128 ('N');
6055 CHECKSUM_ULEB128 (at
->dw_attr
);
6056 if (decl
->die_parent
!= NULL
)
6057 checksum_die_context (decl
->die_parent
, ctx
);
6058 CHECKSUM_ULEB128 ('E');
6059 CHECKSUM_STRING (AT_string (name_attr
));
6064 /* For all other references to another DIE, we check to see if the
6065 target DIE has already been visited. If it has, we emit a
6066 backward reference; if not, we descend recursively. */
6067 if (target_die
->die_mark
> 0)
6069 CHECKSUM_ULEB128 ('R');
6070 CHECKSUM_ULEB128 (at
->dw_attr
);
6071 CHECKSUM_ULEB128 (target_die
->die_mark
);
6075 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6079 target_die
->die_mark
= ++(*mark
);
6080 CHECKSUM_ULEB128 ('T');
6081 CHECKSUM_ULEB128 (at
->dw_attr
);
6082 if (decl
->die_parent
!= NULL
)
6083 checksum_die_context (decl
->die_parent
, ctx
);
6084 die_checksum_ordered (target_die
, ctx
, mark
);
6089 CHECKSUM_ULEB128 ('A');
6090 CHECKSUM_ULEB128 (at
->dw_attr
);
6092 switch (AT_class (at
))
6094 case dw_val_class_const
:
6095 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6096 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6099 case dw_val_class_unsigned_const
:
6100 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6101 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6104 case dw_val_class_const_double
:
6105 CHECKSUM_ULEB128 (DW_FORM_block
);
6106 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6107 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6110 case dw_val_class_wide_int
:
6111 CHECKSUM_ULEB128 (DW_FORM_block
);
6112 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6113 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6114 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6115 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6116 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6119 case dw_val_class_vec
:
6120 CHECKSUM_ULEB128 (DW_FORM_block
);
6121 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6122 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6123 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6124 (at
->dw_attr_val
.v
.val_vec
.length
6125 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6128 case dw_val_class_flag
:
6129 CHECKSUM_ULEB128 (DW_FORM_flag
);
6130 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6133 case dw_val_class_str
:
6134 CHECKSUM_ULEB128 (DW_FORM_string
);
6135 CHECKSUM_STRING (AT_string (at
));
6138 case dw_val_class_addr
:
6140 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6141 CHECKSUM_ULEB128 (DW_FORM_string
);
6142 CHECKSUM_STRING (XSTR (r
, 0));
6145 case dw_val_class_offset
:
6146 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6147 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6150 case dw_val_class_loc
:
6151 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6152 loc_checksum_ordered (loc
, ctx
);
6155 case dw_val_class_fde_ref
:
6156 case dw_val_class_lbl_id
:
6157 case dw_val_class_lineptr
:
6158 case dw_val_class_macptr
:
6159 case dw_val_class_high_pc
:
6162 case dw_val_class_file
:
6163 CHECKSUM_ULEB128 (DW_FORM_string
);
6164 CHECKSUM_STRING (AT_file (at
)->filename
);
6167 case dw_val_class_data8
:
6168 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6176 struct checksum_attributes
6178 dw_attr_ref at_name
;
6179 dw_attr_ref at_type
;
6180 dw_attr_ref at_friend
;
6181 dw_attr_ref at_accessibility
;
6182 dw_attr_ref at_address_class
;
6183 dw_attr_ref at_allocated
;
6184 dw_attr_ref at_artificial
;
6185 dw_attr_ref at_associated
;
6186 dw_attr_ref at_binary_scale
;
6187 dw_attr_ref at_bit_offset
;
6188 dw_attr_ref at_bit_size
;
6189 dw_attr_ref at_bit_stride
;
6190 dw_attr_ref at_byte_size
;
6191 dw_attr_ref at_byte_stride
;
6192 dw_attr_ref at_const_value
;
6193 dw_attr_ref at_containing_type
;
6194 dw_attr_ref at_count
;
6195 dw_attr_ref at_data_location
;
6196 dw_attr_ref at_data_member_location
;
6197 dw_attr_ref at_decimal_scale
;
6198 dw_attr_ref at_decimal_sign
;
6199 dw_attr_ref at_default_value
;
6200 dw_attr_ref at_digit_count
;
6201 dw_attr_ref at_discr
;
6202 dw_attr_ref at_discr_list
;
6203 dw_attr_ref at_discr_value
;
6204 dw_attr_ref at_encoding
;
6205 dw_attr_ref at_endianity
;
6206 dw_attr_ref at_explicit
;
6207 dw_attr_ref at_is_optional
;
6208 dw_attr_ref at_location
;
6209 dw_attr_ref at_lower_bound
;
6210 dw_attr_ref at_mutable
;
6211 dw_attr_ref at_ordering
;
6212 dw_attr_ref at_picture_string
;
6213 dw_attr_ref at_prototyped
;
6214 dw_attr_ref at_small
;
6215 dw_attr_ref at_segment
;
6216 dw_attr_ref at_string_length
;
6217 dw_attr_ref at_threads_scaled
;
6218 dw_attr_ref at_upper_bound
;
6219 dw_attr_ref at_use_location
;
6220 dw_attr_ref at_use_UTF8
;
6221 dw_attr_ref at_variable_parameter
;
6222 dw_attr_ref at_virtuality
;
6223 dw_attr_ref at_visibility
;
6224 dw_attr_ref at_vtable_elem_location
;
6227 /* Collect the attributes that we will want to use for the checksum. */
6230 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6235 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6246 attrs
->at_friend
= a
;
6248 case DW_AT_accessibility
:
6249 attrs
->at_accessibility
= a
;
6251 case DW_AT_address_class
:
6252 attrs
->at_address_class
= a
;
6254 case DW_AT_allocated
:
6255 attrs
->at_allocated
= a
;
6257 case DW_AT_artificial
:
6258 attrs
->at_artificial
= a
;
6260 case DW_AT_associated
:
6261 attrs
->at_associated
= a
;
6263 case DW_AT_binary_scale
:
6264 attrs
->at_binary_scale
= a
;
6266 case DW_AT_bit_offset
:
6267 attrs
->at_bit_offset
= a
;
6269 case DW_AT_bit_size
:
6270 attrs
->at_bit_size
= a
;
6272 case DW_AT_bit_stride
:
6273 attrs
->at_bit_stride
= a
;
6275 case DW_AT_byte_size
:
6276 attrs
->at_byte_size
= a
;
6278 case DW_AT_byte_stride
:
6279 attrs
->at_byte_stride
= a
;
6281 case DW_AT_const_value
:
6282 attrs
->at_const_value
= a
;
6284 case DW_AT_containing_type
:
6285 attrs
->at_containing_type
= a
;
6288 attrs
->at_count
= a
;
6290 case DW_AT_data_location
:
6291 attrs
->at_data_location
= a
;
6293 case DW_AT_data_member_location
:
6294 attrs
->at_data_member_location
= a
;
6296 case DW_AT_decimal_scale
:
6297 attrs
->at_decimal_scale
= a
;
6299 case DW_AT_decimal_sign
:
6300 attrs
->at_decimal_sign
= a
;
6302 case DW_AT_default_value
:
6303 attrs
->at_default_value
= a
;
6305 case DW_AT_digit_count
:
6306 attrs
->at_digit_count
= a
;
6309 attrs
->at_discr
= a
;
6311 case DW_AT_discr_list
:
6312 attrs
->at_discr_list
= a
;
6314 case DW_AT_discr_value
:
6315 attrs
->at_discr_value
= a
;
6317 case DW_AT_encoding
:
6318 attrs
->at_encoding
= a
;
6320 case DW_AT_endianity
:
6321 attrs
->at_endianity
= a
;
6323 case DW_AT_explicit
:
6324 attrs
->at_explicit
= a
;
6326 case DW_AT_is_optional
:
6327 attrs
->at_is_optional
= a
;
6329 case DW_AT_location
:
6330 attrs
->at_location
= a
;
6332 case DW_AT_lower_bound
:
6333 attrs
->at_lower_bound
= a
;
6336 attrs
->at_mutable
= a
;
6338 case DW_AT_ordering
:
6339 attrs
->at_ordering
= a
;
6341 case DW_AT_picture_string
:
6342 attrs
->at_picture_string
= a
;
6344 case DW_AT_prototyped
:
6345 attrs
->at_prototyped
= a
;
6348 attrs
->at_small
= a
;
6351 attrs
->at_segment
= a
;
6353 case DW_AT_string_length
:
6354 attrs
->at_string_length
= a
;
6356 case DW_AT_threads_scaled
:
6357 attrs
->at_threads_scaled
= a
;
6359 case DW_AT_upper_bound
:
6360 attrs
->at_upper_bound
= a
;
6362 case DW_AT_use_location
:
6363 attrs
->at_use_location
= a
;
6365 case DW_AT_use_UTF8
:
6366 attrs
->at_use_UTF8
= a
;
6368 case DW_AT_variable_parameter
:
6369 attrs
->at_variable_parameter
= a
;
6371 case DW_AT_virtuality
:
6372 attrs
->at_virtuality
= a
;
6374 case DW_AT_visibility
:
6375 attrs
->at_visibility
= a
;
6377 case DW_AT_vtable_elem_location
:
6378 attrs
->at_vtable_elem_location
= a
;
6386 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6389 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6393 struct checksum_attributes attrs
;
6395 CHECKSUM_ULEB128 ('D');
6396 CHECKSUM_ULEB128 (die
->die_tag
);
6398 memset (&attrs
, 0, sizeof (attrs
));
6400 decl
= get_AT_ref (die
, DW_AT_specification
);
6402 collect_checksum_attributes (&attrs
, decl
);
6403 collect_checksum_attributes (&attrs
, die
);
6405 CHECKSUM_ATTR (attrs
.at_name
);
6406 CHECKSUM_ATTR (attrs
.at_accessibility
);
6407 CHECKSUM_ATTR (attrs
.at_address_class
);
6408 CHECKSUM_ATTR (attrs
.at_allocated
);
6409 CHECKSUM_ATTR (attrs
.at_artificial
);
6410 CHECKSUM_ATTR (attrs
.at_associated
);
6411 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6412 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6413 CHECKSUM_ATTR (attrs
.at_bit_size
);
6414 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6415 CHECKSUM_ATTR (attrs
.at_byte_size
);
6416 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6417 CHECKSUM_ATTR (attrs
.at_const_value
);
6418 CHECKSUM_ATTR (attrs
.at_containing_type
);
6419 CHECKSUM_ATTR (attrs
.at_count
);
6420 CHECKSUM_ATTR (attrs
.at_data_location
);
6421 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6422 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6423 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6424 CHECKSUM_ATTR (attrs
.at_default_value
);
6425 CHECKSUM_ATTR (attrs
.at_digit_count
);
6426 CHECKSUM_ATTR (attrs
.at_discr
);
6427 CHECKSUM_ATTR (attrs
.at_discr_list
);
6428 CHECKSUM_ATTR (attrs
.at_discr_value
);
6429 CHECKSUM_ATTR (attrs
.at_encoding
);
6430 CHECKSUM_ATTR (attrs
.at_endianity
);
6431 CHECKSUM_ATTR (attrs
.at_explicit
);
6432 CHECKSUM_ATTR (attrs
.at_is_optional
);
6433 CHECKSUM_ATTR (attrs
.at_location
);
6434 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6435 CHECKSUM_ATTR (attrs
.at_mutable
);
6436 CHECKSUM_ATTR (attrs
.at_ordering
);
6437 CHECKSUM_ATTR (attrs
.at_picture_string
);
6438 CHECKSUM_ATTR (attrs
.at_prototyped
);
6439 CHECKSUM_ATTR (attrs
.at_small
);
6440 CHECKSUM_ATTR (attrs
.at_segment
);
6441 CHECKSUM_ATTR (attrs
.at_string_length
);
6442 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6443 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6444 CHECKSUM_ATTR (attrs
.at_use_location
);
6445 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6446 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6447 CHECKSUM_ATTR (attrs
.at_virtuality
);
6448 CHECKSUM_ATTR (attrs
.at_visibility
);
6449 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6450 CHECKSUM_ATTR (attrs
.at_type
);
6451 CHECKSUM_ATTR (attrs
.at_friend
);
6453 /* Checksum the child DIEs. */
6456 dw_attr_ref name_attr
;
6459 name_attr
= get_AT (c
, DW_AT_name
);
6460 if (is_template_instantiation (c
))
6462 /* Ignore instantiations of member type and function templates. */
6464 else if (name_attr
!= NULL
6465 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6467 /* Use a shallow checksum for named nested types and member
6469 CHECKSUM_ULEB128 ('S');
6470 CHECKSUM_ULEB128 (c
->die_tag
);
6471 CHECKSUM_STRING (AT_string (name_attr
));
6475 /* Use a deep checksum for other children. */
6476 /* Mark this DIE so it gets processed when unmarking. */
6477 if (c
->die_mark
== 0)
6479 die_checksum_ordered (c
, ctx
, mark
);
6481 } while (c
!= die
->die_child
);
6483 CHECKSUM_ULEB128 (0);
6486 /* Add a type name and tag to a hash. */
6488 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6490 CHECKSUM_ULEB128 (tag
);
6491 CHECKSUM_STRING (name
);
6495 #undef CHECKSUM_STRING
6496 #undef CHECKSUM_ATTR
6497 #undef CHECKSUM_LEB128
6498 #undef CHECKSUM_ULEB128
6500 /* Generate the type signature for DIE. This is computed by generating an
6501 MD5 checksum over the DIE's tag, its relevant attributes, and its
6502 children. Attributes that are references to other DIEs are processed
6503 by recursion, using the MARK field to prevent infinite recursion.
6504 If the DIE is nested inside a namespace or another type, we also
6505 need to include that context in the signature. The lower 64 bits
6506 of the resulting MD5 checksum comprise the signature. */
6509 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6513 unsigned char checksum
[16];
6518 name
= get_AT_string (die
, DW_AT_name
);
6519 decl
= get_AT_ref (die
, DW_AT_specification
);
6520 parent
= get_die_parent (die
);
6522 /* First, compute a signature for just the type name (and its surrounding
6523 context, if any. This is stored in the type unit DIE for link-time
6524 ODR (one-definition rule) checking. */
6526 if (is_cxx () && name
!= NULL
)
6528 md5_init_ctx (&ctx
);
6530 /* Checksum the names of surrounding namespaces and structures. */
6532 checksum_die_context (parent
, &ctx
);
6534 /* Checksum the current DIE. */
6535 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6536 md5_finish_ctx (&ctx
, checksum
);
6538 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6541 /* Next, compute the complete type signature. */
6543 md5_init_ctx (&ctx
);
6545 die
->die_mark
= mark
;
6547 /* Checksum the names of surrounding namespaces and structures. */
6549 checksum_die_context (parent
, &ctx
);
6551 /* Checksum the DIE and its children. */
6552 die_checksum_ordered (die
, &ctx
, &mark
);
6553 unmark_all_dies (die
);
6554 md5_finish_ctx (&ctx
, checksum
);
6556 /* Store the signature in the type node and link the type DIE and the
6557 type node together. */
6558 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6559 DWARF_TYPE_SIGNATURE_SIZE
);
6560 die
->comdat_type_p
= true;
6561 die
->die_id
.die_type_node
= type_node
;
6562 type_node
->type_die
= die
;
6564 /* If the DIE is a specification, link its declaration to the type node
6568 decl
->comdat_type_p
= true;
6569 decl
->die_id
.die_type_node
= type_node
;
6573 /* Do the location expressions look same? */
6575 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6577 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6578 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6579 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6582 /* Do the values look the same? */
6584 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6586 dw_loc_descr_ref loc1
, loc2
;
6589 if (v1
->val_class
!= v2
->val_class
)
6592 switch (v1
->val_class
)
6594 case dw_val_class_const
:
6595 return v1
->v
.val_int
== v2
->v
.val_int
;
6596 case dw_val_class_unsigned_const
:
6597 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6598 case dw_val_class_const_double
:
6599 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6600 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6601 case dw_val_class_wide_int
:
6602 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6603 case dw_val_class_vec
:
6604 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6605 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6607 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6608 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6611 case dw_val_class_flag
:
6612 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6613 case dw_val_class_str
:
6614 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6616 case dw_val_class_addr
:
6617 r1
= v1
->v
.val_addr
;
6618 r2
= v2
->v
.val_addr
;
6619 if (GET_CODE (r1
) != GET_CODE (r2
))
6621 return !rtx_equal_p (r1
, r2
);
6623 case dw_val_class_offset
:
6624 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6626 case dw_val_class_loc
:
6627 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6629 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6630 if (!same_loc_p (loc1
, loc2
, mark
))
6632 return !loc1
&& !loc2
;
6634 case dw_val_class_die_ref
:
6635 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6637 case dw_val_class_fde_ref
:
6638 case dw_val_class_vms_delta
:
6639 case dw_val_class_lbl_id
:
6640 case dw_val_class_lineptr
:
6641 case dw_val_class_macptr
:
6642 case dw_val_class_high_pc
:
6645 case dw_val_class_file
:
6646 return v1
->v
.val_file
== v2
->v
.val_file
;
6648 case dw_val_class_data8
:
6649 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6656 /* Do the attributes look the same? */
6659 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6661 if (at1
->dw_attr
!= at2
->dw_attr
)
6664 /* We don't care that this was compiled with a different compiler
6665 snapshot; if the output is the same, that's what matters. */
6666 if (at1
->dw_attr
== DW_AT_producer
)
6669 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6672 /* Do the dies look the same? */
6675 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6681 /* To avoid infinite recursion. */
6683 return die1
->die_mark
== die2
->die_mark
;
6684 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6686 if (die1
->die_tag
!= die2
->die_tag
)
6689 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6692 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6693 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6696 c1
= die1
->die_child
;
6697 c2
= die2
->die_child
;
6706 if (!same_die_p (c1
, c2
, mark
))
6710 if (c1
== die1
->die_child
)
6712 if (c2
== die2
->die_child
)
6722 /* Do the dies look the same? Wrapper around same_die_p. */
6725 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6728 int ret
= same_die_p (die1
, die2
, &mark
);
6730 unmark_all_dies (die1
);
6731 unmark_all_dies (die2
);
6736 /* The prefix to attach to symbols on DIEs in the current comdat debug
6738 static const char *comdat_symbol_id
;
6740 /* The index of the current symbol within the current comdat CU. */
6741 static unsigned int comdat_symbol_number
;
6743 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6744 children, and set comdat_symbol_id accordingly. */
6747 compute_section_prefix (dw_die_ref unit_die
)
6749 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6750 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6751 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6754 unsigned char checksum
[16];
6757 /* Compute the checksum of the DIE, then append part of it as hex digits to
6758 the name filename of the unit. */
6760 md5_init_ctx (&ctx
);
6762 die_checksum (unit_die
, &ctx
, &mark
);
6763 unmark_all_dies (unit_die
);
6764 md5_finish_ctx (&ctx
, checksum
);
6766 sprintf (name
, "%s.", base
);
6767 clean_symbol_name (name
);
6769 p
= name
+ strlen (name
);
6770 for (i
= 0; i
< 4; i
++)
6772 sprintf (p
, "%.2x", checksum
[i
]);
6776 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6777 comdat_symbol_number
= 0;
6780 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6783 is_type_die (dw_die_ref die
)
6785 switch (die
->die_tag
)
6787 case DW_TAG_array_type
:
6788 case DW_TAG_class_type
:
6789 case DW_TAG_interface_type
:
6790 case DW_TAG_enumeration_type
:
6791 case DW_TAG_pointer_type
:
6792 case DW_TAG_reference_type
:
6793 case DW_TAG_rvalue_reference_type
:
6794 case DW_TAG_string_type
:
6795 case DW_TAG_structure_type
:
6796 case DW_TAG_subroutine_type
:
6797 case DW_TAG_union_type
:
6798 case DW_TAG_ptr_to_member_type
:
6799 case DW_TAG_set_type
:
6800 case DW_TAG_subrange_type
:
6801 case DW_TAG_base_type
:
6802 case DW_TAG_const_type
:
6803 case DW_TAG_file_type
:
6804 case DW_TAG_packed_type
:
6805 case DW_TAG_volatile_type
:
6806 case DW_TAG_typedef
:
6813 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6814 Basically, we want to choose the bits that are likely to be shared between
6815 compilations (types) and leave out the bits that are specific to individual
6816 compilations (functions). */
6819 is_comdat_die (dw_die_ref c
)
6821 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6822 we do for stabs. The advantage is a greater likelihood of sharing between
6823 objects that don't include headers in the same order (and therefore would
6824 put the base types in a different comdat). jason 8/28/00 */
6826 if (c
->die_tag
== DW_TAG_base_type
)
6829 if (c
->die_tag
== DW_TAG_pointer_type
6830 || c
->die_tag
== DW_TAG_reference_type
6831 || c
->die_tag
== DW_TAG_rvalue_reference_type
6832 || c
->die_tag
== DW_TAG_const_type
6833 || c
->die_tag
== DW_TAG_volatile_type
)
6835 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6837 return t
? is_comdat_die (t
) : 0;
6840 return is_type_die (c
);
6843 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6844 compilation unit. */
6847 is_symbol_die (dw_die_ref c
)
6849 return (is_type_die (c
)
6850 || is_declaration_die (c
)
6851 || c
->die_tag
== DW_TAG_namespace
6852 || c
->die_tag
== DW_TAG_module
);
6855 /* Returns true iff C is a compile-unit DIE. */
6858 is_cu_die (dw_die_ref c
)
6860 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6863 /* Returns true iff C is a unit DIE of some sort. */
6866 is_unit_die (dw_die_ref c
)
6868 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6869 || c
->die_tag
== DW_TAG_partial_unit
6870 || c
->die_tag
== DW_TAG_type_unit
);
6873 /* Returns true iff C is a namespace DIE. */
6876 is_namespace_die (dw_die_ref c
)
6878 return c
&& c
->die_tag
== DW_TAG_namespace
;
6881 /* Returns true iff C is a class or structure DIE. */
6884 is_class_die (dw_die_ref c
)
6886 return c
&& (c
->die_tag
== DW_TAG_class_type
6887 || c
->die_tag
== DW_TAG_structure_type
);
6890 /* Return non-zero if this DIE is a template parameter. */
6893 is_template_parameter (dw_die_ref die
)
6895 switch (die
->die_tag
)
6897 case DW_TAG_template_type_param
:
6898 case DW_TAG_template_value_param
:
6899 case DW_TAG_GNU_template_template_param
:
6900 case DW_TAG_GNU_template_parameter_pack
:
6907 /* Return non-zero if this DIE represents a template instantiation. */
6910 is_template_instantiation (dw_die_ref die
)
6914 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6916 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6921 gen_internal_sym (const char *prefix
)
6925 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6926 return xstrdup (buf
);
6929 /* Assign symbols to all worthy DIEs under DIE. */
6932 assign_symbol_names (dw_die_ref die
)
6936 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6938 if (comdat_symbol_id
)
6940 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6942 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6943 comdat_symbol_id
, comdat_symbol_number
++);
6944 die
->die_id
.die_symbol
= xstrdup (p
);
6947 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6950 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6953 struct cu_hash_table_entry
6956 unsigned min_comdat_num
, max_comdat_num
;
6957 struct cu_hash_table_entry
*next
;
6960 /* Helpers to manipulate hash table of CUs. */
6962 struct cu_hash_table_entry_hasher
6964 typedef cu_hash_table_entry
*value_type
;
6965 typedef die_struct
*compare_type
;
6966 static inline hashval_t
hash (const cu_hash_table_entry
*);
6967 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
6968 static inline void remove (cu_hash_table_entry
*);
6972 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
6974 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6978 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
6979 const die_struct
*entry2
)
6981 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6985 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
6987 struct cu_hash_table_entry
*next
;
6997 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6999 /* Check whether we have already seen this CU and set up SYM_NUM
7002 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7004 struct cu_hash_table_entry dummy
;
7005 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7007 dummy
.max_comdat_num
= 0;
7009 slot
= htable
->find_slot_with_hash (cu
,
7010 htab_hash_string (cu
->die_id
.die_symbol
),
7014 for (; entry
; last
= entry
, entry
= entry
->next
)
7016 if (same_die_p_wrap (cu
, entry
->cu
))
7022 *sym_num
= entry
->min_comdat_num
;
7026 entry
= XCNEW (struct cu_hash_table_entry
);
7028 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7029 entry
->next
= *slot
;
7035 /* Record SYM_NUM to record of CU in HTABLE. */
7037 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7038 unsigned int sym_num
)
7040 struct cu_hash_table_entry
**slot
, *entry
;
7042 slot
= htable
->find_slot_with_hash (cu
,
7043 htab_hash_string (cu
->die_id
.die_symbol
),
7047 entry
->max_comdat_num
= sym_num
;
7050 /* Traverse the DIE (which is always comp_unit_die), and set up
7051 additional compilation units for each of the include files we see
7052 bracketed by BINCL/EINCL. */
7055 break_out_includes (dw_die_ref die
)
7058 dw_die_ref unit
= NULL
;
7059 limbo_die_node
*node
, **pnode
;
7063 dw_die_ref prev
= c
;
7065 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7066 || (unit
&& is_comdat_die (c
)))
7068 dw_die_ref next
= c
->die_sib
;
7070 /* This DIE is for a secondary CU; remove it from the main one. */
7071 remove_child_with_prev (c
, prev
);
7073 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7074 unit
= push_new_compile_unit (unit
, c
);
7075 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7076 unit
= pop_compile_unit (unit
);
7078 add_child_die (unit
, c
);
7080 if (c
== die
->die_child
)
7083 } while (c
!= die
->die_child
);
7086 /* We can only use this in debugging, since the frontend doesn't check
7087 to make sure that we leave every include file we enter. */
7091 assign_symbol_names (die
);
7092 cu_hash_type
cu_hash_table (10);
7093 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7099 compute_section_prefix (node
->die
);
7100 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7101 &comdat_symbol_number
);
7102 assign_symbol_names (node
->die
);
7104 *pnode
= node
->next
;
7107 pnode
= &node
->next
;
7108 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7109 comdat_symbol_number
);
7114 /* Return non-zero if this DIE is a declaration. */
7117 is_declaration_die (dw_die_ref die
)
7122 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7123 if (a
->dw_attr
== DW_AT_declaration
)
7129 /* Return non-zero if this DIE is nested inside a subprogram. */
7132 is_nested_in_subprogram (dw_die_ref die
)
7134 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7138 return local_scope_p (decl
);
7141 /* Return non-zero if this DIE contains a defining declaration of a
7145 contains_subprogram_definition (dw_die_ref die
)
7149 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7151 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7155 /* Return non-zero if this is a type DIE that should be moved to a
7156 COMDAT .debug_types section. */
7159 should_move_die_to_comdat (dw_die_ref die
)
7161 switch (die
->die_tag
)
7163 case DW_TAG_class_type
:
7164 case DW_TAG_structure_type
:
7165 case DW_TAG_enumeration_type
:
7166 case DW_TAG_union_type
:
7167 /* Don't move declarations, inlined instances, types nested in a
7168 subprogram, or types that contain subprogram definitions. */
7169 if (is_declaration_die (die
)
7170 || get_AT (die
, DW_AT_abstract_origin
)
7171 || is_nested_in_subprogram (die
)
7172 || contains_subprogram_definition (die
))
7175 case DW_TAG_array_type
:
7176 case DW_TAG_interface_type
:
7177 case DW_TAG_pointer_type
:
7178 case DW_TAG_reference_type
:
7179 case DW_TAG_rvalue_reference_type
:
7180 case DW_TAG_string_type
:
7181 case DW_TAG_subroutine_type
:
7182 case DW_TAG_ptr_to_member_type
:
7183 case DW_TAG_set_type
:
7184 case DW_TAG_subrange_type
:
7185 case DW_TAG_base_type
:
7186 case DW_TAG_const_type
:
7187 case DW_TAG_file_type
:
7188 case DW_TAG_packed_type
:
7189 case DW_TAG_volatile_type
:
7190 case DW_TAG_typedef
:
7196 /* Make a clone of DIE. */
7199 clone_die (dw_die_ref die
)
7205 clone
= ggc_cleared_alloc
<die_node
> ();
7206 clone
->die_tag
= die
->die_tag
;
7208 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7209 add_dwarf_attr (clone
, a
);
7214 /* Make a clone of the tree rooted at DIE. */
7217 clone_tree (dw_die_ref die
)
7220 dw_die_ref clone
= clone_die (die
);
7222 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7227 /* Make a clone of DIE as a declaration. */
7230 clone_as_declaration (dw_die_ref die
)
7237 /* If the DIE is already a declaration, just clone it. */
7238 if (is_declaration_die (die
))
7239 return clone_die (die
);
7241 /* If the DIE is a specification, just clone its declaration DIE. */
7242 decl
= get_AT_ref (die
, DW_AT_specification
);
7245 clone
= clone_die (decl
);
7246 if (die
->comdat_type_p
)
7247 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7251 clone
= ggc_cleared_alloc
<die_node
> ();
7252 clone
->die_tag
= die
->die_tag
;
7254 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7256 /* We don't want to copy over all attributes.
7257 For example we don't want DW_AT_byte_size because otherwise we will no
7258 longer have a declaration and GDB will treat it as a definition. */
7262 case DW_AT_abstract_origin
:
7263 case DW_AT_artificial
:
7264 case DW_AT_containing_type
:
7265 case DW_AT_external
:
7268 case DW_AT_virtuality
:
7269 case DW_AT_linkage_name
:
7270 case DW_AT_MIPS_linkage_name
:
7271 add_dwarf_attr (clone
, a
);
7273 case DW_AT_byte_size
:
7279 if (die
->comdat_type_p
)
7280 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7282 add_AT_flag (clone
, DW_AT_declaration
, 1);
7287 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7289 struct decl_table_entry
7295 /* Helpers to manipulate hash table of copied declarations. */
7297 /* Hashtable helpers. */
7299 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
7301 typedef decl_table_entry
*value_type
;
7302 typedef die_struct
*compare_type
;
7303 static inline hashval_t
hash (const decl_table_entry
*);
7304 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7308 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7310 return htab_hash_pointer (entry
->orig
);
7314 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7315 const die_struct
*entry2
)
7317 return entry1
->orig
== entry2
;
7320 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7322 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7323 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7324 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7325 to check if the ancestor has already been copied into UNIT. */
7328 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7329 decl_hash_type
*decl_table
)
7331 dw_die_ref parent
= die
->die_parent
;
7332 dw_die_ref new_parent
= unit
;
7334 decl_table_entry
**slot
= NULL
;
7335 struct decl_table_entry
*entry
= NULL
;
7339 /* Check if the entry has already been copied to UNIT. */
7340 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7342 if (*slot
!= HTAB_EMPTY_ENTRY
)
7348 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7349 entry
= XCNEW (struct decl_table_entry
);
7357 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7360 if (!is_unit_die (parent
))
7361 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7364 copy
= clone_as_declaration (die
);
7365 add_child_die (new_parent
, copy
);
7369 /* Record the pointer to the copy. */
7375 /* Copy the declaration context to the new type unit DIE. This includes
7376 any surrounding namespace or type declarations. If the DIE has an
7377 AT_specification attribute, it also includes attributes and children
7378 attached to the specification, and returns a pointer to the original
7379 parent of the declaration DIE. Returns NULL otherwise. */
7382 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7385 dw_die_ref new_decl
;
7386 dw_die_ref orig_parent
= NULL
;
7388 decl
= get_AT_ref (die
, DW_AT_specification
);
7397 /* The original DIE will be changed to a declaration, and must
7398 be moved to be a child of the original declaration DIE. */
7399 orig_parent
= decl
->die_parent
;
7401 /* Copy the type node pointer from the new DIE to the original
7402 declaration DIE so we can forward references later. */
7403 decl
->comdat_type_p
= true;
7404 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7406 remove_AT (die
, DW_AT_specification
);
7408 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7410 if (a
->dw_attr
!= DW_AT_name
7411 && a
->dw_attr
!= DW_AT_declaration
7412 && a
->dw_attr
!= DW_AT_external
)
7413 add_dwarf_attr (die
, a
);
7416 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7419 if (decl
->die_parent
!= NULL
7420 && !is_unit_die (decl
->die_parent
))
7422 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7423 if (new_decl
!= NULL
)
7425 remove_AT (new_decl
, DW_AT_signature
);
7426 add_AT_specification (die
, new_decl
);
7433 /* Generate the skeleton ancestor tree for the given NODE, then clone
7434 the DIE and add the clone into the tree. */
7437 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7439 if (node
->new_die
!= NULL
)
7442 node
->new_die
= clone_as_declaration (node
->old_die
);
7444 if (node
->parent
!= NULL
)
7446 generate_skeleton_ancestor_tree (node
->parent
);
7447 add_child_die (node
->parent
->new_die
, node
->new_die
);
7451 /* Generate a skeleton tree of DIEs containing any declarations that are
7452 found in the original tree. We traverse the tree looking for declaration
7453 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7456 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7458 skeleton_chain_node node
;
7461 dw_die_ref prev
= NULL
;
7462 dw_die_ref next
= NULL
;
7464 node
.parent
= parent
;
7466 first
= c
= parent
->old_die
->die_child
;
7470 if (prev
== NULL
|| prev
->die_sib
== c
)
7473 next
= (c
== first
? NULL
: c
->die_sib
);
7475 node
.new_die
= NULL
;
7476 if (is_declaration_die (c
))
7478 if (is_template_instantiation (c
))
7480 /* Instantiated templates do not need to be cloned into the
7481 type unit. Just move the DIE and its children back to
7482 the skeleton tree (in the main CU). */
7483 remove_child_with_prev (c
, prev
);
7484 add_child_die (parent
->new_die
, c
);
7489 /* Clone the existing DIE, move the original to the skeleton
7490 tree (which is in the main CU), and put the clone, with
7491 all the original's children, where the original came from
7492 (which is about to be moved to the type unit). */
7493 dw_die_ref clone
= clone_die (c
);
7494 move_all_children (c
, clone
);
7496 /* If the original has a DW_AT_object_pointer attribute,
7497 it would now point to a child DIE just moved to the
7498 cloned tree, so we need to remove that attribute from
7500 remove_AT (c
, DW_AT_object_pointer
);
7502 replace_child (c
, clone
, prev
);
7503 generate_skeleton_ancestor_tree (parent
);
7504 add_child_die (parent
->new_die
, c
);
7509 generate_skeleton_bottom_up (&node
);
7510 } while (next
!= NULL
);
7513 /* Wrapper function for generate_skeleton_bottom_up. */
7516 generate_skeleton (dw_die_ref die
)
7518 skeleton_chain_node node
;
7521 node
.new_die
= NULL
;
7524 /* If this type definition is nested inside another type,
7525 and is not an instantiation of a template, always leave
7526 at least a declaration in its place. */
7527 if (die
->die_parent
!= NULL
7528 && is_type_die (die
->die_parent
)
7529 && !is_template_instantiation (die
))
7530 node
.new_die
= clone_as_declaration (die
);
7532 generate_skeleton_bottom_up (&node
);
7533 return node
.new_die
;
7536 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7537 declaration. The original DIE is moved to a new compile unit so that
7538 existing references to it follow it to the new location. If any of the
7539 original DIE's descendants is a declaration, we need to replace the
7540 original DIE with a skeleton tree and move the declarations back into the
7544 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7547 dw_die_ref skeleton
, orig_parent
;
7549 /* Copy the declaration context to the type unit DIE. If the returned
7550 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7552 orig_parent
= copy_declaration_context (unit
, child
);
7554 skeleton
= generate_skeleton (child
);
7555 if (skeleton
== NULL
)
7556 remove_child_with_prev (child
, prev
);
7559 skeleton
->comdat_type_p
= true;
7560 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7562 /* If the original DIE was a specification, we need to put
7563 the skeleton under the parent DIE of the declaration.
7564 This leaves the original declaration in the tree, but
7565 it will be pruned later since there are no longer any
7566 references to it. */
7567 if (orig_parent
!= NULL
)
7569 remove_child_with_prev (child
, prev
);
7570 add_child_die (orig_parent
, skeleton
);
7573 replace_child (child
, skeleton
, prev
);
7579 /* Traverse the DIE and set up additional .debug_types sections for each
7580 type worthy of being placed in a COMDAT section. */
7583 break_out_comdat_types (dw_die_ref die
)
7587 dw_die_ref prev
= NULL
;
7588 dw_die_ref next
= NULL
;
7589 dw_die_ref unit
= NULL
;
7591 first
= c
= die
->die_child
;
7595 if (prev
== NULL
|| prev
->die_sib
== c
)
7598 next
= (c
== first
? NULL
: c
->die_sib
);
7599 if (should_move_die_to_comdat (c
))
7601 dw_die_ref replacement
;
7602 comdat_type_node_ref type_node
;
7604 /* Break out nested types into their own type units. */
7605 break_out_comdat_types (c
);
7607 /* Create a new type unit DIE as the root for the new tree, and
7608 add it to the list of comdat types. */
7609 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7610 add_AT_unsigned (unit
, DW_AT_language
,
7611 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7612 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7613 type_node
->root_die
= unit
;
7614 type_node
->next
= comdat_type_list
;
7615 comdat_type_list
= type_node
;
7617 /* Generate the type signature. */
7618 generate_type_signature (c
, type_node
);
7620 /* Copy the declaration context, attributes, and children of the
7621 declaration into the new type unit DIE, then remove this DIE
7622 from the main CU (or replace it with a skeleton if necessary). */
7623 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7624 type_node
->skeleton_die
= replacement
;
7626 /* Add the DIE to the new compunit. */
7627 add_child_die (unit
, c
);
7629 if (replacement
!= NULL
)
7632 else if (c
->die_tag
== DW_TAG_namespace
7633 || c
->die_tag
== DW_TAG_class_type
7634 || c
->die_tag
== DW_TAG_structure_type
7635 || c
->die_tag
== DW_TAG_union_type
)
7637 /* Look for nested types that can be broken out. */
7638 break_out_comdat_types (c
);
7640 } while (next
!= NULL
);
7643 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7644 Enter all the cloned children into the hash table decl_table. */
7647 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7651 struct decl_table_entry
*entry
;
7652 decl_table_entry
**slot
;
7654 if (die
->die_tag
== DW_TAG_subprogram
)
7655 clone
= clone_as_declaration (die
);
7657 clone
= clone_die (die
);
7659 slot
= decl_table
->find_slot_with_hash (die
,
7660 htab_hash_pointer (die
), INSERT
);
7662 /* Assert that DIE isn't in the hash table yet. If it would be there
7663 before, the ancestors would be necessarily there as well, therefore
7664 clone_tree_partial wouldn't be called. */
7665 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7667 entry
= XCNEW (struct decl_table_entry
);
7669 entry
->copy
= clone
;
7672 if (die
->die_tag
!= DW_TAG_subprogram
)
7673 FOR_EACH_CHILD (die
, c
,
7674 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7679 /* Walk the DIE and its children, looking for references to incomplete
7680 or trivial types that are unmarked (i.e., that are not in the current
7684 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7690 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7692 if (AT_class (a
) == dw_val_class_die_ref
)
7694 dw_die_ref targ
= AT_ref (a
);
7695 decl_table_entry
**slot
;
7696 struct decl_table_entry
*entry
;
7698 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7701 slot
= decl_table
->find_slot_with_hash (targ
,
7702 htab_hash_pointer (targ
),
7705 if (*slot
!= HTAB_EMPTY_ENTRY
)
7707 /* TARG has already been copied, so we just need to
7708 modify the reference to point to the copy. */
7710 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7714 dw_die_ref parent
= unit
;
7715 dw_die_ref copy
= clone_die (targ
);
7717 /* Record in DECL_TABLE that TARG has been copied.
7718 Need to do this now, before the recursive call,
7719 because DECL_TABLE may be expanded and SLOT
7720 would no longer be a valid pointer. */
7721 entry
= XCNEW (struct decl_table_entry
);
7726 /* If TARG is not a declaration DIE, we need to copy its
7728 if (!is_declaration_die (targ
))
7732 add_child_die (copy
,
7733 clone_tree_partial (c
, decl_table
)));
7736 /* Make sure the cloned tree is marked as part of the
7740 /* If TARG has surrounding context, copy its ancestor tree
7741 into the new type unit. */
7742 if (targ
->die_parent
!= NULL
7743 && !is_unit_die (targ
->die_parent
))
7744 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7747 add_child_die (parent
, copy
);
7748 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7750 /* Make sure the newly-copied DIE is walked. If it was
7751 installed in a previously-added context, it won't
7752 get visited otherwise. */
7755 /* Find the highest point of the newly-added tree,
7756 mark each node along the way, and walk from there. */
7757 parent
->die_mark
= 1;
7758 while (parent
->die_parent
7759 && parent
->die_parent
->die_mark
== 0)
7761 parent
= parent
->die_parent
;
7762 parent
->die_mark
= 1;
7764 copy_decls_walk (unit
, parent
, decl_table
);
7770 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7773 /* Copy declarations for "unworthy" types into the new comdat section.
7774 Incomplete types, modified types, and certain other types aren't broken
7775 out into comdat sections of their own, so they don't have a signature,
7776 and we need to copy the declaration into the same section so that we
7777 don't have an external reference. */
7780 copy_decls_for_unworthy_types (dw_die_ref unit
)
7783 decl_hash_type
decl_table (10);
7784 copy_decls_walk (unit
, unit
, &decl_table
);
7788 /* Traverse the DIE and add a sibling attribute if it may have the
7789 effect of speeding up access to siblings. To save some space,
7790 avoid generating sibling attributes for DIE's without children. */
7793 add_sibling_attributes (dw_die_ref die
)
7797 if (! die
->die_child
)
7800 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7801 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7803 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7806 /* Output all location lists for the DIE and its children. */
7809 output_location_lists (dw_die_ref die
)
7815 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7816 if (AT_class (a
) == dw_val_class_loc_list
)
7817 output_loc_list (AT_loc_list (a
));
7819 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7822 /* We want to limit the number of external references, because they are
7823 larger than local references: a relocation takes multiple words, and
7824 even a sig8 reference is always eight bytes, whereas a local reference
7825 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7826 So if we encounter multiple external references to the same type DIE, we
7827 make a local typedef stub for it and redirect all references there.
7829 This is the element of the hash table for keeping track of these
7839 /* Hashtable helpers. */
7841 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7843 typedef external_ref
*value_type
;
7844 typedef external_ref
*compare_type
;
7845 static inline hashval_t
hash (const external_ref
*);
7846 static inline bool equal (const external_ref
*, const external_ref
*);
7850 external_ref_hasher::hash (const external_ref
*r
)
7852 dw_die_ref die
= r
->type
;
7855 /* We can't use the address of the DIE for hashing, because
7856 that will make the order of the stub DIEs non-deterministic. */
7857 if (! die
->comdat_type_p
)
7858 /* We have a symbol; use it to compute a hash. */
7859 h
= htab_hash_string (die
->die_id
.die_symbol
);
7862 /* We have a type signature; use a subset of the bits as the hash.
7863 The 8-byte signature is at least as large as hashval_t. */
7864 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7865 memcpy (&h
, type_node
->signature
, sizeof (h
));
7871 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
7873 return r1
->type
== r2
->type
;
7876 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7878 /* Return a pointer to the external_ref for references to DIE. */
7880 static struct external_ref
*
7881 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
7883 struct external_ref ref
, *ref_p
;
7884 external_ref
**slot
;
7887 slot
= map
->find_slot (&ref
, INSERT
);
7888 if (*slot
!= HTAB_EMPTY_ENTRY
)
7891 ref_p
= XCNEW (struct external_ref
);
7897 /* Subroutine of optimize_external_refs, below.
7899 If we see a type skeleton, record it as our stub. If we see external
7900 references, remember how many we've seen. */
7903 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
7908 struct external_ref
*ref_p
;
7910 if (is_type_die (die
)
7911 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7913 /* This is a local skeleton; use it for local references. */
7914 ref_p
= lookup_external_ref (map
, c
);
7918 /* Scan the DIE references, and remember any that refer to DIEs from
7919 other CUs (i.e. those which are not marked). */
7920 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7921 if (AT_class (a
) == dw_val_class_die_ref
7922 && (c
= AT_ref (a
))->die_mark
== 0
7925 ref_p
= lookup_external_ref (map
, c
);
7929 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7932 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7933 points to an external_ref, DATA is the CU we're processing. If we don't
7934 already have a local stub, and we have multiple refs, build a stub. */
7937 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7939 struct external_ref
*ref_p
= *slot
;
7941 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7943 /* We have multiple references to this type, so build a small stub.
7944 Both of these forms are a bit dodgy from the perspective of the
7945 DWARF standard, since technically they should have names. */
7946 dw_die_ref cu
= data
;
7947 dw_die_ref type
= ref_p
->type
;
7948 dw_die_ref stub
= NULL
;
7950 if (type
->comdat_type_p
)
7952 /* If we refer to this type via sig8, use AT_signature. */
7953 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7954 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7958 /* Otherwise, use a typedef with no name. */
7959 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7960 add_AT_die_ref (stub
, DW_AT_type
, type
);
7969 /* DIE is a unit; look through all the DIE references to see if there are
7970 any external references to types, and if so, create local stubs for
7971 them which will be applied in build_abbrev_table. This is useful because
7972 references to local DIEs are smaller. */
7974 static external_ref_hash_type
*
7975 optimize_external_refs (dw_die_ref die
)
7977 external_ref_hash_type
*map
= new external_ref_hash_type (10);
7978 optimize_external_refs_1 (die
, map
);
7979 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7983 /* The format of each DIE (and its attribute value pairs) is encoded in an
7984 abbreviation table. This routine builds the abbreviation table and assigns
7985 a unique abbreviation id for each abbreviation entry. The children of each
7986 die are visited recursively. */
7989 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
7991 unsigned long abbrev_id
;
7992 unsigned int n_alloc
;
7997 /* Scan the DIE references, and replace any that refer to
7998 DIEs from other CUs (i.e. those which are not marked) with
7999 the local stubs we built in optimize_external_refs. */
8000 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8001 if (AT_class (a
) == dw_val_class_die_ref
8002 && (c
= AT_ref (a
))->die_mark
== 0)
8004 struct external_ref
*ref_p
;
8005 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8007 ref_p
= lookup_external_ref (extern_map
, c
);
8008 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8009 change_AT_die_ref (a
, ref_p
->stub
);
8011 /* We aren't changing this reference, so mark it external. */
8012 set_AT_ref_external (a
, 1);
8015 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8017 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8018 dw_attr_ref die_a
, abbrev_a
;
8022 if (abbrev
->die_tag
!= die
->die_tag
)
8024 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8027 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8030 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8032 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8033 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8034 || (value_format (abbrev_a
) != value_format (die_a
)))
8044 if (abbrev_id
>= abbrev_die_table_in_use
)
8046 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8048 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8049 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8052 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8053 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8054 abbrev_die_table_allocated
= n_alloc
;
8057 ++abbrev_die_table_in_use
;
8058 abbrev_die_table
[abbrev_id
] = die
;
8061 die
->die_abbrev
= abbrev_id
;
8062 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8065 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8068 constant_size (unsigned HOST_WIDE_INT value
)
8075 log
= floor_log2 (value
);
8078 log
= 1 << (floor_log2 (log
) + 1);
8083 /* Return the size of a DIE as it is represented in the
8084 .debug_info section. */
8086 static unsigned long
8087 size_of_die (dw_die_ref die
)
8089 unsigned long size
= 0;
8092 enum dwarf_form form
;
8094 size
+= size_of_uleb128 (die
->die_abbrev
);
8095 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8097 switch (AT_class (a
))
8099 case dw_val_class_addr
:
8100 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8102 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8103 size
+= size_of_uleb128 (AT_index (a
));
8106 size
+= DWARF2_ADDR_SIZE
;
8108 case dw_val_class_offset
:
8109 size
+= DWARF_OFFSET_SIZE
;
8111 case dw_val_class_loc
:
8113 unsigned long lsize
= size_of_locs (AT_loc (a
));
8116 if (dwarf_version
>= 4)
8117 size
+= size_of_uleb128 (lsize
);
8119 size
+= constant_size (lsize
);
8123 case dw_val_class_loc_list
:
8124 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8126 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8127 size
+= size_of_uleb128 (AT_index (a
));
8130 size
+= DWARF_OFFSET_SIZE
;
8132 case dw_val_class_range_list
:
8133 size
+= DWARF_OFFSET_SIZE
;
8135 case dw_val_class_const
:
8136 size
+= size_of_sleb128 (AT_int (a
));
8138 case dw_val_class_unsigned_const
:
8140 int csize
= constant_size (AT_unsigned (a
));
8141 if (dwarf_version
== 3
8142 && a
->dw_attr
== DW_AT_data_member_location
8144 size
+= size_of_uleb128 (AT_unsigned (a
));
8149 case dw_val_class_const_double
:
8150 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8151 if (HOST_BITS_PER_WIDE_INT
>= 64)
8154 case dw_val_class_wide_int
:
8155 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8156 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8157 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8161 case dw_val_class_vec
:
8162 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8163 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8164 + a
->dw_attr_val
.v
.val_vec
.length
8165 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8167 case dw_val_class_flag
:
8168 if (dwarf_version
>= 4)
8169 /* Currently all add_AT_flag calls pass in 1 as last argument,
8170 so DW_FORM_flag_present can be used. If that ever changes,
8171 we'll need to use DW_FORM_flag and have some optimization
8172 in build_abbrev_table that will change those to
8173 DW_FORM_flag_present if it is set to 1 in all DIEs using
8174 the same abbrev entry. */
8175 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8179 case dw_val_class_die_ref
:
8180 if (AT_ref_external (a
))
8182 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8183 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8184 is sized by target address length, whereas in DWARF3
8185 it's always sized as an offset. */
8186 if (use_debug_types
)
8187 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8188 else if (dwarf_version
== 2)
8189 size
+= DWARF2_ADDR_SIZE
;
8191 size
+= DWARF_OFFSET_SIZE
;
8194 size
+= DWARF_OFFSET_SIZE
;
8196 case dw_val_class_fde_ref
:
8197 size
+= DWARF_OFFSET_SIZE
;
8199 case dw_val_class_lbl_id
:
8200 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8202 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8203 size
+= size_of_uleb128 (AT_index (a
));
8206 size
+= DWARF2_ADDR_SIZE
;
8208 case dw_val_class_lineptr
:
8209 case dw_val_class_macptr
:
8210 size
+= DWARF_OFFSET_SIZE
;
8212 case dw_val_class_str
:
8213 form
= AT_string_form (a
);
8214 if (form
== DW_FORM_strp
)
8215 size
+= DWARF_OFFSET_SIZE
;
8216 else if (form
== DW_FORM_GNU_str_index
)
8217 size
+= size_of_uleb128 (AT_index (a
));
8219 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8221 case dw_val_class_file
:
8222 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8224 case dw_val_class_data8
:
8227 case dw_val_class_vms_delta
:
8228 size
+= DWARF_OFFSET_SIZE
;
8230 case dw_val_class_high_pc
:
8231 size
+= DWARF2_ADDR_SIZE
;
8241 /* Size the debugging information associated with a given DIE. Visits the
8242 DIE's children recursively. Updates the global variable next_die_offset, on
8243 each time through. Uses the current value of next_die_offset to update the
8244 die_offset field in each DIE. */
8247 calc_die_sizes (dw_die_ref die
)
8251 gcc_assert (die
->die_offset
== 0
8252 || (unsigned long int) die
->die_offset
== next_die_offset
);
8253 die
->die_offset
= next_die_offset
;
8254 next_die_offset
+= size_of_die (die
);
8256 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8258 if (die
->die_child
!= NULL
)
8259 /* Count the null byte used to terminate sibling lists. */
8260 next_die_offset
+= 1;
8263 /* Size just the base type children at the start of the CU.
8264 This is needed because build_abbrev needs to size locs
8265 and sizing of type based stack ops needs to know die_offset
8266 values for the base types. */
8269 calc_base_type_die_sizes (void)
8271 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8273 dw_die_ref base_type
;
8274 #if ENABLE_ASSERT_CHECKING
8275 dw_die_ref prev
= comp_unit_die ()->die_child
;
8278 die_offset
+= size_of_die (comp_unit_die ());
8279 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8281 #if ENABLE_ASSERT_CHECKING
8282 gcc_assert (base_type
->die_offset
== 0
8283 && prev
->die_sib
== base_type
8284 && base_type
->die_child
== NULL
8285 && base_type
->die_abbrev
);
8288 base_type
->die_offset
= die_offset
;
8289 die_offset
+= size_of_die (base_type
);
8293 /* Set the marks for a die and its children. We do this so
8294 that we know whether or not a reference needs to use FORM_ref_addr; only
8295 DIEs in the same CU will be marked. We used to clear out the offset
8296 and use that as the flag, but ran into ordering problems. */
8299 mark_dies (dw_die_ref die
)
8303 gcc_assert (!die
->die_mark
);
8306 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8309 /* Clear the marks for a die and its children. */
8312 unmark_dies (dw_die_ref die
)
8316 if (! use_debug_types
)
8317 gcc_assert (die
->die_mark
);
8320 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8323 /* Clear the marks for a die, its children and referred dies. */
8326 unmark_all_dies (dw_die_ref die
)
8336 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8338 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8339 if (AT_class (a
) == dw_val_class_die_ref
)
8340 unmark_all_dies (AT_ref (a
));
8343 /* Calculate if the entry should appear in the final output file. It may be
8344 from a pruned a type. */
8347 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8349 /* By limiting gnu pubnames to definitions only, gold can generate a
8350 gdb index without entries for declarations, which don't include
8351 enough information to be useful. */
8352 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8355 if (table
== pubname_table
)
8357 /* Enumerator names are part of the pubname table, but the
8358 parent DW_TAG_enumeration_type die may have been pruned.
8359 Don't output them if that is the case. */
8360 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8361 (p
->die
->die_parent
== NULL
8362 || !p
->die
->die_parent
->die_perennial_p
))
8365 /* Everything else in the pubname table is included. */
8369 /* The pubtypes table shouldn't include types that have been
8371 return (p
->die
->die_offset
!= 0
8372 || !flag_eliminate_unused_debug_types
);
8375 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8376 generated for the compilation unit. */
8378 static unsigned long
8379 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8384 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8386 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8387 FOR_EACH_VEC_ELT (*names
, i
, p
)
8388 if (include_pubname_in_output (names
, p
))
8389 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8391 size
+= DWARF_OFFSET_SIZE
;
8395 /* Return the size of the information in the .debug_aranges section. */
8397 static unsigned long
8398 size_of_aranges (void)
8402 size
= DWARF_ARANGES_HEADER_SIZE
;
8404 /* Count the address/length pair for this compilation unit. */
8405 if (text_section_used
)
8406 size
+= 2 * DWARF2_ADDR_SIZE
;
8407 if (cold_text_section_used
)
8408 size
+= 2 * DWARF2_ADDR_SIZE
;
8409 if (have_multiple_function_sections
)
8414 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8416 if (DECL_IGNORED_P (fde
->decl
))
8418 if (!fde
->in_std_section
)
8419 size
+= 2 * DWARF2_ADDR_SIZE
;
8420 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8421 size
+= 2 * DWARF2_ADDR_SIZE
;
8425 /* Count the two zero words used to terminated the address range table. */
8426 size
+= 2 * DWARF2_ADDR_SIZE
;
8430 /* Select the encoding of an attribute value. */
8432 static enum dwarf_form
8433 value_format (dw_attr_ref a
)
8435 switch (AT_class (a
))
8437 case dw_val_class_addr
:
8438 /* Only very few attributes allow DW_FORM_addr. */
8443 case DW_AT_entry_pc
:
8444 case DW_AT_trampoline
:
8445 return (AT_index (a
) == NOT_INDEXED
8446 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8450 switch (DWARF2_ADDR_SIZE
)
8453 return DW_FORM_data1
;
8455 return DW_FORM_data2
;
8457 return DW_FORM_data4
;
8459 return DW_FORM_data8
;
8463 case dw_val_class_range_list
:
8464 case dw_val_class_loc_list
:
8465 if (dwarf_version
>= 4)
8466 return DW_FORM_sec_offset
;
8468 case dw_val_class_vms_delta
:
8469 case dw_val_class_offset
:
8470 switch (DWARF_OFFSET_SIZE
)
8473 return DW_FORM_data4
;
8475 return DW_FORM_data8
;
8479 case dw_val_class_loc
:
8480 if (dwarf_version
>= 4)
8481 return DW_FORM_exprloc
;
8482 switch (constant_size (size_of_locs (AT_loc (a
))))
8485 return DW_FORM_block1
;
8487 return DW_FORM_block2
;
8489 return DW_FORM_block4
;
8493 case dw_val_class_const
:
8494 return DW_FORM_sdata
;
8495 case dw_val_class_unsigned_const
:
8496 switch (constant_size (AT_unsigned (a
)))
8499 return DW_FORM_data1
;
8501 return DW_FORM_data2
;
8503 /* In DWARF3 DW_AT_data_member_location with
8504 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8505 constant, so we need to use DW_FORM_udata if we need
8506 a large constant. */
8507 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8508 return DW_FORM_udata
;
8509 return DW_FORM_data4
;
8511 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8512 return DW_FORM_udata
;
8513 return DW_FORM_data8
;
8517 case dw_val_class_const_double
:
8518 switch (HOST_BITS_PER_WIDE_INT
)
8521 return DW_FORM_data2
;
8523 return DW_FORM_data4
;
8525 return DW_FORM_data8
;
8528 return DW_FORM_block1
;
8530 case dw_val_class_wide_int
:
8531 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8534 return DW_FORM_data1
;
8536 return DW_FORM_data2
;
8538 return DW_FORM_data4
;
8540 return DW_FORM_data8
;
8542 return DW_FORM_block1
;
8544 case dw_val_class_vec
:
8545 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8546 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8549 return DW_FORM_block1
;
8551 return DW_FORM_block2
;
8553 return DW_FORM_block4
;
8557 case dw_val_class_flag
:
8558 if (dwarf_version
>= 4)
8560 /* Currently all add_AT_flag calls pass in 1 as last argument,
8561 so DW_FORM_flag_present can be used. If that ever changes,
8562 we'll need to use DW_FORM_flag and have some optimization
8563 in build_abbrev_table that will change those to
8564 DW_FORM_flag_present if it is set to 1 in all DIEs using
8565 the same abbrev entry. */
8566 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8567 return DW_FORM_flag_present
;
8569 return DW_FORM_flag
;
8570 case dw_val_class_die_ref
:
8571 if (AT_ref_external (a
))
8572 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8575 case dw_val_class_fde_ref
:
8576 return DW_FORM_data
;
8577 case dw_val_class_lbl_id
:
8578 return (AT_index (a
) == NOT_INDEXED
8579 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8580 case dw_val_class_lineptr
:
8581 case dw_val_class_macptr
:
8582 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8583 case dw_val_class_str
:
8584 return AT_string_form (a
);
8585 case dw_val_class_file
:
8586 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8589 return DW_FORM_data1
;
8591 return DW_FORM_data2
;
8593 return DW_FORM_data4
;
8598 case dw_val_class_data8
:
8599 return DW_FORM_data8
;
8601 case dw_val_class_high_pc
:
8602 switch (DWARF2_ADDR_SIZE
)
8605 return DW_FORM_data1
;
8607 return DW_FORM_data2
;
8609 return DW_FORM_data4
;
8611 return DW_FORM_data8
;
8621 /* Output the encoding of an attribute value. */
8624 output_value_format (dw_attr_ref a
)
8626 enum dwarf_form form
= value_format (a
);
8628 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8631 /* Given a die and id, produce the appropriate abbreviations. */
8634 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8639 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8640 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8641 dwarf_tag_name (abbrev
->die_tag
));
8643 if (abbrev
->die_child
!= NULL
)
8644 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8646 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8648 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8650 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8651 dwarf_attr_name (a_attr
->dw_attr
));
8652 output_value_format (a_attr
);
8655 dw2_asm_output_data (1, 0, NULL
);
8656 dw2_asm_output_data (1, 0, NULL
);
8660 /* Output the .debug_abbrev section which defines the DIE abbreviation
8664 output_abbrev_section (void)
8666 unsigned long abbrev_id
;
8668 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8669 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8671 /* Terminate the table. */
8672 dw2_asm_output_data (1, 0, NULL
);
8675 /* Output a symbol we can use to refer to this DIE from another CU. */
8678 output_die_symbol (dw_die_ref die
)
8680 const char *sym
= die
->die_id
.die_symbol
;
8682 gcc_assert (!die
->comdat_type_p
);
8687 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8688 /* We make these global, not weak; if the target doesn't support
8689 .linkonce, it doesn't support combining the sections, so debugging
8691 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8693 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8696 /* Return a new location list, given the begin and end range, and the
8699 static inline dw_loc_list_ref
8700 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8701 const char *section
)
8703 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8705 retlist
->begin
= begin
;
8706 retlist
->begin_entry
= NULL
;
8708 retlist
->expr
= expr
;
8709 retlist
->section
= section
;
8714 /* Generate a new internal symbol for this location list node, if it
8715 hasn't got one yet. */
8718 gen_llsym (dw_loc_list_ref list
)
8720 gcc_assert (!list
->ll_symbol
);
8721 list
->ll_symbol
= gen_internal_sym ("LLST");
8724 /* Output the location list given to us. */
8727 output_loc_list (dw_loc_list_ref list_head
)
8729 dw_loc_list_ref curr
= list_head
;
8731 if (list_head
->emitted
)
8733 list_head
->emitted
= true;
8735 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8737 /* Walk the location list, and output each range + expression. */
8738 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8741 /* Don't output an entry that starts and ends at the same address. */
8742 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8744 size
= size_of_locs (curr
->expr
);
8745 /* If the expression is too large, drop it on the floor. We could
8746 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8747 in the expression, but >= 64KB expressions for a single value
8748 in a single range are unlikely very useful. */
8751 if (dwarf_split_debug_info
)
8753 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8754 "Location list start/length entry (%s)",
8755 list_head
->ll_symbol
);
8756 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8757 "Location list range start index (%s)",
8759 /* The length field is 4 bytes. If we ever need to support
8760 an 8-byte length, we can add a new DW_LLE code or fall back
8761 to DW_LLE_GNU_start_end_entry. */
8762 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8763 "Location list range length (%s)",
8764 list_head
->ll_symbol
);
8766 else if (!have_multiple_function_sections
)
8768 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8769 "Location list begin address (%s)",
8770 list_head
->ll_symbol
);
8771 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8772 "Location list end address (%s)",
8773 list_head
->ll_symbol
);
8777 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8778 "Location list begin address (%s)",
8779 list_head
->ll_symbol
);
8780 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8781 "Location list end address (%s)",
8782 list_head
->ll_symbol
);
8785 /* Output the block length for this list of location operations. */
8786 gcc_assert (size
<= 0xffff);
8787 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8789 output_loc_sequence (curr
->expr
, -1);
8792 if (dwarf_split_debug_info
)
8793 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8794 "Location list terminator (%s)",
8795 list_head
->ll_symbol
);
8798 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8799 "Location list terminator begin (%s)",
8800 list_head
->ll_symbol
);
8801 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8802 "Location list terminator end (%s)",
8803 list_head
->ll_symbol
);
8807 /* Output a range_list offset into the debug_range section. Emit a
8808 relocated reference if val_entry is NULL, otherwise, emit an
8809 indirect reference. */
8812 output_range_list_offset (dw_attr_ref a
)
8814 const char *name
= dwarf_attr_name (a
->dw_attr
);
8816 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8818 char *p
= strchr (ranges_section_label
, '\0');
8819 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8820 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8821 debug_ranges_section
, "%s", name
);
8825 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8826 "%s (offset from %s)", name
, ranges_section_label
);
8829 /* Output the offset into the debug_loc section. */
8832 output_loc_list_offset (dw_attr_ref a
)
8834 char *sym
= AT_loc_list (a
)->ll_symbol
;
8837 if (dwarf_split_debug_info
)
8838 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8839 "%s", dwarf_attr_name (a
->dw_attr
));
8841 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8842 "%s", dwarf_attr_name (a
->dw_attr
));
8845 /* Output an attribute's index or value appropriately. */
8848 output_attr_index_or_value (dw_attr_ref a
)
8850 const char *name
= dwarf_attr_name (a
->dw_attr
);
8852 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8854 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8857 switch (AT_class (a
))
8859 case dw_val_class_addr
:
8860 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8862 case dw_val_class_high_pc
:
8863 case dw_val_class_lbl_id
:
8864 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8866 case dw_val_class_loc_list
:
8867 output_loc_list_offset (a
);
8874 /* Output a type signature. */
8877 output_signature (const char *sig
, const char *name
)
8881 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8882 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8885 /* Output the DIE and its attributes. Called recursively to generate
8886 the definitions of each child DIE. */
8889 output_die (dw_die_ref die
)
8896 /* If someone in another CU might refer to us, set up a symbol for
8897 them to point to. */
8898 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8899 output_die_symbol (die
);
8901 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8902 (unsigned long)die
->die_offset
,
8903 dwarf_tag_name (die
->die_tag
));
8905 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8907 const char *name
= dwarf_attr_name (a
->dw_attr
);
8909 switch (AT_class (a
))
8911 case dw_val_class_addr
:
8912 output_attr_index_or_value (a
);
8915 case dw_val_class_offset
:
8916 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8920 case dw_val_class_range_list
:
8921 output_range_list_offset (a
);
8924 case dw_val_class_loc
:
8925 size
= size_of_locs (AT_loc (a
));
8927 /* Output the block length for this list of location operations. */
8928 if (dwarf_version
>= 4)
8929 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8931 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8933 output_loc_sequence (AT_loc (a
), -1);
8936 case dw_val_class_const
:
8937 /* ??? It would be slightly more efficient to use a scheme like is
8938 used for unsigned constants below, but gdb 4.x does not sign
8939 extend. Gdb 5.x does sign extend. */
8940 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8943 case dw_val_class_unsigned_const
:
8945 int csize
= constant_size (AT_unsigned (a
));
8946 if (dwarf_version
== 3
8947 && a
->dw_attr
== DW_AT_data_member_location
8949 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8951 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8955 case dw_val_class_const_double
:
8957 unsigned HOST_WIDE_INT first
, second
;
8959 if (HOST_BITS_PER_WIDE_INT
>= 64)
8960 dw2_asm_output_data (1,
8961 HOST_BITS_PER_DOUBLE_INT
8962 / HOST_BITS_PER_CHAR
,
8965 if (WORDS_BIG_ENDIAN
)
8967 first
= a
->dw_attr_val
.v
.val_double
.high
;
8968 second
= a
->dw_attr_val
.v
.val_double
.low
;
8972 first
= a
->dw_attr_val
.v
.val_double
.low
;
8973 second
= a
->dw_attr_val
.v
.val_double
.high
;
8976 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8978 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8983 case dw_val_class_wide_int
:
8986 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8987 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8988 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8989 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8992 if (WORDS_BIG_ENDIAN
)
8993 for (i
= len
- 1; i
>= 0; --i
)
8995 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9000 for (i
= 0; i
< len
; ++i
)
9002 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9009 case dw_val_class_vec
:
9011 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9012 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9016 dw2_asm_output_data (constant_size (len
* elt_size
),
9017 len
* elt_size
, "%s", name
);
9018 if (elt_size
> sizeof (HOST_WIDE_INT
))
9023 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9026 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9027 "fp or vector constant word %u", i
);
9031 case dw_val_class_flag
:
9032 if (dwarf_version
>= 4)
9034 /* Currently all add_AT_flag calls pass in 1 as last argument,
9035 so DW_FORM_flag_present can be used. If that ever changes,
9036 we'll need to use DW_FORM_flag and have some optimization
9037 in build_abbrev_table that will change those to
9038 DW_FORM_flag_present if it is set to 1 in all DIEs using
9039 the same abbrev entry. */
9040 gcc_assert (AT_flag (a
) == 1);
9042 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9043 ASM_COMMENT_START
, name
);
9046 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9049 case dw_val_class_loc_list
:
9050 output_attr_index_or_value (a
);
9053 case dw_val_class_die_ref
:
9054 if (AT_ref_external (a
))
9056 if (AT_ref (a
)->comdat_type_p
)
9058 comdat_type_node_ref type_node
=
9059 AT_ref (a
)->die_id
.die_type_node
;
9061 gcc_assert (type_node
);
9062 output_signature (type_node
->signature
, name
);
9066 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9070 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9071 length, whereas in DWARF3 it's always sized as an
9073 if (dwarf_version
== 2)
9074 size
= DWARF2_ADDR_SIZE
;
9076 size
= DWARF_OFFSET_SIZE
;
9077 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9083 gcc_assert (AT_ref (a
)->die_offset
);
9084 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9089 case dw_val_class_fde_ref
:
9093 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9094 a
->dw_attr_val
.v
.val_fde_index
* 2);
9095 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9100 case dw_val_class_vms_delta
:
9101 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9102 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9103 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9106 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9107 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9112 case dw_val_class_lbl_id
:
9113 output_attr_index_or_value (a
);
9116 case dw_val_class_lineptr
:
9117 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9118 debug_line_section
, "%s", name
);
9121 case dw_val_class_macptr
:
9122 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9123 debug_macinfo_section
, "%s", name
);
9126 case dw_val_class_str
:
9127 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9128 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9129 a
->dw_attr_val
.v
.val_str
->label
,
9131 "%s: \"%s\"", name
, AT_string (a
));
9132 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9133 dw2_asm_output_data_uleb128 (AT_index (a
),
9134 "%s: \"%s\"", name
, AT_string (a
));
9136 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9139 case dw_val_class_file
:
9141 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9143 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9144 a
->dw_attr_val
.v
.val_file
->filename
);
9148 case dw_val_class_data8
:
9152 for (i
= 0; i
< 8; i
++)
9153 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9154 i
== 0 ? "%s" : NULL
, name
);
9158 case dw_val_class_high_pc
:
9159 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9160 get_AT_low_pc (die
), "DW_AT_high_pc");
9168 FOR_EACH_CHILD (die
, c
, output_die (c
));
9170 /* Add null byte to terminate sibling list. */
9171 if (die
->die_child
!= NULL
)
9172 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9173 (unsigned long) die
->die_offset
);
9176 /* Output the compilation unit that appears at the beginning of the
9177 .debug_info section, and precedes the DIE descriptions. */
9180 output_compilation_unit_header (void)
9182 /* We don't support actual DWARFv5 units yet, we just use some
9183 DWARFv5 draft DIE tags in DWARFv4 format. */
9184 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9186 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9187 dw2_asm_output_data (4, 0xffffffff,
9188 "Initial length escape value indicating 64-bit DWARF extension");
9189 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9190 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9191 "Length of Compilation Unit Info");
9192 dw2_asm_output_data (2, ver
, "DWARF version number");
9193 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9194 debug_abbrev_section
,
9195 "Offset Into Abbrev. Section");
9196 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9199 /* Output the compilation unit DIE and its children. */
9202 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9204 const char *secname
, *oldsym
;
9207 /* Unless we are outputting main CU, we may throw away empty ones. */
9208 if (!output_if_empty
&& die
->die_child
== NULL
)
9211 /* Even if there are no children of this DIE, we must output the information
9212 about the compilation unit. Otherwise, on an empty translation unit, we
9213 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9214 will then complain when examining the file. First mark all the DIEs in
9215 this CU so we know which get local refs. */
9218 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9220 build_abbrev_table (die
, extern_map
);
9224 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9225 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9226 calc_die_sizes (die
);
9228 oldsym
= die
->die_id
.die_symbol
;
9231 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9233 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9235 die
->die_id
.die_symbol
= NULL
;
9236 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9240 switch_to_section (debug_info_section
);
9241 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9242 info_section_emitted
= true;
9245 /* Output debugging information. */
9246 output_compilation_unit_header ();
9249 /* Leave the marks on the main CU, so we can check them in
9254 die
->die_id
.die_symbol
= oldsym
;
9258 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9259 and .debug_pubtypes. This is configured per-target, but can be
9260 overridden by the -gpubnames or -gno-pubnames options. */
9263 want_pubnames (void)
9265 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9267 if (debug_generate_pub_sections
!= -1)
9268 return debug_generate_pub_sections
;
9269 return targetm
.want_debug_pub_sections
;
9272 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9275 add_AT_pubnames (dw_die_ref die
)
9277 if (want_pubnames ())
9278 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9281 /* Add a string attribute value to a skeleton DIE. */
9284 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9288 struct indirect_string_node
*node
;
9290 if (! skeleton_debug_str_hash
)
9291 skeleton_debug_str_hash
9292 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9294 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9295 find_string_form (node
);
9296 if (node
->form
== DW_FORM_GNU_str_index
)
9297 node
->form
= DW_FORM_strp
;
9299 attr
.dw_attr
= attr_kind
;
9300 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9301 attr
.dw_attr_val
.val_entry
= NULL
;
9302 attr
.dw_attr_val
.v
.val_str
= node
;
9303 add_dwarf_attr (die
, &attr
);
9306 /* Helper function to generate top-level dies for skeleton debug_info and
9310 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9312 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9313 const char *comp_dir
= comp_dir_string ();
9315 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9316 if (comp_dir
!= NULL
)
9317 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9318 add_AT_pubnames (die
);
9319 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9322 /* Output skeleton debug sections that point to the dwo file. */
9325 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9327 /* We don't support actual DWARFv5 units yet, we just use some
9328 DWARFv5 draft DIE tags in DWARFv4 format. */
9329 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9331 /* These attributes will be found in the full debug_info section. */
9332 remove_AT (comp_unit
, DW_AT_producer
);
9333 remove_AT (comp_unit
, DW_AT_language
);
9335 switch_to_section (debug_skeleton_info_section
);
9336 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9338 /* Produce the skeleton compilation-unit header. This one differs enough from
9339 a normal CU header that it's better not to call output_compilation_unit
9341 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9342 dw2_asm_output_data (4, 0xffffffff,
9343 "Initial length escape value indicating 64-bit DWARF extension");
9345 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9346 DWARF_COMPILE_UNIT_HEADER_SIZE
9347 - DWARF_INITIAL_LENGTH_SIZE
9348 + size_of_die (comp_unit
),
9349 "Length of Compilation Unit Info");
9350 dw2_asm_output_data (2, ver
, "DWARF version number");
9351 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9352 debug_abbrev_section
,
9353 "Offset Into Abbrev. Section");
9354 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9356 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9357 output_die (comp_unit
);
9359 /* Build the skeleton debug_abbrev section. */
9360 switch_to_section (debug_skeleton_abbrev_section
);
9361 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9363 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9365 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9368 /* Output a comdat type unit DIE and its children. */
9371 output_comdat_type_unit (comdat_type_node
*node
)
9373 const char *secname
;
9376 #if defined (OBJECT_FORMAT_ELF)
9380 /* First mark all the DIEs in this CU so we know which get local refs. */
9381 mark_dies (node
->root_die
);
9383 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9385 build_abbrev_table (node
->root_die
, extern_map
);
9390 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9391 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9392 calc_die_sizes (node
->root_die
);
9394 #if defined (OBJECT_FORMAT_ELF)
9395 if (!dwarf_split_debug_info
)
9396 secname
= ".debug_types";
9398 secname
= ".debug_types.dwo";
9400 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9401 sprintf (tmp
, "wt.");
9402 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9403 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9404 comdat_key
= get_identifier (tmp
);
9405 targetm
.asm_out
.named_section (secname
,
9406 SECTION_DEBUG
| SECTION_LINKONCE
,
9409 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9410 sprintf (tmp
, ".gnu.linkonce.wt.");
9411 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9412 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9414 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9417 /* Output debugging information. */
9418 output_compilation_unit_header ();
9419 output_signature (node
->signature
, "Type Signature");
9420 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9421 "Offset to Type DIE");
9422 output_die (node
->root_die
);
9424 unmark_dies (node
->root_die
);
9427 /* Return the DWARF2/3 pubname associated with a decl. */
9430 dwarf2_name (tree decl
, int scope
)
9432 if (DECL_NAMELESS (decl
))
9434 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9437 /* Add a new entry to .debug_pubnames if appropriate. */
9440 add_pubname_string (const char *str
, dw_die_ref die
)
9445 e
.name
= xstrdup (str
);
9446 vec_safe_push (pubname_table
, e
);
9450 add_pubname (tree decl
, dw_die_ref die
)
9452 if (!want_pubnames ())
9455 /* Don't add items to the table when we expect that the consumer will have
9456 just read the enclosing die. For example, if the consumer is looking at a
9457 class_member, it will either be inside the class already, or will have just
9458 looked up the class to find the member. Either way, searching the class is
9459 faster than searching the index. */
9460 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9461 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9463 const char *name
= dwarf2_name (decl
, 1);
9466 add_pubname_string (name
, die
);
9470 /* Add an enumerator to the pubnames section. */
9473 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9477 gcc_assert (scope_name
);
9478 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9480 vec_safe_push (pubname_table
, e
);
9483 /* Add a new entry to .debug_pubtypes if appropriate. */
9486 add_pubtype (tree decl
, dw_die_ref die
)
9490 if (!want_pubnames ())
9493 if ((TREE_PUBLIC (decl
)
9494 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9495 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9498 const char *scope_name
= "";
9499 const char *sep
= is_cxx () ? "::" : ".";
9502 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9503 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9505 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9506 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9507 scope_name
= concat (scope_name
, sep
, NULL
);
9513 name
= type_tag (decl
);
9515 name
= lang_hooks
.dwarf_name (decl
, 1);
9517 /* If we don't have a name for the type, there's no point in adding
9519 if (name
!= NULL
&& name
[0] != '\0')
9522 e
.name
= concat (scope_name
, name
, NULL
);
9523 vec_safe_push (pubtype_table
, e
);
9526 /* Although it might be more consistent to add the pubinfo for the
9527 enumerators as their dies are created, they should only be added if the
9528 enum type meets the criteria above. So rather than re-check the parent
9529 enum type whenever an enumerator die is created, just output them all
9530 here. This isn't protected by the name conditional because anonymous
9531 enums don't have names. */
9532 if (die
->die_tag
== DW_TAG_enumeration_type
)
9536 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9541 /* Output a single entry in the pubnames table. */
9544 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9546 dw_die_ref die
= entry
->die
;
9547 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9549 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9551 if (debug_generate_pub_sections
== 2)
9553 /* This logic follows gdb's method for determining the value of the flag
9555 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9556 switch (die
->die_tag
)
9558 case DW_TAG_typedef
:
9559 case DW_TAG_base_type
:
9560 case DW_TAG_subrange_type
:
9561 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9562 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9564 case DW_TAG_enumerator
:
9565 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9566 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9567 if (!is_cxx () && !is_java ())
9568 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9570 case DW_TAG_subprogram
:
9571 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9572 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9574 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9576 case DW_TAG_constant
:
9577 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9578 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9579 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9581 case DW_TAG_variable
:
9582 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9583 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9584 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9586 case DW_TAG_namespace
:
9587 case DW_TAG_imported_declaration
:
9588 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9590 case DW_TAG_class_type
:
9591 case DW_TAG_interface_type
:
9592 case DW_TAG_structure_type
:
9593 case DW_TAG_union_type
:
9594 case DW_TAG_enumeration_type
:
9595 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9596 if (!is_cxx () && !is_java ())
9597 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9600 /* An unusual tag. Leave the flag-byte empty. */
9603 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9607 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9611 /* Output the public names table used to speed up access to externally
9612 visible names; or the public types table used to find type definitions. */
9615 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9618 unsigned long pubnames_length
= size_of_pubnames (names
);
9621 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9622 dw2_asm_output_data (4, 0xffffffff,
9623 "Initial length escape value indicating 64-bit DWARF extension");
9624 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9626 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9627 dw2_asm_output_data (2, 2, "DWARF Version");
9629 if (dwarf_split_debug_info
)
9630 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9631 debug_skeleton_info_section
,
9632 "Offset of Compilation Unit Info");
9634 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9636 "Offset of Compilation Unit Info");
9637 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9638 "Compilation Unit Length");
9640 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9642 if (include_pubname_in_output (names
, pub
))
9644 dw_offset die_offset
= pub
->die
->die_offset
;
9646 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9647 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9648 gcc_assert (pub
->die
->die_mark
);
9650 /* If we're putting types in their own .debug_types sections,
9651 the .debug_pubtypes table will still point to the compile
9652 unit (not the type unit), so we want to use the offset of
9653 the skeleton DIE (if there is one). */
9654 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9656 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9658 if (type_node
!= NULL
)
9659 die_offset
= (type_node
->skeleton_die
!= NULL
9660 ? type_node
->skeleton_die
->die_offset
9661 : comp_unit_die ()->die_offset
);
9664 output_pubname (die_offset
, pub
);
9668 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9671 /* Output public names and types tables if necessary. */
9674 output_pubtables (void)
9676 if (!want_pubnames () || !info_section_emitted
)
9679 switch_to_section (debug_pubnames_section
);
9680 output_pubnames (pubname_table
);
9681 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9682 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9683 simply won't look for the section. */
9684 switch_to_section (debug_pubtypes_section
);
9685 output_pubnames (pubtype_table
);
9689 /* Output the information that goes into the .debug_aranges table.
9690 Namely, define the beginning and ending address range of the
9691 text section generated for this compilation unit. */
9694 output_aranges (unsigned long aranges_length
)
9698 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9699 dw2_asm_output_data (4, 0xffffffff,
9700 "Initial length escape value indicating 64-bit DWARF extension");
9701 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9702 "Length of Address Ranges Info");
9703 /* Version number for aranges is still 2, even up to DWARF5. */
9704 dw2_asm_output_data (2, 2, "DWARF Version");
9705 if (dwarf_split_debug_info
)
9706 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9707 debug_skeleton_info_section
,
9708 "Offset of Compilation Unit Info");
9710 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9712 "Offset of Compilation Unit Info");
9713 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9714 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9716 /* We need to align to twice the pointer size here. */
9717 if (DWARF_ARANGES_PAD_SIZE
)
9719 /* Pad using a 2 byte words so that padding is correct for any
9721 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9722 2 * DWARF2_ADDR_SIZE
);
9723 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9724 dw2_asm_output_data (2, 0, NULL
);
9727 /* It is necessary not to output these entries if the sections were
9728 not used; if the sections were not used, the length will be 0 and
9729 the address may end up as 0 if the section is discarded by ld
9730 --gc-sections, leaving an invalid (0, 0) entry that can be
9731 confused with the terminator. */
9732 if (text_section_used
)
9734 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9735 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9736 text_section_label
, "Length");
9738 if (cold_text_section_used
)
9740 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9742 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9743 cold_text_section_label
, "Length");
9746 if (have_multiple_function_sections
)
9751 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9753 if (DECL_IGNORED_P (fde
->decl
))
9755 if (!fde
->in_std_section
)
9757 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9759 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9760 fde
->dw_fde_begin
, "Length");
9762 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9764 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9766 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9767 fde
->dw_fde_second_begin
, "Length");
9772 /* Output the terminator words. */
9773 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9774 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9777 /* Add a new entry to .debug_ranges. Return the offset at which it
9781 add_ranges_num (int num
)
9783 unsigned int in_use
= ranges_table_in_use
;
9785 if (in_use
== ranges_table_allocated
)
9787 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9788 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9789 ranges_table_allocated
);
9790 memset (ranges_table
+ ranges_table_in_use
, 0,
9791 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9794 ranges_table
[in_use
].num
= num
;
9795 ranges_table_in_use
= in_use
+ 1;
9797 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9800 /* Add a new entry to .debug_ranges corresponding to a block, or a
9801 range terminator if BLOCK is NULL. */
9804 add_ranges (const_tree block
)
9806 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9809 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9810 When using dwarf_split_debug_info, address attributes in dies destined
9811 for the final executable should be direct references--setting the
9812 parameter force_direct ensures this behavior. */
9815 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9816 bool *added
, bool force_direct
)
9818 unsigned int in_use
= ranges_by_label_in_use
;
9819 unsigned int offset
;
9821 if (in_use
== ranges_by_label_allocated
)
9823 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9824 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9826 ranges_by_label_allocated
);
9827 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9828 RANGES_TABLE_INCREMENT
9829 * sizeof (struct dw_ranges_by_label_struct
));
9832 ranges_by_label
[in_use
].begin
= begin
;
9833 ranges_by_label
[in_use
].end
= end
;
9834 ranges_by_label_in_use
= in_use
+ 1;
9836 offset
= add_ranges_num (-(int)in_use
- 1);
9839 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9845 output_ranges (void)
9848 static const char *const start_fmt
= "Offset %#x";
9849 const char *fmt
= start_fmt
;
9851 for (i
= 0; i
< ranges_table_in_use
; i
++)
9853 int block_num
= ranges_table
[i
].num
;
9857 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9858 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9860 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9861 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9863 /* If all code is in the text section, then the compilation
9864 unit base address defaults to DW_AT_low_pc, which is the
9865 base of the text section. */
9866 if (!have_multiple_function_sections
)
9868 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9870 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9871 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9872 text_section_label
, NULL
);
9875 /* Otherwise, the compilation unit base address is zero,
9876 which allows us to use absolute addresses, and not worry
9877 about whether the target supports cross-section
9881 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9882 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9883 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9889 /* Negative block_num stands for an index into ranges_by_label. */
9890 else if (block_num
< 0)
9892 int lab_idx
= - block_num
- 1;
9894 if (!have_multiple_function_sections
)
9898 /* If we ever use add_ranges_by_labels () for a single
9899 function section, all we have to do is to take out
9901 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9902 ranges_by_label
[lab_idx
].begin
,
9904 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9905 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9906 ranges_by_label
[lab_idx
].end
,
9907 text_section_label
, NULL
);
9912 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9913 ranges_by_label
[lab_idx
].begin
,
9914 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9915 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9916 ranges_by_label
[lab_idx
].end
,
9922 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9923 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9929 /* Data structure containing information about input files. */
9932 const char *path
; /* Complete file name. */
9933 const char *fname
; /* File name part. */
9934 int length
; /* Length of entire string. */
9935 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9936 int dir_idx
; /* Index in directory table. */
9939 /* Data structure containing information about directories with source
9943 const char *path
; /* Path including directory name. */
9944 int length
; /* Path length. */
9945 int prefix
; /* Index of directory entry which is a prefix. */
9946 int count
; /* Number of files in this directory. */
9947 int dir_idx
; /* Index of directory used as base. */
9950 /* Callback function for file_info comparison. We sort by looking at
9951 the directories in the path. */
9954 file_info_cmp (const void *p1
, const void *p2
)
9956 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9957 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9958 const unsigned char *cp1
;
9959 const unsigned char *cp2
;
9961 /* Take care of file names without directories. We need to make sure that
9962 we return consistent values to qsort since some will get confused if
9963 we return the same value when identical operands are passed in opposite
9964 orders. So if neither has a directory, return 0 and otherwise return
9965 1 or -1 depending on which one has the directory. */
9966 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9967 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9969 cp1
= (const unsigned char *) s1
->path
;
9970 cp2
= (const unsigned char *) s2
->path
;
9976 /* Reached the end of the first path? If so, handle like above. */
9977 if ((cp1
== (const unsigned char *) s1
->fname
)
9978 || (cp2
== (const unsigned char *) s2
->fname
))
9979 return ((cp2
== (const unsigned char *) s2
->fname
)
9980 - (cp1
== (const unsigned char *) s1
->fname
));
9982 /* Character of current path component the same? */
9983 else if (*cp1
!= *cp2
)
9988 struct file_name_acquire_data
9990 struct file_info
*files
;
9995 /* Traversal function for the hash table. */
9998 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
10000 struct dwarf_file_data
*d
= *slot
;
10001 struct file_info
*fi
;
10004 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
10006 if (! d
->emitted_number
)
10009 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10011 fi
= fnad
->files
+ fnad
->used_files
++;
10013 /* Skip all leading "./". */
10015 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10018 /* Create a new array entry. */
10020 fi
->length
= strlen (f
);
10023 /* Search for the file name part. */
10024 f
= strrchr (f
, DIR_SEPARATOR
);
10025 #if defined (DIR_SEPARATOR_2)
10027 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10031 if (f
== NULL
|| f
< g
)
10037 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10041 /* Output the directory table and the file name table. We try to minimize
10042 the total amount of memory needed. A heuristic is used to avoid large
10043 slowdowns with many input files. */
10046 output_file_names (void)
10048 struct file_name_acquire_data fnad
;
10050 struct file_info
*files
;
10051 struct dir_info
*dirs
;
10059 if (!last_emitted_file
)
10061 dw2_asm_output_data (1, 0, "End directory table");
10062 dw2_asm_output_data (1, 0, "End file name table");
10066 numfiles
= last_emitted_file
->emitted_number
;
10068 /* Allocate the various arrays we need. */
10069 files
= XALLOCAVEC (struct file_info
, numfiles
);
10070 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10072 fnad
.files
= files
;
10073 fnad
.used_files
= 0;
10074 fnad
.max_files
= numfiles
;
10075 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10076 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10078 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10080 /* Find all the different directories used. */
10081 dirs
[0].path
= files
[0].path
;
10082 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10083 dirs
[0].prefix
= -1;
10085 dirs
[0].dir_idx
= 0;
10086 files
[0].dir_idx
= 0;
10089 for (i
= 1; i
< numfiles
; i
++)
10090 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10091 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10092 dirs
[ndirs
- 1].length
) == 0)
10094 /* Same directory as last entry. */
10095 files
[i
].dir_idx
= ndirs
- 1;
10096 ++dirs
[ndirs
- 1].count
;
10102 /* This is a new directory. */
10103 dirs
[ndirs
].path
= files
[i
].path
;
10104 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10105 dirs
[ndirs
].count
= 1;
10106 dirs
[ndirs
].dir_idx
= ndirs
;
10107 files
[i
].dir_idx
= ndirs
;
10109 /* Search for a prefix. */
10110 dirs
[ndirs
].prefix
= -1;
10111 for (j
= 0; j
< ndirs
; j
++)
10112 if (dirs
[j
].length
< dirs
[ndirs
].length
10113 && dirs
[j
].length
> 1
10114 && (dirs
[ndirs
].prefix
== -1
10115 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10116 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10117 dirs
[ndirs
].prefix
= j
;
10122 /* Now to the actual work. We have to find a subset of the directories which
10123 allow expressing the file name using references to the directory table
10124 with the least amount of characters. We do not do an exhaustive search
10125 where we would have to check out every combination of every single
10126 possible prefix. Instead we use a heuristic which provides nearly optimal
10127 results in most cases and never is much off. */
10128 saved
= XALLOCAVEC (int, ndirs
);
10129 savehere
= XALLOCAVEC (int, ndirs
);
10131 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10132 for (i
= 0; i
< ndirs
; i
++)
10137 /* We can always save some space for the current directory. But this
10138 does not mean it will be enough to justify adding the directory. */
10139 savehere
[i
] = dirs
[i
].length
;
10140 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10142 for (j
= i
+ 1; j
< ndirs
; j
++)
10145 if (saved
[j
] < dirs
[i
].length
)
10147 /* Determine whether the dirs[i] path is a prefix of the
10151 k
= dirs
[j
].prefix
;
10152 while (k
!= -1 && k
!= (int) i
)
10153 k
= dirs
[k
].prefix
;
10157 /* Yes it is. We can possibly save some memory by
10158 writing the filenames in dirs[j] relative to
10160 savehere
[j
] = dirs
[i
].length
;
10161 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10166 /* Check whether we can save enough to justify adding the dirs[i]
10168 if (total
> dirs
[i
].length
+ 1)
10170 /* It's worthwhile adding. */
10171 for (j
= i
; j
< ndirs
; j
++)
10172 if (savehere
[j
] > 0)
10174 /* Remember how much we saved for this directory so far. */
10175 saved
[j
] = savehere
[j
];
10177 /* Remember the prefix directory. */
10178 dirs
[j
].dir_idx
= i
;
10183 /* Emit the directory name table. */
10184 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10185 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10186 dw2_asm_output_nstring (dirs
[i
].path
,
10188 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10189 "Directory Entry: %#x", i
+ idx_offset
);
10191 dw2_asm_output_data (1, 0, "End directory table");
10193 /* We have to emit them in the order of emitted_number since that's
10194 used in the debug info generation. To do this efficiently we
10195 generate a back-mapping of the indices first. */
10196 backmap
= XALLOCAVEC (int, numfiles
);
10197 for (i
= 0; i
< numfiles
; i
++)
10198 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10200 /* Now write all the file names. */
10201 for (i
= 0; i
< numfiles
; i
++)
10203 int file_idx
= backmap
[i
];
10204 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10206 #ifdef VMS_DEBUGGING_INFO
10207 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10209 /* Setting these fields can lead to debugger miscomparisons,
10210 but VMS Debug requires them to be set correctly. */
10215 int maxfilelen
= strlen (files
[file_idx
].path
)
10216 + dirs
[dir_idx
].length
10217 + MAX_VMS_VERSION_LEN
+ 1;
10218 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10220 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10221 snprintf (filebuf
, maxfilelen
, "%s;%d",
10222 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10224 dw2_asm_output_nstring
10225 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10227 /* Include directory index. */
10228 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10230 /* Modification time. */
10231 dw2_asm_output_data_uleb128
10232 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10236 /* File length in bytes. */
10237 dw2_asm_output_data_uleb128
10238 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10242 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10243 "File Entry: %#x", (unsigned) i
+ 1);
10245 /* Include directory index. */
10246 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10248 /* Modification time. */
10249 dw2_asm_output_data_uleb128 (0, NULL
);
10251 /* File length in bytes. */
10252 dw2_asm_output_data_uleb128 (0, NULL
);
10253 #endif /* VMS_DEBUGGING_INFO */
10256 dw2_asm_output_data (1, 0, "End file name table");
10260 /* Output one line number table into the .debug_line section. */
10263 output_one_line_info_table (dw_line_info_table
*table
)
10265 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10266 unsigned int current_line
= 1;
10267 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10268 dw_line_info_entry
*ent
;
10271 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10273 switch (ent
->opcode
)
10275 case LI_set_address
:
10276 /* ??? Unfortunately, we have little choice here currently, and
10277 must always use the most general form. GCC does not know the
10278 address delta itself, so we can't use DW_LNS_advance_pc. Many
10279 ports do have length attributes which will give an upper bound
10280 on the address range. We could perhaps use length attributes
10281 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10282 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10284 /* This can handle any delta. This takes
10285 4+DWARF2_ADDR_SIZE bytes. */
10286 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10287 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10288 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10289 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10293 if (ent
->val
== current_line
)
10295 /* We still need to start a new row, so output a copy insn. */
10296 dw2_asm_output_data (1, DW_LNS_copy
,
10297 "copy line %u", current_line
);
10301 int line_offset
= ent
->val
- current_line
;
10302 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10304 current_line
= ent
->val
;
10305 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10307 /* This can handle deltas from -10 to 234, using the current
10308 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10309 This takes 1 byte. */
10310 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10311 "line %u", current_line
);
10315 /* This can handle any delta. This takes at least 4 bytes,
10316 depending on the value being encoded. */
10317 dw2_asm_output_data (1, DW_LNS_advance_line
,
10318 "advance to line %u", current_line
);
10319 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10320 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10326 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10327 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10330 case LI_set_column
:
10331 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10332 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10335 case LI_negate_stmt
:
10336 current_is_stmt
= !current_is_stmt
;
10337 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10338 "is_stmt %d", current_is_stmt
);
10341 case LI_set_prologue_end
:
10342 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10343 "set prologue end");
10346 case LI_set_epilogue_begin
:
10347 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10348 "set epilogue begin");
10351 case LI_set_discriminator
:
10352 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10353 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10354 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10355 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10360 /* Emit debug info for the address of the end of the table. */
10361 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10362 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10363 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10364 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10366 dw2_asm_output_data (1, 0, "end sequence");
10367 dw2_asm_output_data_uleb128 (1, NULL
);
10368 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10371 /* Output the source line number correspondence information. This
10372 information goes into the .debug_line section. */
10375 output_line_info (bool prologue_only
)
10377 char l1
[20], l2
[20], p1
[20], p2
[20];
10378 /* We don't support DWARFv5 line tables yet. */
10379 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10380 bool saw_one
= false;
10383 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10384 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10385 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10386 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10388 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10389 dw2_asm_output_data (4, 0xffffffff,
10390 "Initial length escape value indicating 64-bit DWARF extension");
10391 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10392 "Length of Source Line Info");
10393 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10395 dw2_asm_output_data (2, ver
, "DWARF Version");
10396 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10397 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10399 /* Define the architecture-dependent minimum instruction length (in bytes).
10400 In this implementation of DWARF, this field is used for information
10401 purposes only. Since GCC generates assembly language, we have no
10402 a priori knowledge of how many instruction bytes are generated for each
10403 source line, and therefore can use only the DW_LNE_set_address and
10404 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10405 this as '1', which is "correct enough" for all architectures,
10406 and don't let the target override. */
10407 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10410 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10411 "Maximum Operations Per Instruction");
10412 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10413 "Default is_stmt_start flag");
10414 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10415 "Line Base Value (Special Opcodes)");
10416 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10417 "Line Range Value (Special Opcodes)");
10418 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10419 "Special Opcode Base");
10421 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10426 case DW_LNS_advance_pc
:
10427 case DW_LNS_advance_line
:
10428 case DW_LNS_set_file
:
10429 case DW_LNS_set_column
:
10430 case DW_LNS_fixed_advance_pc
:
10431 case DW_LNS_set_isa
:
10439 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10443 /* Write out the information about the files we use. */
10444 output_file_names ();
10445 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10448 /* Output the marker for the end of the line number info. */
10449 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10453 if (separate_line_info
)
10455 dw_line_info_table
*table
;
10458 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10461 output_one_line_info_table (table
);
10465 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10467 output_one_line_info_table (cold_text_section_line_info
);
10471 /* ??? Some Darwin linkers crash on a .debug_line section with no
10472 sequences. Further, merely a DW_LNE_end_sequence entry is not
10473 sufficient -- the address column must also be initialized.
10474 Make sure to output at least one set_address/end_sequence pair,
10475 choosing .text since that section is always present. */
10476 if (text_section_line_info
->in_use
|| !saw_one
)
10477 output_one_line_info_table (text_section_line_info
);
10479 /* Output the marker for the end of the line number info. */
10480 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10483 /* Given a pointer to a tree node for some base type, return a pointer to
10484 a DIE that describes the given type.
10486 This routine must only be called for GCC type nodes that correspond to
10487 Dwarf base (fundamental) types. */
10490 base_type_die (tree type
)
10492 dw_die_ref base_type_result
;
10493 enum dwarf_type encoding
;
10495 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10498 /* If this is a subtype that should not be emitted as a subrange type,
10499 use the base type. See subrange_type_for_debug_p. */
10500 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10501 type
= TREE_TYPE (type
);
10503 switch (TREE_CODE (type
))
10506 if ((dwarf_version
>= 4 || !dwarf_strict
)
10507 && TYPE_NAME (type
)
10508 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10509 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10510 && DECL_NAME (TYPE_NAME (type
)))
10512 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10513 if (strcmp (name
, "char16_t") == 0
10514 || strcmp (name
, "char32_t") == 0)
10516 encoding
= DW_ATE_UTF
;
10520 if (TYPE_STRING_FLAG (type
))
10522 if (TYPE_UNSIGNED (type
))
10523 encoding
= DW_ATE_unsigned_char
;
10525 encoding
= DW_ATE_signed_char
;
10527 else if (TYPE_UNSIGNED (type
))
10528 encoding
= DW_ATE_unsigned
;
10530 encoding
= DW_ATE_signed
;
10534 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10536 if (dwarf_version
>= 3 || !dwarf_strict
)
10537 encoding
= DW_ATE_decimal_float
;
10539 encoding
= DW_ATE_lo_user
;
10542 encoding
= DW_ATE_float
;
10545 case FIXED_POINT_TYPE
:
10546 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10547 encoding
= DW_ATE_lo_user
;
10548 else if (TYPE_UNSIGNED (type
))
10549 encoding
= DW_ATE_unsigned_fixed
;
10551 encoding
= DW_ATE_signed_fixed
;
10554 /* Dwarf2 doesn't know anything about complex ints, so use
10555 a user defined type for it. */
10557 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10558 encoding
= DW_ATE_complex_float
;
10560 encoding
= DW_ATE_lo_user
;
10564 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10565 encoding
= DW_ATE_boolean
;
10569 /* No other TREE_CODEs are Dwarf fundamental types. */
10570 gcc_unreachable ();
10573 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10575 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10576 int_size_in_bytes (type
));
10577 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10578 add_pubtype (type
, base_type_result
);
10580 return base_type_result
;
10583 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10584 named 'auto' in its type: return true for it, false otherwise. */
10587 is_cxx_auto (tree type
)
10591 tree name
= TYPE_IDENTIFIER (type
);
10592 if (name
== get_identifier ("auto")
10593 || name
== get_identifier ("decltype(auto)"))
10599 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10600 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10603 is_base_type (tree type
)
10605 switch (TREE_CODE (type
))
10611 case FIXED_POINT_TYPE
:
10614 case POINTER_BOUNDS_TYPE
:
10620 case QUAL_UNION_TYPE
:
10621 case ENUMERAL_TYPE
:
10622 case FUNCTION_TYPE
:
10625 case REFERENCE_TYPE
:
10633 if (is_cxx_auto (type
))
10635 gcc_unreachable ();
10641 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10642 node, return the size in bits for the type if it is a constant, or else
10643 return the alignment for the type if the type's size is not constant, or
10644 else return BITS_PER_WORD if the type actually turns out to be an
10645 ERROR_MARK node. */
10647 static inline unsigned HOST_WIDE_INT
10648 simple_type_size_in_bits (const_tree type
)
10650 if (TREE_CODE (type
) == ERROR_MARK
)
10651 return BITS_PER_WORD
;
10652 else if (TYPE_SIZE (type
) == NULL_TREE
)
10654 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10655 return tree_to_uhwi (TYPE_SIZE (type
));
10657 return TYPE_ALIGN (type
);
10660 /* Similarly, but return an offset_int instead of UHWI. */
10662 static inline offset_int
10663 offset_int_type_size_in_bits (const_tree type
)
10665 if (TREE_CODE (type
) == ERROR_MARK
)
10666 return BITS_PER_WORD
;
10667 else if (TYPE_SIZE (type
) == NULL_TREE
)
10669 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10670 return wi::to_offset (TYPE_SIZE (type
));
10672 return TYPE_ALIGN (type
);
10675 /* Given a pointer to a tree node for a subrange type, return a pointer
10676 to a DIE that describes the given type. */
10679 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10681 dw_die_ref subrange_die
;
10682 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10684 if (context_die
== NULL
)
10685 context_die
= comp_unit_die ();
10687 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10689 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10691 /* The size of the subrange type and its base type do not match,
10692 so we need to generate a size attribute for the subrange type. */
10693 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10697 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
10699 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
10701 return subrange_die
;
10704 /* Returns the (const and/or volatile) cv_qualifiers associated with
10705 the decl node. This will normally be augmented with the
10706 cv_qualifiers of the underlying type in add_type_attribute. */
10709 decl_quals (const_tree decl
)
10711 return ((TREE_READONLY (decl
)
10712 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
10713 | (TREE_THIS_VOLATILE (decl
)
10714 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
10717 /* Determine the TYPE whose qualifiers match the largest strict subset
10718 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10719 qualifiers outside QUAL_MASK. */
10722 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
10725 int best_rank
= 0, best_qual
= 0, max_rank
;
10727 type_quals
&= qual_mask
;
10728 max_rank
= popcount_hwi (type_quals
) - 1;
10730 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
10731 t
= TYPE_NEXT_VARIANT (t
))
10733 int q
= TYPE_QUALS (t
) & qual_mask
;
10735 if ((q
& type_quals
) == q
&& q
!= type_quals
10736 && check_base_type (t
, type
))
10738 int rank
= popcount_hwi (q
);
10740 if (rank
> best_rank
)
10751 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10752 entry that chains various modifiers in front of the given type. */
10755 modified_type_die (tree type
, int cv_quals
, dw_die_ref context_die
)
10757 enum tree_code code
= TREE_CODE (type
);
10758 dw_die_ref mod_type_die
;
10759 dw_die_ref sub_die
= NULL
;
10760 tree item_type
= NULL
;
10761 tree qualified_type
;
10762 tree name
, low
, high
;
10763 dw_die_ref mod_scope
;
10764 /* Only these cv-qualifiers are currently handled. */
10765 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
10766 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
10768 if (code
== ERROR_MARK
)
10771 cv_quals
&= cv_qual_mask
;
10773 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10774 tag modifier (and not an attribute) old consumers won't be able
10776 if (dwarf_version
< 3)
10777 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
10779 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
10780 if (dwarf_version
< 5)
10781 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
10783 /* See if we already have the appropriately qualified variant of
10785 qualified_type
= get_qualified_type (type
, cv_quals
);
10787 if (qualified_type
== sizetype
10788 && TYPE_NAME (qualified_type
)
10789 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10791 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10793 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10794 && TYPE_PRECISION (t
)
10795 == TYPE_PRECISION (qualified_type
)
10796 && TYPE_UNSIGNED (t
)
10797 == TYPE_UNSIGNED (qualified_type
));
10798 qualified_type
= t
;
10801 /* If we do, then we can just use its DIE, if it exists. */
10802 if (qualified_type
)
10804 mod_type_die
= lookup_type_die (qualified_type
);
10806 return mod_type_die
;
10809 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10811 /* Handle C typedef types. */
10812 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10813 && !DECL_ARTIFICIAL (name
))
10815 tree dtype
= TREE_TYPE (name
);
10817 if (qualified_type
== dtype
)
10819 /* For a named type, use the typedef. */
10820 gen_type_die (qualified_type
, context_die
);
10821 return lookup_type_die (qualified_type
);
10825 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
10826 dquals
&= cv_qual_mask
;
10827 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
10828 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
10829 /* cv-unqualified version of named type. Just use
10830 the unnamed type to which it refers. */
10831 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10832 cv_quals
, context_die
);
10833 /* Else cv-qualified version of named type; fall through. */
10837 mod_scope
= scope_die_for (type
, context_die
);
10841 struct qual_info
{ int q
; enum dwarf_tag t
; };
10842 static const struct qual_info qual_info
[] =
10844 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
},
10845 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
10846 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
10847 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
10852 /* Determine a lesser qualified type that most closely matches
10853 this one. Then generate DW_TAG_* entries for the remaining
10855 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
10857 mod_type_die
= modified_type_die (type
, sub_quals
, context_die
);
10859 for (i
= 0; i
< sizeof (qual_info
) / sizeof (qual_info
[0]); i
++)
10860 if (qual_info
[i
].q
& cv_quals
& ~sub_quals
)
10862 dw_die_ref d
= new_die (qual_info
[i
].t
, mod_scope
, type
);
10864 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
10868 else if (code
== POINTER_TYPE
)
10870 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10871 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10872 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10873 item_type
= TREE_TYPE (type
);
10874 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10875 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10876 TYPE_ADDR_SPACE (item_type
));
10878 else if (code
== REFERENCE_TYPE
)
10880 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10881 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10884 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10885 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10886 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10887 item_type
= TREE_TYPE (type
);
10888 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10889 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10890 TYPE_ADDR_SPACE (item_type
));
10892 else if (code
== INTEGER_TYPE
10893 && TREE_TYPE (type
) != NULL_TREE
10894 && subrange_type_for_debug_p (type
, &low
, &high
))
10896 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10897 item_type
= TREE_TYPE (type
);
10899 else if (is_base_type (type
))
10900 mod_type_die
= base_type_die (type
);
10903 gen_type_die (type
, context_die
);
10905 /* We have to get the type_main_variant here (and pass that to the
10906 `lookup_type_die' routine) because the ..._TYPE node we have
10907 might simply be a *copy* of some original type node (where the
10908 copy was created to help us keep track of typedef names) and
10909 that copy might have a different TYPE_UID from the original
10911 if (TREE_CODE (type
) != VECTOR_TYPE
)
10912 return lookup_type_die (type_main_variant (type
));
10914 /* Vectors have the debugging information in the type,
10915 not the main variant. */
10916 return lookup_type_die (type
);
10919 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10920 don't output a DW_TAG_typedef, since there isn't one in the
10921 user's program; just attach a DW_AT_name to the type.
10922 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10923 if the base type already has the same name. */
10925 && ((TREE_CODE (name
) != TYPE_DECL
10926 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10927 || (cv_quals
== TYPE_UNQUALIFIED
)))
10928 || (TREE_CODE (name
) == TYPE_DECL
10929 && TREE_TYPE (name
) == qualified_type
10930 && DECL_NAME (name
))))
10932 if (TREE_CODE (name
) == TYPE_DECL
)
10933 /* Could just call add_name_and_src_coords_attributes here,
10934 but since this is a builtin type it doesn't have any
10935 useful source coordinates anyway. */
10936 name
= DECL_NAME (name
);
10937 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10939 /* This probably indicates a bug. */
10940 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10942 name
= TYPE_IDENTIFIER (type
);
10943 add_name_attribute (mod_type_die
,
10944 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10947 if (qualified_type
)
10948 equate_type_number_to_die (qualified_type
, mod_type_die
);
10951 /* We must do this after the equate_type_number_to_die call, in case
10952 this is a recursive type. This ensures that the modified_type_die
10953 recursion will terminate even if the type is recursive. Recursive
10954 types are possible in Ada. */
10955 sub_die
= modified_type_die (item_type
,
10956 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
10959 if (sub_die
!= NULL
)
10960 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10962 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10963 if (TYPE_ARTIFICIAL (type
))
10964 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10966 return mod_type_die
;
10969 /* Generate DIEs for the generic parameters of T.
10970 T must be either a generic type or a generic function.
10971 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10974 gen_generic_params_dies (tree t
)
10978 dw_die_ref die
= NULL
;
10981 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10985 die
= lookup_type_die (t
);
10986 else if (DECL_P (t
))
10987 die
= lookup_decl_die (t
);
10991 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10993 /* T has no generic parameter. It means T is neither a generic type
10994 or function. End of story. */
10997 parms_num
= TREE_VEC_LENGTH (parms
);
10998 args
= lang_hooks
.get_innermost_generic_args (t
);
10999 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
11000 non_default
= int_cst_value (TREE_CHAIN (args
));
11002 non_default
= TREE_VEC_LENGTH (args
);
11003 for (i
= 0; i
< parms_num
; i
++)
11005 tree parm
, arg
, arg_pack_elems
;
11006 dw_die_ref parm_die
;
11008 parm
= TREE_VEC_ELT (parms
, i
);
11009 arg
= TREE_VEC_ELT (args
, i
);
11010 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11011 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11013 if (parm
&& TREE_VALUE (parm
) && arg
)
11015 /* If PARM represents a template parameter pack,
11016 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11017 by DW_TAG_template_*_parameter DIEs for the argument
11018 pack elements of ARG. Note that ARG would then be
11019 an argument pack. */
11020 if (arg_pack_elems
)
11021 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11025 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11026 true /* emit name */, die
);
11027 if (i
>= non_default
)
11028 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11033 /* Create and return a DIE for PARM which should be
11034 the representation of a generic type parameter.
11035 For instance, in the C++ front end, PARM would be a template parameter.
11036 ARG is the argument to PARM.
11037 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11039 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11040 as a child node. */
11043 generic_parameter_die (tree parm
, tree arg
,
11045 dw_die_ref parent_die
)
11047 dw_die_ref tmpl_die
= NULL
;
11048 const char *name
= NULL
;
11050 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11053 /* We support non-type generic parameters and arguments,
11054 type generic parameters and arguments, as well as
11055 generic generic parameters (a.k.a. template template parameters in C++)
11057 if (TREE_CODE (parm
) == PARM_DECL
)
11058 /* PARM is a nontype generic parameter */
11059 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11060 else if (TREE_CODE (parm
) == TYPE_DECL
)
11061 /* PARM is a type generic parameter. */
11062 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11063 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11064 /* PARM is a generic generic parameter.
11065 Its DIE is a GNU extension. It shall have a
11066 DW_AT_name attribute to represent the name of the template template
11067 parameter, and a DW_AT_GNU_template_name attribute to represent the
11068 name of the template template argument. */
11069 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11072 gcc_unreachable ();
11078 /* If PARM is a generic parameter pack, it means we are
11079 emitting debug info for a template argument pack element.
11080 In other terms, ARG is a template argument pack element.
11081 In that case, we don't emit any DW_AT_name attribute for
11085 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11087 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11090 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11092 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11093 TMPL_DIE should have a child DW_AT_type attribute that is set
11094 to the type of the argument to PARM, which is ARG.
11095 If PARM is a type generic parameter, TMPL_DIE should have a
11096 child DW_AT_type that is set to ARG. */
11097 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11098 add_type_attribute (tmpl_die
, tmpl_type
,
11099 (TREE_THIS_VOLATILE (tmpl_type
)
11100 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11105 /* So TMPL_DIE is a DIE representing a
11106 a generic generic template parameter, a.k.a template template
11107 parameter in C++ and arg is a template. */
11109 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11110 to the name of the argument. */
11111 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11113 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11116 if (TREE_CODE (parm
) == PARM_DECL
)
11117 /* So PARM is a non-type generic parameter.
11118 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11119 attribute of TMPL_DIE which value represents the value
11121 We must be careful here:
11122 The value of ARG might reference some function decls.
11123 We might currently be emitting debug info for a generic
11124 type and types are emitted before function decls, we don't
11125 know if the function decls referenced by ARG will actually be
11126 emitted after cgraph computations.
11127 So must defer the generation of the DW_AT_const_value to
11128 after cgraph is ready. */
11129 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11135 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11136 PARM_PACK must be a template parameter pack. The returned DIE
11137 will be child DIE of PARENT_DIE. */
11140 template_parameter_pack_die (tree parm_pack
,
11141 tree parm_pack_args
,
11142 dw_die_ref parent_die
)
11147 gcc_assert (parent_die
&& parm_pack
);
11149 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11150 add_name_and_src_coords_attributes (die
, parm_pack
);
11151 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11152 generic_parameter_die (parm_pack
,
11153 TREE_VEC_ELT (parm_pack_args
, j
),
11154 false /* Don't emit DW_AT_name */,
11159 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11160 an enumerated type. */
11163 type_is_enum (const_tree type
)
11165 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11168 /* Return the DBX register number described by a given RTL node. */
11170 static unsigned int
11171 dbx_reg_number (const_rtx rtl
)
11173 unsigned regno
= REGNO (rtl
);
11175 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11177 #ifdef LEAF_REG_REMAP
11178 if (crtl
->uses_only_leaf_regs
)
11180 int leaf_reg
= LEAF_REG_REMAP (regno
);
11181 if (leaf_reg
!= -1)
11182 regno
= (unsigned) leaf_reg
;
11186 regno
= DBX_REGISTER_NUMBER (regno
);
11187 gcc_assert (regno
!= INVALID_REGNUM
);
11191 /* Optionally add a DW_OP_piece term to a location description expression.
11192 DW_OP_piece is only added if the location description expression already
11193 doesn't end with DW_OP_piece. */
11196 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11198 dw_loc_descr_ref loc
;
11200 if (*list_head
!= NULL
)
11202 /* Find the end of the chain. */
11203 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11206 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11207 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11211 /* Return a location descriptor that designates a machine register or
11212 zero if there is none. */
11214 static dw_loc_descr_ref
11215 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11219 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11222 /* We only use "frame base" when we're sure we're talking about the
11223 post-prologue local stack frame. We do this by *not* running
11224 register elimination until this point, and recognizing the special
11225 argument pointer and soft frame pointer rtx's.
11226 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11227 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11228 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11230 dw_loc_descr_ref result
= NULL
;
11232 if (dwarf_version
>= 4 || !dwarf_strict
)
11234 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11237 add_loc_descr (&result
,
11238 new_loc_descr (DW_OP_stack_value
, 0, 0));
11243 regs
= targetm
.dwarf_register_span (rtl
);
11245 if (REG_NREGS (rtl
) > 1 || regs
)
11246 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11249 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11250 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11252 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11256 /* Return a location descriptor that designates a machine register for
11257 a given hard register number. */
11259 static dw_loc_descr_ref
11260 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11262 dw_loc_descr_ref reg_loc_descr
;
11266 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11268 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11270 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11271 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11273 return reg_loc_descr
;
11276 /* Given an RTL of a register, return a location descriptor that
11277 designates a value that spans more than one register. */
11279 static dw_loc_descr_ref
11280 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11281 enum var_init_status initialized
)
11284 dw_loc_descr_ref loc_result
= NULL
;
11286 /* Simple, contiguous registers. */
11287 if (regs
== NULL_RTX
)
11289 unsigned reg
= REGNO (rtl
);
11292 #ifdef LEAF_REG_REMAP
11293 if (crtl
->uses_only_leaf_regs
)
11295 int leaf_reg
= LEAF_REG_REMAP (reg
);
11296 if (leaf_reg
!= -1)
11297 reg
= (unsigned) leaf_reg
;
11301 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11302 nregs
= REG_NREGS (rtl
);
11304 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11309 dw_loc_descr_ref t
;
11311 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11312 VAR_INIT_STATUS_INITIALIZED
);
11313 add_loc_descr (&loc_result
, t
);
11314 add_loc_descr_op_piece (&loc_result
, size
);
11320 /* Now onto stupid register sets in non contiguous locations. */
11322 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11324 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11327 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11329 dw_loc_descr_ref t
;
11331 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11332 VAR_INIT_STATUS_INITIALIZED
);
11333 add_loc_descr (&loc_result
, t
);
11334 add_loc_descr_op_piece (&loc_result
, size
);
11337 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11338 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11342 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11344 /* Return a location descriptor that designates a constant i,
11345 as a compound operation from constant (i >> shift), constant shift
11348 static dw_loc_descr_ref
11349 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11351 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11352 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11353 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11357 /* Return a location descriptor that designates a constant. */
11359 static dw_loc_descr_ref
11360 int_loc_descriptor (HOST_WIDE_INT i
)
11362 enum dwarf_location_atom op
;
11364 /* Pick the smallest representation of a constant, rather than just
11365 defaulting to the LEB encoding. */
11368 int clz
= clz_hwi (i
);
11369 int ctz
= ctz_hwi (i
);
11371 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11372 else if (i
<= 0xff)
11373 op
= DW_OP_const1u
;
11374 else if (i
<= 0xffff)
11375 op
= DW_OP_const2u
;
11376 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11377 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11378 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11379 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11380 while DW_OP_const4u is 5 bytes. */
11381 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11382 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11383 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11384 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11385 while DW_OP_const4u is 5 bytes. */
11386 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11387 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11388 op
= DW_OP_const4u
;
11389 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11390 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11391 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11392 while DW_OP_constu of constant >= 0x100000000 takes at least
11394 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11395 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11396 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11397 >= HOST_BITS_PER_WIDE_INT
)
11398 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11399 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11400 while DW_OP_constu takes in this case at least 6 bytes. */
11401 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11402 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11403 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11404 && size_of_uleb128 (i
) > 6)
11405 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11406 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11413 op
= DW_OP_const1s
;
11414 else if (i
>= -0x8000)
11415 op
= DW_OP_const2s
;
11416 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11418 if (size_of_int_loc_descriptor (i
) < 5)
11420 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11421 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11424 op
= DW_OP_const4s
;
11428 if (size_of_int_loc_descriptor (i
)
11429 < (unsigned long) 1 + size_of_sleb128 (i
))
11431 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11432 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11439 return new_loc_descr (op
, i
, 0);
11442 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11443 without actually allocating it. */
11445 static unsigned long
11446 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11448 return size_of_int_loc_descriptor (i
>> shift
)
11449 + size_of_int_loc_descriptor (shift
)
11453 /* Return size_of_locs (int_loc_descriptor (i)) without
11454 actually allocating it. */
11456 static unsigned long
11457 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11466 else if (i
<= 0xff)
11468 else if (i
<= 0xffff)
11472 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11473 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11474 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11476 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11477 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11478 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11480 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11482 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11483 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11484 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11485 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11487 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11488 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11489 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11491 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11492 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11494 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11503 else if (i
>= -0x8000)
11505 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11507 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11509 s
= size_of_int_loc_descriptor (-i
) + 1;
11517 unsigned long r
= 1 + size_of_sleb128 (i
);
11518 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11520 s
= size_of_int_loc_descriptor (-i
) + 1;
11529 /* Return loc description representing "address" of integer value.
11530 This can appear only as toplevel expression. */
11532 static dw_loc_descr_ref
11533 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11536 dw_loc_descr_ref loc_result
= NULL
;
11538 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11541 litsize
= size_of_int_loc_descriptor (i
);
11542 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11543 is more compact. For DW_OP_stack_value we need:
11544 litsize + 1 (DW_OP_stack_value)
11545 and for DW_OP_implicit_value:
11546 1 (DW_OP_implicit_value) + 1 (length) + size. */
11547 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11549 loc_result
= int_loc_descriptor (i
);
11550 add_loc_descr (&loc_result
,
11551 new_loc_descr (DW_OP_stack_value
, 0, 0));
11555 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11557 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11558 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11562 /* Return a location descriptor that designates a base+offset location. */
11564 static dw_loc_descr_ref
11565 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11566 enum var_init_status initialized
)
11568 unsigned int regno
;
11569 dw_loc_descr_ref result
;
11570 dw_fde_ref fde
= cfun
->fde
;
11572 /* We only use "frame base" when we're sure we're talking about the
11573 post-prologue local stack frame. We do this by *not* running
11574 register elimination until this point, and recognizing the special
11575 argument pointer and soft frame pointer rtx's. */
11576 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11578 rtx elim
= (ira_use_lra_p
11579 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11580 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11584 if (GET_CODE (elim
) == PLUS
)
11586 offset
+= INTVAL (XEXP (elim
, 1));
11587 elim
= XEXP (elim
, 0);
11589 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11590 && (elim
== hard_frame_pointer_rtx
11591 || elim
== stack_pointer_rtx
))
11592 || elim
== (frame_pointer_needed
11593 ? hard_frame_pointer_rtx
11594 : stack_pointer_rtx
));
11596 /* If drap register is used to align stack, use frame
11597 pointer + offset to access stack variables. If stack
11598 is aligned without drap, use stack pointer + offset to
11599 access stack variables. */
11600 if (crtl
->stack_realign_tried
11601 && reg
== frame_pointer_rtx
)
11604 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11605 ? HARD_FRAME_POINTER_REGNUM
11607 return new_reg_loc_descr (base_reg
, offset
);
11610 gcc_assert (frame_pointer_fb_offset_valid
);
11611 offset
+= frame_pointer_fb_offset
;
11612 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11616 regno
= REGNO (reg
);
11617 #ifdef LEAF_REG_REMAP
11618 if (crtl
->uses_only_leaf_regs
)
11620 int leaf_reg
= LEAF_REG_REMAP (regno
);
11621 if (leaf_reg
!= -1)
11622 regno
= (unsigned) leaf_reg
;
11625 regno
= DWARF_FRAME_REGNUM (regno
);
11627 if (!optimize
&& fde
11628 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11630 /* Use cfa+offset to represent the location of arguments passed
11631 on the stack when drap is used to align stack.
11632 Only do this when not optimizing, for optimized code var-tracking
11633 is supposed to track where the arguments live and the register
11634 used as vdrap or drap in some spot might be used for something
11635 else in other part of the routine. */
11636 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11640 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11643 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11645 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11646 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11651 /* Return true if this RTL expression describes a base+offset calculation. */
11654 is_based_loc (const_rtx rtl
)
11656 return (GET_CODE (rtl
) == PLUS
11657 && ((REG_P (XEXP (rtl
, 0))
11658 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11659 && CONST_INT_P (XEXP (rtl
, 1)))));
11662 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11665 static dw_loc_descr_ref
11666 tls_mem_loc_descriptor (rtx mem
)
11669 dw_loc_descr_ref loc_result
;
11671 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11674 base
= get_base_address (MEM_EXPR (mem
));
11676 || TREE_CODE (base
) != VAR_DECL
11677 || !DECL_THREAD_LOCAL_P (base
))
11680 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
11681 if (loc_result
== NULL
)
11684 if (MEM_OFFSET (mem
))
11685 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11690 /* Output debug info about reason why we failed to expand expression as dwarf
11694 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11696 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11698 fprintf (dump_file
, "Failed to expand as dwarf: ");
11700 print_generic_expr (dump_file
, expr
, dump_flags
);
11703 fprintf (dump_file
, "\n");
11704 print_rtl (dump_file
, rtl
);
11706 fprintf (dump_file
, "\nReason: %s\n", reason
);
11710 /* Helper function for const_ok_for_output. */
11713 const_ok_for_output_1 (rtx rtl
)
11715 if (GET_CODE (rtl
) == UNSPEC
)
11717 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11718 we can't express it in the debug info. */
11719 #ifdef ENABLE_CHECKING
11720 /* Don't complain about TLS UNSPECs, those are just too hard to
11721 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11722 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11723 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11724 if (XVECLEN (rtl
, 0) == 0
11725 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11726 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11727 inform (current_function_decl
11728 ? DECL_SOURCE_LOCATION (current_function_decl
)
11729 : UNKNOWN_LOCATION
,
11730 #if NUM_UNSPEC_VALUES > 0
11731 "non-delegitimized UNSPEC %s (%d) found in variable location",
11732 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11733 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11736 "non-delegitimized UNSPEC %d found in variable location",
11740 expansion_failed (NULL_TREE
, rtl
,
11741 "UNSPEC hasn't been delegitimized.\n");
11745 if (targetm
.const_not_ok_for_debug_p (rtl
))
11747 expansion_failed (NULL_TREE
, rtl
,
11748 "Expression rejected for debug by the backend.\n");
11752 /* FIXME: Refer to PR60655. It is possible for simplification
11753 of rtl expressions in var tracking to produce such expressions.
11754 We should really identify / validate expressions
11755 enclosed in CONST that can be handled by assemblers on various
11756 targets and only handle legitimate cases here. */
11757 if (GET_CODE (rtl
) != SYMBOL_REF
)
11759 if (GET_CODE (rtl
) == NOT
)
11764 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11767 get_pool_constant_mark (rtl
, &marked
);
11768 /* If all references to this pool constant were optimized away,
11769 it was not output and thus we can't represent it. */
11772 expansion_failed (NULL_TREE
, rtl
,
11773 "Constant was removed from constant pool.\n");
11778 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11781 /* Avoid references to external symbols in debug info, on several targets
11782 the linker might even refuse to link when linking a shared library,
11783 and in many other cases the relocations for .debug_info/.debug_loc are
11784 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11785 to be defined within the same shared library or executable are fine. */
11786 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11788 tree decl
= SYMBOL_REF_DECL (rtl
);
11790 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11792 expansion_failed (NULL_TREE
, rtl
,
11793 "Symbol not defined in current TU.\n");
11801 /* Return true if constant RTL can be emitted in DW_OP_addr or
11802 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11803 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11806 const_ok_for_output (rtx rtl
)
11808 if (GET_CODE (rtl
) == SYMBOL_REF
)
11809 return const_ok_for_output_1 (rtl
);
11811 if (GET_CODE (rtl
) == CONST
)
11813 subrtx_var_iterator::array_type array
;
11814 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
11815 if (!const_ok_for_output_1 (*iter
))
11823 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11824 if possible, NULL otherwise. */
11827 base_type_for_mode (machine_mode mode
, bool unsignedp
)
11829 dw_die_ref type_die
;
11830 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11834 switch (TREE_CODE (type
))
11842 type_die
= lookup_type_die (type
);
11844 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, comp_unit_die ());
11845 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11850 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11851 type matching MODE, or, if MODE is narrower than or as wide as
11852 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11855 static dw_loc_descr_ref
11856 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
11858 machine_mode outer_mode
= mode
;
11859 dw_die_ref type_die
;
11860 dw_loc_descr_ref cvt
;
11862 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11864 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11867 type_die
= base_type_for_mode (outer_mode
, 1);
11868 if (type_die
== NULL
)
11870 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11871 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11872 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11873 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11874 add_loc_descr (&op
, cvt
);
11878 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11880 static dw_loc_descr_ref
11881 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11882 dw_loc_descr_ref op1
)
11884 dw_loc_descr_ref ret
= op0
;
11885 add_loc_descr (&ret
, op1
);
11886 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11887 if (STORE_FLAG_VALUE
!= 1)
11889 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11890 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11895 /* Return location descriptor for signed comparison OP RTL. */
11897 static dw_loc_descr_ref
11898 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11899 machine_mode mem_mode
)
11901 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11902 dw_loc_descr_ref op0
, op1
;
11905 if (op_mode
== VOIDmode
)
11906 op_mode
= GET_MODE (XEXP (rtl
, 1));
11907 if (op_mode
== VOIDmode
)
11911 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11912 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11915 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11916 VAR_INIT_STATUS_INITIALIZED
);
11917 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11918 VAR_INIT_STATUS_INITIALIZED
);
11920 if (op0
== NULL
|| op1
== NULL
)
11923 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11924 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11925 return compare_loc_descriptor (op
, op0
, op1
);
11927 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11929 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11930 dw_loc_descr_ref cvt
;
11932 if (type_die
== NULL
)
11934 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11935 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11936 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11937 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11938 add_loc_descr (&op0
, cvt
);
11939 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11940 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11941 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11942 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11943 add_loc_descr (&op1
, cvt
);
11944 return compare_loc_descriptor (op
, op0
, op1
);
11947 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11948 /* For eq/ne, if the operands are known to be zero-extended,
11949 there is no need to do the fancy shifting up. */
11950 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11952 dw_loc_descr_ref last0
, last1
;
11953 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11955 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11957 /* deref_size zero extends, and for constants we can check
11958 whether they are zero extended or not. */
11959 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11960 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11961 || (CONST_INT_P (XEXP (rtl
, 0))
11962 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11963 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11964 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11965 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11966 || (CONST_INT_P (XEXP (rtl
, 1))
11967 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11968 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11969 return compare_loc_descriptor (op
, op0
, op1
);
11971 /* EQ/NE comparison against constant in narrower type than
11972 DWARF2_ADDR_SIZE can be performed either as
11973 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11976 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11977 DW_OP_{eq,ne}. Pick whatever is shorter. */
11978 if (CONST_INT_P (XEXP (rtl
, 1))
11979 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11980 && (size_of_int_loc_descriptor (shift
) + 1
11981 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11982 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11983 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11984 & GET_MODE_MASK (op_mode
))))
11986 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11987 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11988 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11989 & GET_MODE_MASK (op_mode
));
11990 return compare_loc_descriptor (op
, op0
, op1
);
11993 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11994 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11995 if (CONST_INT_P (XEXP (rtl
, 1)))
11996 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11999 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12000 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12002 return compare_loc_descriptor (op
, op0
, op1
);
12005 /* Return location descriptor for unsigned comparison OP RTL. */
12007 static dw_loc_descr_ref
12008 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12009 machine_mode mem_mode
)
12011 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12012 dw_loc_descr_ref op0
, op1
;
12014 if (op_mode
== VOIDmode
)
12015 op_mode
= GET_MODE (XEXP (rtl
, 1));
12016 if (op_mode
== VOIDmode
)
12018 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
12021 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12024 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12025 VAR_INIT_STATUS_INITIALIZED
);
12026 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12027 VAR_INIT_STATUS_INITIALIZED
);
12029 if (op0
== NULL
|| op1
== NULL
)
12032 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12034 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12035 dw_loc_descr_ref last0
, last1
;
12036 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12038 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12040 if (CONST_INT_P (XEXP (rtl
, 0)))
12041 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12042 /* deref_size zero extends, so no need to mask it again. */
12043 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12044 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12046 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12047 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12049 if (CONST_INT_P (XEXP (rtl
, 1)))
12050 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12051 /* deref_size zero extends, so no need to mask it again. */
12052 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12053 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12055 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12056 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12059 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12061 HOST_WIDE_INT bias
= 1;
12062 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12063 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12064 if (CONST_INT_P (XEXP (rtl
, 1)))
12065 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12066 + INTVAL (XEXP (rtl
, 1)));
12068 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12071 return compare_loc_descriptor (op
, op0
, op1
);
12074 /* Return location descriptor for {U,S}{MIN,MAX}. */
12076 static dw_loc_descr_ref
12077 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12078 machine_mode mem_mode
)
12080 enum dwarf_location_atom op
;
12081 dw_loc_descr_ref op0
, op1
, ret
;
12082 dw_loc_descr_ref bra_node
, drop_node
;
12085 && (GET_MODE_CLASS (mode
) != MODE_INT
12086 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12089 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12090 VAR_INIT_STATUS_INITIALIZED
);
12091 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12092 VAR_INIT_STATUS_INITIALIZED
);
12094 if (op0
== NULL
|| op1
== NULL
)
12097 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12098 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12099 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12100 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12102 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12104 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12105 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12106 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12107 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12108 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12110 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12112 HOST_WIDE_INT bias
= 1;
12113 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12114 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12115 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12118 else if (GET_MODE_CLASS (mode
) == MODE_INT
12119 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12121 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12122 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12123 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12124 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12125 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12127 else if (GET_MODE_CLASS (mode
) == MODE_INT
12128 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12130 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12131 dw_loc_descr_ref cvt
;
12132 if (type_die
== NULL
)
12134 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12135 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12136 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12137 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12138 add_loc_descr (&op0
, cvt
);
12139 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12140 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12141 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12142 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12143 add_loc_descr (&op1
, cvt
);
12146 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12151 add_loc_descr (&ret
, op1
);
12152 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12153 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12154 add_loc_descr (&ret
, bra_node
);
12155 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12156 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12157 add_loc_descr (&ret
, drop_node
);
12158 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12159 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12160 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12161 && GET_MODE_CLASS (mode
) == MODE_INT
12162 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12163 ret
= convert_descriptor_to_mode (mode
, ret
);
12167 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12168 but after converting arguments to type_die, afterwards
12169 convert back to unsigned. */
12171 static dw_loc_descr_ref
12172 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12173 machine_mode mode
, machine_mode mem_mode
)
12175 dw_loc_descr_ref cvt
, op0
, op1
;
12177 if (type_die
== NULL
)
12179 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12180 VAR_INIT_STATUS_INITIALIZED
);
12181 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12182 VAR_INIT_STATUS_INITIALIZED
);
12183 if (op0
== NULL
|| op1
== NULL
)
12185 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12186 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12187 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12188 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12189 add_loc_descr (&op0
, cvt
);
12190 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12191 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12192 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12193 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12194 add_loc_descr (&op1
, cvt
);
12195 add_loc_descr (&op0
, op1
);
12196 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12197 return convert_descriptor_to_mode (mode
, op0
);
12200 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12201 const0 is DW_OP_lit0 or corresponding typed constant,
12202 const1 is DW_OP_lit1 or corresponding typed constant
12203 and constMSB is constant with just the MSB bit set
12205 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12206 L1: const0 DW_OP_swap
12207 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12208 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12213 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12214 L1: const0 DW_OP_swap
12215 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12216 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12221 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12222 L1: const1 DW_OP_swap
12223 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12224 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12228 static dw_loc_descr_ref
12229 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12230 machine_mode mem_mode
)
12232 dw_loc_descr_ref op0
, ret
, tmp
;
12233 HOST_WIDE_INT valv
;
12234 dw_loc_descr_ref l1jump
, l1label
;
12235 dw_loc_descr_ref l2jump
, l2label
;
12236 dw_loc_descr_ref l3jump
, l3label
;
12237 dw_loc_descr_ref l4jump
, l4label
;
12240 if (GET_MODE_CLASS (mode
) != MODE_INT
12241 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12244 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12245 VAR_INIT_STATUS_INITIALIZED
);
12249 if (GET_CODE (rtl
) == CLZ
)
12251 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12252 valv
= GET_MODE_BITSIZE (mode
);
12254 else if (GET_CODE (rtl
) == FFS
)
12256 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12257 valv
= GET_MODE_BITSIZE (mode
);
12258 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12259 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12260 add_loc_descr (&ret
, l1jump
);
12261 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12262 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12263 VAR_INIT_STATUS_INITIALIZED
);
12266 add_loc_descr (&ret
, tmp
);
12267 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12268 add_loc_descr (&ret
, l4jump
);
12269 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12270 ? const1_rtx
: const0_rtx
,
12272 VAR_INIT_STATUS_INITIALIZED
);
12273 if (l1label
== NULL
)
12275 add_loc_descr (&ret
, l1label
);
12276 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12277 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12278 add_loc_descr (&ret
, l2label
);
12279 if (GET_CODE (rtl
) != CLZ
)
12281 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12282 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12283 << (GET_MODE_BITSIZE (mode
) - 1));
12285 msb
= immed_wide_int_const
12286 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12287 GET_MODE_PRECISION (mode
)), mode
);
12288 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12289 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12290 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12291 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12293 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12294 VAR_INIT_STATUS_INITIALIZED
);
12297 add_loc_descr (&ret
, tmp
);
12298 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12299 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12300 add_loc_descr (&ret
, l3jump
);
12301 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12302 VAR_INIT_STATUS_INITIALIZED
);
12305 add_loc_descr (&ret
, tmp
);
12306 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12307 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12308 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12309 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12310 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12311 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12312 add_loc_descr (&ret
, l2jump
);
12313 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12314 add_loc_descr (&ret
, l3label
);
12315 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12316 add_loc_descr (&ret
, l4label
);
12317 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12318 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12319 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12320 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12321 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12322 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12323 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12324 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12328 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12329 const1 is DW_OP_lit1 or corresponding typed constant):
12331 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12332 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12336 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12337 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12340 static dw_loc_descr_ref
12341 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
12342 machine_mode mem_mode
)
12344 dw_loc_descr_ref op0
, ret
, tmp
;
12345 dw_loc_descr_ref l1jump
, l1label
;
12346 dw_loc_descr_ref l2jump
, l2label
;
12348 if (GET_MODE_CLASS (mode
) != MODE_INT
12349 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12352 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12353 VAR_INIT_STATUS_INITIALIZED
);
12357 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12358 VAR_INIT_STATUS_INITIALIZED
);
12361 add_loc_descr (&ret
, tmp
);
12362 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12363 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12364 add_loc_descr (&ret
, l1label
);
12365 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12366 add_loc_descr (&ret
, l2jump
);
12367 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12368 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12369 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12370 VAR_INIT_STATUS_INITIALIZED
);
12373 add_loc_descr (&ret
, tmp
);
12374 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12375 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12376 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12377 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12378 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12379 VAR_INIT_STATUS_INITIALIZED
);
12380 add_loc_descr (&ret
, tmp
);
12381 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12382 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12383 add_loc_descr (&ret
, l1jump
);
12384 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12385 add_loc_descr (&ret
, l2label
);
12386 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12387 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12388 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12389 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12393 /* BSWAP (constS is initial shift count, either 56 or 24):
12395 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12396 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12397 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12398 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12399 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12401 static dw_loc_descr_ref
12402 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
12403 machine_mode mem_mode
)
12405 dw_loc_descr_ref op0
, ret
, tmp
;
12406 dw_loc_descr_ref l1jump
, l1label
;
12407 dw_loc_descr_ref l2jump
, l2label
;
12409 if (GET_MODE_CLASS (mode
) != MODE_INT
12410 || BITS_PER_UNIT
!= 8
12411 || (GET_MODE_BITSIZE (mode
) != 32
12412 && GET_MODE_BITSIZE (mode
) != 64))
12415 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12416 VAR_INIT_STATUS_INITIALIZED
);
12421 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12423 VAR_INIT_STATUS_INITIALIZED
);
12426 add_loc_descr (&ret
, tmp
);
12427 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12428 VAR_INIT_STATUS_INITIALIZED
);
12431 add_loc_descr (&ret
, tmp
);
12432 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12433 add_loc_descr (&ret
, l1label
);
12434 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12436 VAR_INIT_STATUS_INITIALIZED
);
12437 add_loc_descr (&ret
, tmp
);
12438 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12439 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12440 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12441 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12442 VAR_INIT_STATUS_INITIALIZED
);
12445 add_loc_descr (&ret
, tmp
);
12446 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12447 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12448 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12449 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12450 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12451 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12452 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12453 VAR_INIT_STATUS_INITIALIZED
);
12454 add_loc_descr (&ret
, tmp
);
12455 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12456 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12457 add_loc_descr (&ret
, l2jump
);
12458 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12459 VAR_INIT_STATUS_INITIALIZED
);
12460 add_loc_descr (&ret
, tmp
);
12461 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12462 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12463 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12464 add_loc_descr (&ret
, l1jump
);
12465 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12466 add_loc_descr (&ret
, l2label
);
12467 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12468 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12469 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12470 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12471 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12472 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12476 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12477 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12478 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12479 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12481 ROTATERT is similar:
12482 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12483 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12484 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12486 static dw_loc_descr_ref
12487 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
12488 machine_mode mem_mode
)
12490 rtx rtlop1
= XEXP (rtl
, 1);
12491 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12494 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12497 if (GET_MODE (rtlop1
) != VOIDmode
12498 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12499 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12500 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12501 VAR_INIT_STATUS_INITIALIZED
);
12502 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12503 VAR_INIT_STATUS_INITIALIZED
);
12504 if (op0
== NULL
|| op1
== NULL
)
12506 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12507 for (i
= 0; i
< 2; i
++)
12509 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12510 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12512 VAR_INIT_STATUS_INITIALIZED
);
12513 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12514 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12516 : HOST_BITS_PER_WIDE_INT
== 64
12517 ? DW_OP_const8u
: DW_OP_constu
,
12518 GET_MODE_MASK (mode
), 0);
12521 if (mask
[i
] == NULL
)
12523 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12526 add_loc_descr (&ret
, op1
);
12527 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12528 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12529 if (GET_CODE (rtl
) == ROTATERT
)
12531 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12532 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12533 GET_MODE_BITSIZE (mode
), 0));
12535 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12536 if (mask
[0] != NULL
)
12537 add_loc_descr (&ret
, mask
[0]);
12538 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12539 if (mask
[1] != NULL
)
12541 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12542 add_loc_descr (&ret
, mask
[1]);
12543 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12545 if (GET_CODE (rtl
) == ROTATE
)
12547 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12548 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12549 GET_MODE_BITSIZE (mode
), 0));
12551 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12552 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12556 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12557 for DEBUG_PARAMETER_REF RTL. */
12559 static dw_loc_descr_ref
12560 parameter_ref_descriptor (rtx rtl
)
12562 dw_loc_descr_ref ret
;
12567 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12568 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12569 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12572 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12573 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12574 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12578 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12579 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12584 /* The following routine converts the RTL for a variable or parameter
12585 (resident in memory) into an equivalent Dwarf representation of a
12586 mechanism for getting the address of that same variable onto the top of a
12587 hypothetical "address evaluation" stack.
12589 When creating memory location descriptors, we are effectively transforming
12590 the RTL for a memory-resident object into its Dwarf postfix expression
12591 equivalent. This routine recursively descends an RTL tree, turning
12592 it into Dwarf postfix code as it goes.
12594 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12596 MEM_MODE is the mode of the memory reference, needed to handle some
12597 autoincrement addressing modes.
12599 Return 0 if we can't represent the location. */
12602 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
12603 machine_mode mem_mode
,
12604 enum var_init_status initialized
)
12606 dw_loc_descr_ref mem_loc_result
= NULL
;
12607 enum dwarf_location_atom op
;
12608 dw_loc_descr_ref op0
, op1
;
12609 rtx inner
= NULL_RTX
;
12611 if (mode
== VOIDmode
)
12612 mode
= GET_MODE (rtl
);
12614 /* Note that for a dynamically sized array, the location we will generate a
12615 description of here will be the lowest numbered location which is
12616 actually within the array. That's *not* necessarily the same as the
12617 zeroth element of the array. */
12619 rtl
= targetm
.delegitimize_address (rtl
);
12621 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12624 switch (GET_CODE (rtl
))
12629 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12632 /* The case of a subreg may arise when we have a local (register)
12633 variable or a formal (register) parameter which doesn't quite fill
12634 up an entire register. For now, just assume that it is
12635 legitimate to make the Dwarf info refer to the whole register which
12636 contains the given subreg. */
12637 if (!subreg_lowpart_p (rtl
))
12639 inner
= SUBREG_REG (rtl
);
12641 if (inner
== NULL_RTX
)
12642 inner
= XEXP (rtl
, 0);
12643 if (GET_MODE_CLASS (mode
) == MODE_INT
12644 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12645 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12646 #ifdef POINTERS_EXTEND_UNSIGNED
12647 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12650 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12652 mem_loc_result
= mem_loc_descriptor (inner
,
12654 mem_mode
, initialized
);
12659 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12661 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12662 && (GET_MODE_CLASS (mode
) != MODE_INT
12663 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12667 dw_die_ref type_die
;
12668 dw_loc_descr_ref cvt
;
12670 mem_loc_result
= mem_loc_descriptor (inner
,
12672 mem_mode
, initialized
);
12673 if (mem_loc_result
== NULL
)
12675 type_die
= base_type_for_mode (mode
,
12676 GET_MODE_CLASS (mode
) == MODE_INT
);
12677 if (type_die
== NULL
)
12679 mem_loc_result
= NULL
;
12682 if (GET_MODE_SIZE (mode
)
12683 != GET_MODE_SIZE (GET_MODE (inner
)))
12684 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12686 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12687 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12688 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12689 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12690 add_loc_descr (&mem_loc_result
, cvt
);
12695 if (GET_MODE_CLASS (mode
) != MODE_INT
12696 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12697 && rtl
!= arg_pointer_rtx
12698 && rtl
!= frame_pointer_rtx
12699 #ifdef POINTERS_EXTEND_UNSIGNED
12700 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12704 dw_die_ref type_die
;
12705 unsigned int dbx_regnum
;
12709 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12711 type_die
= base_type_for_mode (mode
,
12712 GET_MODE_CLASS (mode
) == MODE_INT
);
12713 if (type_die
== NULL
)
12716 dbx_regnum
= dbx_reg_number (rtl
);
12717 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12719 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12721 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12722 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12723 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12726 /* Whenever a register number forms a part of the description of the
12727 method for calculating the (dynamic) address of a memory resident
12728 object, DWARF rules require the register number be referred to as
12729 a "base register". This distinction is not based in any way upon
12730 what category of register the hardware believes the given register
12731 belongs to. This is strictly DWARF terminology we're dealing with
12732 here. Note that in cases where the location of a memory-resident
12733 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12734 OP_CONST (0)) the actual DWARF location descriptor that we generate
12735 may just be OP_BASEREG (basereg). This may look deceptively like
12736 the object in question was allocated to a register (rather than in
12737 memory) so DWARF consumers need to be aware of the subtle
12738 distinction between OP_REG and OP_BASEREG. */
12739 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12740 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12741 else if (stack_realign_drap
12743 && crtl
->args
.internal_arg_pointer
== rtl
12744 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12746 /* If RTL is internal_arg_pointer, which has been optimized
12747 out, use DRAP instead. */
12748 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12749 VAR_INIT_STATUS_INITIALIZED
);
12755 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12757 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12758 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12761 else if (GET_CODE (rtl
) == ZERO_EXTEND
12762 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12763 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12764 < HOST_BITS_PER_WIDE_INT
12765 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12766 to expand zero extend as two shifts instead of
12768 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12770 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12771 mem_loc_result
= op0
;
12772 add_loc_descr (&mem_loc_result
,
12773 int_loc_descriptor (GET_MODE_MASK (imode
)));
12774 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12776 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12778 int shift
= DWARF2_ADDR_SIZE
12779 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12780 shift
*= BITS_PER_UNIT
;
12781 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12785 mem_loc_result
= op0
;
12786 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12787 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12788 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12789 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12791 else if (!dwarf_strict
)
12793 dw_die_ref type_die1
, type_die2
;
12794 dw_loc_descr_ref cvt
;
12796 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12797 GET_CODE (rtl
) == ZERO_EXTEND
);
12798 if (type_die1
== NULL
)
12800 type_die2
= base_type_for_mode (mode
, 1);
12801 if (type_die2
== NULL
)
12803 mem_loc_result
= op0
;
12804 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12805 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12806 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12807 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12808 add_loc_descr (&mem_loc_result
, cvt
);
12809 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12810 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12811 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12812 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12813 add_loc_descr (&mem_loc_result
, cvt
);
12819 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12820 if (new_rtl
!= rtl
)
12822 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12824 if (mem_loc_result
!= NULL
)
12825 return mem_loc_result
;
12828 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12829 get_address_mode (rtl
), mode
,
12830 VAR_INIT_STATUS_INITIALIZED
);
12831 if (mem_loc_result
== NULL
)
12832 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12833 if (mem_loc_result
!= NULL
)
12835 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12836 || GET_MODE_CLASS (mode
) != MODE_INT
)
12838 dw_die_ref type_die
;
12839 dw_loc_descr_ref deref
;
12844 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12845 if (type_die
== NULL
)
12847 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12848 GET_MODE_SIZE (mode
), 0);
12849 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12850 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12851 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12852 add_loc_descr (&mem_loc_result
, deref
);
12854 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12855 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12857 add_loc_descr (&mem_loc_result
,
12858 new_loc_descr (DW_OP_deref_size
,
12859 GET_MODE_SIZE (mode
), 0));
12864 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12867 /* Some ports can transform a symbol ref into a label ref, because
12868 the symbol ref is too far away and has to be dumped into a constant
12872 if ((GET_MODE_CLASS (mode
) != MODE_INT
12873 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
12874 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12875 #ifdef POINTERS_EXTEND_UNSIGNED
12876 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12880 if (GET_CODE (rtl
) == SYMBOL_REF
12881 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12883 dw_loc_descr_ref temp
;
12885 /* If this is not defined, we have no way to emit the data. */
12886 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12889 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12891 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12892 add_loc_descr (&mem_loc_result
, temp
);
12897 if (!const_ok_for_output (rtl
))
12899 if (GET_CODE (rtl
) == CONST
)
12900 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12906 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12907 vec_safe_push (used_rtx_array
, rtl
);
12913 case DEBUG_IMPLICIT_PTR
:
12914 expansion_failed (NULL_TREE
, rtl
,
12915 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12921 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12923 if (GET_MODE_CLASS (mode
) != MODE_INT
12924 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12925 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12926 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12929 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12930 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12932 op0
= one_reg_loc_descriptor (dbx_regnum
,
12933 VAR_INIT_STATUS_INITIALIZED
);
12936 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12937 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12939 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12940 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12941 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12945 gcc_unreachable ();
12948 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12949 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12950 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12953 case DEBUG_PARAMETER_REF
:
12954 mem_loc_result
= parameter_ref_descriptor (rtl
);
12958 /* Extract the PLUS expression nested inside and fall into
12959 PLUS code below. */
12960 rtl
= XEXP (rtl
, 1);
12965 /* Turn these into a PLUS expression and fall into the PLUS code
12967 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12968 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12969 ? GET_MODE_UNIT_SIZE (mem_mode
)
12970 : -GET_MODE_UNIT_SIZE (mem_mode
),
12973 /* ... fall through ... */
12977 if (is_based_loc (rtl
)
12978 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12979 || XEXP (rtl
, 0) == arg_pointer_rtx
12980 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12981 && GET_MODE_CLASS (mode
) == MODE_INT
)
12982 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12983 INTVAL (XEXP (rtl
, 1)),
12984 VAR_INIT_STATUS_INITIALIZED
);
12987 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12988 VAR_INIT_STATUS_INITIALIZED
);
12989 if (mem_loc_result
== 0)
12992 if (CONST_INT_P (XEXP (rtl
, 1))
12993 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12994 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12997 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12998 VAR_INIT_STATUS_INITIALIZED
);
13001 add_loc_descr (&mem_loc_result
, op1
);
13002 add_loc_descr (&mem_loc_result
,
13003 new_loc_descr (DW_OP_plus
, 0, 0));
13008 /* If a pseudo-reg is optimized away, it is possible for it to
13009 be replaced with a MEM containing a multiply or shift. */
13020 && GET_MODE_CLASS (mode
) == MODE_INT
13021 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13023 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13024 base_type_for_mode (mode
, 0),
13048 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13050 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13051 VAR_INIT_STATUS_INITIALIZED
);
13053 rtx rtlop1
= XEXP (rtl
, 1);
13054 if (GET_MODE (rtlop1
) != VOIDmode
13055 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13056 < GET_MODE_BITSIZE (mode
))
13057 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13058 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13059 VAR_INIT_STATUS_INITIALIZED
);
13062 if (op0
== 0 || op1
== 0)
13065 mem_loc_result
= op0
;
13066 add_loc_descr (&mem_loc_result
, op1
);
13067 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13083 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13084 VAR_INIT_STATUS_INITIALIZED
);
13085 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13086 VAR_INIT_STATUS_INITIALIZED
);
13088 if (op0
== 0 || op1
== 0)
13091 mem_loc_result
= op0
;
13092 add_loc_descr (&mem_loc_result
, op1
);
13093 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13097 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13099 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13100 base_type_for_mode (mode
, 0),
13105 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13106 VAR_INIT_STATUS_INITIALIZED
);
13107 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13108 VAR_INIT_STATUS_INITIALIZED
);
13110 if (op0
== 0 || op1
== 0)
13113 mem_loc_result
= op0
;
13114 add_loc_descr (&mem_loc_result
, op1
);
13115 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13116 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13117 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13118 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13119 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13123 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
13125 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13130 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13131 base_type_for_mode (mode
, 1),
13149 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13150 VAR_INIT_STATUS_INITIALIZED
);
13155 mem_loc_result
= op0
;
13156 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13160 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13161 #ifdef POINTERS_EXTEND_UNSIGNED
13163 && mem_mode
!= VOIDmode
13164 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13168 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13172 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13173 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13175 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13176 machine_mode amode
;
13177 if (type_die
== NULL
)
13179 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13181 if (INTVAL (rtl
) >= 0
13182 && amode
!= BLKmode
13183 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13184 /* const DW_OP_GNU_convert <XXX> vs.
13185 DW_OP_GNU_const_type <XXX, 1, const>. */
13186 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13187 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13189 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13190 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13191 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13192 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13193 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13194 add_loc_descr (&mem_loc_result
, op0
);
13195 return mem_loc_result
;
13197 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13199 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13200 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13201 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13202 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13203 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13206 mem_loc_result
->dw_loc_oprnd2
.val_class
13207 = dw_val_class_const_double
;
13208 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13209 = double_int::from_shwi (INTVAL (rtl
));
13217 dw_die_ref type_die
;
13219 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13220 CONST_DOUBLE rtx could represent either a large integer
13221 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13222 the value is always a floating point constant.
13224 When it is an integer, a CONST_DOUBLE is used whenever
13225 the constant requires 2 HWIs to be adequately represented.
13226 We output CONST_DOUBLEs as blocks. */
13227 if (mode
== VOIDmode
13228 || (GET_MODE (rtl
) == VOIDmode
13229 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13231 type_die
= base_type_for_mode (mode
,
13232 GET_MODE_CLASS (mode
) == MODE_INT
);
13233 if (type_die
== NULL
)
13235 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13236 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13237 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13238 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13239 #if TARGET_SUPPORTS_WIDE_INT == 0
13240 if (!SCALAR_FLOAT_MODE_P (mode
))
13242 mem_loc_result
->dw_loc_oprnd2
.val_class
13243 = dw_val_class_const_double
;
13244 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13245 = rtx_to_double_int (rtl
);
13250 unsigned int length
= GET_MODE_SIZE (mode
);
13251 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13253 insert_float (rtl
, array
);
13254 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13255 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13256 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13257 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13262 case CONST_WIDE_INT
:
13265 dw_die_ref type_die
;
13267 type_die
= base_type_for_mode (mode
,
13268 GET_MODE_CLASS (mode
) == MODE_INT
);
13269 if (type_die
== NULL
)
13271 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13272 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13273 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13274 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13275 mem_loc_result
->dw_loc_oprnd2
.val_class
13276 = dw_val_class_wide_int
;
13277 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13278 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13283 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13287 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13291 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13295 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13299 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13303 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
13307 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13311 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13315 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13319 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13324 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13329 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13334 if (CONST_INT_P (XEXP (rtl
, 1))
13335 && CONST_INT_P (XEXP (rtl
, 2))
13336 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13337 + (unsigned) INTVAL (XEXP (rtl
, 2))
13338 <= GET_MODE_BITSIZE (mode
))
13339 && GET_MODE_CLASS (mode
) == MODE_INT
13340 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13341 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13344 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13345 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13348 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13352 mem_loc_result
= op0
;
13353 size
= INTVAL (XEXP (rtl
, 1));
13354 shift
= INTVAL (XEXP (rtl
, 2));
13355 if (BITS_BIG_ENDIAN
)
13356 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13358 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13360 add_loc_descr (&mem_loc_result
,
13361 int_loc_descriptor (DWARF2_ADDR_SIZE
13363 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13365 if (size
!= (int) DWARF2_ADDR_SIZE
)
13367 add_loc_descr (&mem_loc_result
,
13368 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13369 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13376 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13377 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13378 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13379 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13380 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13381 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13382 VAR_INIT_STATUS_INITIALIZED
);
13383 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13384 VAR_INIT_STATUS_INITIALIZED
);
13385 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13388 mem_loc_result
= op1
;
13389 add_loc_descr (&mem_loc_result
, op2
);
13390 add_loc_descr (&mem_loc_result
, op0
);
13391 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13392 add_loc_descr (&mem_loc_result
, bra_node
);
13393 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13394 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13395 add_loc_descr (&mem_loc_result
, drop_node
);
13396 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13397 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13402 case FLOAT_TRUNCATE
:
13404 case UNSIGNED_FLOAT
:
13409 dw_die_ref type_die
;
13410 dw_loc_descr_ref cvt
;
13412 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13413 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13416 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13417 && (GET_CODE (rtl
) == FLOAT
13418 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13419 <= DWARF2_ADDR_SIZE
))
13421 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13422 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13423 if (type_die
== NULL
)
13425 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13426 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13427 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13428 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13429 add_loc_descr (&op0
, cvt
);
13431 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13432 if (type_die
== NULL
)
13434 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13435 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13436 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13437 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13438 add_loc_descr (&op0
, cvt
);
13439 if (GET_MODE_CLASS (mode
) == MODE_INT
13440 && (GET_CODE (rtl
) == FIX
13441 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13443 op0
= convert_descriptor_to_mode (mode
, op0
);
13447 mem_loc_result
= op0
;
13454 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13459 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13463 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13468 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13472 /* In theory, we could implement the above. */
13473 /* DWARF cannot represent the unsigned compare operations
13498 case FRACT_CONVERT
:
13499 case UNSIGNED_FRACT_CONVERT
:
13501 case UNSIGNED_SAT_FRACT
:
13507 case VEC_DUPLICATE
:
13511 case STRICT_LOW_PART
:
13516 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13517 can't express it in the debug info. This can happen e.g. with some
13522 resolve_one_addr (&rtl
);
13526 #ifdef ENABLE_CHECKING
13527 print_rtl (stderr
, rtl
);
13528 gcc_unreachable ();
13534 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13535 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13537 return mem_loc_result
;
13540 /* Return a descriptor that describes the concatenation of two locations.
13541 This is typically a complex variable. */
13543 static dw_loc_descr_ref
13544 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13546 dw_loc_descr_ref cc_loc_result
= NULL
;
13547 dw_loc_descr_ref x0_ref
13548 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13549 dw_loc_descr_ref x1_ref
13550 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13552 if (x0_ref
== 0 || x1_ref
== 0)
13555 cc_loc_result
= x0_ref
;
13556 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13558 add_loc_descr (&cc_loc_result
, x1_ref
);
13559 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13561 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13562 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13564 return cc_loc_result
;
13567 /* Return a descriptor that describes the concatenation of N
13570 static dw_loc_descr_ref
13571 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13574 dw_loc_descr_ref cc_loc_result
= NULL
;
13575 unsigned int n
= XVECLEN (concatn
, 0);
13577 for (i
= 0; i
< n
; ++i
)
13579 dw_loc_descr_ref ref
;
13580 rtx x
= XVECEXP (concatn
, 0, i
);
13582 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13586 add_loc_descr (&cc_loc_result
, ref
);
13587 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13590 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13591 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13593 return cc_loc_result
;
13596 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13597 for DEBUG_IMPLICIT_PTR RTL. */
13599 static dw_loc_descr_ref
13600 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13602 dw_loc_descr_ref ret
;
13607 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13608 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13609 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13610 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13611 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13612 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13615 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13616 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13617 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13621 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13622 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13627 /* Output a proper Dwarf location descriptor for a variable or parameter
13628 which is either allocated in a register or in a memory location. For a
13629 register, we just generate an OP_REG and the register number. For a
13630 memory location we provide a Dwarf postfix expression describing how to
13631 generate the (dynamic) address of the object onto the address stack.
13633 MODE is mode of the decl if this loc_descriptor is going to be used in
13634 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13635 allowed, VOIDmode otherwise.
13637 If we don't know how to describe it, return 0. */
13639 static dw_loc_descr_ref
13640 loc_descriptor (rtx rtl
, machine_mode mode
,
13641 enum var_init_status initialized
)
13643 dw_loc_descr_ref loc_result
= NULL
;
13645 switch (GET_CODE (rtl
))
13648 /* The case of a subreg may arise when we have a local (register)
13649 variable or a formal (register) parameter which doesn't quite fill
13650 up an entire register. For now, just assume that it is
13651 legitimate to make the Dwarf info refer to the whole register which
13652 contains the given subreg. */
13653 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13654 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13655 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13661 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13665 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13666 GET_MODE (rtl
), initialized
);
13667 if (loc_result
== NULL
)
13668 loc_result
= tls_mem_loc_descriptor (rtl
);
13669 if (loc_result
== NULL
)
13671 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13672 if (new_rtl
!= rtl
)
13673 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13678 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13683 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13688 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13690 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13691 if (GET_CODE (loc
) == EXPR_LIST
)
13692 loc
= XEXP (loc
, 0);
13693 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13697 rtl
= XEXP (rtl
, 1);
13702 rtvec par_elems
= XVEC (rtl
, 0);
13703 int num_elem
= GET_NUM_ELEM (par_elems
);
13707 /* Create the first one, so we have something to add to. */
13708 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13709 VOIDmode
, initialized
);
13710 if (loc_result
== NULL
)
13712 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13713 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13714 for (i
= 1; i
< num_elem
; i
++)
13716 dw_loc_descr_ref temp
;
13718 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13719 VOIDmode
, initialized
);
13722 add_loc_descr (&loc_result
, temp
);
13723 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13724 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13730 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13731 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13736 if (mode
== VOIDmode
)
13737 mode
= GET_MODE (rtl
);
13739 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13741 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13743 /* Note that a CONST_DOUBLE rtx could represent either an integer
13744 or a floating-point constant. A CONST_DOUBLE is used whenever
13745 the constant requires more than one word in order to be
13746 adequately represented. We output CONST_DOUBLEs as blocks. */
13747 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13748 GET_MODE_SIZE (mode
), 0);
13749 #if TARGET_SUPPORTS_WIDE_INT == 0
13750 if (!SCALAR_FLOAT_MODE_P (mode
))
13752 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13753 loc_result
->dw_loc_oprnd2
.v
.val_double
13754 = rtx_to_double_int (rtl
);
13759 unsigned int length
= GET_MODE_SIZE (mode
);
13760 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13762 insert_float (rtl
, array
);
13763 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13764 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13765 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13766 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13771 case CONST_WIDE_INT
:
13772 if (mode
== VOIDmode
)
13773 mode
= GET_MODE (rtl
);
13775 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13777 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13778 GET_MODE_SIZE (mode
), 0);
13779 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13780 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13781 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13786 if (mode
== VOIDmode
)
13787 mode
= GET_MODE (rtl
);
13789 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13791 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13792 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13793 unsigned char *array
13794 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
13797 machine_mode imode
= GET_MODE_INNER (mode
);
13799 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13800 switch (GET_MODE_CLASS (mode
))
13802 case MODE_VECTOR_INT
:
13803 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13805 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13806 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13810 case MODE_VECTOR_FLOAT
:
13811 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13813 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13814 insert_float (elt
, p
);
13819 gcc_unreachable ();
13822 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13823 length
* elt_size
, 0);
13824 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13825 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13826 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13827 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13832 if (mode
== VOIDmode
13833 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13834 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13835 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13837 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13842 if (!const_ok_for_output (rtl
))
13845 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13846 && (dwarf_version
>= 4 || !dwarf_strict
))
13848 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13849 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13850 vec_safe_push (used_rtx_array
, rtl
);
13854 case DEBUG_IMPLICIT_PTR
:
13855 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13859 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13860 && CONST_INT_P (XEXP (rtl
, 1)))
13863 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13869 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13870 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13871 && dwarf_version
>= 4)
13872 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13874 /* Value expression. */
13875 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13877 add_loc_descr (&loc_result
,
13878 new_loc_descr (DW_OP_stack_value
, 0, 0));
13886 /* We need to figure out what section we should use as the base for the
13887 address ranges where a given location is valid.
13888 1. If this particular DECL has a section associated with it, use that.
13889 2. If this function has a section associated with it, use that.
13890 3. Otherwise, use the text section.
13891 XXX: If you split a variable across multiple sections, we won't notice. */
13893 static const char *
13894 secname_for_decl (const_tree decl
)
13896 const char *secname
;
13898 if (VAR_OR_FUNCTION_DECL_P (decl
)
13899 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
13900 && DECL_SECTION_NAME (decl
))
13901 secname
= DECL_SECTION_NAME (decl
);
13902 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13903 secname
= DECL_SECTION_NAME (current_function_decl
);
13904 else if (cfun
&& in_cold_section_p
)
13905 secname
= crtl
->subsections
.cold_section_label
;
13907 secname
= text_section_label
;
13912 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13915 decl_by_reference_p (tree decl
)
13917 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13918 || TREE_CODE (decl
) == VAR_DECL
)
13919 && DECL_BY_REFERENCE (decl
));
13922 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13925 static dw_loc_descr_ref
13926 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13927 enum var_init_status initialized
)
13929 int have_address
= 0;
13930 dw_loc_descr_ref descr
;
13933 if (want_address
!= 2)
13935 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13937 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13939 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13940 if (GET_CODE (varloc
) == EXPR_LIST
)
13941 varloc
= XEXP (varloc
, 0);
13942 mode
= GET_MODE (varloc
);
13943 if (MEM_P (varloc
))
13945 rtx addr
= XEXP (varloc
, 0);
13946 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13947 mode
, initialized
);
13952 rtx x
= avoid_constant_pool_reference (varloc
);
13954 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13959 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13966 if (GET_CODE (varloc
) == VAR_LOCATION
)
13967 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13969 mode
= DECL_MODE (loc
);
13970 descr
= loc_descriptor (varloc
, mode
, initialized
);
13977 if (want_address
== 2 && !have_address
13978 && (dwarf_version
>= 4 || !dwarf_strict
))
13980 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13982 expansion_failed (loc
, NULL_RTX
,
13983 "DWARF address size mismatch");
13986 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13989 /* Show if we can't fill the request for an address. */
13990 if (want_address
&& !have_address
)
13992 expansion_failed (loc
, NULL_RTX
,
13993 "Want address and only have value");
13997 /* If we've got an address and don't want one, dereference. */
13998 if (!want_address
&& have_address
)
14000 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14001 enum dwarf_location_atom op
;
14003 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14005 expansion_failed (loc
, NULL_RTX
,
14006 "DWARF address size mismatch");
14009 else if (size
== DWARF2_ADDR_SIZE
)
14012 op
= DW_OP_deref_size
;
14014 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14020 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14021 if it is not possible. */
14023 static dw_loc_descr_ref
14024 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14026 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14027 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14028 else if (dwarf_version
>= 3 || !dwarf_strict
)
14029 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14034 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14035 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14037 static dw_loc_descr_ref
14038 dw_sra_loc_expr (tree decl
, rtx loc
)
14041 unsigned HOST_WIDE_INT padsize
= 0;
14042 dw_loc_descr_ref descr
, *descr_tail
;
14043 unsigned HOST_WIDE_INT decl_size
;
14045 enum var_init_status initialized
;
14047 if (DECL_SIZE (decl
) == NULL
14048 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14051 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14053 descr_tail
= &descr
;
14055 for (p
= loc
; p
; p
= XEXP (p
, 1))
14057 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14058 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14059 dw_loc_descr_ref cur_descr
;
14060 dw_loc_descr_ref
*tail
, last
= NULL
;
14061 unsigned HOST_WIDE_INT opsize
= 0;
14063 if (loc_note
== NULL_RTX
14064 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14066 padsize
+= bitsize
;
14069 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14070 varloc
= NOTE_VAR_LOCATION (loc_note
);
14071 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14072 if (cur_descr
== NULL
)
14074 padsize
+= bitsize
;
14078 /* Check that cur_descr either doesn't use
14079 DW_OP_*piece operations, or their sum is equal
14080 to bitsize. Otherwise we can't embed it. */
14081 for (tail
= &cur_descr
; *tail
!= NULL
;
14082 tail
= &(*tail
)->dw_loc_next
)
14083 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14085 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14089 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14091 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14095 if (last
!= NULL
&& opsize
!= bitsize
)
14097 padsize
+= bitsize
;
14098 /* Discard the current piece of the descriptor and release any
14099 addr_table entries it uses. */
14100 remove_loc_list_addr_table_entries (cur_descr
);
14104 /* If there is a hole, add DW_OP_*piece after empty DWARF
14105 expression, which means that those bits are optimized out. */
14108 if (padsize
> decl_size
)
14110 remove_loc_list_addr_table_entries (cur_descr
);
14111 goto discard_descr
;
14113 decl_size
-= padsize
;
14114 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14115 if (*descr_tail
== NULL
)
14117 remove_loc_list_addr_table_entries (cur_descr
);
14118 goto discard_descr
;
14120 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14123 *descr_tail
= cur_descr
;
14125 if (bitsize
> decl_size
)
14126 goto discard_descr
;
14127 decl_size
-= bitsize
;
14130 HOST_WIDE_INT offset
= 0;
14131 if (GET_CODE (varloc
) == VAR_LOCATION
14132 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14134 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14135 if (GET_CODE (varloc
) == EXPR_LIST
)
14136 varloc
= XEXP (varloc
, 0);
14140 if (GET_CODE (varloc
) == CONST
14141 || GET_CODE (varloc
) == SIGN_EXTEND
14142 || GET_CODE (varloc
) == ZERO_EXTEND
)
14143 varloc
= XEXP (varloc
, 0);
14144 else if (GET_CODE (varloc
) == SUBREG
)
14145 varloc
= SUBREG_REG (varloc
);
14150 /* DW_OP_bit_size offset should be zero for register
14151 or implicit location descriptions and empty location
14152 descriptions, but for memory addresses needs big endian
14154 if (MEM_P (varloc
))
14156 unsigned HOST_WIDE_INT memsize
14157 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14158 if (memsize
!= bitsize
)
14160 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14161 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14162 goto discard_descr
;
14163 if (memsize
< bitsize
)
14164 goto discard_descr
;
14165 if (BITS_BIG_ENDIAN
)
14166 offset
= memsize
- bitsize
;
14170 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14171 if (*descr_tail
== NULL
)
14172 goto discard_descr
;
14173 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14177 /* If there were any non-empty expressions, add padding till the end of
14179 if (descr
!= NULL
&& decl_size
!= 0)
14181 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14182 if (*descr_tail
== NULL
)
14183 goto discard_descr
;
14188 /* Discard the descriptor and release any addr_table entries it uses. */
14189 remove_loc_list_addr_table_entries (descr
);
14193 /* Return the dwarf representation of the location list LOC_LIST of
14194 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14197 static dw_loc_list_ref
14198 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14200 const char *endname
, *secname
;
14202 enum var_init_status initialized
;
14203 struct var_loc_node
*node
;
14204 dw_loc_descr_ref descr
;
14205 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14206 dw_loc_list_ref list
= NULL
;
14207 dw_loc_list_ref
*listp
= &list
;
14209 /* Now that we know what section we are using for a base,
14210 actually construct the list of locations.
14211 The first location information is what is passed to the
14212 function that creates the location list, and the remaining
14213 locations just get added on to that list.
14214 Note that we only know the start address for a location
14215 (IE location changes), so to build the range, we use
14216 the range [current location start, next location start].
14217 This means we have to special case the last node, and generate
14218 a range of [last location start, end of function label]. */
14220 secname
= secname_for_decl (decl
);
14222 for (node
= loc_list
->first
; node
; node
= node
->next
)
14223 if (GET_CODE (node
->loc
) == EXPR_LIST
14224 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14226 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14228 /* This requires DW_OP_{,bit_}piece, which is not usable
14229 inside DWARF expressions. */
14230 if (want_address
!= 2)
14232 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14238 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14239 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14240 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14244 bool range_across_switch
= false;
14245 /* If section switch happens in between node->label
14246 and node->next->label (or end of function) and
14247 we can't emit it as a single entry list,
14248 emit two ranges, first one ending at the end
14249 of first partition and second one starting at the
14250 beginning of second partition. */
14251 if (node
== loc_list
->last_before_switch
14252 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14253 && current_function_decl
)
14255 endname
= cfun
->fde
->dw_fde_end
;
14256 range_across_switch
= true;
14258 /* The variable has a location between NODE->LABEL and
14259 NODE->NEXT->LABEL. */
14260 else if (node
->next
)
14261 endname
= node
->next
->label
;
14262 /* If the variable has a location at the last label
14263 it keeps its location until the end of function. */
14264 else if (!current_function_decl
)
14265 endname
= text_end_label
;
14268 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14269 current_function_funcdef_no
);
14270 endname
= ggc_strdup (label_id
);
14273 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14274 if (TREE_CODE (decl
) == PARM_DECL
14275 && node
== loc_list
->first
14276 && NOTE_P (node
->loc
)
14277 && strcmp (node
->label
, endname
) == 0)
14278 (*listp
)->force
= true;
14279 listp
= &(*listp
)->dw_loc_next
;
14281 if (range_across_switch
)
14283 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14284 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14287 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14288 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14289 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
14292 gcc_assert (descr
);
14293 /* The variable has a location between NODE->LABEL and
14294 NODE->NEXT->LABEL. */
14296 endname
= node
->next
->label
;
14298 endname
= cfun
->fde
->dw_fde_second_end
;
14299 *listp
= new_loc_list (descr
,
14300 cfun
->fde
->dw_fde_second_begin
,
14302 listp
= &(*listp
)->dw_loc_next
;
14307 /* Try to avoid the overhead of a location list emitting a location
14308 expression instead, but only if we didn't have more than one
14309 location entry in the first place. If some entries were not
14310 representable, we don't want to pretend a single entry that was
14311 applies to the entire scope in which the variable is
14313 if (list
&& loc_list
->first
->next
)
14319 /* Return if the loc_list has only single element and thus can be represented
14320 as location description. */
14323 single_element_loc_list_p (dw_loc_list_ref list
)
14325 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14326 return !list
->ll_symbol
;
14329 /* To each location in list LIST add loc descr REF. */
14332 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14334 dw_loc_descr_ref copy
;
14335 add_loc_descr (&list
->expr
, ref
);
14336 list
= list
->dw_loc_next
;
14339 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14340 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14341 add_loc_descr (&list
->expr
, copy
);
14342 while (copy
->dw_loc_next
)
14344 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14345 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14346 copy
->dw_loc_next
= new_copy
;
14349 list
= list
->dw_loc_next
;
14353 /* Given two lists RET and LIST
14354 produce location list that is result of adding expression in LIST
14355 to expression in RET on each position in program.
14356 Might be destructive on both RET and LIST.
14358 TODO: We handle only simple cases of RET or LIST having at most one
14359 element. General case would inolve sorting the lists in program order
14360 and merging them that will need some additional work.
14361 Adding that will improve quality of debug info especially for SRA-ed
14365 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14374 if (!list
->dw_loc_next
)
14376 add_loc_descr_to_each (*ret
, list
->expr
);
14379 if (!(*ret
)->dw_loc_next
)
14381 add_loc_descr_to_each (list
, (*ret
)->expr
);
14385 expansion_failed (NULL_TREE
, NULL_RTX
,
14386 "Don't know how to merge two non-trivial"
14387 " location lists.\n");
14392 /* LOC is constant expression. Try a luck, look it up in constant
14393 pool and return its loc_descr of its address. */
14395 static dw_loc_descr_ref
14396 cst_pool_loc_descr (tree loc
)
14398 /* Get an RTL for this, if something has been emitted. */
14399 rtx rtl
= lookup_constant_def (loc
);
14401 if (!rtl
|| !MEM_P (rtl
))
14406 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14408 /* TODO: We might get more coverage if we was actually delaying expansion
14409 of all expressions till end of compilation when constant pools are fully
14411 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14413 expansion_failed (loc
, NULL_RTX
,
14414 "CST value in contant pool but not marked.");
14417 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14418 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14421 /* Return dw_loc_list representing address of addr_expr LOC
14422 by looking for inner INDIRECT_REF expression and turning
14423 it into simple arithmetics.
14425 See loc_list_from_tree for the meaning of CONTEXT. */
14427 static dw_loc_list_ref
14428 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
14429 const loc_descr_context
*context
)
14432 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14434 int unsignedp
, volatilep
= 0;
14435 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14437 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14438 &bitsize
, &bitpos
, &offset
, &mode
,
14439 &unsignedp
, &volatilep
, false);
14441 if (bitpos
% BITS_PER_UNIT
)
14443 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14446 if (!INDIRECT_REF_P (obj
))
14448 expansion_failed (obj
,
14449 NULL_RTX
, "no indirect ref in inner refrence");
14452 if (!offset
&& !bitpos
)
14453 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
14456 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14457 && (dwarf_version
>= 4 || !dwarf_strict
))
14459 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
14464 /* Variable offset. */
14465 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14466 if (list_ret1
== 0)
14468 add_loc_list (&list_ret
, list_ret1
);
14471 add_loc_descr_to_each (list_ret
,
14472 new_loc_descr (DW_OP_plus
, 0, 0));
14474 bytepos
= bitpos
/ BITS_PER_UNIT
;
14476 add_loc_descr_to_each (list_ret
,
14477 new_loc_descr (DW_OP_plus_uconst
,
14479 else if (bytepos
< 0)
14480 loc_list_plus_const (list_ret
, bytepos
);
14481 add_loc_descr_to_each (list_ret
,
14482 new_loc_descr (DW_OP_stack_value
, 0, 0));
14488 /* Helper structure for location descriptions generation. */
14489 struct loc_descr_context
14491 /* The type that is implicitly referenced by DW_OP_push_object_address, or
14492 NULL_TREE if DW_OP_push_object_address in invalid for this location
14493 description. This is used when processing PLACEHOLDER_EXPR nodes. */
14495 /* The ..._DECL node that should be translated as a
14496 DW_OP_push_object_address operation. */
14500 /* Generate Dwarf location list representing LOC.
14501 If WANT_ADDRESS is false, expression computing LOC will be computed
14502 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14503 if WANT_ADDRESS is 2, expression computing address useable in location
14504 will be returned (i.e. DW_OP_reg can be used
14505 to refer to register values).
14507 CONTEXT provides information to customize the location descriptions
14508 generation. Its context_type field specifies what type is implicitly
14509 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
14510 will not be generated.
14512 If CONTEXT is NULL, the behavior is the same as if both context_type and
14513 base_decl fields were NULL_TREE. */
14515 static dw_loc_list_ref
14516 loc_list_from_tree (tree loc
, int want_address
,
14517 const struct loc_descr_context
*context
)
14519 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14520 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14521 int have_address
= 0;
14522 enum dwarf_location_atom op
;
14524 /* ??? Most of the time we do not take proper care for sign/zero
14525 extending the values properly. Hopefully this won't be a real
14528 if (context
!= NULL
14529 && context
->base_decl
== loc
14530 && want_address
== 0)
14532 if (dwarf_version
>= 3 || !dwarf_strict
)
14533 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
14539 switch (TREE_CODE (loc
))
14542 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14545 case PLACEHOLDER_EXPR
:
14546 /* This case involves extracting fields from an object to determine the
14547 position of other fields. It is supposed to appear only as the first
14548 operand of COMPONENT_REF nodes and to reference precisely the type
14549 that the context allows. */
14550 if (context
!= NULL
14551 && TREE_TYPE (loc
) == context
->context_type
14552 && want_address
>= 1)
14554 if (dwarf_version
>= 3 || !dwarf_strict
)
14556 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
14564 expansion_failed (loc
, NULL_RTX
,
14565 "PLACEHOLDER_EXPR for an unexpected type");
14569 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14570 /* There are no opcodes for these operations. */
14573 case PREINCREMENT_EXPR
:
14574 case PREDECREMENT_EXPR
:
14575 case POSTINCREMENT_EXPR
:
14576 case POSTDECREMENT_EXPR
:
14577 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14578 /* There are no opcodes for these operations. */
14582 /* If we already want an address, see if there is INDIRECT_REF inside
14583 e.g. for &this->field. */
14586 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14587 (loc
, want_address
== 2, context
);
14590 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14591 && (ret
= cst_pool_loc_descr (loc
)))
14594 /* Otherwise, process the argument and look for the address. */
14595 if (!list_ret
&& !ret
)
14596 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1, context
);
14600 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14606 if (DECL_THREAD_LOCAL_P (loc
))
14609 enum dwarf_location_atom tls_op
;
14610 enum dtprel_bool dtprel
= dtprel_false
;
14612 if (targetm
.have_tls
)
14614 /* If this is not defined, we have no way to emit the
14616 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14619 /* The way DW_OP_GNU_push_tls_address is specified, we
14620 can only look up addresses of objects in the current
14621 module. We used DW_OP_addr as first op, but that's
14622 wrong, because DW_OP_addr is relocated by the debug
14623 info consumer, while DW_OP_GNU_push_tls_address
14624 operand shouldn't be. */
14625 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14627 dtprel
= dtprel_true
;
14628 tls_op
= DW_OP_GNU_push_tls_address
;
14632 if (!targetm
.emutls
.debug_form_tls_address
14633 || !(dwarf_version
>= 3 || !dwarf_strict
))
14635 /* We stuffed the control variable into the DECL_VALUE_EXPR
14636 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14637 no longer appear in gimple code. We used the control
14638 variable in specific so that we could pick it up here. */
14639 loc
= DECL_VALUE_EXPR (loc
);
14640 tls_op
= DW_OP_form_tls_address
;
14643 rtl
= rtl_for_decl_location (loc
);
14644 if (rtl
== NULL_RTX
)
14649 rtl
= XEXP (rtl
, 0);
14650 if (! CONSTANT_P (rtl
))
14653 ret
= new_addr_loc_descr (rtl
, dtprel
);
14654 ret1
= new_loc_descr (tls_op
, 0, 0);
14655 add_loc_descr (&ret
, ret1
);
14664 if (DECL_HAS_VALUE_EXPR_P (loc
))
14665 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14666 want_address
, context
);
14669 case FUNCTION_DECL
:
14672 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14674 if (loc_list
&& loc_list
->first
)
14676 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14677 have_address
= want_address
!= 0;
14680 rtl
= rtl_for_decl_location (loc
);
14681 if (rtl
== NULL_RTX
)
14683 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14686 else if (CONST_INT_P (rtl
))
14688 HOST_WIDE_INT val
= INTVAL (rtl
);
14689 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14690 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14691 ret
= int_loc_descriptor (val
);
14693 else if (GET_CODE (rtl
) == CONST_STRING
)
14695 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14698 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14699 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14702 machine_mode mode
, mem_mode
;
14704 /* Certain constructs can only be represented at top-level. */
14705 if (want_address
== 2)
14707 ret
= loc_descriptor (rtl
, VOIDmode
,
14708 VAR_INIT_STATUS_INITIALIZED
);
14713 mode
= GET_MODE (rtl
);
14714 mem_mode
= VOIDmode
;
14718 mode
= get_address_mode (rtl
);
14719 rtl
= XEXP (rtl
, 0);
14722 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14723 VAR_INIT_STATUS_INITIALIZED
);
14726 expansion_failed (loc
, rtl
,
14727 "failed to produce loc descriptor for rtl");
14733 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14740 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14744 case TARGET_MEM_REF
:
14746 case DEBUG_EXPR_DECL
:
14749 case COMPOUND_EXPR
:
14750 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
, context
);
14753 case VIEW_CONVERT_EXPR
:
14756 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
, context
);
14758 case COMPONENT_REF
:
14759 case BIT_FIELD_REF
:
14761 case ARRAY_RANGE_REF
:
14762 case REALPART_EXPR
:
14763 case IMAGPART_EXPR
:
14766 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14768 int unsignedp
, volatilep
= 0;
14770 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14771 &unsignedp
, &volatilep
, false);
14773 gcc_assert (obj
!= loc
);
14775 list_ret
= loc_list_from_tree (obj
,
14777 && !bitpos
&& !offset
? 2 : 1,
14779 /* TODO: We can extract value of the small expression via shifting even
14780 for nonzero bitpos. */
14783 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14785 expansion_failed (loc
, NULL_RTX
,
14786 "bitfield access");
14790 if (offset
!= NULL_TREE
)
14792 /* Variable offset. */
14793 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14794 if (list_ret1
== 0)
14796 add_loc_list (&list_ret
, list_ret1
);
14799 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14802 bytepos
= bitpos
/ BITS_PER_UNIT
;
14804 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14805 else if (bytepos
< 0)
14806 loc_list_plus_const (list_ret
, bytepos
);
14813 if ((want_address
|| !tree_fits_shwi_p (loc
))
14814 && (ret
= cst_pool_loc_descr (loc
)))
14816 else if (want_address
== 2
14817 && tree_fits_shwi_p (loc
)
14818 && (ret
= address_of_int_loc_descriptor
14819 (int_size_in_bytes (TREE_TYPE (loc
)),
14820 tree_to_shwi (loc
))))
14822 else if (tree_fits_shwi_p (loc
))
14823 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14826 expansion_failed (loc
, NULL_RTX
,
14827 "Integer operand is not host integer");
14836 if ((ret
= cst_pool_loc_descr (loc
)))
14839 /* We can construct small constants here using int_loc_descriptor. */
14840 expansion_failed (loc
, NULL_RTX
,
14841 "constructor or constant not in constant pool");
14844 case TRUTH_AND_EXPR
:
14845 case TRUTH_ANDIF_EXPR
:
14850 case TRUTH_XOR_EXPR
:
14855 case TRUTH_OR_EXPR
:
14856 case TRUTH_ORIF_EXPR
:
14861 case FLOOR_DIV_EXPR
:
14862 case CEIL_DIV_EXPR
:
14863 case ROUND_DIV_EXPR
:
14864 case TRUNC_DIV_EXPR
:
14865 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14874 case FLOOR_MOD_EXPR
:
14875 case CEIL_MOD_EXPR
:
14876 case ROUND_MOD_EXPR
:
14877 case TRUNC_MOD_EXPR
:
14878 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14883 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14884 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14885 if (list_ret
== 0 || list_ret1
== 0)
14888 add_loc_list (&list_ret
, list_ret1
);
14891 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14892 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14893 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14894 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14895 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14907 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14910 case POINTER_PLUS_EXPR
:
14913 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14915 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14919 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14927 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14934 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14941 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14948 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14963 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14964 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14965 if (list_ret
== 0 || list_ret1
== 0)
14968 add_loc_list (&list_ret
, list_ret1
);
14971 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14974 case TRUTH_NOT_EXPR
:
14988 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14992 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14998 const enum tree_code code
=
14999 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
15001 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
15002 build2 (code
, integer_type_node
,
15003 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
15004 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
15007 /* ... fall through ... */
15011 dw_loc_descr_ref lhs
15012 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
15013 dw_loc_list_ref rhs
15014 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0, context
);
15015 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15017 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
15018 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15021 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15022 add_loc_descr_to_each (list_ret
, bra_node
);
15024 add_loc_list (&list_ret
, rhs
);
15025 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15026 add_loc_descr_to_each (list_ret
, jump_node
);
15028 add_loc_descr_to_each (list_ret
, lhs
);
15029 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15030 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15032 /* ??? Need a node to point the skip at. Use a nop. */
15033 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15034 add_loc_descr_to_each (list_ret
, tmp
);
15035 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15036 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15040 case FIX_TRUNC_EXPR
:
15044 /* Leave front-end specific codes as simply unknown. This comes
15045 up, for instance, with the C STMT_EXPR. */
15046 if ((unsigned int) TREE_CODE (loc
)
15047 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15049 expansion_failed (loc
, NULL_RTX
,
15050 "language specific tree node");
15054 #ifdef ENABLE_CHECKING
15055 /* Otherwise this is a generic code; we should just lists all of
15056 these explicitly. We forgot one. */
15057 gcc_unreachable ();
15059 /* In a release build, we want to degrade gracefully: better to
15060 generate incomplete debugging information than to crash. */
15065 if (!ret
&& !list_ret
)
15068 if (want_address
== 2 && !have_address
15069 && (dwarf_version
>= 4 || !dwarf_strict
))
15071 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15073 expansion_failed (loc
, NULL_RTX
,
15074 "DWARF address size mismatch");
15078 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15080 add_loc_descr_to_each (list_ret
,
15081 new_loc_descr (DW_OP_stack_value
, 0, 0));
15084 /* Show if we can't fill the request for an address. */
15085 if (want_address
&& !have_address
)
15087 expansion_failed (loc
, NULL_RTX
,
15088 "Want address and only have value");
15092 gcc_assert (!ret
|| !list_ret
);
15094 /* If we've got an address and don't want one, dereference. */
15095 if (!want_address
&& have_address
)
15097 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15099 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15101 expansion_failed (loc
, NULL_RTX
,
15102 "DWARF address size mismatch");
15105 else if (size
== DWARF2_ADDR_SIZE
)
15108 op
= DW_OP_deref_size
;
15111 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15113 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15116 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15121 /* Same as above but return only single location expression. */
15122 static dw_loc_descr_ref
15123 loc_descriptor_from_tree (tree loc
, int want_address
,
15124 const struct loc_descr_context
*context
)
15126 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
15129 if (ret
->dw_loc_next
)
15131 expansion_failed (loc
, NULL_RTX
,
15132 "Location list where only loc descriptor needed");
15138 /* Given a value, round it up to the lowest multiple of `boundary'
15139 which is not less than the value itself. */
15141 static inline HOST_WIDE_INT
15142 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15144 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15147 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15148 pointer to the declared type for the relevant field variable, or return
15149 `integer_type_node' if the given node turns out to be an
15150 ERROR_MARK node. */
15153 field_type (const_tree decl
)
15157 if (TREE_CODE (decl
) == ERROR_MARK
)
15158 return integer_type_node
;
15160 type
= DECL_BIT_FIELD_TYPE (decl
);
15161 if (type
== NULL_TREE
)
15162 type
= TREE_TYPE (decl
);
15167 /* Given a pointer to a tree node, return the alignment in bits for
15168 it, or else return BITS_PER_WORD if the node actually turns out to
15169 be an ERROR_MARK node. */
15171 static inline unsigned
15172 simple_type_align_in_bits (const_tree type
)
15174 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15177 static inline unsigned
15178 simple_decl_align_in_bits (const_tree decl
)
15180 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15183 /* Return the result of rounding T up to ALIGN. */
15185 static inline offset_int
15186 round_up_to_align (const offset_int
&t
, unsigned int align
)
15188 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
15191 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15192 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15193 or return 0 if we are unable to determine what that offset is, either
15194 because the argument turns out to be a pointer to an ERROR_MARK node, or
15195 because the offset is actually variable. (We can't handle the latter case
15198 static HOST_WIDE_INT
15199 field_byte_offset (const_tree decl
)
15201 offset_int object_offset_in_bits
;
15202 offset_int object_offset_in_bytes
;
15203 offset_int bitpos_int
;
15205 if (TREE_CODE (decl
) == ERROR_MARK
)
15208 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15210 /* We cannot yet cope with fields whose positions are variable, so
15211 for now, when we see such things, we simply return 0. Someday, we may
15212 be able to handle such cases, but it will be damn difficult. */
15213 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15216 bitpos_int
= wi::to_offset (bit_position (decl
));
15218 if (PCC_BITFIELD_TYPE_MATTERS
)
15221 tree field_size_tree
;
15222 offset_int deepest_bitpos
;
15223 offset_int field_size_in_bits
;
15224 unsigned int type_align_in_bits
;
15225 unsigned int decl_align_in_bits
;
15226 offset_int type_size_in_bits
;
15228 type
= field_type (decl
);
15229 type_size_in_bits
= offset_int_type_size_in_bits (type
);
15230 type_align_in_bits
= simple_type_align_in_bits (type
);
15232 field_size_tree
= DECL_SIZE (decl
);
15234 /* The size could be unspecified if there was an error, or for
15235 a flexible array member. */
15236 if (!field_size_tree
)
15237 field_size_tree
= bitsize_zero_node
;
15239 /* If the size of the field is not constant, use the type size. */
15240 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15241 field_size_in_bits
= wi::to_offset (field_size_tree
);
15243 field_size_in_bits
= type_size_in_bits
;
15245 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15247 /* The GCC front-end doesn't make any attempt to keep track of the
15248 starting bit offset (relative to the start of the containing
15249 structure type) of the hypothetical "containing object" for a
15250 bit-field. Thus, when computing the byte offset value for the
15251 start of the "containing object" of a bit-field, we must deduce
15252 this information on our own. This can be rather tricky to do in
15253 some cases. For example, handling the following structure type
15254 definition when compiling for an i386/i486 target (which only
15255 aligns long long's to 32-bit boundaries) can be very tricky:
15257 struct S { int field1; long long field2:31; };
15259 Fortunately, there is a simple rule-of-thumb which can be used
15260 in such cases. When compiling for an i386/i486, GCC will
15261 allocate 8 bytes for the structure shown above. It decides to
15262 do this based upon one simple rule for bit-field allocation.
15263 GCC allocates each "containing object" for each bit-field at
15264 the first (i.e. lowest addressed) legitimate alignment boundary
15265 (based upon the required minimum alignment for the declared
15266 type of the field) which it can possibly use, subject to the
15267 condition that there is still enough available space remaining
15268 in the containing object (when allocated at the selected point)
15269 to fully accommodate all of the bits of the bit-field itself.
15271 This simple rule makes it obvious why GCC allocates 8 bytes for
15272 each object of the structure type shown above. When looking
15273 for a place to allocate the "containing object" for `field2',
15274 the compiler simply tries to allocate a 64-bit "containing
15275 object" at each successive 32-bit boundary (starting at zero)
15276 until it finds a place to allocate that 64- bit field such that
15277 at least 31 contiguous (and previously unallocated) bits remain
15278 within that selected 64 bit field. (As it turns out, for the
15279 example above, the compiler finds it is OK to allocate the
15280 "containing object" 64-bit field at bit-offset zero within the
15283 Here we attempt to work backwards from the limited set of facts
15284 we're given, and we try to deduce from those facts, where GCC
15285 must have believed that the containing object started (within
15286 the structure type). The value we deduce is then used (by the
15287 callers of this routine) to generate DW_AT_location and
15288 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15289 the case of DW_AT_location, regular fields as well). */
15291 /* Figure out the bit-distance from the start of the structure to
15292 the "deepest" bit of the bit-field. */
15293 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
15295 /* This is the tricky part. Use some fancy footwork to deduce
15296 where the lowest addressed bit of the containing object must
15298 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15300 /* Round up to type_align by default. This works best for
15302 object_offset_in_bits
15303 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15305 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
15307 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15309 /* Round up to decl_align instead. */
15310 object_offset_in_bits
15311 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15315 object_offset_in_bits
= bitpos_int
;
15317 object_offset_in_bytes
15318 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
15319 return object_offset_in_bytes
.to_shwi ();
15322 /* The following routines define various Dwarf attributes and any data
15323 associated with them. */
15325 /* Add a location description attribute value to a DIE.
15327 This emits location attributes suitable for whole variables and
15328 whole parameters. Note that the location attributes for struct fields are
15329 generated by the routine `data_member_location_attribute' below. */
15332 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15333 dw_loc_list_ref descr
)
15337 if (single_element_loc_list_p (descr
))
15338 add_AT_loc (die
, attr_kind
, descr
->expr
);
15340 add_AT_loc_list (die
, attr_kind
, descr
);
15343 /* Add DW_AT_accessibility attribute to DIE if needed. */
15346 add_accessibility_attribute (dw_die_ref die
, tree decl
)
15348 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15349 children, otherwise the default is DW_ACCESS_public. In DWARF2
15350 the default has always been DW_ACCESS_public. */
15351 if (TREE_PROTECTED (decl
))
15352 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
15353 else if (TREE_PRIVATE (decl
))
15355 if (dwarf_version
== 2
15356 || die
->die_parent
== NULL
15357 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
15358 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
15360 else if (dwarf_version
> 2
15362 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15363 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15366 /* Attach the specialized form of location attribute used for data members of
15367 struct and union types. In the special case of a FIELD_DECL node which
15368 represents a bit-field, the "offset" part of this special location
15369 descriptor must indicate the distance in bytes from the lowest-addressed
15370 byte of the containing struct or union type to the lowest-addressed byte of
15371 the "containing object" for the bit-field. (See the `field_byte_offset'
15374 For any given bit-field, the "containing object" is a hypothetical object
15375 (of some integral or enum type) within which the given bit-field lives. The
15376 type of this hypothetical "containing object" is always the same as the
15377 declared type of the individual bit-field itself (for GCC anyway... the
15378 DWARF spec doesn't actually mandate this). Note that it is the size (in
15379 bytes) of the hypothetical "containing object" which will be given in the
15380 DW_AT_byte_size attribute for this bit-field. (See the
15381 `byte_size_attribute' function below.) It is also used when calculating the
15382 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15383 function below.) */
15386 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15388 HOST_WIDE_INT offset
;
15389 dw_loc_descr_ref loc_descr
= 0;
15391 if (TREE_CODE (decl
) == TREE_BINFO
)
15393 /* We're working on the TAG_inheritance for a base class. */
15394 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15396 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15397 aren't at a fixed offset from all (sub)objects of the same
15398 type. We need to extract the appropriate offset from our
15399 vtable. The following dwarf expression means
15401 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15403 This is specific to the V3 ABI, of course. */
15405 dw_loc_descr_ref tmp
;
15407 /* Make a copy of the object address. */
15408 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15409 add_loc_descr (&loc_descr
, tmp
);
15411 /* Extract the vtable address. */
15412 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15413 add_loc_descr (&loc_descr
, tmp
);
15415 /* Calculate the address of the offset. */
15416 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15417 gcc_assert (offset
< 0);
15419 tmp
= int_loc_descriptor (-offset
);
15420 add_loc_descr (&loc_descr
, tmp
);
15421 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15422 add_loc_descr (&loc_descr
, tmp
);
15424 /* Extract the offset. */
15425 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15426 add_loc_descr (&loc_descr
, tmp
);
15428 /* Add it to the object address. */
15429 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15430 add_loc_descr (&loc_descr
, tmp
);
15433 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15436 offset
= field_byte_offset (decl
);
15440 if (dwarf_version
> 2)
15442 /* Don't need to output a location expression, just the constant. */
15444 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15446 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15451 enum dwarf_location_atom op
;
15453 /* The DWARF2 standard says that we should assume that the structure
15454 address is already on the stack, so we can specify a structure
15455 field address by using DW_OP_plus_uconst. */
15456 op
= DW_OP_plus_uconst
;
15457 loc_descr
= new_loc_descr (op
, offset
, 0);
15461 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15464 /* Writes integer values to dw_vec_const array. */
15467 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15471 *dest
++ = val
& 0xff;
15477 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15479 static HOST_WIDE_INT
15480 extract_int (const unsigned char *src
, unsigned int size
)
15482 HOST_WIDE_INT val
= 0;
15488 val
|= *--src
& 0xff;
15494 /* Writes wide_int values to dw_vec_const array. */
15497 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15501 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15503 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15507 /* We'd have to extend this code to support odd sizes. */
15508 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
15510 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
15512 if (WORDS_BIG_ENDIAN
)
15513 for (i
= n
- 1; i
>= 0; i
--)
15515 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15516 dest
+= sizeof (HOST_WIDE_INT
);
15519 for (i
= 0; i
< n
; i
++)
15521 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15522 dest
+= sizeof (HOST_WIDE_INT
);
15526 /* Writes floating point values to dw_vec_const array. */
15529 insert_float (const_rtx rtl
, unsigned char *array
)
15531 REAL_VALUE_TYPE rv
;
15535 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15536 real_to_target (val
, &rv
, GET_MODE (rtl
));
15538 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15539 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15541 insert_int (val
[i
], 4, array
);
15546 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15547 does not have a "location" either in memory or in a register. These
15548 things can arise in GNU C when a constant is passed as an actual parameter
15549 to an inlined function. They can also arise in C++ where declared
15550 constants do not necessarily get memory "homes". */
15553 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15555 switch (GET_CODE (rtl
))
15559 HOST_WIDE_INT val
= INTVAL (rtl
);
15562 add_AT_int (die
, DW_AT_const_value
, val
);
15564 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15568 case CONST_WIDE_INT
:
15569 add_AT_wide (die
, DW_AT_const_value
,
15570 std::make_pair (rtl
, GET_MODE (rtl
)));
15574 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15575 floating-point constant. A CONST_DOUBLE is used whenever the
15576 constant requires more than one word in order to be adequately
15579 machine_mode mode
= GET_MODE (rtl
);
15581 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15582 add_AT_double (die
, DW_AT_const_value
,
15583 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15586 unsigned int length
= GET_MODE_SIZE (mode
);
15587 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15589 insert_float (rtl
, array
);
15590 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15597 machine_mode mode
= GET_MODE (rtl
);
15598 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15599 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15600 unsigned char *array
15601 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15604 machine_mode imode
= GET_MODE_INNER (mode
);
15606 switch (GET_MODE_CLASS (mode
))
15608 case MODE_VECTOR_INT
:
15609 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15611 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15612 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15616 case MODE_VECTOR_FLOAT
:
15617 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15619 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15620 insert_float (elt
, p
);
15625 gcc_unreachable ();
15628 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15633 if (dwarf_version
>= 4 || !dwarf_strict
)
15635 dw_loc_descr_ref loc_result
;
15636 resolve_one_addr (&rtl
);
15638 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15639 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15640 add_AT_loc (die
, DW_AT_location
, loc_result
);
15641 vec_safe_push (used_rtx_array
, rtl
);
15647 if (CONSTANT_P (XEXP (rtl
, 0)))
15648 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15651 if (!const_ok_for_output (rtl
))
15654 if (dwarf_version
>= 4 || !dwarf_strict
)
15659 /* In cases where an inlined instance of an inline function is passed
15660 the address of an `auto' variable (which is local to the caller) we
15661 can get a situation where the DECL_RTL of the artificial local
15662 variable (for the inlining) which acts as a stand-in for the
15663 corresponding formal parameter (of the inline function) will look
15664 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15665 exactly a compile-time constant expression, but it isn't the address
15666 of the (artificial) local variable either. Rather, it represents the
15667 *value* which the artificial local variable always has during its
15668 lifetime. We currently have no way to represent such quasi-constant
15669 values in Dwarf, so for now we just punt and generate nothing. */
15677 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15678 && MEM_READONLY_P (rtl
)
15679 && GET_MODE (rtl
) == BLKmode
)
15681 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15687 /* No other kinds of rtx should be possible here. */
15688 gcc_unreachable ();
15693 /* Determine whether the evaluation of EXPR references any variables
15694 or functions which aren't otherwise used (and therefore may not be
15697 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15698 void * data ATTRIBUTE_UNUSED
)
15700 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15701 *walk_subtrees
= 0;
15703 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15704 && ! TREE_ASM_WRITTEN (*tp
))
15706 /* ??? The C++ FE emits debug information for using decls, so
15707 putting gcc_unreachable here falls over. See PR31899. For now
15708 be conservative. */
15709 else if (!symtab
->global_info_ready
15710 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15712 else if (TREE_CODE (*tp
) == VAR_DECL
)
15714 varpool_node
*node
= varpool_node::get (*tp
);
15715 if (!node
|| !node
->definition
)
15718 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15719 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15721 /* The call graph machinery must have finished analyzing,
15722 optimizing and gimplifying the CU by now.
15723 So if *TP has no call graph node associated
15724 to it, it means *TP will not be emitted. */
15725 if (!cgraph_node::get (*tp
))
15728 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15734 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15735 for use in a later add_const_value_attribute call. */
15738 rtl_for_decl_init (tree init
, tree type
)
15740 rtx rtl
= NULL_RTX
;
15744 /* If a variable is initialized with a string constant without embedded
15745 zeros, build CONST_STRING. */
15746 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15748 tree enttype
= TREE_TYPE (type
);
15749 tree domain
= TYPE_DOMAIN (type
);
15750 machine_mode mode
= TYPE_MODE (enttype
);
15752 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15754 && integer_zerop (TYPE_MIN_VALUE (domain
))
15755 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15756 TREE_STRING_LENGTH (init
) - 1) == 0
15757 && ((size_t) TREE_STRING_LENGTH (init
)
15758 == strlen (TREE_STRING_POINTER (init
)) + 1))
15760 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15761 ggc_strdup (TREE_STRING_POINTER (init
)));
15762 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15763 MEM_READONLY_P (rtl
) = 1;
15766 /* Other aggregates, and complex values, could be represented using
15768 else if (AGGREGATE_TYPE_P (type
)
15769 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15770 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15771 || TREE_CODE (type
) == COMPLEX_TYPE
)
15773 /* Vectors only work if their mode is supported by the target.
15774 FIXME: generic vectors ought to work too. */
15775 else if (TREE_CODE (type
) == VECTOR_TYPE
15776 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15778 /* If the initializer is something that we know will expand into an
15779 immediate RTL constant, expand it now. We must be careful not to
15780 reference variables which won't be output. */
15781 else if (initializer_constant_valid_p (init
, type
)
15782 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15784 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15786 if (TREE_CODE (type
) == VECTOR_TYPE
)
15787 switch (TREE_CODE (init
))
15792 if (TREE_CONSTANT (init
))
15794 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15795 bool constant_p
= true;
15797 unsigned HOST_WIDE_INT ix
;
15799 /* Even when ctor is constant, it might contain non-*_CST
15800 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15801 belong into VECTOR_CST nodes. */
15802 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15803 if (!CONSTANT_CLASS_P (value
))
15805 constant_p
= false;
15811 init
= build_vector_from_ctor (type
, elts
);
15821 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15823 /* If expand_expr returns a MEM, it wasn't immediate. */
15824 gcc_assert (!rtl
|| !MEM_P (rtl
));
15830 /* Generate RTL for the variable DECL to represent its location. */
15833 rtl_for_decl_location (tree decl
)
15837 /* Here we have to decide where we are going to say the parameter "lives"
15838 (as far as the debugger is concerned). We only have a couple of
15839 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15841 DECL_RTL normally indicates where the parameter lives during most of the
15842 activation of the function. If optimization is enabled however, this
15843 could be either NULL or else a pseudo-reg. Both of those cases indicate
15844 that the parameter doesn't really live anywhere (as far as the code
15845 generation parts of GCC are concerned) during most of the function's
15846 activation. That will happen (for example) if the parameter is never
15847 referenced within the function.
15849 We could just generate a location descriptor here for all non-NULL
15850 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15851 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15852 where DECL_RTL is NULL or is a pseudo-reg.
15854 Note however that we can only get away with using DECL_INCOMING_RTL as
15855 a backup substitute for DECL_RTL in certain limited cases. In cases
15856 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15857 we can be sure that the parameter was passed using the same type as it is
15858 declared to have within the function, and that its DECL_INCOMING_RTL
15859 points us to a place where a value of that type is passed.
15861 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15862 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15863 because in these cases DECL_INCOMING_RTL points us to a value of some
15864 type which is *different* from the type of the parameter itself. Thus,
15865 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15866 such cases, the debugger would end up (for example) trying to fetch a
15867 `float' from a place which actually contains the first part of a
15868 `double'. That would lead to really incorrect and confusing
15869 output at debug-time.
15871 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15872 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15873 are a couple of exceptions however. On little-endian machines we can
15874 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15875 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15876 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15877 when (on a little-endian machine) a non-prototyped function has a
15878 parameter declared to be of type `short' or `char'. In such cases,
15879 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15880 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15881 passed `int' value. If the debugger then uses that address to fetch
15882 a `short' or a `char' (on a little-endian machine) the result will be
15883 the correct data, so we allow for such exceptional cases below.
15885 Note that our goal here is to describe the place where the given formal
15886 parameter lives during most of the function's activation (i.e. between the
15887 end of the prologue and the start of the epilogue). We'll do that as best
15888 as we can. Note however that if the given formal parameter is modified
15889 sometime during the execution of the function, then a stack backtrace (at
15890 debug-time) will show the function as having been called with the *new*
15891 value rather than the value which was originally passed in. This happens
15892 rarely enough that it is not a major problem, but it *is* a problem, and
15893 I'd like to fix it.
15895 A future version of dwarf2out.c may generate two additional attributes for
15896 any given DW_TAG_formal_parameter DIE which will describe the "passed
15897 type" and the "passed location" for the given formal parameter in addition
15898 to the attributes we now generate to indicate the "declared type" and the
15899 "active location" for each parameter. This additional set of attributes
15900 could be used by debuggers for stack backtraces. Separately, note that
15901 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15902 This happens (for example) for inlined-instances of inline function formal
15903 parameters which are never referenced. This really shouldn't be
15904 happening. All PARM_DECL nodes should get valid non-NULL
15905 DECL_INCOMING_RTL values. FIXME. */
15907 /* Use DECL_RTL as the "location" unless we find something better. */
15908 rtl
= DECL_RTL_IF_SET (decl
);
15910 /* When generating abstract instances, ignore everything except
15911 constants, symbols living in memory, and symbols living in
15912 fixed registers. */
15913 if (! reload_completed
)
15916 && (CONSTANT_P (rtl
)
15918 && CONSTANT_P (XEXP (rtl
, 0)))
15920 && TREE_CODE (decl
) == VAR_DECL
15921 && TREE_STATIC (decl
))))
15923 rtl
= targetm
.delegitimize_address (rtl
);
15928 else if (TREE_CODE (decl
) == PARM_DECL
)
15930 if (rtl
== NULL_RTX
15931 || is_pseudo_reg (rtl
)
15933 && is_pseudo_reg (XEXP (rtl
, 0))
15934 && DECL_INCOMING_RTL (decl
)
15935 && MEM_P (DECL_INCOMING_RTL (decl
))
15936 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15938 tree declared_type
= TREE_TYPE (decl
);
15939 tree passed_type
= DECL_ARG_TYPE (decl
);
15940 machine_mode dmode
= TYPE_MODE (declared_type
);
15941 machine_mode pmode
= TYPE_MODE (passed_type
);
15943 /* This decl represents a formal parameter which was optimized out.
15944 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15945 all cases where (rtl == NULL_RTX) just below. */
15946 if (dmode
== pmode
)
15947 rtl
= DECL_INCOMING_RTL (decl
);
15948 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15949 && SCALAR_INT_MODE_P (dmode
)
15950 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15951 && DECL_INCOMING_RTL (decl
))
15953 rtx inc
= DECL_INCOMING_RTL (decl
);
15956 else if (MEM_P (inc
))
15958 if (BYTES_BIG_ENDIAN
)
15959 rtl
= adjust_address_nv (inc
, dmode
,
15960 GET_MODE_SIZE (pmode
)
15961 - GET_MODE_SIZE (dmode
));
15968 /* If the parm was passed in registers, but lives on the stack, then
15969 make a big endian correction if the mode of the type of the
15970 parameter is not the same as the mode of the rtl. */
15971 /* ??? This is the same series of checks that are made in dbxout.c before
15972 we reach the big endian correction code there. It isn't clear if all
15973 of these checks are necessary here, but keeping them all is the safe
15975 else if (MEM_P (rtl
)
15976 && XEXP (rtl
, 0) != const0_rtx
15977 && ! CONSTANT_P (XEXP (rtl
, 0))
15978 /* Not passed in memory. */
15979 && !MEM_P (DECL_INCOMING_RTL (decl
))
15980 /* Not passed by invisible reference. */
15981 && (!REG_P (XEXP (rtl
, 0))
15982 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15983 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15984 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15985 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15988 /* Big endian correction check. */
15989 && BYTES_BIG_ENDIAN
15990 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15991 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15994 machine_mode addr_mode
= get_address_mode (rtl
);
15995 int offset
= (UNITS_PER_WORD
15996 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15998 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15999 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
16002 else if (TREE_CODE (decl
) == VAR_DECL
16005 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
16006 && BYTES_BIG_ENDIAN
)
16008 machine_mode addr_mode
= get_address_mode (rtl
);
16009 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16010 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16012 /* If a variable is declared "register" yet is smaller than
16013 a register, then if we store the variable to memory, it
16014 looks like we're storing a register-sized value, when in
16015 fact we are not. We need to adjust the offset of the
16016 storage location to reflect the actual value's bytes,
16017 else gdb will not be able to display it. */
16019 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16020 plus_constant (addr_mode
, XEXP (rtl
, 0),
16024 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16025 and will have been substituted directly into all expressions that use it.
16026 C does not have such a concept, but C++ and other languages do. */
16027 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16028 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16031 rtl
= targetm
.delegitimize_address (rtl
);
16033 /* If we don't look past the constant pool, we risk emitting a
16034 reference to a constant pool entry that isn't referenced from
16035 code, and thus is not emitted. */
16037 rtl
= avoid_constant_pool_reference (rtl
);
16039 /* Try harder to get a rtl. If this symbol ends up not being emitted
16040 in the current CU, resolve_addr will remove the expression referencing
16042 if (rtl
== NULL_RTX
16043 && TREE_CODE (decl
) == VAR_DECL
16044 && !DECL_EXTERNAL (decl
)
16045 && TREE_STATIC (decl
)
16046 && DECL_NAME (decl
)
16047 && !DECL_HARD_REGISTER (decl
)
16048 && DECL_MODE (decl
) != VOIDmode
)
16050 rtl
= make_decl_rtl_for_debug (decl
);
16052 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16053 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16060 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16061 returned. If so, the decl for the COMMON block is returned, and the
16062 value is the offset into the common block for the symbol. */
16065 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16067 tree val_expr
, cvar
;
16069 HOST_WIDE_INT bitsize
, bitpos
;
16071 int unsignedp
, volatilep
= 0;
16073 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16074 it does not have a value (the offset into the common area), or if it
16075 is thread local (as opposed to global) then it isn't common, and shouldn't
16076 be handled as such. */
16077 if (TREE_CODE (decl
) != VAR_DECL
16078 || !TREE_STATIC (decl
)
16079 || !DECL_HAS_VALUE_EXPR_P (decl
)
16083 val_expr
= DECL_VALUE_EXPR (decl
);
16084 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16087 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16088 &mode
, &unsignedp
, &volatilep
, true);
16090 if (cvar
== NULL_TREE
16091 || TREE_CODE (cvar
) != VAR_DECL
16092 || DECL_ARTIFICIAL (cvar
)
16093 || !TREE_PUBLIC (cvar
))
16097 if (offset
!= NULL
)
16099 if (!tree_fits_shwi_p (offset
))
16101 *value
= tree_to_shwi (offset
);
16104 *value
+= bitpos
/ BITS_PER_UNIT
;
16109 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16110 data attribute for a variable or a parameter. We generate the
16111 DW_AT_const_value attribute only in those cases where the given variable
16112 or parameter does not have a true "location" either in memory or in a
16113 register. This can happen (for example) when a constant is passed as an
16114 actual argument in a call to an inline function. (It's possible that
16115 these things can crop up in other ways also.) Note that one type of
16116 constant value which can be passed into an inlined function is a constant
16117 pointer. This can happen for example if an actual argument in an inlined
16118 function call evaluates to a compile-time constant address.
16120 CACHE_P is true if it is worth caching the location list for DECL,
16121 so that future calls can reuse it rather than regenerate it from scratch.
16122 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16123 since we will need to refer to them each time the function is inlined. */
16126 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
16127 enum dwarf_attribute attr
)
16130 dw_loc_list_ref list
;
16131 var_loc_list
*loc_list
;
16132 cached_dw_loc_list
*cache
;
16134 if (TREE_CODE (decl
) == ERROR_MARK
)
16137 if (get_AT (die
, attr
))
16140 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16141 || TREE_CODE (decl
) == RESULT_DECL
);
16143 /* Try to get some constant RTL for this decl, and use that as the value of
16146 rtl
= rtl_for_decl_location (decl
);
16147 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16148 && add_const_value_attribute (die
, rtl
))
16151 /* See if we have single element location list that is equivalent to
16152 a constant value. That way we are better to use add_const_value_attribute
16153 rather than expanding constant value equivalent. */
16154 loc_list
= lookup_decl_loc (decl
);
16157 && loc_list
->first
->next
== NULL
16158 && NOTE_P (loc_list
->first
->loc
)
16159 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16160 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16162 struct var_loc_node
*node
;
16164 node
= loc_list
->first
;
16165 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16166 if (GET_CODE (rtl
) == EXPR_LIST
)
16167 rtl
= XEXP (rtl
, 0);
16168 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16169 && add_const_value_attribute (die
, rtl
))
16172 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16173 list several times. See if we've already cached the contents. */
16175 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
16179 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
16181 list
= cache
->loc_list
;
16185 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
16187 /* It is usually worth caching this result if the decl is from
16188 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16189 if (cache_p
&& list
&& list
->dw_loc_next
)
16191 cached_dw_loc_list
**slot
16192 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
16195 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
16196 cache
->decl_id
= DECL_UID (decl
);
16197 cache
->loc_list
= list
;
16203 add_AT_location_description (die
, attr
, list
);
16206 /* None of that worked, so it must not really have a location;
16207 try adding a constant value attribute from the DECL_INITIAL. */
16208 return tree_add_const_value_attribute_for_decl (die
, decl
);
16211 /* Helper function for tree_add_const_value_attribute. Natively encode
16212 initializer INIT into an array. Return true if successful. */
16215 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16219 if (init
== NULL_TREE
)
16223 switch (TREE_CODE (init
))
16226 type
= TREE_TYPE (init
);
16227 if (TREE_CODE (type
) == ARRAY_TYPE
)
16229 tree enttype
= TREE_TYPE (type
);
16230 machine_mode mode
= TYPE_MODE (enttype
);
16232 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16234 if (int_size_in_bytes (type
) != size
)
16236 if (size
> TREE_STRING_LENGTH (init
))
16238 memcpy (array
, TREE_STRING_POINTER (init
),
16239 TREE_STRING_LENGTH (init
));
16240 memset (array
+ TREE_STRING_LENGTH (init
),
16241 '\0', size
- TREE_STRING_LENGTH (init
));
16244 memcpy (array
, TREE_STRING_POINTER (init
), size
);
16249 type
= TREE_TYPE (init
);
16250 if (int_size_in_bytes (type
) != size
)
16252 if (TREE_CODE (type
) == ARRAY_TYPE
)
16254 HOST_WIDE_INT min_index
;
16255 unsigned HOST_WIDE_INT cnt
;
16256 int curpos
= 0, fieldsize
;
16257 constructor_elt
*ce
;
16259 if (TYPE_DOMAIN (type
) == NULL_TREE
16260 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
16263 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
16264 if (fieldsize
<= 0)
16267 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
16268 memset (array
, '\0', size
);
16269 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16271 tree val
= ce
->value
;
16272 tree index
= ce
->index
;
16274 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16275 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
16278 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
16283 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16286 curpos
= pos
+ fieldsize
;
16287 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16289 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
16290 - tree_to_shwi (TREE_OPERAND (index
, 0));
16291 while (count
-- > 0)
16294 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16295 curpos
+= fieldsize
;
16298 gcc_assert (curpos
<= size
);
16302 else if (TREE_CODE (type
) == RECORD_TYPE
16303 || TREE_CODE (type
) == UNION_TYPE
)
16305 tree field
= NULL_TREE
;
16306 unsigned HOST_WIDE_INT cnt
;
16307 constructor_elt
*ce
;
16309 if (int_size_in_bytes (type
) != size
)
16312 if (TREE_CODE (type
) == RECORD_TYPE
)
16313 field
= TYPE_FIELDS (type
);
16315 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16317 tree val
= ce
->value
;
16318 int pos
, fieldsize
;
16320 if (ce
->index
!= 0)
16326 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16329 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16330 && TYPE_DOMAIN (TREE_TYPE (field
))
16331 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16333 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16334 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
16336 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
16337 pos
= int_byte_position (field
);
16338 gcc_assert (pos
+ fieldsize
<= size
);
16340 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16346 case VIEW_CONVERT_EXPR
:
16347 case NON_LVALUE_EXPR
:
16348 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16350 return native_encode_expr (init
, array
, size
) == size
;
16354 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16355 attribute is the const value T. */
16358 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16361 tree type
= TREE_TYPE (t
);
16364 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16368 gcc_assert (!DECL_P (init
));
16370 rtl
= rtl_for_decl_init (init
, type
);
16372 return add_const_value_attribute (die
, rtl
);
16373 /* If the host and target are sane, try harder. */
16374 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16375 && initializer_constant_valid_p (init
, type
))
16377 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16378 if (size
> 0 && (int) size
== size
)
16380 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
16382 if (native_encode_initializer (init
, array
, size
))
16384 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16393 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16394 attribute is the const value of T, where T is an integral constant
16395 variable with static storage duration
16396 (so it can't be a PARM_DECL or a RESULT_DECL). */
16399 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16403 || (TREE_CODE (decl
) != VAR_DECL
16404 && TREE_CODE (decl
) != CONST_DECL
)
16405 || (TREE_CODE (decl
) == VAR_DECL
16406 && !TREE_STATIC (decl
)))
16409 if (TREE_READONLY (decl
)
16410 && ! TREE_THIS_VOLATILE (decl
)
16411 && DECL_INITIAL (decl
))
16416 /* Don't add DW_AT_const_value if abstract origin already has one. */
16417 if (get_AT (var_die
, DW_AT_const_value
))
16420 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16423 /* Convert the CFI instructions for the current function into a
16424 location list. This is used for DW_AT_frame_base when we targeting
16425 a dwarf2 consumer that does not support the dwarf3
16426 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16429 static dw_loc_list_ref
16430 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16434 dw_loc_list_ref list
, *list_tail
;
16436 dw_cfa_location last_cfa
, next_cfa
;
16437 const char *start_label
, *last_label
, *section
;
16438 dw_cfa_location remember
;
16441 gcc_assert (fde
!= NULL
);
16443 section
= secname_for_decl (current_function_decl
);
16447 memset (&next_cfa
, 0, sizeof (next_cfa
));
16448 next_cfa
.reg
= INVALID_REGNUM
;
16449 remember
= next_cfa
;
16451 start_label
= fde
->dw_fde_begin
;
16453 /* ??? Bald assumption that the CIE opcode list does not contain
16454 advance opcodes. */
16455 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16456 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16458 last_cfa
= next_cfa
;
16459 last_label
= start_label
;
16461 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16463 /* If the first partition contained no CFI adjustments, the
16464 CIE opcodes apply to the whole first partition. */
16465 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16466 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16467 list_tail
=&(*list_tail
)->dw_loc_next
;
16468 start_label
= last_label
= fde
->dw_fde_second_begin
;
16471 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16473 switch (cfi
->dw_cfi_opc
)
16475 case DW_CFA_set_loc
:
16476 case DW_CFA_advance_loc1
:
16477 case DW_CFA_advance_loc2
:
16478 case DW_CFA_advance_loc4
:
16479 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16481 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16482 start_label
, last_label
, section
);
16484 list_tail
= &(*list_tail
)->dw_loc_next
;
16485 last_cfa
= next_cfa
;
16486 start_label
= last_label
;
16488 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16491 case DW_CFA_advance_loc
:
16492 /* The encoding is complex enough that we should never emit this. */
16493 gcc_unreachable ();
16496 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16499 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16501 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16503 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16504 start_label
, last_label
, section
);
16506 list_tail
= &(*list_tail
)->dw_loc_next
;
16507 last_cfa
= next_cfa
;
16508 start_label
= last_label
;
16510 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16511 start_label
, fde
->dw_fde_end
, section
);
16512 list_tail
= &(*list_tail
)->dw_loc_next
;
16513 start_label
= last_label
= fde
->dw_fde_second_begin
;
16517 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16519 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16520 start_label
, last_label
, section
);
16521 list_tail
= &(*list_tail
)->dw_loc_next
;
16522 start_label
= last_label
;
16525 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16527 fde
->dw_fde_second_begin
16528 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16531 if (list
&& list
->dw_loc_next
)
16537 /* Compute a displacement from the "steady-state frame pointer" to the
16538 frame base (often the same as the CFA), and store it in
16539 frame_pointer_fb_offset. OFFSET is added to the displacement
16540 before the latter is negated. */
16543 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16547 #ifdef FRAME_POINTER_CFA_OFFSET
16548 reg
= frame_pointer_rtx
;
16549 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16551 reg
= arg_pointer_rtx
;
16552 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16555 elim
= (ira_use_lra_p
16556 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16557 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16558 if (GET_CODE (elim
) == PLUS
)
16560 offset
+= INTVAL (XEXP (elim
, 1));
16561 elim
= XEXP (elim
, 0);
16564 frame_pointer_fb_offset
= -offset
;
16566 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16567 in which to eliminate. This is because it's stack pointer isn't
16568 directly accessible as a register within the ISA. To work around
16569 this, assume that while we cannot provide a proper value for
16570 frame_pointer_fb_offset, we won't need one either. */
16571 frame_pointer_fb_offset_valid
16572 = ((SUPPORTS_STACK_ALIGNMENT
16573 && (elim
== hard_frame_pointer_rtx
16574 || elim
== stack_pointer_rtx
))
16575 || elim
== (frame_pointer_needed
16576 ? hard_frame_pointer_rtx
16577 : stack_pointer_rtx
));
16580 /* Generate a DW_AT_name attribute given some string value to be included as
16581 the value of the attribute. */
16584 add_name_attribute (dw_die_ref die
, const char *name_string
)
16586 if (name_string
!= NULL
&& *name_string
!= 0)
16588 if (demangle_name_func
)
16589 name_string
= (*demangle_name_func
) (name_string
);
16591 add_AT_string (die
, DW_AT_name
, name_string
);
16595 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16596 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16597 of TYPE accordingly.
16599 ??? This is a temporary measure until after we're able to generate
16600 regular DWARF for the complex Ada type system. */
16603 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16604 dw_die_ref context_die
)
16607 dw_die_ref dtype_die
;
16609 if (!lang_hooks
.types
.descriptive_type
)
16612 dtype
= lang_hooks
.types
.descriptive_type (type
);
16616 dtype_die
= lookup_type_die (dtype
);
16619 gen_type_die (dtype
, context_die
);
16620 dtype_die
= lookup_type_die (dtype
);
16621 gcc_assert (dtype_die
);
16624 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16627 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16629 static const char *
16630 comp_dir_string (void)
16634 static const char *cached_wd
= NULL
;
16636 if (cached_wd
!= NULL
)
16639 wd
= get_src_pwd ();
16643 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16647 wdlen
= strlen (wd
);
16648 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
16650 wd1
[wdlen
] = DIR_SEPARATOR
;
16651 wd1
[wdlen
+ 1] = 0;
16655 cached_wd
= remap_debug_filename (wd
);
16659 /* Generate a DW_AT_comp_dir attribute for DIE. */
16662 add_comp_dir_attribute (dw_die_ref die
)
16664 const char * wd
= comp_dir_string ();
16666 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16669 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
16670 pointer computation, ...), output a representation for that bound according
16671 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
16672 loc_list_from_tree for the meaning of CONTEXT. */
16675 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
16676 int forms
, const struct loc_descr_context
*context
)
16678 dw_die_ref ctx
, decl_die
;
16679 dw_loc_list_ref list
;
16681 bool strip_conversions
= true;
16683 while (strip_conversions
)
16684 switch (TREE_CODE (value
))
16691 case VIEW_CONVERT_EXPR
:
16692 value
= TREE_OPERAND (value
, 0);
16696 strip_conversions
= false;
16700 /* If possible and permitted, output the attribute as a constant. */
16701 if ((forms
& dw_scalar_form_constant
) != 0
16702 && TREE_CODE (value
) == INTEGER_CST
)
16704 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
16706 /* If HOST_WIDE_INT is big enough then represent the bound as
16707 a constant value. We need to choose a form based on
16708 whether the type is signed or unsigned. We cannot just
16709 call add_AT_unsigned if the value itself is positive
16710 (add_AT_unsigned might add the unsigned value encoded as
16711 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16712 bounds type and then sign extend any unsigned values found
16713 for signed types. This is needed only for
16714 DW_AT_{lower,upper}_bound, since for most other attributes,
16715 consumers will treat DW_FORM_data[1248] as unsigned values,
16716 regardless of the underlying type. */
16717 if (prec
<= HOST_BITS_PER_WIDE_INT
16718 || tree_fits_uhwi_p (value
))
16720 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
16721 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
16723 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
16726 /* Otherwise represent the bound as an unsigned value with
16727 the precision of its type. The precision and signedness
16728 of the type will be necessary to re-interpret it
16730 add_AT_wide (die
, attr
, value
);
16734 /* Otherwise, if it's possible and permitted too, output a reference to
16736 if ((forms
& dw_scalar_form_reference
) != 0)
16738 tree decl
= NULL_TREE
;
16740 /* Some type attributes reference an outer type. For instance, the upper
16741 bound of an array may reference an embedding record (this happens in
16743 if (TREE_CODE (value
) == COMPONENT_REF
16744 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
16745 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
16746 decl
= TREE_OPERAND (value
, 1);
16748 else if (TREE_CODE (value
) == VAR_DECL
16749 || TREE_CODE (value
) == PARM_DECL
16750 || TREE_CODE (value
) == RESULT_DECL
)
16753 if (decl
!= NULL_TREE
)
16755 dw_die_ref decl_die
= lookup_decl_die (decl
);
16757 /* ??? Can this happen, or should the variable have been bound
16758 first? Probably it can, since I imagine that we try to create
16759 the types of parameters in the order in which they exist in
16760 the list, and won't have created a forward reference to a
16761 later parameter. */
16762 if (decl_die
!= NULL
)
16764 add_AT_die_ref (die
, attr
, decl_die
);
16770 /* Last chance: try to create a stack operation procedure to evaluate the
16771 value. Do nothing if even that is not possible or permitted. */
16772 if ((forms
& dw_scalar_form_exprloc
) == 0)
16775 list
= loc_list_from_tree (value
, 2, context
);
16776 if (list
== NULL
|| single_element_loc_list_p (list
))
16778 /* If this attribute is not a reference nor constant, it is
16779 a DWARF expression rather than location description. For that
16780 loc_list_from_tree (value, 0, &context) is needed. */
16781 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
16782 if (list2
&& single_element_loc_list_p (list2
))
16784 add_AT_loc (die
, attr
, list2
->expr
);
16789 /* If that failed to give a single element location list, fall back to
16790 outputting this as a reference... still if permitted. */
16791 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
16794 if (current_function_decl
== 0)
16795 ctx
= comp_unit_die ();
16797 ctx
= lookup_decl_die (current_function_decl
);
16799 decl_die
= new_die (DW_TAG_variable
, ctx
, value
);
16800 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16801 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, ctx
);
16802 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16803 add_AT_die_ref (die
, attr
, decl_die
);
16806 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16810 lower_bound_default (void)
16812 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16818 case DW_LANG_C_plus_plus
:
16819 case DW_LANG_C_plus_plus_11
:
16820 case DW_LANG_C_plus_plus_14
:
16822 case DW_LANG_ObjC_plus_plus
:
16825 case DW_LANG_Fortran77
:
16826 case DW_LANG_Fortran90
:
16827 case DW_LANG_Fortran95
:
16828 case DW_LANG_Fortran03
:
16829 case DW_LANG_Fortran08
:
16833 case DW_LANG_Python
:
16834 return dwarf_version
>= 4 ? 0 : -1;
16835 case DW_LANG_Ada95
:
16836 case DW_LANG_Ada83
:
16837 case DW_LANG_Cobol74
:
16838 case DW_LANG_Cobol85
:
16839 case DW_LANG_Pascal83
:
16840 case DW_LANG_Modula2
:
16842 return dwarf_version
>= 4 ? 1 : -1;
16848 /* Given a tree node describing an array bound (either lower or upper) output
16849 a representation for that bound. */
16852 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
16853 tree bound
, const struct loc_descr_context
*context
)
16858 switch (TREE_CODE (bound
))
16860 /* Strip all conversions. */
16862 case VIEW_CONVERT_EXPR
:
16863 bound
= TREE_OPERAND (bound
, 0);
16866 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
16867 are even omitted when they are the default. */
16869 /* If the value for this bound is the default one, we can even omit the
16871 if (bound_attr
== DW_AT_lower_bound
16872 && tree_fits_shwi_p (bound
)
16873 && (dflt
= lower_bound_default ()) != -1
16874 && tree_to_shwi (bound
) == dflt
)
16880 add_scalar_info (subrange_die
, bound_attr
, bound
,
16881 dw_scalar_form_constant
16882 | dw_scalar_form_exprloc
16883 | dw_scalar_form_reference
,
16889 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16890 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16891 Note that the block of subscript information for an array type also
16892 includes information about the element type of the given array type.
16894 This function reuses previously set type and bound information if
16898 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16900 unsigned dimension_number
;
16902 dw_die_ref child
= type_die
->die_child
;
16904 for (dimension_number
= 0;
16905 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16906 type
= TREE_TYPE (type
), dimension_number
++)
16908 tree domain
= TYPE_DOMAIN (type
);
16910 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16913 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16914 and (in GNU C only) variable bounds. Handle all three forms
16917 /* Find and reuse a previously generated DW_TAG_subrange_type if
16920 For multi-dimensional arrays, as we iterate through the
16921 various dimensions in the enclosing for loop above, we also
16922 iterate through the DIE children and pick at each
16923 DW_TAG_subrange_type previously generated (if available).
16924 Each child DW_TAG_subrange_type DIE describes the range of
16925 the current dimension. At this point we should have as many
16926 DW_TAG_subrange_type's as we have dimensions in the
16928 dw_die_ref subrange_die
= NULL
;
16932 child
= child
->die_sib
;
16933 if (child
->die_tag
== DW_TAG_subrange_type
)
16934 subrange_die
= child
;
16935 if (child
== type_die
->die_child
)
16937 /* If we wrapped around, stop looking next time. */
16941 if (child
->die_tag
== DW_TAG_subrange_type
)
16945 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16949 /* We have an array type with specified bounds. */
16950 lower
= TYPE_MIN_VALUE (domain
);
16951 upper
= TYPE_MAX_VALUE (domain
);
16953 /* Define the index type. */
16954 if (TREE_TYPE (domain
)
16955 && !get_AT (subrange_die
, DW_AT_type
))
16957 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16958 TREE_TYPE field. We can't emit debug info for this
16959 because it is an unnamed integral type. */
16960 if (TREE_CODE (domain
) == INTEGER_TYPE
16961 && TYPE_NAME (domain
) == NULL_TREE
16962 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16963 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16966 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
16967 TYPE_UNQUALIFIED
, type_die
);
16970 /* ??? If upper is NULL, the array has unspecified length,
16971 but it does have a lower bound. This happens with Fortran
16973 Since the debugger is definitely going to need to know N
16974 to produce useful results, go ahead and output the lower
16975 bound solo, and hope the debugger can cope. */
16977 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
16978 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
16979 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
16980 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
16983 /* Otherwise we have an array type with an unspecified length. The
16984 DWARF-2 spec does not say how to handle this; let's just leave out the
16989 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16992 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16994 dw_die_ref decl_die
;
16995 HOST_WIDE_INT size
;
16997 switch (TREE_CODE (tree_node
))
17002 case ENUMERAL_TYPE
:
17005 case QUAL_UNION_TYPE
:
17006 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
17007 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
17009 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
17012 size
= int_size_in_bytes (tree_node
);
17015 /* For a data member of a struct or union, the DW_AT_byte_size is
17016 generally given as the number of bytes normally allocated for an
17017 object of the *declared* type of the member itself. This is true
17018 even for bit-fields. */
17019 size
= int_size_in_bytes (field_type (tree_node
));
17022 gcc_unreachable ();
17025 /* Note that `size' might be -1 when we get to this point. If it is, that
17026 indicates that the byte size of the entity in question is variable. We
17027 have no good way of expressing this fact in Dwarf at the present time,
17028 when location description was not used by the caller code instead. */
17030 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17033 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17034 which specifies the distance in bits from the highest order bit of the
17035 "containing object" for the bit-field to the highest order bit of the
17038 For any given bit-field, the "containing object" is a hypothetical object
17039 (of some integral or enum type) within which the given bit-field lives. The
17040 type of this hypothetical "containing object" is always the same as the
17041 declared type of the individual bit-field itself. The determination of the
17042 exact location of the "containing object" for a bit-field is rather
17043 complicated. It's handled by the `field_byte_offset' function (above).
17045 Note that it is the size (in bytes) of the hypothetical "containing object"
17046 which will be given in the DW_AT_byte_size attribute for this bit-field.
17047 (See `byte_size_attribute' above). */
17050 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17052 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17053 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17054 HOST_WIDE_INT bitpos_int
;
17055 HOST_WIDE_INT highest_order_object_bit_offset
;
17056 HOST_WIDE_INT highest_order_field_bit_offset
;
17057 HOST_WIDE_INT bit_offset
;
17059 /* Must be a field and a bit field. */
17060 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17062 /* We can't yet handle bit-fields whose offsets are variable, so if we
17063 encounter such things, just return without generating any attribute
17064 whatsoever. Likewise for variable or too large size. */
17065 if (! tree_fits_shwi_p (bit_position (decl
))
17066 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
17069 bitpos_int
= int_bit_position (decl
);
17071 /* Note that the bit offset is always the distance (in bits) from the
17072 highest-order bit of the "containing object" to the highest-order bit of
17073 the bit-field itself. Since the "high-order end" of any object or field
17074 is different on big-endian and little-endian machines, the computation
17075 below must take account of these differences. */
17076 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17077 highest_order_field_bit_offset
= bitpos_int
;
17079 if (! BYTES_BIG_ENDIAN
)
17081 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
17082 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17086 = (! BYTES_BIG_ENDIAN
17087 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17088 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17090 if (bit_offset
< 0)
17091 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
17093 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
17096 /* For a FIELD_DECL node which represents a bit field, output an attribute
17097 which specifies the length in bits of the given field. */
17100 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17102 /* Must be a field and a bit field. */
17103 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17104 && DECL_BIT_FIELD_TYPE (decl
));
17106 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
17107 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
17110 /* If the compiled language is ANSI C, then add a 'prototyped'
17111 attribute, if arg types are given for the parameters of a function. */
17114 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17116 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17123 if (prototype_p (func_type
))
17124 add_AT_flag (die
, DW_AT_prototyped
, 1);
17131 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17132 by looking in either the type declaration or object declaration
17135 static inline dw_die_ref
17136 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17138 dw_die_ref origin_die
= NULL
;
17140 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17142 /* We may have gotten separated from the block for the inlined
17143 function, if we're in an exception handler or some such; make
17144 sure that the abstract function has been written out.
17146 Doing this for nested functions is wrong, however; functions are
17147 distinct units, and our context might not even be inline. */
17151 fn
= TYPE_STUB_DECL (fn
);
17153 fn
= decl_function_context (fn
);
17155 dwarf2out_abstract_function (fn
);
17158 if (DECL_P (origin
))
17159 origin_die
= lookup_decl_die (origin
);
17160 else if (TYPE_P (origin
))
17161 origin_die
= lookup_type_die (origin
);
17163 /* XXX: Functions that are never lowered don't always have correct block
17164 trees (in the case of java, they simply have no block tree, in some other
17165 languages). For these functions, there is nothing we can really do to
17166 output correct debug info for inlined functions in all cases. Rather
17167 than die, we'll just produce deficient debug info now, in that we will
17168 have variables without a proper abstract origin. In the future, when all
17169 functions are lowered, we should re-add a gcc_assert (origin_die)
17173 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17177 /* We do not currently support the pure_virtual attribute. */
17180 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17182 if (DECL_VINDEX (func_decl
))
17184 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17186 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
17187 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17188 new_loc_descr (DW_OP_constu
,
17189 tree_to_shwi (DECL_VINDEX (func_decl
)),
17192 /* GNU extension: Record what type this method came from originally. */
17193 if (debug_info_level
> DINFO_LEVEL_TERSE
17194 && DECL_CONTEXT (func_decl
))
17195 add_AT_die_ref (die
, DW_AT_containing_type
,
17196 lookup_type_die (DECL_CONTEXT (func_decl
)));
17200 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17201 given decl. This used to be a vendor extension until after DWARF 4
17202 standardized it. */
17205 add_linkage_attr (dw_die_ref die
, tree decl
)
17207 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17209 /* Mimic what assemble_name_raw does with a leading '*'. */
17210 if (name
[0] == '*')
17213 if (dwarf_version
>= 4)
17214 add_AT_string (die
, DW_AT_linkage_name
, name
);
17216 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17219 /* Add source coordinate attributes for the given decl. */
17222 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17224 expanded_location s
;
17226 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
17228 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17229 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17230 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17233 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17236 add_linkage_name (dw_die_ref die
, tree decl
)
17238 if (debug_info_level
> DINFO_LEVEL_NONE
17239 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17240 && TREE_PUBLIC (decl
)
17241 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17242 && die
->die_tag
!= DW_TAG_member
)
17244 /* Defer until we have an assembler name set. */
17245 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17247 limbo_die_node
*asm_name
;
17249 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
17250 asm_name
->die
= die
;
17251 asm_name
->created_for
= decl
;
17252 asm_name
->next
= deferred_asm_name
;
17253 deferred_asm_name
= asm_name
;
17255 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17256 add_linkage_attr (die
, decl
);
17260 /* Add a DW_AT_name attribute and source coordinate attribute for the
17261 given decl, but only if it actually has a name. */
17264 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17268 decl_name
= DECL_NAME (decl
);
17269 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17271 const char *name
= dwarf2_name (decl
, 0);
17273 add_name_attribute (die
, name
);
17274 if (! DECL_ARTIFICIAL (decl
))
17275 add_src_coords_attributes (die
, decl
);
17277 add_linkage_name (die
, decl
);
17280 #ifdef VMS_DEBUGGING_INFO
17281 /* Get the function's name, as described by its RTL. This may be different
17282 from the DECL_NAME name used in the source file. */
17283 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17285 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17286 XEXP (DECL_RTL (decl
), 0), false);
17287 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17289 #endif /* VMS_DEBUGGING_INFO */
17292 #ifdef VMS_DEBUGGING_INFO
17293 /* Output the debug main pointer die for VMS */
17296 dwarf2out_vms_debug_main_pointer (void)
17298 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17301 /* Allocate the VMS debug main subprogram die. */
17302 die
= ggc_cleared_alloc
<die_node
> ();
17303 die
->die_tag
= DW_TAG_subprogram
;
17304 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17305 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17306 current_function_funcdef_no
);
17307 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17309 /* Make it the first child of comp_unit_die (). */
17310 die
->die_parent
= comp_unit_die ();
17311 if (comp_unit_die ()->die_child
)
17313 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17314 comp_unit_die ()->die_child
->die_sib
= die
;
17318 die
->die_sib
= die
;
17319 comp_unit_die ()->die_child
= die
;
17322 #endif /* VMS_DEBUGGING_INFO */
17324 /* Push a new declaration scope. */
17327 push_decl_scope (tree scope
)
17329 vec_safe_push (decl_scope_table
, scope
);
17332 /* Pop a declaration scope. */
17335 pop_decl_scope (void)
17337 decl_scope_table
->pop ();
17340 /* walk_tree helper function for uses_local_type, below. */
17343 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
17346 *walk_subtrees
= 0;
17349 tree name
= TYPE_NAME (*tp
);
17350 if (name
&& DECL_P (name
) && decl_function_context (name
))
17356 /* If TYPE involves a function-local type (including a local typedef to a
17357 non-local type), returns that type; otherwise returns NULL_TREE. */
17360 uses_local_type (tree type
)
17362 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
17366 /* Return the DIE for the scope that immediately contains this type.
17367 Non-named types that do not involve a function-local type get global
17368 scope. Named types nested in namespaces or other types get their
17369 containing scope. All other types (i.e. function-local named types) get
17370 the current active scope. */
17373 scope_die_for (tree t
, dw_die_ref context_die
)
17375 dw_die_ref scope_die
= NULL
;
17376 tree containing_scope
;
17378 /* Non-types always go in the current scope. */
17379 gcc_assert (TYPE_P (t
));
17381 /* Use the scope of the typedef, rather than the scope of the type
17383 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
17384 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
17386 containing_scope
= TYPE_CONTEXT (t
);
17388 /* Use the containing namespace if there is one. */
17389 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17391 if (context_die
== lookup_decl_die (containing_scope
))
17393 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
17394 context_die
= get_context_die (containing_scope
);
17396 containing_scope
= NULL_TREE
;
17399 /* Ignore function type "scopes" from the C frontend. They mean that
17400 a tagged type is local to a parmlist of a function declarator, but
17401 that isn't useful to DWARF. */
17402 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17403 containing_scope
= NULL_TREE
;
17405 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17407 /* If T uses a local type keep it local as well, to avoid references
17408 to function-local DIEs from outside the function. */
17409 if (current_function_decl
&& uses_local_type (t
))
17410 scope_die
= context_die
;
17412 scope_die
= comp_unit_die ();
17414 else if (TYPE_P (containing_scope
))
17416 /* For types, we can just look up the appropriate DIE. */
17417 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17418 scope_die
= get_context_die (containing_scope
);
17421 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
17422 if (scope_die
== NULL
)
17423 scope_die
= comp_unit_die ();
17427 scope_die
= context_die
;
17432 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17435 local_scope_p (dw_die_ref context_die
)
17437 for (; context_die
; context_die
= context_die
->die_parent
)
17438 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17439 || context_die
->die_tag
== DW_TAG_subprogram
)
17445 /* Returns nonzero if CONTEXT_DIE is a class. */
17448 class_scope_p (dw_die_ref context_die
)
17450 return (context_die
17451 && (context_die
->die_tag
== DW_TAG_structure_type
17452 || context_die
->die_tag
== DW_TAG_class_type
17453 || context_die
->die_tag
== DW_TAG_interface_type
17454 || context_die
->die_tag
== DW_TAG_union_type
));
17457 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17458 whether or not to treat a DIE in this context as a declaration. */
17461 class_or_namespace_scope_p (dw_die_ref context_die
)
17463 return (class_scope_p (context_die
)
17464 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17467 /* Many forms of DIEs require a "type description" attribute. This
17468 routine locates the proper "type descriptor" die for the type given
17469 by 'type' plus any additional qualifiers given by 'cv_quals', and
17470 adds a DW_AT_type attribute below the given die. */
17473 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
17474 dw_die_ref context_die
)
17476 enum tree_code code
= TREE_CODE (type
);
17477 dw_die_ref type_die
= NULL
;
17479 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17480 or fixed-point type, use the inner type. This is because we have no
17481 support for unnamed types in base_type_die. This can happen if this is
17482 an Ada subrange type. Correct solution is emit a subrange type die. */
17483 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17484 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17485 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17487 if (code
== ERROR_MARK
17488 /* Handle a special case. For functions whose return type is void, we
17489 generate *no* type attribute. (Note that no object may have type
17490 `void', so this only applies to function return types). */
17491 || code
== VOID_TYPE
)
17494 type_die
= modified_type_die (type
,
17495 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
17498 if (type_die
!= NULL
)
17499 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17502 /* Given an object die, add the calling convention attribute for the
17503 function call type. */
17505 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17507 enum dwarf_calling_convention value
= DW_CC_normal
;
17509 value
= ((enum dwarf_calling_convention
)
17510 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17513 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17515 /* DWARF 2 doesn't provide a way to identify a program's source-level
17516 entry point. DW_AT_calling_convention attributes are only meant
17517 to describe functions' calling conventions. However, lacking a
17518 better way to signal the Fortran main program, we used this for
17519 a long time, following existing custom. Now, DWARF 4 has
17520 DW_AT_main_subprogram, which we add below, but some tools still
17521 rely on the old way, which we thus keep. */
17522 value
= DW_CC_program
;
17524 if (dwarf_version
>= 4 || !dwarf_strict
)
17525 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17528 /* Only add the attribute if the backend requests it, and
17529 is not DW_CC_normal. */
17530 if (value
&& (value
!= DW_CC_normal
))
17531 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17534 /* Given a tree pointer to a struct, class, union, or enum type node, return
17535 a pointer to the (string) tag name for the given type, or zero if the type
17536 was declared without a tag. */
17538 static const char *
17539 type_tag (const_tree type
)
17541 const char *name
= 0;
17543 if (TYPE_NAME (type
) != 0)
17547 /* Find the IDENTIFIER_NODE for the type name. */
17548 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17549 && !TYPE_NAMELESS (type
))
17550 t
= TYPE_NAME (type
);
17552 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17553 a TYPE_DECL node, regardless of whether or not a `typedef' was
17555 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17556 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17558 /* We want to be extra verbose. Don't call dwarf_name if
17559 DECL_NAME isn't set. The default hook for decl_printable_name
17560 doesn't like that, and in this context it's correct to return
17561 0, instead of "<anonymous>" or the like. */
17562 if (DECL_NAME (TYPE_NAME (type
))
17563 && !DECL_NAMELESS (TYPE_NAME (type
)))
17564 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17567 /* Now get the name as a string, or invent one. */
17568 if (!name
&& t
!= 0)
17569 name
= IDENTIFIER_POINTER (t
);
17572 return (name
== 0 || *name
== '\0') ? 0 : name
;
17575 /* Return the type associated with a data member, make a special check
17576 for bit field types. */
17579 member_declared_type (const_tree member
)
17581 return (DECL_BIT_FIELD_TYPE (member
)
17582 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17585 /* Get the decl's label, as described by its RTL. This may be different
17586 from the DECL_NAME name used in the source file. */
17589 static const char *
17590 decl_start_label (tree decl
)
17593 const char *fnname
;
17595 x
= DECL_RTL (decl
);
17596 gcc_assert (MEM_P (x
));
17599 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17601 fnname
= XSTR (x
, 0);
17606 /* For variable-length arrays that have been previously generated, but
17607 may be incomplete due to missing subscript info, fill the subscript
17608 info. Return TRUE if this is one of those cases. */
17610 fill_variable_array_bounds (tree type
)
17612 if (TREE_ASM_WRITTEN (type
)
17613 && TREE_CODE (type
) == ARRAY_TYPE
17614 && variably_modified_type_p (type
, NULL
))
17616 dw_die_ref array_die
= lookup_type_die (type
);
17619 add_subscript_info (array_die
, type
, !is_ada ());
17625 /* These routines generate the internal representation of the DIE's for
17626 the compilation unit. Debugging information is collected by walking
17627 the declaration trees passed in from dwarf2out_decl(). */
17630 gen_array_type_die (tree type
, dw_die_ref context_die
)
17632 dw_die_ref array_die
;
17634 /* GNU compilers represent multidimensional array types as sequences of one
17635 dimensional array types whose element types are themselves array types.
17636 We sometimes squish that down to a single array_type DIE with multiple
17637 subscripts in the Dwarf debugging info. The draft Dwarf specification
17638 say that we are allowed to do this kind of compression in C, because
17639 there is no difference between an array of arrays and a multidimensional
17640 array. We don't do this for Ada to remain as close as possible to the
17641 actual representation, which is especially important against the language
17642 flexibilty wrt arrays of variable size. */
17644 bool collapse_nested_arrays
= !is_ada ();
17646 if (fill_variable_array_bounds (type
))
17649 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17652 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17653 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17654 if (TYPE_STRING_FLAG (type
)
17655 && TREE_CODE (type
) == ARRAY_TYPE
17657 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17659 HOST_WIDE_INT size
;
17661 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17662 add_name_attribute (array_die
, type_tag (type
));
17663 equate_type_number_to_die (type
, array_die
);
17664 size
= int_size_in_bytes (type
);
17666 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17667 else if (TYPE_DOMAIN (type
) != NULL_TREE
17668 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17669 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17671 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17672 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
17674 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17675 if (loc
&& size
> 0)
17677 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17678 if (size
!= DWARF2_ADDR_SIZE
)
17679 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17685 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17686 add_name_attribute (array_die
, type_tag (type
));
17687 equate_type_number_to_die (type
, array_die
);
17689 if (TREE_CODE (type
) == VECTOR_TYPE
)
17690 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17692 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17694 && TREE_CODE (type
) == ARRAY_TYPE
17695 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17696 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17697 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17700 /* We default the array ordering. SDB will probably do
17701 the right things even if DW_AT_ordering is not present. It's not even
17702 an issue until we start to get into multidimensional arrays anyway. If
17703 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17704 then we'll have to put the DW_AT_ordering attribute back in. (But if
17705 and when we find out that we need to put these in, we will only do so
17706 for multidimensional arrays. */
17707 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17710 if (TREE_CODE (type
) == VECTOR_TYPE
)
17712 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17713 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17714 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
17715 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17716 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
17719 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17721 /* Add representation of the type of the elements of this array type and
17722 emit the corresponding DIE if we haven't done it already. */
17723 element_type
= TREE_TYPE (type
);
17724 if (collapse_nested_arrays
)
17725 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17727 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17729 element_type
= TREE_TYPE (element_type
);
17732 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
, context_die
);
17734 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17735 if (TYPE_ARTIFICIAL (type
))
17736 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17738 if (get_AT (array_die
, DW_AT_name
))
17739 add_pubtype (type
, array_die
);
17742 /* This routine generates DIE for array with hidden descriptor, details
17743 are filled into *info by a langhook. */
17746 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17747 dw_die_ref context_die
)
17749 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17750 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17751 const struct loc_descr_context context
= { type
, info
->base_decl
};
17754 add_name_attribute (array_die
, type_tag (type
));
17755 equate_type_number_to_die (type
, array_die
);
17757 if (info
->ndimensions
> 1)
17758 switch (info
->ordering
)
17760 case array_descr_ordering_row_major
:
17761 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17763 case array_descr_ordering_column_major
:
17764 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17770 if (dwarf_version
>= 3 || !dwarf_strict
)
17772 if (info
->data_location
)
17773 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
17774 dw_scalar_form_exprloc
, &context
);
17775 if (info
->associated
)
17776 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
17777 dw_scalar_form_constant
17778 | dw_scalar_form_exprloc
17779 | dw_scalar_form_reference
, &context
);
17780 if (info
->allocated
)
17781 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
17782 dw_scalar_form_constant
17783 | dw_scalar_form_exprloc
17784 | dw_scalar_form_reference
, &context
);
17787 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17789 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17791 dw_die_ref subrange_die
17792 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17794 if (info
->dimen
[dim
].bounds_type
)
17795 add_type_attribute (subrange_die
,
17796 info
->dimen
[dim
].bounds_type
, 0,
17798 if (info
->dimen
[dim
].lower_bound
)
17799 add_bound_info (subrange_die
, DW_AT_lower_bound
,
17800 info
->dimen
[dim
].lower_bound
, &context
);
17801 if (info
->dimen
[dim
].upper_bound
)
17802 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17803 info
->dimen
[dim
].upper_bound
, &context
);
17804 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
17805 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
17806 info
->dimen
[dim
].stride
,
17807 dw_scalar_form_constant
17808 | dw_scalar_form_exprloc
17809 | dw_scalar_form_reference
,
17813 gen_type_die (info
->element_type
, context_die
);
17814 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
17817 if (get_AT (array_die
, DW_AT_name
))
17818 add_pubtype (type
, array_die
);
17823 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17825 tree origin
= decl_ultimate_origin (decl
);
17826 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17828 if (origin
!= NULL
)
17829 add_abstract_origin_attribute (decl_die
, origin
);
17832 add_name_and_src_coords_attributes (decl_die
, decl
);
17833 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17834 TYPE_UNQUALIFIED
, context_die
);
17837 if (DECL_ABSTRACT_P (decl
))
17838 equate_decl_number_to_die (decl
, decl_die
);
17840 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17844 /* Walk through the list of incomplete types again, trying once more to
17845 emit full debugging info for them. */
17848 retry_incomplete_types (void)
17852 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17853 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17854 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17857 /* Determine what tag to use for a record type. */
17859 static enum dwarf_tag
17860 record_type_tag (tree type
)
17862 if (! lang_hooks
.types
.classify_record
)
17863 return DW_TAG_structure_type
;
17865 switch (lang_hooks
.types
.classify_record (type
))
17867 case RECORD_IS_STRUCT
:
17868 return DW_TAG_structure_type
;
17870 case RECORD_IS_CLASS
:
17871 return DW_TAG_class_type
;
17873 case RECORD_IS_INTERFACE
:
17874 if (dwarf_version
>= 3 || !dwarf_strict
)
17875 return DW_TAG_interface_type
;
17876 return DW_TAG_structure_type
;
17879 gcc_unreachable ();
17883 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17884 include all of the information about the enumeration values also. Each
17885 enumerated type name/value is listed as a child of the enumerated type
17889 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17891 dw_die_ref type_die
= lookup_type_die (type
);
17893 if (type_die
== NULL
)
17895 type_die
= new_die (DW_TAG_enumeration_type
,
17896 scope_die_for (type
, context_die
), type
);
17897 equate_type_number_to_die (type
, type_die
);
17898 add_name_attribute (type_die
, type_tag (type
));
17899 if (dwarf_version
>= 4 || !dwarf_strict
)
17901 if (ENUM_IS_SCOPED (type
))
17902 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17903 if (ENUM_IS_OPAQUE (type
))
17904 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17907 else if (! TYPE_SIZE (type
))
17910 remove_AT (type_die
, DW_AT_declaration
);
17912 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17913 given enum type is incomplete, do not generate the DW_AT_byte_size
17914 attribute or the DW_AT_element_list attribute. */
17915 if (TYPE_SIZE (type
))
17919 TREE_ASM_WRITTEN (type
) = 1;
17920 add_byte_size_attribute (type_die
, type
);
17921 if (dwarf_version
>= 3 || !dwarf_strict
)
17923 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
17924 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
,
17927 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17929 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17930 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17933 /* If the first reference to this type was as the return type of an
17934 inline function, then it may not have a parent. Fix this now. */
17935 if (type_die
->die_parent
== NULL
)
17936 add_child_die (scope_die_for (type
, context_die
), type_die
);
17938 for (link
= TYPE_VALUES (type
);
17939 link
!= NULL
; link
= TREE_CHAIN (link
))
17941 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17942 tree value
= TREE_VALUE (link
);
17944 add_name_attribute (enum_die
,
17945 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17947 if (TREE_CODE (value
) == CONST_DECL
)
17948 value
= DECL_INITIAL (value
);
17950 if (simple_type_size_in_bits (TREE_TYPE (value
))
17951 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17953 /* For constant forms created by add_AT_unsigned DWARF
17954 consumers (GDB, elfutils, etc.) always zero extend
17955 the value. Only when the actual value is negative
17956 do we need to use add_AT_int to generate a constant
17957 form that can represent negative values. */
17958 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17959 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17960 add_AT_unsigned (enum_die
, DW_AT_const_value
,
17961 (unsigned HOST_WIDE_INT
) val
);
17963 add_AT_int (enum_die
, DW_AT_const_value
, val
);
17966 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17967 that here. TODO: This should be re-worked to use correct
17968 signed/unsigned double tags for all cases. */
17969 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17972 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17973 if (TYPE_ARTIFICIAL (type
))
17974 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17977 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17979 add_pubtype (type
, type_die
);
17984 /* Generate a DIE to represent either a real live formal parameter decl or to
17985 represent just the type of some formal parameter position in some function
17988 Note that this routine is a bit unusual because its argument may be a
17989 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17990 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17991 node. If it's the former then this function is being called to output a
17992 DIE to represent a formal parameter object (or some inlining thereof). If
17993 it's the latter, then this function is only being called to output a
17994 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17995 argument type of some subprogram type.
17996 If EMIT_NAME_P is true, name and source coordinate attributes
18000 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
18001 dw_die_ref context_die
)
18003 tree node_or_origin
= node
? node
: origin
;
18004 tree ultimate_origin
;
18005 dw_die_ref parm_die
= NULL
;
18007 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
18009 parm_die
= lookup_decl_die (node
);
18011 /* If the contexts differ, we may not be talking about the same
18013 if (parm_die
&& parm_die
->die_parent
!= context_die
)
18015 if (!DECL_ABSTRACT_P (node
))
18017 /* This can happen when creating an inlined instance, in
18018 which case we need to create a new DIE that will get
18019 annotated with DW_AT_abstract_origin. */
18024 /* FIXME: Reuse DIE even with a differing context.
18026 This happens when called through
18027 dwarf2out_abstract_function for formal parameter
18028 packs. The issue is that we're calling
18029 dwarf2out_abstract_function to build debug info for
18030 the abstract instance of a function for which we have
18031 already generated a DIE in
18032 dwarf2out_early_global_decl.
18034 Once we remove dwarf2out_abstract_function, this
18035 gcc_assert should be a gcc_unreachable. */
18036 gcc_assert (parm_die
->die_parent
->die_tag
18037 == DW_TAG_GNU_formal_parameter_pack
);
18041 if (parm_die
&& parm_die
->die_parent
== NULL
)
18043 /* Check that parm_die already has the right attributes that
18044 we would have added below. If any attributes are
18045 missing, fall through to add them. */
18046 if (! DECL_ABSTRACT_P (node_or_origin
)
18047 && !get_AT (parm_die
, DW_AT_location
)
18048 && !get_AT (parm_die
, DW_AT_const_value
))
18049 /* We are missing location info, and are about to add it. */
18053 add_child_die (context_die
, parm_die
);
18059 /* If we have a previously generated DIE, use it, unless this is an
18060 concrete instance (origin != NULL), in which case we need a new
18061 DIE with a corresponding DW_AT_abstract_origin. */
18063 if (parm_die
&& origin
== NULL
)
18064 reusing_die
= true;
18067 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
18068 reusing_die
= false;
18071 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18073 case tcc_declaration
:
18074 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18075 if (node
|| ultimate_origin
)
18076 origin
= ultimate_origin
;
18081 if (origin
!= NULL
)
18082 add_abstract_origin_attribute (parm_die
, origin
);
18083 else if (emit_name_p
)
18084 add_name_and_src_coords_attributes (parm_die
, node
);
18086 || (! DECL_ABSTRACT_P (node_or_origin
)
18087 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18088 decl_function_context
18089 (node_or_origin
))))
18091 tree type
= TREE_TYPE (node_or_origin
);
18092 if (decl_by_reference_p (node_or_origin
))
18093 add_type_attribute (parm_die
, TREE_TYPE (type
),
18094 TYPE_UNQUALIFIED
, context_die
);
18096 add_type_attribute (parm_die
, type
,
18097 decl_quals (node_or_origin
),
18100 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18101 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18103 if (node
&& node
!= origin
)
18104 equate_decl_number_to_die (node
, parm_die
);
18105 if (! DECL_ABSTRACT_P (node_or_origin
))
18106 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18107 node
== NULL
, DW_AT_location
);
18112 /* We were called with some kind of a ..._TYPE node. */
18113 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
,
18118 gcc_unreachable ();
18124 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18125 children DW_TAG_formal_parameter DIEs representing the arguments of the
18128 PARM_PACK must be a function parameter pack.
18129 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18130 must point to the subsequent arguments of the function PACK_ARG belongs to.
18131 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18132 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18133 following the last one for which a DIE was generated. */
18136 gen_formal_parameter_pack_die (tree parm_pack
,
18138 dw_die_ref subr_die
,
18142 dw_die_ref parm_pack_die
;
18144 gcc_assert (parm_pack
18145 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18148 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18149 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18151 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18153 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18156 gen_formal_parameter_die (arg
, NULL
,
18157 false /* Don't emit name attribute. */,
18162 return parm_pack_die
;
18165 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18166 at the end of an (ANSI prototyped) formal parameters list. */
18169 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18171 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18174 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18175 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18176 parameters as specified in some function type specification (except for
18177 those which appear as part of a function *definition*). */
18180 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18183 tree formal_type
= NULL
;
18184 tree first_parm_type
;
18187 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18189 arg
= DECL_ARGUMENTS (function_or_method_type
);
18190 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18195 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18197 /* Make our first pass over the list of formal parameter types and output a
18198 DW_TAG_formal_parameter DIE for each one. */
18199 for (link
= first_parm_type
; link
; )
18201 dw_die_ref parm_die
;
18203 formal_type
= TREE_VALUE (link
);
18204 if (formal_type
== void_type_node
)
18207 /* Output a (nameless) DIE to represent the formal parameter itself. */
18208 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
18210 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18211 true /* Emit name attribute. */,
18213 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18214 && link
== first_parm_type
)
18216 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18217 if (dwarf_version
>= 3 || !dwarf_strict
)
18218 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18220 else if (arg
&& DECL_ARTIFICIAL (arg
))
18221 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18224 link
= TREE_CHAIN (link
);
18226 arg
= DECL_CHAIN (arg
);
18229 /* If this function type has an ellipsis, add a
18230 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18231 if (formal_type
!= void_type_node
)
18232 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18234 /* Make our second (and final) pass over the list of formal parameter types
18235 and output DIEs to represent those types (as necessary). */
18236 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18237 link
&& TREE_VALUE (link
);
18238 link
= TREE_CHAIN (link
))
18239 gen_type_die (TREE_VALUE (link
), context_die
);
18242 /* We want to generate the DIE for TYPE so that we can generate the
18243 die for MEMBER, which has been defined; we will need to refer back
18244 to the member declaration nested within TYPE. If we're trying to
18245 generate minimal debug info for TYPE, processing TYPE won't do the
18246 trick; we need to attach the member declaration by hand. */
18249 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18251 gen_type_die (type
, context_die
);
18253 /* If we're trying to avoid duplicate debug info, we may not have
18254 emitted the member decl for this function. Emit it now. */
18255 if (TYPE_STUB_DECL (type
)
18256 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18257 && ! lookup_decl_die (member
))
18259 dw_die_ref type_die
;
18260 gcc_assert (!decl_ultimate_origin (member
));
18262 push_decl_scope (type
);
18263 type_die
= lookup_type_die_strip_naming_typedef (type
);
18264 if (TREE_CODE (member
) == FUNCTION_DECL
)
18265 gen_subprogram_die (member
, type_die
);
18266 else if (TREE_CODE (member
) == FIELD_DECL
)
18268 /* Ignore the nameless fields that are used to skip bits but handle
18269 C++ anonymous unions and structs. */
18270 if (DECL_NAME (member
) != NULL_TREE
18271 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18272 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18274 gen_type_die (member_declared_type (member
), type_die
);
18275 gen_field_die (member
, type_die
);
18279 gen_variable_die (member
, NULL_TREE
, type_die
);
18285 /* Forward declare these functions, because they are mutually recursive
18286 with their set_block_* pairing functions. */
18287 static void set_decl_origin_self (tree
);
18288 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
18290 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
18291 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
18292 that it points to the node itself, thus indicating that the node is its
18293 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
18294 the given node is NULL, recursively descend the decl/block tree which
18295 it is the root of, and for each other ..._DECL or BLOCK node contained
18296 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
18297 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
18298 values to point to themselves. */
18301 set_block_origin_self (tree stmt
)
18303 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
18305 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
18310 for (local_decl
= BLOCK_VARS (stmt
);
18311 local_decl
!= NULL_TREE
;
18312 local_decl
= DECL_CHAIN (local_decl
))
18313 /* Do not recurse on nested functions since the inlining status
18314 of parent and child can be different as per the DWARF spec. */
18315 if (TREE_CODE (local_decl
) != FUNCTION_DECL
18316 && !DECL_EXTERNAL (local_decl
))
18317 set_decl_origin_self (local_decl
);
18323 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18324 subblock
!= NULL_TREE
;
18325 subblock
= BLOCK_CHAIN (subblock
))
18326 set_block_origin_self (subblock
); /* Recurse. */
18331 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
18332 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
18333 node to so that it points to the node itself, thus indicating that the
18334 node represents its own (abstract) origin. Additionally, if the
18335 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
18336 the decl/block tree of which the given node is the root of, and for
18337 each other ..._DECL or BLOCK node contained therein whose
18338 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
18339 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
18340 point to themselves. */
18343 set_decl_origin_self (tree decl
)
18345 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
18347 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
18348 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18352 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18353 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
18354 if (DECL_INITIAL (decl
) != NULL_TREE
18355 && DECL_INITIAL (decl
) != error_mark_node
)
18356 set_block_origin_self (DECL_INITIAL (decl
));
18361 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
18362 and if it wasn't 1 before, push it to abstract_vec vector.
18363 For all local decls and all local sub-blocks (recursively) do it
18367 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
18373 if (!BLOCK_ABSTRACT (stmt
))
18375 abstract_vec
.safe_push (stmt
);
18376 BLOCK_ABSTRACT (stmt
) = 1;
18379 for (local_decl
= BLOCK_VARS (stmt
);
18380 local_decl
!= NULL_TREE
;
18381 local_decl
= DECL_CHAIN (local_decl
))
18382 if (! DECL_EXTERNAL (local_decl
))
18383 set_decl_abstract_flags (local_decl
, abstract_vec
);
18385 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18387 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
18388 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
18389 || TREE_CODE (local_decl
) == PARM_DECL
)
18390 set_decl_abstract_flags (local_decl
, abstract_vec
);
18393 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18394 subblock
!= NULL_TREE
;
18395 subblock
= BLOCK_CHAIN (subblock
))
18396 set_block_abstract_flags (subblock
, abstract_vec
);
18399 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
18400 to 1 and if it wasn't 1 before, push to abstract_vec vector.
18401 In the case where the decl is a FUNCTION_DECL also set the abstract
18402 flags for all of the parameters, local vars, local
18403 blocks and sub-blocks (recursively). */
18406 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
18408 if (!DECL_ABSTRACT_P (decl
))
18410 abstract_vec
.safe_push (decl
);
18411 DECL_ABSTRACT_P (decl
) = 1;
18414 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18418 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18419 if (!DECL_ABSTRACT_P (arg
))
18421 abstract_vec
.safe_push (arg
);
18422 DECL_ABSTRACT_P (arg
) = 1;
18424 if (DECL_INITIAL (decl
) != NULL_TREE
18425 && DECL_INITIAL (decl
) != error_mark_node
)
18426 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
18430 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18431 may later generate inlined and/or out-of-line instances of.
18433 FIXME: In the early-dwarf world, this function, and most of the
18434 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
18435 the abstract instance. All we would need to do is annotate
18436 the early DIE with the appropriate DW_AT_inline in late
18437 dwarf (perhaps in gen_inlined_subroutine_die).
18439 However, we can't do this yet, because LTO streaming of DIEs
18440 has not been implemented yet. */
18443 dwarf2out_abstract_function (tree decl
)
18445 dw_die_ref old_die
;
18448 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
18449 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
18450 int old_call_site_count
, old_tail_call_site_count
;
18451 struct call_arg_loc_node
*old_call_arg_locations
;
18453 /* Make sure we have the actual abstract inline, not a clone. */
18454 decl
= DECL_ORIGIN (decl
);
18456 old_die
= lookup_decl_die (decl
);
18457 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18458 /* We've already generated the abstract instance. */
18461 /* We can be called while recursively when seeing block defining inlined subroutine
18462 DIE. Be sure to not clobber the outer location table nor use it or we would
18463 get locations in abstract instantces. */
18464 old_decl_loc_table
= decl_loc_table
;
18465 decl_loc_table
= NULL
;
18466 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
18467 cached_dw_loc_list_table
= NULL
;
18468 old_call_arg_locations
= call_arg_locations
;
18469 call_arg_locations
= NULL
;
18470 old_call_site_count
= call_site_count
;
18471 call_site_count
= -1;
18472 old_tail_call_site_count
= tail_call_site_count
;
18473 tail_call_site_count
= -1;
18475 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18476 we don't get confused by DECL_ABSTRACT_P. */
18477 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18479 context
= decl_class_context (decl
);
18481 gen_type_die_for_member
18482 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18485 /* Pretend we've just finished compiling this function. */
18486 save_fn
= current_function_decl
;
18487 current_function_decl
= decl
;
18489 auto_vec
<tree
, 64> abstract_vec
;
18490 set_decl_abstract_flags (decl
, abstract_vec
);
18491 dwarf2out_decl (decl
);
18494 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
18495 if (TREE_CODE (t
) == BLOCK
)
18496 BLOCK_ABSTRACT (t
) = 0;
18498 DECL_ABSTRACT_P (t
) = 0;
18500 current_function_decl
= save_fn
;
18501 decl_loc_table
= old_decl_loc_table
;
18502 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
18503 call_arg_locations
= old_call_arg_locations
;
18504 call_site_count
= old_call_site_count
;
18505 tail_call_site_count
= old_tail_call_site_count
;
18508 /* Helper function of premark_used_types() which gets called through
18511 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18512 marked as unused by prune_unused_types. */
18515 premark_used_types_helper (tree
const &type
, void *)
18519 die
= lookup_type_die (type
);
18521 die
->die_perennial_p
= 1;
18525 /* Helper function of premark_types_used_by_global_vars which gets called
18526 through htab_traverse.
18528 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18529 marked as unused by prune_unused_types. The DIE of the type is marked
18530 only if the global variable using the type will actually be emitted. */
18533 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
18536 struct types_used_by_vars_entry
*entry
;
18539 entry
= (struct types_used_by_vars_entry
*) *slot
;
18540 gcc_assert (entry
->type
!= NULL
18541 && entry
->var_decl
!= NULL
);
18542 die
= lookup_type_die (entry
->type
);
18545 /* Ask cgraph if the global variable really is to be emitted.
18546 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18547 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
18548 if (node
&& node
->definition
)
18550 die
->die_perennial_p
= 1;
18551 /* Keep the parent DIEs as well. */
18552 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18553 die
->die_perennial_p
= 1;
18559 /* Mark all members of used_types_hash as perennial. */
18562 premark_used_types (struct function
*fun
)
18564 if (fun
&& fun
->used_types_hash
)
18565 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
18568 /* Mark all members of types_used_by_vars_entry as perennial. */
18571 premark_types_used_by_global_vars (void)
18573 if (types_used_by_vars_hash
)
18574 types_used_by_vars_hash
18575 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
18578 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18579 for CA_LOC call arg loc node. */
18582 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18583 struct call_arg_loc_node
*ca_loc
)
18585 dw_die_ref stmt_die
= NULL
, die
;
18586 tree block
= ca_loc
->block
;
18589 && block
!= DECL_INITIAL (decl
)
18590 && TREE_CODE (block
) == BLOCK
)
18592 stmt_die
= BLOCK_DIE (block
);
18595 block
= BLOCK_SUPERCONTEXT (block
);
18597 if (stmt_die
== NULL
)
18598 stmt_die
= subr_die
;
18599 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18600 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18601 if (ca_loc
->tail_call_p
)
18602 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18603 if (ca_loc
->symbol_ref
)
18605 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18607 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18609 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18614 /* Generate a DIE to represent a declared function (either file-scope or
18618 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18620 tree origin
= decl_ultimate_origin (decl
);
18621 dw_die_ref subr_die
;
18622 dw_die_ref old_die
= lookup_decl_die (decl
);
18624 /* This function gets called multiple times for different stages of
18625 the debug process. For example, for func() in this code:
18629 void func() { ... }
18632 ...we get called 4 times. Twice in early debug and twice in
18638 1. Once while generating func() within the namespace. This is
18639 the declaration. The declaration bit below is set, as the
18640 context is the namespace.
18642 A new DIE will be generated with DW_AT_declaration set.
18644 2. Once for func() itself. This is the specification. The
18645 declaration bit below is clear as the context is the CU.
18647 We will use the cached DIE from (1) to create a new DIE with
18648 DW_AT_specification pointing to the declaration in (1).
18650 Late debug via rest_of_handle_final()
18651 -------------------------------------
18653 3. Once generating func() within the namespace. This is also the
18654 declaration, as in (1), but this time we will early exit below
18655 as we have a cached DIE and a declaration needs no additional
18656 annotations (no locations), as the source declaration line
18659 4. Once for func() itself. As in (2), this is the specification,
18660 but this time we will re-use the cached DIE, and just annotate
18661 it with the location information that should now be available.
18663 For something without namespaces, but with abstract instances, we
18664 are also called a multiple times:
18669 Base (); // constructor declaration (1)
18672 Base::Base () { } // constructor specification (2)
18677 1. Once for the Base() constructor by virtue of it being a
18678 member of the Base class. This is done via
18679 rest_of_type_compilation.
18681 This is a declaration, so a new DIE will be created with
18684 2. Once for the Base() constructor definition, but this time
18685 while generating the abstract instance of the base
18686 constructor (__base_ctor) which is being generated via early
18687 debug of reachable functions.
18689 Even though we have a cached version of the declaration (1),
18690 we will create a DW_AT_specification of the declaration DIE
18693 3. Once for the __base_ctor itself, but this time, we generate
18694 an DW_AT_abstract_origin version of the DW_AT_specification in
18697 Late debug via rest_of_handle_final
18698 -----------------------------------
18700 4. One final time for the __base_ctor (which will have a cached
18701 DIE with DW_AT_abstract_origin created in (3). This time,
18702 we will just annotate the location information now
18705 int declaration
= (current_function_decl
!= decl
18706 || class_or_namespace_scope_p (context_die
));
18708 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18710 /* Now that the C++ front end lazily declares artificial member fns, we
18711 might need to retrofit the declaration into its class. */
18712 if (!declaration
&& !origin
&& !old_die
18713 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18714 && !class_or_namespace_scope_p (context_die
)
18715 && debug_info_level
> DINFO_LEVEL_TERSE
)
18716 old_die
= force_decl_die (decl
);
18718 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
18719 if (origin
!= NULL
)
18721 gcc_assert (!declaration
|| local_scope_p (context_die
));
18723 /* Fixup die_parent for the abstract instance of a nested
18724 inline function. */
18725 if (old_die
&& old_die
->die_parent
== NULL
)
18726 add_child_die (context_die
, old_die
);
18728 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
18730 /* If we have a DW_AT_abstract_origin we have a working
18732 subr_die
= old_die
;
18736 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18737 add_abstract_origin_attribute (subr_die
, origin
);
18738 /* This is where the actual code for a cloned function is.
18739 Let's emit linkage name attribute for it. This helps
18740 debuggers to e.g, set breakpoints into
18741 constructors/destructors when the user asks "break
18743 add_linkage_name (subr_die
, decl
);
18746 /* A cached copy, possibly from early dwarf generation. Reuse as
18747 much as possible. */
18750 /* A declaration that has been previously dumped needs no
18751 additional information. */
18755 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18756 /* We can have a normal definition following an inline one in the
18757 case of redefinition of GNU C extern inlines.
18758 It seems reasonable to use AT_specification in this case. */
18759 && !get_AT (old_die
, DW_AT_inline
))
18761 /* Detect and ignore this case, where we are trying to output
18762 something we have already output. */
18763 if (get_AT (old_die
, DW_AT_low_pc
)
18764 || get_AT (old_die
, DW_AT_ranges
))
18767 /* If we have no location information, this must be a
18768 partially generated DIE from early dwarf generation.
18769 Fall through and generate it. */
18772 /* If the definition comes from the same place as the declaration,
18773 maybe use the old DIE. We always want the DIE for this function
18774 that has the *_pc attributes to be under comp_unit_die so the
18775 debugger can find it. We also need to do this for abstract
18776 instances of inlines, since the spec requires the out-of-line copy
18777 to have the same parent. For local class methods, this doesn't
18778 apply; we just use the old DIE. */
18779 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18780 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18781 if ((is_cu_die (old_die
->die_parent
)
18782 /* This condition fixes the inconsistency/ICE with the
18783 following Fortran test (or some derivative thereof) while
18784 building libgfortran:
18788 logical function funky (FLAG)
18793 || (old_die
->die_parent
18794 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
18795 || context_die
== NULL
)
18796 && (DECL_ARTIFICIAL (decl
)
18797 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18798 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18799 == (unsigned) s
.line
))))
18801 subr_die
= old_die
;
18803 /* Clear out the declaration attribute, but leave the
18804 parameters so they can be augmented with location
18805 information later. Unless this was a declaration, in
18806 which case, wipe out the nameless parameters and recreate
18807 them further down. */
18808 if (remove_AT (subr_die
, DW_AT_declaration
))
18811 remove_AT (subr_die
, DW_AT_object_pointer
);
18812 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18815 /* Make a specification pointing to the previously built
18819 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18820 add_AT_specification (subr_die
, old_die
);
18821 add_pubname (decl
, subr_die
);
18822 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18823 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18824 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18825 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18827 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18828 emit the real type on the definition die. */
18829 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18831 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18832 if (die
== auto_die
|| die
== decltype_auto_die
)
18833 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18834 TYPE_UNQUALIFIED
, context_die
);
18838 /* Create a fresh DIE for anything else. */
18841 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18843 if (TREE_PUBLIC (decl
))
18844 add_AT_flag (subr_die
, DW_AT_external
, 1);
18846 add_name_and_src_coords_attributes (subr_die
, decl
);
18847 add_pubname (decl
, subr_die
);
18848 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18850 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18851 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18852 TYPE_UNQUALIFIED
, context_die
);
18855 add_pure_or_virtual_attribute (subr_die
, decl
);
18856 if (DECL_ARTIFICIAL (decl
))
18857 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18859 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
18860 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
18862 add_accessibility_attribute (subr_die
, decl
);
18865 /* Unless we have an existing non-declaration DIE, equate the new
18867 if (!old_die
|| is_declaration_die (old_die
))
18868 equate_decl_number_to_die (decl
, subr_die
);
18872 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18874 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18876 /* If this is an explicit function declaration then generate
18877 a DW_AT_explicit attribute. */
18878 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18879 && (dwarf_version
>= 3 || !dwarf_strict
))
18880 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18882 /* If this is a C++11 deleted special function member then generate
18883 a DW_AT_GNU_deleted attribute. */
18884 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
18885 && (! dwarf_strict
))
18886 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
18889 /* Tag abstract instances with DW_AT_inline. */
18890 else if (DECL_ABSTRACT_P (decl
))
18892 if (DECL_DECLARED_INLINE_P (decl
))
18894 if (cgraph_function_possibly_inlined_p (decl
))
18895 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18897 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18901 if (cgraph_function_possibly_inlined_p (decl
))
18902 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18904 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18907 if (DECL_DECLARED_INLINE_P (decl
)
18908 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18909 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18911 /* For non DECL_EXTERNALs, if range information is available, fill
18912 the DIE with it. */
18913 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
18915 HOST_WIDE_INT cfa_fb_offset
;
18917 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18919 if (!flag_reorder_blocks_and_partition
)
18921 dw_fde_ref fde
= fun
->fde
;
18922 if (fde
->dw_fde_begin
)
18924 /* We have already generated the labels. */
18925 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18926 fde
->dw_fde_end
, false);
18930 /* Create start/end labels and add the range. */
18931 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18932 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18933 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18934 current_function_funcdef_no
);
18935 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18936 current_function_funcdef_no
);
18937 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18941 #if VMS_DEBUGGING_INFO
18942 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18943 Section 2.3 Prologue and Epilogue Attributes:
18944 When a breakpoint is set on entry to a function, it is generally
18945 desirable for execution to be suspended, not on the very first
18946 instruction of the function, but rather at a point after the
18947 function's frame has been set up, after any language defined local
18948 declaration processing has been completed, and before execution of
18949 the first statement of the function begins. Debuggers generally
18950 cannot properly determine where this point is. Similarly for a
18951 breakpoint set on exit from a function. The prologue and epilogue
18952 attributes allow a compiler to communicate the location(s) to use. */
18955 if (fde
->dw_fde_vms_end_prologue
)
18956 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18957 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18959 if (fde
->dw_fde_vms_begin_epilogue
)
18960 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18961 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18968 /* Generate pubnames entries for the split function code ranges. */
18969 dw_fde_ref fde
= fun
->fde
;
18971 if (fde
->dw_fde_second_begin
)
18973 if (dwarf_version
>= 3 || !dwarf_strict
)
18975 /* We should use ranges for non-contiguous code section
18976 addresses. Use the actual code range for the initial
18977 section, since the HOT/COLD labels might precede an
18978 alignment offset. */
18979 bool range_list_added
= false;
18980 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18981 fde
->dw_fde_end
, &range_list_added
,
18983 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18984 fde
->dw_fde_second_end
,
18985 &range_list_added
, false);
18986 if (range_list_added
)
18991 /* There is no real support in DW2 for this .. so we make
18992 a work-around. First, emit the pub name for the segment
18993 containing the function label. Then make and emit a
18994 simplified subprogram DIE for the second segment with the
18995 name pre-fixed by __hot/cold_sect_of_. We use the same
18996 linkage name for the second die so that gdb will find both
18997 sections when given "b foo". */
18998 const char *name
= NULL
;
18999 tree decl_name
= DECL_NAME (decl
);
19000 dw_die_ref seg_die
;
19002 /* Do the 'primary' section. */
19003 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
19004 fde
->dw_fde_end
, false);
19006 /* Build a minimal DIE for the secondary section. */
19007 seg_die
= new_die (DW_TAG_subprogram
,
19008 subr_die
->die_parent
, decl
);
19010 if (TREE_PUBLIC (decl
))
19011 add_AT_flag (seg_die
, DW_AT_external
, 1);
19013 if (decl_name
!= NULL
19014 && IDENTIFIER_POINTER (decl_name
) != NULL
)
19016 name
= dwarf2_name (decl
, 1);
19017 if (! DECL_ARTIFICIAL (decl
))
19018 add_src_coords_attributes (seg_die
, decl
);
19020 add_linkage_name (seg_die
, decl
);
19022 gcc_assert (name
!= NULL
);
19023 add_pure_or_virtual_attribute (seg_die
, decl
);
19024 if (DECL_ARTIFICIAL (decl
))
19025 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
19027 name
= concat ("__second_sect_of_", name
, NULL
);
19028 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
19029 fde
->dw_fde_second_end
, false);
19030 add_name_attribute (seg_die
, name
);
19031 if (want_pubnames ())
19032 add_pubname_string (name
, seg_die
);
19036 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
19040 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
19042 /* We define the "frame base" as the function's CFA. This is more
19043 convenient for several reasons: (1) It's stable across the prologue
19044 and epilogue, which makes it better than just a frame pointer,
19045 (2) With dwarf3, there exists a one-byte encoding that allows us
19046 to reference the .debug_frame data by proxy, but failing that,
19047 (3) We can at least reuse the code inspection and interpretation
19048 code that determines the CFA position at various points in the
19050 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
19052 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
19053 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
19057 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
19058 if (list
->dw_loc_next
)
19059 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
19061 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
19064 /* Compute a displacement from the "steady-state frame pointer" to
19065 the CFA. The former is what all stack slots and argument slots
19066 will reference in the rtl; the latter is what we've told the
19067 debugger about. We'll need to adjust all frame_base references
19068 by this displacement. */
19069 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19071 if (fun
->static_chain_decl
)
19072 add_AT_location_description
19073 (subr_die
, DW_AT_static_link
,
19074 loc_list_from_tree (fun
->static_chain_decl
, 2, NULL
));
19077 /* Generate child dies for template paramaters. */
19078 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19079 gen_generic_params_dies (decl
);
19081 /* Now output descriptions of the arguments for this function. This gets
19082 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19083 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19084 `...' at the end of the formal parameter list. In order to find out if
19085 there was a trailing ellipsis or not, we must instead look at the type
19086 associated with the FUNCTION_DECL. This will be a node of type
19087 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19088 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19089 an ellipsis at the end. */
19091 /* In the case where we are describing a mere function declaration, all we
19092 need to do here (and all we *can* do here) is to describe the *types* of
19093 its formal parameters. */
19094 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19096 else if (declaration
)
19097 gen_formal_types_die (decl
, subr_die
);
19100 /* Generate DIEs to represent all known formal parameters. */
19101 tree parm
= DECL_ARGUMENTS (decl
);
19102 tree generic_decl
= early_dwarf
19103 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
19104 tree generic_decl_parm
= generic_decl
19105 ? DECL_ARGUMENTS (generic_decl
)
19108 /* Now we want to walk the list of parameters of the function and
19109 emit their relevant DIEs.
19111 We consider the case of DECL being an instance of a generic function
19112 as well as it being a normal function.
19114 If DECL is an instance of a generic function we walk the
19115 parameters of the generic function declaration _and_ the parameters of
19116 DECL itself. This is useful because we want to emit specific DIEs for
19117 function parameter packs and those are declared as part of the
19118 generic function declaration. In that particular case,
19119 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19120 That DIE has children DIEs representing the set of arguments
19121 of the pack. Note that the set of pack arguments can be empty.
19122 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19125 Otherwise, we just consider the parameters of DECL. */
19126 while (generic_decl_parm
|| parm
)
19128 if (generic_decl_parm
19129 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19130 gen_formal_parameter_pack_die (generic_decl_parm
,
19133 else if (parm
&& !POINTER_BOUNDS_P (parm
))
19135 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19137 if (parm
== DECL_ARGUMENTS (decl
)
19138 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19140 && (dwarf_version
>= 3 || !dwarf_strict
))
19141 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19143 parm
= DECL_CHAIN (parm
);
19146 parm
= DECL_CHAIN (parm
);
19148 if (generic_decl_parm
)
19149 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19152 /* Decide whether we need an unspecified_parameters DIE at the end.
19153 There are 2 more cases to do this for: 1) the ansi ... declaration -
19154 this is detectable when the end of the arg list is not a
19155 void_type_node 2) an unprototyped function declaration (not a
19156 definition). This just means that we have no info about the
19157 parameters at all. */
19158 if (prototype_p (TREE_TYPE (decl
)))
19160 /* This is the prototyped case, check for.... */
19161 if (stdarg_p (TREE_TYPE (decl
)))
19162 gen_unspecified_parameters_die (decl
, subr_die
);
19164 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19165 gen_unspecified_parameters_die (decl
, subr_die
);
19168 if (subr_die
!= old_die
)
19169 /* Add the calling convention attribute if requested. */
19170 add_calling_convention_attribute (subr_die
, decl
);
19172 /* Output Dwarf info for all of the stuff within the body of the function
19173 (if it has one - it may be just a declaration).
19175 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19176 a function. This BLOCK actually represents the outermost binding contour
19177 for the function, i.e. the contour in which the function's formal
19178 parameters and labels get declared. Curiously, it appears that the front
19179 end doesn't actually put the PARM_DECL nodes for the current function onto
19180 the BLOCK_VARS list for this outer scope, but are strung off of the
19181 DECL_ARGUMENTS list for the function instead.
19183 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19184 the LABEL_DECL nodes for the function however, and we output DWARF info
19185 for those in decls_for_scope. Just within the `outer_scope' there will be
19186 a BLOCK node representing the function's outermost pair of curly braces,
19187 and any blocks used for the base and member initializers of a C++
19188 constructor function. */
19189 tree outer_scope
= DECL_INITIAL (decl
);
19190 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19192 int call_site_note_count
= 0;
19193 int tail_call_site_note_count
= 0;
19195 /* Emit a DW_TAG_variable DIE for a named return value. */
19196 if (DECL_NAME (DECL_RESULT (decl
)))
19197 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19199 /* The first time through decls_for_scope we will generate the
19200 DIEs for the locals. The second time, we fill in the
19202 decls_for_scope (outer_scope
, subr_die
);
19204 if (call_arg_locations
&& !dwarf_strict
)
19206 struct call_arg_loc_node
*ca_loc
;
19207 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
19209 dw_die_ref die
= NULL
;
19210 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
19213 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
19214 arg
; arg
= next_arg
)
19216 dw_loc_descr_ref reg
, val
;
19217 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
19218 dw_die_ref cdie
, tdie
= NULL
;
19220 next_arg
= XEXP (arg
, 1);
19221 if (REG_P (XEXP (XEXP (arg
, 0), 0))
19223 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
19224 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
19225 && REGNO (XEXP (XEXP (arg
, 0), 0))
19226 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
19227 next_arg
= XEXP (next_arg
, 1);
19228 if (mode
== VOIDmode
)
19230 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
19231 if (mode
== VOIDmode
)
19232 mode
= GET_MODE (XEXP (arg
, 0));
19234 if (mode
== VOIDmode
|| mode
== BLKmode
)
19236 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
19238 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19239 tloc
= XEXP (XEXP (arg
, 0), 1);
19242 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
19243 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
19245 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19246 tlocc
= XEXP (XEXP (arg
, 0), 1);
19250 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
19251 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
19252 VAR_INIT_STATUS_INITIALIZED
);
19253 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
19255 rtx mem
= XEXP (XEXP (arg
, 0), 0);
19256 reg
= mem_loc_descriptor (XEXP (mem
, 0),
19257 get_address_mode (mem
),
19259 VAR_INIT_STATUS_INITIALIZED
);
19261 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
19262 == DEBUG_PARAMETER_REF
)
19265 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
19266 tdie
= lookup_decl_die (tdecl
);
19273 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
19274 != DEBUG_PARAMETER_REF
)
19276 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
19278 VAR_INIT_STATUS_INITIALIZED
);
19282 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19283 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
19286 add_AT_loc (cdie
, DW_AT_location
, reg
);
19287 else if (tdie
!= NULL
)
19288 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
19289 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
19290 if (next_arg
!= XEXP (arg
, 1))
19292 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
19293 if (mode
== VOIDmode
)
19294 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
19295 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
19298 VAR_INIT_STATUS_INITIALIZED
);
19300 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
19304 && (ca_loc
->symbol_ref
|| tloc
))
19305 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19306 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
19308 dw_loc_descr_ref tval
= NULL
;
19310 if (tloc
!= NULL_RTX
)
19311 tval
= mem_loc_descriptor (tloc
,
19312 GET_MODE (tloc
) == VOIDmode
19313 ? Pmode
: GET_MODE (tloc
),
19315 VAR_INIT_STATUS_INITIALIZED
);
19317 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
19318 else if (tlocc
!= NULL_RTX
)
19320 tval
= mem_loc_descriptor (tlocc
,
19321 GET_MODE (tlocc
) == VOIDmode
19322 ? Pmode
: GET_MODE (tlocc
),
19324 VAR_INIT_STATUS_INITIALIZED
);
19326 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
19332 call_site_note_count
++;
19333 if (ca_loc
->tail_call_p
)
19334 tail_call_site_note_count
++;
19338 call_arg_locations
= NULL
;
19339 call_arg_loc_last
= NULL
;
19340 if (tail_call_site_count
>= 0
19341 && tail_call_site_count
== tail_call_site_note_count
19344 if (call_site_count
>= 0
19345 && call_site_count
== call_site_note_count
)
19346 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
19348 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
19350 call_site_count
= -1;
19351 tail_call_site_count
= -1;
19355 /* Returns a hash value for X (which really is a die_struct). */
19358 block_die_hasher::hash (die_struct
*d
)
19360 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19363 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19364 as decl_id and die_parent of die_struct Y. */
19367 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
19369 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
19372 /* Return TRUE if DECL, which may have been previously generated as
19373 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
19374 true if decl (or its origin) is either an extern declaration or a
19375 class/namespace scoped declaration.
19377 The declare_in_namespace support causes us to get two DIEs for one
19378 variable, both of which are declarations. We want to avoid
19379 considering one to be a specification, so we must test for
19380 DECLARATION and DW_AT_declaration. */
19382 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
19384 return (old_die
&& TREE_STATIC (decl
) && !declaration
19385 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
19388 /* Return true if DECL is a local static. */
19391 local_function_static (tree decl
)
19393 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
19394 return TREE_STATIC (decl
)
19395 && DECL_CONTEXT (decl
)
19396 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
19399 /* Generate a DIE to represent a declared data object.
19400 Either DECL or ORIGIN must be non-null. */
19403 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19405 HOST_WIDE_INT off
= 0;
19407 tree decl_or_origin
= decl
? decl
: origin
;
19408 tree ultimate_origin
;
19409 dw_die_ref var_die
;
19410 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19411 dw_die_ref origin_die
= NULL
;
19412 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19413 || class_or_namespace_scope_p (context_die
));
19414 bool specialization_p
= false;
19416 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19417 if (decl
|| ultimate_origin
)
19418 origin
= ultimate_origin
;
19419 com_decl
= fortran_common (decl_or_origin
, &off
);
19421 /* Symbol in common gets emitted as a child of the common block, in the form
19422 of a data member. */
19425 dw_die_ref com_die
;
19426 dw_loc_list_ref loc
;
19427 die_node com_die_arg
;
19429 var_die
= lookup_decl_die (decl_or_origin
);
19432 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19434 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
19439 /* Optimize the common case. */
19440 if (single_element_loc_list_p (loc
)
19441 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19442 && loc
->expr
->dw_loc_next
== NULL
19443 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19446 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19447 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19448 = plus_constant (GET_MODE (x
), x
, off
);
19451 loc_list_plus_const (loc
, off
);
19453 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19454 remove_AT (var_die
, DW_AT_declaration
);
19460 if (common_block_die_table
== NULL
)
19461 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
19463 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19464 com_die_arg
.die_parent
= context_die
;
19465 com_die
= common_block_die_table
->find (&com_die_arg
);
19466 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19467 if (com_die
== NULL
)
19470 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19473 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19474 add_name_and_src_coords_attributes (com_die
, com_decl
);
19477 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19478 /* Avoid sharing the same loc descriptor between
19479 DW_TAG_common_block and DW_TAG_variable. */
19480 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19482 else if (DECL_EXTERNAL (decl
))
19483 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19484 if (want_pubnames ())
19485 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19486 com_die
->decl_id
= DECL_UID (com_decl
);
19487 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
19490 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19492 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19493 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19494 remove_AT (com_die
, DW_AT_declaration
);
19496 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19497 add_name_and_src_coords_attributes (var_die
, decl
);
19498 add_type_attribute (var_die
, TREE_TYPE (decl
), decl_quals (decl
),
19500 add_AT_flag (var_die
, DW_AT_external
, 1);
19505 /* Optimize the common case. */
19506 if (single_element_loc_list_p (loc
)
19507 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19508 && loc
->expr
->dw_loc_next
== NULL
19509 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19511 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19512 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19513 = plus_constant (GET_MODE (x
), x
, off
);
19516 loc_list_plus_const (loc
, off
);
19518 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19520 else if (DECL_EXTERNAL (decl
))
19521 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19522 equate_decl_number_to_die (decl
, var_die
);
19530 /* A declaration that has been previously dumped, needs no
19531 further annotations, since it doesn't need location on
19532 the second pass. */
19535 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
19536 && !get_AT (old_die
, DW_AT_specification
))
19538 /* Fall-thru so we can make a new variable die along with a
19539 DW_AT_specification. */
19541 else if (origin
&& old_die
->die_parent
!= context_die
)
19543 /* If we will be creating an inlined instance, we need a
19544 new DIE that will get annotated with
19545 DW_AT_abstract_origin. Clear things so we can get a
19547 gcc_assert (!DECL_ABSTRACT_P (decl
));
19552 /* If a DIE was dumped early, it still needs location info.
19553 Skip to where we fill the location bits. */
19555 goto gen_variable_die_location
;
19559 /* For static data members, the declaration in the class is supposed
19560 to have DW_TAG_member tag; the specification should still be
19561 DW_TAG_variable referencing the DW_TAG_member DIE. */
19562 if (declaration
&& class_scope_p (context_die
))
19563 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19565 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19567 if (origin
!= NULL
)
19568 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19570 /* Loop unrolling can create multiple blocks that refer to the same
19571 static variable, so we must test for the DW_AT_declaration flag.
19573 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19574 copy decls and set the DECL_ABSTRACT_P flag on them instead of
19577 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
19578 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
19580 /* This is a definition of a C++ class level static. */
19581 add_AT_specification (var_die
, old_die
);
19582 specialization_p
= true;
19583 if (DECL_NAME (decl
))
19585 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19586 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19588 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19589 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19591 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19592 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19594 if (old_die
->die_tag
== DW_TAG_member
)
19595 add_linkage_name (var_die
, decl
);
19599 add_name_and_src_coords_attributes (var_die
, decl
);
19601 if ((origin
== NULL
&& !specialization_p
)
19603 && !DECL_ABSTRACT_P (decl_or_origin
)
19604 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19605 decl_function_context
19606 (decl_or_origin
))))
19608 tree type
= TREE_TYPE (decl_or_origin
);
19610 if (decl_by_reference_p (decl_or_origin
))
19611 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19614 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
19618 if (origin
== NULL
&& !specialization_p
)
19620 if (TREE_PUBLIC (decl
))
19621 add_AT_flag (var_die
, DW_AT_external
, 1);
19623 if (DECL_ARTIFICIAL (decl
))
19624 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19626 add_accessibility_attribute (var_die
, decl
);
19630 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19632 if (decl
&& (DECL_ABSTRACT_P (decl
)
19633 || !old_die
|| is_declaration_die (old_die
)))
19634 equate_decl_number_to_die (decl
, var_die
);
19636 gen_variable_die_location
:
19638 && (! DECL_ABSTRACT_P (decl_or_origin
)
19639 /* Local static vars are shared between all clones/inlines,
19640 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19642 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19643 && TREE_STATIC (decl_or_origin
)
19644 && DECL_RTL_SET_P (decl_or_origin
)))
19645 /* When abstract origin already has DW_AT_location attribute, no need
19646 to add it again. */
19647 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19650 add_pubname (decl_or_origin
, var_die
);
19652 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
19653 decl
== NULL
, DW_AT_location
);
19656 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19659 /* Generate a DIE to represent a named constant. */
19662 gen_const_die (tree decl
, dw_die_ref context_die
)
19664 dw_die_ref const_die
;
19665 tree type
= TREE_TYPE (decl
);
19667 const_die
= lookup_decl_die (decl
);
19671 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19672 equate_decl_number_to_die (decl
, const_die
);
19673 add_name_and_src_coords_attributes (const_die
, decl
);
19674 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, context_die
);
19675 if (TREE_PUBLIC (decl
))
19676 add_AT_flag (const_die
, DW_AT_external
, 1);
19677 if (DECL_ARTIFICIAL (decl
))
19678 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19679 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19682 /* Generate a DIE to represent a label identifier. */
19685 gen_label_die (tree decl
, dw_die_ref context_die
)
19687 tree origin
= decl_ultimate_origin (decl
);
19688 dw_die_ref lbl_die
= lookup_decl_die (decl
);
19690 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19694 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19695 equate_decl_number_to_die (decl
, lbl_die
);
19697 if (origin
!= NULL
)
19698 add_abstract_origin_attribute (lbl_die
, origin
);
19700 add_name_and_src_coords_attributes (lbl_die
, decl
);
19703 if (DECL_ABSTRACT_P (decl
))
19704 equate_decl_number_to_die (decl
, lbl_die
);
19707 insn
= DECL_RTL_IF_SET (decl
);
19709 /* Deleted labels are programmer specified labels which have been
19710 eliminated because of various optimizations. We still emit them
19711 here so that it is possible to put breakpoints on them. */
19715 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19717 /* When optimization is enabled (via -O) some parts of the compiler
19718 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19719 represent source-level labels which were explicitly declared by
19720 the user. This really shouldn't be happening though, so catch
19721 it if it ever does happen. */
19722 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
19724 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19725 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19729 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19730 && CODE_LABEL_NUMBER (insn
) != -1)
19732 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19733 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19738 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19739 attributes to the DIE for a block STMT, to describe where the inlined
19740 function was called from. This is similar to add_src_coords_attributes. */
19743 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19745 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19747 if (dwarf_version
>= 3 || !dwarf_strict
)
19749 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19750 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19755 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19756 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19759 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19761 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19763 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19764 && (dwarf_version
>= 3 || !dwarf_strict
))
19766 tree chain
, superblock
= NULL_TREE
;
19768 dw_attr_ref attr
= NULL
;
19770 if (inlined_function_outer_scope_p (stmt
))
19772 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19773 BLOCK_NUMBER (stmt
));
19774 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19777 /* Optimize duplicate .debug_ranges lists or even tails of
19778 lists. If this BLOCK has same ranges as its supercontext,
19779 lookup DW_AT_ranges attribute in the supercontext (and
19780 recursively so), verify that the ranges_table contains the
19781 right values and use it instead of adding a new .debug_range. */
19782 for (chain
= stmt
, pdie
= die
;
19783 BLOCK_SAME_RANGE (chain
);
19784 chain
= BLOCK_SUPERCONTEXT (chain
))
19786 dw_attr_ref new_attr
;
19788 pdie
= pdie
->die_parent
;
19791 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19793 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19794 if (new_attr
== NULL
19795 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19798 superblock
= BLOCK_SUPERCONTEXT (chain
);
19801 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19802 / 2 / DWARF2_ADDR_SIZE
].num
19803 == BLOCK_NUMBER (superblock
))
19804 && BLOCK_FRAGMENT_CHAIN (superblock
))
19806 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19807 / 2 / DWARF2_ADDR_SIZE
;
19808 unsigned long supercnt
= 0, thiscnt
= 0;
19809 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19810 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19813 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19814 == BLOCK_NUMBER (chain
));
19816 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19817 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19818 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19820 gcc_assert (supercnt
>= thiscnt
);
19821 add_AT_range_list (die
, DW_AT_ranges
,
19822 ((off
+ supercnt
- thiscnt
)
19823 * 2 * DWARF2_ADDR_SIZE
),
19828 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19830 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19833 add_ranges (chain
);
19834 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19841 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19842 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19843 BLOCK_NUMBER (stmt
));
19844 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19845 BLOCK_NUMBER (stmt
));
19846 add_AT_low_high_pc (die
, label
, label_high
, false);
19850 /* Generate a DIE for a lexical block. */
19853 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
19855 dw_die_ref old_die
= BLOCK_DIE (stmt
);
19856 dw_die_ref stmt_die
= NULL
;
19859 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19860 BLOCK_DIE (stmt
) = stmt_die
;
19863 if (BLOCK_ABSTRACT (stmt
))
19867 #ifdef ENABLE_CHECKING
19868 /* This must have been generated early and it won't even
19869 need location information since it's a DW_AT_inline
19871 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
19872 if (c
->die_tag
== DW_TAG_inlined_subroutine
19873 || c
->die_tag
== DW_TAG_subprogram
)
19875 gcc_assert (get_AT (c
, DW_AT_inline
));
19882 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
19884 /* If this is an inlined instance, create a new lexical die for
19885 anything below to attach DW_AT_abstract_origin to. */
19888 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19889 BLOCK_DIE (stmt
) = stmt_die
;
19895 stmt_die
= old_die
;
19897 /* A non abstract block whose blocks have already been reordered
19898 should have the instruction range for this block. If so, set the
19899 high/low attributes. */
19900 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19902 gcc_assert (stmt_die
);
19903 add_high_low_attributes (stmt
, stmt_die
);
19906 decls_for_scope (stmt
, stmt_die
);
19909 /* Generate a DIE for an inlined subprogram. */
19912 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
19916 /* The instance of function that is effectively being inlined shall not
19918 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19920 decl
= block_ultimate_origin (stmt
);
19922 /* Emit info for the abstract instance first, if we haven't yet. We
19923 must emit this even if the block is abstract, otherwise when we
19924 emit the block below (or elsewhere), we may end up trying to emit
19925 a die whose origin die hasn't been emitted, and crashing. */
19926 dwarf2out_abstract_function (decl
);
19928 if (! BLOCK_ABSTRACT (stmt
))
19930 dw_die_ref subr_die
19931 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19933 if (call_arg_locations
)
19934 BLOCK_DIE (stmt
) = subr_die
;
19935 add_abstract_origin_attribute (subr_die
, decl
);
19936 if (TREE_ASM_WRITTEN (stmt
))
19937 add_high_low_attributes (stmt
, subr_die
);
19938 add_call_src_coords_attributes (stmt
, subr_die
);
19940 decls_for_scope (stmt
, subr_die
);
19944 /* Generate a DIE for a field in a record, or structure. */
19947 gen_field_die (tree decl
, dw_die_ref context_die
)
19949 dw_die_ref decl_die
;
19951 if (TREE_TYPE (decl
) == error_mark_node
)
19954 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19955 add_name_and_src_coords_attributes (decl_die
, decl
);
19956 add_type_attribute (decl_die
, member_declared_type (decl
),
19957 decl_quals (decl
), context_die
);
19959 if (DECL_BIT_FIELD_TYPE (decl
))
19961 add_byte_size_attribute (decl_die
, decl
);
19962 add_bit_size_attribute (decl_die
, decl
);
19963 add_bit_offset_attribute (decl_die
, decl
);
19966 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19967 add_data_member_location_attribute (decl_die
, decl
);
19969 if (DECL_ARTIFICIAL (decl
))
19970 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19972 add_accessibility_attribute (decl_die
, decl
);
19974 /* Equate decl number to die, so that we can look up this decl later on. */
19975 equate_decl_number_to_die (decl
, decl_die
);
19979 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19980 Use modified_type_die instead.
19981 We keep this code here just in case these types of DIEs may be needed to
19982 represent certain things in other languages (e.g. Pascal) someday. */
19985 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19988 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19990 equate_type_number_to_die (type
, ptr_die
);
19991 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19993 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19996 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19997 Use modified_type_die instead.
19998 We keep this code here just in case these types of DIEs may be needed to
19999 represent certain things in other languages (e.g. Pascal) someday. */
20002 gen_reference_type_die (tree type
, dw_die_ref context_die
)
20004 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
20006 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
20007 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
20009 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
20011 equate_type_number_to_die (type
, ref_die
);
20012 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20014 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20018 /* Generate a DIE for a pointer to a member type. */
20021 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
20024 = new_die (DW_TAG_ptr_to_member_type
,
20025 scope_die_for (type
, context_die
), type
);
20027 equate_type_number_to_die (type
, ptr_die
);
20028 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
20029 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
20030 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20034 typedef const char *dchar_p
; /* For DEF_VEC_P. */
20036 static char *producer_string
;
20038 /* Return a heap allocated producer string including command line options
20039 if -grecord-gcc-switches. */
20042 gen_producer_string (void)
20045 auto_vec
<dchar_p
> switches
;
20046 const char *language_string
= lang_hooks
.name
;
20047 char *producer
, *tail
;
20049 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
20050 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
20052 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
20053 switch (save_decoded_options
[j
].opt_index
)
20060 case OPT_auxbase_strip
:
20069 case OPT_SPECIAL_unknown
:
20070 case OPT_SPECIAL_ignore
:
20071 case OPT_SPECIAL_program_name
:
20072 case OPT_SPECIAL_input_file
:
20073 case OPT_grecord_gcc_switches
:
20074 case OPT_gno_record_gcc_switches
:
20075 case OPT__output_pch_
:
20076 case OPT_fdiagnostics_show_location_
:
20077 case OPT_fdiagnostics_show_option
:
20078 case OPT_fdiagnostics_show_caret
:
20079 case OPT_fdiagnostics_color_
:
20080 case OPT_fverbose_asm
:
20082 case OPT__sysroot_
:
20084 case OPT_nostdinc__
:
20085 case OPT_fpreprocessed
:
20086 case OPT_fltrans_output_list_
:
20087 case OPT_fresolution_
:
20088 /* Ignore these. */
20091 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
20092 & CL_NO_DWARF_RECORD
)
20094 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
20096 switch (save_decoded_options
[j
].canonical_option
[0][1])
20103 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
20110 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
20111 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
20115 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
20117 sprintf (tail
, "%s %s", language_string
, version_string
);
20120 FOR_EACH_VEC_ELT (switches
, j
, p
)
20124 memcpy (tail
+ 1, p
, len
);
20132 /* Given a C and/or C++ language/version string return the "highest".
20133 C++ is assumed to be "higher" than C in this case. Used for merging
20134 LTO translation unit languages. */
20135 static const char *
20136 highest_c_language (const char *lang1
, const char *lang2
)
20138 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
20139 return "GNU C++14";
20140 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
20141 return "GNU C++11";
20142 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
20143 return "GNU C++98";
20145 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
20147 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
20149 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
20152 gcc_unreachable ();
20156 /* Generate the DIE for the compilation unit. */
20159 gen_compile_unit_die (const char *filename
)
20162 const char *language_string
= lang_hooks
.name
;
20165 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
20169 add_name_attribute (die
, filename
);
20170 /* Don't add cwd for <built-in>. */
20171 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
20172 add_comp_dir_attribute (die
);
20175 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
20177 /* If our producer is LTO try to figure out a common language to use
20178 from the global list of translation units. */
20179 if (strcmp (language_string
, "GNU GIMPLE") == 0)
20183 const char *common_lang
= NULL
;
20185 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
20187 if (!TRANSLATION_UNIT_LANGUAGE (t
))
20190 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
20191 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
20193 else if (strncmp (common_lang
, "GNU C", 5) == 0
20194 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
20195 /* Mixing C and C++ is ok, use C++ in that case. */
20196 common_lang
= highest_c_language (common_lang
,
20197 TRANSLATION_UNIT_LANGUAGE (t
));
20200 /* Fall back to C. */
20201 common_lang
= NULL
;
20207 language_string
= common_lang
;
20210 language
= DW_LANG_C
;
20211 if (strncmp (language_string
, "GNU C", 5) == 0
20212 && ISDIGIT (language_string
[5]))
20214 language
= DW_LANG_C89
;
20215 if (dwarf_version
>= 3 || !dwarf_strict
)
20217 if (strcmp (language_string
, "GNU C89") != 0)
20218 language
= DW_LANG_C99
;
20220 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20221 if (strcmp (language_string
, "GNU C11") == 0)
20222 language
= DW_LANG_C11
;
20225 else if (strncmp (language_string
, "GNU C++", 7) == 0)
20227 language
= DW_LANG_C_plus_plus
;
20228 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20230 if (strcmp (language_string
, "GNU C++11") == 0)
20231 language
= DW_LANG_C_plus_plus_11
;
20232 else if (strcmp (language_string
, "GNU C++14") == 0)
20233 language
= DW_LANG_C_plus_plus_14
;
20236 else if (strcmp (language_string
, "GNU F77") == 0)
20237 language
= DW_LANG_Fortran77
;
20238 else if (strcmp (language_string
, "GNU Pascal") == 0)
20239 language
= DW_LANG_Pascal83
;
20240 else if (dwarf_version
>= 3 || !dwarf_strict
)
20242 if (strcmp (language_string
, "GNU Ada") == 0)
20243 language
= DW_LANG_Ada95
;
20244 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20246 language
= DW_LANG_Fortran95
;
20247 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20249 if (strcmp (language_string
, "GNU Fortran2003") == 0)
20250 language
= DW_LANG_Fortran03
;
20251 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
20252 language
= DW_LANG_Fortran08
;
20255 else if (strcmp (language_string
, "GNU Java") == 0)
20256 language
= DW_LANG_Java
;
20257 else if (strcmp (language_string
, "GNU Objective-C") == 0)
20258 language
= DW_LANG_ObjC
;
20259 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
20260 language
= DW_LANG_ObjC_plus_plus
;
20261 else if (dwarf_version
>= 5 || !dwarf_strict
)
20263 if (strcmp (language_string
, "GNU Go") == 0)
20264 language
= DW_LANG_Go
;
20267 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
20268 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20269 language
= DW_LANG_Fortran90
;
20271 add_AT_unsigned (die
, DW_AT_language
, language
);
20275 case DW_LANG_Fortran77
:
20276 case DW_LANG_Fortran90
:
20277 case DW_LANG_Fortran95
:
20278 case DW_LANG_Fortran03
:
20279 case DW_LANG_Fortran08
:
20280 /* Fortran has case insensitive identifiers and the front-end
20281 lowercases everything. */
20282 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
20285 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20291 /* Generate the DIE for a base class. */
20294 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
20296 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
20298 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, context_die
);
20299 add_data_member_location_attribute (die
, binfo
);
20301 if (BINFO_VIRTUAL_P (binfo
))
20302 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20304 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20305 children, otherwise the default is DW_ACCESS_public. In DWARF2
20306 the default has always been DW_ACCESS_private. */
20307 if (access
== access_public_node
)
20309 if (dwarf_version
== 2
20310 || context_die
->die_tag
== DW_TAG_class_type
)
20311 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20313 else if (access
== access_protected_node
)
20314 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20315 else if (dwarf_version
> 2
20316 && context_die
->die_tag
!= DW_TAG_class_type
)
20317 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20320 /* Generate a DIE for a class member. */
20323 gen_member_die (tree type
, dw_die_ref context_die
)
20326 tree binfo
= TYPE_BINFO (type
);
20329 /* If this is not an incomplete type, output descriptions of each of its
20330 members. Note that as we output the DIEs necessary to represent the
20331 members of this record or union type, we will also be trying to output
20332 DIEs to represent the *types* of those members. However the `type'
20333 function (above) will specifically avoid generating type DIEs for member
20334 types *within* the list of member DIEs for this (containing) type except
20335 for those types (of members) which are explicitly marked as also being
20336 members of this (containing) type themselves. The g++ front- end can
20337 force any given type to be treated as a member of some other (containing)
20338 type by setting the TYPE_CONTEXT of the given (member) type to point to
20339 the TREE node representing the appropriate (containing) type. */
20341 /* First output info about the base classes. */
20344 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
20348 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
20349 gen_inheritance_die (base
,
20350 (accesses
? (*accesses
)[i
] : access_public_node
),
20354 /* Now output info about the data members and type members. */
20355 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
20357 /* If we thought we were generating minimal debug info for TYPE
20358 and then changed our minds, some of the member declarations
20359 may have already been defined. Don't define them again, but
20360 do put them in the right order. */
20362 child
= lookup_decl_die (member
);
20364 splice_child_die (context_die
, child
);
20366 gen_decl_die (member
, NULL
, context_die
);
20369 /* We do not keep type methods in type variants. */
20370 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
20371 /* Now output info about the function members (if any). */
20372 if (TYPE_METHODS (type
) != error_mark_node
)
20373 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
20375 /* Don't include clones in the member list. */
20376 if (DECL_ABSTRACT_ORIGIN (member
))
20378 /* Nor constructors for anonymous classes. */
20379 if (DECL_ARTIFICIAL (member
)
20380 && dwarf2_name (member
, 0) == NULL
)
20383 child
= lookup_decl_die (member
);
20385 splice_child_die (context_die
, child
);
20387 gen_decl_die (member
, NULL
, context_die
);
20391 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20392 is set, we pretend that the type was never defined, so we only get the
20393 member DIEs needed by later specification DIEs. */
20396 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
20397 enum debug_info_usage usage
)
20399 if (TREE_ASM_WRITTEN (type
))
20401 /* Fill in the bound of variable-length fields in late dwarf if
20402 still incomplete. */
20403 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
20404 for (tree member
= TYPE_FIELDS (type
);
20406 member
= DECL_CHAIN (member
))
20407 fill_variable_array_bounds (TREE_TYPE (member
));
20411 dw_die_ref type_die
= lookup_type_die (type
);
20412 dw_die_ref scope_die
= 0;
20414 int complete
= (TYPE_SIZE (type
)
20415 && (! TYPE_STUB_DECL (type
)
20416 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
20417 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
20418 complete
= complete
&& should_emit_struct_debug (type
, usage
);
20420 if (type_die
&& ! complete
)
20423 if (TYPE_CONTEXT (type
) != NULL_TREE
20424 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20425 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
20428 scope_die
= scope_die_for (type
, context_die
);
20430 /* Generate child dies for template paramaters. */
20431 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20432 schedule_generic_params_dies_gen (type
);
20434 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
20435 /* First occurrence of type or toplevel definition of nested class. */
20437 dw_die_ref old_die
= type_die
;
20439 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
20440 ? record_type_tag (type
) : DW_TAG_union_type
,
20442 equate_type_number_to_die (type
, type_die
);
20444 add_AT_specification (type_die
, old_die
);
20446 add_name_attribute (type_die
, type_tag (type
));
20449 remove_AT (type_die
, DW_AT_declaration
);
20451 /* If this type has been completed, then give it a byte_size attribute and
20452 then give a list of members. */
20453 if (complete
&& !ns_decl
)
20455 /* Prevent infinite recursion in cases where the type of some member of
20456 this type is expressed in terms of this type itself. */
20457 TREE_ASM_WRITTEN (type
) = 1;
20458 add_byte_size_attribute (type_die
, type
);
20459 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20461 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20462 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20465 /* If the first reference to this type was as the return type of an
20466 inline function, then it may not have a parent. Fix this now. */
20467 if (type_die
->die_parent
== NULL
)
20468 add_child_die (scope_die
, type_die
);
20470 push_decl_scope (type
);
20471 gen_member_die (type
, type_die
);
20474 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
20475 if (TYPE_ARTIFICIAL (type
))
20476 add_AT_flag (type_die
, DW_AT_artificial
, 1);
20478 /* GNU extension: Record what type our vtable lives in. */
20479 if (TYPE_VFIELD (type
))
20481 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
20483 gen_type_die (vtype
, context_die
);
20484 add_AT_die_ref (type_die
, DW_AT_containing_type
,
20485 lookup_type_die (vtype
));
20490 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20492 /* We don't need to do this for function-local types. */
20493 if (TYPE_STUB_DECL (type
)
20494 && ! decl_function_context (TYPE_STUB_DECL (type
)))
20495 vec_safe_push (incomplete_types
, type
);
20498 if (get_AT (type_die
, DW_AT_name
))
20499 add_pubtype (type
, type_die
);
20502 /* Generate a DIE for a subroutine _type_. */
20505 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
20507 tree return_type
= TREE_TYPE (type
);
20508 dw_die_ref subr_die
20509 = new_die (DW_TAG_subroutine_type
,
20510 scope_die_for (type
, context_die
), type
);
20512 equate_type_number_to_die (type
, subr_die
);
20513 add_prototyped_attribute (subr_die
, type
);
20514 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, context_die
);
20515 gen_formal_types_die (type
, subr_die
);
20517 if (get_AT (subr_die
, DW_AT_name
))
20518 add_pubtype (type
, subr_die
);
20521 /* Generate a DIE for a type definition. */
20524 gen_typedef_die (tree decl
, dw_die_ref context_die
)
20526 dw_die_ref type_die
;
20529 if (TREE_ASM_WRITTEN (decl
))
20531 if (DECL_ORIGINAL_TYPE (decl
))
20532 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
20536 TREE_ASM_WRITTEN (decl
) = 1;
20537 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
20538 origin
= decl_ultimate_origin (decl
);
20539 if (origin
!= NULL
)
20540 add_abstract_origin_attribute (type_die
, origin
);
20545 add_name_and_src_coords_attributes (type_die
, decl
);
20546 if (DECL_ORIGINAL_TYPE (decl
))
20548 type
= DECL_ORIGINAL_TYPE (decl
);
20550 if (type
== error_mark_node
)
20553 gcc_assert (type
!= TREE_TYPE (decl
));
20554 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
20558 type
= TREE_TYPE (decl
);
20560 if (type
== error_mark_node
)
20563 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20565 /* Here, we are in the case of decl being a typedef naming
20566 an anonymous type, e.g:
20567 typedef struct {...} foo;
20568 In that case TREE_TYPE (decl) is not a typedef variant
20569 type and TYPE_NAME of the anonymous type is set to the
20570 TYPE_DECL of the typedef. This construct is emitted by
20573 TYPE is the anonymous struct named by the typedef
20574 DECL. As we need the DW_AT_type attribute of the
20575 DW_TAG_typedef to point to the DIE of TYPE, let's
20576 generate that DIE right away. add_type_attribute
20577 called below will then pick (via lookup_type_die) that
20578 anonymous struct DIE. */
20579 if (!TREE_ASM_WRITTEN (type
))
20580 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20582 /* This is a GNU Extension. We are adding a
20583 DW_AT_linkage_name attribute to the DIE of the
20584 anonymous struct TYPE. The value of that attribute
20585 is the name of the typedef decl naming the anonymous
20586 struct. This greatly eases the work of consumers of
20587 this debug info. */
20588 add_linkage_attr (lookup_type_die (type
), decl
);
20592 add_type_attribute (type_die
, type
, decl_quals (decl
), context_die
);
20594 if (is_naming_typedef_decl (decl
))
20595 /* We want that all subsequent calls to lookup_type_die with
20596 TYPE in argument yield the DW_TAG_typedef we have just
20598 equate_type_number_to_die (type
, type_die
);
20600 add_accessibility_attribute (type_die
, decl
);
20603 if (DECL_ABSTRACT_P (decl
))
20604 equate_decl_number_to_die (decl
, type_die
);
20606 if (get_AT (type_die
, DW_AT_name
))
20607 add_pubtype (decl
, type_die
);
20610 /* Generate a DIE for a struct, class, enum or union type. */
20613 gen_tagged_type_die (tree type
,
20614 dw_die_ref context_die
,
20615 enum debug_info_usage usage
)
20619 if (type
== NULL_TREE
20620 || !is_tagged_type (type
))
20623 if (TREE_ASM_WRITTEN (type
))
20625 /* If this is a nested type whose containing class hasn't been written
20626 out yet, writing it out will cover this one, too. This does not apply
20627 to instantiations of member class templates; they need to be added to
20628 the containing class as they are generated. FIXME: This hurts the
20629 idea of combining type decls from multiple TUs, since we can't predict
20630 what set of template instantiations we'll get. */
20631 else if (TYPE_CONTEXT (type
)
20632 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20633 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20635 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20637 if (TREE_ASM_WRITTEN (type
))
20640 /* If that failed, attach ourselves to the stub. */
20641 push_decl_scope (TYPE_CONTEXT (type
));
20642 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20645 else if (TYPE_CONTEXT (type
) != NULL_TREE
20646 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20648 /* If this type is local to a function that hasn't been written
20649 out yet, use a NULL context for now; it will be fixed up in
20650 decls_for_scope. */
20651 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20652 /* A declaration DIE doesn't count; nested types need to go in the
20654 if (context_die
&& is_declaration_die (context_die
))
20655 context_die
= NULL
;
20660 context_die
= declare_in_namespace (type
, context_die
);
20664 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20666 /* This might have been written out by the call to
20667 declare_in_namespace. */
20668 if (!TREE_ASM_WRITTEN (type
))
20669 gen_enumeration_type_die (type
, context_die
);
20672 gen_struct_or_union_type_die (type
, context_die
, usage
);
20677 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20678 it up if it is ever completed. gen_*_type_die will set it for us
20679 when appropriate. */
20682 /* Generate a type description DIE. */
20685 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20686 enum debug_info_usage usage
)
20688 struct array_descr_info info
;
20690 if (type
== NULL_TREE
|| type
== error_mark_node
)
20693 #ifdef ENABLE_CHECKING
20695 verify_type (type
);
20698 if (TYPE_NAME (type
) != NULL_TREE
20699 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20700 && is_redundant_typedef (TYPE_NAME (type
))
20701 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
20702 /* The DECL of this type is a typedef we don't want to emit debug
20703 info for but we want debug info for its underlying typedef.
20704 This can happen for e.g, the injected-class-name of a C++
20706 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
20708 /* If TYPE is a typedef type variant, let's generate debug info
20709 for the parent typedef which TYPE is a type of. */
20710 if (typedef_variant_p (type
))
20712 if (TREE_ASM_WRITTEN (type
))
20715 /* Prevent broken recursion; we can't hand off to the same type. */
20716 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20718 /* Give typedefs the right scope. */
20719 context_die
= scope_die_for (type
, context_die
);
20721 TREE_ASM_WRITTEN (type
) = 1;
20723 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20727 /* If type is an anonymous tagged type named by a typedef, let's
20728 generate debug info for the typedef. */
20729 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20731 /* Use the DIE of the containing namespace as the parent DIE of
20732 the type description DIE we want to generate. */
20733 if (DECL_CONTEXT (TYPE_NAME (type
))
20734 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20735 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20737 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20741 /* We are going to output a DIE to represent the unqualified version
20742 of this type (i.e. without any const or volatile qualifiers) so
20743 get the main variant (i.e. the unqualified version) of this type
20744 now. (Vectors are special because the debugging info is in the
20745 cloned type itself). */
20746 if (TREE_CODE (type
) != VECTOR_TYPE
)
20747 type
= type_main_variant (type
);
20749 /* If this is an array type with hidden descriptor, handle it first. */
20750 if (!TREE_ASM_WRITTEN (type
)
20751 && lang_hooks
.types
.get_array_descr_info
)
20753 memset (&info
, 0, sizeof (info
));
20754 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
20756 gen_descr_array_type_die (type
, &info
, context_die
);
20757 TREE_ASM_WRITTEN (type
) = 1;
20762 if (TREE_ASM_WRITTEN (type
))
20764 /* Variable-length types may be incomplete even if
20765 TREE_ASM_WRITTEN. For such types, fall through to
20766 gen_array_type_die() and possibly fill in
20767 DW_AT_{upper,lower}_bound attributes. */
20768 if ((TREE_CODE (type
) != ARRAY_TYPE
20769 && TREE_CODE (type
) != RECORD_TYPE
20770 && TREE_CODE (type
) != UNION_TYPE
20771 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
20772 || !variably_modified_type_p (type
, NULL
))
20776 switch (TREE_CODE (type
))
20782 case REFERENCE_TYPE
:
20783 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20784 ensures that the gen_type_die recursion will terminate even if the
20785 type is recursive. Recursive types are possible in Ada. */
20786 /* ??? We could perhaps do this for all types before the switch
20788 TREE_ASM_WRITTEN (type
) = 1;
20790 /* For these types, all that is required is that we output a DIE (or a
20791 set of DIEs) to represent the "basis" type. */
20792 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20793 DINFO_USAGE_IND_USE
);
20797 /* This code is used for C++ pointer-to-data-member types.
20798 Output a description of the relevant class type. */
20799 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20800 DINFO_USAGE_IND_USE
);
20802 /* Output a description of the type of the object pointed to. */
20803 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20804 DINFO_USAGE_IND_USE
);
20806 /* Now output a DIE to represent this pointer-to-data-member type
20808 gen_ptr_to_mbr_type_die (type
, context_die
);
20811 case FUNCTION_TYPE
:
20812 /* Force out return type (in case it wasn't forced out already). */
20813 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20814 DINFO_USAGE_DIR_USE
);
20815 gen_subroutine_type_die (type
, context_die
);
20819 /* Force out return type (in case it wasn't forced out already). */
20820 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20821 DINFO_USAGE_DIR_USE
);
20822 gen_subroutine_type_die (type
, context_die
);
20827 gen_array_type_die (type
, context_die
);
20830 case ENUMERAL_TYPE
:
20833 case QUAL_UNION_TYPE
:
20834 gen_tagged_type_die (type
, context_die
, usage
);
20840 case FIXED_POINT_TYPE
:
20843 case POINTER_BOUNDS_TYPE
:
20844 /* No DIEs needed for fundamental types. */
20849 /* Just use DW_TAG_unspecified_type. */
20851 dw_die_ref type_die
= lookup_type_die (type
);
20852 if (type_die
== NULL
)
20854 tree name
= TYPE_IDENTIFIER (type
);
20855 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
20857 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20858 equate_type_number_to_die (type
, type_die
);
20864 if (is_cxx_auto (type
))
20866 tree name
= TYPE_IDENTIFIER (type
);
20867 dw_die_ref
*die
= (name
== get_identifier ("auto")
20868 ? &auto_die
: &decltype_auto_die
);
20871 *die
= new_die (DW_TAG_unspecified_type
,
20872 comp_unit_die (), NULL_TREE
);
20873 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20875 equate_type_number_to_die (type
, *die
);
20878 gcc_unreachable ();
20881 TREE_ASM_WRITTEN (type
) = 1;
20885 gen_type_die (tree type
, dw_die_ref context_die
)
20887 if (type
!= error_mark_node
)
20889 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20890 #ifdef ENABLE_CHECKING
20891 dw_die_ref die
= lookup_type_die (type
);
20898 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20899 things which are local to the given block. */
20902 gen_block_die (tree stmt
, dw_die_ref context_die
)
20904 int must_output_die
= 0;
20907 /* Ignore blocks that are NULL. */
20908 if (stmt
== NULL_TREE
)
20911 inlined_func
= inlined_function_outer_scope_p (stmt
);
20913 /* If the block is one fragment of a non-contiguous block, do not
20914 process the variables, since they will have been done by the
20915 origin block. Do process subblocks. */
20916 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20920 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20921 gen_block_die (sub
, context_die
);
20926 /* Determine if we need to output any Dwarf DIEs at all to represent this
20929 /* The outer scopes for inlinings *must* always be represented. We
20930 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20931 must_output_die
= 1;
20934 /* Determine if this block directly contains any "significant"
20935 local declarations which we will need to output DIEs for. */
20936 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20937 /* We are not in terse mode so *any* local declaration counts
20938 as being a "significant" one. */
20939 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20940 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20941 && (TREE_USED (stmt
)
20942 || TREE_ASM_WRITTEN (stmt
)
20943 || BLOCK_ABSTRACT (stmt
)));
20944 else if ((TREE_USED (stmt
)
20945 || TREE_ASM_WRITTEN (stmt
)
20946 || BLOCK_ABSTRACT (stmt
))
20947 && !dwarf2out_ignore_block (stmt
))
20948 must_output_die
= 1;
20951 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20952 DIE for any block which contains no significant local declarations at
20953 all. Rather, in such cases we just call `decls_for_scope' so that any
20954 needed Dwarf info for any sub-blocks will get properly generated. Note
20955 that in terse mode, our definition of what constitutes a "significant"
20956 local declaration gets restricted to include only inlined function
20957 instances and local (nested) function definitions. */
20958 if (must_output_die
)
20962 /* If STMT block is abstract, that means we have been called
20963 indirectly from dwarf2out_abstract_function.
20964 That function rightfully marks the descendent blocks (of
20965 the abstract function it is dealing with) as being abstract,
20966 precisely to prevent us from emitting any
20967 DW_TAG_inlined_subroutine DIE as a descendent
20968 of an abstract function instance. So in that case, we should
20969 not call gen_inlined_subroutine_die.
20971 Later though, when cgraph asks dwarf2out to emit info
20972 for the concrete instance of the function decl into which
20973 the concrete instance of STMT got inlined, the later will lead
20974 to the generation of a DW_TAG_inlined_subroutine DIE. */
20975 if (! BLOCK_ABSTRACT (stmt
))
20976 gen_inlined_subroutine_die (stmt
, context_die
);
20979 gen_lexical_block_die (stmt
, context_die
);
20982 decls_for_scope (stmt
, context_die
);
20985 /* Process variable DECL (or variable with origin ORIGIN) within
20986 block STMT and add it to CONTEXT_DIE. */
20988 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20991 tree decl_or_origin
= decl
? decl
: origin
;
20993 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20994 die
= lookup_decl_die (decl_or_origin
);
20995 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20996 && TYPE_DECL_IS_STUB (decl_or_origin
))
20997 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
21001 if (die
!= NULL
&& die
->die_parent
== NULL
)
21002 add_child_die (context_die
, die
);
21003 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
21006 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
21007 stmt
, context_die
);
21010 gen_decl_die (decl
, origin
, context_die
);
21013 /* Generate all of the decls declared within a given scope and (recursively)
21014 all of its sub-blocks. */
21017 decls_for_scope (tree stmt
, dw_die_ref context_die
)
21023 /* Ignore NULL blocks. */
21024 if (stmt
== NULL_TREE
)
21027 /* Output the DIEs to represent all of the data objects and typedefs
21028 declared directly within this block but not within any nested
21029 sub-blocks. Also, nested function and tag DIEs have been
21030 generated with a parent of NULL; fix that up now. We don't
21031 have to do this if we're at -g1. */
21032 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21034 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
21035 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
21036 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21037 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
21041 /* Even if we're at -g1, we need to process the subblocks in order to get
21042 inlined call information. */
21044 /* Output the DIEs to represent all sub-blocks (and the items declared
21045 therein) of this block. */
21046 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
21048 subblocks
= BLOCK_CHAIN (subblocks
))
21049 gen_block_die (subblocks
, context_die
);
21052 /* Is this a typedef we can avoid emitting? */
21055 is_redundant_typedef (const_tree decl
)
21057 if (TYPE_DECL_IS_STUB (decl
))
21060 if (DECL_ARTIFICIAL (decl
)
21061 && DECL_CONTEXT (decl
)
21062 && is_tagged_type (DECL_CONTEXT (decl
))
21063 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
21064 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
21065 /* Also ignore the artificial member typedef for the class name. */
21071 /* Return TRUE if TYPE is a typedef that names a type for linkage
21072 purposes. This kind of typedefs is produced by the C++ FE for
21075 typedef struct {...} foo;
21077 In that case, there is no typedef variant type produced for foo.
21078 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21082 is_naming_typedef_decl (const_tree decl
)
21084 if (decl
== NULL_TREE
21085 || TREE_CODE (decl
) != TYPE_DECL
21086 || !is_tagged_type (TREE_TYPE (decl
))
21087 || DECL_IS_BUILTIN (decl
)
21088 || is_redundant_typedef (decl
)
21089 /* It looks like Ada produces TYPE_DECLs that are very similar
21090 to C++ naming typedefs but that have different
21091 semantics. Let's be specific to c++ for now. */
21095 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
21096 && TYPE_NAME (TREE_TYPE (decl
)) == decl
21097 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
21098 != TYPE_NAME (TREE_TYPE (decl
))));
21101 /* Looks up the DIE for a context. */
21103 static inline dw_die_ref
21104 lookup_context_die (tree context
)
21108 /* Find die that represents this context. */
21109 if (TYPE_P (context
))
21111 context
= TYPE_MAIN_VARIANT (context
);
21112 dw_die_ref ctx
= lookup_type_die (context
);
21115 return strip_naming_typedef (context
, ctx
);
21118 return lookup_decl_die (context
);
21120 return comp_unit_die ();
21123 /* Returns the DIE for a context. */
21125 static inline dw_die_ref
21126 get_context_die (tree context
)
21130 /* Find die that represents this context. */
21131 if (TYPE_P (context
))
21133 context
= TYPE_MAIN_VARIANT (context
);
21134 return strip_naming_typedef (context
, force_type_die (context
));
21137 return force_decl_die (context
);
21139 return comp_unit_die ();
21142 /* Returns the DIE for decl. A DIE will always be returned. */
21145 force_decl_die (tree decl
)
21147 dw_die_ref decl_die
;
21148 unsigned saved_external_flag
;
21149 tree save_fn
= NULL_TREE
;
21150 decl_die
= lookup_decl_die (decl
);
21153 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
21155 decl_die
= lookup_decl_die (decl
);
21159 switch (TREE_CODE (decl
))
21161 case FUNCTION_DECL
:
21162 /* Clear current_function_decl, so that gen_subprogram_die thinks
21163 that this is a declaration. At this point, we just want to force
21164 declaration die. */
21165 save_fn
= current_function_decl
;
21166 current_function_decl
= NULL_TREE
;
21167 gen_subprogram_die (decl
, context_die
);
21168 current_function_decl
= save_fn
;
21172 /* Set external flag to force declaration die. Restore it after
21173 gen_decl_die() call. */
21174 saved_external_flag
= DECL_EXTERNAL (decl
);
21175 DECL_EXTERNAL (decl
) = 1;
21176 gen_decl_die (decl
, NULL
, context_die
);
21177 DECL_EXTERNAL (decl
) = saved_external_flag
;
21180 case NAMESPACE_DECL
:
21181 if (dwarf_version
>= 3 || !dwarf_strict
)
21182 dwarf2out_decl (decl
);
21184 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21185 decl_die
= comp_unit_die ();
21188 case TRANSLATION_UNIT_DECL
:
21189 decl_die
= comp_unit_die ();
21193 gcc_unreachable ();
21196 /* We should be able to find the DIE now. */
21198 decl_die
= lookup_decl_die (decl
);
21199 gcc_assert (decl_die
);
21205 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21206 always returned. */
21209 force_type_die (tree type
)
21211 dw_die_ref type_die
;
21213 type_die
= lookup_type_die (type
);
21216 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
21218 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
21220 gcc_assert (type_die
);
21225 /* Force out any required namespaces to be able to output DECL,
21226 and return the new context_die for it, if it's changed. */
21229 setup_namespace_context (tree thing
, dw_die_ref context_die
)
21231 tree context
= (DECL_P (thing
)
21232 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
21233 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
21234 /* Force out the namespace. */
21235 context_die
= force_decl_die (context
);
21237 return context_die
;
21240 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21241 type) within its namespace, if appropriate.
21243 For compatibility with older debuggers, namespace DIEs only contain
21244 declarations; all definitions are emitted at CU scope, with
21245 DW_AT_specification pointing to the declaration (like with class
21249 declare_in_namespace (tree thing
, dw_die_ref context_die
)
21251 dw_die_ref ns_context
;
21253 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21254 return context_die
;
21256 /* External declarations in the local scope only need to be emitted
21257 once, not once in the namespace and once in the scope.
21259 This avoids declaring the `extern' below in the
21260 namespace DIE as well as in the innermost scope:
21273 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
21274 return context_die
;
21276 /* If this decl is from an inlined function, then don't try to emit it in its
21277 namespace, as we will get confused. It would have already been emitted
21278 when the abstract instance of the inline function was emitted anyways. */
21279 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
21280 return context_die
;
21282 ns_context
= setup_namespace_context (thing
, context_die
);
21284 if (ns_context
!= context_die
)
21288 if (DECL_P (thing
))
21289 gen_decl_die (thing
, NULL
, ns_context
);
21291 gen_type_die (thing
, ns_context
);
21293 return context_die
;
21296 /* Generate a DIE for a namespace or namespace alias. */
21299 gen_namespace_die (tree decl
, dw_die_ref context_die
)
21301 dw_die_ref namespace_die
;
21303 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21304 they are an alias of. */
21305 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
21307 /* Output a real namespace or module. */
21308 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21309 namespace_die
= new_die (is_fortran ()
21310 ? DW_TAG_module
: DW_TAG_namespace
,
21311 context_die
, decl
);
21312 /* For Fortran modules defined in different CU don't add src coords. */
21313 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
21315 const char *name
= dwarf2_name (decl
, 0);
21317 add_name_attribute (namespace_die
, name
);
21320 add_name_and_src_coords_attributes (namespace_die
, decl
);
21321 if (DECL_EXTERNAL (decl
))
21322 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
21323 equate_decl_number_to_die (decl
, namespace_die
);
21327 /* Output a namespace alias. */
21329 /* Force out the namespace we are an alias of, if necessary. */
21330 dw_die_ref origin_die
21331 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
21333 if (DECL_FILE_SCOPE_P (decl
)
21334 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
21335 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21336 /* Now create the namespace alias DIE. */
21337 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
21338 add_name_and_src_coords_attributes (namespace_die
, decl
);
21339 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
21340 equate_decl_number_to_die (decl
, namespace_die
);
21342 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
21343 if (want_pubnames ())
21344 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
21347 /* Generate Dwarf debug information for a decl described by DECL.
21348 The return value is currently only meaningful for PARM_DECLs,
21349 for all other decls it returns NULL. */
21352 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
21354 tree decl_or_origin
= decl
? decl
: origin
;
21355 tree class_origin
= NULL
, ultimate_origin
;
21357 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
21360 /* Ignore pointer bounds decls. */
21361 if (DECL_P (decl_or_origin
)
21362 && TREE_TYPE (decl_or_origin
)
21363 && POINTER_BOUNDS_P (decl_or_origin
))
21366 switch (TREE_CODE (decl_or_origin
))
21372 if (!is_fortran () && !is_ada ())
21374 /* The individual enumerators of an enum type get output when we output
21375 the Dwarf representation of the relevant enum type itself. */
21379 /* Emit its type. */
21380 gen_type_die (TREE_TYPE (decl
), context_die
);
21382 /* And its containing namespace. */
21383 context_die
= declare_in_namespace (decl
, context_die
);
21385 gen_const_die (decl
, context_die
);
21388 case FUNCTION_DECL
:
21389 /* Don't output any DIEs to represent mere function declarations,
21390 unless they are class members or explicit block externs. */
21391 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
21392 && DECL_FILE_SCOPE_P (decl_or_origin
)
21393 && (current_function_decl
== NULL_TREE
21394 || DECL_ARTIFICIAL (decl_or_origin
)))
21399 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21400 on local redeclarations of global functions. That seems broken. */
21401 if (current_function_decl
!= decl
)
21402 /* This is only a declaration. */;
21405 /* If we're emitting a clone, emit info for the abstract instance. */
21406 if (origin
|| DECL_ORIGIN (decl
) != decl
)
21407 dwarf2out_abstract_function (origin
21408 ? DECL_ORIGIN (origin
)
21409 : DECL_ABSTRACT_ORIGIN (decl
));
21411 /* If we're emitting an out-of-line copy of an inline function,
21412 emit info for the abstract instance and set up to refer to it. */
21413 else if (cgraph_function_possibly_inlined_p (decl
)
21414 && ! DECL_ABSTRACT_P (decl
)
21415 && ! class_or_namespace_scope_p (context_die
)
21416 /* dwarf2out_abstract_function won't emit a die if this is just
21417 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21418 that case, because that works only if we have a die. */
21419 && DECL_INITIAL (decl
) != NULL_TREE
)
21421 dwarf2out_abstract_function (decl
);
21422 set_decl_origin_self (decl
);
21425 /* Otherwise we're emitting the primary DIE for this decl. */
21426 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21428 /* Before we describe the FUNCTION_DECL itself, make sure that we
21429 have its containing type. */
21431 origin
= decl_class_context (decl
);
21432 if (origin
!= NULL_TREE
)
21433 gen_type_die (origin
, context_die
);
21435 /* And its return type. */
21436 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
21438 /* And its virtual context. */
21439 if (DECL_VINDEX (decl
) != NULL_TREE
)
21440 gen_type_die (DECL_CONTEXT (decl
), context_die
);
21442 /* Make sure we have a member DIE for decl. */
21443 if (origin
!= NULL_TREE
)
21444 gen_type_die_for_member (origin
, decl
, context_die
);
21446 /* And its containing namespace. */
21447 context_die
= declare_in_namespace (decl
, context_die
);
21450 /* Now output a DIE to represent the function itself. */
21452 gen_subprogram_die (decl
, context_die
);
21456 /* If we are in terse mode, don't generate any DIEs to represent any
21457 actual typedefs. */
21458 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21461 /* In the special case of a TYPE_DECL node representing the declaration
21462 of some type tag, if the given TYPE_DECL is marked as having been
21463 instantiated from some other (original) TYPE_DECL node (e.g. one which
21464 was generated within the original definition of an inline function) we
21465 used to generate a special (abbreviated) DW_TAG_structure_type,
21466 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21467 should be actually referencing those DIEs, as variable DIEs with that
21468 type would be emitted already in the abstract origin, so it was always
21469 removed during unused type prunning. Don't add anything in this
21471 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
21474 if (is_redundant_typedef (decl
))
21475 gen_type_die (TREE_TYPE (decl
), context_die
);
21477 /* Output a DIE to represent the typedef itself. */
21478 gen_typedef_die (decl
, context_die
);
21482 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
21483 gen_label_die (decl
, context_die
);
21488 /* If we are in terse mode, don't generate any DIEs to represent any
21489 variable declarations or definitions. */
21490 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21493 /* Output any DIEs that are needed to specify the type of this data
21495 if (decl_by_reference_p (decl_or_origin
))
21496 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21498 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21500 /* And its containing type. */
21501 class_origin
= decl_class_context (decl_or_origin
);
21502 if (class_origin
!= NULL_TREE
)
21503 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
21505 /* And its containing namespace. */
21506 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
21508 /* Now output the DIE to represent the data object itself. This gets
21509 complicated because of the possibility that the VAR_DECL really
21510 represents an inlined instance of a formal parameter for an inline
21512 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21513 if (ultimate_origin
!= NULL_TREE
21514 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
21515 gen_formal_parameter_die (decl
, origin
,
21516 true /* Emit name attribute. */,
21519 gen_variable_die (decl
, origin
, context_die
);
21523 /* Ignore the nameless fields that are used to skip bits but handle C++
21524 anonymous unions and structs. */
21525 if (DECL_NAME (decl
) != NULL_TREE
21526 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
21527 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
21529 gen_type_die (member_declared_type (decl
), context_die
);
21530 gen_field_die (decl
, context_die
);
21535 if (DECL_BY_REFERENCE (decl_or_origin
))
21536 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21538 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21539 return gen_formal_parameter_die (decl
, origin
,
21540 true /* Emit name attribute. */,
21543 case NAMESPACE_DECL
:
21544 case IMPORTED_DECL
:
21545 if (dwarf_version
>= 3 || !dwarf_strict
)
21546 gen_namespace_die (decl
, context_die
);
21549 case NAMELIST_DECL
:
21550 gen_namelist_decl (DECL_NAME (decl
), context_die
,
21551 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
21555 /* Probably some frontend-internal decl. Assume we don't care. */
21556 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
21563 /* Output initial debug information for global DECL. Called at the
21564 end of the parsing process.
21566 This is the initial debug generation process. As such, the DIEs
21567 generated may be incomplete. A later debug generation pass
21568 (dwarf2out_late_global_decl) will augment the information generated
21569 in this pass (e.g., with complete location info). */
21572 dwarf2out_early_global_decl (tree decl
)
21576 /* gen_decl_die() will set DECL_ABSTRACT because
21577 cgraph_function_possibly_inlined_p() returns true. This is in
21578 turn will cause DW_AT_inline attributes to be set.
21580 This happens because at early dwarf generation, there is no
21581 cgraph information, causing cgraph_function_possibly_inlined_p()
21582 to return true. Trick cgraph_function_possibly_inlined_p()
21583 while we generate dwarf early. */
21584 bool save
= symtab
->global_info_ready
;
21585 symtab
->global_info_ready
= true;
21587 /* We don't handle TYPE_DECLs. If required, they'll be reached via
21588 other DECLs and they can point to template types or other things
21589 that dwarf2out can't handle when done via dwarf2out_decl. */
21590 if (TREE_CODE (decl
) != TYPE_DECL
21591 && TREE_CODE (decl
) != PARM_DECL
)
21593 tree save_fndecl
= current_function_decl
;
21594 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21596 /* No cfun means the symbol has no body, so there's nothing
21598 if (!DECL_STRUCT_FUNCTION (decl
))
21599 goto early_decl_exit
;
21601 current_function_decl
= decl
;
21603 dwarf2out_decl (decl
);
21604 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21605 current_function_decl
= save_fndecl
;
21608 symtab
->global_info_ready
= save
;
21611 /* Output debug information for global decl DECL. Called from
21612 toplev.c after compilation proper has finished. */
21615 dwarf2out_late_global_decl (tree decl
)
21617 /* Output any global decls we missed or fill-in any location
21618 information we were unable to determine on the first pass.
21620 Skip over functions because they were handled by the
21621 debug_hooks->function_decl() call in rest_of_handle_final. */
21622 if ((TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
21623 && !POINTER_BOUNDS_P (decl
))
21624 dwarf2out_decl (decl
);
21627 /* Output debug information for type decl DECL. Called from toplev.c
21628 and from language front ends (to record built-in types). */
21630 dwarf2out_type_decl (tree decl
, int local
)
21635 dwarf2out_decl (decl
);
21639 /* Output debug information for imported module or decl DECL.
21640 NAME is non-NULL name in the lexical block if the decl has been renamed.
21641 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21642 that DECL belongs to.
21643 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21645 dwarf2out_imported_module_or_decl_1 (tree decl
,
21647 tree lexical_block
,
21648 dw_die_ref lexical_block_die
)
21650 expanded_location xloc
;
21651 dw_die_ref imported_die
= NULL
;
21652 dw_die_ref at_import_die
;
21654 if (TREE_CODE (decl
) == IMPORTED_DECL
)
21656 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
21657 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
21661 xloc
= expand_location (input_location
);
21663 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
21665 at_import_die
= force_type_die (TREE_TYPE (decl
));
21666 /* For namespace N { typedef void T; } using N::T; base_type_die
21667 returns NULL, but DW_TAG_imported_declaration requires
21668 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21669 if (!at_import_die
)
21671 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
21672 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
21673 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
21674 gcc_assert (at_import_die
);
21679 at_import_die
= lookup_decl_die (decl
);
21680 if (!at_import_die
)
21682 /* If we're trying to avoid duplicate debug info, we may not have
21683 emitted the member decl for this field. Emit it now. */
21684 if (TREE_CODE (decl
) == FIELD_DECL
)
21686 tree type
= DECL_CONTEXT (decl
);
21688 if (TYPE_CONTEXT (type
)
21689 && TYPE_P (TYPE_CONTEXT (type
))
21690 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
21691 DINFO_USAGE_DIR_USE
))
21693 gen_type_die_for_member (type
, decl
,
21694 get_context_die (TYPE_CONTEXT (type
)));
21696 if (TREE_CODE (decl
) == NAMELIST_DECL
)
21697 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
21698 get_context_die (DECL_CONTEXT (decl
)),
21701 at_import_die
= force_decl_die (decl
);
21705 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
21707 if (dwarf_version
>= 3 || !dwarf_strict
)
21708 imported_die
= new_die (DW_TAG_imported_module
,
21715 imported_die
= new_die (DW_TAG_imported_declaration
,
21719 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
21720 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
21722 add_AT_string (imported_die
, DW_AT_name
,
21723 IDENTIFIER_POINTER (name
));
21724 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
21727 /* Output debug information for imported module or decl DECL.
21728 NAME is non-NULL name in context if the decl has been renamed.
21729 CHILD is true if decl is one of the renamed decls as part of
21730 importing whole module. */
21733 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
21736 /* dw_die_ref at_import_die; */
21737 dw_die_ref scope_die
;
21739 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21746 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21747 We need decl DIE for reference and scope die. First, get DIE for the decl
21750 /* Get the scope die for decl context. Use comp_unit_die for global module
21751 or decl. If die is not found for non globals, force new die. */
21753 && TYPE_P (context
)
21754 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
21757 if (!(dwarf_version
>= 3 || !dwarf_strict
))
21760 scope_die
= get_context_die (context
);
21764 gcc_assert (scope_die
->die_child
);
21765 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21766 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21767 scope_die
= scope_die
->die_child
;
21770 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21771 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21774 /* Output debug information for namelists. */
21777 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
21779 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
21783 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21786 gcc_assert (scope_die
!= NULL
);
21787 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
21788 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
21790 /* If there are no item_decls, we have a nondefining namelist, e.g.
21791 with USE association; hence, set DW_AT_declaration. */
21792 if (item_decls
== NULL_TREE
)
21794 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
21798 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
21800 nml_item_ref_die
= lookup_decl_die (value
);
21801 if (!nml_item_ref_die
)
21802 nml_item_ref_die
= force_decl_die (value
);
21804 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
21805 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
21811 /* Write the debugging output for DECL and return the DIE. */
21814 dwarf2out_decl (tree decl
)
21816 dw_die_ref context_die
= comp_unit_die ();
21818 switch (TREE_CODE (decl
))
21823 case FUNCTION_DECL
:
21824 /* What we would really like to do here is to filter out all mere
21825 file-scope declarations of file-scope functions which are never
21826 referenced later within this translation unit (and keep all of ones
21827 that *are* referenced later on) but we aren't clairvoyant, so we have
21828 no idea which functions will be referenced in the future (i.e. later
21829 on within the current translation unit). So here we just ignore all
21830 file-scope function declarations which are not also definitions. If
21831 and when the debugger needs to know something about these functions,
21832 it will have to hunt around and find the DWARF information associated
21833 with the definition of the function.
21835 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21836 nodes represent definitions and which ones represent mere
21837 declarations. We have to check DECL_INITIAL instead. That's because
21838 the C front-end supports some weird semantics for "extern inline"
21839 function definitions. These can get inlined within the current
21840 translation unit (and thus, we need to generate Dwarf info for their
21841 abstract instances so that the Dwarf info for the concrete inlined
21842 instances can have something to refer to) but the compiler never
21843 generates any out-of-lines instances of such things (despite the fact
21844 that they *are* definitions).
21846 The important point is that the C front-end marks these "extern
21847 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21848 them anyway. Note that the C++ front-end also plays some similar games
21849 for inline function definitions appearing within include files which
21850 also contain `#pragma interface' pragmas.
21852 If we are called from dwarf2out_abstract_function output a DIE
21853 anyway. We can end up here this way with early inlining and LTO
21854 where the inlined function is output in a different LTRANS unit
21856 if (DECL_INITIAL (decl
) == NULL_TREE
21857 && ! DECL_ABSTRACT_P (decl
))
21860 /* If we're a nested function, initially use a parent of NULL; if we're
21861 a plain function, this will be fixed up in decls_for_scope. If
21862 we're a method, it will be ignored, since we already have a DIE. */
21863 if (decl_function_context (decl
)
21864 /* But if we're in terse mode, we don't care about scope. */
21865 && debug_info_level
> DINFO_LEVEL_TERSE
)
21866 context_die
= NULL
;
21870 /* For local statics lookup proper context die. */
21871 if (local_function_static (decl
))
21872 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21874 /* If we are in terse mode, don't generate any DIEs to represent any
21875 variable declarations or definitions. */
21876 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21881 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21883 if (!is_fortran () && !is_ada ())
21885 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21886 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21889 case NAMESPACE_DECL
:
21890 case IMPORTED_DECL
:
21891 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21893 if (lookup_decl_die (decl
) != NULL
)
21898 /* Don't emit stubs for types unless they are needed by other DIEs. */
21899 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21902 /* Don't bother trying to generate any DIEs to represent any of the
21903 normal built-in types for the language we are compiling. */
21904 if (DECL_IS_BUILTIN (decl
))
21907 /* If we are in terse mode, don't generate any DIEs for types. */
21908 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21911 /* If we're a function-scope tag, initially use a parent of NULL;
21912 this will be fixed up in decls_for_scope. */
21913 if (decl_function_context (decl
))
21914 context_die
= NULL
;
21918 case NAMELIST_DECL
:
21925 gen_decl_die (decl
, NULL
, context_die
);
21927 #ifdef ENABLE_CHECKING
21928 dw_die_ref die
= lookup_decl_die (decl
);
21934 /* Write the debugging output for DECL. */
21937 dwarf2out_function_decl (tree decl
)
21939 dwarf2out_decl (decl
);
21940 call_arg_locations
= NULL
;
21941 call_arg_loc_last
= NULL
;
21942 call_site_count
= -1;
21943 tail_call_site_count
= -1;
21944 decl_loc_table
->empty ();
21945 cached_dw_loc_list_table
->empty ();
21948 /* Output a marker (i.e. a label) for the beginning of the generated code for
21949 a lexical block. */
21952 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21953 unsigned int blocknum
)
21955 switch_to_section (current_function_section ());
21956 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21959 /* Output a marker (i.e. a label) for the end of the generated code for a
21963 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21965 switch_to_section (current_function_section ());
21966 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21969 /* Returns nonzero if it is appropriate not to emit any debugging
21970 information for BLOCK, because it doesn't contain any instructions.
21972 Don't allow this for blocks with nested functions or local classes
21973 as we would end up with orphans, and in the presence of scheduling
21974 we may end up calling them anyway. */
21977 dwarf2out_ignore_block (const_tree block
)
21982 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21983 if (TREE_CODE (decl
) == FUNCTION_DECL
21984 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21986 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21988 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21989 if (TREE_CODE (decl
) == FUNCTION_DECL
21990 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21997 /* Hash table routines for file_hash. */
22000 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
22002 return filename_cmp (p1
->filename
, p2
) == 0;
22006 dwarf_file_hasher::hash (dwarf_file_data
*p
)
22008 return htab_hash_string (p
->filename
);
22011 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22012 dwarf2out.c) and return its "index". The index of each (known) filename is
22013 just a unique number which is associated with only that one filename. We
22014 need such numbers for the sake of generating labels (in the .debug_sfnames
22015 section) and references to those files numbers (in the .debug_srcinfo
22016 and.debug_macinfo sections). If the filename given as an argument is not
22017 found in our current list, add it to the list and assign it the next
22018 available unique index number. */
22020 static struct dwarf_file_data
*
22021 lookup_filename (const char *file_name
)
22023 struct dwarf_file_data
* created
;
22028 dwarf_file_data
**slot
22029 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
22034 created
= ggc_alloc
<dwarf_file_data
> ();
22035 created
->filename
= file_name
;
22036 created
->emitted_number
= 0;
22041 /* If the assembler will construct the file table, then translate the compiler
22042 internal file table number into the assembler file table number, and emit
22043 a .file directive if we haven't already emitted one yet. The file table
22044 numbers are different because we prune debug info for unused variables and
22045 types, which may include filenames. */
22048 maybe_emit_file (struct dwarf_file_data
* fd
)
22050 if (! fd
->emitted_number
)
22052 if (last_emitted_file
)
22053 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
22055 fd
->emitted_number
= 1;
22056 last_emitted_file
= fd
;
22058 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22060 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
22061 output_quoted_string (asm_out_file
,
22062 remap_debug_filename (fd
->filename
));
22063 fputc ('\n', asm_out_file
);
22067 return fd
->emitted_number
;
22070 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22071 That generation should happen after function debug info has been
22072 generated. The value of the attribute is the constant value of ARG. */
22075 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
22077 die_arg_entry entry
;
22082 if (!tmpl_value_parm_die_table
)
22083 vec_alloc (tmpl_value_parm_die_table
, 32);
22087 vec_safe_push (tmpl_value_parm_die_table
, entry
);
22090 /* Return TRUE if T is an instance of generic type, FALSE
22094 generic_type_p (tree t
)
22096 if (t
== NULL_TREE
|| !TYPE_P (t
))
22098 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
22101 /* Schedule the generation of the generic parameter dies for the
22102 instance of generic type T. The proper generation itself is later
22103 done by gen_scheduled_generic_parms_dies. */
22106 schedule_generic_params_dies_gen (tree t
)
22108 if (!generic_type_p (t
))
22111 if (!generic_type_instances
)
22112 vec_alloc (generic_type_instances
, 256);
22114 vec_safe_push (generic_type_instances
, t
);
22117 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22118 by append_entry_to_tmpl_value_parm_die_table. This function must
22119 be called after function DIEs have been generated. */
22122 gen_remaining_tmpl_value_param_die_attribute (void)
22124 if (tmpl_value_parm_die_table
)
22129 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
22130 tree_add_const_value_attribute (e
->die
, e
->arg
);
22134 /* Generate generic parameters DIEs for instances of generic types
22135 that have been previously scheduled by
22136 schedule_generic_params_dies_gen. This function must be called
22137 after all the types of the CU have been laid out. */
22140 gen_scheduled_generic_parms_dies (void)
22145 if (!generic_type_instances
)
22148 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
22149 if (COMPLETE_TYPE_P (t
))
22150 gen_generic_params_dies (t
);
22154 /* Replace DW_AT_name for the decl with name. */
22157 dwarf2out_set_name (tree decl
, tree name
)
22163 die
= TYPE_SYMTAB_DIE (decl
);
22167 dname
= dwarf2_name (name
, 0);
22171 attr
= get_AT (die
, DW_AT_name
);
22174 struct indirect_string_node
*node
;
22176 node
= find_AT_string (dname
);
22177 /* replace the string. */
22178 attr
->dw_attr_val
.v
.val_str
= node
;
22182 add_name_attribute (die
, dname
);
22185 /* True if before or during processing of the first function being emitted. */
22186 static bool in_first_function_p
= true;
22187 /* True if loc_note during dwarf2out_var_location call might still be
22188 before first real instruction at address equal to .Ltext0. */
22189 static bool maybe_at_text_label_p
= true;
22190 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
22191 static unsigned int first_loclabel_num_not_at_text_label
;
22193 /* Called by the final INSN scan whenever we see a var location. We
22194 use it to drop labels in the right places, and throw the location in
22195 our lookup table. */
22198 dwarf2out_var_location (rtx_insn
*loc_note
)
22200 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
22201 struct var_loc_node
*newloc
;
22202 rtx_insn
*next_real
, *next_note
;
22203 static const char *last_label
;
22204 static const char *last_postcall_label
;
22205 static bool last_in_cold_section_p
;
22206 static rtx_insn
*expected_next_loc_note
;
22210 if (!NOTE_P (loc_note
))
22212 if (CALL_P (loc_note
))
22215 if (SIBLING_CALL_P (loc_note
))
22216 tail_call_site_count
++;
22221 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
22222 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
22225 /* Optimize processing a large consecutive sequence of location
22226 notes so we don't spend too much time in next_real_insn. If the
22227 next insn is another location note, remember the next_real_insn
22228 calculation for next time. */
22229 next_real
= cached_next_real_insn
;
22232 if (expected_next_loc_note
!= loc_note
)
22236 next_note
= NEXT_INSN (loc_note
);
22238 || next_note
->deleted ()
22239 || ! NOTE_P (next_note
)
22240 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
22241 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
22245 next_real
= next_real_insn (loc_note
);
22249 expected_next_loc_note
= next_note
;
22250 cached_next_real_insn
= next_real
;
22253 cached_next_real_insn
= NULL
;
22255 /* If there are no instructions which would be affected by this note,
22256 don't do anything. */
22258 && next_real
== NULL_RTX
22259 && !NOTE_DURING_CALL_P (loc_note
))
22262 if (next_real
== NULL_RTX
)
22263 next_real
= get_last_insn ();
22265 /* If there were any real insns between note we processed last time
22266 and this note (or if it is the first note), clear
22267 last_{,postcall_}label so that they are not reused this time. */
22268 if (last_var_location_insn
== NULL_RTX
22269 || last_var_location_insn
!= next_real
22270 || last_in_cold_section_p
!= in_cold_section_p
)
22273 last_postcall_label
= NULL
;
22278 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
22279 newloc
= add_var_loc_to_decl (decl
, loc_note
,
22280 NOTE_DURING_CALL_P (loc_note
)
22281 ? last_postcall_label
: last_label
);
22282 if (newloc
== NULL
)
22291 /* If there were no real insns between note we processed last time
22292 and this note, use the label we emitted last time. Otherwise
22293 create a new label and emit it. */
22294 if (last_label
== NULL
)
22296 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
22297 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
22299 last_label
= ggc_strdup (loclabel
);
22300 /* See if loclabel might be equal to .Ltext0. If yes,
22301 bump first_loclabel_num_not_at_text_label. */
22302 if (!have_multiple_function_sections
22303 && in_first_function_p
22304 && maybe_at_text_label_p
)
22306 static rtx_insn
*last_start
;
22308 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
22309 if (insn
== last_start
)
22311 else if (!NONDEBUG_INSN_P (insn
))
22315 rtx body
= PATTERN (insn
);
22316 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
22318 /* Inline asm could occupy zero bytes. */
22319 else if (GET_CODE (body
) == ASM_INPUT
22320 || asm_noperands (body
) >= 0)
22322 #ifdef HAVE_attr_length
22323 else if (get_attr_min_length (insn
) == 0)
22328 /* Assume insn has non-zero length. */
22329 maybe_at_text_label_p
= false;
22333 if (maybe_at_text_label_p
)
22335 last_start
= loc_note
;
22336 first_loclabel_num_not_at_text_label
= loclabel_num
;
22343 struct call_arg_loc_node
*ca_loc
22344 = ggc_cleared_alloc
<call_arg_loc_node
> ();
22345 rtx_insn
*prev
= prev_real_insn (loc_note
);
22347 ca_loc
->call_arg_loc_note
= loc_note
;
22348 ca_loc
->next
= NULL
;
22349 ca_loc
->label
= last_label
;
22352 || (NONJUMP_INSN_P (prev
)
22353 && GET_CODE (PATTERN (prev
)) == SEQUENCE
22354 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
22355 if (!CALL_P (prev
))
22356 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
22357 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
22358 x
= get_call_rtx_from (PATTERN (prev
));
22361 x
= XEXP (XEXP (x
, 0), 0);
22362 if (GET_CODE (x
) == SYMBOL_REF
22363 && SYMBOL_REF_DECL (x
)
22364 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
22365 ca_loc
->symbol_ref
= x
;
22367 ca_loc
->block
= insn_scope (prev
);
22368 if (call_arg_locations
)
22369 call_arg_loc_last
->next
= ca_loc
;
22371 call_arg_locations
= ca_loc
;
22372 call_arg_loc_last
= ca_loc
;
22374 else if (!NOTE_DURING_CALL_P (loc_note
))
22375 newloc
->label
= last_label
;
22378 if (!last_postcall_label
)
22380 sprintf (loclabel
, "%s-1", last_label
);
22381 last_postcall_label
= ggc_strdup (loclabel
);
22383 newloc
->label
= last_postcall_label
;
22386 last_var_location_insn
= next_real
;
22387 last_in_cold_section_p
= in_cold_section_p
;
22390 /* Note in one location list that text section has changed. */
22393 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
22395 var_loc_list
*list
= *slot
;
22397 list
->last_before_switch
22398 = list
->last
->next
? list
->last
->next
: list
->last
;
22402 /* Note in all location lists that text section has changed. */
22405 var_location_switch_text_section (void)
22407 if (decl_loc_table
== NULL
)
22410 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
22413 /* Create a new line number table. */
22415 static dw_line_info_table
*
22416 new_line_info_table (void)
22418 dw_line_info_table
*table
;
22420 table
= ggc_cleared_alloc
<dw_line_info_table_struct
> ();
22421 table
->file_num
= 1;
22422 table
->line_num
= 1;
22423 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
22428 /* Lookup the "current" table into which we emit line info, so
22429 that we don't have to do it for every source line. */
22432 set_cur_line_info_table (section
*sec
)
22434 dw_line_info_table
*table
;
22436 if (sec
== text_section
)
22437 table
= text_section_line_info
;
22438 else if (sec
== cold_text_section
)
22440 table
= cold_text_section_line_info
;
22443 cold_text_section_line_info
= table
= new_line_info_table ();
22444 table
->end_label
= cold_end_label
;
22449 const char *end_label
;
22451 if (flag_reorder_blocks_and_partition
)
22453 if (in_cold_section_p
)
22454 end_label
= crtl
->subsections
.cold_section_end_label
;
22456 end_label
= crtl
->subsections
.hot_section_end_label
;
22460 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22461 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
22462 current_function_funcdef_no
);
22463 end_label
= ggc_strdup (label
);
22466 table
= new_line_info_table ();
22467 table
->end_label
= end_label
;
22469 vec_safe_push (separate_line_info
, table
);
22472 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22473 table
->is_stmt
= (cur_line_info_table
22474 ? cur_line_info_table
->is_stmt
22475 : DWARF_LINE_DEFAULT_IS_STMT_START
);
22476 cur_line_info_table
= table
;
22480 /* We need to reset the locations at the beginning of each
22481 function. We can't do this in the end_function hook, because the
22482 declarations that use the locations won't have been output when
22483 that hook is called. Also compute have_multiple_function_sections here. */
22486 dwarf2out_begin_function (tree fun
)
22488 section
*sec
= function_section (fun
);
22490 if (sec
!= text_section
)
22491 have_multiple_function_sections
= true;
22493 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
22495 gcc_assert (current_function_decl
== fun
);
22496 cold_text_section
= unlikely_text_section ();
22497 switch_to_section (cold_text_section
);
22498 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
22499 switch_to_section (sec
);
22502 dwarf2out_note_section_used ();
22503 call_site_count
= 0;
22504 tail_call_site_count
= 0;
22506 set_cur_line_info_table (sec
);
22509 /* Helper function of dwarf2out_end_function, called only after emitting
22510 the very first function into assembly. Check if some .debug_loc range
22511 might end with a .LVL* label that could be equal to .Ltext0.
22512 In that case we must force using absolute addresses in .debug_loc ranges,
22513 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
22514 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
22516 Set have_multiple_function_sections to true in that case and
22517 terminate htab traversal. */
22520 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
22522 var_loc_list
*entry
= *slot
;
22523 struct var_loc_node
*node
;
22525 node
= entry
->first
;
22526 if (node
&& node
->next
&& node
->next
->label
)
22529 const char *label
= node
->next
->label
;
22530 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
22532 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
22534 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
22535 if (strcmp (label
, loclabel
) == 0)
22537 have_multiple_function_sections
= true;
22545 /* Hook called after emitting a function into assembly.
22546 This does something only for the very first function emitted. */
22549 dwarf2out_end_function (unsigned int)
22551 if (in_first_function_p
22552 && !have_multiple_function_sections
22553 && first_loclabel_num_not_at_text_label
22555 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
22556 in_first_function_p
= false;
22557 maybe_at_text_label_p
= false;
22560 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
22561 front-ends register a translation unit even before dwarf2out_init is
22563 static tree main_translation_unit
= NULL_TREE
;
22565 /* Hook called by front-ends after they built their main translation unit.
22566 Associate comp_unit_die to UNIT. */
22569 dwarf2out_register_main_translation_unit (tree unit
)
22571 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
22572 && main_translation_unit
== NULL_TREE
);
22573 main_translation_unit
= unit
;
22574 /* If dwarf2out_init has not been called yet, it will perform the association
22575 itself looking at main_translation_unit. */
22576 if (decl_die_table
!= NULL
)
22577 equate_decl_number_to_die (unit
, comp_unit_die ());
22580 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22583 push_dw_line_info_entry (dw_line_info_table
*table
,
22584 enum dw_line_info_opcode opcode
, unsigned int val
)
22586 dw_line_info_entry e
;
22589 vec_safe_push (table
->entries
, e
);
22592 /* Output a label to mark the beginning of a source code line entry
22593 and record information relating to this source line, in
22594 'line_info_table' for later output of the .debug_line section. */
22595 /* ??? The discriminator parameter ought to be unsigned. */
22598 dwarf2out_source_line (unsigned int line
, const char *filename
,
22599 int discriminator
, bool is_stmt
)
22601 unsigned int file_num
;
22602 dw_line_info_table
*table
;
22604 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
22607 /* The discriminator column was added in dwarf4. Simplify the below
22608 by simply removing it if we're not supposed to output it. */
22609 if (dwarf_version
< 4 && dwarf_strict
)
22612 table
= cur_line_info_table
;
22613 file_num
= maybe_emit_file (lookup_filename (filename
));
22615 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22616 the debugger has used the second (possibly duplicate) line number
22617 at the beginning of the function to mark the end of the prologue.
22618 We could eliminate any other duplicates within the function. For
22619 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22620 that second line number entry. */
22621 /* Recall that this end-of-prologue indication is *not* the same thing
22622 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22623 to which the hook corresponds, follows the last insn that was
22624 emitted by gen_prologue. What we need is to precede the first insn
22625 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22626 insn that corresponds to something the user wrote. These may be
22627 very different locations once scheduling is enabled. */
22629 if (0 && file_num
== table
->file_num
22630 && line
== table
->line_num
22631 && discriminator
== table
->discrim_num
22632 && is_stmt
== table
->is_stmt
)
22635 switch_to_section (current_function_section ());
22637 /* If requested, emit something human-readable. */
22638 if (flag_debug_asm
)
22639 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
22641 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22643 /* Emit the .loc directive understood by GNU as. */
22644 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
22645 file_num, line, is_stmt, discriminator */
22646 fputs ("\t.loc ", asm_out_file
);
22647 fprint_ul (asm_out_file
, file_num
);
22648 putc (' ', asm_out_file
);
22649 fprint_ul (asm_out_file
, line
);
22650 putc (' ', asm_out_file
);
22651 putc ('0', asm_out_file
);
22653 if (is_stmt
!= table
->is_stmt
)
22655 fputs (" is_stmt ", asm_out_file
);
22656 putc (is_stmt
? '1' : '0', asm_out_file
);
22658 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
22660 gcc_assert (discriminator
> 0);
22661 fputs (" discriminator ", asm_out_file
);
22662 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
22664 putc ('\n', asm_out_file
);
22668 unsigned int label_num
= ++line_info_label_num
;
22670 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
22672 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
22673 if (file_num
!= table
->file_num
)
22674 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
22675 if (discriminator
!= table
->discrim_num
)
22676 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
22677 if (is_stmt
!= table
->is_stmt
)
22678 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
22679 push_dw_line_info_entry (table
, LI_set_line
, line
);
22682 table
->file_num
= file_num
;
22683 table
->line_num
= line
;
22684 table
->discrim_num
= discriminator
;
22685 table
->is_stmt
= is_stmt
;
22686 table
->in_use
= true;
22689 /* Record the beginning of a new source file. */
22692 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
22694 if (flag_eliminate_dwarf2_dups
)
22696 /* Record the beginning of the file for break_out_includes. */
22697 dw_die_ref bincl_die
;
22699 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
22700 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
22703 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22706 e
.code
= DW_MACINFO_start_file
;
22708 e
.info
= ggc_strdup (filename
);
22709 vec_safe_push (macinfo_table
, e
);
22713 /* Record the end of a source file. */
22716 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
22718 if (flag_eliminate_dwarf2_dups
)
22719 /* Record the end of the file for break_out_includes. */
22720 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
22722 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22725 e
.code
= DW_MACINFO_end_file
;
22728 vec_safe_push (macinfo_table
, e
);
22732 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22733 the tail part of the directive line, i.e. the part which is past the
22734 initial whitespace, #, whitespace, directive-name, whitespace part. */
22737 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
22738 const char *buffer ATTRIBUTE_UNUSED
)
22740 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22743 /* Insert a dummy first entry to be able to optimize the whole
22744 predefined macro block using DW_MACRO_GNU_transparent_include. */
22745 if (macinfo_table
->is_empty () && lineno
<= 1)
22750 vec_safe_push (macinfo_table
, e
);
22752 e
.code
= DW_MACINFO_define
;
22754 e
.info
= ggc_strdup (buffer
);
22755 vec_safe_push (macinfo_table
, e
);
22759 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22760 the tail part of the directive line, i.e. the part which is past the
22761 initial whitespace, #, whitespace, directive-name, whitespace part. */
22764 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
22765 const char *buffer ATTRIBUTE_UNUSED
)
22767 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22770 /* Insert a dummy first entry to be able to optimize the whole
22771 predefined macro block using DW_MACRO_GNU_transparent_include. */
22772 if (macinfo_table
->is_empty () && lineno
<= 1)
22777 vec_safe_push (macinfo_table
, e
);
22779 e
.code
= DW_MACINFO_undef
;
22781 e
.info
= ggc_strdup (buffer
);
22782 vec_safe_push (macinfo_table
, e
);
22786 /* Helpers to manipulate hash table of CUs. */
22788 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
22790 typedef macinfo_entry
*value_type
;
22791 typedef macinfo_entry
*compare_type
;
22792 static inline hashval_t
hash (const macinfo_entry
*);
22793 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
22797 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
22799 return htab_hash_string (entry
->info
);
22803 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
22804 const macinfo_entry
*entry2
)
22806 return !strcmp (entry1
->info
, entry2
->info
);
22809 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
22811 /* Output a single .debug_macinfo entry. */
22814 output_macinfo_op (macinfo_entry
*ref
)
22818 struct indirect_string_node
*node
;
22819 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22820 struct dwarf_file_data
*fd
;
22824 case DW_MACINFO_start_file
:
22825 fd
= lookup_filename (ref
->info
);
22826 file_num
= maybe_emit_file (fd
);
22827 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22828 dw2_asm_output_data_uleb128 (ref
->lineno
,
22829 "Included from line number %lu",
22830 (unsigned long) ref
->lineno
);
22831 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22833 case DW_MACINFO_end_file
:
22834 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22836 case DW_MACINFO_define
:
22837 case DW_MACINFO_undef
:
22838 len
= strlen (ref
->info
) + 1;
22840 && len
> DWARF_OFFSET_SIZE
22841 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22842 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22844 ref
->code
= ref
->code
== DW_MACINFO_define
22845 ? DW_MACRO_GNU_define_indirect
22846 : DW_MACRO_GNU_undef_indirect
;
22847 output_macinfo_op (ref
);
22850 dw2_asm_output_data (1, ref
->code
,
22851 ref
->code
== DW_MACINFO_define
22852 ? "Define macro" : "Undefine macro");
22853 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22854 (unsigned long) ref
->lineno
);
22855 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22857 case DW_MACRO_GNU_define_indirect
:
22858 case DW_MACRO_GNU_undef_indirect
:
22859 node
= find_AT_string (ref
->info
);
22861 && ((node
->form
== DW_FORM_strp
)
22862 || (node
->form
== DW_FORM_GNU_str_index
)));
22863 dw2_asm_output_data (1, ref
->code
,
22864 ref
->code
== DW_MACRO_GNU_define_indirect
22865 ? "Define macro indirect"
22866 : "Undefine macro indirect");
22867 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22868 (unsigned long) ref
->lineno
);
22869 if (node
->form
== DW_FORM_strp
)
22870 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
22871 debug_str_section
, "The macro: \"%s\"",
22874 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
22877 case DW_MACRO_GNU_transparent_include
:
22878 dw2_asm_output_data (1, ref
->code
, "Transparent include");
22879 ASM_GENERATE_INTERNAL_LABEL (label
,
22880 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
22881 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
22884 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22885 ASM_COMMENT_START
, (unsigned long) ref
->code
);
22890 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22891 other compilation unit .debug_macinfo sections. IDX is the first
22892 index of a define/undef, return the number of ops that should be
22893 emitted in a comdat .debug_macinfo section and emit
22894 a DW_MACRO_GNU_transparent_include entry referencing it.
22895 If the define/undef entry should be emitted normally, return 0. */
22898 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
22899 macinfo_hash_type
**macinfo_htab
)
22901 macinfo_entry
*first
, *second
, *cur
, *inc
;
22902 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
22903 unsigned char checksum
[16];
22904 struct md5_ctx ctx
;
22905 char *grp_name
, *tail
;
22907 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
22908 macinfo_entry
**slot
;
22910 first
= &(*macinfo_table
)[idx
];
22911 second
= &(*macinfo_table
)[idx
+ 1];
22913 /* Optimize only if there are at least two consecutive define/undef ops,
22914 and either all of them are before first DW_MACINFO_start_file
22915 with lineno {0,1} (i.e. predefined macro block), or all of them are
22916 in some included header file. */
22917 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
22919 if (vec_safe_is_empty (files
))
22921 if (first
->lineno
> 1 || second
->lineno
> 1)
22924 else if (first
->lineno
== 0)
22927 /* Find the last define/undef entry that can be grouped together
22928 with first and at the same time compute md5 checksum of their
22929 codes, linenumbers and strings. */
22930 md5_init_ctx (&ctx
);
22931 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
22932 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
22934 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
22938 unsigned char code
= cur
->code
;
22939 md5_process_bytes (&code
, 1, &ctx
);
22940 checksum_uleb128 (cur
->lineno
, &ctx
);
22941 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
22943 md5_finish_ctx (&ctx
, checksum
);
22946 /* From the containing include filename (if any) pick up just
22947 usable characters from its basename. */
22948 if (vec_safe_is_empty (files
))
22951 base
= lbasename (files
->last ().info
);
22952 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
22953 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22954 encoded_filename_len
++;
22955 /* Count . at the end. */
22956 if (encoded_filename_len
)
22957 encoded_filename_len
++;
22959 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
22960 linebuf_len
= strlen (linebuf
);
22962 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
22963 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
22965 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
22966 tail
= grp_name
+ 4;
22967 if (encoded_filename_len
)
22969 for (i
= 0; base
[i
]; i
++)
22970 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22974 memcpy (tail
, linebuf
, linebuf_len
);
22975 tail
+= linebuf_len
;
22977 for (i
= 0; i
< 16; i
++)
22978 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
22980 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
22981 in the empty vector entry before the first define/undef. */
22982 inc
= &(*macinfo_table
)[idx
- 1];
22983 inc
->code
= DW_MACRO_GNU_transparent_include
;
22985 inc
->info
= ggc_strdup (grp_name
);
22986 if (!*macinfo_htab
)
22987 *macinfo_htab
= new macinfo_hash_type (10);
22988 /* Avoid emitting duplicates. */
22989 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
22994 /* If such an entry has been used before, just emit
22995 a DW_MACRO_GNU_transparent_include op. */
22997 output_macinfo_op (inc
);
22998 /* And clear all macinfo_entry in the range to avoid emitting them
22999 in the second pass. */
23000 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
23009 inc
->lineno
= (*macinfo_htab
)->elements ();
23010 output_macinfo_op (inc
);
23015 /* Save any strings needed by the macinfo table in the debug str
23016 table. All strings must be collected into the table by the time
23017 index_string is called. */
23020 save_macinfo_strings (void)
23024 macinfo_entry
*ref
;
23026 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
23030 /* Match the logic in output_macinfo_op to decide on
23031 indirect strings. */
23032 case DW_MACINFO_define
:
23033 case DW_MACINFO_undef
:
23034 len
= strlen (ref
->info
) + 1;
23036 && len
> DWARF_OFFSET_SIZE
23037 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
23038 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
23039 set_indirect_string (find_AT_string (ref
->info
));
23041 case DW_MACRO_GNU_define_indirect
:
23042 case DW_MACRO_GNU_undef_indirect
:
23043 set_indirect_string (find_AT_string (ref
->info
));
23051 /* Output macinfo section(s). */
23054 output_macinfo (void)
23057 unsigned long length
= vec_safe_length (macinfo_table
);
23058 macinfo_entry
*ref
;
23059 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
23060 macinfo_hash_type
*macinfo_htab
= NULL
;
23065 /* output_macinfo* uses these interchangeably. */
23066 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
23067 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
23068 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
23069 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
23071 /* For .debug_macro emit the section header. */
23074 dw2_asm_output_data (2, 4, "DWARF macro version number");
23075 if (DWARF_OFFSET_SIZE
== 8)
23076 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
23078 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
23079 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
23080 (!dwarf_split_debug_info
? debug_line_section_label
23081 : debug_skeleton_line_section_label
),
23082 debug_line_section
, NULL
);
23085 /* In the first loop, it emits the primary .debug_macinfo section
23086 and after each emitted op the macinfo_entry is cleared.
23087 If a longer range of define/undef ops can be optimized using
23088 DW_MACRO_GNU_transparent_include, the
23089 DW_MACRO_GNU_transparent_include op is emitted and kept in
23090 the vector before the first define/undef in the range and the
23091 whole range of define/undef ops is not emitted and kept. */
23092 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23096 case DW_MACINFO_start_file
:
23097 vec_safe_push (files
, *ref
);
23099 case DW_MACINFO_end_file
:
23100 if (!vec_safe_is_empty (files
))
23103 case DW_MACINFO_define
:
23104 case DW_MACINFO_undef
:
23106 && HAVE_COMDAT_GROUP
23107 && vec_safe_length (files
) != 1
23110 && (*macinfo_table
)[i
- 1].code
== 0)
23112 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
23121 /* A dummy entry may be inserted at the beginning to be able
23122 to optimize the whole block of predefined macros. */
23128 output_macinfo_op (ref
);
23136 delete macinfo_htab
;
23137 macinfo_htab
= NULL
;
23139 /* If any DW_MACRO_GNU_transparent_include were used, on those
23140 DW_MACRO_GNU_transparent_include entries terminate the
23141 current chain and switch to a new comdat .debug_macinfo
23142 section and emit the define/undef entries within it. */
23143 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23148 case DW_MACRO_GNU_transparent_include
:
23150 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23151 tree comdat_key
= get_identifier (ref
->info
);
23152 /* Terminate the previous .debug_macinfo section. */
23153 dw2_asm_output_data (1, 0, "End compilation unit");
23154 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
23156 | SECTION_LINKONCE
,
23158 ASM_GENERATE_INTERNAL_LABEL (label
,
23159 DEBUG_MACRO_SECTION_LABEL
,
23161 ASM_OUTPUT_LABEL (asm_out_file
, label
);
23164 dw2_asm_output_data (2, 4, "DWARF macro version number");
23165 if (DWARF_OFFSET_SIZE
== 8)
23166 dw2_asm_output_data (1, 1, "Flags: 64-bit");
23168 dw2_asm_output_data (1, 0, "Flags: 32-bit");
23171 case DW_MACINFO_define
:
23172 case DW_MACINFO_undef
:
23173 output_macinfo_op (ref
);
23178 gcc_unreachable ();
23182 /* Set up for Dwarf output at the start of compilation. */
23185 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
23187 /* This option is currently broken, see (PR53118 and PR46102). */
23188 if (flag_eliminate_dwarf2_dups
23189 && strstr (lang_hooks
.name
, "C++"))
23191 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
23192 flag_eliminate_dwarf2_dups
= 0;
23195 /* Allocate the file_table. */
23196 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
23198 /* Allocate the decl_die_table. */
23199 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
23201 /* Allocate the decl_loc_table. */
23202 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
23204 /* Allocate the cached_dw_loc_list_table. */
23205 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
23207 /* Allocate the initial hunk of the decl_scope_table. */
23208 vec_alloc (decl_scope_table
, 256);
23210 /* Allocate the initial hunk of the abbrev_die_table. */
23211 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
23212 (ABBREV_DIE_TABLE_INCREMENT
);
23213 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
23214 /* Zero-th entry is allocated, but unused. */
23215 abbrev_die_table_in_use
= 1;
23217 /* Allocate the pubtypes and pubnames vectors. */
23218 vec_alloc (pubname_table
, 32);
23219 vec_alloc (pubtype_table
, 32);
23221 vec_alloc (incomplete_types
, 64);
23223 vec_alloc (used_rtx_array
, 32);
23225 if (!dwarf_split_debug_info
)
23227 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
23228 SECTION_DEBUG
, NULL
);
23229 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23230 SECTION_DEBUG
, NULL
);
23231 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
23232 SECTION_DEBUG
, NULL
);
23236 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
23237 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23238 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
23239 SECTION_DEBUG
| SECTION_EXCLUDE
,
23241 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
23242 SECTION_DEBUG
, NULL
);
23243 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
23244 SECTION_DEBUG
, NULL
);
23245 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23246 SECTION_DEBUG
, NULL
);
23247 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
23248 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
23250 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
23251 the main .o, but the skeleton_line goes into the split off dwo. */
23252 debug_skeleton_line_section
23253 = get_section (DEBUG_DWO_LINE_SECTION
,
23254 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23255 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
23256 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
23257 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
23258 SECTION_DEBUG
| SECTION_EXCLUDE
,
23260 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
23261 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
23262 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
23263 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23264 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
23265 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
23267 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
23268 SECTION_DEBUG
, NULL
);
23269 debug_macinfo_section
= get_section (dwarf_strict
23270 ? DEBUG_MACINFO_SECTION
23271 : DEBUG_MACRO_SECTION
,
23272 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
23273 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
23274 SECTION_DEBUG
, NULL
);
23275 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
23276 SECTION_DEBUG
, NULL
);
23277 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
23278 SECTION_DEBUG
, NULL
);
23279 debug_str_section
= get_section (DEBUG_STR_SECTION
,
23280 DEBUG_STR_SECTION_FLAGS
, NULL
);
23281 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
23282 SECTION_DEBUG
, NULL
);
23283 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
23284 SECTION_DEBUG
, NULL
);
23286 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
23287 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
23288 DEBUG_ABBREV_SECTION_LABEL
, 0);
23289 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
23290 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
23291 COLD_TEXT_SECTION_LABEL
, 0);
23292 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
23294 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
23295 DEBUG_INFO_SECTION_LABEL
, 0);
23296 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
23297 DEBUG_LINE_SECTION_LABEL
, 0);
23298 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
23299 DEBUG_RANGES_SECTION_LABEL
, 0);
23300 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
23301 DEBUG_ADDR_SECTION_LABEL
, 0);
23302 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
23304 ? DEBUG_MACINFO_SECTION_LABEL
23305 : DEBUG_MACRO_SECTION_LABEL
, 0);
23306 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
23308 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23309 vec_alloc (macinfo_table
, 64);
23311 switch_to_section (text_section
);
23312 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
23314 /* Make sure the line number table for .text always exists. */
23315 text_section_line_info
= new_line_info_table ();
23316 text_section_line_info
->end_label
= text_end_label
;
23318 /* If front-ends already registered a main translation unit but we were not
23319 ready to perform the association, do this now. */
23320 if (main_translation_unit
!= NULL_TREE
)
23321 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
23324 /* Called before compile () starts outputtting functions, variables
23325 and toplevel asms into assembly. */
23328 dwarf2out_assembly_start (void)
23330 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23331 && dwarf2out_do_cfi_asm ()
23332 && (!(flag_unwind_tables
|| flag_exceptions
)
23333 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
23334 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
23337 /* A helper function for dwarf2out_finish called through
23338 htab_traverse. Assign a string its index. All strings must be
23339 collected into the table by the time index_string is called,
23340 because the indexing code relies on htab_traverse to traverse nodes
23341 in the same order for each run. */
23344 index_string (indirect_string_node
**h
, unsigned int *index
)
23346 indirect_string_node
*node
= *h
;
23348 find_string_form (node
);
23349 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23351 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
23352 node
->index
= *index
;
23358 /* A helper function for output_indirect_strings called through
23359 htab_traverse. Output the offset to a string and update the
23363 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
23365 indirect_string_node
*node
= *h
;
23367 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23369 /* Assert that this node has been assigned an index. */
23370 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
23371 && node
->index
!= NOT_INDEXED
);
23372 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
23373 "indexed string 0x%x: %s", node
->index
, node
->str
);
23374 *offset
+= strlen (node
->str
) + 1;
23379 /* A helper function for dwarf2out_finish called through
23380 htab_traverse. Output the indexed string. */
23383 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
23385 struct indirect_string_node
*node
= *h
;
23387 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23389 /* Assert that the strings are output in the same order as their
23390 indexes were assigned. */
23391 gcc_assert (*cur_idx
== node
->index
);
23392 assemble_string (node
->str
, strlen (node
->str
) + 1);
23398 /* A helper function for dwarf2out_finish called through
23399 htab_traverse. Emit one queued .debug_str string. */
23402 output_indirect_string (indirect_string_node
**h
, void *)
23404 struct indirect_string_node
*node
= *h
;
23406 node
->form
= find_string_form (node
);
23407 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
23409 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
23410 assemble_string (node
->str
, strlen (node
->str
) + 1);
23416 /* Output the indexed string table. */
23419 output_indirect_strings (void)
23421 switch_to_section (debug_str_section
);
23422 if (!dwarf_split_debug_info
)
23423 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23426 unsigned int offset
= 0;
23427 unsigned int cur_idx
= 0;
23429 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23431 switch_to_section (debug_str_offsets_section
);
23432 debug_str_hash
->traverse_noresize
23433 <unsigned int *, output_index_string_offset
> (&offset
);
23434 switch_to_section (debug_str_dwo_section
);
23435 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
23440 /* Callback for htab_traverse to assign an index to an entry in the
23441 table, and to write that entry to the .debug_addr section. */
23444 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
23446 addr_table_entry
*entry
= *slot
;
23448 if (entry
->refcount
== 0)
23450 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
23451 || entry
->index
== NOT_INDEXED
);
23455 gcc_assert (entry
->index
== *cur_index
);
23458 switch (entry
->kind
)
23461 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
23462 "0x%x", entry
->index
);
23464 case ate_kind_rtx_dtprel
:
23465 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
23466 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
23469 fputc ('\n', asm_out_file
);
23471 case ate_kind_label
:
23472 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
23473 "0x%x", entry
->index
);
23476 gcc_unreachable ();
23481 /* Produce the .debug_addr section. */
23484 output_addr_table (void)
23486 unsigned int index
= 0;
23487 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
23490 switch_to_section (debug_addr_section
);
23492 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
23495 #if ENABLE_ASSERT_CHECKING
23496 /* Verify that all marks are clear. */
23499 verify_marks_clear (dw_die_ref die
)
23503 gcc_assert (! die
->die_mark
);
23504 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
23506 #endif /* ENABLE_ASSERT_CHECKING */
23508 /* Clear the marks for a die and its children.
23509 Be cool if the mark isn't set. */
23512 prune_unmark_dies (dw_die_ref die
)
23518 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
23521 /* Given DIE that we're marking as used, find any other dies
23522 it references as attributes and mark them as used. */
23525 prune_unused_types_walk_attribs (dw_die_ref die
)
23530 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23532 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
23534 /* A reference to another DIE.
23535 Make sure that it will get emitted.
23536 If it was broken out into a comdat group, don't follow it. */
23537 if (! AT_ref (a
)->comdat_type_p
23538 || a
->dw_attr
== DW_AT_specification
)
23539 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
23541 /* Set the string's refcount to 0 so that prune_unused_types_mark
23542 accounts properly for it. */
23543 if (AT_class (a
) == dw_val_class_str
)
23544 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
23548 /* Mark the generic parameters and arguments children DIEs of DIE. */
23551 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
23555 if (die
== NULL
|| die
->die_child
== NULL
)
23557 c
= die
->die_child
;
23560 if (is_template_parameter (c
))
23561 prune_unused_types_mark (c
, 1);
23563 } while (c
&& c
!= die
->die_child
);
23566 /* Mark DIE as being used. If DOKIDS is true, then walk down
23567 to DIE's children. */
23570 prune_unused_types_mark (dw_die_ref die
, int dokids
)
23574 if (die
->die_mark
== 0)
23576 /* We haven't done this node yet. Mark it as used. */
23578 /* If this is the DIE of a generic type instantiation,
23579 mark the children DIEs that describe its generic parms and
23581 prune_unused_types_mark_generic_parms_dies (die
);
23583 /* We also have to mark its parents as used.
23584 (But we don't want to mark our parent's kids due to this,
23585 unless it is a class.) */
23586 if (die
->die_parent
)
23587 prune_unused_types_mark (die
->die_parent
,
23588 class_scope_p (die
->die_parent
));
23590 /* Mark any referenced nodes. */
23591 prune_unused_types_walk_attribs (die
);
23593 /* If this node is a specification,
23594 also mark the definition, if it exists. */
23595 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
23596 prune_unused_types_mark (die
->die_definition
, 1);
23599 if (dokids
&& die
->die_mark
!= 2)
23601 /* We need to walk the children, but haven't done so yet.
23602 Remember that we've walked the kids. */
23605 /* If this is an array type, we need to make sure our
23606 kids get marked, even if they're types. If we're
23607 breaking out types into comdat sections, do this
23608 for all type definitions. */
23609 if (die
->die_tag
== DW_TAG_array_type
23610 || (use_debug_types
23611 && is_type_die (die
) && ! is_declaration_die (die
)))
23612 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
23614 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23618 /* For local classes, look if any static member functions were emitted
23619 and if so, mark them. */
23622 prune_unused_types_walk_local_classes (dw_die_ref die
)
23626 if (die
->die_mark
== 2)
23629 switch (die
->die_tag
)
23631 case DW_TAG_structure_type
:
23632 case DW_TAG_union_type
:
23633 case DW_TAG_class_type
:
23636 case DW_TAG_subprogram
:
23637 if (!get_AT_flag (die
, DW_AT_declaration
)
23638 || die
->die_definition
!= NULL
)
23639 prune_unused_types_mark (die
, 1);
23646 /* Mark children. */
23647 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
23650 /* Walk the tree DIE and mark types that we actually use. */
23653 prune_unused_types_walk (dw_die_ref die
)
23657 /* Don't do anything if this node is already marked and
23658 children have been marked as well. */
23659 if (die
->die_mark
== 2)
23662 switch (die
->die_tag
)
23664 case DW_TAG_structure_type
:
23665 case DW_TAG_union_type
:
23666 case DW_TAG_class_type
:
23667 if (die
->die_perennial_p
)
23670 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
23671 if (c
->die_tag
== DW_TAG_subprogram
)
23674 /* Finding used static member functions inside of classes
23675 is needed just for local classes, because for other classes
23676 static member function DIEs with DW_AT_specification
23677 are emitted outside of the DW_TAG_*_type. If we ever change
23678 it, we'd need to call this even for non-local classes. */
23680 prune_unused_types_walk_local_classes (die
);
23682 /* It's a type node --- don't mark it. */
23685 case DW_TAG_const_type
:
23686 case DW_TAG_packed_type
:
23687 case DW_TAG_pointer_type
:
23688 case DW_TAG_reference_type
:
23689 case DW_TAG_rvalue_reference_type
:
23690 case DW_TAG_volatile_type
:
23691 case DW_TAG_typedef
:
23692 case DW_TAG_array_type
:
23693 case DW_TAG_interface_type
:
23694 case DW_TAG_friend
:
23695 case DW_TAG_variant_part
:
23696 case DW_TAG_enumeration_type
:
23697 case DW_TAG_subroutine_type
:
23698 case DW_TAG_string_type
:
23699 case DW_TAG_set_type
:
23700 case DW_TAG_subrange_type
:
23701 case DW_TAG_ptr_to_member_type
:
23702 case DW_TAG_file_type
:
23703 if (die
->die_perennial_p
)
23706 /* It's a type node --- don't mark it. */
23710 /* Mark everything else. */
23714 if (die
->die_mark
== 0)
23718 /* Now, mark any dies referenced from here. */
23719 prune_unused_types_walk_attribs (die
);
23724 /* Mark children. */
23725 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23728 /* Increment the string counts on strings referred to from DIE's
23732 prune_unused_types_update_strings (dw_die_ref die
)
23737 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23738 if (AT_class (a
) == dw_val_class_str
)
23740 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
23742 /* Avoid unnecessarily putting strings that are used less than
23743 twice in the hash table. */
23745 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
23747 indirect_string_node
**slot
23748 = debug_str_hash
->find_slot_with_hash (s
->str
,
23749 htab_hash_string (s
->str
),
23751 gcc_assert (*slot
== NULL
);
23757 /* Remove from the tree DIE any dies that aren't marked. */
23760 prune_unused_types_prune (dw_die_ref die
)
23764 gcc_assert (die
->die_mark
);
23765 prune_unused_types_update_strings (die
);
23767 if (! die
->die_child
)
23770 c
= die
->die_child
;
23772 dw_die_ref prev
= c
;
23773 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
23774 if (c
== die
->die_child
)
23776 /* No marked children between 'prev' and the end of the list. */
23778 /* No marked children at all. */
23779 die
->die_child
= NULL
;
23782 prev
->die_sib
= c
->die_sib
;
23783 die
->die_child
= prev
;
23788 if (c
!= prev
->die_sib
)
23790 prune_unused_types_prune (c
);
23791 } while (c
!= die
->die_child
);
23794 /* Remove dies representing declarations that we never use. */
23797 prune_unused_types (void)
23800 limbo_die_node
*node
;
23801 comdat_type_node
*ctnode
;
23803 dw_die_ref base_type
;
23805 #if ENABLE_ASSERT_CHECKING
23806 /* All the marks should already be clear. */
23807 verify_marks_clear (comp_unit_die ());
23808 for (node
= limbo_die_list
; node
; node
= node
->next
)
23809 verify_marks_clear (node
->die
);
23810 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23811 verify_marks_clear (ctnode
->root_die
);
23812 #endif /* ENABLE_ASSERT_CHECKING */
23814 /* Mark types that are used in global variables. */
23815 premark_types_used_by_global_vars ();
23817 /* Set the mark on nodes that are actually used. */
23818 prune_unused_types_walk (comp_unit_die ());
23819 for (node
= limbo_die_list
; node
; node
= node
->next
)
23820 prune_unused_types_walk (node
->die
);
23821 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23823 prune_unused_types_walk (ctnode
->root_die
);
23824 prune_unused_types_mark (ctnode
->type_die
, 1);
23827 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
23828 are unusual in that they are pubnames that are the children of pubtypes.
23829 They should only be marked via their parent DW_TAG_enumeration_type die,
23830 not as roots in themselves. */
23831 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
23832 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
23833 prune_unused_types_mark (pub
->die
, 1);
23834 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23835 prune_unused_types_mark (base_type
, 1);
23837 if (debug_str_hash
)
23838 debug_str_hash
->empty ();
23839 if (skeleton_debug_str_hash
)
23840 skeleton_debug_str_hash
->empty ();
23841 prune_unused_types_prune (comp_unit_die ());
23842 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
23845 if (!node
->die
->die_mark
)
23846 *pnode
= node
->next
;
23849 prune_unused_types_prune (node
->die
);
23850 pnode
= &node
->next
;
23853 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23854 prune_unused_types_prune (ctnode
->root_die
);
23856 /* Leave the marks clear. */
23857 prune_unmark_dies (comp_unit_die ());
23858 for (node
= limbo_die_list
; node
; node
= node
->next
)
23859 prune_unmark_dies (node
->die
);
23860 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23861 prune_unmark_dies (ctnode
->root_die
);
23864 /* Set the parameter to true if there are any relative pathnames in
23867 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
23869 struct dwarf_file_data
*d
= *slot
;
23870 if (!IS_ABSOLUTE_PATH (d
->filename
))
23878 /* Helpers to manipulate hash table of comdat type units. */
23880 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
23882 typedef comdat_type_node
*value_type
;
23883 typedef comdat_type_node
*compare_type
;
23884 static inline hashval_t
hash (const comdat_type_node
*);
23885 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
23889 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
23892 memcpy (&h
, type_node
->signature
, sizeof (h
));
23897 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
23898 const comdat_type_node
*type_node_2
)
23900 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
23901 DWARF_TYPE_SIGNATURE_SIZE
));
23904 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23905 to the location it would have been added, should we know its
23906 DECL_ASSEMBLER_NAME when we added other attributes. This will
23907 probably improve compactness of debug info, removing equivalent
23908 abbrevs, and hide any differences caused by deferring the
23909 computation of the assembler name, triggered by e.g. PCH. */
23912 move_linkage_attr (dw_die_ref die
)
23914 unsigned ix
= vec_safe_length (die
->die_attr
);
23915 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
23917 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
23918 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
23922 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
23924 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
23928 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
23930 die
->die_attr
->pop ();
23931 die
->die_attr
->quick_insert (ix
, linkage
);
23935 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23936 referenced from typed stack ops and count how often they are used. */
23939 mark_base_types (dw_loc_descr_ref loc
)
23941 dw_die_ref base_type
= NULL
;
23943 for (; loc
; loc
= loc
->dw_loc_next
)
23945 switch (loc
->dw_loc_opc
)
23947 case DW_OP_GNU_regval_type
:
23948 case DW_OP_GNU_deref_type
:
23949 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23951 case DW_OP_GNU_convert
:
23952 case DW_OP_GNU_reinterpret
:
23953 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
23956 case DW_OP_GNU_const_type
:
23957 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23959 case DW_OP_GNU_entry_value
:
23960 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
23965 gcc_assert (base_type
->die_parent
== comp_unit_die ());
23966 if (base_type
->die_mark
)
23967 base_type
->die_mark
++;
23970 base_types
.safe_push (base_type
);
23971 base_type
->die_mark
= 1;
23976 /* Comparison function for sorting marked base types. */
23979 base_type_cmp (const void *x
, const void *y
)
23981 dw_die_ref dx
= *(const dw_die_ref
*) x
;
23982 dw_die_ref dy
= *(const dw_die_ref
*) y
;
23983 unsigned int byte_size1
, byte_size2
;
23984 unsigned int encoding1
, encoding2
;
23985 if (dx
->die_mark
> dy
->die_mark
)
23987 if (dx
->die_mark
< dy
->die_mark
)
23989 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
23990 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
23991 if (byte_size1
< byte_size2
)
23993 if (byte_size1
> byte_size2
)
23995 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
23996 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
23997 if (encoding1
< encoding2
)
23999 if (encoding1
> encoding2
)
24004 /* Move base types marked by mark_base_types as early as possible
24005 in the CU, sorted by decreasing usage count both to make the
24006 uleb128 references as small as possible and to make sure they
24007 will have die_offset already computed by calc_die_sizes when
24008 sizes of typed stack loc ops is computed. */
24011 move_marked_base_types (void)
24014 dw_die_ref base_type
, die
, c
;
24016 if (base_types
.is_empty ())
24019 /* Sort by decreasing usage count, they will be added again in that
24021 base_types
.qsort (base_type_cmp
);
24022 die
= comp_unit_die ();
24023 c
= die
->die_child
;
24026 dw_die_ref prev
= c
;
24028 while (c
->die_mark
)
24030 remove_child_with_prev (c
, prev
);
24031 /* As base types got marked, there must be at least
24032 one node other than DW_TAG_base_type. */
24033 gcc_assert (c
!= c
->die_sib
);
24037 while (c
!= die
->die_child
);
24038 gcc_assert (die
->die_child
);
24039 c
= die
->die_child
;
24040 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
24042 base_type
->die_mark
= 0;
24043 base_type
->die_sib
= c
->die_sib
;
24044 c
->die_sib
= base_type
;
24049 /* Helper function for resolve_addr, attempt to resolve
24050 one CONST_STRING, return true if successful. Similarly verify that
24051 SYMBOL_REFs refer to variables emitted in the current CU. */
24054 resolve_one_addr (rtx
*addr
)
24058 if (GET_CODE (rtl
) == CONST_STRING
)
24060 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24061 tree t
= build_string (len
, XSTR (rtl
, 0));
24062 tree tlen
= size_int (len
- 1);
24064 = build_array_type (char_type_node
, build_index_type (tlen
));
24065 rtl
= lookup_constant_def (t
);
24066 if (!rtl
|| !MEM_P (rtl
))
24068 rtl
= XEXP (rtl
, 0);
24069 if (GET_CODE (rtl
) == SYMBOL_REF
24070 && SYMBOL_REF_DECL (rtl
)
24071 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24073 vec_safe_push (used_rtx_array
, rtl
);
24078 if (GET_CODE (rtl
) == SYMBOL_REF
24079 && SYMBOL_REF_DECL (rtl
))
24081 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
24083 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
24086 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24090 if (GET_CODE (rtl
) == CONST
)
24092 subrtx_ptr_iterator::array_type array
;
24093 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
24094 if (!resolve_one_addr (*iter
))
24101 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
24102 if possible, and create DW_TAG_dwarf_procedure that can be referenced
24103 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
24106 string_cst_pool_decl (tree t
)
24108 rtx rtl
= output_constant_def (t
, 1);
24109 unsigned char *array
;
24110 dw_loc_descr_ref l
;
24115 if (!rtl
|| !MEM_P (rtl
))
24117 rtl
= XEXP (rtl
, 0);
24118 if (GET_CODE (rtl
) != SYMBOL_REF
24119 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
24122 decl
= SYMBOL_REF_DECL (rtl
);
24123 if (!lookup_decl_die (decl
))
24125 len
= TREE_STRING_LENGTH (t
);
24126 vec_safe_push (used_rtx_array
, rtl
);
24127 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
24128 array
= ggc_vec_alloc
<unsigned char> (len
);
24129 memcpy (array
, TREE_STRING_POINTER (t
), len
);
24130 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
24131 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
24132 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
24133 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
24134 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
24135 add_AT_loc (ref
, DW_AT_location
, l
);
24136 equate_decl_number_to_die (decl
, ref
);
24141 /* Helper function of resolve_addr_in_expr. LOC is
24142 a DW_OP_addr followed by DW_OP_stack_value, either at the start
24143 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
24144 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
24145 with DW_OP_GNU_implicit_pointer if possible
24146 and return true, if unsuccessful, return false. */
24149 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
24151 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
24152 HOST_WIDE_INT offset
= 0;
24153 dw_die_ref ref
= NULL
;
24156 if (GET_CODE (rtl
) == CONST
24157 && GET_CODE (XEXP (rtl
, 0)) == PLUS
24158 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
24160 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
24161 rtl
= XEXP (XEXP (rtl
, 0), 0);
24163 if (GET_CODE (rtl
) == CONST_STRING
)
24165 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24166 tree t
= build_string (len
, XSTR (rtl
, 0));
24167 tree tlen
= size_int (len
- 1);
24170 = build_array_type (char_type_node
, build_index_type (tlen
));
24171 rtl
= string_cst_pool_decl (t
);
24175 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
24177 decl
= SYMBOL_REF_DECL (rtl
);
24178 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
24180 ref
= lookup_decl_die (decl
);
24181 if (ref
&& (get_AT (ref
, DW_AT_location
)
24182 || get_AT (ref
, DW_AT_const_value
)))
24184 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
24185 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24186 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
24187 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24188 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24189 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24190 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
24198 /* Helper function for resolve_addr, handle one location
24199 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24200 the location list couldn't be resolved. */
24203 resolve_addr_in_expr (dw_loc_descr_ref loc
)
24205 dw_loc_descr_ref keep
= NULL
;
24206 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
24207 switch (loc
->dw_loc_opc
)
24210 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24213 || prev
->dw_loc_opc
== DW_OP_piece
24214 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
24215 && loc
->dw_loc_next
24216 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
24218 && optimize_one_addr_into_implicit_ptr (loc
))
24223 case DW_OP_GNU_addr_index
:
24224 case DW_OP_GNU_const_index
:
24225 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
24226 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
24228 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
24229 if (!resolve_one_addr (&rtl
))
24231 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
24232 loc
->dw_loc_oprnd1
.val_entry
=
24233 add_addr_table_entry (rtl
, ate_kind_rtx
);
24236 case DW_OP_const4u
:
24237 case DW_OP_const8u
:
24239 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24242 case DW_OP_plus_uconst
:
24243 if (size_of_loc_descr (loc
)
24244 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
24246 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
24248 dw_loc_descr_ref repl
24249 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
24250 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
24251 add_loc_descr (&repl
, loc
->dw_loc_next
);
24255 case DW_OP_implicit_value
:
24256 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
24257 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
24260 case DW_OP_GNU_implicit_pointer
:
24261 case DW_OP_GNU_parameter_ref
:
24262 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
24265 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
24268 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24269 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24270 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24273 case DW_OP_GNU_const_type
:
24274 case DW_OP_GNU_regval_type
:
24275 case DW_OP_GNU_deref_type
:
24276 case DW_OP_GNU_convert
:
24277 case DW_OP_GNU_reinterpret
:
24278 while (loc
->dw_loc_next
24279 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
24281 dw_die_ref base1
, base2
;
24282 unsigned enc1
, enc2
, size1
, size2
;
24283 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24284 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24285 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
24286 else if (loc
->dw_loc_oprnd1
.val_class
24287 == dw_val_class_unsigned_const
)
24290 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24291 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
24292 == dw_val_class_unsigned_const
)
24294 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24295 gcc_assert (base1
->die_tag
== DW_TAG_base_type
24296 && base2
->die_tag
== DW_TAG_base_type
);
24297 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
24298 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
24299 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
24300 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
24302 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
24303 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
24307 /* Optimize away next DW_OP_GNU_convert after
24308 adjusting LOC's base type die reference. */
24309 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24310 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24311 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
24313 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
24314 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24317 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24318 point typed stack entry. */
24319 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
24320 keep
= loc
->dw_loc_next
;
24330 /* Helper function of resolve_addr. DIE had DW_AT_location of
24331 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
24332 and DW_OP_addr couldn't be resolved. resolve_addr has already
24333 removed the DW_AT_location attribute. This function attempts to
24334 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
24335 to it or DW_AT_const_value attribute, if possible. */
24338 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
24340 if (TREE_CODE (decl
) != VAR_DECL
24341 || lookup_decl_die (decl
) != die
24342 || DECL_EXTERNAL (decl
)
24343 || !TREE_STATIC (decl
)
24344 || DECL_INITIAL (decl
) == NULL_TREE
24345 || DECL_P (DECL_INITIAL (decl
))
24346 || get_AT (die
, DW_AT_const_value
))
24349 tree init
= DECL_INITIAL (decl
);
24350 HOST_WIDE_INT offset
= 0;
24351 /* For variables that have been optimized away and thus
24352 don't have a memory location, see if we can emit
24353 DW_AT_const_value instead. */
24354 if (tree_add_const_value_attribute (die
, init
))
24358 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
24359 and ADDR_EXPR refers to a decl that has DW_AT_location or
24360 DW_AT_const_value (but isn't addressable, otherwise
24361 resolving the original DW_OP_addr wouldn't fail), see if
24362 we can add DW_OP_GNU_implicit_pointer. */
24364 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
24365 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
24367 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
24368 init
= TREE_OPERAND (init
, 0);
24371 if (TREE_CODE (init
) != ADDR_EXPR
)
24373 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
24374 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
24375 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
24376 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
24377 && TREE_OPERAND (init
, 0) != decl
))
24380 dw_loc_descr_ref l
;
24382 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
24384 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
24387 decl
= SYMBOL_REF_DECL (rtl
);
24390 decl
= TREE_OPERAND (init
, 0);
24391 ref
= lookup_decl_die (decl
);
24393 || (!get_AT (ref
, DW_AT_location
)
24394 && !get_AT (ref
, DW_AT_const_value
)))
24396 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
24397 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24398 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24399 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24400 add_AT_loc (die
, DW_AT_location
, l
);
24404 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24405 an address in .rodata section if the string literal is emitted there,
24406 or remove the containing location list or replace DW_AT_const_value
24407 with DW_AT_location and empty location expression, if it isn't found
24408 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24409 to something that has been emitted in the current CU. */
24412 resolve_addr (dw_die_ref die
)
24416 dw_loc_list_ref
*curr
, *start
, loc
;
24419 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24420 switch (AT_class (a
))
24422 case dw_val_class_loc_list
:
24423 start
= curr
= AT_loc_list_ptr (a
);
24426 /* The same list can be referenced more than once. See if we have
24427 already recorded the result from a previous pass. */
24429 *curr
= loc
->dw_loc_next
;
24430 else if (!loc
->resolved_addr
)
24432 /* As things stand, we do not expect or allow one die to
24433 reference a suffix of another die's location list chain.
24434 References must be identical or completely separate.
24435 There is therefore no need to cache the result of this
24436 pass on any list other than the first; doing so
24437 would lead to unnecessary writes. */
24440 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
24441 if (!resolve_addr_in_expr ((*curr
)->expr
))
24443 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
24444 dw_loc_descr_ref l
= (*curr
)->expr
;
24446 if (next
&& (*curr
)->ll_symbol
)
24448 gcc_assert (!next
->ll_symbol
);
24449 next
->ll_symbol
= (*curr
)->ll_symbol
;
24451 if (dwarf_split_debug_info
)
24452 remove_loc_list_addr_table_entries (l
);
24457 mark_base_types ((*curr
)->expr
);
24458 curr
= &(*curr
)->dw_loc_next
;
24462 loc
->resolved_addr
= 1;
24466 loc
->dw_loc_next
= *start
;
24471 remove_AT (die
, a
->dw_attr
);
24475 case dw_val_class_loc
:
24477 dw_loc_descr_ref l
= AT_loc (a
);
24478 /* For -gdwarf-2 don't attempt to optimize
24479 DW_AT_data_member_location containing
24480 DW_OP_plus_uconst - older consumers might
24481 rely on it being that op instead of a more complex,
24482 but shorter, location description. */
24483 if ((dwarf_version
> 2
24484 || a
->dw_attr
!= DW_AT_data_member_location
24486 || l
->dw_loc_opc
!= DW_OP_plus_uconst
24487 || l
->dw_loc_next
!= NULL
)
24488 && !resolve_addr_in_expr (l
))
24490 if (dwarf_split_debug_info
)
24491 remove_loc_list_addr_table_entries (l
);
24493 && l
->dw_loc_next
== NULL
24494 && l
->dw_loc_opc
== DW_OP_addr
24495 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
24496 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
24497 && a
->dw_attr
== DW_AT_location
)
24499 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
24500 remove_AT (die
, a
->dw_attr
);
24502 optimize_location_into_implicit_ptr (die
, decl
);
24505 remove_AT (die
, a
->dw_attr
);
24509 mark_base_types (l
);
24512 case dw_val_class_addr
:
24513 if (a
->dw_attr
== DW_AT_const_value
24514 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
24516 if (AT_index (a
) != NOT_INDEXED
)
24517 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24518 remove_AT (die
, a
->dw_attr
);
24521 if (die
->die_tag
== DW_TAG_GNU_call_site
24522 && a
->dw_attr
== DW_AT_abstract_origin
)
24524 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
24525 dw_die_ref tdie
= lookup_decl_die (tdecl
);
24528 && DECL_EXTERNAL (tdecl
)
24529 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
24530 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
24532 /* Creating a full DIE for tdecl is overly expensive and
24533 at this point even wrong when in the LTO phase
24534 as it can end up generating new type DIEs we didn't
24535 output and thus optimize_external_refs will crash. */
24536 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
24537 add_AT_flag (tdie
, DW_AT_external
, 1);
24538 add_AT_flag (tdie
, DW_AT_declaration
, 1);
24539 add_linkage_attr (tdie
, tdecl
);
24540 add_name_and_src_coords_attributes (tdie
, tdecl
);
24541 equate_decl_number_to_die (tdecl
, tdie
);
24545 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
24546 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
24547 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
24551 if (AT_index (a
) != NOT_INDEXED
)
24552 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24553 remove_AT (die
, a
->dw_attr
);
24562 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
24565 /* Helper routines for optimize_location_lists.
24566 This pass tries to share identical local lists in .debug_loc
24569 /* Iteratively hash operands of LOC opcode into HSTATE. */
24572 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24574 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
24575 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
24577 switch (loc
->dw_loc_opc
)
24579 case DW_OP_const4u
:
24580 case DW_OP_const8u
:
24584 case DW_OP_const1u
:
24585 case DW_OP_const1s
:
24586 case DW_OP_const2u
:
24587 case DW_OP_const2s
:
24588 case DW_OP_const4s
:
24589 case DW_OP_const8s
:
24593 case DW_OP_plus_uconst
:
24629 case DW_OP_deref_size
:
24630 case DW_OP_xderef_size
:
24631 hstate
.add_object (val1
->v
.val_int
);
24638 gcc_assert (val1
->val_class
== dw_val_class_loc
);
24639 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
24640 hstate
.add_object (offset
);
24643 case DW_OP_implicit_value
:
24644 hstate
.add_object (val1
->v
.val_unsigned
);
24645 switch (val2
->val_class
)
24647 case dw_val_class_const
:
24648 hstate
.add_object (val2
->v
.val_int
);
24650 case dw_val_class_vec
:
24652 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24653 unsigned int len
= val2
->v
.val_vec
.length
;
24655 hstate
.add_int (elt_size
);
24656 hstate
.add_int (len
);
24657 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24660 case dw_val_class_const_double
:
24661 hstate
.add_object (val2
->v
.val_double
.low
);
24662 hstate
.add_object (val2
->v
.val_double
.high
);
24664 case dw_val_class_wide_int
:
24665 hstate
.add (val2
->v
.val_wide
->get_val (),
24666 get_full_len (*val2
->v
.val_wide
)
24667 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24669 case dw_val_class_addr
:
24670 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
24673 gcc_unreachable ();
24677 case DW_OP_bit_piece
:
24678 hstate
.add_object (val1
->v
.val_int
);
24679 hstate
.add_object (val2
->v
.val_int
);
24685 unsigned char dtprel
= 0xd1;
24686 hstate
.add_object (dtprel
);
24688 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
24690 case DW_OP_GNU_addr_index
:
24691 case DW_OP_GNU_const_index
:
24695 unsigned char dtprel
= 0xd1;
24696 hstate
.add_object (dtprel
);
24698 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
24701 case DW_OP_GNU_implicit_pointer
:
24702 hstate
.add_int (val2
->v
.val_int
);
24704 case DW_OP_GNU_entry_value
:
24705 hstate
.add_object (val1
->v
.val_loc
);
24707 case DW_OP_GNU_regval_type
:
24708 case DW_OP_GNU_deref_type
:
24710 unsigned int byte_size
24711 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24712 unsigned int encoding
24713 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
24714 hstate
.add_object (val1
->v
.val_int
);
24715 hstate
.add_object (byte_size
);
24716 hstate
.add_object (encoding
);
24719 case DW_OP_GNU_convert
:
24720 case DW_OP_GNU_reinterpret
:
24721 if (val1
->val_class
== dw_val_class_unsigned_const
)
24723 hstate
.add_object (val1
->v
.val_unsigned
);
24727 case DW_OP_GNU_const_type
:
24729 unsigned int byte_size
24730 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24731 unsigned int encoding
24732 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
24733 hstate
.add_object (byte_size
);
24734 hstate
.add_object (encoding
);
24735 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
24737 hstate
.add_object (val2
->val_class
);
24738 switch (val2
->val_class
)
24740 case dw_val_class_const
:
24741 hstate
.add_object (val2
->v
.val_int
);
24743 case dw_val_class_vec
:
24745 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24746 unsigned int len
= val2
->v
.val_vec
.length
;
24748 hstate
.add_object (elt_size
);
24749 hstate
.add_object (len
);
24750 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24753 case dw_val_class_const_double
:
24754 hstate
.add_object (val2
->v
.val_double
.low
);
24755 hstate
.add_object (val2
->v
.val_double
.high
);
24757 case dw_val_class_wide_int
:
24758 hstate
.add (val2
->v
.val_wide
->get_val (),
24759 get_full_len (*val2
->v
.val_wide
)
24760 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24763 gcc_unreachable ();
24769 /* Other codes have no operands. */
24774 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
24777 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24779 dw_loc_descr_ref l
;
24780 bool sizes_computed
= false;
24781 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24782 size_of_locs (loc
);
24784 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
24786 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
24787 hstate
.add_object (opc
);
24788 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
24790 size_of_locs (loc
);
24791 sizes_computed
= true;
24793 hash_loc_operands (l
, hstate
);
24797 /* Compute hash of the whole location list LIST_HEAD. */
24800 hash_loc_list (dw_loc_list_ref list_head
)
24802 dw_loc_list_ref curr
= list_head
;
24803 inchash::hash hstate
;
24805 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24807 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
24808 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
24810 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
24811 hash_locs (curr
->expr
, hstate
);
24813 list_head
->hash
= hstate
.end ();
24816 /* Return true if X and Y opcodes have the same operands. */
24819 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24821 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
24822 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
24823 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
24824 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
24826 switch (x
->dw_loc_opc
)
24828 case DW_OP_const4u
:
24829 case DW_OP_const8u
:
24833 case DW_OP_const1u
:
24834 case DW_OP_const1s
:
24835 case DW_OP_const2u
:
24836 case DW_OP_const2s
:
24837 case DW_OP_const4s
:
24838 case DW_OP_const8s
:
24842 case DW_OP_plus_uconst
:
24878 case DW_OP_deref_size
:
24879 case DW_OP_xderef_size
:
24880 return valx1
->v
.val_int
== valy1
->v
.val_int
;
24883 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24884 can cause irrelevant differences in dw_loc_addr. */
24885 gcc_assert (valx1
->val_class
== dw_val_class_loc
24886 && valy1
->val_class
== dw_val_class_loc
24887 && (dwarf_split_debug_info
24888 || x
->dw_loc_addr
== y
->dw_loc_addr
));
24889 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
24890 case DW_OP_implicit_value
:
24891 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
24892 || valx2
->val_class
!= valy2
->val_class
)
24894 switch (valx2
->val_class
)
24896 case dw_val_class_const
:
24897 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24898 case dw_val_class_vec
:
24899 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24900 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24901 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24902 valx2
->v
.val_vec
.elt_size
24903 * valx2
->v
.val_vec
.length
) == 0;
24904 case dw_val_class_const_double
:
24905 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24906 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24907 case dw_val_class_wide_int
:
24908 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24909 case dw_val_class_addr
:
24910 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
24912 gcc_unreachable ();
24915 case DW_OP_bit_piece
:
24916 return valx1
->v
.val_int
== valy1
->v
.val_int
24917 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24920 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
24921 case DW_OP_GNU_addr_index
:
24922 case DW_OP_GNU_const_index
:
24924 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
24925 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
24926 return rtx_equal_p (ax1
, ay1
);
24928 case DW_OP_GNU_implicit_pointer
:
24929 return valx1
->val_class
== dw_val_class_die_ref
24930 && valx1
->val_class
== valy1
->val_class
24931 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
24932 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24933 case DW_OP_GNU_entry_value
:
24934 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
24935 case DW_OP_GNU_const_type
:
24936 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
24937 || valx2
->val_class
!= valy2
->val_class
)
24939 switch (valx2
->val_class
)
24941 case dw_val_class_const
:
24942 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24943 case dw_val_class_vec
:
24944 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24945 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24946 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24947 valx2
->v
.val_vec
.elt_size
24948 * valx2
->v
.val_vec
.length
) == 0;
24949 case dw_val_class_const_double
:
24950 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24951 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24952 case dw_val_class_wide_int
:
24953 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24955 gcc_unreachable ();
24957 case DW_OP_GNU_regval_type
:
24958 case DW_OP_GNU_deref_type
:
24959 return valx1
->v
.val_int
== valy1
->v
.val_int
24960 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
24961 case DW_OP_GNU_convert
:
24962 case DW_OP_GNU_reinterpret
:
24963 if (valx1
->val_class
!= valy1
->val_class
)
24965 if (valx1
->val_class
== dw_val_class_unsigned_const
)
24966 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
24967 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24968 case DW_OP_GNU_parameter_ref
:
24969 return valx1
->val_class
== dw_val_class_die_ref
24970 && valx1
->val_class
== valy1
->val_class
24971 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24973 /* Other codes have no operands. */
24978 /* Return true if DWARF location expressions X and Y are the same. */
24981 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24983 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
24984 if (x
->dw_loc_opc
!= y
->dw_loc_opc
24985 || x
->dtprel
!= y
->dtprel
24986 || !compare_loc_operands (x
, y
))
24988 return x
== NULL
&& y
== NULL
;
24991 /* Hashtable helpers. */
24993 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
24995 typedef dw_loc_list_struct
*value_type
;
24996 typedef dw_loc_list_struct
*compare_type
;
24997 static inline hashval_t
hash (const dw_loc_list_struct
*);
24998 static inline bool equal (const dw_loc_list_struct
*,
24999 const dw_loc_list_struct
*);
25002 /* Return precomputed hash of location list X. */
25005 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
25010 /* Return true if location lists A and B are the same. */
25013 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
25014 const dw_loc_list_struct
*b
)
25018 if (a
->hash
!= b
->hash
)
25020 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
25021 if (strcmp (a
->begin
, b
->begin
) != 0
25022 || strcmp (a
->end
, b
->end
) != 0
25023 || (a
->section
== NULL
) != (b
->section
== NULL
)
25024 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
25025 || !compare_locs (a
->expr
, b
->expr
))
25027 return a
== NULL
&& b
== NULL
;
25030 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
25033 /* Recursively optimize location lists referenced from DIE
25034 children and share them whenever possible. */
25037 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
25042 dw_loc_list_struct
**slot
;
25044 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25045 if (AT_class (a
) == dw_val_class_loc_list
)
25047 dw_loc_list_ref list
= AT_loc_list (a
);
25048 /* TODO: perform some optimizations here, before hashing
25049 it and storing into the hash table. */
25050 hash_loc_list (list
);
25051 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
25055 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
25058 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
25062 /* Recursively assign each location list a unique index into the debug_addr
25066 index_location_lists (dw_die_ref die
)
25072 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25073 if (AT_class (a
) == dw_val_class_loc_list
)
25075 dw_loc_list_ref list
= AT_loc_list (a
);
25076 dw_loc_list_ref curr
;
25077 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
25079 /* Don't index an entry that has already been indexed
25080 or won't be output. */
25081 if (curr
->begin_entry
!= NULL
25082 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
25086 = add_addr_table_entry (xstrdup (curr
->begin
),
25091 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
25094 /* Optimize location lists referenced from DIE
25095 children and share them whenever possible. */
25098 optimize_location_lists (dw_die_ref die
)
25100 loc_list_hash_type
htab (500);
25101 optimize_location_lists_1 (die
, &htab
);
25104 /* Output stuff that dwarf requires at the end of every file,
25105 and generate the DWARF-2 debugging info. */
25108 dwarf2out_finish (const char *filename
)
25110 comdat_type_node
*ctnode
;
25111 dw_die_ref main_comp_unit_die
;
25113 /* Flush out any latecomers to the limbo party. */
25114 dwarf2out_early_finish ();
25116 /* PCH might result in DW_AT_producer string being restored from the
25117 header compilation, so always fill it with empty string initially
25118 and overwrite only here. */
25119 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
25120 producer_string
= gen_producer_string ();
25121 producer
->dw_attr_val
.v
.val_str
->refcount
--;
25122 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
25124 gen_scheduled_generic_parms_dies ();
25125 gen_remaining_tmpl_value_param_die_attribute ();
25127 /* Add the name for the main input file now. We delayed this from
25128 dwarf2out_init to avoid complications with PCH.
25129 For LTO produced units use a fixed artificial name to avoid
25130 leaking tempfile names into the dwarf. */
25132 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
25134 add_name_attribute (comp_unit_die (), "<artificial>");
25135 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
25136 add_comp_dir_attribute (comp_unit_die ());
25137 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
25140 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
25142 add_comp_dir_attribute (comp_unit_die ());
25145 #if ENABLE_ASSERT_CHECKING
25147 dw_die_ref die
= comp_unit_die (), c
;
25148 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
25151 resolve_addr (comp_unit_die ());
25152 move_marked_base_types ();
25154 /* Walk through the list of incomplete types again, trying once more to
25155 emit full debugging info for them. */
25156 retry_incomplete_types ();
25158 if (flag_eliminate_unused_debug_types
)
25159 prune_unused_types ();
25161 /* Generate separate COMDAT sections for type DIEs. */
25162 if (use_debug_types
)
25164 break_out_comdat_types (comp_unit_die ());
25166 /* Each new type_unit DIE was added to the limbo die list when created.
25167 Since these have all been added to comdat_type_list, clear the
25169 limbo_die_list
= NULL
;
25171 /* For each new comdat type unit, copy declarations for incomplete
25172 types to make the new unit self-contained (i.e., no direct
25173 references to the main compile unit). */
25174 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25175 copy_decls_for_unworthy_types (ctnode
->root_die
);
25176 copy_decls_for_unworthy_types (comp_unit_die ());
25178 /* In the process of copying declarations from one unit to another,
25179 we may have left some declarations behind that are no longer
25180 referenced. Prune them. */
25181 prune_unused_types ();
25184 /* Generate separate CUs for each of the include files we've seen.
25185 They will go into limbo_die_list. */
25186 if (flag_eliminate_dwarf2_dups
)
25187 break_out_includes (comp_unit_die ());
25189 /* Traverse the DIE's and add add sibling attributes to those DIE's
25190 that have children. */
25191 add_sibling_attributes (comp_unit_die ());
25192 limbo_die_node
*node
;
25193 for (node
= limbo_die_list
; node
; node
= node
->next
)
25194 add_sibling_attributes (node
->die
);
25195 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25196 add_sibling_attributes (ctnode
->root_die
);
25198 /* When splitting DWARF info, we put some attributes in the
25199 skeleton compile_unit DIE that remains in the .o, while
25200 most attributes go in the DWO compile_unit_die. */
25201 if (dwarf_split_debug_info
)
25202 main_comp_unit_die
= gen_compile_unit_die (NULL
);
25204 main_comp_unit_die
= comp_unit_die ();
25206 /* Output a terminator label for the .text section. */
25207 switch_to_section (text_section
);
25208 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
25209 if (cold_text_section
)
25211 switch_to_section (cold_text_section
);
25212 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
25215 /* We can only use the low/high_pc attributes if all of the code was
25217 if (!have_multiple_function_sections
25218 || (dwarf_version
< 3 && dwarf_strict
))
25220 /* Don't add if the CU has no associated code. */
25221 if (text_section_used
)
25222 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
25223 text_end_label
, true);
25229 bool range_list_added
= false;
25231 if (text_section_used
)
25232 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
25233 text_end_label
, &range_list_added
, true);
25234 if (cold_text_section_used
)
25235 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
25236 cold_end_label
, &range_list_added
, true);
25238 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
25240 if (DECL_IGNORED_P (fde
->decl
))
25242 if (!fde
->in_std_section
)
25243 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
25244 fde
->dw_fde_end
, &range_list_added
,
25246 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
25247 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
25248 fde
->dw_fde_second_end
, &range_list_added
,
25252 if (range_list_added
)
25254 /* We need to give .debug_loc and .debug_ranges an appropriate
25255 "base address". Use zero so that these addresses become
25256 absolute. Historically, we've emitted the unexpected
25257 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25258 Emit both to give time for other tools to adapt. */
25259 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
25260 if (! dwarf_strict
&& dwarf_version
< 4)
25261 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
25267 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25268 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
25269 debug_line_section_label
);
25272 add_AT_macptr (comp_unit_die (),
25273 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
25274 macinfo_section_label
);
25276 if (dwarf_split_debug_info
)
25278 /* optimize_location_lists calculates the size of the lists,
25279 so index them first, and assign indices to the entries.
25280 Although optimize_location_lists will remove entries from
25281 the table, it only does so for duplicates, and therefore
25282 only reduces ref_counts to 1. */
25283 index_location_lists (comp_unit_die ());
25285 if (addr_index_table
!= NULL
)
25287 unsigned int index
= 0;
25289 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
25294 if (have_location_lists
)
25295 optimize_location_lists (comp_unit_die ());
25297 save_macinfo_strings ();
25299 if (dwarf_split_debug_info
)
25301 unsigned int index
= 0;
25303 /* Add attributes common to skeleton compile_units and
25304 type_units. Because these attributes include strings, it
25305 must be done before freezing the string table. Top-level
25306 skeleton die attrs are added when the skeleton type unit is
25307 created, so ensure it is created by this point. */
25308 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
25309 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
25312 /* Output all of the compilation units. We put the main one last so that
25313 the offsets are available to output_pubnames. */
25314 for (node
= limbo_die_list
; node
; node
= node
->next
)
25315 output_comp_unit (node
->die
, 0);
25317 hash_table
<comdat_type_hasher
> comdat_type_table (100);
25318 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25320 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
25322 /* Don't output duplicate types. */
25323 if (*slot
!= HTAB_EMPTY_ENTRY
)
25326 /* Add a pointer to the line table for the main compilation unit
25327 so that the debugger can make sense of DW_AT_decl_file
25329 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25330 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
25331 (!dwarf_split_debug_info
25332 ? debug_line_section_label
25333 : debug_skeleton_line_section_label
));
25335 output_comdat_type_unit (ctnode
);
25339 /* The AT_pubnames attribute needs to go in all skeleton dies, including
25340 both the main_cu and all skeleton TUs. Making this call unconditional
25341 would end up either adding a second copy of the AT_pubnames attribute, or
25342 requiring a special case in add_top_level_skeleton_die_attrs. */
25343 if (!dwarf_split_debug_info
)
25344 add_AT_pubnames (comp_unit_die ());
25346 if (dwarf_split_debug_info
)
25349 unsigned char checksum
[16];
25350 struct md5_ctx ctx
;
25352 /* Compute a checksum of the comp_unit to use as the dwo_id. */
25353 md5_init_ctx (&ctx
);
25355 die_checksum (comp_unit_die (), &ctx
, &mark
);
25356 unmark_all_dies (comp_unit_die ());
25357 md5_finish_ctx (&ctx
, checksum
);
25359 /* Use the first 8 bytes of the checksum as the dwo_id,
25360 and add it to both comp-unit DIEs. */
25361 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
25362 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
25364 /* Add the base offset of the ranges table to the skeleton
25366 if (ranges_table_in_use
)
25367 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
25368 ranges_section_label
);
25370 switch_to_section (debug_addr_section
);
25371 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
25372 output_addr_table ();
25375 /* Output the main compilation unit if non-empty or if .debug_macinfo
25376 or .debug_macro will be emitted. */
25377 output_comp_unit (comp_unit_die (), have_macinfo
);
25379 if (dwarf_split_debug_info
&& info_section_emitted
)
25380 output_skeleton_debug_sections (main_comp_unit_die
);
25382 /* Output the abbreviation table. */
25383 if (abbrev_die_table_in_use
!= 1)
25385 switch_to_section (debug_abbrev_section
);
25386 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
25387 output_abbrev_section ();
25390 /* Output location list section if necessary. */
25391 if (have_location_lists
)
25393 /* Output the location lists info. */
25394 switch_to_section (debug_loc_section
);
25395 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
25396 output_location_lists (comp_unit_die ());
25399 output_pubtables ();
25401 /* Output the address range information if a CU (.debug_info section)
25402 was emitted. We output an empty table even if we had no functions
25403 to put in it. This because the consumer has no way to tell the
25404 difference between an empty table that we omitted and failure to
25405 generate a table that would have contained data. */
25406 if (info_section_emitted
)
25408 unsigned long aranges_length
= size_of_aranges ();
25410 switch_to_section (debug_aranges_section
);
25411 output_aranges (aranges_length
);
25414 /* Output ranges section if necessary. */
25415 if (ranges_table_in_use
)
25417 switch_to_section (debug_ranges_section
);
25418 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
25422 /* Have to end the macro section. */
25425 switch_to_section (debug_macinfo_section
);
25426 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
25428 dw2_asm_output_data (1, 0, "End compilation unit");
25431 /* Output the source line correspondence table. We must do this
25432 even if there is no line information. Otherwise, on an empty
25433 translation unit, we will generate a present, but empty,
25434 .debug_info section. IRIX 6.5 `nm' will then complain when
25435 examining the file. This is done late so that any filenames
25436 used by the debug_info section are marked as 'used'. */
25437 switch_to_section (debug_line_section
);
25438 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
25439 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
25440 output_line_info (false);
25442 if (dwarf_split_debug_info
&& info_section_emitted
)
25444 switch_to_section (debug_skeleton_line_section
);
25445 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
25446 output_line_info (true);
25449 /* If we emitted any indirect strings, output the string table too. */
25450 if (debug_str_hash
|| skeleton_debug_str_hash
)
25451 output_indirect_strings ();
25454 /* Perform any cleanups needed after the early debug generation pass
25458 dwarf2out_early_finish (void)
25460 limbo_die_node
*node
, *next_node
;
25462 /* Add DW_AT_linkage_name for all deferred DIEs. */
25463 for (node
= deferred_asm_name
; node
; node
= node
->next
)
25465 tree decl
= node
->created_for
;
25466 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
25467 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
25468 ended up in in deferred_asm_name before we knew it was
25469 constant and never written to disk. */
25470 && DECL_ASSEMBLER_NAME (decl
))
25472 add_linkage_attr (node
->die
, decl
);
25473 move_linkage_attr (node
->die
);
25476 deferred_asm_name
= NULL
;
25478 /* Traverse the limbo die list, and add parent/child links. The only
25479 dies without parents that should be here are concrete instances of
25480 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25481 For concrete instances, we can get the parent die from the abstract
25484 The point here is to flush out the limbo list so that it is empty
25485 and we don't need to stream it for LTO. */
25486 for (node
= limbo_die_list
; node
; node
= next_node
)
25488 dw_die_ref die
= node
->die
;
25489 next_node
= node
->next
;
25491 if (die
->die_parent
== NULL
)
25493 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
25495 if (origin
&& origin
->die_parent
)
25496 add_child_die (origin
->die_parent
, die
);
25497 else if (is_cu_die (die
))
25499 else if (seen_error ())
25500 /* It's OK to be confused by errors in the input. */
25501 add_child_die (comp_unit_die (), die
);
25504 /* In certain situations, the lexical block containing a
25505 nested function can be optimized away, which results
25506 in the nested function die being orphaned. Likewise
25507 with the return type of that nested function. Force
25508 this to be a child of the containing function.
25510 It may happen that even the containing function got fully
25511 inlined and optimized out. In that case we are lost and
25512 assign the empty child. This should not be big issue as
25513 the function is likely unreachable too. */
25514 gcc_assert (node
->created_for
);
25516 if (DECL_P (node
->created_for
))
25517 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
25518 else if (TYPE_P (node
->created_for
))
25519 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
25521 origin
= comp_unit_die ();
25523 add_child_die (origin
, die
);
25528 limbo_die_list
= NULL
;
25531 /* Reset all state within dwarf2out.c so that we can rerun the compiler
25532 within the same process. For use by toplev::finalize. */
25535 dwarf2out_c_finalize (void)
25537 last_var_location_insn
= NULL
;
25538 cached_next_real_insn
= NULL
;
25539 used_rtx_array
= NULL
;
25540 incomplete_types
= NULL
;
25541 decl_scope_table
= NULL
;
25542 debug_info_section
= NULL
;
25543 debug_skeleton_info_section
= NULL
;
25544 debug_abbrev_section
= NULL
;
25545 debug_skeleton_abbrev_section
= NULL
;
25546 debug_aranges_section
= NULL
;
25547 debug_addr_section
= NULL
;
25548 debug_macinfo_section
= NULL
;
25549 debug_line_section
= NULL
;
25550 debug_skeleton_line_section
= NULL
;
25551 debug_loc_section
= NULL
;
25552 debug_pubnames_section
= NULL
;
25553 debug_pubtypes_section
= NULL
;
25554 debug_str_section
= NULL
;
25555 debug_str_dwo_section
= NULL
;
25556 debug_str_offsets_section
= NULL
;
25557 debug_ranges_section
= NULL
;
25558 debug_frame_section
= NULL
;
25560 debug_str_hash
= NULL
;
25561 skeleton_debug_str_hash
= NULL
;
25562 dw2_string_counter
= 0;
25563 have_multiple_function_sections
= false;
25564 text_section_used
= false;
25565 cold_text_section_used
= false;
25566 cold_text_section
= NULL
;
25567 current_unit_personality
= NULL
;
25569 next_die_offset
= 0;
25570 single_comp_unit_die
= NULL
;
25571 comdat_type_list
= NULL
;
25572 limbo_die_list
= NULL
;
25574 decl_die_table
= NULL
;
25575 common_block_die_table
= NULL
;
25576 decl_loc_table
= NULL
;
25577 call_arg_locations
= NULL
;
25578 call_arg_loc_last
= NULL
;
25579 call_site_count
= -1;
25580 tail_call_site_count
= -1;
25581 cached_dw_loc_list_table
= NULL
;
25582 abbrev_die_table
= NULL
;
25583 abbrev_die_table_allocated
= 0;
25584 abbrev_die_table_in_use
= 0;
25585 line_info_label_num
= 0;
25586 cur_line_info_table
= NULL
;
25587 text_section_line_info
= NULL
;
25588 cold_text_section_line_info
= NULL
;
25589 separate_line_info
= NULL
;
25590 info_section_emitted
= false;
25591 pubname_table
= NULL
;
25592 pubtype_table
= NULL
;
25593 macinfo_table
= NULL
;
25594 ranges_table
= NULL
;
25595 ranges_table_allocated
= 0;
25596 ranges_table_in_use
= 0;
25597 ranges_by_label
= 0;
25598 ranges_by_label_allocated
= 0;
25599 ranges_by_label_in_use
= 0;
25600 have_location_lists
= false;
25603 last_emitted_file
= NULL
;
25605 tmpl_value_parm_die_table
= NULL
;
25606 generic_type_instances
= NULL
;
25607 frame_pointer_fb_offset
= 0;
25608 frame_pointer_fb_offset_valid
= false;
25609 base_types
.release ();
25610 XDELETEVEC (producer_string
);
25611 producer_string
= NULL
;
25614 #include "gt-dwarf2out.h"