1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2014 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
64 #include "stringpool.h"
65 #include "stor-layout.h"
69 #include "hash-table.h"
72 #include "hard-reg-set.h"
74 #include "insn-config.h"
81 #include "dwarf2out.h"
82 #include "dwarf2asm.h"
86 #include "diagnostic.h"
87 #include "tree-pretty-print.h"
90 #include "common/common-target.h"
91 #include "langhooks.h"
99 #include "gdb/gdb-index.h"
101 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
102 static rtx last_var_location_insn
;
103 static rtx cached_next_real_insn
;
105 #ifdef VMS_DEBUGGING_INFO
106 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
108 /* Define this macro to be a nonzero value if the directory specifications
109 which are output in the debug info should end with a separator. */
110 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
111 /* Define this macro to evaluate to a nonzero value if GCC should refrain
112 from generating indirect strings in DWARF2 debug information, for instance
113 if your target is stuck with an old version of GDB that is unable to
114 process them properly or uses VMS Debug. */
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
117 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
118 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
121 /* ??? Poison these here until it can be done generically. They've been
122 totally replaced in this file; make sure it stays that way. */
123 #undef DWARF2_UNWIND_INFO
124 #undef DWARF2_FRAME_INFO
125 #if (GCC_VERSION >= 3000)
126 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
129 /* The size of the target's pointer type. */
131 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
134 /* Array of RTXes referenced by the debugging information, which therefore
135 must be kept around forever. */
136 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
138 /* A pointer to the base of a list of incomplete types which might be
139 completed at some later time. incomplete_types_list needs to be a
140 vec<tree, va_gc> *because we want to tell the garbage collector about
142 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
144 /* A pointer to the base of a table of references to declaration
145 scopes. This table is a display which tracks the nesting
146 of declaration scopes at the current scope and containing
147 scopes. This table is used to find the proper place to
148 define type declaration DIE's. */
149 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
151 /* Pointers to various DWARF2 sections. */
152 static GTY(()) section
*debug_info_section
;
153 static GTY(()) section
*debug_skeleton_info_section
;
154 static GTY(()) section
*debug_abbrev_section
;
155 static GTY(()) section
*debug_skeleton_abbrev_section
;
156 static GTY(()) section
*debug_aranges_section
;
157 static GTY(()) section
*debug_addr_section
;
158 static GTY(()) section
*debug_macinfo_section
;
159 static GTY(()) section
*debug_line_section
;
160 static GTY(()) section
*debug_skeleton_line_section
;
161 static GTY(()) section
*debug_loc_section
;
162 static GTY(()) section
*debug_pubnames_section
;
163 static GTY(()) section
*debug_pubtypes_section
;
164 static GTY(()) section
*debug_str_section
;
165 static GTY(()) section
*debug_str_dwo_section
;
166 static GTY(()) section
*debug_str_offsets_section
;
167 static GTY(()) section
*debug_ranges_section
;
168 static GTY(()) section
*debug_frame_section
;
170 /* Maximum size (in bytes) of an artificially generated label. */
171 #define MAX_ARTIFICIAL_LABEL_BYTES 30
173 /* According to the (draft) DWARF 3 specification, the initial length
174 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
175 bytes are 0xffffffff, followed by the length stored in the next 8
178 However, the SGI/MIPS ABI uses an initial length which is equal to
179 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
181 #ifndef DWARF_INITIAL_LENGTH_SIZE
182 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
185 /* Round SIZE up to the nearest BOUNDARY. */
186 #define DWARF_ROUND(SIZE,BOUNDARY) \
187 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
189 /* CIE identifier. */
190 #if HOST_BITS_PER_WIDE_INT >= 64
191 #define DWARF_CIE_ID \
192 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
194 #define DWARF_CIE_ID DW_CIE_ID
198 /* A vector for a table that contains frame description
199 information for each routine. */
200 #define NOT_INDEXED (-1U)
201 #define NO_INDEX_ASSIGNED (-2U)
203 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
205 struct GTY(()) indirect_string_node
{
207 unsigned int refcount
;
208 enum dwarf_form form
;
213 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
215 /* With split_debug_info, both the comp_dir and dwo_name go in the
216 main object file, rather than the dwo, similar to the force_direct
217 parameter elsewhere but with additional complications:
219 1) The string is needed in both the main object file and the dwo.
220 That is, the comp_dir and dwo_name will appear in both places.
222 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
223 DW_FORM_GNU_str_index.
225 3) GCC chooses the form to use late, depending on the size and
228 Rather than forcing the all debug string handling functions and
229 callers to deal with these complications, simply use a separate,
230 special-cased string table for any attribute that should go in the
231 main object file. This limits the complexity to just the places
234 static GTY ((param_is (struct indirect_string_node
)))
235 htab_t skeleton_debug_str_hash
;
237 static GTY(()) int dw2_string_counter
;
239 /* True if the compilation unit places functions in more than one section. */
240 static GTY(()) bool have_multiple_function_sections
= false;
242 /* Whether the default text and cold text sections have been used at all. */
244 static GTY(()) bool text_section_used
= false;
245 static GTY(()) bool cold_text_section_used
= false;
247 /* The default cold text section. */
248 static GTY(()) section
*cold_text_section
;
250 /* The DIE for C++1y 'auto' in a function return type. */
251 static GTY(()) dw_die_ref auto_die
;
253 /* The DIE for C++1y 'decltype(auto)' in a function return type. */
254 static GTY(()) dw_die_ref decltype_auto_die
;
256 /* Forward declarations for functions defined in this file. */
258 static char *stripattributes (const char *);
259 static void output_call_frame_info (int);
260 static void dwarf2out_note_section_used (void);
262 /* Personality decl of current unit. Used only when assembler does not support
264 static GTY(()) rtx current_unit_personality
;
266 /* Data and reference forms for relocatable data. */
267 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
268 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
270 #ifndef DEBUG_FRAME_SECTION
271 #define DEBUG_FRAME_SECTION ".debug_frame"
274 #ifndef FUNC_BEGIN_LABEL
275 #define FUNC_BEGIN_LABEL "LFB"
278 #ifndef FUNC_END_LABEL
279 #define FUNC_END_LABEL "LFE"
282 #ifndef PROLOGUE_END_LABEL
283 #define PROLOGUE_END_LABEL "LPE"
286 #ifndef EPILOGUE_BEGIN_LABEL
287 #define EPILOGUE_BEGIN_LABEL "LEB"
290 #ifndef FRAME_BEGIN_LABEL
291 #define FRAME_BEGIN_LABEL "Lframe"
293 #define CIE_AFTER_SIZE_LABEL "LSCIE"
294 #define CIE_END_LABEL "LECIE"
295 #define FDE_LABEL "LSFDE"
296 #define FDE_AFTER_SIZE_LABEL "LASFDE"
297 #define FDE_END_LABEL "LEFDE"
298 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
299 #define LINE_NUMBER_END_LABEL "LELT"
300 #define LN_PROLOG_AS_LABEL "LASLTP"
301 #define LN_PROLOG_END_LABEL "LELTP"
302 #define DIE_LABEL_PREFIX "DW"
304 /* Match the base name of a file to the base name of a compilation unit. */
307 matches_main_base (const char *path
)
309 /* Cache the last query. */
310 static const char *last_path
= NULL
;
311 static int last_match
= 0;
312 if (path
!= last_path
)
315 int length
= base_of_path (path
, &base
);
317 last_match
= (length
== main_input_baselength
318 && memcmp (base
, main_input_basename
, length
) == 0);
323 #ifdef DEBUG_DEBUG_STRUCT
326 dump_struct_debug (tree type
, enum debug_info_usage usage
,
327 enum debug_struct_file criterion
, int generic
,
328 int matches
, int result
)
330 /* Find the type name. */
331 tree type_decl
= TYPE_STUB_DECL (type
);
333 const char *name
= 0;
334 if (TREE_CODE (t
) == TYPE_DECL
)
337 name
= IDENTIFIER_POINTER (t
);
339 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
341 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
342 matches
? "bas" : "hdr",
343 generic
? "gen" : "ord",
344 usage
== DINFO_USAGE_DFN
? ";" :
345 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
347 (void*) type_decl
, name
);
350 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
351 dump_struct_debug (type, usage, criterion, generic, matches, result)
355 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
361 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
363 enum debug_struct_file criterion
;
365 bool generic
= lang_hooks
.types
.generic_p (type
);
368 criterion
= debug_struct_generic
[usage
];
370 criterion
= debug_struct_ordinary
[usage
];
372 if (criterion
== DINFO_STRUCT_FILE_NONE
)
373 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
374 if (criterion
== DINFO_STRUCT_FILE_ANY
)
375 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
377 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
379 if (type_decl
!= NULL
)
381 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
382 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
384 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
385 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
388 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
391 /* Return a pointer to a copy of the section string name S with all
392 attributes stripped off, and an asterisk prepended (for assemble_name). */
395 stripattributes (const char *s
)
397 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
402 while (*s
&& *s
!= ',')
409 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
410 switch to the data section instead, and write out a synthetic start label
411 for collect2 the first time around. */
414 switch_to_eh_frame_section (bool back
)
418 #ifdef EH_FRAME_SECTION_NAME
419 if (eh_frame_section
== 0)
423 if (EH_TABLES_CAN_BE_READ_ONLY
)
429 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
431 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
433 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
436 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
437 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
438 && (per_encoding
& 0x70) != DW_EH_PE_absptr
439 && (per_encoding
& 0x70) != DW_EH_PE_aligned
440 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
441 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
442 ? 0 : SECTION_WRITE
);
445 flags
= SECTION_WRITE
;
446 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
448 #endif /* EH_FRAME_SECTION_NAME */
450 if (eh_frame_section
)
451 switch_to_section (eh_frame_section
);
454 /* We have no special eh_frame section. Put the information in
455 the data section and emit special labels to guide collect2. */
456 switch_to_section (data_section
);
460 label
= get_file_function_name ("F");
461 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
462 targetm
.asm_out
.globalize_label (asm_out_file
,
463 IDENTIFIER_POINTER (label
));
464 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
469 /* Switch [BACK] to the eh or debug frame table section, depending on
473 switch_to_frame_table_section (int for_eh
, bool back
)
476 switch_to_eh_frame_section (back
);
479 if (!debug_frame_section
)
480 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
481 SECTION_DEBUG
, NULL
);
482 switch_to_section (debug_frame_section
);
486 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
488 enum dw_cfi_oprnd_type
489 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
494 case DW_CFA_GNU_window_save
:
495 case DW_CFA_remember_state
:
496 case DW_CFA_restore_state
:
497 return dw_cfi_oprnd_unused
;
500 case DW_CFA_advance_loc1
:
501 case DW_CFA_advance_loc2
:
502 case DW_CFA_advance_loc4
:
503 case DW_CFA_MIPS_advance_loc8
:
504 return dw_cfi_oprnd_addr
;
507 case DW_CFA_offset_extended
:
509 case DW_CFA_offset_extended_sf
:
510 case DW_CFA_def_cfa_sf
:
512 case DW_CFA_restore_extended
:
513 case DW_CFA_undefined
:
514 case DW_CFA_same_value
:
515 case DW_CFA_def_cfa_register
:
516 case DW_CFA_register
:
517 case DW_CFA_expression
:
518 return dw_cfi_oprnd_reg_num
;
520 case DW_CFA_def_cfa_offset
:
521 case DW_CFA_GNU_args_size
:
522 case DW_CFA_def_cfa_offset_sf
:
523 return dw_cfi_oprnd_offset
;
525 case DW_CFA_def_cfa_expression
:
526 return dw_cfi_oprnd_loc
;
533 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
535 enum dw_cfi_oprnd_type
536 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
541 case DW_CFA_def_cfa_sf
:
543 case DW_CFA_offset_extended_sf
:
544 case DW_CFA_offset_extended
:
545 return dw_cfi_oprnd_offset
;
547 case DW_CFA_register
:
548 return dw_cfi_oprnd_reg_num
;
550 case DW_CFA_expression
:
551 return dw_cfi_oprnd_loc
;
554 return dw_cfi_oprnd_unused
;
558 /* Output one FDE. */
561 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
562 char *section_start_label
, int fde_encoding
, char *augmentation
,
563 bool any_lsda_needed
, int lsda_encoding
)
565 const char *begin
, *end
;
566 static unsigned int j
;
569 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
571 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
573 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
574 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
575 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
576 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
577 " indicating 64-bit DWARF extension");
578 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
580 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
583 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
585 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
586 debug_frame_section
, "FDE CIE offset");
588 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
589 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
593 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
594 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
595 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
596 "FDE initial location");
597 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
598 end
, begin
, "FDE address range");
602 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
603 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
610 int size
= size_of_encoded_value (lsda_encoding
);
612 if (lsda_encoding
== DW_EH_PE_aligned
)
614 int offset
= ( 4 /* Length */
616 + 2 * size_of_encoded_value (fde_encoding
)
617 + 1 /* Augmentation size */ );
618 int pad
= -offset
& (PTR_SIZE
- 1);
621 gcc_assert (size_of_uleb128 (size
) == 1);
624 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
626 if (fde
->uses_eh_lsda
)
628 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
629 fde
->funcdef_number
);
630 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
631 gen_rtx_SYMBOL_REF (Pmode
, l1
),
633 "Language Specific Data Area");
637 if (lsda_encoding
== DW_EH_PE_aligned
)
638 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
639 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
640 "Language Specific Data Area (none)");
644 dw2_asm_output_data_uleb128 (0, "Augmentation size");
647 /* Loop through the Call Frame Instructions associated with this FDE. */
648 fde
->dw_fde_current_label
= begin
;
650 size_t from
, until
, i
;
653 until
= vec_safe_length (fde
->dw_fde_cfi
);
655 if (fde
->dw_fde_second_begin
== NULL
)
658 until
= fde
->dw_fde_switch_cfi_index
;
660 from
= fde
->dw_fde_switch_cfi_index
;
662 for (i
= from
; i
< until
; i
++)
663 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
666 /* If we are to emit a ref/link from function bodies to their frame tables,
667 do it now. This is typically performed to make sure that tables
668 associated with functions are dragged with them and not discarded in
669 garbage collecting links. We need to do this on a per function basis to
670 cope with -ffunction-sections. */
672 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
673 /* Switch to the function section, emit the ref to the tables, and
674 switch *back* into the table section. */
675 switch_to_section (function_section (fde
->decl
));
676 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
677 switch_to_frame_table_section (for_eh
, true);
680 /* Pad the FDE out to an address sized boundary. */
681 ASM_OUTPUT_ALIGN (asm_out_file
,
682 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
683 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
688 /* Return true if frame description entry FDE is needed for EH. */
691 fde_needed_for_eh_p (dw_fde_ref fde
)
693 if (flag_asynchronous_unwind_tables
)
696 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
699 if (fde
->uses_eh_lsda
)
702 /* If exceptions are enabled, we have collected nothrow info. */
703 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
709 /* Output the call frame information used to record information
710 that relates to calculating the frame pointer, and records the
711 location of saved registers. */
714 output_call_frame_info (int for_eh
)
719 char l1
[20], l2
[20], section_start_label
[20];
720 bool any_lsda_needed
= false;
721 char augmentation
[6];
722 int augmentation_size
;
723 int fde_encoding
= DW_EH_PE_absptr
;
724 int per_encoding
= DW_EH_PE_absptr
;
725 int lsda_encoding
= DW_EH_PE_absptr
;
727 rtx personality
= NULL
;
730 /* Don't emit a CIE if there won't be any FDEs. */
734 /* Nothing to do if the assembler's doing it all. */
735 if (dwarf2out_do_cfi_asm ())
738 /* If we don't have any functions we'll want to unwind out of, don't emit
739 any EH unwind information. If we make FDEs linkonce, we may have to
740 emit an empty label for an FDE that wouldn't otherwise be emitted. We
741 want to avoid having an FDE kept around when the function it refers to
742 is discarded. Example where this matters: a primary function template
743 in C++ requires EH information, an explicit specialization doesn't. */
746 bool any_eh_needed
= false;
748 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
750 if (fde
->uses_eh_lsda
)
751 any_eh_needed
= any_lsda_needed
= true;
752 else if (fde_needed_for_eh_p (fde
))
753 any_eh_needed
= true;
754 else if (TARGET_USES_WEAK_UNWIND_INFO
)
755 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
762 /* We're going to be generating comments, so turn on app. */
766 /* Switch to the proper frame section, first time. */
767 switch_to_frame_table_section (for_eh
, false);
769 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
770 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
772 /* Output the CIE. */
773 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
774 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
775 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
776 dw2_asm_output_data (4, 0xffffffff,
777 "Initial length escape value indicating 64-bit DWARF extension");
778 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
779 "Length of Common Information Entry");
780 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
782 /* Now that the CIE pointer is PC-relative for EH,
783 use 0 to identify the CIE. */
784 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
785 (for_eh
? 0 : DWARF_CIE_ID
),
786 "CIE Identifier Tag");
788 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
789 use CIE version 1, unless that would produce incorrect results
790 due to overflowing the return register column. */
791 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
793 if (return_reg
>= 256 || dwarf_version
> 2)
795 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
798 augmentation_size
= 0;
800 personality
= current_unit_personality
;
806 z Indicates that a uleb128 is present to size the
807 augmentation section.
808 L Indicates the encoding (and thus presence) of
809 an LSDA pointer in the FDE augmentation.
810 R Indicates a non-default pointer encoding for
812 P Indicates the presence of an encoding + language
813 personality routine in the CIE augmentation. */
815 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
816 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
817 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
819 p
= augmentation
+ 1;
823 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
824 assemble_external_libcall (personality
);
829 augmentation_size
+= 1;
831 if (fde_encoding
!= DW_EH_PE_absptr
)
834 augmentation_size
+= 1;
836 if (p
> augmentation
+ 1)
838 augmentation
[0] = 'z';
842 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
843 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
845 int offset
= ( 4 /* Length */
847 + 1 /* CIE version */
848 + strlen (augmentation
) + 1 /* Augmentation */
849 + size_of_uleb128 (1) /* Code alignment */
850 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
852 + 1 /* Augmentation size */
853 + 1 /* Personality encoding */ );
854 int pad
= -offset
& (PTR_SIZE
- 1);
856 augmentation_size
+= pad
;
858 /* Augmentations should be small, so there's scarce need to
859 iterate for a solution. Die if we exceed one uleb128 byte. */
860 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
864 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
865 if (dw_cie_version
>= 4)
867 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
868 dw2_asm_output_data (1, 0, "CIE Segment Size");
870 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
871 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
872 "CIE Data Alignment Factor");
874 if (dw_cie_version
== 1)
875 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
877 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
881 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
884 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
885 eh_data_format_name (per_encoding
));
886 dw2_asm_output_encoded_addr_rtx (per_encoding
,
892 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
893 eh_data_format_name (lsda_encoding
));
895 if (fde_encoding
!= DW_EH_PE_absptr
)
896 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
897 eh_data_format_name (fde_encoding
));
900 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
901 output_cfi (cfi
, NULL
, for_eh
);
903 /* Pad the CIE out to an address sized boundary. */
904 ASM_OUTPUT_ALIGN (asm_out_file
,
905 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
906 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
908 /* Loop through all of the FDE's. */
909 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
913 /* Don't emit EH unwind info for leaf functions that don't need it. */
914 if (for_eh
&& !fde_needed_for_eh_p (fde
))
917 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
918 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
919 augmentation
, any_lsda_needed
, lsda_encoding
);
922 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
923 dw2_asm_output_data (4, 0, "End of Table");
925 /* Turn off app to make assembly quicker. */
930 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
933 dwarf2out_do_cfi_startproc (bool second
)
937 rtx personality
= get_personality_function (current_function_decl
);
939 fprintf (asm_out_file
, "\t.cfi_startproc\n");
943 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
946 /* ??? The GAS support isn't entirely consistent. We have to
947 handle indirect support ourselves, but PC-relative is done
948 in the assembler. Further, the assembler can't handle any
949 of the weirder relocation types. */
950 if (enc
& DW_EH_PE_indirect
)
951 ref
= dw2_force_const_mem (ref
, true);
953 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
954 output_addr_const (asm_out_file
, ref
);
955 fputc ('\n', asm_out_file
);
958 if (crtl
->uses_eh_lsda
)
962 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
963 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
964 current_function_funcdef_no
);
965 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
966 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
968 if (enc
& DW_EH_PE_indirect
)
969 ref
= dw2_force_const_mem (ref
, true);
971 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
972 output_addr_const (asm_out_file
, ref
);
973 fputc ('\n', asm_out_file
);
977 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
978 this allocation may be done before pass_final. */
981 dwarf2out_alloc_current_fde (void)
985 fde
= ggc_alloc_cleared_dw_fde_node ();
986 fde
->decl
= current_function_decl
;
987 fde
->funcdef_number
= current_function_funcdef_no
;
988 fde
->fde_index
= vec_safe_length (fde_vec
);
989 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
990 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
991 fde
->nothrow
= crtl
->nothrow
;
992 fde
->drap_reg
= INVALID_REGNUM
;
993 fde
->vdrap_reg
= INVALID_REGNUM
;
995 /* Record the FDE associated with this function. */
997 vec_safe_push (fde_vec
, fde
);
1002 /* Output a marker (i.e. a label) for the beginning of a function, before
1006 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1007 const char *file ATTRIBUTE_UNUSED
)
1009 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1015 current_function_func_begin_label
= NULL
;
1017 do_frame
= dwarf2out_do_frame ();
1019 /* ??? current_function_func_begin_label is also used by except.c for
1020 call-site information. We must emit this label if it might be used. */
1022 && (!flag_exceptions
1023 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1026 fnsec
= function_section (current_function_decl
);
1027 switch_to_section (fnsec
);
1028 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1029 current_function_funcdef_no
);
1030 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1031 current_function_funcdef_no
);
1032 dup_label
= xstrdup (label
);
1033 current_function_func_begin_label
= dup_label
;
1035 /* We can elide the fde allocation if we're not emitting debug info. */
1039 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1040 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1041 would include pass_dwarf2_frame. If we've not created the FDE yet,
1045 fde
= dwarf2out_alloc_current_fde ();
1047 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1048 fde
->dw_fde_begin
= dup_label
;
1049 fde
->dw_fde_current_label
= dup_label
;
1050 fde
->in_std_section
= (fnsec
== text_section
1051 || (cold_text_section
&& fnsec
== cold_text_section
));
1053 /* We only want to output line number information for the genuine dwarf2
1054 prologue case, not the eh frame case. */
1055 #ifdef DWARF2_DEBUGGING_INFO
1057 dwarf2out_source_line (line
, file
, 0, true);
1060 if (dwarf2out_do_cfi_asm ())
1061 dwarf2out_do_cfi_startproc (false);
1064 rtx personality
= get_personality_function (current_function_decl
);
1065 if (!current_unit_personality
)
1066 current_unit_personality
= personality
;
1068 /* We cannot keep a current personality per function as without CFI
1069 asm, at the point where we emit the CFI data, there is no current
1070 function anymore. */
1071 if (personality
&& current_unit_personality
!= personality
)
1072 sorry ("multiple EH personalities are supported only with assemblers "
1073 "supporting .cfi_personality directive");
1077 /* Output a marker (i.e. a label) for the end of the generated code
1078 for a function prologue. This gets called *after* the prologue code has
1082 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1083 const char *file ATTRIBUTE_UNUSED
)
1085 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1087 /* Output a label to mark the endpoint of the code generated for this
1089 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1090 current_function_funcdef_no
);
1091 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1092 current_function_funcdef_no
);
1093 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1096 /* Output a marker (i.e. a label) for the beginning of the generated code
1097 for a function epilogue. This gets called *before* the prologue code has
1101 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1102 const char *file ATTRIBUTE_UNUSED
)
1104 dw_fde_ref fde
= cfun
->fde
;
1105 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1107 if (fde
->dw_fde_vms_begin_epilogue
)
1110 /* Output a label to mark the endpoint of the code generated for this
1112 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1113 current_function_funcdef_no
);
1114 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1115 current_function_funcdef_no
);
1116 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1119 /* Output a marker (i.e. a label) for the absolute end of the generated code
1120 for a function definition. This gets called *after* the epilogue code has
1124 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1125 const char *file ATTRIBUTE_UNUSED
)
1128 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1130 last_var_location_insn
= NULL_RTX
;
1131 cached_next_real_insn
= NULL_RTX
;
1133 if (dwarf2out_do_cfi_asm ())
1134 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1136 /* Output a label to mark the endpoint of the code generated for this
1138 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1139 current_function_funcdef_no
);
1140 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1142 gcc_assert (fde
!= NULL
);
1143 if (fde
->dw_fde_second_begin
== NULL
)
1144 fde
->dw_fde_end
= xstrdup (label
);
1148 dwarf2out_frame_finish (void)
1150 /* Output call frame information. */
1151 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1152 output_call_frame_info (0);
1154 /* Output another copy for the unwinder. */
1155 if ((flag_unwind_tables
|| flag_exceptions
)
1156 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1157 output_call_frame_info (1);
1160 /* Note that the current function section is being used for code. */
1163 dwarf2out_note_section_used (void)
1165 section
*sec
= current_function_section ();
1166 if (sec
== text_section
)
1167 text_section_used
= true;
1168 else if (sec
== cold_text_section
)
1169 cold_text_section_used
= true;
1172 static void var_location_switch_text_section (void);
1173 static void set_cur_line_info_table (section
*);
1176 dwarf2out_switch_text_section (void)
1179 dw_fde_ref fde
= cfun
->fde
;
1181 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1183 if (!in_cold_section_p
)
1185 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1186 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1187 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1191 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1192 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1193 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1195 have_multiple_function_sections
= true;
1197 /* There is no need to mark used sections when not debugging. */
1198 if (cold_text_section
!= NULL
)
1199 dwarf2out_note_section_used ();
1201 if (dwarf2out_do_cfi_asm ())
1202 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1204 /* Now do the real section switch. */
1205 sect
= current_function_section ();
1206 switch_to_section (sect
);
1208 fde
->second_in_std_section
1209 = (sect
== text_section
1210 || (cold_text_section
&& sect
== cold_text_section
));
1212 if (dwarf2out_do_cfi_asm ())
1213 dwarf2out_do_cfi_startproc (true);
1215 var_location_switch_text_section ();
1217 if (cold_text_section
!= NULL
)
1218 set_cur_line_info_table (sect
);
1221 /* And now, the subset of the debugging information support code necessary
1222 for emitting location expressions. */
1224 /* Data about a single source file. */
1225 struct GTY(()) dwarf_file_data
{
1226 const char * filename
;
1230 typedef struct GTY(()) deferred_locations_struct
1234 } deferred_locations
;
1237 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1240 /* Describe an entry into the .debug_addr section. */
1244 ate_kind_rtx_dtprel
,
1248 typedef struct GTY(()) addr_table_entry_struct
{
1250 unsigned int refcount
;
1252 union addr_table_entry_struct_union
1254 rtx
GTY ((tag ("0"))) rtl
;
1255 char * GTY ((tag ("1"))) label
;
1257 GTY ((desc ("%1.kind"))) addr
;
1261 /* Location lists are ranges + location descriptions for that range,
1262 so you can track variables that are in different places over
1263 their entire life. */
1264 typedef struct GTY(()) dw_loc_list_struct
{
1265 dw_loc_list_ref dw_loc_next
;
1266 const char *begin
; /* Label and addr_entry for start of range */
1267 addr_table_entry
*begin_entry
;
1268 const char *end
; /* Label for end of range */
1269 char *ll_symbol
; /* Label for beginning of location list.
1270 Only on head of list */
1271 const char *section
; /* Section this loclist is relative to */
1272 dw_loc_descr_ref expr
;
1274 /* True if all addresses in this and subsequent lists are known to be
1277 /* True if this list has been replaced by dw_loc_next. */
1280 /* True if the range should be emitted even if begin and end
1285 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1287 /* Convert a DWARF stack opcode into its string name. */
1290 dwarf_stack_op_name (unsigned int op
)
1292 const char *name
= get_DW_OP_name (op
);
1297 return "OP_<unknown>";
1300 /* Return a pointer to a newly allocated location description. Location
1301 descriptions are simple expression terms that can be strung
1302 together to form more complicated location (address) descriptions. */
1304 static inline dw_loc_descr_ref
1305 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1306 unsigned HOST_WIDE_INT oprnd2
)
1308 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1310 descr
->dw_loc_opc
= op
;
1311 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1312 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1313 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1314 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1315 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1316 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1321 /* Return a pointer to a newly allocated location description for
1324 static inline dw_loc_descr_ref
1325 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1328 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1331 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1334 /* Add a location description term to a location description expression. */
1337 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1339 dw_loc_descr_ref
*d
;
1341 /* Find the end of the chain. */
1342 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1348 /* Compare two location operands for exact equality. */
1351 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1353 if (a
->val_class
!= b
->val_class
)
1355 switch (a
->val_class
)
1357 case dw_val_class_none
:
1359 case dw_val_class_addr
:
1360 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1362 case dw_val_class_offset
:
1363 case dw_val_class_unsigned_const
:
1364 case dw_val_class_const
:
1365 case dw_val_class_range_list
:
1366 case dw_val_class_lineptr
:
1367 case dw_val_class_macptr
:
1368 /* These are all HOST_WIDE_INT, signed or unsigned. */
1369 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1371 case dw_val_class_loc
:
1372 return a
->v
.val_loc
== b
->v
.val_loc
;
1373 case dw_val_class_loc_list
:
1374 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1375 case dw_val_class_die_ref
:
1376 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1377 case dw_val_class_fde_ref
:
1378 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1379 case dw_val_class_lbl_id
:
1380 case dw_val_class_high_pc
:
1381 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1382 case dw_val_class_str
:
1383 return a
->v
.val_str
== b
->v
.val_str
;
1384 case dw_val_class_flag
:
1385 return a
->v
.val_flag
== b
->v
.val_flag
;
1386 case dw_val_class_file
:
1387 return a
->v
.val_file
== b
->v
.val_file
;
1388 case dw_val_class_decl_ref
:
1389 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1391 case dw_val_class_const_double
:
1392 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1393 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1395 case dw_val_class_vec
:
1397 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1398 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1400 return (a_len
== b_len
1401 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1404 case dw_val_class_data8
:
1405 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1407 case dw_val_class_vms_delta
:
1408 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1409 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1414 /* Compare two location atoms for exact equality. */
1417 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1419 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1422 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1423 address size, but since we always allocate cleared storage it
1424 should be zero for other types of locations. */
1425 if (a
->dtprel
!= b
->dtprel
)
1428 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1429 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1432 /* Compare two complete location expressions for exact equality. */
1435 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1441 if (a
== NULL
|| b
== NULL
)
1443 if (!loc_descr_equal_p_1 (a
, b
))
1452 /* Add a constant OFFSET to a location expression. */
1455 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1457 dw_loc_descr_ref loc
;
1460 gcc_assert (*list_head
!= NULL
);
1465 /* Find the end of the chain. */
1466 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1470 if (loc
->dw_loc_opc
== DW_OP_fbreg
1471 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1472 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1473 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1474 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1476 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1477 offset. Don't optimize if an signed integer overflow would happen. */
1479 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1480 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1483 else if (offset
> 0)
1484 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1488 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1489 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1493 /* Add a constant OFFSET to a location list. */
1496 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1499 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1500 loc_descr_plus_const (&d
->expr
, offset
);
1503 #define DWARF_REF_SIZE \
1504 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1506 static unsigned long int get_base_type_offset (dw_die_ref
);
1508 /* Return the size of a location descriptor. */
1510 static unsigned long
1511 size_of_loc_descr (dw_loc_descr_ref loc
)
1513 unsigned long size
= 1;
1515 switch (loc
->dw_loc_opc
)
1518 size
+= DWARF2_ADDR_SIZE
;
1520 case DW_OP_GNU_addr_index
:
1521 case DW_OP_GNU_const_index
:
1522 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1523 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1542 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1545 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1550 case DW_OP_plus_uconst
:
1551 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1589 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1592 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1595 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1598 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1599 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1602 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1604 case DW_OP_bit_piece
:
1605 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1606 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1608 case DW_OP_deref_size
:
1609 case DW_OP_xderef_size
:
1618 case DW_OP_call_ref
:
1619 size
+= DWARF_REF_SIZE
;
1621 case DW_OP_implicit_value
:
1622 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1623 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1625 case DW_OP_GNU_implicit_pointer
:
1626 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1628 case DW_OP_GNU_entry_value
:
1630 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1631 size
+= size_of_uleb128 (op_size
) + op_size
;
1634 case DW_OP_GNU_const_type
:
1637 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1638 size
+= size_of_uleb128 (o
) + 1;
1639 switch (loc
->dw_loc_oprnd2
.val_class
)
1641 case dw_val_class_vec
:
1642 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1643 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1645 case dw_val_class_const
:
1646 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1648 case dw_val_class_const_double
:
1649 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1656 case DW_OP_GNU_regval_type
:
1659 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1660 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1661 + size_of_uleb128 (o
);
1664 case DW_OP_GNU_deref_type
:
1667 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1668 size
+= 1 + size_of_uleb128 (o
);
1671 case DW_OP_GNU_convert
:
1672 case DW_OP_GNU_reinterpret
:
1673 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1674 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1678 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1679 size
+= size_of_uleb128 (o
);
1682 case DW_OP_GNU_parameter_ref
:
1692 /* Return the size of a series of location descriptors. */
1695 size_of_locs (dw_loc_descr_ref loc
)
1700 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1701 field, to avoid writing to a PCH file. */
1702 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1704 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1706 size
+= size_of_loc_descr (l
);
1711 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1713 l
->dw_loc_addr
= size
;
1714 size
+= size_of_loc_descr (l
);
1720 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1721 static void get_ref_die_offset_label (char *, dw_die_ref
);
1722 static unsigned long int get_ref_die_offset (dw_die_ref
);
1724 /* Output location description stack opcode's operands (if any).
1725 The for_eh_or_skip parameter controls whether register numbers are
1726 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1727 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1728 info). This should be suppressed for the cases that have not been converted
1729 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1732 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1734 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1735 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1737 switch (loc
->dw_loc_opc
)
1739 #ifdef DWARF2_DEBUGGING_INFO
1742 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1747 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1748 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1750 fputc ('\n', asm_out_file
);
1755 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1760 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1761 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1763 fputc ('\n', asm_out_file
);
1768 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1769 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1776 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1777 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1779 dw2_asm_output_data (2, offset
, NULL
);
1782 case DW_OP_implicit_value
:
1783 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1784 switch (val2
->val_class
)
1786 case dw_val_class_const
:
1787 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1789 case dw_val_class_vec
:
1791 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1792 unsigned int len
= val2
->v
.val_vec
.length
;
1796 if (elt_size
> sizeof (HOST_WIDE_INT
))
1801 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1804 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1805 "fp or vector constant word %u", i
);
1808 case dw_val_class_const_double
:
1810 unsigned HOST_WIDE_INT first
, second
;
1812 if (WORDS_BIG_ENDIAN
)
1814 first
= val2
->v
.val_double
.high
;
1815 second
= val2
->v
.val_double
.low
;
1819 first
= val2
->v
.val_double
.low
;
1820 second
= val2
->v
.val_double
.high
;
1822 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1824 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1828 case dw_val_class_addr
:
1829 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1830 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1845 case DW_OP_implicit_value
:
1846 /* We currently don't make any attempt to make sure these are
1847 aligned properly like we do for the main unwind info, so
1848 don't support emitting things larger than a byte if we're
1849 only doing unwinding. */
1854 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1857 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1860 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1863 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1865 case DW_OP_plus_uconst
:
1866 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1900 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1904 unsigned r
= val1
->v
.val_unsigned
;
1905 if (for_eh_or_skip
>= 0)
1906 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1907 gcc_assert (size_of_uleb128 (r
)
1908 == size_of_uleb128 (val1
->v
.val_unsigned
));
1909 dw2_asm_output_data_uleb128 (r
, NULL
);
1913 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1917 unsigned r
= val1
->v
.val_unsigned
;
1918 if (for_eh_or_skip
>= 0)
1919 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1920 gcc_assert (size_of_uleb128 (r
)
1921 == size_of_uleb128 (val1
->v
.val_unsigned
));
1922 dw2_asm_output_data_uleb128 (r
, NULL
);
1923 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1927 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1929 case DW_OP_bit_piece
:
1930 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1931 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1933 case DW_OP_deref_size
:
1934 case DW_OP_xderef_size
:
1935 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1941 if (targetm
.asm_out
.output_dwarf_dtprel
)
1943 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1946 fputc ('\n', asm_out_file
);
1953 #ifdef DWARF2_DEBUGGING_INFO
1954 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1961 case DW_OP_GNU_addr_index
:
1962 case DW_OP_GNU_const_index
:
1963 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1964 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1965 "(index into .debug_addr)");
1968 case DW_OP_GNU_implicit_pointer
:
1970 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1971 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1972 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1973 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1974 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1975 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1979 case DW_OP_GNU_entry_value
:
1980 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1981 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1984 case DW_OP_GNU_const_type
:
1986 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1988 dw2_asm_output_data_uleb128 (o
, NULL
);
1989 switch (val2
->val_class
)
1991 case dw_val_class_const
:
1992 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1993 dw2_asm_output_data (1, l
, NULL
);
1994 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1996 case dw_val_class_vec
:
1998 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1999 unsigned int len
= val2
->v
.val_vec
.length
;
2004 dw2_asm_output_data (1, l
, NULL
);
2005 if (elt_size
> sizeof (HOST_WIDE_INT
))
2010 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2013 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2014 "fp or vector constant word %u", i
);
2017 case dw_val_class_const_double
:
2019 unsigned HOST_WIDE_INT first
, second
;
2020 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2022 dw2_asm_output_data (1, 2 * l
, NULL
);
2023 if (WORDS_BIG_ENDIAN
)
2025 first
= val2
->v
.val_double
.high
;
2026 second
= val2
->v
.val_double
.low
;
2030 first
= val2
->v
.val_double
.low
;
2031 second
= val2
->v
.val_double
.high
;
2033 dw2_asm_output_data (l
, first
, NULL
);
2034 dw2_asm_output_data (l
, second
, NULL
);
2042 case DW_OP_GNU_regval_type
:
2044 unsigned r
= val1
->v
.val_unsigned
;
2045 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2047 if (for_eh_or_skip
>= 0)
2049 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2050 gcc_assert (size_of_uleb128 (r
)
2051 == size_of_uleb128 (val1
->v
.val_unsigned
));
2053 dw2_asm_output_data_uleb128 (r
, NULL
);
2054 dw2_asm_output_data_uleb128 (o
, NULL
);
2057 case DW_OP_GNU_deref_type
:
2059 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2061 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2062 dw2_asm_output_data_uleb128 (o
, NULL
);
2065 case DW_OP_GNU_convert
:
2066 case DW_OP_GNU_reinterpret
:
2067 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2068 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2071 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2073 dw2_asm_output_data_uleb128 (o
, NULL
);
2077 case DW_OP_GNU_parameter_ref
:
2080 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2081 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2082 dw2_asm_output_data (4, o
, NULL
);
2087 /* Other codes have no operands. */
2092 /* Output a sequence of location operations.
2093 The for_eh_or_skip parameter controls whether register numbers are
2094 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2095 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2096 info). This should be suppressed for the cases that have not been converted
2097 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2100 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2102 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2104 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2105 /* Output the opcode. */
2106 if (for_eh_or_skip
>= 0
2107 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2109 unsigned r
= (opc
- DW_OP_breg0
);
2110 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2111 gcc_assert (r
<= 31);
2112 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2114 else if (for_eh_or_skip
>= 0
2115 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2117 unsigned r
= (opc
- DW_OP_reg0
);
2118 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2119 gcc_assert (r
<= 31);
2120 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2123 dw2_asm_output_data (1, opc
,
2124 "%s", dwarf_stack_op_name (opc
));
2126 /* Output the operand(s) (if any). */
2127 output_loc_operands (loc
, for_eh_or_skip
);
2131 /* Output location description stack opcode's operands (if any).
2132 The output is single bytes on a line, suitable for .cfi_escape. */
2135 output_loc_operands_raw (dw_loc_descr_ref loc
)
2137 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2138 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2140 switch (loc
->dw_loc_opc
)
2143 case DW_OP_GNU_addr_index
:
2144 case DW_OP_GNU_const_index
:
2145 case DW_OP_implicit_value
:
2146 /* We cannot output addresses in .cfi_escape, only bytes. */
2152 case DW_OP_deref_size
:
2153 case DW_OP_xderef_size
:
2154 fputc (',', asm_out_file
);
2155 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2160 fputc (',', asm_out_file
);
2161 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2166 fputc (',', asm_out_file
);
2167 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2172 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2173 fputc (',', asm_out_file
);
2174 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2182 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2183 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2185 fputc (',', asm_out_file
);
2186 dw2_asm_output_data_raw (2, offset
);
2192 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2193 gcc_assert (size_of_uleb128 (r
)
2194 == size_of_uleb128 (val1
->v
.val_unsigned
));
2195 fputc (',', asm_out_file
);
2196 dw2_asm_output_data_uleb128_raw (r
);
2201 case DW_OP_plus_uconst
:
2203 fputc (',', asm_out_file
);
2204 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2207 case DW_OP_bit_piece
:
2208 fputc (',', asm_out_file
);
2209 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2210 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2247 fputc (',', asm_out_file
);
2248 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2253 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2254 gcc_assert (size_of_uleb128 (r
)
2255 == size_of_uleb128 (val1
->v
.val_unsigned
));
2256 fputc (',', asm_out_file
);
2257 dw2_asm_output_data_uleb128_raw (r
);
2258 fputc (',', asm_out_file
);
2259 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2263 case DW_OP_GNU_implicit_pointer
:
2264 case DW_OP_GNU_entry_value
:
2265 case DW_OP_GNU_const_type
:
2266 case DW_OP_GNU_regval_type
:
2267 case DW_OP_GNU_deref_type
:
2268 case DW_OP_GNU_convert
:
2269 case DW_OP_GNU_reinterpret
:
2270 case DW_OP_GNU_parameter_ref
:
2275 /* Other codes have no operands. */
2281 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2285 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2286 /* Output the opcode. */
2287 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2289 unsigned r
= (opc
- DW_OP_breg0
);
2290 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2291 gcc_assert (r
<= 31);
2292 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2294 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2296 unsigned r
= (opc
- DW_OP_reg0
);
2297 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2298 gcc_assert (r
<= 31);
2299 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2301 /* Output the opcode. */
2302 fprintf (asm_out_file
, "%#x", opc
);
2303 output_loc_operands_raw (loc
);
2305 if (!loc
->dw_loc_next
)
2307 loc
= loc
->dw_loc_next
;
2309 fputc (',', asm_out_file
);
2313 /* This function builds a dwarf location descriptor sequence from a
2314 dw_cfa_location, adding the given OFFSET to the result of the
2317 struct dw_loc_descr_node
*
2318 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2320 struct dw_loc_descr_node
*head
, *tmp
;
2322 offset
+= cfa
->offset
;
2326 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2327 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2328 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2329 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2330 add_loc_descr (&head
, tmp
);
2333 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2334 add_loc_descr (&head
, tmp
);
2338 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2343 /* This function builds a dwarf location descriptor sequence for
2344 the address at OFFSET from the CFA when stack is aligned to
2347 struct dw_loc_descr_node
*
2348 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2349 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2351 struct dw_loc_descr_node
*head
;
2352 unsigned int dwarf_fp
2353 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2355 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2356 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2358 head
= new_reg_loc_descr (dwarf_fp
, 0);
2359 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2360 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2361 loc_descr_plus_const (&head
, offset
);
2364 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2368 /* And now, the support for symbolic debugging information. */
2370 /* .debug_str support. */
2371 static int output_indirect_string (void **, void *);
2373 static void dwarf2out_init (const char *);
2374 static void dwarf2out_finish (const char *);
2375 static void dwarf2out_assembly_start (void);
2376 static void dwarf2out_define (unsigned int, const char *);
2377 static void dwarf2out_undef (unsigned int, const char *);
2378 static void dwarf2out_start_source_file (unsigned, const char *);
2379 static void dwarf2out_end_source_file (unsigned);
2380 static void dwarf2out_function_decl (tree
);
2381 static void dwarf2out_begin_block (unsigned, unsigned);
2382 static void dwarf2out_end_block (unsigned, unsigned);
2383 static bool dwarf2out_ignore_block (const_tree
);
2384 static void dwarf2out_global_decl (tree
);
2385 static void dwarf2out_type_decl (tree
, int);
2386 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2387 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2389 static void dwarf2out_abstract_function (tree
);
2390 static void dwarf2out_var_location (rtx
);
2391 static void dwarf2out_begin_function (tree
);
2392 static void dwarf2out_end_function (unsigned int);
2393 static void dwarf2out_set_name (tree
, tree
);
2395 /* The debug hooks structure. */
2397 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2401 dwarf2out_assembly_start
,
2404 dwarf2out_start_source_file
,
2405 dwarf2out_end_source_file
,
2406 dwarf2out_begin_block
,
2407 dwarf2out_end_block
,
2408 dwarf2out_ignore_block
,
2409 dwarf2out_source_line
,
2410 dwarf2out_begin_prologue
,
2411 #if VMS_DEBUGGING_INFO
2412 dwarf2out_vms_end_prologue
,
2413 dwarf2out_vms_begin_epilogue
,
2415 debug_nothing_int_charstar
,
2416 debug_nothing_int_charstar
,
2418 dwarf2out_end_epilogue
,
2419 dwarf2out_begin_function
,
2420 dwarf2out_end_function
, /* end_function */
2421 dwarf2out_function_decl
, /* function_decl */
2422 dwarf2out_global_decl
,
2423 dwarf2out_type_decl
, /* type_decl */
2424 dwarf2out_imported_module_or_decl
,
2425 debug_nothing_tree
, /* deferred_inline_function */
2426 /* The DWARF 2 backend tries to reduce debugging bloat by not
2427 emitting the abstract description of inline functions until
2428 something tries to reference them. */
2429 dwarf2out_abstract_function
, /* outlining_inline_function */
2430 debug_nothing_rtx
, /* label */
2431 debug_nothing_int
, /* handle_pch */
2432 dwarf2out_var_location
,
2433 dwarf2out_switch_text_section
,
2435 1, /* start_end_main_source_file */
2436 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2439 /* NOTE: In the comments in this file, many references are made to
2440 "Debugging Information Entries". This term is abbreviated as `DIE'
2441 throughout the remainder of this file. */
2443 /* An internal representation of the DWARF output is built, and then
2444 walked to generate the DWARF debugging info. The walk of the internal
2445 representation is done after the entire program has been compiled.
2446 The types below are used to describe the internal representation. */
2448 /* Whether to put type DIEs into their own section .debug_types instead
2449 of making them part of the .debug_info section. Only supported for
2450 Dwarf V4 or higher and the user didn't disable them through
2451 -fno-debug-types-section. It is more efficient to put them in a
2452 separate comdat sections since the linker will then be able to
2453 remove duplicates. But not all tools support .debug_types sections
2456 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2458 /* Various DIE's use offsets relative to the beginning of the
2459 .debug_info section to refer to each other. */
2461 typedef long int dw_offset
;
2463 /* Define typedefs here to avoid circular dependencies. */
2465 typedef struct dw_attr_struct
*dw_attr_ref
;
2466 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2467 typedef struct pubname_struct
*pubname_ref
;
2468 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2469 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2470 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2472 /* The entries in the line_info table more-or-less mirror the opcodes
2473 that are used in the real dwarf line table. Arrays of these entries
2474 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2477 enum dw_line_info_opcode
{
2478 /* Emit DW_LNE_set_address; the operand is the label index. */
2481 /* Emit a row to the matrix with the given line. This may be done
2482 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2486 /* Emit a DW_LNS_set_file. */
2489 /* Emit a DW_LNS_set_column. */
2492 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2495 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2496 LI_set_prologue_end
,
2497 LI_set_epilogue_begin
,
2499 /* Emit a DW_LNE_set_discriminator. */
2500 LI_set_discriminator
2503 typedef struct GTY(()) dw_line_info_struct
{
2504 enum dw_line_info_opcode opcode
;
2506 } dw_line_info_entry
;
2509 typedef struct GTY(()) dw_line_info_table_struct
{
2510 /* The label that marks the end of this section. */
2511 const char *end_label
;
2513 /* The values for the last row of the matrix, as collected in the table.
2514 These are used to minimize the changes to the next row. */
2515 unsigned int file_num
;
2516 unsigned int line_num
;
2517 unsigned int column_num
;
2522 vec
<dw_line_info_entry
, va_gc
> *entries
;
2523 } dw_line_info_table
;
2525 typedef dw_line_info_table
*dw_line_info_table_p
;
2528 /* Each DIE attribute has a field specifying the attribute kind,
2529 a link to the next attribute in the chain, and an attribute value.
2530 Attributes are typically linked below the DIE they modify. */
2532 typedef struct GTY(()) dw_attr_struct
{
2533 enum dwarf_attribute dw_attr
;
2534 dw_val_node dw_attr_val
;
2539 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2540 The children of each node form a circular list linked by
2541 die_sib. die_child points to the node *before* the "first" child node. */
2543 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2544 union die_symbol_or_type_node
2546 const char * GTY ((tag ("0"))) die_symbol
;
2547 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2549 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2550 vec
<dw_attr_node
, va_gc
> *die_attr
;
2551 dw_die_ref die_parent
;
2552 dw_die_ref die_child
;
2554 dw_die_ref die_definition
; /* ref from a specification to its definition */
2555 dw_offset die_offset
;
2556 unsigned long die_abbrev
;
2558 unsigned int decl_id
;
2559 enum dwarf_tag die_tag
;
2560 /* Die is used and must not be pruned as unused. */
2561 BOOL_BITFIELD die_perennial_p
: 1;
2562 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2563 /* Lots of spare bits. */
2567 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2568 #define FOR_EACH_CHILD(die, c, expr) do { \
2569 c = die->die_child; \
2573 } while (c != die->die_child); \
2576 /* The pubname structure */
2578 typedef struct GTY(()) pubname_struct
{
2585 struct GTY(()) dw_ranges_struct
{
2586 /* If this is positive, it's a block number, otherwise it's a
2587 bitwise-negated index into dw_ranges_by_label. */
2591 /* A structure to hold a macinfo entry. */
2593 typedef struct GTY(()) macinfo_struct
{
2595 unsigned HOST_WIDE_INT lineno
;
2601 struct GTY(()) dw_ranges_by_label_struct
{
2606 /* The comdat type node structure. */
2607 typedef struct GTY(()) comdat_type_struct
2609 dw_die_ref root_die
;
2610 dw_die_ref type_die
;
2611 dw_die_ref skeleton_die
;
2612 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2613 struct comdat_type_struct
*next
;
2617 /* The limbo die list structure. */
2618 typedef struct GTY(()) limbo_die_struct
{
2621 struct limbo_die_struct
*next
;
2625 typedef struct skeleton_chain_struct
2629 struct skeleton_chain_struct
*parent
;
2631 skeleton_chain_node
;
2633 /* Define a macro which returns nonzero for a TYPE_DECL which was
2634 implicitly generated for a type.
2636 Note that, unlike the C front-end (which generates a NULL named
2637 TYPE_DECL node for each complete tagged type, each array type,
2638 and each function type node created) the C++ front-end generates
2639 a _named_ TYPE_DECL node for each tagged type node created.
2640 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2641 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2642 front-end, but for each type, tagged or not. */
2644 #define TYPE_DECL_IS_STUB(decl) \
2645 (DECL_NAME (decl) == NULL_TREE \
2646 || (DECL_ARTIFICIAL (decl) \
2647 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2648 /* This is necessary for stub decls that \
2649 appear in nested inline functions. */ \
2650 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2651 && (decl_ultimate_origin (decl) \
2652 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2654 /* Information concerning the compilation unit's programming
2655 language, and compiler version. */
2657 /* Fixed size portion of the DWARF compilation unit header. */
2658 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2659 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2661 /* Fixed size portion of the DWARF comdat type unit header. */
2662 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2663 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2664 + DWARF_OFFSET_SIZE)
2666 /* Fixed size portion of public names info. */
2667 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2669 /* Fixed size portion of the address range info. */
2670 #define DWARF_ARANGES_HEADER_SIZE \
2671 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2672 DWARF2_ADDR_SIZE * 2) \
2673 - DWARF_INITIAL_LENGTH_SIZE)
2675 /* Size of padding portion in the address range info. It must be
2676 aligned to twice the pointer size. */
2677 #define DWARF_ARANGES_PAD_SIZE \
2678 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2679 DWARF2_ADDR_SIZE * 2) \
2680 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2682 /* Use assembler line directives if available. */
2683 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2684 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2685 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2687 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2691 /* Minimum line offset in a special line info. opcode.
2692 This value was chosen to give a reasonable range of values. */
2693 #define DWARF_LINE_BASE -10
2695 /* First special line opcode - leave room for the standard opcodes. */
2696 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2698 /* Range of line offsets in a special line info. opcode. */
2699 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2701 /* Flag that indicates the initial value of the is_stmt_start flag.
2702 In the present implementation, we do not mark any lines as
2703 the beginning of a source statement, because that information
2704 is not made available by the GCC front-end. */
2705 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2707 /* Maximum number of operations per instruction bundle. */
2708 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2709 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2712 /* This location is used by calc_die_sizes() to keep track
2713 the offset of each DIE within the .debug_info section. */
2714 static unsigned long next_die_offset
;
2716 /* Record the root of the DIE's built for the current compilation unit. */
2717 static GTY(()) dw_die_ref single_comp_unit_die
;
2719 /* A list of type DIEs that have been separated into comdat sections. */
2720 static GTY(()) comdat_type_node
*comdat_type_list
;
2722 /* A list of DIEs with a NULL parent waiting to be relocated. */
2723 static GTY(()) limbo_die_node
*limbo_die_list
;
2725 /* A list of DIEs for which we may have to generate
2726 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2727 static GTY(()) limbo_die_node
*deferred_asm_name
;
2729 /* Filenames referenced by this compilation unit. */
2730 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2732 /* A hash table of references to DIE's that describe declarations.
2733 The key is a DECL_UID() which is a unique number identifying each decl. */
2734 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2736 /* A hash table of references to DIE's that describe COMMON blocks.
2737 The key is DECL_UID() ^ die_parent. */
2738 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2740 typedef struct GTY(()) die_arg_entry_struct
{
2746 /* Node of the variable location list. */
2747 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2748 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2749 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2750 in mode of the EXPR_LIST node and first EXPR_LIST operand
2751 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2752 location or NULL for padding. For larger bitsizes,
2753 mode is 0 and first operand is a CONCAT with bitsize
2754 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2755 NULL as second operand. */
2757 const char * GTY (()) label
;
2758 struct var_loc_node
* GTY (()) next
;
2761 /* Variable location list. */
2762 struct GTY (()) var_loc_list_def
{
2763 struct var_loc_node
* GTY (()) first
;
2765 /* Pointer to the last but one or last element of the
2766 chained list. If the list is empty, both first and
2767 last are NULL, if the list contains just one node
2768 or the last node certainly is not redundant, it points
2769 to the last node, otherwise points to the last but one.
2770 Do not mark it for GC because it is marked through the chain. */
2771 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2773 /* Pointer to the last element before section switch,
2774 if NULL, either sections weren't switched or first
2775 is after section switch. */
2776 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2778 /* DECL_UID of the variable decl. */
2779 unsigned int decl_id
;
2781 typedef struct var_loc_list_def var_loc_list
;
2783 /* Call argument location list. */
2784 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2785 rtx
GTY (()) call_arg_loc_note
;
2786 const char * GTY (()) label
;
2787 tree
GTY (()) block
;
2789 rtx
GTY (()) symbol_ref
;
2790 struct call_arg_loc_node
* GTY (()) next
;
2794 /* Table of decl location linked lists. */
2795 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2797 /* Head and tail of call_arg_loc chain. */
2798 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2799 static struct call_arg_loc_node
*call_arg_loc_last
;
2801 /* Number of call sites in the current function. */
2802 static int call_site_count
= -1;
2803 /* Number of tail call sites in the current function. */
2804 static int tail_call_site_count
= -1;
2806 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2808 static vec
<dw_die_ref
> block_map
;
2810 /* A cached location list. */
2811 struct GTY (()) cached_dw_loc_list_def
{
2812 /* The DECL_UID of the decl that this entry describes. */
2813 unsigned int decl_id
;
2815 /* The cached location list. */
2816 dw_loc_list_ref loc_list
;
2818 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2820 /* Table of cached location lists. */
2821 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2823 /* A pointer to the base of a list of references to DIE's that
2824 are uniquely identified by their tag, presence/absence of
2825 children DIE's, and list of attribute/value pairs. */
2826 static GTY((length ("abbrev_die_table_allocated")))
2827 dw_die_ref
*abbrev_die_table
;
2829 /* Number of elements currently allocated for abbrev_die_table. */
2830 static GTY(()) unsigned abbrev_die_table_allocated
;
2832 /* Number of elements in type_die_table currently in use. */
2833 static GTY(()) unsigned abbrev_die_table_in_use
;
2835 /* Size (in elements) of increments by which we may expand the
2836 abbrev_die_table. */
2837 #define ABBREV_DIE_TABLE_INCREMENT 256
2839 /* A global counter for generating labels for line number data. */
2840 static unsigned int line_info_label_num
;
2842 /* The current table to which we should emit line number information
2843 for the current function. This will be set up at the beginning of
2844 assembly for the function. */
2845 static dw_line_info_table
*cur_line_info_table
;
2847 /* The two default tables of line number info. */
2848 static GTY(()) dw_line_info_table
*text_section_line_info
;
2849 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2851 /* The set of all non-default tables of line number info. */
2852 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2854 /* A flag to tell pubnames/types export if there is an info section to
2856 static bool info_section_emitted
;
2858 /* A pointer to the base of a table that contains a list of publicly
2859 accessible names. */
2860 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2862 /* A pointer to the base of a table that contains a list of publicly
2863 accessible types. */
2864 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2866 /* A pointer to the base of a table that contains a list of macro
2867 defines/undefines (and file start/end markers). */
2868 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2870 /* True if .debug_macinfo or .debug_macros section is going to be
2872 #define have_macinfo \
2873 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2874 && !macinfo_table->is_empty ())
2876 /* Array of dies for which we should generate .debug_ranges info. */
2877 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2879 /* Number of elements currently allocated for ranges_table. */
2880 static GTY(()) unsigned ranges_table_allocated
;
2882 /* Number of elements in ranges_table currently in use. */
2883 static GTY(()) unsigned ranges_table_in_use
;
2885 /* Array of pairs of labels referenced in ranges_table. */
2886 static GTY ((length ("ranges_by_label_allocated")))
2887 dw_ranges_by_label_ref ranges_by_label
;
2889 /* Number of elements currently allocated for ranges_by_label. */
2890 static GTY(()) unsigned ranges_by_label_allocated
;
2892 /* Number of elements in ranges_by_label currently in use. */
2893 static GTY(()) unsigned ranges_by_label_in_use
;
2895 /* Size (in elements) of increments by which we may expand the
2897 #define RANGES_TABLE_INCREMENT 64
2899 /* Whether we have location lists that need outputting */
2900 static GTY(()) bool have_location_lists
;
2902 /* Unique label counter. */
2903 static GTY(()) unsigned int loclabel_num
;
2905 /* Unique label counter for point-of-call tables. */
2906 static GTY(()) unsigned int poc_label_num
;
2908 /* Record whether the function being analyzed contains inlined functions. */
2909 static int current_function_has_inlines
;
2911 /* The last file entry emitted by maybe_emit_file(). */
2912 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2914 /* Number of internal labels generated by gen_internal_sym(). */
2915 static GTY(()) int label_num
;
2917 /* Cached result of previous call to lookup_filename. */
2918 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2920 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2922 /* Instances of generic types for which we need to generate debug
2923 info that describe their generic parameters and arguments. That
2924 generation needs to happen once all types are properly laid out so
2925 we do it at the end of compilation. */
2926 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2928 /* Offset from the "steady-state frame pointer" to the frame base,
2929 within the current function. */
2930 static HOST_WIDE_INT frame_pointer_fb_offset
;
2931 static bool frame_pointer_fb_offset_valid
;
2933 static vec
<dw_die_ref
> base_types
;
2935 /* Forward declarations for functions defined in this file. */
2937 static int is_pseudo_reg (const_rtx
);
2938 static tree
type_main_variant (tree
);
2939 static int is_tagged_type (const_tree
);
2940 static const char *dwarf_tag_name (unsigned);
2941 static const char *dwarf_attr_name (unsigned);
2942 static const char *dwarf_form_name (unsigned);
2943 static tree
decl_ultimate_origin (const_tree
);
2944 static tree
decl_class_context (tree
);
2945 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2946 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2947 static inline unsigned int AT_index (dw_attr_ref
);
2948 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2949 static inline unsigned AT_flag (dw_attr_ref
);
2950 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2951 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2952 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2953 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2954 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2955 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2956 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2957 unsigned int, unsigned char *);
2958 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2959 static hashval_t
debug_str_do_hash (const void *);
2960 static int debug_str_eq (const void *, const void *);
2961 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2962 static inline const char *AT_string (dw_attr_ref
);
2963 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2964 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2965 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2966 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2967 static inline int AT_ref_external (dw_attr_ref
);
2968 static inline void set_AT_ref_external (dw_attr_ref
, int);
2969 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2970 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2971 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2972 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2974 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2975 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2976 static void remove_addr_table_entry (addr_table_entry
*);
2977 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2978 static inline rtx
AT_addr (dw_attr_ref
);
2979 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2980 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2981 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2982 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2983 unsigned HOST_WIDE_INT
);
2984 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2985 unsigned long, bool);
2986 static inline const char *AT_lbl (dw_attr_ref
);
2987 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2988 static const char *get_AT_low_pc (dw_die_ref
);
2989 static const char *get_AT_hi_pc (dw_die_ref
);
2990 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2991 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2992 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2993 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2994 static bool is_cxx (void);
2995 static bool is_fortran (void);
2996 static bool is_ada (void);
2997 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2998 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2999 static void add_child_die (dw_die_ref
, dw_die_ref
);
3000 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3001 static dw_die_ref
lookup_type_die (tree
);
3002 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3003 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3004 static void equate_type_number_to_die (tree
, dw_die_ref
);
3005 static hashval_t
decl_die_table_hash (const void *);
3006 static int decl_die_table_eq (const void *, const void *);
3007 static dw_die_ref
lookup_decl_die (tree
);
3008 static hashval_t
common_block_die_table_hash (const void *);
3009 static int common_block_die_table_eq (const void *, const void *);
3010 static hashval_t
decl_loc_table_hash (const void *);
3011 static int decl_loc_table_eq (const void *, const void *);
3012 static var_loc_list
*lookup_decl_loc (const_tree
);
3013 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3014 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3015 static void print_spaces (FILE *);
3016 static void print_die (dw_die_ref
, FILE *);
3017 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3018 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3019 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3020 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3021 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3022 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3023 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3024 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3025 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3026 struct md5_ctx
*, int *);
3027 struct checksum_attributes
;
3028 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3029 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3030 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3031 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3032 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3033 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3034 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3035 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3036 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3037 static void compute_section_prefix (dw_die_ref
);
3038 static int is_type_die (dw_die_ref
);
3039 static int is_comdat_die (dw_die_ref
);
3040 static int is_symbol_die (dw_die_ref
);
3041 static inline bool is_template_instantiation (dw_die_ref
);
3042 static void assign_symbol_names (dw_die_ref
);
3043 static void break_out_includes (dw_die_ref
);
3044 static int is_declaration_die (dw_die_ref
);
3045 static int should_move_die_to_comdat (dw_die_ref
);
3046 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3047 static dw_die_ref
clone_die (dw_die_ref
);
3048 static dw_die_ref
clone_tree (dw_die_ref
);
3049 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3050 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3051 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3052 static dw_die_ref
generate_skeleton (dw_die_ref
);
3053 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3056 static void break_out_comdat_types (dw_die_ref
);
3057 static void copy_decls_for_unworthy_types (dw_die_ref
);
3059 static void add_sibling_attributes (dw_die_ref
);
3060 static void output_location_lists (dw_die_ref
);
3061 static int constant_size (unsigned HOST_WIDE_INT
);
3062 static unsigned long size_of_die (dw_die_ref
);
3063 static void calc_die_sizes (dw_die_ref
);
3064 static void calc_base_type_die_sizes (void);
3065 static void mark_dies (dw_die_ref
);
3066 static void unmark_dies (dw_die_ref
);
3067 static void unmark_all_dies (dw_die_ref
);
3068 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3069 static unsigned long size_of_aranges (void);
3070 static enum dwarf_form
value_format (dw_attr_ref
);
3071 static void output_value_format (dw_attr_ref
);
3072 static void output_abbrev_section (void);
3073 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3074 static void output_die_symbol (dw_die_ref
);
3075 static void output_die (dw_die_ref
);
3076 static void output_compilation_unit_header (void);
3077 static void output_comp_unit (dw_die_ref
, int);
3078 static void output_comdat_type_unit (comdat_type_node
*);
3079 static const char *dwarf2_name (tree
, int);
3080 static void add_pubname (tree
, dw_die_ref
);
3081 static void add_enumerator_pubname (const char *, dw_die_ref
);
3082 static void add_pubname_string (const char *, dw_die_ref
);
3083 static void add_pubtype (tree
, dw_die_ref
);
3084 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3085 static void output_aranges (unsigned long);
3086 static unsigned int add_ranges_num (int);
3087 static unsigned int add_ranges (const_tree
);
3088 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3090 static void output_ranges (void);
3091 static dw_line_info_table
*new_line_info_table (void);
3092 static void output_line_info (bool);
3093 static void output_file_names (void);
3094 static dw_die_ref
base_type_die (tree
);
3095 static int is_base_type (tree
);
3096 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3097 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3098 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3099 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3100 static int type_is_enum (const_tree
);
3101 static unsigned int dbx_reg_number (const_rtx
);
3102 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3103 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3104 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3105 enum var_init_status
);
3106 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3107 enum var_init_status
);
3108 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3109 enum var_init_status
);
3110 static int is_based_loc (const_rtx
);
3111 static int resolve_one_addr (rtx
*, void *);
3112 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3113 enum var_init_status
);
3114 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3115 enum var_init_status
);
3116 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3117 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3118 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3119 static tree
field_type (const_tree
);
3120 static unsigned int simple_type_align_in_bits (const_tree
);
3121 static unsigned int simple_decl_align_in_bits (const_tree
);
3122 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3123 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3124 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3126 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3127 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3128 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3129 static void insert_double (double_int
, unsigned char *);
3130 static void insert_float (const_rtx
, unsigned char *);
3131 static rtx
rtl_for_decl_location (tree
);
3132 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3133 enum dwarf_attribute
);
3134 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3135 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3136 static void add_name_attribute (dw_die_ref
, const char *);
3137 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3138 static void add_comp_dir_attribute (dw_die_ref
);
3139 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3140 static void add_subscript_info (dw_die_ref
, tree
, bool);
3141 static void add_byte_size_attribute (dw_die_ref
, tree
);
3142 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3143 static void add_bit_size_attribute (dw_die_ref
, tree
);
3144 static void add_prototyped_attribute (dw_die_ref
, tree
);
3145 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3146 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3147 static void add_src_coords_attributes (dw_die_ref
, tree
);
3148 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3149 static void push_decl_scope (tree
);
3150 static void pop_decl_scope (void);
3151 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3152 static inline int local_scope_p (dw_die_ref
);
3153 static inline int class_scope_p (dw_die_ref
);
3154 static inline int class_or_namespace_scope_p (dw_die_ref
);
3155 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3156 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3157 static const char *type_tag (const_tree
);
3158 static tree
member_declared_type (const_tree
);
3160 static const char *decl_start_label (tree
);
3162 static void gen_array_type_die (tree
, dw_die_ref
);
3163 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3165 static void gen_entry_point_die (tree
, dw_die_ref
);
3167 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3168 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3169 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3170 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3171 static void gen_formal_types_die (tree
, dw_die_ref
);
3172 static void gen_subprogram_die (tree
, dw_die_ref
);
3173 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3174 static void gen_const_die (tree
, dw_die_ref
);
3175 static void gen_label_die (tree
, dw_die_ref
);
3176 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3177 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3178 static void gen_field_die (tree
, dw_die_ref
);
3179 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3180 static dw_die_ref
gen_compile_unit_die (const char *);
3181 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3182 static void gen_member_die (tree
, dw_die_ref
);
3183 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3184 enum debug_info_usage
);
3185 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3186 static void gen_typedef_die (tree
, dw_die_ref
);
3187 static void gen_type_die (tree
, dw_die_ref
);
3188 static void gen_block_die (tree
, dw_die_ref
, int);
3189 static void decls_for_scope (tree
, dw_die_ref
, int);
3190 static inline int is_redundant_typedef (const_tree
);
3191 static bool is_naming_typedef_decl (const_tree
);
3192 static inline dw_die_ref
get_context_die (tree
);
3193 static void gen_namespace_die (tree
, dw_die_ref
);
3194 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3195 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3196 static dw_die_ref
force_decl_die (tree
);
3197 static dw_die_ref
force_type_die (tree
);
3198 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3199 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3200 static struct dwarf_file_data
* lookup_filename (const char *);
3201 static void retry_incomplete_types (void);
3202 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3203 static void gen_generic_params_dies (tree
);
3204 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3205 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3206 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3207 static int file_info_cmp (const void *, const void *);
3208 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3209 const char *, const char *);
3210 static void output_loc_list (dw_loc_list_ref
);
3211 static char *gen_internal_sym (const char *);
3212 static bool want_pubnames (void);
3214 static void prune_unmark_dies (dw_die_ref
);
3215 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3216 static void prune_unused_types_mark (dw_die_ref
, int);
3217 static void prune_unused_types_walk (dw_die_ref
);
3218 static void prune_unused_types_walk_attribs (dw_die_ref
);
3219 static void prune_unused_types_prune (dw_die_ref
);
3220 static void prune_unused_types (void);
3221 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3222 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3223 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3224 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3225 const char *, const char *);
3226 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3227 static void gen_remaining_tmpl_value_param_die_attribute (void);
3228 static bool generic_type_p (tree
);
3229 static void schedule_generic_params_dies_gen (tree t
);
3230 static void gen_scheduled_generic_parms_dies (void);
3232 static const char *comp_dir_string (void);
3234 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3236 /* enum for tracking thread-local variables whose address is really an offset
3237 relative to the TLS pointer, which will need link-time relocation, but will
3238 not need relocation by the DWARF consumer. */
3246 /* Return the operator to use for an address of a variable. For dtprel_true, we
3247 use DW_OP_const*. For regular variables, which need both link-time
3248 relocation and consumer-level relocation (e.g., to account for shared objects
3249 loaded at a random address), we use DW_OP_addr*. */
3251 static inline enum dwarf_location_atom
3252 dw_addr_op (enum dtprel_bool dtprel
)
3254 if (dtprel
== dtprel_true
)
3255 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3256 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3258 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3261 /* Return a pointer to a newly allocated address location description. If
3262 dwarf_split_debug_info is true, then record the address with the appropriate
3264 static inline dw_loc_descr_ref
3265 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3267 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3269 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3270 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3271 ref
->dtprel
= dtprel
;
3272 if (dwarf_split_debug_info
)
3273 ref
->dw_loc_oprnd1
.val_entry
3274 = add_addr_table_entry (addr
,
3275 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3277 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3282 /* Section names used to hold DWARF debugging information. */
3284 #ifndef DEBUG_INFO_SECTION
3285 #define DEBUG_INFO_SECTION ".debug_info"
3287 #ifndef DEBUG_DWO_INFO_SECTION
3288 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3290 #ifndef DEBUG_ABBREV_SECTION
3291 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3293 #ifndef DEBUG_DWO_ABBREV_SECTION
3294 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3296 #ifndef DEBUG_ARANGES_SECTION
3297 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3299 #ifndef DEBUG_ADDR_SECTION
3300 #define DEBUG_ADDR_SECTION ".debug_addr"
3302 #ifndef DEBUG_NORM_MACINFO_SECTION
3303 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3305 #ifndef DEBUG_DWO_MACINFO_SECTION
3306 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3308 #ifndef DEBUG_MACINFO_SECTION
3309 #define DEBUG_MACINFO_SECTION \
3310 (!dwarf_split_debug_info \
3311 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3313 #ifndef DEBUG_NORM_MACRO_SECTION
3314 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3316 #ifndef DEBUG_DWO_MACRO_SECTION
3317 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3319 #ifndef DEBUG_MACRO_SECTION
3320 #define DEBUG_MACRO_SECTION \
3321 (!dwarf_split_debug_info \
3322 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3324 #ifndef DEBUG_LINE_SECTION
3325 #define DEBUG_LINE_SECTION ".debug_line"
3327 #ifndef DEBUG_DWO_LINE_SECTION
3328 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3330 #ifndef DEBUG_LOC_SECTION
3331 #define DEBUG_LOC_SECTION ".debug_loc"
3333 #ifndef DEBUG_DWO_LOC_SECTION
3334 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3336 #ifndef DEBUG_PUBNAMES_SECTION
3337 #define DEBUG_PUBNAMES_SECTION \
3338 ((debug_generate_pub_sections == 2) \
3339 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3341 #ifndef DEBUG_PUBTYPES_SECTION
3342 #define DEBUG_PUBTYPES_SECTION \
3343 ((debug_generate_pub_sections == 2) \
3344 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3346 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3347 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3348 #ifndef DEBUG_STR_OFFSETS_SECTION
3349 #define DEBUG_STR_OFFSETS_SECTION \
3350 (!dwarf_split_debug_info \
3351 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3353 #ifndef DEBUG_STR_DWO_SECTION
3354 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3356 #ifndef DEBUG_STR_SECTION
3357 #define DEBUG_STR_SECTION ".debug_str"
3359 #ifndef DEBUG_RANGES_SECTION
3360 #define DEBUG_RANGES_SECTION ".debug_ranges"
3363 /* Standard ELF section names for compiled code and data. */
3364 #ifndef TEXT_SECTION_NAME
3365 #define TEXT_SECTION_NAME ".text"
3368 /* Section flags for .debug_macinfo/.debug_macro section. */
3369 #define DEBUG_MACRO_SECTION_FLAGS \
3370 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3372 /* Section flags for .debug_str section. */
3373 #define DEBUG_STR_SECTION_FLAGS \
3374 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3375 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3378 /* Section flags for .debug_str.dwo section. */
3379 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3381 /* Labels we insert at beginning sections we can reference instead of
3382 the section names themselves. */
3384 #ifndef TEXT_SECTION_LABEL
3385 #define TEXT_SECTION_LABEL "Ltext"
3387 #ifndef COLD_TEXT_SECTION_LABEL
3388 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3390 #ifndef DEBUG_LINE_SECTION_LABEL
3391 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3393 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3394 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3396 #ifndef DEBUG_INFO_SECTION_LABEL
3397 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3399 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3400 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3402 #ifndef DEBUG_ABBREV_SECTION_LABEL
3403 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3405 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3406 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3408 #ifndef DEBUG_ADDR_SECTION_LABEL
3409 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3411 #ifndef DEBUG_LOC_SECTION_LABEL
3412 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3414 #ifndef DEBUG_RANGES_SECTION_LABEL
3415 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3417 #ifndef DEBUG_MACINFO_SECTION_LABEL
3418 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3420 #ifndef DEBUG_MACRO_SECTION_LABEL
3421 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3423 #define SKELETON_COMP_DIE_ABBREV 1
3424 #define SKELETON_TYPE_DIE_ABBREV 2
3426 /* Definitions of defaults for formats and names of various special
3427 (artificial) labels which may be generated within this file (when the -g
3428 options is used and DWARF2_DEBUGGING_INFO is in effect.
3429 If necessary, these may be overridden from within the tm.h file, but
3430 typically, overriding these defaults is unnecessary. */
3432 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3433 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3434 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3435 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3436 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3437 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3438 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3439 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3440 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3441 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3442 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3443 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3444 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3445 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3447 #ifndef TEXT_END_LABEL
3448 #define TEXT_END_LABEL "Letext"
3450 #ifndef COLD_END_LABEL
3451 #define COLD_END_LABEL "Letext_cold"
3453 #ifndef BLOCK_BEGIN_LABEL
3454 #define BLOCK_BEGIN_LABEL "LBB"
3456 #ifndef BLOCK_END_LABEL
3457 #define BLOCK_END_LABEL "LBE"
3459 #ifndef LINE_CODE_LABEL
3460 #define LINE_CODE_LABEL "LM"
3464 /* Return the root of the DIE's built for the current compilation unit. */
3466 comp_unit_die (void)
3468 if (!single_comp_unit_die
)
3469 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3470 return single_comp_unit_die
;
3473 /* We allow a language front-end to designate a function that is to be
3474 called to "demangle" any name before it is put into a DIE. */
3476 static const char *(*demangle_name_func
) (const char *);
3479 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3481 demangle_name_func
= func
;
3484 /* Test if rtl node points to a pseudo register. */
3487 is_pseudo_reg (const_rtx rtl
)
3489 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3490 || (GET_CODE (rtl
) == SUBREG
3491 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3494 /* Return a reference to a type, with its const and volatile qualifiers
3498 type_main_variant (tree type
)
3500 type
= TYPE_MAIN_VARIANT (type
);
3502 /* ??? There really should be only one main variant among any group of
3503 variants of a given type (and all of the MAIN_VARIANT values for all
3504 members of the group should point to that one type) but sometimes the C
3505 front-end messes this up for array types, so we work around that bug
3507 if (TREE_CODE (type
) == ARRAY_TYPE
)
3508 while (type
!= TYPE_MAIN_VARIANT (type
))
3509 type
= TYPE_MAIN_VARIANT (type
);
3514 /* Return nonzero if the given type node represents a tagged type. */
3517 is_tagged_type (const_tree type
)
3519 enum tree_code code
= TREE_CODE (type
);
3521 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3522 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3525 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3528 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3530 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3533 /* Return die_offset of a DIE reference to a base type. */
3535 static unsigned long int
3536 get_base_type_offset (dw_die_ref ref
)
3538 if (ref
->die_offset
)
3539 return ref
->die_offset
;
3540 if (comp_unit_die ()->die_abbrev
)
3542 calc_base_type_die_sizes ();
3543 gcc_assert (ref
->die_offset
);
3545 return ref
->die_offset
;
3548 /* Return die_offset of a DIE reference other than base type. */
3550 static unsigned long int
3551 get_ref_die_offset (dw_die_ref ref
)
3553 gcc_assert (ref
->die_offset
);
3554 return ref
->die_offset
;
3557 /* Convert a DIE tag into its string name. */
3560 dwarf_tag_name (unsigned int tag
)
3562 const char *name
= get_DW_TAG_name (tag
);
3567 return "DW_TAG_<unknown>";
3570 /* Convert a DWARF attribute code into its string name. */
3573 dwarf_attr_name (unsigned int attr
)
3579 #if VMS_DEBUGGING_INFO
3580 case DW_AT_HP_prologue
:
3581 return "DW_AT_HP_prologue";
3583 case DW_AT_MIPS_loop_unroll_factor
:
3584 return "DW_AT_MIPS_loop_unroll_factor";
3587 #if VMS_DEBUGGING_INFO
3588 case DW_AT_HP_epilogue
:
3589 return "DW_AT_HP_epilogue";
3591 case DW_AT_MIPS_stride
:
3592 return "DW_AT_MIPS_stride";
3596 name
= get_DW_AT_name (attr
);
3601 return "DW_AT_<unknown>";
3604 /* Convert a DWARF value form code into its string name. */
3607 dwarf_form_name (unsigned int form
)
3609 const char *name
= get_DW_FORM_name (form
);
3614 return "DW_FORM_<unknown>";
3617 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3618 instance of an inlined instance of a decl which is local to an inline
3619 function, so we have to trace all of the way back through the origin chain
3620 to find out what sort of node actually served as the original seed for the
3624 decl_ultimate_origin (const_tree decl
)
3626 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3629 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3630 nodes in the function to point to themselves; ignore that if
3631 we're trying to output the abstract instance of this function. */
3632 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3635 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3636 most distant ancestor, this should never happen. */
3637 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3639 return DECL_ABSTRACT_ORIGIN (decl
);
3642 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3643 of a virtual function may refer to a base class, so we check the 'this'
3647 decl_class_context (tree decl
)
3649 tree context
= NULL_TREE
;
3651 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3652 context
= DECL_CONTEXT (decl
);
3654 context
= TYPE_MAIN_VARIANT
3655 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3657 if (context
&& !TYPE_P (context
))
3658 context
= NULL_TREE
;
3663 /* Add an attribute/value pair to a DIE. */
3666 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3668 /* Maybe this should be an assert? */
3672 vec_safe_reserve (die
->die_attr
, 1);
3673 vec_safe_push (die
->die_attr
, *attr
);
3676 static inline enum dw_val_class
3677 AT_class (dw_attr_ref a
)
3679 return a
->dw_attr_val
.val_class
;
3682 /* Return the index for any attribute that will be referenced with a
3683 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3684 are stored in dw_attr_val.v.val_str for reference counting
3687 static inline unsigned int
3688 AT_index (dw_attr_ref a
)
3690 if (AT_class (a
) == dw_val_class_str
)
3691 return a
->dw_attr_val
.v
.val_str
->index
;
3692 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3693 return a
->dw_attr_val
.val_entry
->index
;
3697 /* Add a flag value attribute to a DIE. */
3700 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3704 attr
.dw_attr
= attr_kind
;
3705 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3706 attr
.dw_attr_val
.val_entry
= NULL
;
3707 attr
.dw_attr_val
.v
.val_flag
= flag
;
3708 add_dwarf_attr (die
, &attr
);
3711 static inline unsigned
3712 AT_flag (dw_attr_ref a
)
3714 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3715 return a
->dw_attr_val
.v
.val_flag
;
3718 /* Add a signed integer attribute value to a DIE. */
3721 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3725 attr
.dw_attr
= attr_kind
;
3726 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3727 attr
.dw_attr_val
.val_entry
= NULL
;
3728 attr
.dw_attr_val
.v
.val_int
= int_val
;
3729 add_dwarf_attr (die
, &attr
);
3732 static inline HOST_WIDE_INT
3733 AT_int (dw_attr_ref a
)
3735 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3736 return a
->dw_attr_val
.v
.val_int
;
3739 /* Add an unsigned integer attribute value to a DIE. */
3742 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3743 unsigned HOST_WIDE_INT unsigned_val
)
3747 attr
.dw_attr
= attr_kind
;
3748 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3749 attr
.dw_attr_val
.val_entry
= NULL
;
3750 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3751 add_dwarf_attr (die
, &attr
);
3754 static inline unsigned HOST_WIDE_INT
3755 AT_unsigned (dw_attr_ref a
)
3757 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3758 return a
->dw_attr_val
.v
.val_unsigned
;
3761 /* Add an unsigned double integer attribute value to a DIE. */
3764 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3765 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3769 attr
.dw_attr
= attr_kind
;
3770 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3771 attr
.dw_attr_val
.val_entry
= NULL
;
3772 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3773 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3774 add_dwarf_attr (die
, &attr
);
3777 /* Add a floating point attribute value to a DIE and return it. */
3780 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3781 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3785 attr
.dw_attr
= attr_kind
;
3786 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3787 attr
.dw_attr_val
.val_entry
= NULL
;
3788 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3789 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3790 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3791 add_dwarf_attr (die
, &attr
);
3794 /* Add an 8-byte data attribute value to a DIE. */
3797 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3798 unsigned char data8
[8])
3802 attr
.dw_attr
= attr_kind
;
3803 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3804 attr
.dw_attr_val
.val_entry
= NULL
;
3805 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3806 add_dwarf_attr (die
, &attr
);
3809 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3810 dwarf_split_debug_info, address attributes in dies destined for the
3811 final executable have force_direct set to avoid using indexed
3815 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3821 lbl_id
= xstrdup (lbl_low
);
3822 attr
.dw_attr
= DW_AT_low_pc
;
3823 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3824 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3825 if (dwarf_split_debug_info
&& !force_direct
)
3826 attr
.dw_attr_val
.val_entry
3827 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3829 attr
.dw_attr_val
.val_entry
= NULL
;
3830 add_dwarf_attr (die
, &attr
);
3832 attr
.dw_attr
= DW_AT_high_pc
;
3833 if (dwarf_version
< 4)
3834 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3836 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3837 lbl_id
= xstrdup (lbl_high
);
3838 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3839 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3840 && dwarf_split_debug_info
&& !force_direct
)
3841 attr
.dw_attr_val
.val_entry
3842 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3844 attr
.dw_attr_val
.val_entry
= NULL
;
3845 add_dwarf_attr (die
, &attr
);
3848 /* Hash and equality functions for debug_str_hash. */
3851 debug_str_do_hash (const void *x
)
3853 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3857 debug_str_eq (const void *x1
, const void *x2
)
3859 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3860 (const char *)x2
) == 0;
3863 /* Add STR to the given string hash table. */
3865 static struct indirect_string_node
*
3866 find_AT_string_in_table (const char *str
, htab_t table
)
3868 struct indirect_string_node
*node
;
3871 slot
= htab_find_slot_with_hash (table
, str
,
3872 htab_hash_string (str
), INSERT
);
3875 node
= ggc_alloc_cleared_indirect_string_node ();
3876 node
->str
= ggc_strdup (str
);
3880 node
= (struct indirect_string_node
*) *slot
;
3886 /* Add STR to the indirect string hash table. */
3888 static struct indirect_string_node
*
3889 find_AT_string (const char *str
)
3891 if (! debug_str_hash
)
3892 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3893 debug_str_eq
, NULL
);
3895 return find_AT_string_in_table (str
, debug_str_hash
);
3898 /* Add a string attribute value to a DIE. */
3901 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3904 struct indirect_string_node
*node
;
3906 node
= find_AT_string (str
);
3908 attr
.dw_attr
= attr_kind
;
3909 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3910 attr
.dw_attr_val
.val_entry
= NULL
;
3911 attr
.dw_attr_val
.v
.val_str
= node
;
3912 add_dwarf_attr (die
, &attr
);
3915 static inline const char *
3916 AT_string (dw_attr_ref a
)
3918 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3919 return a
->dw_attr_val
.v
.val_str
->str
;
3922 /* Call this function directly to bypass AT_string_form's logic to put
3923 the string inline in the die. */
3926 set_indirect_string (struct indirect_string_node
*node
)
3929 /* Already indirect is a no op. */
3930 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3932 gcc_assert (node
->label
);
3935 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3936 ++dw2_string_counter
;
3937 node
->label
= xstrdup (label
);
3939 if (!dwarf_split_debug_info
)
3941 node
->form
= DW_FORM_strp
;
3942 node
->index
= NOT_INDEXED
;
3946 node
->form
= DW_FORM_GNU_str_index
;
3947 node
->index
= NO_INDEX_ASSIGNED
;
3951 /* Find out whether a string should be output inline in DIE
3952 or out-of-line in .debug_str section. */
3954 static enum dwarf_form
3955 find_string_form (struct indirect_string_node
*node
)
3962 len
= strlen (node
->str
) + 1;
3964 /* If the string is shorter or equal to the size of the reference, it is
3965 always better to put it inline. */
3966 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3967 return node
->form
= DW_FORM_string
;
3969 /* If we cannot expect the linker to merge strings in .debug_str
3970 section, only put it into .debug_str if it is worth even in this
3972 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3973 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3974 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3975 return node
->form
= DW_FORM_string
;
3977 set_indirect_string (node
);
3982 /* Find out whether the string referenced from the attribute should be
3983 output inline in DIE or out-of-line in .debug_str section. */
3985 static enum dwarf_form
3986 AT_string_form (dw_attr_ref a
)
3988 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3989 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3992 /* Add a DIE reference attribute value to a DIE. */
3995 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3999 #ifdef ENABLE_CHECKING
4000 gcc_assert (targ_die
!= NULL
);
4002 /* With LTO we can end up trying to reference something we didn't create
4003 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4004 if (targ_die
== NULL
)
4008 attr
.dw_attr
= attr_kind
;
4009 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4010 attr
.dw_attr_val
.val_entry
= NULL
;
4011 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4012 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4013 add_dwarf_attr (die
, &attr
);
4016 /* Change DIE reference REF to point to NEW_DIE instead. */
4019 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4021 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4022 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4023 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4026 /* Add an AT_specification attribute to a DIE, and also make the back
4027 pointer from the specification to the definition. */
4030 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4032 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4033 gcc_assert (!targ_die
->die_definition
);
4034 targ_die
->die_definition
= die
;
4037 static inline dw_die_ref
4038 AT_ref (dw_attr_ref a
)
4040 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4041 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4045 AT_ref_external (dw_attr_ref a
)
4047 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4048 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4054 set_AT_ref_external (dw_attr_ref a
, int i
)
4056 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4057 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4060 /* Add an FDE reference attribute value to a DIE. */
4063 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4067 attr
.dw_attr
= attr_kind
;
4068 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4069 attr
.dw_attr_val
.val_entry
= NULL
;
4070 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4071 add_dwarf_attr (die
, &attr
);
4074 /* Add a location description attribute value to a DIE. */
4077 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4081 attr
.dw_attr
= attr_kind
;
4082 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4083 attr
.dw_attr_val
.val_entry
= NULL
;
4084 attr
.dw_attr_val
.v
.val_loc
= loc
;
4085 add_dwarf_attr (die
, &attr
);
4088 static inline dw_loc_descr_ref
4089 AT_loc (dw_attr_ref a
)
4091 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4092 return a
->dw_attr_val
.v
.val_loc
;
4096 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4100 attr
.dw_attr
= attr_kind
;
4101 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4102 attr
.dw_attr_val
.val_entry
= NULL
;
4103 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4104 add_dwarf_attr (die
, &attr
);
4105 have_location_lists
= true;
4108 static inline dw_loc_list_ref
4109 AT_loc_list (dw_attr_ref a
)
4111 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4112 return a
->dw_attr_val
.v
.val_loc_list
;
4115 static inline dw_loc_list_ref
*
4116 AT_loc_list_ptr (dw_attr_ref a
)
4118 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4119 return &a
->dw_attr_val
.v
.val_loc_list
;
4122 /* Table of entries into the .debug_addr section. */
4124 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4126 /* Hash an address_table_entry. */
4129 addr_table_entry_do_hash (const void *x
)
4131 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4135 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4136 case ate_kind_rtx_dtprel
:
4137 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4138 case ate_kind_label
:
4139 return htab_hash_string (a
->addr
.label
);
4145 /* Determine equality for two address_table_entries. */
4148 addr_table_entry_eq (const void *x1
, const void *x2
)
4150 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4151 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4153 if (a1
->kind
!= a2
->kind
)
4158 case ate_kind_rtx_dtprel
:
4159 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4160 case ate_kind_label
:
4161 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4167 /* Initialize an addr_table_entry. */
4170 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4176 case ate_kind_rtx_dtprel
:
4177 e
->addr
.rtl
= (rtx
) addr
;
4179 case ate_kind_label
:
4180 e
->addr
.label
= (char *) addr
;
4184 e
->index
= NO_INDEX_ASSIGNED
;
4187 /* Add attr to the address table entry to the table. Defer setting an
4188 index until output time. */
4190 static addr_table_entry
*
4191 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4193 addr_table_entry
*node
;
4194 addr_table_entry finder
;
4197 gcc_assert (dwarf_split_debug_info
);
4198 if (! addr_index_table
)
4199 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4200 addr_table_entry_eq
, NULL
);
4201 init_addr_table_entry (&finder
, kind
, addr
);
4202 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4204 if (*slot
== HTAB_EMPTY_ENTRY
)
4206 node
= ggc_alloc_cleared_addr_table_entry ();
4207 init_addr_table_entry (node
, kind
, addr
);
4211 node
= (addr_table_entry
*) *slot
;
4217 /* Remove an entry from the addr table by decrementing its refcount.
4218 Strictly, decrementing the refcount would be enough, but the
4219 assertion that the entry is actually in the table has found
4223 remove_addr_table_entry (addr_table_entry
*entry
)
4225 addr_table_entry
*node
;
4227 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4228 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4229 /* After an index is assigned, the table is frozen. */
4230 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4234 /* Given a location list, remove all addresses it refers to from the
4238 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4240 for (; descr
; descr
= descr
->dw_loc_next
)
4241 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4243 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4244 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4248 /* A helper function for dwarf2out_finish called through
4249 htab_traverse. Assign an addr_table_entry its index. All entries
4250 must be collected into the table when this function is called,
4251 because the indexing code relies on htab_traverse to traverse nodes
4252 in the same order for each run. */
4255 index_addr_table_entry (void **h
, void *v
)
4257 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4258 unsigned int *index
= (unsigned int *) v
;
4260 /* Don't index unreferenced nodes. */
4261 if (node
->refcount
== 0)
4264 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4265 node
->index
= *index
;
4271 /* Add an address constant attribute value to a DIE. When using
4272 dwarf_split_debug_info, address attributes in dies destined for the
4273 final executable should be direct references--setting the parameter
4274 force_direct ensures this behavior. */
4277 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4282 attr
.dw_attr
= attr_kind
;
4283 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4284 attr
.dw_attr_val
.v
.val_addr
= addr
;
4285 if (dwarf_split_debug_info
&& !force_direct
)
4286 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4288 attr
.dw_attr_val
.val_entry
= NULL
;
4289 add_dwarf_attr (die
, &attr
);
4292 /* Get the RTX from to an address DIE attribute. */
4295 AT_addr (dw_attr_ref a
)
4297 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4298 return a
->dw_attr_val
.v
.val_addr
;
4301 /* Add a file attribute value to a DIE. */
4304 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4305 struct dwarf_file_data
*fd
)
4309 attr
.dw_attr
= attr_kind
;
4310 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4311 attr
.dw_attr_val
.val_entry
= NULL
;
4312 attr
.dw_attr_val
.v
.val_file
= fd
;
4313 add_dwarf_attr (die
, &attr
);
4316 /* Get the dwarf_file_data from a file DIE attribute. */
4318 static inline struct dwarf_file_data
*
4319 AT_file (dw_attr_ref a
)
4321 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4322 return a
->dw_attr_val
.v
.val_file
;
4325 /* Add a vms delta attribute value to a DIE. */
4328 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4329 const char *lbl1
, const char *lbl2
)
4333 attr
.dw_attr
= attr_kind
;
4334 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4335 attr
.dw_attr_val
.val_entry
= NULL
;
4336 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4337 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4338 add_dwarf_attr (die
, &attr
);
4341 /* Add a label identifier attribute value to a DIE. */
4344 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4349 attr
.dw_attr
= attr_kind
;
4350 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4351 attr
.dw_attr_val
.val_entry
= NULL
;
4352 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4353 if (dwarf_split_debug_info
)
4354 attr
.dw_attr_val
.val_entry
4355 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4357 add_dwarf_attr (die
, &attr
);
4360 /* Add a section offset attribute value to a DIE, an offset into the
4361 debug_line section. */
4364 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4369 attr
.dw_attr
= attr_kind
;
4370 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4371 attr
.dw_attr_val
.val_entry
= NULL
;
4372 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4373 add_dwarf_attr (die
, &attr
);
4376 /* Add a section offset attribute value to a DIE, an offset into the
4377 debug_macinfo section. */
4380 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4385 attr
.dw_attr
= attr_kind
;
4386 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4387 attr
.dw_attr_val
.val_entry
= NULL
;
4388 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4389 add_dwarf_attr (die
, &attr
);
4392 /* Add an offset attribute value to a DIE. */
4395 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4396 unsigned HOST_WIDE_INT offset
)
4400 attr
.dw_attr
= attr_kind
;
4401 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4402 attr
.dw_attr_val
.val_entry
= NULL
;
4403 attr
.dw_attr_val
.v
.val_offset
= offset
;
4404 add_dwarf_attr (die
, &attr
);
4407 /* Add a range_list attribute value to a DIE. When using
4408 dwarf_split_debug_info, address attributes in dies destined for the
4409 final executable should be direct references--setting the parameter
4410 force_direct ensures this behavior. */
4412 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4413 #define RELOCATED_OFFSET (NULL)
4416 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4417 long unsigned int offset
, bool force_direct
)
4421 attr
.dw_attr
= attr_kind
;
4422 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4423 /* For the range_list attribute, use val_entry to store whether the
4424 offset should follow split-debug-info or normal semantics. This
4425 value is read in output_range_list_offset. */
4426 if (dwarf_split_debug_info
&& !force_direct
)
4427 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4429 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4430 attr
.dw_attr_val
.v
.val_offset
= offset
;
4431 add_dwarf_attr (die
, &attr
);
4434 /* Return the start label of a delta attribute. */
4436 static inline const char *
4437 AT_vms_delta1 (dw_attr_ref a
)
4439 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4440 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4443 /* Return the end label of a delta attribute. */
4445 static inline const char *
4446 AT_vms_delta2 (dw_attr_ref a
)
4448 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4449 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4452 static inline const char *
4453 AT_lbl (dw_attr_ref a
)
4455 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4456 || AT_class (a
) == dw_val_class_lineptr
4457 || AT_class (a
) == dw_val_class_macptr
4458 || AT_class (a
) == dw_val_class_high_pc
));
4459 return a
->dw_attr_val
.v
.val_lbl_id
;
4462 /* Get the attribute of type attr_kind. */
4465 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4469 dw_die_ref spec
= NULL
;
4474 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4475 if (a
->dw_attr
== attr_kind
)
4477 else if (a
->dw_attr
== DW_AT_specification
4478 || a
->dw_attr
== DW_AT_abstract_origin
)
4482 return get_AT (spec
, attr_kind
);
4487 /* Returns the parent of the declaration of DIE. */
4490 get_die_parent (dw_die_ref die
)
4497 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4498 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4501 return die
->die_parent
;
4504 /* Return the "low pc" attribute value, typically associated with a subprogram
4505 DIE. Return null if the "low pc" attribute is either not present, or if it
4506 cannot be represented as an assembler label identifier. */
4508 static inline const char *
4509 get_AT_low_pc (dw_die_ref die
)
4511 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4513 return a
? AT_lbl (a
) : NULL
;
4516 /* Return the "high pc" attribute value, typically associated with a subprogram
4517 DIE. Return null if the "high pc" attribute is either not present, or if it
4518 cannot be represented as an assembler label identifier. */
4520 static inline const char *
4521 get_AT_hi_pc (dw_die_ref die
)
4523 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4525 return a
? AT_lbl (a
) : NULL
;
4528 /* Return the value of the string attribute designated by ATTR_KIND, or
4529 NULL if it is not present. */
4531 static inline const char *
4532 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4534 dw_attr_ref a
= get_AT (die
, attr_kind
);
4536 return a
? AT_string (a
) : NULL
;
4539 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4540 if it is not present. */
4543 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4545 dw_attr_ref a
= get_AT (die
, attr_kind
);
4547 return a
? AT_flag (a
) : 0;
4550 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4551 if it is not present. */
4553 static inline unsigned
4554 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4556 dw_attr_ref a
= get_AT (die
, attr_kind
);
4558 return a
? AT_unsigned (a
) : 0;
4561 static inline dw_die_ref
4562 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4564 dw_attr_ref a
= get_AT (die
, attr_kind
);
4566 return a
? AT_ref (a
) : NULL
;
4569 static inline struct dwarf_file_data
*
4570 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4572 dw_attr_ref a
= get_AT (die
, attr_kind
);
4574 return a
? AT_file (a
) : NULL
;
4577 /* Return TRUE if the language is C++. */
4582 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4584 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4587 /* Return TRUE if the language is Java. */
4592 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4594 return lang
== DW_LANG_Java
;
4597 /* Return TRUE if the language is Fortran. */
4602 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4604 return (lang
== DW_LANG_Fortran77
4605 || lang
== DW_LANG_Fortran90
4606 || lang
== DW_LANG_Fortran95
);
4609 /* Return TRUE if the language is Ada. */
4614 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4616 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4619 /* Remove the specified attribute if present. */
4622 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4630 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4631 if (a
->dw_attr
== attr_kind
)
4633 if (AT_class (a
) == dw_val_class_str
)
4634 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4635 a
->dw_attr_val
.v
.val_str
->refcount
--;
4637 /* vec::ordered_remove should help reduce the number of abbrevs
4639 die
->die_attr
->ordered_remove (ix
);
4644 /* Remove CHILD from its parent. PREV must have the property that
4645 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4648 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4650 gcc_assert (child
->die_parent
== prev
->die_parent
);
4651 gcc_assert (prev
->die_sib
== child
);
4654 gcc_assert (child
->die_parent
->die_child
== child
);
4658 prev
->die_sib
= child
->die_sib
;
4659 if (child
->die_parent
->die_child
== child
)
4660 child
->die_parent
->die_child
= prev
;
4663 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4664 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4667 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4669 dw_die_ref parent
= old_child
->die_parent
;
4671 gcc_assert (parent
== prev
->die_parent
);
4672 gcc_assert (prev
->die_sib
== old_child
);
4674 new_child
->die_parent
= parent
;
4675 if (prev
== old_child
)
4677 gcc_assert (parent
->die_child
== old_child
);
4678 new_child
->die_sib
= new_child
;
4682 prev
->die_sib
= new_child
;
4683 new_child
->die_sib
= old_child
->die_sib
;
4685 if (old_child
->die_parent
->die_child
== old_child
)
4686 old_child
->die_parent
->die_child
= new_child
;
4689 /* Move all children from OLD_PARENT to NEW_PARENT. */
4692 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4695 new_parent
->die_child
= old_parent
->die_child
;
4696 old_parent
->die_child
= NULL
;
4697 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4700 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4704 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4710 dw_die_ref prev
= c
;
4712 while (c
->die_tag
== tag
)
4714 remove_child_with_prev (c
, prev
);
4715 /* Might have removed every child. */
4716 if (c
== c
->die_sib
)
4720 } while (c
!= die
->die_child
);
4723 /* Add a CHILD_DIE as the last child of DIE. */
4726 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4728 /* FIXME this should probably be an assert. */
4729 if (! die
|| ! child_die
)
4731 gcc_assert (die
!= child_die
);
4733 child_die
->die_parent
= die
;
4736 child_die
->die_sib
= die
->die_child
->die_sib
;
4737 die
->die_child
->die_sib
= child_die
;
4740 child_die
->die_sib
= child_die
;
4741 die
->die_child
= child_die
;
4744 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4745 is the specification, to the end of PARENT's list of children.
4746 This is done by removing and re-adding it. */
4749 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4753 /* We want the declaration DIE from inside the class, not the
4754 specification DIE at toplevel. */
4755 if (child
->die_parent
!= parent
)
4757 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4763 gcc_assert (child
->die_parent
== parent
4764 || (child
->die_parent
4765 == get_AT_ref (parent
, DW_AT_specification
)));
4767 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4768 if (p
->die_sib
== child
)
4770 remove_child_with_prev (child
, p
);
4774 add_child_die (parent
, child
);
4777 /* Return a pointer to a newly created DIE node. */
4779 static inline dw_die_ref
4780 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4782 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4784 die
->die_tag
= tag_value
;
4786 if (parent_die
!= NULL
)
4787 add_child_die (parent_die
, die
);
4790 limbo_die_node
*limbo_node
;
4792 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4793 limbo_node
->die
= die
;
4794 limbo_node
->created_for
= t
;
4795 limbo_node
->next
= limbo_die_list
;
4796 limbo_die_list
= limbo_node
;
4802 /* Return the DIE associated with the given type specifier. */
4804 static inline dw_die_ref
4805 lookup_type_die (tree type
)
4807 return TYPE_SYMTAB_DIE (type
);
4810 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4811 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4812 anonymous type instead the one of the naming typedef. */
4814 static inline dw_die_ref
4815 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4818 && TREE_CODE (type
) == RECORD_TYPE
4820 && type_die
->die_tag
== DW_TAG_typedef
4821 && is_naming_typedef_decl (TYPE_NAME (type
)))
4822 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4826 /* Like lookup_type_die, but if type is an anonymous type named by a
4827 typedef[1], return the DIE of the anonymous type instead the one of
4828 the naming typedef. This is because in gen_typedef_die, we did
4829 equate the anonymous struct named by the typedef with the DIE of
4830 the naming typedef. So by default, lookup_type_die on an anonymous
4831 struct yields the DIE of the naming typedef.
4833 [1]: Read the comment of is_naming_typedef_decl to learn about what
4834 a naming typedef is. */
4836 static inline dw_die_ref
4837 lookup_type_die_strip_naming_typedef (tree type
)
4839 dw_die_ref die
= lookup_type_die (type
);
4840 return strip_naming_typedef (type
, die
);
4843 /* Equate a DIE to a given type specifier. */
4846 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4848 TYPE_SYMTAB_DIE (type
) = type_die
;
4851 /* Returns a hash value for X (which really is a die_struct). */
4854 decl_die_table_hash (const void *x
)
4856 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4859 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4862 decl_die_table_eq (const void *x
, const void *y
)
4864 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4867 /* Return the DIE associated with a given declaration. */
4869 static inline dw_die_ref
4870 lookup_decl_die (tree decl
)
4872 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4875 /* Returns a hash value for X (which really is a var_loc_list). */
4878 decl_loc_table_hash (const void *x
)
4880 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4883 /* Return nonzero if decl_id of var_loc_list X is the same as
4887 decl_loc_table_eq (const void *x
, const void *y
)
4889 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4892 /* Return the var_loc list associated with a given declaration. */
4894 static inline var_loc_list
*
4895 lookup_decl_loc (const_tree decl
)
4897 if (!decl_loc_table
)
4899 return (var_loc_list
*)
4900 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4903 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4906 cached_dw_loc_list_table_hash (const void *x
)
4908 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4911 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4915 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4917 return (((const cached_dw_loc_list
*) x
)->decl_id
4918 == DECL_UID ((const_tree
) y
));
4921 /* Equate a DIE to a particular declaration. */
4924 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4926 unsigned int decl_id
= DECL_UID (decl
);
4929 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4931 decl_die
->decl_id
= decl_id
;
4934 /* Return how many bits covers PIECE EXPR_LIST. */
4937 decl_piece_bitsize (rtx piece
)
4939 int ret
= (int) GET_MODE (piece
);
4942 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4943 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4944 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4947 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4950 decl_piece_varloc_ptr (rtx piece
)
4952 if ((int) GET_MODE (piece
))
4953 return &XEXP (piece
, 0);
4955 return &XEXP (XEXP (piece
, 0), 1);
4958 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4959 Next is the chain of following piece nodes. */
4962 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4964 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4965 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4967 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4972 /* Return rtx that should be stored into loc field for
4973 LOC_NOTE and BITPOS/BITSIZE. */
4976 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4977 HOST_WIDE_INT bitsize
)
4981 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4983 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4988 /* This function either modifies location piece list *DEST in
4989 place (if SRC and INNER is NULL), or copies location piece list
4990 *SRC to *DEST while modifying it. Location BITPOS is modified
4991 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4992 not copied and if needed some padding around it is added.
4993 When modifying in place, DEST should point to EXPR_LIST where
4994 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4995 to the start of the whole list and INNER points to the EXPR_LIST
4996 where earlier pieces cover PIECE_BITPOS bits. */
4999 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5000 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5001 HOST_WIDE_INT bitsize
, rtx loc_note
)
5004 bool copy
= inner
!= NULL
;
5008 /* First copy all nodes preceding the current bitpos. */
5009 while (src
!= inner
)
5011 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5012 decl_piece_bitsize (*src
), NULL_RTX
);
5013 dest
= &XEXP (*dest
, 1);
5014 src
= &XEXP (*src
, 1);
5017 /* Add padding if needed. */
5018 if (bitpos
!= piece_bitpos
)
5020 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5021 copy
? NULL_RTX
: *dest
);
5022 dest
= &XEXP (*dest
, 1);
5024 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5027 /* A piece with correct bitpos and bitsize already exist,
5028 just update the location for it and return. */
5029 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5032 /* Add the piece that changed. */
5033 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5034 dest
= &XEXP (*dest
, 1);
5035 /* Skip over pieces that overlap it. */
5036 diff
= bitpos
- piece_bitpos
+ bitsize
;
5039 while (diff
> 0 && *src
)
5042 diff
-= decl_piece_bitsize (piece
);
5044 src
= &XEXP (piece
, 1);
5047 *src
= XEXP (piece
, 1);
5048 free_EXPR_LIST_node (piece
);
5051 /* Add padding if needed. */
5052 if (diff
< 0 && *src
)
5056 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5057 dest
= &XEXP (*dest
, 1);
5061 /* Finally copy all nodes following it. */
5064 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5065 decl_piece_bitsize (*src
), NULL_RTX
);
5066 dest
= &XEXP (*dest
, 1);
5067 src
= &XEXP (*src
, 1);
5071 /* Add a variable location node to the linked list for DECL. */
5073 static struct var_loc_node
*
5074 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5076 unsigned int decl_id
;
5079 struct var_loc_node
*loc
= NULL
;
5080 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5082 if (TREE_CODE (decl
) == VAR_DECL
5083 && DECL_HAS_DEBUG_EXPR_P (decl
))
5085 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5086 if (handled_component_p (realdecl
)
5087 || (TREE_CODE (realdecl
) == MEM_REF
5088 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5090 HOST_WIDE_INT maxsize
;
5093 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5094 if (!DECL_P (innerdecl
)
5095 || DECL_IGNORED_P (innerdecl
)
5096 || TREE_STATIC (innerdecl
)
5098 || bitpos
+ bitsize
> 256
5099 || bitsize
!= maxsize
)
5105 decl_id
= DECL_UID (decl
);
5106 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5109 temp
= ggc_alloc_cleared_var_loc_list ();
5110 temp
->decl_id
= decl_id
;
5114 temp
= (var_loc_list
*) *slot
;
5116 /* For PARM_DECLs try to keep around the original incoming value,
5117 even if that means we'll emit a zero-range .debug_loc entry. */
5119 && temp
->first
== temp
->last
5120 && TREE_CODE (decl
) == PARM_DECL
5121 && NOTE_P (temp
->first
->loc
)
5122 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5123 && DECL_INCOMING_RTL (decl
)
5124 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5125 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5126 == GET_CODE (DECL_INCOMING_RTL (decl
))
5127 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5129 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5130 NOTE_VAR_LOCATION_LOC (loc_note
))
5131 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5132 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5134 loc
= ggc_alloc_cleared_var_loc_node ();
5135 temp
->first
->next
= loc
;
5137 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5139 else if (temp
->last
)
5141 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5142 rtx
*piece_loc
= NULL
, last_loc_note
;
5143 int piece_bitpos
= 0;
5147 gcc_assert (last
->next
== NULL
);
5149 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5151 piece_loc
= &last
->loc
;
5154 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5155 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5157 piece_bitpos
+= cur_bitsize
;
5158 piece_loc
= &XEXP (*piece_loc
, 1);
5162 /* TEMP->LAST here is either pointer to the last but one or
5163 last element in the chained list, LAST is pointer to the
5165 if (label
&& strcmp (last
->label
, label
) == 0)
5167 /* For SRA optimized variables if there weren't any real
5168 insns since last note, just modify the last node. */
5169 if (piece_loc
!= NULL
)
5171 adjust_piece_list (piece_loc
, NULL
, NULL
,
5172 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5175 /* If the last note doesn't cover any instructions, remove it. */
5176 if (temp
->last
!= last
)
5178 temp
->last
->next
= NULL
;
5181 gcc_assert (strcmp (last
->label
, label
) != 0);
5185 gcc_assert (temp
->first
== temp
->last
5186 || (temp
->first
->next
== temp
->last
5187 && TREE_CODE (decl
) == PARM_DECL
));
5188 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5189 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5193 if (bitsize
== -1 && NOTE_P (last
->loc
))
5194 last_loc_note
= last
->loc
;
5195 else if (piece_loc
!= NULL
5196 && *piece_loc
!= NULL_RTX
5197 && piece_bitpos
== bitpos
5198 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5199 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5201 last_loc_note
= NULL_RTX
;
5202 /* If the current location is the same as the end of the list,
5203 and either both or neither of the locations is uninitialized,
5204 we have nothing to do. */
5205 if (last_loc_note
== NULL_RTX
5206 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5207 NOTE_VAR_LOCATION_LOC (loc_note
)))
5208 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5209 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5210 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5211 == VAR_INIT_STATUS_UNINITIALIZED
)
5212 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5213 == VAR_INIT_STATUS_UNINITIALIZED
))))
5215 /* Add LOC to the end of list and update LAST. If the last
5216 element of the list has been removed above, reuse its
5217 memory for the new node, otherwise allocate a new one. */
5221 memset (loc
, '\0', sizeof (*loc
));
5224 loc
= ggc_alloc_cleared_var_loc_node ();
5225 if (bitsize
== -1 || piece_loc
== NULL
)
5226 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5228 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5229 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5231 /* Ensure TEMP->LAST will point either to the new last but one
5232 element of the chain, or to the last element in it. */
5233 if (last
!= temp
->last
)
5241 loc
= ggc_alloc_cleared_var_loc_node ();
5244 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5249 /* Keep track of the number of spaces used to indent the
5250 output of the debugging routines that print the structure of
5251 the DIE internal representation. */
5252 static int print_indent
;
5254 /* Indent the line the number of spaces given by print_indent. */
5257 print_spaces (FILE *outfile
)
5259 fprintf (outfile
, "%*s", print_indent
, "");
5262 /* Print a type signature in hex. */
5265 print_signature (FILE *outfile
, char *sig
)
5269 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5270 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5273 /* Print the information associated with a given DIE, and its children.
5274 This routine is a debugging aid only. */
5277 print_die (dw_die_ref die
, FILE *outfile
)
5283 print_spaces (outfile
);
5284 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5285 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5287 print_spaces (outfile
);
5288 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5289 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5290 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5292 if (die
->comdat_type_p
)
5294 print_spaces (outfile
);
5295 fprintf (outfile
, " signature: ");
5296 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5297 fprintf (outfile
, "\n");
5300 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5302 print_spaces (outfile
);
5303 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5305 switch (AT_class (a
))
5307 case dw_val_class_addr
:
5308 fprintf (outfile
, "address");
5310 case dw_val_class_offset
:
5311 fprintf (outfile
, "offset");
5313 case dw_val_class_loc
:
5314 fprintf (outfile
, "location descriptor");
5316 case dw_val_class_loc_list
:
5317 fprintf (outfile
, "location list -> label:%s",
5318 AT_loc_list (a
)->ll_symbol
);
5320 case dw_val_class_range_list
:
5321 fprintf (outfile
, "range list");
5323 case dw_val_class_const
:
5324 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5326 case dw_val_class_unsigned_const
:
5327 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5329 case dw_val_class_const_double
:
5330 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5331 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5332 a
->dw_attr_val
.v
.val_double
.high
,
5333 a
->dw_attr_val
.v
.val_double
.low
);
5335 case dw_val_class_vec
:
5336 fprintf (outfile
, "floating-point or vector constant");
5338 case dw_val_class_flag
:
5339 fprintf (outfile
, "%u", AT_flag (a
));
5341 case dw_val_class_die_ref
:
5342 if (AT_ref (a
) != NULL
)
5344 if (AT_ref (a
)->comdat_type_p
)
5346 fprintf (outfile
, "die -> signature: ");
5347 print_signature (outfile
,
5348 AT_ref (a
)->die_id
.die_type_node
->signature
);
5350 else if (AT_ref (a
)->die_id
.die_symbol
)
5351 fprintf (outfile
, "die -> label: %s",
5352 AT_ref (a
)->die_id
.die_symbol
);
5354 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5355 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5358 fprintf (outfile
, "die -> <null>");
5360 case dw_val_class_vms_delta
:
5361 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5362 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5364 case dw_val_class_lbl_id
:
5365 case dw_val_class_lineptr
:
5366 case dw_val_class_macptr
:
5367 case dw_val_class_high_pc
:
5368 fprintf (outfile
, "label: %s", AT_lbl (a
));
5370 case dw_val_class_str
:
5371 if (AT_string (a
) != NULL
)
5372 fprintf (outfile
, "\"%s\"", AT_string (a
));
5374 fprintf (outfile
, "<null>");
5376 case dw_val_class_file
:
5377 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5378 AT_file (a
)->emitted_number
);
5380 case dw_val_class_data8
:
5384 for (i
= 0; i
< 8; i
++)
5385 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5392 fprintf (outfile
, "\n");
5395 if (die
->die_child
!= NULL
)
5398 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5401 if (print_indent
== 0)
5402 fprintf (outfile
, "\n");
5405 /* Print the information collected for a given DIE. */
5408 debug_dwarf_die (dw_die_ref die
)
5410 print_die (die
, stderr
);
5414 debug (die_struct
&ref
)
5416 print_die (&ref
, stderr
);
5420 debug (die_struct
*ptr
)
5425 fprintf (stderr
, "<nil>\n");
5429 /* Print all DWARF information collected for the compilation unit.
5430 This routine is a debugging aid only. */
5436 print_die (comp_unit_die (), stderr
);
5439 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5440 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5441 DIE that marks the start of the DIEs for this include file. */
5444 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5446 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5447 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5449 new_unit
->die_sib
= old_unit
;
5453 /* Close an include-file CU and reopen the enclosing one. */
5456 pop_compile_unit (dw_die_ref old_unit
)
5458 dw_die_ref new_unit
= old_unit
->die_sib
;
5460 old_unit
->die_sib
= NULL
;
5464 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5465 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5466 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5468 /* Calculate the checksum of a location expression. */
5471 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5476 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5478 hash
= hash_loc_operands (loc
, hash
);
5482 /* Calculate the checksum of an attribute. */
5485 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5487 dw_loc_descr_ref loc
;
5490 CHECKSUM (at
->dw_attr
);
5492 /* We don't care that this was compiled with a different compiler
5493 snapshot; if the output is the same, that's what matters. */
5494 if (at
->dw_attr
== DW_AT_producer
)
5497 switch (AT_class (at
))
5499 case dw_val_class_const
:
5500 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5502 case dw_val_class_unsigned_const
:
5503 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5505 case dw_val_class_const_double
:
5506 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5508 case dw_val_class_vec
:
5509 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5510 (at
->dw_attr_val
.v
.val_vec
.length
5511 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5513 case dw_val_class_flag
:
5514 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5516 case dw_val_class_str
:
5517 CHECKSUM_STRING (AT_string (at
));
5520 case dw_val_class_addr
:
5522 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5523 CHECKSUM_STRING (XSTR (r
, 0));
5526 case dw_val_class_offset
:
5527 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5530 case dw_val_class_loc
:
5531 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5532 loc_checksum (loc
, ctx
);
5535 case dw_val_class_die_ref
:
5536 die_checksum (AT_ref (at
), ctx
, mark
);
5539 case dw_val_class_fde_ref
:
5540 case dw_val_class_vms_delta
:
5541 case dw_val_class_lbl_id
:
5542 case dw_val_class_lineptr
:
5543 case dw_val_class_macptr
:
5544 case dw_val_class_high_pc
:
5547 case dw_val_class_file
:
5548 CHECKSUM_STRING (AT_file (at
)->filename
);
5551 case dw_val_class_data8
:
5552 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5560 /* Calculate the checksum of a DIE. */
5563 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5569 /* To avoid infinite recursion. */
5572 CHECKSUM (die
->die_mark
);
5575 die
->die_mark
= ++(*mark
);
5577 CHECKSUM (die
->die_tag
);
5579 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5580 attr_checksum (a
, ctx
, mark
);
5582 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5586 #undef CHECKSUM_BLOCK
5587 #undef CHECKSUM_STRING
5589 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5590 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5591 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5592 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5593 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5594 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5595 #define CHECKSUM_ATTR(FOO) \
5596 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5598 /* Calculate the checksum of a number in signed LEB128 format. */
5601 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5608 byte
= (value
& 0x7f);
5610 more
= !((value
== 0 && (byte
& 0x40) == 0)
5611 || (value
== -1 && (byte
& 0x40) != 0));
5620 /* Calculate the checksum of a number in unsigned LEB128 format. */
5623 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5627 unsigned char byte
= (value
& 0x7f);
5630 /* More bytes to follow. */
5638 /* Checksum the context of the DIE. This adds the names of any
5639 surrounding namespaces or structures to the checksum. */
5642 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5646 int tag
= die
->die_tag
;
5648 if (tag
!= DW_TAG_namespace
5649 && tag
!= DW_TAG_structure_type
5650 && tag
!= DW_TAG_class_type
)
5653 name
= get_AT_string (die
, DW_AT_name
);
5655 spec
= get_AT_ref (die
, DW_AT_specification
);
5659 if (die
->die_parent
!= NULL
)
5660 checksum_die_context (die
->die_parent
, ctx
);
5662 CHECKSUM_ULEB128 ('C');
5663 CHECKSUM_ULEB128 (tag
);
5665 CHECKSUM_STRING (name
);
5668 /* Calculate the checksum of a location expression. */
5671 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5673 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5674 were emitted as a DW_FORM_sdata instead of a location expression. */
5675 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5677 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5678 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5682 /* Otherwise, just checksum the raw location expression. */
5687 CHECKSUM_ULEB128 (loc
->dtprel
);
5688 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5689 hash
= hash_loc_operands (loc
, hash
);
5691 loc
= loc
->dw_loc_next
;
5695 /* Calculate the checksum of an attribute. */
5698 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5699 struct md5_ctx
*ctx
, int *mark
)
5701 dw_loc_descr_ref loc
;
5704 if (AT_class (at
) == dw_val_class_die_ref
)
5706 dw_die_ref target_die
= AT_ref (at
);
5708 /* For pointer and reference types, we checksum only the (qualified)
5709 name of the target type (if there is a name). For friend entries,
5710 we checksum only the (qualified) name of the target type or function.
5711 This allows the checksum to remain the same whether the target type
5712 is complete or not. */
5713 if ((at
->dw_attr
== DW_AT_type
5714 && (tag
== DW_TAG_pointer_type
5715 || tag
== DW_TAG_reference_type
5716 || tag
== DW_TAG_rvalue_reference_type
5717 || tag
== DW_TAG_ptr_to_member_type
))
5718 || (at
->dw_attr
== DW_AT_friend
5719 && tag
== DW_TAG_friend
))
5721 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5723 if (name_attr
!= NULL
)
5725 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5729 CHECKSUM_ULEB128 ('N');
5730 CHECKSUM_ULEB128 (at
->dw_attr
);
5731 if (decl
->die_parent
!= NULL
)
5732 checksum_die_context (decl
->die_parent
, ctx
);
5733 CHECKSUM_ULEB128 ('E');
5734 CHECKSUM_STRING (AT_string (name_attr
));
5739 /* For all other references to another DIE, we check to see if the
5740 target DIE has already been visited. If it has, we emit a
5741 backward reference; if not, we descend recursively. */
5742 if (target_die
->die_mark
> 0)
5744 CHECKSUM_ULEB128 ('R');
5745 CHECKSUM_ULEB128 (at
->dw_attr
);
5746 CHECKSUM_ULEB128 (target_die
->die_mark
);
5750 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5754 target_die
->die_mark
= ++(*mark
);
5755 CHECKSUM_ULEB128 ('T');
5756 CHECKSUM_ULEB128 (at
->dw_attr
);
5757 if (decl
->die_parent
!= NULL
)
5758 checksum_die_context (decl
->die_parent
, ctx
);
5759 die_checksum_ordered (target_die
, ctx
, mark
);
5764 CHECKSUM_ULEB128 ('A');
5765 CHECKSUM_ULEB128 (at
->dw_attr
);
5767 switch (AT_class (at
))
5769 case dw_val_class_const
:
5770 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5771 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5774 case dw_val_class_unsigned_const
:
5775 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5776 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5779 case dw_val_class_const_double
:
5780 CHECKSUM_ULEB128 (DW_FORM_block
);
5781 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5782 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5785 case dw_val_class_vec
:
5786 CHECKSUM_ULEB128 (DW_FORM_block
);
5787 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5788 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5789 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5790 (at
->dw_attr_val
.v
.val_vec
.length
5791 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5794 case dw_val_class_flag
:
5795 CHECKSUM_ULEB128 (DW_FORM_flag
);
5796 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5799 case dw_val_class_str
:
5800 CHECKSUM_ULEB128 (DW_FORM_string
);
5801 CHECKSUM_STRING (AT_string (at
));
5804 case dw_val_class_addr
:
5806 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5807 CHECKSUM_ULEB128 (DW_FORM_string
);
5808 CHECKSUM_STRING (XSTR (r
, 0));
5811 case dw_val_class_offset
:
5812 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5813 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5816 case dw_val_class_loc
:
5817 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5818 loc_checksum_ordered (loc
, ctx
);
5821 case dw_val_class_fde_ref
:
5822 case dw_val_class_lbl_id
:
5823 case dw_val_class_lineptr
:
5824 case dw_val_class_macptr
:
5825 case dw_val_class_high_pc
:
5828 case dw_val_class_file
:
5829 CHECKSUM_ULEB128 (DW_FORM_string
);
5830 CHECKSUM_STRING (AT_file (at
)->filename
);
5833 case dw_val_class_data8
:
5834 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5842 struct checksum_attributes
5844 dw_attr_ref at_name
;
5845 dw_attr_ref at_type
;
5846 dw_attr_ref at_friend
;
5847 dw_attr_ref at_accessibility
;
5848 dw_attr_ref at_address_class
;
5849 dw_attr_ref at_allocated
;
5850 dw_attr_ref at_artificial
;
5851 dw_attr_ref at_associated
;
5852 dw_attr_ref at_binary_scale
;
5853 dw_attr_ref at_bit_offset
;
5854 dw_attr_ref at_bit_size
;
5855 dw_attr_ref at_bit_stride
;
5856 dw_attr_ref at_byte_size
;
5857 dw_attr_ref at_byte_stride
;
5858 dw_attr_ref at_const_value
;
5859 dw_attr_ref at_containing_type
;
5860 dw_attr_ref at_count
;
5861 dw_attr_ref at_data_location
;
5862 dw_attr_ref at_data_member_location
;
5863 dw_attr_ref at_decimal_scale
;
5864 dw_attr_ref at_decimal_sign
;
5865 dw_attr_ref at_default_value
;
5866 dw_attr_ref at_digit_count
;
5867 dw_attr_ref at_discr
;
5868 dw_attr_ref at_discr_list
;
5869 dw_attr_ref at_discr_value
;
5870 dw_attr_ref at_encoding
;
5871 dw_attr_ref at_endianity
;
5872 dw_attr_ref at_explicit
;
5873 dw_attr_ref at_is_optional
;
5874 dw_attr_ref at_location
;
5875 dw_attr_ref at_lower_bound
;
5876 dw_attr_ref at_mutable
;
5877 dw_attr_ref at_ordering
;
5878 dw_attr_ref at_picture_string
;
5879 dw_attr_ref at_prototyped
;
5880 dw_attr_ref at_small
;
5881 dw_attr_ref at_segment
;
5882 dw_attr_ref at_string_length
;
5883 dw_attr_ref at_threads_scaled
;
5884 dw_attr_ref at_upper_bound
;
5885 dw_attr_ref at_use_location
;
5886 dw_attr_ref at_use_UTF8
;
5887 dw_attr_ref at_variable_parameter
;
5888 dw_attr_ref at_virtuality
;
5889 dw_attr_ref at_visibility
;
5890 dw_attr_ref at_vtable_elem_location
;
5893 /* Collect the attributes that we will want to use for the checksum. */
5896 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5901 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5912 attrs
->at_friend
= a
;
5914 case DW_AT_accessibility
:
5915 attrs
->at_accessibility
= a
;
5917 case DW_AT_address_class
:
5918 attrs
->at_address_class
= a
;
5920 case DW_AT_allocated
:
5921 attrs
->at_allocated
= a
;
5923 case DW_AT_artificial
:
5924 attrs
->at_artificial
= a
;
5926 case DW_AT_associated
:
5927 attrs
->at_associated
= a
;
5929 case DW_AT_binary_scale
:
5930 attrs
->at_binary_scale
= a
;
5932 case DW_AT_bit_offset
:
5933 attrs
->at_bit_offset
= a
;
5935 case DW_AT_bit_size
:
5936 attrs
->at_bit_size
= a
;
5938 case DW_AT_bit_stride
:
5939 attrs
->at_bit_stride
= a
;
5941 case DW_AT_byte_size
:
5942 attrs
->at_byte_size
= a
;
5944 case DW_AT_byte_stride
:
5945 attrs
->at_byte_stride
= a
;
5947 case DW_AT_const_value
:
5948 attrs
->at_const_value
= a
;
5950 case DW_AT_containing_type
:
5951 attrs
->at_containing_type
= a
;
5954 attrs
->at_count
= a
;
5956 case DW_AT_data_location
:
5957 attrs
->at_data_location
= a
;
5959 case DW_AT_data_member_location
:
5960 attrs
->at_data_member_location
= a
;
5962 case DW_AT_decimal_scale
:
5963 attrs
->at_decimal_scale
= a
;
5965 case DW_AT_decimal_sign
:
5966 attrs
->at_decimal_sign
= a
;
5968 case DW_AT_default_value
:
5969 attrs
->at_default_value
= a
;
5971 case DW_AT_digit_count
:
5972 attrs
->at_digit_count
= a
;
5975 attrs
->at_discr
= a
;
5977 case DW_AT_discr_list
:
5978 attrs
->at_discr_list
= a
;
5980 case DW_AT_discr_value
:
5981 attrs
->at_discr_value
= a
;
5983 case DW_AT_encoding
:
5984 attrs
->at_encoding
= a
;
5986 case DW_AT_endianity
:
5987 attrs
->at_endianity
= a
;
5989 case DW_AT_explicit
:
5990 attrs
->at_explicit
= a
;
5992 case DW_AT_is_optional
:
5993 attrs
->at_is_optional
= a
;
5995 case DW_AT_location
:
5996 attrs
->at_location
= a
;
5998 case DW_AT_lower_bound
:
5999 attrs
->at_lower_bound
= a
;
6002 attrs
->at_mutable
= a
;
6004 case DW_AT_ordering
:
6005 attrs
->at_ordering
= a
;
6007 case DW_AT_picture_string
:
6008 attrs
->at_picture_string
= a
;
6010 case DW_AT_prototyped
:
6011 attrs
->at_prototyped
= a
;
6014 attrs
->at_small
= a
;
6017 attrs
->at_segment
= a
;
6019 case DW_AT_string_length
:
6020 attrs
->at_string_length
= a
;
6022 case DW_AT_threads_scaled
:
6023 attrs
->at_threads_scaled
= a
;
6025 case DW_AT_upper_bound
:
6026 attrs
->at_upper_bound
= a
;
6028 case DW_AT_use_location
:
6029 attrs
->at_use_location
= a
;
6031 case DW_AT_use_UTF8
:
6032 attrs
->at_use_UTF8
= a
;
6034 case DW_AT_variable_parameter
:
6035 attrs
->at_variable_parameter
= a
;
6037 case DW_AT_virtuality
:
6038 attrs
->at_virtuality
= a
;
6040 case DW_AT_visibility
:
6041 attrs
->at_visibility
= a
;
6043 case DW_AT_vtable_elem_location
:
6044 attrs
->at_vtable_elem_location
= a
;
6052 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6055 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6059 struct checksum_attributes attrs
;
6061 CHECKSUM_ULEB128 ('D');
6062 CHECKSUM_ULEB128 (die
->die_tag
);
6064 memset (&attrs
, 0, sizeof (attrs
));
6066 decl
= get_AT_ref (die
, DW_AT_specification
);
6068 collect_checksum_attributes (&attrs
, decl
);
6069 collect_checksum_attributes (&attrs
, die
);
6071 CHECKSUM_ATTR (attrs
.at_name
);
6072 CHECKSUM_ATTR (attrs
.at_accessibility
);
6073 CHECKSUM_ATTR (attrs
.at_address_class
);
6074 CHECKSUM_ATTR (attrs
.at_allocated
);
6075 CHECKSUM_ATTR (attrs
.at_artificial
);
6076 CHECKSUM_ATTR (attrs
.at_associated
);
6077 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6078 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6079 CHECKSUM_ATTR (attrs
.at_bit_size
);
6080 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6081 CHECKSUM_ATTR (attrs
.at_byte_size
);
6082 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6083 CHECKSUM_ATTR (attrs
.at_const_value
);
6084 CHECKSUM_ATTR (attrs
.at_containing_type
);
6085 CHECKSUM_ATTR (attrs
.at_count
);
6086 CHECKSUM_ATTR (attrs
.at_data_location
);
6087 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6088 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6089 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6090 CHECKSUM_ATTR (attrs
.at_default_value
);
6091 CHECKSUM_ATTR (attrs
.at_digit_count
);
6092 CHECKSUM_ATTR (attrs
.at_discr
);
6093 CHECKSUM_ATTR (attrs
.at_discr_list
);
6094 CHECKSUM_ATTR (attrs
.at_discr_value
);
6095 CHECKSUM_ATTR (attrs
.at_encoding
);
6096 CHECKSUM_ATTR (attrs
.at_endianity
);
6097 CHECKSUM_ATTR (attrs
.at_explicit
);
6098 CHECKSUM_ATTR (attrs
.at_is_optional
);
6099 CHECKSUM_ATTR (attrs
.at_location
);
6100 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6101 CHECKSUM_ATTR (attrs
.at_mutable
);
6102 CHECKSUM_ATTR (attrs
.at_ordering
);
6103 CHECKSUM_ATTR (attrs
.at_picture_string
);
6104 CHECKSUM_ATTR (attrs
.at_prototyped
);
6105 CHECKSUM_ATTR (attrs
.at_small
);
6106 CHECKSUM_ATTR (attrs
.at_segment
);
6107 CHECKSUM_ATTR (attrs
.at_string_length
);
6108 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6109 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6110 CHECKSUM_ATTR (attrs
.at_use_location
);
6111 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6112 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6113 CHECKSUM_ATTR (attrs
.at_virtuality
);
6114 CHECKSUM_ATTR (attrs
.at_visibility
);
6115 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6116 CHECKSUM_ATTR (attrs
.at_type
);
6117 CHECKSUM_ATTR (attrs
.at_friend
);
6119 /* Checksum the child DIEs. */
6122 dw_attr_ref name_attr
;
6125 name_attr
= get_AT (c
, DW_AT_name
);
6126 if (is_template_instantiation (c
))
6128 /* Ignore instantiations of member type and function templates. */
6130 else if (name_attr
!= NULL
6131 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6133 /* Use a shallow checksum for named nested types and member
6135 CHECKSUM_ULEB128 ('S');
6136 CHECKSUM_ULEB128 (c
->die_tag
);
6137 CHECKSUM_STRING (AT_string (name_attr
));
6141 /* Use a deep checksum for other children. */
6142 /* Mark this DIE so it gets processed when unmarking. */
6143 if (c
->die_mark
== 0)
6145 die_checksum_ordered (c
, ctx
, mark
);
6147 } while (c
!= die
->die_child
);
6149 CHECKSUM_ULEB128 (0);
6152 /* Add a type name and tag to a hash. */
6154 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6156 CHECKSUM_ULEB128 (tag
);
6157 CHECKSUM_STRING (name
);
6161 #undef CHECKSUM_STRING
6162 #undef CHECKSUM_ATTR
6163 #undef CHECKSUM_LEB128
6164 #undef CHECKSUM_ULEB128
6166 /* Generate the type signature for DIE. This is computed by generating an
6167 MD5 checksum over the DIE's tag, its relevant attributes, and its
6168 children. Attributes that are references to other DIEs are processed
6169 by recursion, using the MARK field to prevent infinite recursion.
6170 If the DIE is nested inside a namespace or another type, we also
6171 need to include that context in the signature. The lower 64 bits
6172 of the resulting MD5 checksum comprise the signature. */
6175 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6179 unsigned char checksum
[16];
6184 name
= get_AT_string (die
, DW_AT_name
);
6185 decl
= get_AT_ref (die
, DW_AT_specification
);
6186 parent
= get_die_parent (die
);
6188 /* First, compute a signature for just the type name (and its surrounding
6189 context, if any. This is stored in the type unit DIE for link-time
6190 ODR (one-definition rule) checking. */
6192 if (is_cxx () && name
!= NULL
)
6194 md5_init_ctx (&ctx
);
6196 /* Checksum the names of surrounding namespaces and structures. */
6198 checksum_die_context (parent
, &ctx
);
6200 /* Checksum the current DIE. */
6201 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6202 md5_finish_ctx (&ctx
, checksum
);
6204 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6207 /* Next, compute the complete type signature. */
6209 md5_init_ctx (&ctx
);
6211 die
->die_mark
= mark
;
6213 /* Checksum the names of surrounding namespaces and structures. */
6215 checksum_die_context (parent
, &ctx
);
6217 /* Checksum the DIE and its children. */
6218 die_checksum_ordered (die
, &ctx
, &mark
);
6219 unmark_all_dies (die
);
6220 md5_finish_ctx (&ctx
, checksum
);
6222 /* Store the signature in the type node and link the type DIE and the
6223 type node together. */
6224 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6225 DWARF_TYPE_SIGNATURE_SIZE
);
6226 die
->comdat_type_p
= true;
6227 die
->die_id
.die_type_node
= type_node
;
6228 type_node
->type_die
= die
;
6230 /* If the DIE is a specification, link its declaration to the type node
6234 decl
->comdat_type_p
= true;
6235 decl
->die_id
.die_type_node
= type_node
;
6239 /* Do the location expressions look same? */
6241 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6243 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6244 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6245 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6248 /* Do the values look the same? */
6250 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6252 dw_loc_descr_ref loc1
, loc2
;
6255 if (v1
->val_class
!= v2
->val_class
)
6258 switch (v1
->val_class
)
6260 case dw_val_class_const
:
6261 return v1
->v
.val_int
== v2
->v
.val_int
;
6262 case dw_val_class_unsigned_const
:
6263 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6264 case dw_val_class_const_double
:
6265 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6266 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6267 case dw_val_class_vec
:
6268 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6269 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6271 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6272 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6275 case dw_val_class_flag
:
6276 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6277 case dw_val_class_str
:
6278 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6280 case dw_val_class_addr
:
6281 r1
= v1
->v
.val_addr
;
6282 r2
= v2
->v
.val_addr
;
6283 if (GET_CODE (r1
) != GET_CODE (r2
))
6285 return !rtx_equal_p (r1
, r2
);
6287 case dw_val_class_offset
:
6288 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6290 case dw_val_class_loc
:
6291 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6293 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6294 if (!same_loc_p (loc1
, loc2
, mark
))
6296 return !loc1
&& !loc2
;
6298 case dw_val_class_die_ref
:
6299 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6301 case dw_val_class_fde_ref
:
6302 case dw_val_class_vms_delta
:
6303 case dw_val_class_lbl_id
:
6304 case dw_val_class_lineptr
:
6305 case dw_val_class_macptr
:
6306 case dw_val_class_high_pc
:
6309 case dw_val_class_file
:
6310 return v1
->v
.val_file
== v2
->v
.val_file
;
6312 case dw_val_class_data8
:
6313 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6320 /* Do the attributes look the same? */
6323 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6325 if (at1
->dw_attr
!= at2
->dw_attr
)
6328 /* We don't care that this was compiled with a different compiler
6329 snapshot; if the output is the same, that's what matters. */
6330 if (at1
->dw_attr
== DW_AT_producer
)
6333 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6336 /* Do the dies look the same? */
6339 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6345 /* To avoid infinite recursion. */
6347 return die1
->die_mark
== die2
->die_mark
;
6348 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6350 if (die1
->die_tag
!= die2
->die_tag
)
6353 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6356 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6357 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6360 c1
= die1
->die_child
;
6361 c2
= die2
->die_child
;
6370 if (!same_die_p (c1
, c2
, mark
))
6374 if (c1
== die1
->die_child
)
6376 if (c2
== die2
->die_child
)
6386 /* Do the dies look the same? Wrapper around same_die_p. */
6389 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6392 int ret
= same_die_p (die1
, die2
, &mark
);
6394 unmark_all_dies (die1
);
6395 unmark_all_dies (die2
);
6400 /* The prefix to attach to symbols on DIEs in the current comdat debug
6402 static const char *comdat_symbol_id
;
6404 /* The index of the current symbol within the current comdat CU. */
6405 static unsigned int comdat_symbol_number
;
6407 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6408 children, and set comdat_symbol_id accordingly. */
6411 compute_section_prefix (dw_die_ref unit_die
)
6413 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6414 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6415 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6418 unsigned char checksum
[16];
6421 /* Compute the checksum of the DIE, then append part of it as hex digits to
6422 the name filename of the unit. */
6424 md5_init_ctx (&ctx
);
6426 die_checksum (unit_die
, &ctx
, &mark
);
6427 unmark_all_dies (unit_die
);
6428 md5_finish_ctx (&ctx
, checksum
);
6430 sprintf (name
, "%s.", base
);
6431 clean_symbol_name (name
);
6433 p
= name
+ strlen (name
);
6434 for (i
= 0; i
< 4; i
++)
6436 sprintf (p
, "%.2x", checksum
[i
]);
6440 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6441 comdat_symbol_number
= 0;
6444 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6447 is_type_die (dw_die_ref die
)
6449 switch (die
->die_tag
)
6451 case DW_TAG_array_type
:
6452 case DW_TAG_class_type
:
6453 case DW_TAG_interface_type
:
6454 case DW_TAG_enumeration_type
:
6455 case DW_TAG_pointer_type
:
6456 case DW_TAG_reference_type
:
6457 case DW_TAG_rvalue_reference_type
:
6458 case DW_TAG_string_type
:
6459 case DW_TAG_structure_type
:
6460 case DW_TAG_subroutine_type
:
6461 case DW_TAG_union_type
:
6462 case DW_TAG_ptr_to_member_type
:
6463 case DW_TAG_set_type
:
6464 case DW_TAG_subrange_type
:
6465 case DW_TAG_base_type
:
6466 case DW_TAG_const_type
:
6467 case DW_TAG_file_type
:
6468 case DW_TAG_packed_type
:
6469 case DW_TAG_volatile_type
:
6470 case DW_TAG_typedef
:
6477 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6478 Basically, we want to choose the bits that are likely to be shared between
6479 compilations (types) and leave out the bits that are specific to individual
6480 compilations (functions). */
6483 is_comdat_die (dw_die_ref c
)
6485 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6486 we do for stabs. The advantage is a greater likelihood of sharing between
6487 objects that don't include headers in the same order (and therefore would
6488 put the base types in a different comdat). jason 8/28/00 */
6490 if (c
->die_tag
== DW_TAG_base_type
)
6493 if (c
->die_tag
== DW_TAG_pointer_type
6494 || c
->die_tag
== DW_TAG_reference_type
6495 || c
->die_tag
== DW_TAG_rvalue_reference_type
6496 || c
->die_tag
== DW_TAG_const_type
6497 || c
->die_tag
== DW_TAG_volatile_type
)
6499 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6501 return t
? is_comdat_die (t
) : 0;
6504 return is_type_die (c
);
6507 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6508 compilation unit. */
6511 is_symbol_die (dw_die_ref c
)
6513 return (is_type_die (c
)
6514 || is_declaration_die (c
)
6515 || c
->die_tag
== DW_TAG_namespace
6516 || c
->die_tag
== DW_TAG_module
);
6519 /* Returns true iff C is a compile-unit DIE. */
6522 is_cu_die (dw_die_ref c
)
6524 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6527 /* Returns true iff C is a unit DIE of some sort. */
6530 is_unit_die (dw_die_ref c
)
6532 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6533 || c
->die_tag
== DW_TAG_partial_unit
6534 || c
->die_tag
== DW_TAG_type_unit
);
6537 /* Returns true iff C is a namespace DIE. */
6540 is_namespace_die (dw_die_ref c
)
6542 return c
&& c
->die_tag
== DW_TAG_namespace
;
6545 /* Returns true iff C is a class or structure DIE. */
6548 is_class_die (dw_die_ref c
)
6550 return c
&& (c
->die_tag
== DW_TAG_class_type
6551 || c
->die_tag
== DW_TAG_structure_type
);
6554 /* Return non-zero if this DIE is a template parameter. */
6557 is_template_parameter (dw_die_ref die
)
6559 switch (die
->die_tag
)
6561 case DW_TAG_template_type_param
:
6562 case DW_TAG_template_value_param
:
6563 case DW_TAG_GNU_template_template_param
:
6564 case DW_TAG_GNU_template_parameter_pack
:
6571 /* Return non-zero if this DIE represents a template instantiation. */
6574 is_template_instantiation (dw_die_ref die
)
6578 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6580 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6585 gen_internal_sym (const char *prefix
)
6589 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6590 return xstrdup (buf
);
6593 /* Assign symbols to all worthy DIEs under DIE. */
6596 assign_symbol_names (dw_die_ref die
)
6600 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6602 if (comdat_symbol_id
)
6604 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6606 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6607 comdat_symbol_id
, comdat_symbol_number
++);
6608 die
->die_id
.die_symbol
= xstrdup (p
);
6611 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6614 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6617 struct cu_hash_table_entry
6620 unsigned min_comdat_num
, max_comdat_num
;
6621 struct cu_hash_table_entry
*next
;
6624 /* Helpers to manipulate hash table of CUs. */
6626 struct cu_hash_table_entry_hasher
6628 typedef cu_hash_table_entry value_type
;
6629 typedef die_struct compare_type
;
6630 static inline hashval_t
hash (const value_type
*);
6631 static inline bool equal (const value_type
*, const compare_type
*);
6632 static inline void remove (value_type
*);
6636 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6638 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6642 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6643 const compare_type
*entry2
)
6645 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6649 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6651 struct cu_hash_table_entry
*next
;
6661 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6663 /* Check whether we have already seen this CU and set up SYM_NUM
6666 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6668 struct cu_hash_table_entry dummy
;
6669 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6671 dummy
.max_comdat_num
= 0;
6673 slot
= htable
.find_slot_with_hash (cu
,
6674 htab_hash_string (cu
->die_id
.die_symbol
),
6678 for (; entry
; last
= entry
, entry
= entry
->next
)
6680 if (same_die_p_wrap (cu
, entry
->cu
))
6686 *sym_num
= entry
->min_comdat_num
;
6690 entry
= XCNEW (struct cu_hash_table_entry
);
6692 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6693 entry
->next
= *slot
;
6699 /* Record SYM_NUM to record of CU in HTABLE. */
6701 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6702 unsigned int sym_num
)
6704 struct cu_hash_table_entry
**slot
, *entry
;
6706 slot
= htable
.find_slot_with_hash (cu
,
6707 htab_hash_string (cu
->die_id
.die_symbol
),
6711 entry
->max_comdat_num
= sym_num
;
6714 /* Traverse the DIE (which is always comp_unit_die), and set up
6715 additional compilation units for each of the include files we see
6716 bracketed by BINCL/EINCL. */
6719 break_out_includes (dw_die_ref die
)
6722 dw_die_ref unit
= NULL
;
6723 limbo_die_node
*node
, **pnode
;
6724 cu_hash_type cu_hash_table
;
6728 dw_die_ref prev
= c
;
6730 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6731 || (unit
&& is_comdat_die (c
)))
6733 dw_die_ref next
= c
->die_sib
;
6735 /* This DIE is for a secondary CU; remove it from the main one. */
6736 remove_child_with_prev (c
, prev
);
6738 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6739 unit
= push_new_compile_unit (unit
, c
);
6740 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6741 unit
= pop_compile_unit (unit
);
6743 add_child_die (unit
, c
);
6745 if (c
== die
->die_child
)
6748 } while (c
!= die
->die_child
);
6751 /* We can only use this in debugging, since the frontend doesn't check
6752 to make sure that we leave every include file we enter. */
6756 assign_symbol_names (die
);
6757 cu_hash_table
.create (10);
6758 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6764 compute_section_prefix (node
->die
);
6765 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6766 &comdat_symbol_number
);
6767 assign_symbol_names (node
->die
);
6769 *pnode
= node
->next
;
6772 pnode
= &node
->next
;
6773 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6774 comdat_symbol_number
);
6777 cu_hash_table
.dispose ();
6780 /* Return non-zero if this DIE is a declaration. */
6783 is_declaration_die (dw_die_ref die
)
6788 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6789 if (a
->dw_attr
== DW_AT_declaration
)
6795 /* Return non-zero if this DIE is nested inside a subprogram. */
6798 is_nested_in_subprogram (dw_die_ref die
)
6800 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6804 return local_scope_p (decl
);
6807 /* Return non-zero if this DIE contains a defining declaration of a
6811 contains_subprogram_definition (dw_die_ref die
)
6815 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6817 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6821 /* Return non-zero if this is a type DIE that should be moved to a
6822 COMDAT .debug_types section. */
6825 should_move_die_to_comdat (dw_die_ref die
)
6827 switch (die
->die_tag
)
6829 case DW_TAG_class_type
:
6830 case DW_TAG_structure_type
:
6831 case DW_TAG_enumeration_type
:
6832 case DW_TAG_union_type
:
6833 /* Don't move declarations, inlined instances, types nested in a
6834 subprogram, or types that contain subprogram definitions. */
6835 if (is_declaration_die (die
)
6836 || get_AT (die
, DW_AT_abstract_origin
)
6837 || is_nested_in_subprogram (die
)
6838 || contains_subprogram_definition (die
))
6841 case DW_TAG_array_type
:
6842 case DW_TAG_interface_type
:
6843 case DW_TAG_pointer_type
:
6844 case DW_TAG_reference_type
:
6845 case DW_TAG_rvalue_reference_type
:
6846 case DW_TAG_string_type
:
6847 case DW_TAG_subroutine_type
:
6848 case DW_TAG_ptr_to_member_type
:
6849 case DW_TAG_set_type
:
6850 case DW_TAG_subrange_type
:
6851 case DW_TAG_base_type
:
6852 case DW_TAG_const_type
:
6853 case DW_TAG_file_type
:
6854 case DW_TAG_packed_type
:
6855 case DW_TAG_volatile_type
:
6856 case DW_TAG_typedef
:
6862 /* Make a clone of DIE. */
6865 clone_die (dw_die_ref die
)
6871 clone
= ggc_alloc_cleared_die_node ();
6872 clone
->die_tag
= die
->die_tag
;
6874 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6875 add_dwarf_attr (clone
, a
);
6880 /* Make a clone of the tree rooted at DIE. */
6883 clone_tree (dw_die_ref die
)
6886 dw_die_ref clone
= clone_die (die
);
6888 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6893 /* Make a clone of DIE as a declaration. */
6896 clone_as_declaration (dw_die_ref die
)
6903 /* If the DIE is already a declaration, just clone it. */
6904 if (is_declaration_die (die
))
6905 return clone_die (die
);
6907 /* If the DIE is a specification, just clone its declaration DIE. */
6908 decl
= get_AT_ref (die
, DW_AT_specification
);
6911 clone
= clone_die (decl
);
6912 if (die
->comdat_type_p
)
6913 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6917 clone
= ggc_alloc_cleared_die_node ();
6918 clone
->die_tag
= die
->die_tag
;
6920 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6922 /* We don't want to copy over all attributes.
6923 For example we don't want DW_AT_byte_size because otherwise we will no
6924 longer have a declaration and GDB will treat it as a definition. */
6928 case DW_AT_abstract_origin
:
6929 case DW_AT_artificial
:
6930 case DW_AT_containing_type
:
6931 case DW_AT_external
:
6934 case DW_AT_virtuality
:
6935 case DW_AT_linkage_name
:
6936 case DW_AT_MIPS_linkage_name
:
6937 add_dwarf_attr (clone
, a
);
6939 case DW_AT_byte_size
:
6945 if (die
->comdat_type_p
)
6946 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6948 add_AT_flag (clone
, DW_AT_declaration
, 1);
6953 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6955 struct decl_table_entry
6961 /* Helpers to manipulate hash table of copied declarations. */
6963 /* Hashtable helpers. */
6965 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6967 typedef decl_table_entry value_type
;
6968 typedef die_struct compare_type
;
6969 static inline hashval_t
hash (const value_type
*);
6970 static inline bool equal (const value_type
*, const compare_type
*);
6974 decl_table_entry_hasher::hash (const value_type
*entry
)
6976 return htab_hash_pointer (entry
->orig
);
6980 decl_table_entry_hasher::equal (const value_type
*entry1
,
6981 const compare_type
*entry2
)
6983 return entry1
->orig
== entry2
;
6986 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6988 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6989 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6990 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6991 to check if the ancestor has already been copied into UNIT. */
6994 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6996 dw_die_ref parent
= die
->die_parent
;
6997 dw_die_ref new_parent
= unit
;
6999 decl_table_entry
**slot
= NULL
;
7000 struct decl_table_entry
*entry
= NULL
;
7002 if (decl_table
.is_created ())
7004 /* Check if the entry has already been copied to UNIT. */
7005 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
7007 if (*slot
!= HTAB_EMPTY_ENTRY
)
7013 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7014 entry
= XCNEW (struct decl_table_entry
);
7022 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7025 if (!is_unit_die (parent
))
7026 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7029 copy
= clone_as_declaration (die
);
7030 add_child_die (new_parent
, copy
);
7032 if (decl_table
.is_created ())
7034 /* Record the pointer to the copy. */
7040 /* Copy the declaration context to the new type unit DIE. This includes
7041 any surrounding namespace or type declarations. If the DIE has an
7042 AT_specification attribute, it also includes attributes and children
7043 attached to the specification, and returns a pointer to the original
7044 parent of the declaration DIE. Returns NULL otherwise. */
7047 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7050 dw_die_ref new_decl
;
7051 dw_die_ref orig_parent
= NULL
;
7053 decl
= get_AT_ref (die
, DW_AT_specification
);
7062 /* The original DIE will be changed to a declaration, and must
7063 be moved to be a child of the original declaration DIE. */
7064 orig_parent
= decl
->die_parent
;
7066 /* Copy the type node pointer from the new DIE to the original
7067 declaration DIE so we can forward references later. */
7068 decl
->comdat_type_p
= true;
7069 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7071 remove_AT (die
, DW_AT_specification
);
7073 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7075 if (a
->dw_attr
!= DW_AT_name
7076 && a
->dw_attr
!= DW_AT_declaration
7077 && a
->dw_attr
!= DW_AT_external
)
7078 add_dwarf_attr (die
, a
);
7081 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7084 if (decl
->die_parent
!= NULL
7085 && !is_unit_die (decl
->die_parent
))
7087 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7088 if (new_decl
!= NULL
)
7090 remove_AT (new_decl
, DW_AT_signature
);
7091 add_AT_specification (die
, new_decl
);
7098 /* Generate the skeleton ancestor tree for the given NODE, then clone
7099 the DIE and add the clone into the tree. */
7102 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7104 if (node
->new_die
!= NULL
)
7107 node
->new_die
= clone_as_declaration (node
->old_die
);
7109 if (node
->parent
!= NULL
)
7111 generate_skeleton_ancestor_tree (node
->parent
);
7112 add_child_die (node
->parent
->new_die
, node
->new_die
);
7116 /* Generate a skeleton tree of DIEs containing any declarations that are
7117 found in the original tree. We traverse the tree looking for declaration
7118 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7121 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7123 skeleton_chain_node node
;
7126 dw_die_ref prev
= NULL
;
7127 dw_die_ref next
= NULL
;
7129 node
.parent
= parent
;
7131 first
= c
= parent
->old_die
->die_child
;
7135 if (prev
== NULL
|| prev
->die_sib
== c
)
7138 next
= (c
== first
? NULL
: c
->die_sib
);
7140 node
.new_die
= NULL
;
7141 if (is_declaration_die (c
))
7143 if (is_template_instantiation (c
))
7145 /* Instantiated templates do not need to be cloned into the
7146 type unit. Just move the DIE and its children back to
7147 the skeleton tree (in the main CU). */
7148 remove_child_with_prev (c
, prev
);
7149 add_child_die (parent
->new_die
, c
);
7154 /* Clone the existing DIE, move the original to the skeleton
7155 tree (which is in the main CU), and put the clone, with
7156 all the original's children, where the original came from
7157 (which is about to be moved to the type unit). */
7158 dw_die_ref clone
= clone_die (c
);
7159 move_all_children (c
, clone
);
7161 /* If the original has a DW_AT_object_pointer attribute,
7162 it would now point to a child DIE just moved to the
7163 cloned tree, so we need to remove that attribute from
7165 remove_AT (c
, DW_AT_object_pointer
);
7167 replace_child (c
, clone
, prev
);
7168 generate_skeleton_ancestor_tree (parent
);
7169 add_child_die (parent
->new_die
, c
);
7174 generate_skeleton_bottom_up (&node
);
7175 } while (next
!= NULL
);
7178 /* Wrapper function for generate_skeleton_bottom_up. */
7181 generate_skeleton (dw_die_ref die
)
7183 skeleton_chain_node node
;
7186 node
.new_die
= NULL
;
7189 /* If this type definition is nested inside another type,
7190 and is not an instantiation of a template, always leave
7191 at least a declaration in its place. */
7192 if (die
->die_parent
!= NULL
7193 && is_type_die (die
->die_parent
)
7194 && !is_template_instantiation (die
))
7195 node
.new_die
= clone_as_declaration (die
);
7197 generate_skeleton_bottom_up (&node
);
7198 return node
.new_die
;
7201 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7202 declaration. The original DIE is moved to a new compile unit so that
7203 existing references to it follow it to the new location. If any of the
7204 original DIE's descendants is a declaration, we need to replace the
7205 original DIE with a skeleton tree and move the declarations back into the
7209 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7212 dw_die_ref skeleton
, orig_parent
;
7214 /* Copy the declaration context to the type unit DIE. If the returned
7215 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7217 orig_parent
= copy_declaration_context (unit
, child
);
7219 skeleton
= generate_skeleton (child
);
7220 if (skeleton
== NULL
)
7221 remove_child_with_prev (child
, prev
);
7224 skeleton
->comdat_type_p
= true;
7225 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7227 /* If the original DIE was a specification, we need to put
7228 the skeleton under the parent DIE of the declaration.
7229 This leaves the original declaration in the tree, but
7230 it will be pruned later since there are no longer any
7231 references to it. */
7232 if (orig_parent
!= NULL
)
7234 remove_child_with_prev (child
, prev
);
7235 add_child_die (orig_parent
, skeleton
);
7238 replace_child (child
, skeleton
, prev
);
7244 /* Traverse the DIE and set up additional .debug_types sections for each
7245 type worthy of being placed in a COMDAT section. */
7248 break_out_comdat_types (dw_die_ref die
)
7252 dw_die_ref prev
= NULL
;
7253 dw_die_ref next
= NULL
;
7254 dw_die_ref unit
= NULL
;
7256 first
= c
= die
->die_child
;
7260 if (prev
== NULL
|| prev
->die_sib
== c
)
7263 next
= (c
== first
? NULL
: c
->die_sib
);
7264 if (should_move_die_to_comdat (c
))
7266 dw_die_ref replacement
;
7267 comdat_type_node_ref type_node
;
7269 /* Break out nested types into their own type units. */
7270 break_out_comdat_types (c
);
7272 /* Create a new type unit DIE as the root for the new tree, and
7273 add it to the list of comdat types. */
7274 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7275 add_AT_unsigned (unit
, DW_AT_language
,
7276 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7277 type_node
= ggc_alloc_cleared_comdat_type_node ();
7278 type_node
->root_die
= unit
;
7279 type_node
->next
= comdat_type_list
;
7280 comdat_type_list
= type_node
;
7282 /* Generate the type signature. */
7283 generate_type_signature (c
, type_node
);
7285 /* Copy the declaration context, attributes, and children of the
7286 declaration into the new type unit DIE, then remove this DIE
7287 from the main CU (or replace it with a skeleton if necessary). */
7288 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7289 type_node
->skeleton_die
= replacement
;
7291 /* Add the DIE to the new compunit. */
7292 add_child_die (unit
, c
);
7294 if (replacement
!= NULL
)
7297 else if (c
->die_tag
== DW_TAG_namespace
7298 || c
->die_tag
== DW_TAG_class_type
7299 || c
->die_tag
== DW_TAG_structure_type
7300 || c
->die_tag
== DW_TAG_union_type
)
7302 /* Look for nested types that can be broken out. */
7303 break_out_comdat_types (c
);
7305 } while (next
!= NULL
);
7308 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7309 Enter all the cloned children into the hash table decl_table. */
7312 clone_tree_partial (dw_die_ref die
, decl_hash_type decl_table
)
7316 struct decl_table_entry
*entry
;
7317 decl_table_entry
**slot
;
7319 if (die
->die_tag
== DW_TAG_subprogram
)
7320 clone
= clone_as_declaration (die
);
7322 clone
= clone_die (die
);
7324 slot
= decl_table
.find_slot_with_hash (die
,
7325 htab_hash_pointer (die
), INSERT
);
7327 /* Assert that DIE isn't in the hash table yet. If it would be there
7328 before, the ancestors would be necessarily there as well, therefore
7329 clone_tree_partial wouldn't be called. */
7330 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7332 entry
= XCNEW (struct decl_table_entry
);
7334 entry
->copy
= clone
;
7337 if (die
->die_tag
!= DW_TAG_subprogram
)
7338 FOR_EACH_CHILD (die
, c
,
7339 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7344 /* Walk the DIE and its children, looking for references to incomplete
7345 or trivial types that are unmarked (i.e., that are not in the current
7349 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7355 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7357 if (AT_class (a
) == dw_val_class_die_ref
)
7359 dw_die_ref targ
= AT_ref (a
);
7360 decl_table_entry
**slot
;
7361 struct decl_table_entry
*entry
;
7363 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7366 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7369 if (*slot
!= HTAB_EMPTY_ENTRY
)
7371 /* TARG has already been copied, so we just need to
7372 modify the reference to point to the copy. */
7374 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7378 dw_die_ref parent
= unit
;
7379 dw_die_ref copy
= clone_die (targ
);
7381 /* Record in DECL_TABLE that TARG has been copied.
7382 Need to do this now, before the recursive call,
7383 because DECL_TABLE may be expanded and SLOT
7384 would no longer be a valid pointer. */
7385 entry
= XCNEW (struct decl_table_entry
);
7390 /* If TARG is not a declaration DIE, we need to copy its
7392 if (!is_declaration_die (targ
))
7396 add_child_die (copy
,
7397 clone_tree_partial (c
, decl_table
)));
7400 /* Make sure the cloned tree is marked as part of the
7404 /* If TARG has surrounding context, copy its ancestor tree
7405 into the new type unit. */
7406 if (targ
->die_parent
!= NULL
7407 && !is_unit_die (targ
->die_parent
))
7408 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7411 add_child_die (parent
, copy
);
7412 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7414 /* Make sure the newly-copied DIE is walked. If it was
7415 installed in a previously-added context, it won't
7416 get visited otherwise. */
7419 /* Find the highest point of the newly-added tree,
7420 mark each node along the way, and walk from there. */
7421 parent
->die_mark
= 1;
7422 while (parent
->die_parent
7423 && parent
->die_parent
->die_mark
== 0)
7425 parent
= parent
->die_parent
;
7426 parent
->die_mark
= 1;
7428 copy_decls_walk (unit
, parent
, decl_table
);
7434 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7437 /* Copy declarations for "unworthy" types into the new comdat section.
7438 Incomplete types, modified types, and certain other types aren't broken
7439 out into comdat sections of their own, so they don't have a signature,
7440 and we need to copy the declaration into the same section so that we
7441 don't have an external reference. */
7444 copy_decls_for_unworthy_types (dw_die_ref unit
)
7446 decl_hash_type decl_table
;
7449 decl_table
.create (10);
7450 copy_decls_walk (unit
, unit
, decl_table
);
7451 decl_table
.dispose ();
7455 /* Traverse the DIE and add a sibling attribute if it may have the
7456 effect of speeding up access to siblings. To save some space,
7457 avoid generating sibling attributes for DIE's without children. */
7460 add_sibling_attributes (dw_die_ref die
)
7464 if (! die
->die_child
)
7467 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7468 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7470 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7473 /* Output all location lists for the DIE and its children. */
7476 output_location_lists (dw_die_ref die
)
7482 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7483 if (AT_class (a
) == dw_val_class_loc_list
)
7484 output_loc_list (AT_loc_list (a
));
7486 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7489 /* We want to limit the number of external references, because they are
7490 larger than local references: a relocation takes multiple words, and
7491 even a sig8 reference is always eight bytes, whereas a local reference
7492 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7493 So if we encounter multiple external references to the same type DIE, we
7494 make a local typedef stub for it and redirect all references there.
7496 This is the element of the hash table for keeping track of these
7506 /* Hashtable helpers. */
7508 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7510 typedef external_ref value_type
;
7511 typedef external_ref compare_type
;
7512 static inline hashval_t
hash (const value_type
*);
7513 static inline bool equal (const value_type
*, const compare_type
*);
7517 external_ref_hasher::hash (const value_type
*r
)
7519 dw_die_ref die
= r
->type
;
7522 /* We can't use the address of the DIE for hashing, because
7523 that will make the order of the stub DIEs non-deterministic. */
7524 if (! die
->comdat_type_p
)
7525 /* We have a symbol; use it to compute a hash. */
7526 h
= htab_hash_string (die
->die_id
.die_symbol
);
7529 /* We have a type signature; use a subset of the bits as the hash.
7530 The 8-byte signature is at least as large as hashval_t. */
7531 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7532 memcpy (&h
, type_node
->signature
, sizeof (h
));
7538 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7540 return r1
->type
== r2
->type
;
7543 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7545 /* Return a pointer to the external_ref for references to DIE. */
7547 static struct external_ref
*
7548 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7550 struct external_ref ref
, *ref_p
;
7551 external_ref
**slot
;
7554 slot
= map
.find_slot (&ref
, INSERT
);
7555 if (*slot
!= HTAB_EMPTY_ENTRY
)
7558 ref_p
= XCNEW (struct external_ref
);
7564 /* Subroutine of optimize_external_refs, below.
7566 If we see a type skeleton, record it as our stub. If we see external
7567 references, remember how many we've seen. */
7570 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7575 struct external_ref
*ref_p
;
7577 if (is_type_die (die
)
7578 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7580 /* This is a local skeleton; use it for local references. */
7581 ref_p
= lookup_external_ref (map
, c
);
7585 /* Scan the DIE references, and remember any that refer to DIEs from
7586 other CUs (i.e. those which are not marked). */
7587 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7588 if (AT_class (a
) == dw_val_class_die_ref
7589 && (c
= AT_ref (a
))->die_mark
== 0
7592 ref_p
= lookup_external_ref (map
, c
);
7596 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7599 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7600 points to an external_ref, DATA is the CU we're processing. If we don't
7601 already have a local stub, and we have multiple refs, build a stub. */
7604 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7606 struct external_ref
*ref_p
= *slot
;
7608 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7610 /* We have multiple references to this type, so build a small stub.
7611 Both of these forms are a bit dodgy from the perspective of the
7612 DWARF standard, since technically they should have names. */
7613 dw_die_ref cu
= data
;
7614 dw_die_ref type
= ref_p
->type
;
7615 dw_die_ref stub
= NULL
;
7617 if (type
->comdat_type_p
)
7619 /* If we refer to this type via sig8, use AT_signature. */
7620 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7621 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7625 /* Otherwise, use a typedef with no name. */
7626 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7627 add_AT_die_ref (stub
, DW_AT_type
, type
);
7636 /* DIE is a unit; look through all the DIE references to see if there are
7637 any external references to types, and if so, create local stubs for
7638 them which will be applied in build_abbrev_table. This is useful because
7639 references to local DIEs are smaller. */
7641 static external_ref_hash_type
7642 optimize_external_refs (dw_die_ref die
)
7644 external_ref_hash_type map
;
7646 optimize_external_refs_1 (die
, map
);
7647 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7651 /* The format of each DIE (and its attribute value pairs) is encoded in an
7652 abbreviation table. This routine builds the abbreviation table and assigns
7653 a unique abbreviation id for each abbreviation entry. The children of each
7654 die are visited recursively. */
7657 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7659 unsigned long abbrev_id
;
7660 unsigned int n_alloc
;
7665 /* Scan the DIE references, and replace any that refer to
7666 DIEs from other CUs (i.e. those which are not marked) with
7667 the local stubs we built in optimize_external_refs. */
7668 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7669 if (AT_class (a
) == dw_val_class_die_ref
7670 && (c
= AT_ref (a
))->die_mark
== 0)
7672 struct external_ref
*ref_p
;
7673 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7675 ref_p
= lookup_external_ref (extern_map
, c
);
7676 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7677 change_AT_die_ref (a
, ref_p
->stub
);
7679 /* We aren't changing this reference, so mark it external. */
7680 set_AT_ref_external (a
, 1);
7683 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7685 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7686 dw_attr_ref die_a
, abbrev_a
;
7690 if (abbrev
->die_tag
!= die
->die_tag
)
7692 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7695 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7698 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7700 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7701 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7702 || (value_format (abbrev_a
) != value_format (die_a
)))
7712 if (abbrev_id
>= abbrev_die_table_in_use
)
7714 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7716 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7717 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7720 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7721 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7722 abbrev_die_table_allocated
= n_alloc
;
7725 ++abbrev_die_table_in_use
;
7726 abbrev_die_table
[abbrev_id
] = die
;
7729 die
->die_abbrev
= abbrev_id
;
7730 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7733 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7736 constant_size (unsigned HOST_WIDE_INT value
)
7743 log
= floor_log2 (value
);
7746 log
= 1 << (floor_log2 (log
) + 1);
7751 /* Return the size of a DIE as it is represented in the
7752 .debug_info section. */
7754 static unsigned long
7755 size_of_die (dw_die_ref die
)
7757 unsigned long size
= 0;
7760 enum dwarf_form form
;
7762 size
+= size_of_uleb128 (die
->die_abbrev
);
7763 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7765 switch (AT_class (a
))
7767 case dw_val_class_addr
:
7768 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7770 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7771 size
+= size_of_uleb128 (AT_index (a
));
7774 size
+= DWARF2_ADDR_SIZE
;
7776 case dw_val_class_offset
:
7777 size
+= DWARF_OFFSET_SIZE
;
7779 case dw_val_class_loc
:
7781 unsigned long lsize
= size_of_locs (AT_loc (a
));
7784 if (dwarf_version
>= 4)
7785 size
+= size_of_uleb128 (lsize
);
7787 size
+= constant_size (lsize
);
7791 case dw_val_class_loc_list
:
7792 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7794 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7795 size
+= size_of_uleb128 (AT_index (a
));
7798 size
+= DWARF_OFFSET_SIZE
;
7800 case dw_val_class_range_list
:
7801 size
+= DWARF_OFFSET_SIZE
;
7803 case dw_val_class_const
:
7804 size
+= size_of_sleb128 (AT_int (a
));
7806 case dw_val_class_unsigned_const
:
7808 int csize
= constant_size (AT_unsigned (a
));
7809 if (dwarf_version
== 3
7810 && a
->dw_attr
== DW_AT_data_member_location
7812 size
+= size_of_uleb128 (AT_unsigned (a
));
7817 case dw_val_class_const_double
:
7818 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7819 if (HOST_BITS_PER_WIDE_INT
>= 64)
7822 case dw_val_class_vec
:
7823 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7824 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7825 + a
->dw_attr_val
.v
.val_vec
.length
7826 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7828 case dw_val_class_flag
:
7829 if (dwarf_version
>= 4)
7830 /* Currently all add_AT_flag calls pass in 1 as last argument,
7831 so DW_FORM_flag_present can be used. If that ever changes,
7832 we'll need to use DW_FORM_flag and have some optimization
7833 in build_abbrev_table that will change those to
7834 DW_FORM_flag_present if it is set to 1 in all DIEs using
7835 the same abbrev entry. */
7836 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7840 case dw_val_class_die_ref
:
7841 if (AT_ref_external (a
))
7843 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7844 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7845 is sized by target address length, whereas in DWARF3
7846 it's always sized as an offset. */
7847 if (use_debug_types
)
7848 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7849 else if (dwarf_version
== 2)
7850 size
+= DWARF2_ADDR_SIZE
;
7852 size
+= DWARF_OFFSET_SIZE
;
7855 size
+= DWARF_OFFSET_SIZE
;
7857 case dw_val_class_fde_ref
:
7858 size
+= DWARF_OFFSET_SIZE
;
7860 case dw_val_class_lbl_id
:
7861 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7863 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7864 size
+= size_of_uleb128 (AT_index (a
));
7867 size
+= DWARF2_ADDR_SIZE
;
7869 case dw_val_class_lineptr
:
7870 case dw_val_class_macptr
:
7871 size
+= DWARF_OFFSET_SIZE
;
7873 case dw_val_class_str
:
7874 form
= AT_string_form (a
);
7875 if (form
== DW_FORM_strp
)
7876 size
+= DWARF_OFFSET_SIZE
;
7877 else if (form
== DW_FORM_GNU_str_index
)
7878 size
+= size_of_uleb128 (AT_index (a
));
7880 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7882 case dw_val_class_file
:
7883 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7885 case dw_val_class_data8
:
7888 case dw_val_class_vms_delta
:
7889 size
+= DWARF_OFFSET_SIZE
;
7891 case dw_val_class_high_pc
:
7892 size
+= DWARF2_ADDR_SIZE
;
7902 /* Size the debugging information associated with a given DIE. Visits the
7903 DIE's children recursively. Updates the global variable next_die_offset, on
7904 each time through. Uses the current value of next_die_offset to update the
7905 die_offset field in each DIE. */
7908 calc_die_sizes (dw_die_ref die
)
7912 gcc_assert (die
->die_offset
== 0
7913 || (unsigned long int) die
->die_offset
== next_die_offset
);
7914 die
->die_offset
= next_die_offset
;
7915 next_die_offset
+= size_of_die (die
);
7917 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7919 if (die
->die_child
!= NULL
)
7920 /* Count the null byte used to terminate sibling lists. */
7921 next_die_offset
+= 1;
7924 /* Size just the base type children at the start of the CU.
7925 This is needed because build_abbrev needs to size locs
7926 and sizing of type based stack ops needs to know die_offset
7927 values for the base types. */
7930 calc_base_type_die_sizes (void)
7932 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7934 dw_die_ref base_type
;
7935 #if ENABLE_ASSERT_CHECKING
7936 dw_die_ref prev
= comp_unit_die ()->die_child
;
7939 die_offset
+= size_of_die (comp_unit_die ());
7940 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7942 #if ENABLE_ASSERT_CHECKING
7943 gcc_assert (base_type
->die_offset
== 0
7944 && prev
->die_sib
== base_type
7945 && base_type
->die_child
== NULL
7946 && base_type
->die_abbrev
);
7949 base_type
->die_offset
= die_offset
;
7950 die_offset
+= size_of_die (base_type
);
7954 /* Set the marks for a die and its children. We do this so
7955 that we know whether or not a reference needs to use FORM_ref_addr; only
7956 DIEs in the same CU will be marked. We used to clear out the offset
7957 and use that as the flag, but ran into ordering problems. */
7960 mark_dies (dw_die_ref die
)
7964 gcc_assert (!die
->die_mark
);
7967 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7970 /* Clear the marks for a die and its children. */
7973 unmark_dies (dw_die_ref die
)
7977 if (! use_debug_types
)
7978 gcc_assert (die
->die_mark
);
7981 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7984 /* Clear the marks for a die, its children and referred dies. */
7987 unmark_all_dies (dw_die_ref die
)
7997 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7999 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8000 if (AT_class (a
) == dw_val_class_die_ref
)
8001 unmark_all_dies (AT_ref (a
));
8004 /* Calculate if the entry should appear in the final output file. It may be
8005 from a pruned a type. */
8008 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8010 /* By limiting gnu pubnames to definitions only, gold can generate a
8011 gdb index without entries for declarations, which don't include
8012 enough information to be useful. */
8013 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8016 if (table
== pubname_table
)
8018 /* Enumerator names are part of the pubname table, but the
8019 parent DW_TAG_enumeration_type die may have been pruned.
8020 Don't output them if that is the case. */
8021 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8022 (p
->die
->die_parent
== NULL
8023 || !p
->die
->die_parent
->die_perennial_p
))
8026 /* Everything else in the pubname table is included. */
8030 /* The pubtypes table shouldn't include types that have been
8032 return (p
->die
->die_offset
!= 0
8033 || !flag_eliminate_unused_debug_types
);
8036 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8037 generated for the compilation unit. */
8039 static unsigned long
8040 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8045 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8047 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8048 FOR_EACH_VEC_ELT (*names
, i
, p
)
8049 if (include_pubname_in_output (names
, p
))
8050 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8052 size
+= DWARF_OFFSET_SIZE
;
8056 /* Return the size of the information in the .debug_aranges section. */
8058 static unsigned long
8059 size_of_aranges (void)
8063 size
= DWARF_ARANGES_HEADER_SIZE
;
8065 /* Count the address/length pair for this compilation unit. */
8066 if (text_section_used
)
8067 size
+= 2 * DWARF2_ADDR_SIZE
;
8068 if (cold_text_section_used
)
8069 size
+= 2 * DWARF2_ADDR_SIZE
;
8070 if (have_multiple_function_sections
)
8075 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8077 if (DECL_IGNORED_P (fde
->decl
))
8079 if (!fde
->in_std_section
)
8080 size
+= 2 * DWARF2_ADDR_SIZE
;
8081 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8082 size
+= 2 * DWARF2_ADDR_SIZE
;
8086 /* Count the two zero words used to terminated the address range table. */
8087 size
+= 2 * DWARF2_ADDR_SIZE
;
8091 /* Select the encoding of an attribute value. */
8093 static enum dwarf_form
8094 value_format (dw_attr_ref a
)
8096 switch (AT_class (a
))
8098 case dw_val_class_addr
:
8099 /* Only very few attributes allow DW_FORM_addr. */
8104 case DW_AT_entry_pc
:
8105 case DW_AT_trampoline
:
8106 return (AT_index (a
) == NOT_INDEXED
8107 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8111 switch (DWARF2_ADDR_SIZE
)
8114 return DW_FORM_data1
;
8116 return DW_FORM_data2
;
8118 return DW_FORM_data4
;
8120 return DW_FORM_data8
;
8124 case dw_val_class_range_list
:
8125 case dw_val_class_loc_list
:
8126 if (dwarf_version
>= 4)
8127 return DW_FORM_sec_offset
;
8129 case dw_val_class_vms_delta
:
8130 case dw_val_class_offset
:
8131 switch (DWARF_OFFSET_SIZE
)
8134 return DW_FORM_data4
;
8136 return DW_FORM_data8
;
8140 case dw_val_class_loc
:
8141 if (dwarf_version
>= 4)
8142 return DW_FORM_exprloc
;
8143 switch (constant_size (size_of_locs (AT_loc (a
))))
8146 return DW_FORM_block1
;
8148 return DW_FORM_block2
;
8150 return DW_FORM_block4
;
8154 case dw_val_class_const
:
8155 return DW_FORM_sdata
;
8156 case dw_val_class_unsigned_const
:
8157 switch (constant_size (AT_unsigned (a
)))
8160 return DW_FORM_data1
;
8162 return DW_FORM_data2
;
8164 /* In DWARF3 DW_AT_data_member_location with
8165 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8166 constant, so we need to use DW_FORM_udata if we need
8167 a large constant. */
8168 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8169 return DW_FORM_udata
;
8170 return DW_FORM_data4
;
8172 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8173 return DW_FORM_udata
;
8174 return DW_FORM_data8
;
8178 case dw_val_class_const_double
:
8179 switch (HOST_BITS_PER_WIDE_INT
)
8182 return DW_FORM_data2
;
8184 return DW_FORM_data4
;
8186 return DW_FORM_data8
;
8189 return DW_FORM_block1
;
8191 case dw_val_class_vec
:
8192 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8193 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8196 return DW_FORM_block1
;
8198 return DW_FORM_block2
;
8200 return DW_FORM_block4
;
8204 case dw_val_class_flag
:
8205 if (dwarf_version
>= 4)
8207 /* Currently all add_AT_flag calls pass in 1 as last argument,
8208 so DW_FORM_flag_present can be used. If that ever changes,
8209 we'll need to use DW_FORM_flag and have some optimization
8210 in build_abbrev_table that will change those to
8211 DW_FORM_flag_present if it is set to 1 in all DIEs using
8212 the same abbrev entry. */
8213 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8214 return DW_FORM_flag_present
;
8216 return DW_FORM_flag
;
8217 case dw_val_class_die_ref
:
8218 if (AT_ref_external (a
))
8219 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8222 case dw_val_class_fde_ref
:
8223 return DW_FORM_data
;
8224 case dw_val_class_lbl_id
:
8225 return (AT_index (a
) == NOT_INDEXED
8226 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8227 case dw_val_class_lineptr
:
8228 case dw_val_class_macptr
:
8229 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8230 case dw_val_class_str
:
8231 return AT_string_form (a
);
8232 case dw_val_class_file
:
8233 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8236 return DW_FORM_data1
;
8238 return DW_FORM_data2
;
8240 return DW_FORM_data4
;
8245 case dw_val_class_data8
:
8246 return DW_FORM_data8
;
8248 case dw_val_class_high_pc
:
8249 switch (DWARF2_ADDR_SIZE
)
8252 return DW_FORM_data1
;
8254 return DW_FORM_data2
;
8256 return DW_FORM_data4
;
8258 return DW_FORM_data8
;
8268 /* Output the encoding of an attribute value. */
8271 output_value_format (dw_attr_ref a
)
8273 enum dwarf_form form
= value_format (a
);
8275 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8278 /* Given a die and id, produce the appropriate abbreviations. */
8281 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8286 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8287 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8288 dwarf_tag_name (abbrev
->die_tag
));
8290 if (abbrev
->die_child
!= NULL
)
8291 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8293 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8295 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8297 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8298 dwarf_attr_name (a_attr
->dw_attr
));
8299 output_value_format (a_attr
);
8302 dw2_asm_output_data (1, 0, NULL
);
8303 dw2_asm_output_data (1, 0, NULL
);
8307 /* Output the .debug_abbrev section which defines the DIE abbreviation
8311 output_abbrev_section (void)
8313 unsigned long abbrev_id
;
8315 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8316 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8318 /* Terminate the table. */
8319 dw2_asm_output_data (1, 0, NULL
);
8322 /* Output a symbol we can use to refer to this DIE from another CU. */
8325 output_die_symbol (dw_die_ref die
)
8327 const char *sym
= die
->die_id
.die_symbol
;
8329 gcc_assert (!die
->comdat_type_p
);
8334 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8335 /* We make these global, not weak; if the target doesn't support
8336 .linkonce, it doesn't support combining the sections, so debugging
8338 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8340 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8343 /* Return a new location list, given the begin and end range, and the
8346 static inline dw_loc_list_ref
8347 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8348 const char *section
)
8350 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8352 retlist
->begin
= begin
;
8353 retlist
->begin_entry
= NULL
;
8355 retlist
->expr
= expr
;
8356 retlist
->section
= section
;
8361 /* Generate a new internal symbol for this location list node, if it
8362 hasn't got one yet. */
8365 gen_llsym (dw_loc_list_ref list
)
8367 gcc_assert (!list
->ll_symbol
);
8368 list
->ll_symbol
= gen_internal_sym ("LLST");
8371 /* Output the location list given to us. */
8374 output_loc_list (dw_loc_list_ref list_head
)
8376 dw_loc_list_ref curr
= list_head
;
8378 if (list_head
->emitted
)
8380 list_head
->emitted
= true;
8382 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8384 /* Walk the location list, and output each range + expression. */
8385 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8388 /* Don't output an entry that starts and ends at the same address. */
8389 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8391 size
= size_of_locs (curr
->expr
);
8392 /* If the expression is too large, drop it on the floor. We could
8393 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8394 in the expression, but >= 64KB expressions for a single value
8395 in a single range are unlikely very useful. */
8398 if (dwarf_split_debug_info
)
8400 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8401 "Location list start/length entry (%s)",
8402 list_head
->ll_symbol
);
8403 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8404 "Location list range start index (%s)",
8406 /* The length field is 4 bytes. If we ever need to support
8407 an 8-byte length, we can add a new DW_LLE code or fall back
8408 to DW_LLE_GNU_start_end_entry. */
8409 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8410 "Location list range length (%s)",
8411 list_head
->ll_symbol
);
8413 else if (!have_multiple_function_sections
)
8415 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8416 "Location list begin address (%s)",
8417 list_head
->ll_symbol
);
8418 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8419 "Location list end address (%s)",
8420 list_head
->ll_symbol
);
8424 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8425 "Location list begin address (%s)",
8426 list_head
->ll_symbol
);
8427 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8428 "Location list end address (%s)",
8429 list_head
->ll_symbol
);
8432 /* Output the block length for this list of location operations. */
8433 gcc_assert (size
<= 0xffff);
8434 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8436 output_loc_sequence (curr
->expr
, -1);
8439 if (dwarf_split_debug_info
)
8440 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8441 "Location list terminator (%s)",
8442 list_head
->ll_symbol
);
8445 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8446 "Location list terminator begin (%s)",
8447 list_head
->ll_symbol
);
8448 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8449 "Location list terminator end (%s)",
8450 list_head
->ll_symbol
);
8454 /* Output a range_list offset into the debug_range section. Emit a
8455 relocated reference if val_entry is NULL, otherwise, emit an
8456 indirect reference. */
8459 output_range_list_offset (dw_attr_ref a
)
8461 const char *name
= dwarf_attr_name (a
->dw_attr
);
8463 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8465 char *p
= strchr (ranges_section_label
, '\0');
8466 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8467 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8468 debug_ranges_section
, "%s", name
);
8472 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8473 "%s (offset from %s)", name
, ranges_section_label
);
8476 /* Output the offset into the debug_loc section. */
8479 output_loc_list_offset (dw_attr_ref a
)
8481 char *sym
= AT_loc_list (a
)->ll_symbol
;
8484 if (dwarf_split_debug_info
)
8485 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8486 "%s", dwarf_attr_name (a
->dw_attr
));
8488 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8489 "%s", dwarf_attr_name (a
->dw_attr
));
8492 /* Output an attribute's index or value appropriately. */
8495 output_attr_index_or_value (dw_attr_ref a
)
8497 const char *name
= dwarf_attr_name (a
->dw_attr
);
8499 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8501 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8504 switch (AT_class (a
))
8506 case dw_val_class_addr
:
8507 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8509 case dw_val_class_high_pc
:
8510 case dw_val_class_lbl_id
:
8511 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8513 case dw_val_class_loc_list
:
8514 output_loc_list_offset (a
);
8521 /* Output a type signature. */
8524 output_signature (const char *sig
, const char *name
)
8528 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8529 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8532 /* Output the DIE and its attributes. Called recursively to generate
8533 the definitions of each child DIE. */
8536 output_die (dw_die_ref die
)
8543 /* If someone in another CU might refer to us, set up a symbol for
8544 them to point to. */
8545 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8546 output_die_symbol (die
);
8548 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8549 (unsigned long)die
->die_offset
,
8550 dwarf_tag_name (die
->die_tag
));
8552 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8554 const char *name
= dwarf_attr_name (a
->dw_attr
);
8556 switch (AT_class (a
))
8558 case dw_val_class_addr
:
8559 output_attr_index_or_value (a
);
8562 case dw_val_class_offset
:
8563 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8567 case dw_val_class_range_list
:
8568 output_range_list_offset (a
);
8571 case dw_val_class_loc
:
8572 size
= size_of_locs (AT_loc (a
));
8574 /* Output the block length for this list of location operations. */
8575 if (dwarf_version
>= 4)
8576 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8578 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8580 output_loc_sequence (AT_loc (a
), -1);
8583 case dw_val_class_const
:
8584 /* ??? It would be slightly more efficient to use a scheme like is
8585 used for unsigned constants below, but gdb 4.x does not sign
8586 extend. Gdb 5.x does sign extend. */
8587 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8590 case dw_val_class_unsigned_const
:
8592 int csize
= constant_size (AT_unsigned (a
));
8593 if (dwarf_version
== 3
8594 && a
->dw_attr
== DW_AT_data_member_location
8596 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8598 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8602 case dw_val_class_const_double
:
8604 unsigned HOST_WIDE_INT first
, second
;
8606 if (HOST_BITS_PER_WIDE_INT
>= 64)
8607 dw2_asm_output_data (1,
8608 HOST_BITS_PER_DOUBLE_INT
8609 / HOST_BITS_PER_CHAR
,
8612 if (WORDS_BIG_ENDIAN
)
8614 first
= a
->dw_attr_val
.v
.val_double
.high
;
8615 second
= a
->dw_attr_val
.v
.val_double
.low
;
8619 first
= a
->dw_attr_val
.v
.val_double
.low
;
8620 second
= a
->dw_attr_val
.v
.val_double
.high
;
8623 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8625 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8630 case dw_val_class_vec
:
8632 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8633 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8637 dw2_asm_output_data (constant_size (len
* elt_size
),
8638 len
* elt_size
, "%s", name
);
8639 if (elt_size
> sizeof (HOST_WIDE_INT
))
8644 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8647 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8648 "fp or vector constant word %u", i
);
8652 case dw_val_class_flag
:
8653 if (dwarf_version
>= 4)
8655 /* Currently all add_AT_flag calls pass in 1 as last argument,
8656 so DW_FORM_flag_present can be used. If that ever changes,
8657 we'll need to use DW_FORM_flag and have some optimization
8658 in build_abbrev_table that will change those to
8659 DW_FORM_flag_present if it is set to 1 in all DIEs using
8660 the same abbrev entry. */
8661 gcc_assert (AT_flag (a
) == 1);
8663 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8664 ASM_COMMENT_START
, name
);
8667 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8670 case dw_val_class_loc_list
:
8671 output_attr_index_or_value (a
);
8674 case dw_val_class_die_ref
:
8675 if (AT_ref_external (a
))
8677 if (AT_ref (a
)->comdat_type_p
)
8679 comdat_type_node_ref type_node
=
8680 AT_ref (a
)->die_id
.die_type_node
;
8682 gcc_assert (type_node
);
8683 output_signature (type_node
->signature
, name
);
8687 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8691 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8692 length, whereas in DWARF3 it's always sized as an
8694 if (dwarf_version
== 2)
8695 size
= DWARF2_ADDR_SIZE
;
8697 size
= DWARF_OFFSET_SIZE
;
8698 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8704 gcc_assert (AT_ref (a
)->die_offset
);
8705 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8710 case dw_val_class_fde_ref
:
8714 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8715 a
->dw_attr_val
.v
.val_fde_index
* 2);
8716 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8721 case dw_val_class_vms_delta
:
8722 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8723 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8727 case dw_val_class_lbl_id
:
8728 output_attr_index_or_value (a
);
8731 case dw_val_class_lineptr
:
8732 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8733 debug_line_section
, "%s", name
);
8736 case dw_val_class_macptr
:
8737 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8738 debug_macinfo_section
, "%s", name
);
8741 case dw_val_class_str
:
8742 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8743 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8744 a
->dw_attr_val
.v
.val_str
->label
,
8746 "%s: \"%s\"", name
, AT_string (a
));
8747 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8748 dw2_asm_output_data_uleb128 (AT_index (a
),
8749 "%s: \"%s\"", name
, AT_string (a
));
8751 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8754 case dw_val_class_file
:
8756 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8758 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8759 a
->dw_attr_val
.v
.val_file
->filename
);
8763 case dw_val_class_data8
:
8767 for (i
= 0; i
< 8; i
++)
8768 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8769 i
== 0 ? "%s" : NULL
, name
);
8773 case dw_val_class_high_pc
:
8774 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8775 get_AT_low_pc (die
), "DW_AT_high_pc");
8783 FOR_EACH_CHILD (die
, c
, output_die (c
));
8785 /* Add null byte to terminate sibling list. */
8786 if (die
->die_child
!= NULL
)
8787 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8788 (unsigned long) die
->die_offset
);
8791 /* Output the compilation unit that appears at the beginning of the
8792 .debug_info section, and precedes the DIE descriptions. */
8795 output_compilation_unit_header (void)
8797 int ver
= dwarf_version
;
8799 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8800 dw2_asm_output_data (4, 0xffffffff,
8801 "Initial length escape value indicating 64-bit DWARF extension");
8802 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8803 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8804 "Length of Compilation Unit Info");
8805 dw2_asm_output_data (2, ver
, "DWARF version number");
8806 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8807 debug_abbrev_section
,
8808 "Offset Into Abbrev. Section");
8809 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8812 /* Output the compilation unit DIE and its children. */
8815 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8817 const char *secname
, *oldsym
;
8819 external_ref_hash_type extern_map
;
8821 /* Unless we are outputting main CU, we may throw away empty ones. */
8822 if (!output_if_empty
&& die
->die_child
== NULL
)
8825 /* Even if there are no children of this DIE, we must output the information
8826 about the compilation unit. Otherwise, on an empty translation unit, we
8827 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8828 will then complain when examining the file. First mark all the DIEs in
8829 this CU so we know which get local refs. */
8832 extern_map
= optimize_external_refs (die
);
8834 build_abbrev_table (die
, extern_map
);
8836 extern_map
.dispose ();
8838 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8839 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8840 calc_die_sizes (die
);
8842 oldsym
= die
->die_id
.die_symbol
;
8845 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8847 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8849 die
->die_id
.die_symbol
= NULL
;
8850 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8854 switch_to_section (debug_info_section
);
8855 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8856 info_section_emitted
= true;
8859 /* Output debugging information. */
8860 output_compilation_unit_header ();
8863 /* Leave the marks on the main CU, so we can check them in
8868 die
->die_id
.die_symbol
= oldsym
;
8872 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8873 and .debug_pubtypes. This is configured per-target, but can be
8874 overridden by the -gpubnames or -gno-pubnames options. */
8877 want_pubnames (void)
8879 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8881 if (debug_generate_pub_sections
!= -1)
8882 return debug_generate_pub_sections
;
8883 return targetm
.want_debug_pub_sections
;
8886 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8889 add_AT_pubnames (dw_die_ref die
)
8891 if (want_pubnames ())
8892 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8895 /* Add a string attribute value to a skeleton DIE. */
8898 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8902 struct indirect_string_node
*node
;
8904 if (! skeleton_debug_str_hash
)
8905 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8906 debug_str_eq
, NULL
);
8908 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8909 find_string_form (node
);
8910 if (node
->form
== DW_FORM_GNU_str_index
)
8911 node
->form
= DW_FORM_strp
;
8913 attr
.dw_attr
= attr_kind
;
8914 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8915 attr
.dw_attr_val
.val_entry
= NULL
;
8916 attr
.dw_attr_val
.v
.val_str
= node
;
8917 add_dwarf_attr (die
, &attr
);
8920 /* Helper function to generate top-level dies for skeleton debug_info and
8924 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8926 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8927 const char *comp_dir
= comp_dir_string ();
8929 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8930 if (comp_dir
!= NULL
)
8931 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8932 add_AT_pubnames (die
);
8933 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8936 /* Return the single type-unit die for skeleton type units. */
8939 get_skeleton_type_unit (void)
8941 /* For dwarf_split_debug_sections with use_type info, all type units in the
8942 skeleton sections have identical dies (but different headers). This
8943 single die will be output many times. */
8945 static dw_die_ref skeleton_type_unit
= NULL
;
8947 if (skeleton_type_unit
== NULL
)
8949 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8950 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8951 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8953 return skeleton_type_unit
;
8956 /* Output skeleton debug sections that point to the dwo file. */
8959 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8961 /* These attributes will be found in the full debug_info section. */
8962 remove_AT (comp_unit
, DW_AT_producer
);
8963 remove_AT (comp_unit
, DW_AT_language
);
8965 switch_to_section (debug_skeleton_info_section
);
8966 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8968 /* Produce the skeleton compilation-unit header. This one differs enough from
8969 a normal CU header that it's better not to call output_compilation_unit
8971 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8972 dw2_asm_output_data (4, 0xffffffff,
8973 "Initial length escape value indicating 64-bit DWARF extension");
8975 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8976 DWARF_COMPILE_UNIT_HEADER_SIZE
8977 - DWARF_INITIAL_LENGTH_SIZE
8978 + size_of_die (comp_unit
),
8979 "Length of Compilation Unit Info");
8980 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8981 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8982 debug_abbrev_section
,
8983 "Offset Into Abbrev. Section");
8984 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8986 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8987 output_die (comp_unit
);
8989 /* Build the skeleton debug_abbrev section. */
8990 switch_to_section (debug_skeleton_abbrev_section
);
8991 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8993 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8994 if (use_debug_types
)
8995 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8997 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9000 /* Output a comdat type unit DIE and its children. */
9003 output_comdat_type_unit (comdat_type_node
*node
)
9005 const char *secname
;
9008 #if defined (OBJECT_FORMAT_ELF)
9011 external_ref_hash_type extern_map
;
9013 /* First mark all the DIEs in this CU so we know which get local refs. */
9014 mark_dies (node
->root_die
);
9016 extern_map
= optimize_external_refs (node
->root_die
);
9018 build_abbrev_table (node
->root_die
, extern_map
);
9020 extern_map
.dispose ();
9022 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9023 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9024 calc_die_sizes (node
->root_die
);
9026 #if defined (OBJECT_FORMAT_ELF)
9027 if (!dwarf_split_debug_info
)
9028 secname
= ".debug_types";
9030 secname
= ".debug_types.dwo";
9032 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9033 sprintf (tmp
, "wt.");
9034 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9035 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9036 comdat_key
= get_identifier (tmp
);
9037 targetm
.asm_out
.named_section (secname
,
9038 SECTION_DEBUG
| SECTION_LINKONCE
,
9041 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9042 sprintf (tmp
, ".gnu.linkonce.wt.");
9043 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9044 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9046 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9049 /* Output debugging information. */
9050 output_compilation_unit_header ();
9051 output_signature (node
->signature
, "Type Signature");
9052 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9053 "Offset to Type DIE");
9054 output_die (node
->root_die
);
9056 unmark_dies (node
->root_die
);
9058 #if defined (OBJECT_FORMAT_ELF)
9059 if (dwarf_split_debug_info
)
9061 /* Produce the skeleton type-unit header. */
9062 const char *secname
= ".debug_types";
9064 targetm
.asm_out
.named_section (secname
,
9065 SECTION_DEBUG
| SECTION_LINKONCE
,
9067 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9068 dw2_asm_output_data (4, 0xffffffff,
9069 "Initial length escape value indicating 64-bit DWARF extension");
9071 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9072 DWARF_COMPILE_UNIT_HEADER_SIZE
9073 - DWARF_INITIAL_LENGTH_SIZE
9074 + size_of_die (get_skeleton_type_unit ())
9075 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9076 "Length of Type Unit Info");
9077 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9078 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9079 debug_skeleton_abbrev_section_label
,
9080 debug_abbrev_section
,
9081 "Offset Into Abbrev. Section");
9082 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9083 output_signature (node
->signature
, "Type Signature");
9084 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9086 output_die (get_skeleton_type_unit ());
9091 /* Return the DWARF2/3 pubname associated with a decl. */
9094 dwarf2_name (tree decl
, int scope
)
9096 if (DECL_NAMELESS (decl
))
9098 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9101 /* Add a new entry to .debug_pubnames if appropriate. */
9104 add_pubname_string (const char *str
, dw_die_ref die
)
9109 e
.name
= xstrdup (str
);
9110 vec_safe_push (pubname_table
, e
);
9114 add_pubname (tree decl
, dw_die_ref die
)
9116 if (!want_pubnames ())
9119 /* Don't add items to the table when we expect that the consumer will have
9120 just read the enclosing die. For example, if the consumer is looking at a
9121 class_member, it will either be inside the class already, or will have just
9122 looked up the class to find the member. Either way, searching the class is
9123 faster than searching the index. */
9124 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9125 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9127 const char *name
= dwarf2_name (decl
, 1);
9130 add_pubname_string (name
, die
);
9134 /* Add an enumerator to the pubnames section. */
9137 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9141 gcc_assert (scope_name
);
9142 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9144 vec_safe_push (pubname_table
, e
);
9147 /* Add a new entry to .debug_pubtypes if appropriate. */
9150 add_pubtype (tree decl
, dw_die_ref die
)
9154 if (!want_pubnames ())
9157 if ((TREE_PUBLIC (decl
)
9158 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9159 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9162 const char *scope_name
= "";
9163 const char *sep
= is_cxx () ? "::" : ".";
9166 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9167 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9169 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9170 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9171 scope_name
= concat (scope_name
, sep
, NULL
);
9177 name
= type_tag (decl
);
9179 name
= lang_hooks
.dwarf_name (decl
, 1);
9181 /* If we don't have a name for the type, there's no point in adding
9183 if (name
!= NULL
&& name
[0] != '\0')
9186 e
.name
= concat (scope_name
, name
, NULL
);
9187 vec_safe_push (pubtype_table
, e
);
9190 /* Although it might be more consistent to add the pubinfo for the
9191 enumerators as their dies are created, they should only be added if the
9192 enum type meets the criteria above. So rather than re-check the parent
9193 enum type whenever an enumerator die is created, just output them all
9194 here. This isn't protected by the name conditional because anonymous
9195 enums don't have names. */
9196 if (die
->die_tag
== DW_TAG_enumeration_type
)
9200 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9205 /* Output a single entry in the pubnames table. */
9208 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9210 dw_die_ref die
= entry
->die
;
9211 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9213 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9215 if (debug_generate_pub_sections
== 2)
9217 /* This logic follows gdb's method for determining the value of the flag
9219 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9220 switch (die
->die_tag
)
9222 case DW_TAG_typedef
:
9223 case DW_TAG_base_type
:
9224 case DW_TAG_subrange_type
:
9225 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9226 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9228 case DW_TAG_enumerator
:
9229 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9230 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9231 if (!is_cxx () && !is_java ())
9232 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9234 case DW_TAG_subprogram
:
9235 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9236 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9238 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9240 case DW_TAG_constant
:
9241 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9242 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9243 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9245 case DW_TAG_variable
:
9246 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9247 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9248 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9250 case DW_TAG_namespace
:
9251 case DW_TAG_imported_declaration
:
9252 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9254 case DW_TAG_class_type
:
9255 case DW_TAG_interface_type
:
9256 case DW_TAG_structure_type
:
9257 case DW_TAG_union_type
:
9258 case DW_TAG_enumeration_type
:
9259 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9260 if (!is_cxx () && !is_java ())
9261 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9264 /* An unusual tag. Leave the flag-byte empty. */
9267 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9271 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9275 /* Output the public names table used to speed up access to externally
9276 visible names; or the public types table used to find type definitions. */
9279 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9282 unsigned long pubnames_length
= size_of_pubnames (names
);
9285 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9286 dw2_asm_output_data (4, 0xffffffff,
9287 "Initial length escape value indicating 64-bit DWARF extension");
9288 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9290 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9291 dw2_asm_output_data (2, 2, "DWARF Version");
9293 if (dwarf_split_debug_info
)
9294 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9295 debug_skeleton_info_section
,
9296 "Offset of Compilation Unit Info");
9298 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9300 "Offset of Compilation Unit Info");
9301 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9302 "Compilation Unit Length");
9304 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9306 if (include_pubname_in_output (names
, pub
))
9308 dw_offset die_offset
= pub
->die
->die_offset
;
9310 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9311 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9312 gcc_assert (pub
->die
->die_mark
);
9314 /* If we're putting types in their own .debug_types sections,
9315 the .debug_pubtypes table will still point to the compile
9316 unit (not the type unit), so we want to use the offset of
9317 the skeleton DIE (if there is one). */
9318 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9320 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9322 if (type_node
!= NULL
)
9323 die_offset
= (type_node
->skeleton_die
!= NULL
9324 ? type_node
->skeleton_die
->die_offset
9325 : comp_unit_die ()->die_offset
);
9328 output_pubname (die_offset
, pub
);
9332 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9335 /* Output public names and types tables if necessary. */
9338 output_pubtables (void)
9340 if (!want_pubnames () || !info_section_emitted
)
9343 switch_to_section (debug_pubnames_section
);
9344 output_pubnames (pubname_table
);
9345 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9346 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9347 simply won't look for the section. */
9348 switch_to_section (debug_pubtypes_section
);
9349 output_pubnames (pubtype_table
);
9353 /* Output the information that goes into the .debug_aranges table.
9354 Namely, define the beginning and ending address range of the
9355 text section generated for this compilation unit. */
9358 output_aranges (unsigned long aranges_length
)
9362 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9363 dw2_asm_output_data (4, 0xffffffff,
9364 "Initial length escape value indicating 64-bit DWARF extension");
9365 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9366 "Length of Address Ranges Info");
9367 /* Version number for aranges is still 2, even in DWARF3. */
9368 dw2_asm_output_data (2, 2, "DWARF Version");
9369 if (dwarf_split_debug_info
)
9370 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9371 debug_skeleton_info_section
,
9372 "Offset of Compilation Unit Info");
9374 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9376 "Offset of Compilation Unit Info");
9377 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9378 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9380 /* We need to align to twice the pointer size here. */
9381 if (DWARF_ARANGES_PAD_SIZE
)
9383 /* Pad using a 2 byte words so that padding is correct for any
9385 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9386 2 * DWARF2_ADDR_SIZE
);
9387 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9388 dw2_asm_output_data (2, 0, NULL
);
9391 /* It is necessary not to output these entries if the sections were
9392 not used; if the sections were not used, the length will be 0 and
9393 the address may end up as 0 if the section is discarded by ld
9394 --gc-sections, leaving an invalid (0, 0) entry that can be
9395 confused with the terminator. */
9396 if (text_section_used
)
9398 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9399 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9400 text_section_label
, "Length");
9402 if (cold_text_section_used
)
9404 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9406 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9407 cold_text_section_label
, "Length");
9410 if (have_multiple_function_sections
)
9415 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9417 if (DECL_IGNORED_P (fde
->decl
))
9419 if (!fde
->in_std_section
)
9421 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9423 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9424 fde
->dw_fde_begin
, "Length");
9426 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9428 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9430 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9431 fde
->dw_fde_second_begin
, "Length");
9436 /* Output the terminator words. */
9437 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9438 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9441 /* Add a new entry to .debug_ranges. Return the offset at which it
9445 add_ranges_num (int num
)
9447 unsigned int in_use
= ranges_table_in_use
;
9449 if (in_use
== ranges_table_allocated
)
9451 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9452 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9453 ranges_table_allocated
);
9454 memset (ranges_table
+ ranges_table_in_use
, 0,
9455 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9458 ranges_table
[in_use
].num
= num
;
9459 ranges_table_in_use
= in_use
+ 1;
9461 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9464 /* Add a new entry to .debug_ranges corresponding to a block, or a
9465 range terminator if BLOCK is NULL. */
9468 add_ranges (const_tree block
)
9470 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9473 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9474 When using dwarf_split_debug_info, address attributes in dies destined
9475 for the final executable should be direct references--setting the
9476 parameter force_direct ensures this behavior. */
9479 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9480 bool *added
, bool force_direct
)
9482 unsigned int in_use
= ranges_by_label_in_use
;
9483 unsigned int offset
;
9485 if (in_use
== ranges_by_label_allocated
)
9487 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9488 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9490 ranges_by_label_allocated
);
9491 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9492 RANGES_TABLE_INCREMENT
9493 * sizeof (struct dw_ranges_by_label_struct
));
9496 ranges_by_label
[in_use
].begin
= begin
;
9497 ranges_by_label
[in_use
].end
= end
;
9498 ranges_by_label_in_use
= in_use
+ 1;
9500 offset
= add_ranges_num (-(int)in_use
- 1);
9503 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9509 output_ranges (void)
9512 static const char *const start_fmt
= "Offset %#x";
9513 const char *fmt
= start_fmt
;
9515 for (i
= 0; i
< ranges_table_in_use
; i
++)
9517 int block_num
= ranges_table
[i
].num
;
9521 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9522 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9524 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9525 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9527 /* If all code is in the text section, then the compilation
9528 unit base address defaults to DW_AT_low_pc, which is the
9529 base of the text section. */
9530 if (!have_multiple_function_sections
)
9532 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9534 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9535 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9536 text_section_label
, NULL
);
9539 /* Otherwise, the compilation unit base address is zero,
9540 which allows us to use absolute addresses, and not worry
9541 about whether the target supports cross-section
9545 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9546 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9547 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9553 /* Negative block_num stands for an index into ranges_by_label. */
9554 else if (block_num
< 0)
9556 int lab_idx
= - block_num
- 1;
9558 if (!have_multiple_function_sections
)
9562 /* If we ever use add_ranges_by_labels () for a single
9563 function section, all we have to do is to take out
9565 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9566 ranges_by_label
[lab_idx
].begin
,
9568 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9569 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9570 ranges_by_label
[lab_idx
].end
,
9571 text_section_label
, NULL
);
9576 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9577 ranges_by_label
[lab_idx
].begin
,
9578 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9579 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9580 ranges_by_label
[lab_idx
].end
,
9586 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9587 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9593 /* Data structure containing information about input files. */
9596 const char *path
; /* Complete file name. */
9597 const char *fname
; /* File name part. */
9598 int length
; /* Length of entire string. */
9599 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9600 int dir_idx
; /* Index in directory table. */
9603 /* Data structure containing information about directories with source
9607 const char *path
; /* Path including directory name. */
9608 int length
; /* Path length. */
9609 int prefix
; /* Index of directory entry which is a prefix. */
9610 int count
; /* Number of files in this directory. */
9611 int dir_idx
; /* Index of directory used as base. */
9614 /* Callback function for file_info comparison. We sort by looking at
9615 the directories in the path. */
9618 file_info_cmp (const void *p1
, const void *p2
)
9620 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9621 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9622 const unsigned char *cp1
;
9623 const unsigned char *cp2
;
9625 /* Take care of file names without directories. We need to make sure that
9626 we return consistent values to qsort since some will get confused if
9627 we return the same value when identical operands are passed in opposite
9628 orders. So if neither has a directory, return 0 and otherwise return
9629 1 or -1 depending on which one has the directory. */
9630 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9631 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9633 cp1
= (const unsigned char *) s1
->path
;
9634 cp2
= (const unsigned char *) s2
->path
;
9640 /* Reached the end of the first path? If so, handle like above. */
9641 if ((cp1
== (const unsigned char *) s1
->fname
)
9642 || (cp2
== (const unsigned char *) s2
->fname
))
9643 return ((cp2
== (const unsigned char *) s2
->fname
)
9644 - (cp1
== (const unsigned char *) s1
->fname
));
9646 /* Character of current path component the same? */
9647 else if (*cp1
!= *cp2
)
9652 struct file_name_acquire_data
9654 struct file_info
*files
;
9659 /* Traversal function for the hash table. */
9662 file_name_acquire (void ** slot
, void *data
)
9664 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9665 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9666 struct file_info
*fi
;
9669 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9671 if (! d
->emitted_number
)
9674 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9676 fi
= fnad
->files
+ fnad
->used_files
++;
9678 /* Skip all leading "./". */
9680 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9683 /* Create a new array entry. */
9685 fi
->length
= strlen (f
);
9688 /* Search for the file name part. */
9689 f
= strrchr (f
, DIR_SEPARATOR
);
9690 #if defined (DIR_SEPARATOR_2)
9692 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9696 if (f
== NULL
|| f
< g
)
9702 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9706 /* Output the directory table and the file name table. We try to minimize
9707 the total amount of memory needed. A heuristic is used to avoid large
9708 slowdowns with many input files. */
9711 output_file_names (void)
9713 struct file_name_acquire_data fnad
;
9715 struct file_info
*files
;
9716 struct dir_info
*dirs
;
9724 if (!last_emitted_file
)
9726 dw2_asm_output_data (1, 0, "End directory table");
9727 dw2_asm_output_data (1, 0, "End file name table");
9731 numfiles
= last_emitted_file
->emitted_number
;
9733 /* Allocate the various arrays we need. */
9734 files
= XALLOCAVEC (struct file_info
, numfiles
);
9735 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9738 fnad
.used_files
= 0;
9739 fnad
.max_files
= numfiles
;
9740 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9741 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9743 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9745 /* Find all the different directories used. */
9746 dirs
[0].path
= files
[0].path
;
9747 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9748 dirs
[0].prefix
= -1;
9750 dirs
[0].dir_idx
= 0;
9751 files
[0].dir_idx
= 0;
9754 for (i
= 1; i
< numfiles
; i
++)
9755 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9756 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9757 dirs
[ndirs
- 1].length
) == 0)
9759 /* Same directory as last entry. */
9760 files
[i
].dir_idx
= ndirs
- 1;
9761 ++dirs
[ndirs
- 1].count
;
9767 /* This is a new directory. */
9768 dirs
[ndirs
].path
= files
[i
].path
;
9769 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9770 dirs
[ndirs
].count
= 1;
9771 dirs
[ndirs
].dir_idx
= ndirs
;
9772 files
[i
].dir_idx
= ndirs
;
9774 /* Search for a prefix. */
9775 dirs
[ndirs
].prefix
= -1;
9776 for (j
= 0; j
< ndirs
; j
++)
9777 if (dirs
[j
].length
< dirs
[ndirs
].length
9778 && dirs
[j
].length
> 1
9779 && (dirs
[ndirs
].prefix
== -1
9780 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9781 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9782 dirs
[ndirs
].prefix
= j
;
9787 /* Now to the actual work. We have to find a subset of the directories which
9788 allow expressing the file name using references to the directory table
9789 with the least amount of characters. We do not do an exhaustive search
9790 where we would have to check out every combination of every single
9791 possible prefix. Instead we use a heuristic which provides nearly optimal
9792 results in most cases and never is much off. */
9793 saved
= XALLOCAVEC (int, ndirs
);
9794 savehere
= XALLOCAVEC (int, ndirs
);
9796 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9797 for (i
= 0; i
< ndirs
; i
++)
9802 /* We can always save some space for the current directory. But this
9803 does not mean it will be enough to justify adding the directory. */
9804 savehere
[i
] = dirs
[i
].length
;
9805 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9807 for (j
= i
+ 1; j
< ndirs
; j
++)
9810 if (saved
[j
] < dirs
[i
].length
)
9812 /* Determine whether the dirs[i] path is a prefix of the
9817 while (k
!= -1 && k
!= (int) i
)
9822 /* Yes it is. We can possibly save some memory by
9823 writing the filenames in dirs[j] relative to
9825 savehere
[j
] = dirs
[i
].length
;
9826 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9831 /* Check whether we can save enough to justify adding the dirs[i]
9833 if (total
> dirs
[i
].length
+ 1)
9835 /* It's worthwhile adding. */
9836 for (j
= i
; j
< ndirs
; j
++)
9837 if (savehere
[j
] > 0)
9839 /* Remember how much we saved for this directory so far. */
9840 saved
[j
] = savehere
[j
];
9842 /* Remember the prefix directory. */
9843 dirs
[j
].dir_idx
= i
;
9848 /* Emit the directory name table. */
9849 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9850 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9851 dw2_asm_output_nstring (dirs
[i
].path
,
9853 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9854 "Directory Entry: %#x", i
+ idx_offset
);
9856 dw2_asm_output_data (1, 0, "End directory table");
9858 /* We have to emit them in the order of emitted_number since that's
9859 used in the debug info generation. To do this efficiently we
9860 generate a back-mapping of the indices first. */
9861 backmap
= XALLOCAVEC (int, numfiles
);
9862 for (i
= 0; i
< numfiles
; i
++)
9863 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9865 /* Now write all the file names. */
9866 for (i
= 0; i
< numfiles
; i
++)
9868 int file_idx
= backmap
[i
];
9869 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9871 #ifdef VMS_DEBUGGING_INFO
9872 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9874 /* Setting these fields can lead to debugger miscomparisons,
9875 but VMS Debug requires them to be set correctly. */
9880 int maxfilelen
= strlen (files
[file_idx
].path
)
9881 + dirs
[dir_idx
].length
9882 + MAX_VMS_VERSION_LEN
+ 1;
9883 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9885 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9886 snprintf (filebuf
, maxfilelen
, "%s;%d",
9887 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9889 dw2_asm_output_nstring
9890 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9892 /* Include directory index. */
9893 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9895 /* Modification time. */
9896 dw2_asm_output_data_uleb128
9897 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9901 /* File length in bytes. */
9902 dw2_asm_output_data_uleb128
9903 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9907 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9908 "File Entry: %#x", (unsigned) i
+ 1);
9910 /* Include directory index. */
9911 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9913 /* Modification time. */
9914 dw2_asm_output_data_uleb128 (0, NULL
);
9916 /* File length in bytes. */
9917 dw2_asm_output_data_uleb128 (0, NULL
);
9918 #endif /* VMS_DEBUGGING_INFO */
9921 dw2_asm_output_data (1, 0, "End file name table");
9925 /* Output one line number table into the .debug_line section. */
9928 output_one_line_info_table (dw_line_info_table
*table
)
9930 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9931 unsigned int current_line
= 1;
9932 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9933 dw_line_info_entry
*ent
;
9936 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9938 switch (ent
->opcode
)
9940 case LI_set_address
:
9941 /* ??? Unfortunately, we have little choice here currently, and
9942 must always use the most general form. GCC does not know the
9943 address delta itself, so we can't use DW_LNS_advance_pc. Many
9944 ports do have length attributes which will give an upper bound
9945 on the address range. We could perhaps use length attributes
9946 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9947 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9949 /* This can handle any delta. This takes
9950 4+DWARF2_ADDR_SIZE bytes. */
9951 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9952 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9953 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9954 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9958 if (ent
->val
== current_line
)
9960 /* We still need to start a new row, so output a copy insn. */
9961 dw2_asm_output_data (1, DW_LNS_copy
,
9962 "copy line %u", current_line
);
9966 int line_offset
= ent
->val
- current_line
;
9967 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9969 current_line
= ent
->val
;
9970 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9972 /* This can handle deltas from -10 to 234, using the current
9973 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9974 This takes 1 byte. */
9975 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9976 "line %u", current_line
);
9980 /* This can handle any delta. This takes at least 4 bytes,
9981 depending on the value being encoded. */
9982 dw2_asm_output_data (1, DW_LNS_advance_line
,
9983 "advance to line %u", current_line
);
9984 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9985 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9991 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9992 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9996 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9997 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10000 case LI_negate_stmt
:
10001 current_is_stmt
= !current_is_stmt
;
10002 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10003 "is_stmt %d", current_is_stmt
);
10006 case LI_set_prologue_end
:
10007 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10008 "set prologue end");
10011 case LI_set_epilogue_begin
:
10012 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10013 "set epilogue begin");
10016 case LI_set_discriminator
:
10017 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10018 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10019 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10020 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10025 /* Emit debug info for the address of the end of the table. */
10026 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10027 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10028 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10029 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10031 dw2_asm_output_data (1, 0, "end sequence");
10032 dw2_asm_output_data_uleb128 (1, NULL
);
10033 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10036 /* Output the source line number correspondence information. This
10037 information goes into the .debug_line section. */
10040 output_line_info (bool prologue_only
)
10042 char l1
[20], l2
[20], p1
[20], p2
[20];
10043 int ver
= dwarf_version
;
10044 bool saw_one
= false;
10047 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10048 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10049 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10050 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10052 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10053 dw2_asm_output_data (4, 0xffffffff,
10054 "Initial length escape value indicating 64-bit DWARF extension");
10055 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10056 "Length of Source Line Info");
10057 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10059 dw2_asm_output_data (2, ver
, "DWARF Version");
10060 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10061 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10063 /* Define the architecture-dependent minimum instruction length (in bytes).
10064 In this implementation of DWARF, this field is used for information
10065 purposes only. Since GCC generates assembly language, we have no
10066 a priori knowledge of how many instruction bytes are generated for each
10067 source line, and therefore can use only the DW_LNE_set_address and
10068 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10069 this as '1', which is "correct enough" for all architectures,
10070 and don't let the target override. */
10071 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10074 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10075 "Maximum Operations Per Instruction");
10076 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10077 "Default is_stmt_start flag");
10078 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10079 "Line Base Value (Special Opcodes)");
10080 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10081 "Line Range Value (Special Opcodes)");
10082 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10083 "Special Opcode Base");
10085 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10090 case DW_LNS_advance_pc
:
10091 case DW_LNS_advance_line
:
10092 case DW_LNS_set_file
:
10093 case DW_LNS_set_column
:
10094 case DW_LNS_fixed_advance_pc
:
10095 case DW_LNS_set_isa
:
10103 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10107 /* Write out the information about the files we use. */
10108 output_file_names ();
10109 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10112 /* Output the marker for the end of the line number info. */
10113 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10117 if (separate_line_info
)
10119 dw_line_info_table
*table
;
10122 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10125 output_one_line_info_table (table
);
10129 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10131 output_one_line_info_table (cold_text_section_line_info
);
10135 /* ??? Some Darwin linkers crash on a .debug_line section with no
10136 sequences. Further, merely a DW_LNE_end_sequence entry is not
10137 sufficient -- the address column must also be initialized.
10138 Make sure to output at least one set_address/end_sequence pair,
10139 choosing .text since that section is always present. */
10140 if (text_section_line_info
->in_use
|| !saw_one
)
10141 output_one_line_info_table (text_section_line_info
);
10143 /* Output the marker for the end of the line number info. */
10144 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10147 /* Given a pointer to a tree node for some base type, return a pointer to
10148 a DIE that describes the given type.
10150 This routine must only be called for GCC type nodes that correspond to
10151 Dwarf base (fundamental) types. */
10154 base_type_die (tree type
)
10156 dw_die_ref base_type_result
;
10157 enum dwarf_type encoding
;
10159 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10162 /* If this is a subtype that should not be emitted as a subrange type,
10163 use the base type. See subrange_type_for_debug_p. */
10164 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10165 type
= TREE_TYPE (type
);
10167 switch (TREE_CODE (type
))
10170 if ((dwarf_version
>= 4 || !dwarf_strict
)
10171 && TYPE_NAME (type
)
10172 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10173 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10174 && DECL_NAME (TYPE_NAME (type
)))
10176 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10177 if (strcmp (name
, "char16_t") == 0
10178 || strcmp (name
, "char32_t") == 0)
10180 encoding
= DW_ATE_UTF
;
10184 if (TYPE_STRING_FLAG (type
))
10186 if (TYPE_UNSIGNED (type
))
10187 encoding
= DW_ATE_unsigned_char
;
10189 encoding
= DW_ATE_signed_char
;
10191 else if (TYPE_UNSIGNED (type
))
10192 encoding
= DW_ATE_unsigned
;
10194 encoding
= DW_ATE_signed
;
10198 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10200 if (dwarf_version
>= 3 || !dwarf_strict
)
10201 encoding
= DW_ATE_decimal_float
;
10203 encoding
= DW_ATE_lo_user
;
10206 encoding
= DW_ATE_float
;
10209 case FIXED_POINT_TYPE
:
10210 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10211 encoding
= DW_ATE_lo_user
;
10212 else if (TYPE_UNSIGNED (type
))
10213 encoding
= DW_ATE_unsigned_fixed
;
10215 encoding
= DW_ATE_signed_fixed
;
10218 /* Dwarf2 doesn't know anything about complex ints, so use
10219 a user defined type for it. */
10221 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10222 encoding
= DW_ATE_complex_float
;
10224 encoding
= DW_ATE_lo_user
;
10228 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10229 encoding
= DW_ATE_boolean
;
10233 /* No other TREE_CODEs are Dwarf fundamental types. */
10234 gcc_unreachable ();
10237 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10239 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10240 int_size_in_bytes (type
));
10241 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10242 add_pubtype (type
, base_type_result
);
10244 return base_type_result
;
10247 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10248 named 'auto' in its type: return true for it, false otherwise. */
10251 is_cxx_auto (tree type
)
10255 tree name
= TYPE_IDENTIFIER (type
);
10256 if (name
== get_identifier ("auto")
10257 || name
== get_identifier ("decltype(auto)"))
10263 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10264 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10267 is_base_type (tree type
)
10269 switch (TREE_CODE (type
))
10275 case FIXED_POINT_TYPE
:
10283 case QUAL_UNION_TYPE
:
10284 case ENUMERAL_TYPE
:
10285 case FUNCTION_TYPE
:
10288 case REFERENCE_TYPE
:
10296 if (is_cxx_auto (type
))
10298 gcc_unreachable ();
10304 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10305 node, return the size in bits for the type if it is a constant, or else
10306 return the alignment for the type if the type's size is not constant, or
10307 else return BITS_PER_WORD if the type actually turns out to be an
10308 ERROR_MARK node. */
10310 static inline unsigned HOST_WIDE_INT
10311 simple_type_size_in_bits (const_tree type
)
10313 if (TREE_CODE (type
) == ERROR_MARK
)
10314 return BITS_PER_WORD
;
10315 else if (TYPE_SIZE (type
) == NULL_TREE
)
10317 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10318 return tree_to_uhwi (TYPE_SIZE (type
));
10320 return TYPE_ALIGN (type
);
10323 /* Similarly, but return a double_int instead of UHWI. */
10325 static inline double_int
10326 double_int_type_size_in_bits (const_tree type
)
10328 if (TREE_CODE (type
) == ERROR_MARK
)
10329 return double_int::from_uhwi (BITS_PER_WORD
);
10330 else if (TYPE_SIZE (type
) == NULL_TREE
)
10331 return double_int_zero
;
10332 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10333 return tree_to_double_int (TYPE_SIZE (type
));
10335 return double_int::from_uhwi (TYPE_ALIGN (type
));
10338 /* Given a pointer to a tree node for a subrange type, return a pointer
10339 to a DIE that describes the given type. */
10342 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10344 dw_die_ref subrange_die
;
10345 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10347 if (context_die
== NULL
)
10348 context_die
= comp_unit_die ();
10350 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10352 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10354 /* The size of the subrange type and its base type do not match,
10355 so we need to generate a size attribute for the subrange type. */
10356 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10360 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10362 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10364 return subrange_die
;
10367 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10368 entry that chains various modifiers in front of the given type. */
10371 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10372 dw_die_ref context_die
)
10374 enum tree_code code
= TREE_CODE (type
);
10375 dw_die_ref mod_type_die
;
10376 dw_die_ref sub_die
= NULL
;
10377 tree item_type
= NULL
;
10378 tree qualified_type
;
10379 tree name
, low
, high
;
10380 dw_die_ref mod_scope
;
10382 if (code
== ERROR_MARK
)
10385 /* See if we already have the appropriately qualified variant of
10388 = get_qualified_type (type
,
10389 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10390 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10392 if (qualified_type
== sizetype
10393 && TYPE_NAME (qualified_type
)
10394 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10396 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10398 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10399 && TYPE_PRECISION (t
)
10400 == TYPE_PRECISION (qualified_type
)
10401 && TYPE_UNSIGNED (t
)
10402 == TYPE_UNSIGNED (qualified_type
));
10403 qualified_type
= t
;
10406 /* If we do, then we can just use its DIE, if it exists. */
10407 if (qualified_type
)
10409 mod_type_die
= lookup_type_die (qualified_type
);
10411 return mod_type_die
;
10414 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10416 /* Handle C typedef types. */
10417 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10418 && !DECL_ARTIFICIAL (name
))
10420 tree dtype
= TREE_TYPE (name
);
10422 if (qualified_type
== dtype
)
10424 /* For a named type, use the typedef. */
10425 gen_type_die (qualified_type
, context_die
);
10426 return lookup_type_die (qualified_type
);
10428 else if (is_const_type
< TYPE_READONLY (dtype
)
10429 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10430 || (is_const_type
<= TYPE_READONLY (dtype
)
10431 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10432 && DECL_ORIGINAL_TYPE (name
) != type
))
10433 /* cv-unqualified version of named type. Just use the unnamed
10434 type to which it refers. */
10435 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10436 is_const_type
, is_volatile_type
,
10438 /* Else cv-qualified version of named type; fall through. */
10441 mod_scope
= scope_die_for (type
, context_die
);
10444 /* If both is_const_type and is_volatile_type, prefer the path
10445 which leads to a qualified type. */
10446 && (!is_volatile_type
10447 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10448 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10450 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10451 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10453 else if (is_volatile_type
)
10455 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10456 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10458 else if (code
== POINTER_TYPE
)
10460 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10461 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10462 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10463 item_type
= TREE_TYPE (type
);
10464 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10465 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10466 TYPE_ADDR_SPACE (item_type
));
10468 else if (code
== REFERENCE_TYPE
)
10470 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10471 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10474 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10475 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10476 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10477 item_type
= TREE_TYPE (type
);
10478 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10479 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10480 TYPE_ADDR_SPACE (item_type
));
10482 else if (code
== INTEGER_TYPE
10483 && TREE_TYPE (type
) != NULL_TREE
10484 && subrange_type_for_debug_p (type
, &low
, &high
))
10486 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10487 item_type
= TREE_TYPE (type
);
10489 else if (is_base_type (type
))
10490 mod_type_die
= base_type_die (type
);
10493 gen_type_die (type
, context_die
);
10495 /* We have to get the type_main_variant here (and pass that to the
10496 `lookup_type_die' routine) because the ..._TYPE node we have
10497 might simply be a *copy* of some original type node (where the
10498 copy was created to help us keep track of typedef names) and
10499 that copy might have a different TYPE_UID from the original
10501 if (TREE_CODE (type
) != VECTOR_TYPE
)
10502 return lookup_type_die (type_main_variant (type
));
10504 /* Vectors have the debugging information in the type,
10505 not the main variant. */
10506 return lookup_type_die (type
);
10509 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10510 don't output a DW_TAG_typedef, since there isn't one in the
10511 user's program; just attach a DW_AT_name to the type.
10512 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10513 if the base type already has the same name. */
10515 && ((TREE_CODE (name
) != TYPE_DECL
10516 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10517 || (!is_const_type
&& !is_volatile_type
)))
10518 || (TREE_CODE (name
) == TYPE_DECL
10519 && TREE_TYPE (name
) == qualified_type
10520 && DECL_NAME (name
))))
10522 if (TREE_CODE (name
) == TYPE_DECL
)
10523 /* Could just call add_name_and_src_coords_attributes here,
10524 but since this is a builtin type it doesn't have any
10525 useful source coordinates anyway. */
10526 name
= DECL_NAME (name
);
10527 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10529 /* This probably indicates a bug. */
10530 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10532 name
= TYPE_IDENTIFIER (type
);
10533 add_name_attribute (mod_type_die
,
10534 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10537 if (qualified_type
)
10538 equate_type_number_to_die (qualified_type
, mod_type_die
);
10541 /* We must do this after the equate_type_number_to_die call, in case
10542 this is a recursive type. This ensures that the modified_type_die
10543 recursion will terminate even if the type is recursive. Recursive
10544 types are possible in Ada. */
10545 sub_die
= modified_type_die (item_type
,
10546 TYPE_READONLY (item_type
),
10547 TYPE_VOLATILE (item_type
),
10550 if (sub_die
!= NULL
)
10551 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10553 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10554 if (TYPE_ARTIFICIAL (type
))
10555 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10557 return mod_type_die
;
10560 /* Generate DIEs for the generic parameters of T.
10561 T must be either a generic type or a generic function.
10562 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10565 gen_generic_params_dies (tree t
)
10569 dw_die_ref die
= NULL
;
10572 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10576 die
= lookup_type_die (t
);
10577 else if (DECL_P (t
))
10578 die
= lookup_decl_die (t
);
10582 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10584 /* T has no generic parameter. It means T is neither a generic type
10585 or function. End of story. */
10588 parms_num
= TREE_VEC_LENGTH (parms
);
10589 args
= lang_hooks
.get_innermost_generic_args (t
);
10590 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10591 non_default
= int_cst_value (TREE_CHAIN (args
));
10593 non_default
= TREE_VEC_LENGTH (args
);
10594 for (i
= 0; i
< parms_num
; i
++)
10596 tree parm
, arg
, arg_pack_elems
;
10597 dw_die_ref parm_die
;
10599 parm
= TREE_VEC_ELT (parms
, i
);
10600 arg
= TREE_VEC_ELT (args
, i
);
10601 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10602 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10604 if (parm
&& TREE_VALUE (parm
) && arg
)
10606 /* If PARM represents a template parameter pack,
10607 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10608 by DW_TAG_template_*_parameter DIEs for the argument
10609 pack elements of ARG. Note that ARG would then be
10610 an argument pack. */
10611 if (arg_pack_elems
)
10612 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10616 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10617 true /* emit name */, die
);
10618 if (i
>= non_default
)
10619 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10624 /* Create and return a DIE for PARM which should be
10625 the representation of a generic type parameter.
10626 For instance, in the C++ front end, PARM would be a template parameter.
10627 ARG is the argument to PARM.
10628 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10630 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10631 as a child node. */
10634 generic_parameter_die (tree parm
, tree arg
,
10636 dw_die_ref parent_die
)
10638 dw_die_ref tmpl_die
= NULL
;
10639 const char *name
= NULL
;
10641 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10644 /* We support non-type generic parameters and arguments,
10645 type generic parameters and arguments, as well as
10646 generic generic parameters (a.k.a. template template parameters in C++)
10648 if (TREE_CODE (parm
) == PARM_DECL
)
10649 /* PARM is a nontype generic parameter */
10650 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10651 else if (TREE_CODE (parm
) == TYPE_DECL
)
10652 /* PARM is a type generic parameter. */
10653 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10654 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10655 /* PARM is a generic generic parameter.
10656 Its DIE is a GNU extension. It shall have a
10657 DW_AT_name attribute to represent the name of the template template
10658 parameter, and a DW_AT_GNU_template_name attribute to represent the
10659 name of the template template argument. */
10660 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10663 gcc_unreachable ();
10669 /* If PARM is a generic parameter pack, it means we are
10670 emitting debug info for a template argument pack element.
10671 In other terms, ARG is a template argument pack element.
10672 In that case, we don't emit any DW_AT_name attribute for
10676 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10678 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10681 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10683 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10684 TMPL_DIE should have a child DW_AT_type attribute that is set
10685 to the type of the argument to PARM, which is ARG.
10686 If PARM is a type generic parameter, TMPL_DIE should have a
10687 child DW_AT_type that is set to ARG. */
10688 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10689 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10690 TREE_THIS_VOLATILE (tmpl_type
),
10695 /* So TMPL_DIE is a DIE representing a
10696 a generic generic template parameter, a.k.a template template
10697 parameter in C++ and arg is a template. */
10699 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10700 to the name of the argument. */
10701 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10703 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10706 if (TREE_CODE (parm
) == PARM_DECL
)
10707 /* So PARM is a non-type generic parameter.
10708 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10709 attribute of TMPL_DIE which value represents the value
10711 We must be careful here:
10712 The value of ARG might reference some function decls.
10713 We might currently be emitting debug info for a generic
10714 type and types are emitted before function decls, we don't
10715 know if the function decls referenced by ARG will actually be
10716 emitted after cgraph computations.
10717 So must defer the generation of the DW_AT_const_value to
10718 after cgraph is ready. */
10719 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10725 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10726 PARM_PACK must be a template parameter pack. The returned DIE
10727 will be child DIE of PARENT_DIE. */
10730 template_parameter_pack_die (tree parm_pack
,
10731 tree parm_pack_args
,
10732 dw_die_ref parent_die
)
10737 gcc_assert (parent_die
&& parm_pack
);
10739 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10740 add_name_and_src_coords_attributes (die
, parm_pack
);
10741 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10742 generic_parameter_die (parm_pack
,
10743 TREE_VEC_ELT (parm_pack_args
, j
),
10744 false /* Don't emit DW_AT_name */,
10749 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10750 an enumerated type. */
10753 type_is_enum (const_tree type
)
10755 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10758 /* Return the DBX register number described by a given RTL node. */
10760 static unsigned int
10761 dbx_reg_number (const_rtx rtl
)
10763 unsigned regno
= REGNO (rtl
);
10765 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10767 #ifdef LEAF_REG_REMAP
10768 if (crtl
->uses_only_leaf_regs
)
10770 int leaf_reg
= LEAF_REG_REMAP (regno
);
10771 if (leaf_reg
!= -1)
10772 regno
= (unsigned) leaf_reg
;
10776 regno
= DBX_REGISTER_NUMBER (regno
);
10777 gcc_assert (regno
!= INVALID_REGNUM
);
10781 /* Optionally add a DW_OP_piece term to a location description expression.
10782 DW_OP_piece is only added if the location description expression already
10783 doesn't end with DW_OP_piece. */
10786 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10788 dw_loc_descr_ref loc
;
10790 if (*list_head
!= NULL
)
10792 /* Find the end of the chain. */
10793 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10796 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10797 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10801 /* Return a location descriptor that designates a machine register or
10802 zero if there is none. */
10804 static dw_loc_descr_ref
10805 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10809 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10812 /* We only use "frame base" when we're sure we're talking about the
10813 post-prologue local stack frame. We do this by *not* running
10814 register elimination until this point, and recognizing the special
10815 argument pointer and soft frame pointer rtx's.
10816 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10817 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10818 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10820 dw_loc_descr_ref result
= NULL
;
10822 if (dwarf_version
>= 4 || !dwarf_strict
)
10824 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10827 add_loc_descr (&result
,
10828 new_loc_descr (DW_OP_stack_value
, 0, 0));
10833 regs
= targetm
.dwarf_register_span (rtl
);
10835 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10836 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10839 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10840 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10842 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10846 /* Return a location descriptor that designates a machine register for
10847 a given hard register number. */
10849 static dw_loc_descr_ref
10850 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10852 dw_loc_descr_ref reg_loc_descr
;
10856 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10858 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10860 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10861 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10863 return reg_loc_descr
;
10866 /* Given an RTL of a register, return a location descriptor that
10867 designates a value that spans more than one register. */
10869 static dw_loc_descr_ref
10870 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10871 enum var_init_status initialized
)
10874 dw_loc_descr_ref loc_result
= NULL
;
10876 /* Simple, contiguous registers. */
10877 if (regs
== NULL_RTX
)
10879 unsigned reg
= REGNO (rtl
);
10882 #ifdef LEAF_REG_REMAP
10883 if (crtl
->uses_only_leaf_regs
)
10885 int leaf_reg
= LEAF_REG_REMAP (reg
);
10886 if (leaf_reg
!= -1)
10887 reg
= (unsigned) leaf_reg
;
10891 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10892 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10894 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10899 dw_loc_descr_ref t
;
10901 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10902 VAR_INIT_STATUS_INITIALIZED
);
10903 add_loc_descr (&loc_result
, t
);
10904 add_loc_descr_op_piece (&loc_result
, size
);
10910 /* Now onto stupid register sets in non contiguous locations. */
10912 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10914 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10917 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10919 dw_loc_descr_ref t
;
10921 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
10922 VAR_INIT_STATUS_INITIALIZED
);
10923 add_loc_descr (&loc_result
, t
);
10924 add_loc_descr_op_piece (&loc_result
, size
);
10927 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10928 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10932 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10934 /* Return a location descriptor that designates a constant i,
10935 as a compound operation from constant (i >> shift), constant shift
10938 static dw_loc_descr_ref
10939 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10941 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10942 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10943 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10947 /* Return a location descriptor that designates a constant. */
10949 static dw_loc_descr_ref
10950 int_loc_descriptor (HOST_WIDE_INT i
)
10952 enum dwarf_location_atom op
;
10954 /* Pick the smallest representation of a constant, rather than just
10955 defaulting to the LEB encoding. */
10958 int clz
= clz_hwi (i
);
10959 int ctz
= ctz_hwi (i
);
10961 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10962 else if (i
<= 0xff)
10963 op
= DW_OP_const1u
;
10964 else if (i
<= 0xffff)
10965 op
= DW_OP_const2u
;
10966 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10967 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10968 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10969 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10970 while DW_OP_const4u is 5 bytes. */
10971 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10972 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10973 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10974 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10975 while DW_OP_const4u is 5 bytes. */
10976 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10977 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10978 op
= DW_OP_const4u
;
10979 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10980 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10981 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10982 while DW_OP_constu of constant >= 0x100000000 takes at least
10984 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10985 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10986 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10987 >= HOST_BITS_PER_WIDE_INT
)
10988 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10989 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10990 while DW_OP_constu takes in this case at least 6 bytes. */
10991 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10992 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10993 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10994 && size_of_uleb128 (i
) > 6)
10995 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10996 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11003 op
= DW_OP_const1s
;
11004 else if (i
>= -0x8000)
11005 op
= DW_OP_const2s
;
11006 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11008 if (size_of_int_loc_descriptor (i
) < 5)
11010 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11011 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11014 op
= DW_OP_const4s
;
11018 if (size_of_int_loc_descriptor (i
)
11019 < (unsigned long) 1 + size_of_sleb128 (i
))
11021 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11022 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11029 return new_loc_descr (op
, i
, 0);
11032 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11033 without actually allocating it. */
11035 static unsigned long
11036 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11038 return size_of_int_loc_descriptor (i
>> shift
)
11039 + size_of_int_loc_descriptor (shift
)
11043 /* Return size_of_locs (int_loc_descriptor (i)) without
11044 actually allocating it. */
11046 static unsigned long
11047 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11056 else if (i
<= 0xff)
11058 else if (i
<= 0xffff)
11062 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11063 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11064 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11066 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11067 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11068 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11070 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11072 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11073 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11074 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11075 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11077 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11078 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11079 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11081 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11082 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11084 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11093 else if (i
>= -0x8000)
11095 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11097 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11099 s
= size_of_int_loc_descriptor (-i
) + 1;
11107 unsigned long r
= 1 + size_of_sleb128 (i
);
11108 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11110 s
= size_of_int_loc_descriptor (-i
) + 1;
11119 /* Return loc description representing "address" of integer value.
11120 This can appear only as toplevel expression. */
11122 static dw_loc_descr_ref
11123 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11126 dw_loc_descr_ref loc_result
= NULL
;
11128 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11131 litsize
= size_of_int_loc_descriptor (i
);
11132 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11133 is more compact. For DW_OP_stack_value we need:
11134 litsize + 1 (DW_OP_stack_value)
11135 and for DW_OP_implicit_value:
11136 1 (DW_OP_implicit_value) + 1 (length) + size. */
11137 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11139 loc_result
= int_loc_descriptor (i
);
11140 add_loc_descr (&loc_result
,
11141 new_loc_descr (DW_OP_stack_value
, 0, 0));
11145 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11147 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11148 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11152 /* Return a location descriptor that designates a base+offset location. */
11154 static dw_loc_descr_ref
11155 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11156 enum var_init_status initialized
)
11158 unsigned int regno
;
11159 dw_loc_descr_ref result
;
11160 dw_fde_ref fde
= cfun
->fde
;
11162 /* We only use "frame base" when we're sure we're talking about the
11163 post-prologue local stack frame. We do this by *not* running
11164 register elimination until this point, and recognizing the special
11165 argument pointer and soft frame pointer rtx's. */
11166 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11168 rtx elim
= (ira_use_lra_p
11169 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11170 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11174 if (GET_CODE (elim
) == PLUS
)
11176 offset
+= INTVAL (XEXP (elim
, 1));
11177 elim
= XEXP (elim
, 0);
11179 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11180 && (elim
== hard_frame_pointer_rtx
11181 || elim
== stack_pointer_rtx
))
11182 || elim
== (frame_pointer_needed
11183 ? hard_frame_pointer_rtx
11184 : stack_pointer_rtx
));
11186 /* If drap register is used to align stack, use frame
11187 pointer + offset to access stack variables. If stack
11188 is aligned without drap, use stack pointer + offset to
11189 access stack variables. */
11190 if (crtl
->stack_realign_tried
11191 && reg
== frame_pointer_rtx
)
11194 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11195 ? HARD_FRAME_POINTER_REGNUM
11197 return new_reg_loc_descr (base_reg
, offset
);
11200 gcc_assert (frame_pointer_fb_offset_valid
);
11201 offset
+= frame_pointer_fb_offset
;
11202 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11206 regno
= REGNO (reg
);
11207 #ifdef LEAF_REG_REMAP
11208 if (crtl
->uses_only_leaf_regs
)
11210 int leaf_reg
= LEAF_REG_REMAP (regno
);
11211 if (leaf_reg
!= -1)
11212 regno
= (unsigned) leaf_reg
;
11215 regno
= DWARF_FRAME_REGNUM (regno
);
11217 if (!optimize
&& fde
11218 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11220 /* Use cfa+offset to represent the location of arguments passed
11221 on the stack when drap is used to align stack.
11222 Only do this when not optimizing, for optimized code var-tracking
11223 is supposed to track where the arguments live and the register
11224 used as vdrap or drap in some spot might be used for something
11225 else in other part of the routine. */
11226 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11230 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11233 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11235 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11236 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11241 /* Return true if this RTL expression describes a base+offset calculation. */
11244 is_based_loc (const_rtx rtl
)
11246 return (GET_CODE (rtl
) == PLUS
11247 && ((REG_P (XEXP (rtl
, 0))
11248 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11249 && CONST_INT_P (XEXP (rtl
, 1)))));
11252 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11255 static dw_loc_descr_ref
11256 tls_mem_loc_descriptor (rtx mem
)
11259 dw_loc_descr_ref loc_result
;
11261 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11264 base
= get_base_address (MEM_EXPR (mem
));
11266 || TREE_CODE (base
) != VAR_DECL
11267 || !DECL_THREAD_LOCAL_P (base
))
11270 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11271 if (loc_result
== NULL
)
11274 if (MEM_OFFSET (mem
))
11275 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11280 /* Output debug info about reason why we failed to expand expression as dwarf
11284 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11286 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11288 fprintf (dump_file
, "Failed to expand as dwarf: ");
11290 print_generic_expr (dump_file
, expr
, dump_flags
);
11293 fprintf (dump_file
, "\n");
11294 print_rtl (dump_file
, rtl
);
11296 fprintf (dump_file
, "\nReason: %s\n", reason
);
11300 /* Helper function for const_ok_for_output, called either directly
11301 or via for_each_rtx. */
11304 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11308 if (GET_CODE (rtl
) == UNSPEC
)
11310 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11311 we can't express it in the debug info. */
11312 #ifdef ENABLE_CHECKING
11313 /* Don't complain about TLS UNSPECs, those are just too hard to
11314 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11315 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11316 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11317 if (XVECLEN (rtl
, 0) == 0
11318 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11319 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11320 inform (current_function_decl
11321 ? DECL_SOURCE_LOCATION (current_function_decl
)
11322 : UNKNOWN_LOCATION
,
11323 #if NUM_UNSPEC_VALUES > 0
11324 "non-delegitimized UNSPEC %s (%d) found in variable location",
11325 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11326 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11329 "non-delegitimized UNSPEC %d found in variable location",
11333 expansion_failed (NULL_TREE
, rtl
,
11334 "UNSPEC hasn't been delegitimized.\n");
11338 if (targetm
.const_not_ok_for_debug_p (rtl
))
11340 expansion_failed (NULL_TREE
, rtl
,
11341 "Expression rejected for debug by the backend.\n");
11345 /* FIXME: Refer to PR60655. It is possible for simplification
11346 of rtl expressions in var tracking to produce such expressions.
11347 We should really identify / validate expressions
11348 enclosed in CONST that can be handled by assemblers on various
11349 targets and only handle legitimate cases here. */
11350 if (GET_CODE (rtl
) != SYMBOL_REF
)
11352 if (GET_CODE (rtl
) == NOT
)
11358 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11361 get_pool_constant_mark (rtl
, &marked
);
11362 /* If all references to this pool constant were optimized away,
11363 it was not output and thus we can't represent it. */
11366 expansion_failed (NULL_TREE
, rtl
,
11367 "Constant was removed from constant pool.\n");
11372 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11375 /* Avoid references to external symbols in debug info, on several targets
11376 the linker might even refuse to link when linking a shared library,
11377 and in many other cases the relocations for .debug_info/.debug_loc are
11378 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11379 to be defined within the same shared library or executable are fine. */
11380 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11382 tree decl
= SYMBOL_REF_DECL (rtl
);
11384 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11386 expansion_failed (NULL_TREE
, rtl
,
11387 "Symbol not defined in current TU.\n");
11395 /* Return true if constant RTL can be emitted in DW_OP_addr or
11396 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11397 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11400 const_ok_for_output (rtx rtl
)
11402 if (GET_CODE (rtl
) == SYMBOL_REF
)
11403 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11405 if (GET_CODE (rtl
) == CONST
)
11406 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11411 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11412 if possible, NULL otherwise. */
11415 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11417 dw_die_ref type_die
;
11418 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11422 switch (TREE_CODE (type
))
11430 type_die
= lookup_type_die (type
);
11432 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11433 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11438 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11439 type matching MODE, or, if MODE is narrower than or as wide as
11440 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11443 static dw_loc_descr_ref
11444 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11446 enum machine_mode outer_mode
= mode
;
11447 dw_die_ref type_die
;
11448 dw_loc_descr_ref cvt
;
11450 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11452 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11455 type_die
= base_type_for_mode (outer_mode
, 1);
11456 if (type_die
== NULL
)
11458 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11459 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11460 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11461 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11462 add_loc_descr (&op
, cvt
);
11466 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11468 static dw_loc_descr_ref
11469 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11470 dw_loc_descr_ref op1
)
11472 dw_loc_descr_ref ret
= op0
;
11473 add_loc_descr (&ret
, op1
);
11474 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11475 if (STORE_FLAG_VALUE
!= 1)
11477 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11478 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11483 /* Return location descriptor for signed comparison OP RTL. */
11485 static dw_loc_descr_ref
11486 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11487 enum machine_mode mem_mode
)
11489 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11490 dw_loc_descr_ref op0
, op1
;
11493 if (op_mode
== VOIDmode
)
11494 op_mode
= GET_MODE (XEXP (rtl
, 1));
11495 if (op_mode
== VOIDmode
)
11499 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11500 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11503 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11504 VAR_INIT_STATUS_INITIALIZED
);
11505 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11506 VAR_INIT_STATUS_INITIALIZED
);
11508 if (op0
== NULL
|| op1
== NULL
)
11511 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11512 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11513 return compare_loc_descriptor (op
, op0
, op1
);
11515 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11517 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11518 dw_loc_descr_ref cvt
;
11520 if (type_die
== NULL
)
11522 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11523 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11524 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11525 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11526 add_loc_descr (&op0
, cvt
);
11527 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11528 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11529 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11530 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11531 add_loc_descr (&op1
, cvt
);
11532 return compare_loc_descriptor (op
, op0
, op1
);
11535 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11536 /* For eq/ne, if the operands are known to be zero-extended,
11537 there is no need to do the fancy shifting up. */
11538 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11540 dw_loc_descr_ref last0
, last1
;
11541 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11543 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11545 /* deref_size zero extends, and for constants we can check
11546 whether they are zero extended or not. */
11547 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11548 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11549 || (CONST_INT_P (XEXP (rtl
, 0))
11550 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11551 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11552 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11553 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11554 || (CONST_INT_P (XEXP (rtl
, 1))
11555 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11556 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11557 return compare_loc_descriptor (op
, op0
, op1
);
11559 /* EQ/NE comparison against constant in narrower type than
11560 DWARF2_ADDR_SIZE can be performed either as
11561 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11564 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11565 DW_OP_{eq,ne}. Pick whatever is shorter. */
11566 if (CONST_INT_P (XEXP (rtl
, 1))
11567 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11568 && (size_of_int_loc_descriptor (shift
) + 1
11569 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11570 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11571 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11572 & GET_MODE_MASK (op_mode
))))
11574 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11575 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11576 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11577 & GET_MODE_MASK (op_mode
));
11578 return compare_loc_descriptor (op
, op0
, op1
);
11581 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11582 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11583 if (CONST_INT_P (XEXP (rtl
, 1)))
11584 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11587 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11588 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11590 return compare_loc_descriptor (op
, op0
, op1
);
11593 /* Return location descriptor for unsigned comparison OP RTL. */
11595 static dw_loc_descr_ref
11596 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11597 enum machine_mode mem_mode
)
11599 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11600 dw_loc_descr_ref op0
, op1
;
11602 if (op_mode
== VOIDmode
)
11603 op_mode
= GET_MODE (XEXP (rtl
, 1));
11604 if (op_mode
== VOIDmode
)
11606 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11609 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11612 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11613 VAR_INIT_STATUS_INITIALIZED
);
11614 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11615 VAR_INIT_STATUS_INITIALIZED
);
11617 if (op0
== NULL
|| op1
== NULL
)
11620 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11622 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11623 dw_loc_descr_ref last0
, last1
;
11624 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11626 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11628 if (CONST_INT_P (XEXP (rtl
, 0)))
11629 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11630 /* deref_size zero extends, so no need to mask it again. */
11631 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11632 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11634 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11635 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11637 if (CONST_INT_P (XEXP (rtl
, 1)))
11638 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11639 /* deref_size zero extends, so no need to mask it again. */
11640 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11641 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11643 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11644 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11647 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11649 HOST_WIDE_INT bias
= 1;
11650 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11651 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11652 if (CONST_INT_P (XEXP (rtl
, 1)))
11653 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11654 + INTVAL (XEXP (rtl
, 1)));
11656 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11659 return compare_loc_descriptor (op
, op0
, op1
);
11662 /* Return location descriptor for {U,S}{MIN,MAX}. */
11664 static dw_loc_descr_ref
11665 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11666 enum machine_mode mem_mode
)
11668 enum dwarf_location_atom op
;
11669 dw_loc_descr_ref op0
, op1
, ret
;
11670 dw_loc_descr_ref bra_node
, drop_node
;
11673 && (GET_MODE_CLASS (mode
) != MODE_INT
11674 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11677 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11678 VAR_INIT_STATUS_INITIALIZED
);
11679 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11680 VAR_INIT_STATUS_INITIALIZED
);
11682 if (op0
== NULL
|| op1
== NULL
)
11685 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11686 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11687 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11688 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11690 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11692 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11693 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11694 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11695 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11696 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11698 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11700 HOST_WIDE_INT bias
= 1;
11701 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11702 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11703 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11706 else if (GET_MODE_CLASS (mode
) == MODE_INT
11707 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11709 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11710 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11711 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11712 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11713 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11715 else if (GET_MODE_CLASS (mode
) == MODE_INT
11716 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11718 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11719 dw_loc_descr_ref cvt
;
11720 if (type_die
== NULL
)
11722 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11723 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11724 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11725 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11726 add_loc_descr (&op0
, cvt
);
11727 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11728 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11729 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11730 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11731 add_loc_descr (&op1
, cvt
);
11734 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11739 add_loc_descr (&ret
, op1
);
11740 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11741 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11742 add_loc_descr (&ret
, bra_node
);
11743 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11744 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11745 add_loc_descr (&ret
, drop_node
);
11746 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11747 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11748 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11749 && GET_MODE_CLASS (mode
) == MODE_INT
11750 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11751 ret
= convert_descriptor_to_mode (mode
, ret
);
11755 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11756 but after converting arguments to type_die, afterwards
11757 convert back to unsigned. */
11759 static dw_loc_descr_ref
11760 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11761 enum machine_mode mode
, enum machine_mode mem_mode
)
11763 dw_loc_descr_ref cvt
, op0
, op1
;
11765 if (type_die
== NULL
)
11767 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11768 VAR_INIT_STATUS_INITIALIZED
);
11769 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11770 VAR_INIT_STATUS_INITIALIZED
);
11771 if (op0
== NULL
|| op1
== NULL
)
11773 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11774 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11775 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11776 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11777 add_loc_descr (&op0
, cvt
);
11778 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11779 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11780 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11781 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11782 add_loc_descr (&op1
, cvt
);
11783 add_loc_descr (&op0
, op1
);
11784 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11785 return convert_descriptor_to_mode (mode
, op0
);
11788 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11789 const0 is DW_OP_lit0 or corresponding typed constant,
11790 const1 is DW_OP_lit1 or corresponding typed constant
11791 and constMSB is constant with just the MSB bit set
11793 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11794 L1: const0 DW_OP_swap
11795 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11796 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11801 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11802 L1: const0 DW_OP_swap
11803 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11804 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11809 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11810 L1: const1 DW_OP_swap
11811 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11812 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11816 static dw_loc_descr_ref
11817 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11818 enum machine_mode mem_mode
)
11820 dw_loc_descr_ref op0
, ret
, tmp
;
11821 HOST_WIDE_INT valv
;
11822 dw_loc_descr_ref l1jump
, l1label
;
11823 dw_loc_descr_ref l2jump
, l2label
;
11824 dw_loc_descr_ref l3jump
, l3label
;
11825 dw_loc_descr_ref l4jump
, l4label
;
11828 if (GET_MODE_CLASS (mode
) != MODE_INT
11829 || GET_MODE (XEXP (rtl
, 0)) != mode
11830 || (GET_CODE (rtl
) == CLZ
11831 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11834 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11835 VAR_INIT_STATUS_INITIALIZED
);
11839 if (GET_CODE (rtl
) == CLZ
)
11841 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11842 valv
= GET_MODE_BITSIZE (mode
);
11844 else if (GET_CODE (rtl
) == FFS
)
11846 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11847 valv
= GET_MODE_BITSIZE (mode
);
11848 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11849 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11850 add_loc_descr (&ret
, l1jump
);
11851 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11852 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11853 VAR_INIT_STATUS_INITIALIZED
);
11856 add_loc_descr (&ret
, tmp
);
11857 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11858 add_loc_descr (&ret
, l4jump
);
11859 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11860 ? const1_rtx
: const0_rtx
,
11862 VAR_INIT_STATUS_INITIALIZED
);
11863 if (l1label
== NULL
)
11865 add_loc_descr (&ret
, l1label
);
11866 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11867 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11868 add_loc_descr (&ret
, l2label
);
11869 if (GET_CODE (rtl
) != CLZ
)
11871 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11872 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11873 << (GET_MODE_BITSIZE (mode
) - 1));
11875 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11876 << (GET_MODE_BITSIZE (mode
)
11877 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11878 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11879 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11880 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11881 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11883 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11884 VAR_INIT_STATUS_INITIALIZED
);
11887 add_loc_descr (&ret
, tmp
);
11888 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11889 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11890 add_loc_descr (&ret
, l3jump
);
11891 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11892 VAR_INIT_STATUS_INITIALIZED
);
11895 add_loc_descr (&ret
, tmp
);
11896 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11897 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11898 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11899 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11900 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11901 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11902 add_loc_descr (&ret
, l2jump
);
11903 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11904 add_loc_descr (&ret
, l3label
);
11905 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11906 add_loc_descr (&ret
, l4label
);
11907 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11908 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11909 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11910 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11911 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11912 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11913 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11914 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11918 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11919 const1 is DW_OP_lit1 or corresponding typed constant):
11921 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11922 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11926 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11927 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11930 static dw_loc_descr_ref
11931 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11932 enum machine_mode mem_mode
)
11934 dw_loc_descr_ref op0
, ret
, tmp
;
11935 dw_loc_descr_ref l1jump
, l1label
;
11936 dw_loc_descr_ref l2jump
, l2label
;
11938 if (GET_MODE_CLASS (mode
) != MODE_INT
11939 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11942 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11943 VAR_INIT_STATUS_INITIALIZED
);
11947 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11948 VAR_INIT_STATUS_INITIALIZED
);
11951 add_loc_descr (&ret
, tmp
);
11952 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11953 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11954 add_loc_descr (&ret
, l1label
);
11955 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11956 add_loc_descr (&ret
, l2jump
);
11957 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11958 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11959 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11960 VAR_INIT_STATUS_INITIALIZED
);
11963 add_loc_descr (&ret
, tmp
);
11964 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11965 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11966 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11967 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11968 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11969 VAR_INIT_STATUS_INITIALIZED
);
11970 add_loc_descr (&ret
, tmp
);
11971 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11972 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11973 add_loc_descr (&ret
, l1jump
);
11974 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11975 add_loc_descr (&ret
, l2label
);
11976 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11977 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11978 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11979 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11983 /* BSWAP (constS is initial shift count, either 56 or 24):
11985 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11986 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11987 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11988 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11989 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11991 static dw_loc_descr_ref
11992 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11993 enum machine_mode mem_mode
)
11995 dw_loc_descr_ref op0
, ret
, tmp
;
11996 dw_loc_descr_ref l1jump
, l1label
;
11997 dw_loc_descr_ref l2jump
, l2label
;
11999 if (GET_MODE_CLASS (mode
) != MODE_INT
12000 || BITS_PER_UNIT
!= 8
12001 || (GET_MODE_BITSIZE (mode
) != 32
12002 && GET_MODE_BITSIZE (mode
) != 64))
12005 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12006 VAR_INIT_STATUS_INITIALIZED
);
12011 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12013 VAR_INIT_STATUS_INITIALIZED
);
12016 add_loc_descr (&ret
, tmp
);
12017 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12018 VAR_INIT_STATUS_INITIALIZED
);
12021 add_loc_descr (&ret
, tmp
);
12022 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12023 add_loc_descr (&ret
, l1label
);
12024 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12026 VAR_INIT_STATUS_INITIALIZED
);
12027 add_loc_descr (&ret
, tmp
);
12028 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12029 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12030 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12031 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12032 VAR_INIT_STATUS_INITIALIZED
);
12035 add_loc_descr (&ret
, tmp
);
12036 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12037 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12038 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12039 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12040 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12041 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12042 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12043 VAR_INIT_STATUS_INITIALIZED
);
12044 add_loc_descr (&ret
, tmp
);
12045 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12046 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12047 add_loc_descr (&ret
, l2jump
);
12048 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12049 VAR_INIT_STATUS_INITIALIZED
);
12050 add_loc_descr (&ret
, tmp
);
12051 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12052 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12053 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12054 add_loc_descr (&ret
, l1jump
);
12055 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12056 add_loc_descr (&ret
, l2label
);
12057 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12058 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12059 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12060 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12061 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12062 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12066 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12067 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12068 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12069 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12071 ROTATERT is similar:
12072 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12073 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12074 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12076 static dw_loc_descr_ref
12077 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12078 enum machine_mode mem_mode
)
12080 rtx rtlop1
= XEXP (rtl
, 1);
12081 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12084 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12087 if (GET_MODE (rtlop1
) != VOIDmode
12088 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12089 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12090 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12091 VAR_INIT_STATUS_INITIALIZED
);
12092 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12093 VAR_INIT_STATUS_INITIALIZED
);
12094 if (op0
== NULL
|| op1
== NULL
)
12096 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12097 for (i
= 0; i
< 2; i
++)
12099 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12100 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12102 VAR_INIT_STATUS_INITIALIZED
);
12103 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12104 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12106 : HOST_BITS_PER_WIDE_INT
== 64
12107 ? DW_OP_const8u
: DW_OP_constu
,
12108 GET_MODE_MASK (mode
), 0);
12111 if (mask
[i
] == NULL
)
12113 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12116 add_loc_descr (&ret
, op1
);
12117 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12118 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12119 if (GET_CODE (rtl
) == ROTATERT
)
12121 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12122 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12123 GET_MODE_BITSIZE (mode
), 0));
12125 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12126 if (mask
[0] != NULL
)
12127 add_loc_descr (&ret
, mask
[0]);
12128 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12129 if (mask
[1] != NULL
)
12131 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12132 add_loc_descr (&ret
, mask
[1]);
12133 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12135 if (GET_CODE (rtl
) == ROTATE
)
12137 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12138 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12139 GET_MODE_BITSIZE (mode
), 0));
12141 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12142 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12146 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12147 for DEBUG_PARAMETER_REF RTL. */
12149 static dw_loc_descr_ref
12150 parameter_ref_descriptor (rtx rtl
)
12152 dw_loc_descr_ref ret
;
12157 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12158 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12159 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12162 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12163 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12164 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12168 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12169 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12174 /* The following routine converts the RTL for a variable or parameter
12175 (resident in memory) into an equivalent Dwarf representation of a
12176 mechanism for getting the address of that same variable onto the top of a
12177 hypothetical "address evaluation" stack.
12179 When creating memory location descriptors, we are effectively transforming
12180 the RTL for a memory-resident object into its Dwarf postfix expression
12181 equivalent. This routine recursively descends an RTL tree, turning
12182 it into Dwarf postfix code as it goes.
12184 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12186 MEM_MODE is the mode of the memory reference, needed to handle some
12187 autoincrement addressing modes.
12189 Return 0 if we can't represent the location. */
12192 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12193 enum machine_mode mem_mode
,
12194 enum var_init_status initialized
)
12196 dw_loc_descr_ref mem_loc_result
= NULL
;
12197 enum dwarf_location_atom op
;
12198 dw_loc_descr_ref op0
, op1
;
12199 rtx inner
= NULL_RTX
;
12201 if (mode
== VOIDmode
)
12202 mode
= GET_MODE (rtl
);
12204 /* Note that for a dynamically sized array, the location we will generate a
12205 description of here will be the lowest numbered location which is
12206 actually within the array. That's *not* necessarily the same as the
12207 zeroth element of the array. */
12209 rtl
= targetm
.delegitimize_address (rtl
);
12211 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12214 switch (GET_CODE (rtl
))
12219 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12222 /* The case of a subreg may arise when we have a local (register)
12223 variable or a formal (register) parameter which doesn't quite fill
12224 up an entire register. For now, just assume that it is
12225 legitimate to make the Dwarf info refer to the whole register which
12226 contains the given subreg. */
12227 if (!subreg_lowpart_p (rtl
))
12229 inner
= SUBREG_REG (rtl
);
12231 if (inner
== NULL_RTX
)
12232 inner
= XEXP (rtl
, 0);
12233 if (GET_MODE_CLASS (mode
) == MODE_INT
12234 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12235 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12236 #ifdef POINTERS_EXTEND_UNSIGNED
12237 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12240 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12242 mem_loc_result
= mem_loc_descriptor (inner
,
12244 mem_mode
, initialized
);
12249 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12251 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12252 && (GET_MODE_CLASS (mode
) != MODE_INT
12253 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12257 dw_die_ref type_die
;
12258 dw_loc_descr_ref cvt
;
12260 mem_loc_result
= mem_loc_descriptor (inner
,
12262 mem_mode
, initialized
);
12263 if (mem_loc_result
== NULL
)
12265 type_die
= base_type_for_mode (mode
,
12266 GET_MODE_CLASS (mode
) == MODE_INT
);
12267 if (type_die
== NULL
)
12269 mem_loc_result
= NULL
;
12272 if (GET_MODE_SIZE (mode
)
12273 != GET_MODE_SIZE (GET_MODE (inner
)))
12274 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12276 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12277 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12278 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12279 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12280 add_loc_descr (&mem_loc_result
, cvt
);
12285 if (GET_MODE_CLASS (mode
) != MODE_INT
12286 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12287 && rtl
!= arg_pointer_rtx
12288 && rtl
!= frame_pointer_rtx
12289 #ifdef POINTERS_EXTEND_UNSIGNED
12290 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12294 dw_die_ref type_die
;
12295 unsigned int dbx_regnum
;
12299 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12301 type_die
= base_type_for_mode (mode
,
12302 GET_MODE_CLASS (mode
) == MODE_INT
);
12303 if (type_die
== NULL
)
12306 dbx_regnum
= dbx_reg_number (rtl
);
12307 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12309 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12311 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12312 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12313 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12316 /* Whenever a register number forms a part of the description of the
12317 method for calculating the (dynamic) address of a memory resident
12318 object, DWARF rules require the register number be referred to as
12319 a "base register". This distinction is not based in any way upon
12320 what category of register the hardware believes the given register
12321 belongs to. This is strictly DWARF terminology we're dealing with
12322 here. Note that in cases where the location of a memory-resident
12323 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12324 OP_CONST (0)) the actual DWARF location descriptor that we generate
12325 may just be OP_BASEREG (basereg). This may look deceptively like
12326 the object in question was allocated to a register (rather than in
12327 memory) so DWARF consumers need to be aware of the subtle
12328 distinction between OP_REG and OP_BASEREG. */
12329 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12330 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12331 else if (stack_realign_drap
12333 && crtl
->args
.internal_arg_pointer
== rtl
12334 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12336 /* If RTL is internal_arg_pointer, which has been optimized
12337 out, use DRAP instead. */
12338 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12339 VAR_INIT_STATUS_INITIALIZED
);
12345 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12347 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12348 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12351 else if (GET_CODE (rtl
) == ZERO_EXTEND
12352 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12353 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12354 < HOST_BITS_PER_WIDE_INT
12355 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12356 to expand zero extend as two shifts instead of
12358 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12360 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12361 mem_loc_result
= op0
;
12362 add_loc_descr (&mem_loc_result
,
12363 int_loc_descriptor (GET_MODE_MASK (imode
)));
12364 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12366 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12368 int shift
= DWARF2_ADDR_SIZE
12369 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12370 shift
*= BITS_PER_UNIT
;
12371 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12375 mem_loc_result
= op0
;
12376 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12377 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12378 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12379 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12381 else if (!dwarf_strict
)
12383 dw_die_ref type_die1
, type_die2
;
12384 dw_loc_descr_ref cvt
;
12386 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12387 GET_CODE (rtl
) == ZERO_EXTEND
);
12388 if (type_die1
== NULL
)
12390 type_die2
= base_type_for_mode (mode
, 1);
12391 if (type_die2
== NULL
)
12393 mem_loc_result
= op0
;
12394 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12395 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12396 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12397 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12398 add_loc_descr (&mem_loc_result
, cvt
);
12399 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12400 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12401 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12402 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12403 add_loc_descr (&mem_loc_result
, cvt
);
12409 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12410 if (new_rtl
!= rtl
)
12412 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12414 if (mem_loc_result
!= NULL
)
12415 return mem_loc_result
;
12418 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12419 get_address_mode (rtl
), mode
,
12420 VAR_INIT_STATUS_INITIALIZED
);
12421 if (mem_loc_result
== NULL
)
12422 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12423 if (mem_loc_result
!= NULL
)
12425 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12426 || GET_MODE_CLASS (mode
) != MODE_INT
)
12428 dw_die_ref type_die
;
12429 dw_loc_descr_ref deref
;
12434 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12435 if (type_die
== NULL
)
12437 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12438 GET_MODE_SIZE (mode
), 0);
12439 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12440 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12441 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12442 add_loc_descr (&mem_loc_result
, deref
);
12444 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12445 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12447 add_loc_descr (&mem_loc_result
,
12448 new_loc_descr (DW_OP_deref_size
,
12449 GET_MODE_SIZE (mode
), 0));
12454 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12457 /* Some ports can transform a symbol ref into a label ref, because
12458 the symbol ref is too far away and has to be dumped into a constant
12462 if (GET_MODE_CLASS (mode
) != MODE_INT
12463 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12464 #ifdef POINTERS_EXTEND_UNSIGNED
12465 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12469 if (GET_CODE (rtl
) == SYMBOL_REF
12470 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12472 dw_loc_descr_ref temp
;
12474 /* If this is not defined, we have no way to emit the data. */
12475 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12478 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12480 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12481 add_loc_descr (&mem_loc_result
, temp
);
12486 if (!const_ok_for_output (rtl
))
12490 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12491 vec_safe_push (used_rtx_array
, rtl
);
12497 case DEBUG_IMPLICIT_PTR
:
12498 expansion_failed (NULL_TREE
, rtl
,
12499 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12505 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12507 if (GET_MODE_CLASS (mode
) != MODE_INT
12508 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12509 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12510 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12513 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12514 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12516 op0
= one_reg_loc_descriptor (dbx_regnum
,
12517 VAR_INIT_STATUS_INITIALIZED
);
12520 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12521 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12523 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12524 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12525 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12529 gcc_unreachable ();
12532 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12533 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12534 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12537 case DEBUG_PARAMETER_REF
:
12538 mem_loc_result
= parameter_ref_descriptor (rtl
);
12542 /* Extract the PLUS expression nested inside and fall into
12543 PLUS code below. */
12544 rtl
= XEXP (rtl
, 1);
12549 /* Turn these into a PLUS expression and fall into the PLUS code
12551 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12552 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12553 ? GET_MODE_UNIT_SIZE (mem_mode
)
12554 : -GET_MODE_UNIT_SIZE (mem_mode
),
12557 /* ... fall through ... */
12561 if (is_based_loc (rtl
)
12562 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12563 || XEXP (rtl
, 0) == arg_pointer_rtx
12564 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12565 && GET_MODE_CLASS (mode
) == MODE_INT
)
12566 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12567 INTVAL (XEXP (rtl
, 1)),
12568 VAR_INIT_STATUS_INITIALIZED
);
12571 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12572 VAR_INIT_STATUS_INITIALIZED
);
12573 if (mem_loc_result
== 0)
12576 if (CONST_INT_P (XEXP (rtl
, 1))
12577 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12578 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12581 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12582 VAR_INIT_STATUS_INITIALIZED
);
12585 add_loc_descr (&mem_loc_result
, op1
);
12586 add_loc_descr (&mem_loc_result
,
12587 new_loc_descr (DW_OP_plus
, 0, 0));
12592 /* If a pseudo-reg is optimized away, it is possible for it to
12593 be replaced with a MEM containing a multiply or shift. */
12604 && GET_MODE_CLASS (mode
) == MODE_INT
12605 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12607 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12608 base_type_for_mode (mode
, 0),
12632 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12634 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12635 VAR_INIT_STATUS_INITIALIZED
);
12637 rtx rtlop1
= XEXP (rtl
, 1);
12638 if (GET_MODE (rtlop1
) != VOIDmode
12639 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12640 < GET_MODE_BITSIZE (mode
))
12641 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12642 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12643 VAR_INIT_STATUS_INITIALIZED
);
12646 if (op0
== 0 || op1
== 0)
12649 mem_loc_result
= op0
;
12650 add_loc_descr (&mem_loc_result
, op1
);
12651 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12667 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12668 VAR_INIT_STATUS_INITIALIZED
);
12669 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12670 VAR_INIT_STATUS_INITIALIZED
);
12672 if (op0
== 0 || op1
== 0)
12675 mem_loc_result
= op0
;
12676 add_loc_descr (&mem_loc_result
, op1
);
12677 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12681 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12683 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12684 base_type_for_mode (mode
, 0),
12689 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12690 VAR_INIT_STATUS_INITIALIZED
);
12691 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12692 VAR_INIT_STATUS_INITIALIZED
);
12694 if (op0
== 0 || op1
== 0)
12697 mem_loc_result
= op0
;
12698 add_loc_descr (&mem_loc_result
, op1
);
12699 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12700 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12701 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12702 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12703 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12707 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12709 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12714 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12715 base_type_for_mode (mode
, 1),
12733 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12734 VAR_INIT_STATUS_INITIALIZED
);
12739 mem_loc_result
= op0
;
12740 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12744 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12745 #ifdef POINTERS_EXTEND_UNSIGNED
12747 && mem_mode
!= VOIDmode
12748 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12752 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12756 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12757 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12759 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12760 enum machine_mode amode
;
12761 if (type_die
== NULL
)
12763 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12765 if (INTVAL (rtl
) >= 0
12766 && amode
!= BLKmode
12767 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12768 /* const DW_OP_GNU_convert <XXX> vs.
12769 DW_OP_GNU_const_type <XXX, 1, const>. */
12770 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12771 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12773 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12774 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12775 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12776 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12777 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12778 add_loc_descr (&mem_loc_result
, op0
);
12779 return mem_loc_result
;
12781 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12783 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12784 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12785 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12786 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12787 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12790 mem_loc_result
->dw_loc_oprnd2
.val_class
12791 = dw_val_class_const_double
;
12792 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12793 = double_int::from_shwi (INTVAL (rtl
));
12801 dw_die_ref type_die
;
12803 /* Note that a CONST_DOUBLE rtx could represent either an integer
12804 or a floating-point constant. A CONST_DOUBLE is used whenever
12805 the constant requires more than one word in order to be
12806 adequately represented. We output CONST_DOUBLEs as blocks. */
12807 if (mode
== VOIDmode
12808 || (GET_MODE (rtl
) == VOIDmode
12809 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12811 type_die
= base_type_for_mode (mode
,
12812 GET_MODE_CLASS (mode
) == MODE_INT
);
12813 if (type_die
== NULL
)
12815 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12816 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12817 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12818 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12819 if (SCALAR_FLOAT_MODE_P (mode
))
12821 unsigned int length
= GET_MODE_SIZE (mode
);
12822 unsigned char *array
12823 = (unsigned char*) ggc_alloc_atomic (length
);
12825 insert_float (rtl
, array
);
12826 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12827 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12828 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12829 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12833 mem_loc_result
->dw_loc_oprnd2
.val_class
12834 = dw_val_class_const_double
;
12835 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12836 = rtx_to_double_int (rtl
);
12842 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12846 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12850 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12854 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12858 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12862 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12866 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12870 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12874 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12878 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12883 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12888 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12893 if (CONST_INT_P (XEXP (rtl
, 1))
12894 && CONST_INT_P (XEXP (rtl
, 2))
12895 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12896 + (unsigned) INTVAL (XEXP (rtl
, 2))
12897 <= GET_MODE_BITSIZE (mode
))
12898 && GET_MODE_CLASS (mode
) == MODE_INT
12899 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12900 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12903 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12904 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12907 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12911 mem_loc_result
= op0
;
12912 size
= INTVAL (XEXP (rtl
, 1));
12913 shift
= INTVAL (XEXP (rtl
, 2));
12914 if (BITS_BIG_ENDIAN
)
12915 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12917 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12919 add_loc_descr (&mem_loc_result
,
12920 int_loc_descriptor (DWARF2_ADDR_SIZE
12922 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12924 if (size
!= (int) DWARF2_ADDR_SIZE
)
12926 add_loc_descr (&mem_loc_result
,
12927 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12928 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12935 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12936 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12937 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12938 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12939 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12940 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12941 VAR_INIT_STATUS_INITIALIZED
);
12942 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12943 VAR_INIT_STATUS_INITIALIZED
);
12944 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12947 mem_loc_result
= op1
;
12948 add_loc_descr (&mem_loc_result
, op2
);
12949 add_loc_descr (&mem_loc_result
, op0
);
12950 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12951 add_loc_descr (&mem_loc_result
, bra_node
);
12952 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12953 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12954 add_loc_descr (&mem_loc_result
, drop_node
);
12955 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12956 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12961 case FLOAT_TRUNCATE
:
12963 case UNSIGNED_FLOAT
:
12968 dw_die_ref type_die
;
12969 dw_loc_descr_ref cvt
;
12971 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12972 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12975 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12976 && (GET_CODE (rtl
) == FLOAT
12977 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12978 <= DWARF2_ADDR_SIZE
))
12980 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12981 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12982 if (type_die
== NULL
)
12984 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12985 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12986 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12987 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12988 add_loc_descr (&op0
, cvt
);
12990 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12991 if (type_die
== NULL
)
12993 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12994 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12995 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12996 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12997 add_loc_descr (&op0
, cvt
);
12998 if (GET_MODE_CLASS (mode
) == MODE_INT
12999 && (GET_CODE (rtl
) == FIX
13000 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13002 op0
= convert_descriptor_to_mode (mode
, op0
);
13006 mem_loc_result
= op0
;
13013 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13018 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13022 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13027 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13031 /* In theory, we could implement the above. */
13032 /* DWARF cannot represent the unsigned compare operations
13057 case FRACT_CONVERT
:
13058 case UNSIGNED_FRACT_CONVERT
:
13060 case UNSIGNED_SAT_FRACT
:
13066 case VEC_DUPLICATE
:
13070 case STRICT_LOW_PART
:
13075 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13076 can't express it in the debug info. This can happen e.g. with some
13081 resolve_one_addr (&rtl
, NULL
);
13085 #ifdef ENABLE_CHECKING
13086 print_rtl (stderr
, rtl
);
13087 gcc_unreachable ();
13093 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13094 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13096 return mem_loc_result
;
13099 /* Return a descriptor that describes the concatenation of two locations.
13100 This is typically a complex variable. */
13102 static dw_loc_descr_ref
13103 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13105 dw_loc_descr_ref cc_loc_result
= NULL
;
13106 dw_loc_descr_ref x0_ref
13107 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13108 dw_loc_descr_ref x1_ref
13109 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13111 if (x0_ref
== 0 || x1_ref
== 0)
13114 cc_loc_result
= x0_ref
;
13115 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13117 add_loc_descr (&cc_loc_result
, x1_ref
);
13118 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13120 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13121 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13123 return cc_loc_result
;
13126 /* Return a descriptor that describes the concatenation of N
13129 static dw_loc_descr_ref
13130 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13133 dw_loc_descr_ref cc_loc_result
= NULL
;
13134 unsigned int n
= XVECLEN (concatn
, 0);
13136 for (i
= 0; i
< n
; ++i
)
13138 dw_loc_descr_ref ref
;
13139 rtx x
= XVECEXP (concatn
, 0, i
);
13141 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13145 add_loc_descr (&cc_loc_result
, ref
);
13146 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13149 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13150 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13152 return cc_loc_result
;
13155 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13156 for DEBUG_IMPLICIT_PTR RTL. */
13158 static dw_loc_descr_ref
13159 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13161 dw_loc_descr_ref ret
;
13166 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13167 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13168 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13169 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13170 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13171 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13174 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13175 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13176 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13180 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13181 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13186 /* Output a proper Dwarf location descriptor for a variable or parameter
13187 which is either allocated in a register or in a memory location. For a
13188 register, we just generate an OP_REG and the register number. For a
13189 memory location we provide a Dwarf postfix expression describing how to
13190 generate the (dynamic) address of the object onto the address stack.
13192 MODE is mode of the decl if this loc_descriptor is going to be used in
13193 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13194 allowed, VOIDmode otherwise.
13196 If we don't know how to describe it, return 0. */
13198 static dw_loc_descr_ref
13199 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13200 enum var_init_status initialized
)
13202 dw_loc_descr_ref loc_result
= NULL
;
13204 switch (GET_CODE (rtl
))
13207 /* The case of a subreg may arise when we have a local (register)
13208 variable or a formal (register) parameter which doesn't quite fill
13209 up an entire register. For now, just assume that it is
13210 legitimate to make the Dwarf info refer to the whole register which
13211 contains the given subreg. */
13212 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13213 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13214 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13220 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13224 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13225 GET_MODE (rtl
), initialized
);
13226 if (loc_result
== NULL
)
13227 loc_result
= tls_mem_loc_descriptor (rtl
);
13228 if (loc_result
== NULL
)
13230 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13231 if (new_rtl
!= rtl
)
13232 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13237 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13242 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13247 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13249 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13250 if (GET_CODE (loc
) == EXPR_LIST
)
13251 loc
= XEXP (loc
, 0);
13252 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13256 rtl
= XEXP (rtl
, 1);
13261 rtvec par_elems
= XVEC (rtl
, 0);
13262 int num_elem
= GET_NUM_ELEM (par_elems
);
13263 enum machine_mode mode
;
13266 /* Create the first one, so we have something to add to. */
13267 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13268 VOIDmode
, initialized
);
13269 if (loc_result
== NULL
)
13271 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13272 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13273 for (i
= 1; i
< num_elem
; i
++)
13275 dw_loc_descr_ref temp
;
13277 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13278 VOIDmode
, initialized
);
13281 add_loc_descr (&loc_result
, temp
);
13282 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13283 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13289 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13290 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13295 if (mode
== VOIDmode
)
13296 mode
= GET_MODE (rtl
);
13298 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13300 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13302 /* Note that a CONST_DOUBLE rtx could represent either an integer
13303 or a floating-point constant. A CONST_DOUBLE is used whenever
13304 the constant requires more than one word in order to be
13305 adequately represented. We output CONST_DOUBLEs as blocks. */
13306 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13307 GET_MODE_SIZE (mode
), 0);
13308 if (SCALAR_FLOAT_MODE_P (mode
))
13310 unsigned int length
= GET_MODE_SIZE (mode
);
13311 unsigned char *array
13312 = (unsigned char*) ggc_alloc_atomic (length
);
13314 insert_float (rtl
, array
);
13315 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13316 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13317 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13318 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13322 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13323 loc_result
->dw_loc_oprnd2
.v
.val_double
13324 = rtx_to_double_int (rtl
);
13330 if (mode
== VOIDmode
)
13331 mode
= GET_MODE (rtl
);
13333 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13335 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13336 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13337 unsigned char *array
= (unsigned char *)
13338 ggc_alloc_atomic (length
* elt_size
);
13342 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13343 switch (GET_MODE_CLASS (mode
))
13345 case MODE_VECTOR_INT
:
13346 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13348 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13349 double_int val
= rtx_to_double_int (elt
);
13351 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13352 insert_int (val
.to_shwi (), elt_size
, p
);
13355 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13356 insert_double (val
, p
);
13361 case MODE_VECTOR_FLOAT
:
13362 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13364 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13365 insert_float (elt
, p
);
13370 gcc_unreachable ();
13373 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13374 length
* elt_size
, 0);
13375 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13376 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13377 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13378 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13383 if (mode
== VOIDmode
13384 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13385 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13386 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13388 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13393 if (!const_ok_for_output (rtl
))
13396 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13397 && (dwarf_version
>= 4 || !dwarf_strict
))
13399 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13400 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13401 vec_safe_push (used_rtx_array
, rtl
);
13405 case DEBUG_IMPLICIT_PTR
:
13406 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13410 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13411 && CONST_INT_P (XEXP (rtl
, 1)))
13414 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13420 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13421 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13422 && dwarf_version
>= 4)
13423 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13425 /* Value expression. */
13426 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13428 add_loc_descr (&loc_result
,
13429 new_loc_descr (DW_OP_stack_value
, 0, 0));
13437 /* We need to figure out what section we should use as the base for the
13438 address ranges where a given location is valid.
13439 1. If this particular DECL has a section associated with it, use that.
13440 2. If this function has a section associated with it, use that.
13441 3. Otherwise, use the text section.
13442 XXX: If you split a variable across multiple sections, we won't notice. */
13444 static const char *
13445 secname_for_decl (const_tree decl
)
13447 const char *secname
;
13449 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13451 tree sectree
= DECL_SECTION_NAME (decl
);
13452 secname
= TREE_STRING_POINTER (sectree
);
13454 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13456 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13457 secname
= TREE_STRING_POINTER (sectree
);
13459 else if (cfun
&& in_cold_section_p
)
13460 secname
= crtl
->subsections
.cold_section_label
;
13462 secname
= text_section_label
;
13467 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13470 decl_by_reference_p (tree decl
)
13472 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13473 || TREE_CODE (decl
) == VAR_DECL
)
13474 && DECL_BY_REFERENCE (decl
));
13477 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13480 static dw_loc_descr_ref
13481 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13482 enum var_init_status initialized
)
13484 int have_address
= 0;
13485 dw_loc_descr_ref descr
;
13486 enum machine_mode mode
;
13488 if (want_address
!= 2)
13490 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13492 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13494 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13495 if (GET_CODE (varloc
) == EXPR_LIST
)
13496 varloc
= XEXP (varloc
, 0);
13497 mode
= GET_MODE (varloc
);
13498 if (MEM_P (varloc
))
13500 rtx addr
= XEXP (varloc
, 0);
13501 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13502 mode
, initialized
);
13507 rtx x
= avoid_constant_pool_reference (varloc
);
13509 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13514 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13521 if (GET_CODE (varloc
) == VAR_LOCATION
)
13522 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13524 mode
= DECL_MODE (loc
);
13525 descr
= loc_descriptor (varloc
, mode
, initialized
);
13532 if (want_address
== 2 && !have_address
13533 && (dwarf_version
>= 4 || !dwarf_strict
))
13535 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13537 expansion_failed (loc
, NULL_RTX
,
13538 "DWARF address size mismatch");
13541 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13544 /* Show if we can't fill the request for an address. */
13545 if (want_address
&& !have_address
)
13547 expansion_failed (loc
, NULL_RTX
,
13548 "Want address and only have value");
13552 /* If we've got an address and don't want one, dereference. */
13553 if (!want_address
&& have_address
)
13555 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13556 enum dwarf_location_atom op
;
13558 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13560 expansion_failed (loc
, NULL_RTX
,
13561 "DWARF address size mismatch");
13564 else if (size
== DWARF2_ADDR_SIZE
)
13567 op
= DW_OP_deref_size
;
13569 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13575 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13576 if it is not possible. */
13578 static dw_loc_descr_ref
13579 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13581 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13582 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13583 else if (dwarf_version
>= 3 || !dwarf_strict
)
13584 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13589 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13590 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13592 static dw_loc_descr_ref
13593 dw_sra_loc_expr (tree decl
, rtx loc
)
13596 unsigned int padsize
= 0;
13597 dw_loc_descr_ref descr
, *descr_tail
;
13598 unsigned HOST_WIDE_INT decl_size
;
13600 enum var_init_status initialized
;
13602 if (DECL_SIZE (decl
) == NULL
13603 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
13606 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
13608 descr_tail
= &descr
;
13610 for (p
= loc
; p
; p
= XEXP (p
, 1))
13612 unsigned int bitsize
= decl_piece_bitsize (p
);
13613 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13614 dw_loc_descr_ref cur_descr
;
13615 dw_loc_descr_ref
*tail
, last
= NULL
;
13616 unsigned int opsize
= 0;
13618 if (loc_note
== NULL_RTX
13619 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13621 padsize
+= bitsize
;
13624 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13625 varloc
= NOTE_VAR_LOCATION (loc_note
);
13626 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13627 if (cur_descr
== NULL
)
13629 padsize
+= bitsize
;
13633 /* Check that cur_descr either doesn't use
13634 DW_OP_*piece operations, or their sum is equal
13635 to bitsize. Otherwise we can't embed it. */
13636 for (tail
= &cur_descr
; *tail
!= NULL
;
13637 tail
= &(*tail
)->dw_loc_next
)
13638 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13640 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13644 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13646 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13650 if (last
!= NULL
&& opsize
!= bitsize
)
13652 padsize
+= bitsize
;
13653 /* Discard the current piece of the descriptor and release any
13654 addr_table entries it uses. */
13655 remove_loc_list_addr_table_entries (cur_descr
);
13659 /* If there is a hole, add DW_OP_*piece after empty DWARF
13660 expression, which means that those bits are optimized out. */
13663 if (padsize
> decl_size
)
13665 remove_loc_list_addr_table_entries (cur_descr
);
13666 goto discard_descr
;
13668 decl_size
-= padsize
;
13669 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13670 if (*descr_tail
== NULL
)
13672 remove_loc_list_addr_table_entries (cur_descr
);
13673 goto discard_descr
;
13675 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13678 *descr_tail
= cur_descr
;
13680 if (bitsize
> decl_size
)
13681 goto discard_descr
;
13682 decl_size
-= bitsize
;
13685 HOST_WIDE_INT offset
= 0;
13686 if (GET_CODE (varloc
) == VAR_LOCATION
13687 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13689 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13690 if (GET_CODE (varloc
) == EXPR_LIST
)
13691 varloc
= XEXP (varloc
, 0);
13695 if (GET_CODE (varloc
) == CONST
13696 || GET_CODE (varloc
) == SIGN_EXTEND
13697 || GET_CODE (varloc
) == ZERO_EXTEND
)
13698 varloc
= XEXP (varloc
, 0);
13699 else if (GET_CODE (varloc
) == SUBREG
)
13700 varloc
= SUBREG_REG (varloc
);
13705 /* DW_OP_bit_size offset should be zero for register
13706 or implicit location descriptions and empty location
13707 descriptions, but for memory addresses needs big endian
13709 if (MEM_P (varloc
))
13711 unsigned HOST_WIDE_INT memsize
13712 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13713 if (memsize
!= bitsize
)
13715 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13716 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13717 goto discard_descr
;
13718 if (memsize
< bitsize
)
13719 goto discard_descr
;
13720 if (BITS_BIG_ENDIAN
)
13721 offset
= memsize
- bitsize
;
13725 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13726 if (*descr_tail
== NULL
)
13727 goto discard_descr
;
13728 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13732 /* If there were any non-empty expressions, add padding till the end of
13734 if (descr
!= NULL
&& decl_size
!= 0)
13736 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13737 if (*descr_tail
== NULL
)
13738 goto discard_descr
;
13743 /* Discard the descriptor and release any addr_table entries it uses. */
13744 remove_loc_list_addr_table_entries (descr
);
13748 /* Return the dwarf representation of the location list LOC_LIST of
13749 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13752 static dw_loc_list_ref
13753 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13755 const char *endname
, *secname
;
13757 enum var_init_status initialized
;
13758 struct var_loc_node
*node
;
13759 dw_loc_descr_ref descr
;
13760 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13761 dw_loc_list_ref list
= NULL
;
13762 dw_loc_list_ref
*listp
= &list
;
13764 /* Now that we know what section we are using for a base,
13765 actually construct the list of locations.
13766 The first location information is what is passed to the
13767 function that creates the location list, and the remaining
13768 locations just get added on to that list.
13769 Note that we only know the start address for a location
13770 (IE location changes), so to build the range, we use
13771 the range [current location start, next location start].
13772 This means we have to special case the last node, and generate
13773 a range of [last location start, end of function label]. */
13775 secname
= secname_for_decl (decl
);
13777 for (node
= loc_list
->first
; node
; node
= node
->next
)
13778 if (GET_CODE (node
->loc
) == EXPR_LIST
13779 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13781 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13783 /* This requires DW_OP_{,bit_}piece, which is not usable
13784 inside DWARF expressions. */
13785 if (want_address
!= 2)
13787 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13793 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13794 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13795 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13799 bool range_across_switch
= false;
13800 /* If section switch happens in between node->label
13801 and node->next->label (or end of function) and
13802 we can't emit it as a single entry list,
13803 emit two ranges, first one ending at the end
13804 of first partition and second one starting at the
13805 beginning of second partition. */
13806 if (node
== loc_list
->last_before_switch
13807 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13808 && current_function_decl
)
13810 endname
= cfun
->fde
->dw_fde_end
;
13811 range_across_switch
= true;
13813 /* The variable has a location between NODE->LABEL and
13814 NODE->NEXT->LABEL. */
13815 else if (node
->next
)
13816 endname
= node
->next
->label
;
13817 /* If the variable has a location at the last label
13818 it keeps its location until the end of function. */
13819 else if (!current_function_decl
)
13820 endname
= text_end_label
;
13823 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13824 current_function_funcdef_no
);
13825 endname
= ggc_strdup (label_id
);
13828 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13829 if (TREE_CODE (decl
) == PARM_DECL
13830 && node
== loc_list
->first
13831 && NOTE_P (node
->loc
)
13832 && strcmp (node
->label
, endname
) == 0)
13833 (*listp
)->force
= true;
13834 listp
= &(*listp
)->dw_loc_next
;
13836 if (range_across_switch
)
13838 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13839 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13842 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13843 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13844 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13847 gcc_assert (descr
);
13848 /* The variable has a location between NODE->LABEL and
13849 NODE->NEXT->LABEL. */
13851 endname
= node
->next
->label
;
13853 endname
= cfun
->fde
->dw_fde_second_end
;
13854 *listp
= new_loc_list (descr
,
13855 cfun
->fde
->dw_fde_second_begin
,
13857 listp
= &(*listp
)->dw_loc_next
;
13862 /* Try to avoid the overhead of a location list emitting a location
13863 expression instead, but only if we didn't have more than one
13864 location entry in the first place. If some entries were not
13865 representable, we don't want to pretend a single entry that was
13866 applies to the entire scope in which the variable is
13868 if (list
&& loc_list
->first
->next
)
13874 /* Return if the loc_list has only single element and thus can be represented
13875 as location description. */
13878 single_element_loc_list_p (dw_loc_list_ref list
)
13880 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13881 return !list
->ll_symbol
;
13884 /* To each location in list LIST add loc descr REF. */
13887 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13889 dw_loc_descr_ref copy
;
13890 add_loc_descr (&list
->expr
, ref
);
13891 list
= list
->dw_loc_next
;
13894 copy
= ggc_alloc_dw_loc_descr_node ();
13895 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13896 add_loc_descr (&list
->expr
, copy
);
13897 while (copy
->dw_loc_next
)
13899 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13900 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13901 copy
->dw_loc_next
= new_copy
;
13904 list
= list
->dw_loc_next
;
13908 /* Given two lists RET and LIST
13909 produce location list that is result of adding expression in LIST
13910 to expression in RET on each position in program.
13911 Might be destructive on both RET and LIST.
13913 TODO: We handle only simple cases of RET or LIST having at most one
13914 element. General case would inolve sorting the lists in program order
13915 and merging them that will need some additional work.
13916 Adding that will improve quality of debug info especially for SRA-ed
13920 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13929 if (!list
->dw_loc_next
)
13931 add_loc_descr_to_each (*ret
, list
->expr
);
13934 if (!(*ret
)->dw_loc_next
)
13936 add_loc_descr_to_each (list
, (*ret
)->expr
);
13940 expansion_failed (NULL_TREE
, NULL_RTX
,
13941 "Don't know how to merge two non-trivial"
13942 " location lists.\n");
13947 /* LOC is constant expression. Try a luck, look it up in constant
13948 pool and return its loc_descr of its address. */
13950 static dw_loc_descr_ref
13951 cst_pool_loc_descr (tree loc
)
13953 /* Get an RTL for this, if something has been emitted. */
13954 rtx rtl
= lookup_constant_def (loc
);
13956 if (!rtl
|| !MEM_P (rtl
))
13961 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13963 /* TODO: We might get more coverage if we was actually delaying expansion
13964 of all expressions till end of compilation when constant pools are fully
13966 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13968 expansion_failed (loc
, NULL_RTX
,
13969 "CST value in contant pool but not marked.");
13972 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13973 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13976 /* Return dw_loc_list representing address of addr_expr LOC
13977 by looking for inner INDIRECT_REF expression and turning
13978 it into simple arithmetics. */
13980 static dw_loc_list_ref
13981 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13984 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13985 enum machine_mode mode
;
13986 int unsignedp
, volatilep
= 0;
13987 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13989 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13990 &bitsize
, &bitpos
, &offset
, &mode
,
13991 &unsignedp
, &volatilep
, false);
13993 if (bitpos
% BITS_PER_UNIT
)
13995 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13998 if (!INDIRECT_REF_P (obj
))
14000 expansion_failed (obj
,
14001 NULL_RTX
, "no indirect ref in inner refrence");
14004 if (!offset
&& !bitpos
)
14005 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
14007 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14008 && (dwarf_version
>= 4 || !dwarf_strict
))
14010 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
14015 /* Variable offset. */
14016 list_ret1
= loc_list_from_tree (offset
, 0);
14017 if (list_ret1
== 0)
14019 add_loc_list (&list_ret
, list_ret1
);
14022 add_loc_descr_to_each (list_ret
,
14023 new_loc_descr (DW_OP_plus
, 0, 0));
14025 bytepos
= bitpos
/ BITS_PER_UNIT
;
14027 add_loc_descr_to_each (list_ret
,
14028 new_loc_descr (DW_OP_plus_uconst
,
14030 else if (bytepos
< 0)
14031 loc_list_plus_const (list_ret
, bytepos
);
14032 add_loc_descr_to_each (list_ret
,
14033 new_loc_descr (DW_OP_stack_value
, 0, 0));
14039 /* Generate Dwarf location list representing LOC.
14040 If WANT_ADDRESS is false, expression computing LOC will be computed
14041 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14042 if WANT_ADDRESS is 2, expression computing address useable in location
14043 will be returned (i.e. DW_OP_reg can be used
14044 to refer to register values). */
14046 static dw_loc_list_ref
14047 loc_list_from_tree (tree loc
, int want_address
)
14049 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14050 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14051 int have_address
= 0;
14052 enum dwarf_location_atom op
;
14054 /* ??? Most of the time we do not take proper care for sign/zero
14055 extending the values properly. Hopefully this won't be a real
14058 switch (TREE_CODE (loc
))
14061 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14064 case PLACEHOLDER_EXPR
:
14065 /* This case involves extracting fields from an object to determine the
14066 position of other fields. We don't try to encode this here. The
14067 only user of this is Ada, which encodes the needed information using
14068 the names of types. */
14069 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14073 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14074 /* There are no opcodes for these operations. */
14077 case PREINCREMENT_EXPR
:
14078 case PREDECREMENT_EXPR
:
14079 case POSTINCREMENT_EXPR
:
14080 case POSTDECREMENT_EXPR
:
14081 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14082 /* There are no opcodes for these operations. */
14086 /* If we already want an address, see if there is INDIRECT_REF inside
14087 e.g. for &this->field. */
14090 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14091 (loc
, want_address
== 2);
14094 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14095 && (ret
= cst_pool_loc_descr (loc
)))
14098 /* Otherwise, process the argument and look for the address. */
14099 if (!list_ret
&& !ret
)
14100 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14104 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14110 if (DECL_THREAD_LOCAL_P (loc
))
14113 enum dwarf_location_atom tls_op
;
14114 enum dtprel_bool dtprel
= dtprel_false
;
14116 if (targetm
.have_tls
)
14118 /* If this is not defined, we have no way to emit the
14120 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14123 /* The way DW_OP_GNU_push_tls_address is specified, we
14124 can only look up addresses of objects in the current
14125 module. We used DW_OP_addr as first op, but that's
14126 wrong, because DW_OP_addr is relocated by the debug
14127 info consumer, while DW_OP_GNU_push_tls_address
14128 operand shouldn't be. */
14129 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14131 dtprel
= dtprel_true
;
14132 tls_op
= DW_OP_GNU_push_tls_address
;
14136 if (!targetm
.emutls
.debug_form_tls_address
14137 || !(dwarf_version
>= 3 || !dwarf_strict
))
14139 /* We stuffed the control variable into the DECL_VALUE_EXPR
14140 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14141 no longer appear in gimple code. We used the control
14142 variable in specific so that we could pick it up here. */
14143 loc
= DECL_VALUE_EXPR (loc
);
14144 tls_op
= DW_OP_form_tls_address
;
14147 rtl
= rtl_for_decl_location (loc
);
14148 if (rtl
== NULL_RTX
)
14153 rtl
= XEXP (rtl
, 0);
14154 if (! CONSTANT_P (rtl
))
14157 ret
= new_addr_loc_descr (rtl
, dtprel
);
14158 ret1
= new_loc_descr (tls_op
, 0, 0);
14159 add_loc_descr (&ret
, ret1
);
14168 if (DECL_HAS_VALUE_EXPR_P (loc
))
14169 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14173 case FUNCTION_DECL
:
14176 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14178 if (loc_list
&& loc_list
->first
)
14180 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14181 have_address
= want_address
!= 0;
14184 rtl
= rtl_for_decl_location (loc
);
14185 if (rtl
== NULL_RTX
)
14187 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14190 else if (CONST_INT_P (rtl
))
14192 HOST_WIDE_INT val
= INTVAL (rtl
);
14193 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14194 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14195 ret
= int_loc_descriptor (val
);
14197 else if (GET_CODE (rtl
) == CONST_STRING
)
14199 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14202 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14203 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14206 enum machine_mode mode
, mem_mode
;
14208 /* Certain constructs can only be represented at top-level. */
14209 if (want_address
== 2)
14211 ret
= loc_descriptor (rtl
, VOIDmode
,
14212 VAR_INIT_STATUS_INITIALIZED
);
14217 mode
= GET_MODE (rtl
);
14218 mem_mode
= VOIDmode
;
14222 mode
= get_address_mode (rtl
);
14223 rtl
= XEXP (rtl
, 0);
14226 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14227 VAR_INIT_STATUS_INITIALIZED
);
14230 expansion_failed (loc
, rtl
,
14231 "failed to produce loc descriptor for rtl");
14238 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14242 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14246 case COMPOUND_EXPR
:
14247 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14250 case VIEW_CONVERT_EXPR
:
14253 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14255 case COMPONENT_REF
:
14256 case BIT_FIELD_REF
:
14258 case ARRAY_RANGE_REF
:
14259 case REALPART_EXPR
:
14260 case IMAGPART_EXPR
:
14263 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14264 enum machine_mode mode
;
14265 int unsignedp
, volatilep
= 0;
14267 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14268 &unsignedp
, &volatilep
, false);
14270 gcc_assert (obj
!= loc
);
14272 list_ret
= loc_list_from_tree (obj
,
14274 && !bitpos
&& !offset
? 2 : 1);
14275 /* TODO: We can extract value of the small expression via shifting even
14276 for nonzero bitpos. */
14279 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14281 expansion_failed (loc
, NULL_RTX
,
14282 "bitfield access");
14286 if (offset
!= NULL_TREE
)
14288 /* Variable offset. */
14289 list_ret1
= loc_list_from_tree (offset
, 0);
14290 if (list_ret1
== 0)
14292 add_loc_list (&list_ret
, list_ret1
);
14295 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14298 bytepos
= bitpos
/ BITS_PER_UNIT
;
14300 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14301 else if (bytepos
< 0)
14302 loc_list_plus_const (list_ret
, bytepos
);
14309 if ((want_address
|| !tree_fits_shwi_p (loc
))
14310 && (ret
= cst_pool_loc_descr (loc
)))
14312 else if (want_address
== 2
14313 && tree_fits_shwi_p (loc
)
14314 && (ret
= address_of_int_loc_descriptor
14315 (int_size_in_bytes (TREE_TYPE (loc
)),
14316 tree_to_shwi (loc
))))
14318 else if (tree_fits_shwi_p (loc
))
14319 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14322 expansion_failed (loc
, NULL_RTX
,
14323 "Integer operand is not host integer");
14332 if ((ret
= cst_pool_loc_descr (loc
)))
14335 /* We can construct small constants here using int_loc_descriptor. */
14336 expansion_failed (loc
, NULL_RTX
,
14337 "constructor or constant not in constant pool");
14340 case TRUTH_AND_EXPR
:
14341 case TRUTH_ANDIF_EXPR
:
14346 case TRUTH_XOR_EXPR
:
14351 case TRUTH_OR_EXPR
:
14352 case TRUTH_ORIF_EXPR
:
14357 case FLOOR_DIV_EXPR
:
14358 case CEIL_DIV_EXPR
:
14359 case ROUND_DIV_EXPR
:
14360 case TRUNC_DIV_EXPR
:
14361 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14370 case FLOOR_MOD_EXPR
:
14371 case CEIL_MOD_EXPR
:
14372 case ROUND_MOD_EXPR
:
14373 case TRUNC_MOD_EXPR
:
14374 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14379 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14380 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14381 if (list_ret
== 0 || list_ret1
== 0)
14384 add_loc_list (&list_ret
, list_ret1
);
14387 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14388 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14389 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14390 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14391 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14403 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14406 case POINTER_PLUS_EXPR
:
14408 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14410 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14414 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14422 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14429 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14436 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14443 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14458 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14459 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14460 if (list_ret
== 0 || list_ret1
== 0)
14463 add_loc_list (&list_ret
, list_ret1
);
14466 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14469 case TRUTH_NOT_EXPR
:
14483 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14487 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14493 const enum tree_code code
=
14494 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14496 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14497 build2 (code
, integer_type_node
,
14498 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14499 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14502 /* ... fall through ... */
14506 dw_loc_descr_ref lhs
14507 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14508 dw_loc_list_ref rhs
14509 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14510 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14512 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14513 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14516 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14517 add_loc_descr_to_each (list_ret
, bra_node
);
14519 add_loc_list (&list_ret
, rhs
);
14520 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14521 add_loc_descr_to_each (list_ret
, jump_node
);
14523 add_loc_descr_to_each (list_ret
, lhs
);
14524 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14525 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14527 /* ??? Need a node to point the skip at. Use a nop. */
14528 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14529 add_loc_descr_to_each (list_ret
, tmp
);
14530 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14531 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14535 case FIX_TRUNC_EXPR
:
14539 /* Leave front-end specific codes as simply unknown. This comes
14540 up, for instance, with the C STMT_EXPR. */
14541 if ((unsigned int) TREE_CODE (loc
)
14542 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14544 expansion_failed (loc
, NULL_RTX
,
14545 "language specific tree node");
14549 #ifdef ENABLE_CHECKING
14550 /* Otherwise this is a generic code; we should just lists all of
14551 these explicitly. We forgot one. */
14552 gcc_unreachable ();
14554 /* In a release build, we want to degrade gracefully: better to
14555 generate incomplete debugging information than to crash. */
14560 if (!ret
&& !list_ret
)
14563 if (want_address
== 2 && !have_address
14564 && (dwarf_version
>= 4 || !dwarf_strict
))
14566 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14568 expansion_failed (loc
, NULL_RTX
,
14569 "DWARF address size mismatch");
14573 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14575 add_loc_descr_to_each (list_ret
,
14576 new_loc_descr (DW_OP_stack_value
, 0, 0));
14579 /* Show if we can't fill the request for an address. */
14580 if (want_address
&& !have_address
)
14582 expansion_failed (loc
, NULL_RTX
,
14583 "Want address and only have value");
14587 gcc_assert (!ret
|| !list_ret
);
14589 /* If we've got an address and don't want one, dereference. */
14590 if (!want_address
&& have_address
)
14592 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14594 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14596 expansion_failed (loc
, NULL_RTX
,
14597 "DWARF address size mismatch");
14600 else if (size
== DWARF2_ADDR_SIZE
)
14603 op
= DW_OP_deref_size
;
14606 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14608 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14611 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14616 /* Same as above but return only single location expression. */
14617 static dw_loc_descr_ref
14618 loc_descriptor_from_tree (tree loc
, int want_address
)
14620 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14623 if (ret
->dw_loc_next
)
14625 expansion_failed (loc
, NULL_RTX
,
14626 "Location list where only loc descriptor needed");
14632 /* Given a value, round it up to the lowest multiple of `boundary'
14633 which is not less than the value itself. */
14635 static inline HOST_WIDE_INT
14636 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14638 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14641 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14642 pointer to the declared type for the relevant field variable, or return
14643 `integer_type_node' if the given node turns out to be an
14644 ERROR_MARK node. */
14647 field_type (const_tree decl
)
14651 if (TREE_CODE (decl
) == ERROR_MARK
)
14652 return integer_type_node
;
14654 type
= DECL_BIT_FIELD_TYPE (decl
);
14655 if (type
== NULL_TREE
)
14656 type
= TREE_TYPE (decl
);
14661 /* Given a pointer to a tree node, return the alignment in bits for
14662 it, or else return BITS_PER_WORD if the node actually turns out to
14663 be an ERROR_MARK node. */
14665 static inline unsigned
14666 simple_type_align_in_bits (const_tree type
)
14668 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14671 static inline unsigned
14672 simple_decl_align_in_bits (const_tree decl
)
14674 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14677 /* Return the result of rounding T up to ALIGN. */
14679 static inline double_int
14680 round_up_to_align (double_int t
, unsigned int align
)
14682 double_int alignd
= double_int::from_uhwi (align
);
14684 t
+= double_int_minus_one
;
14685 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14690 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14691 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14692 or return 0 if we are unable to determine what that offset is, either
14693 because the argument turns out to be a pointer to an ERROR_MARK node, or
14694 because the offset is actually variable. (We can't handle the latter case
14697 static HOST_WIDE_INT
14698 field_byte_offset (const_tree decl
)
14700 double_int object_offset_in_bits
;
14701 double_int object_offset_in_bytes
;
14702 double_int bitpos_int
;
14704 if (TREE_CODE (decl
) == ERROR_MARK
)
14707 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14709 /* We cannot yet cope with fields whose positions are variable, so
14710 for now, when we see such things, we simply return 0. Someday, we may
14711 be able to handle such cases, but it will be damn difficult. */
14712 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14715 bitpos_int
= tree_to_double_int (bit_position (decl
));
14717 #ifdef PCC_BITFIELD_TYPE_MATTERS
14718 if (PCC_BITFIELD_TYPE_MATTERS
)
14721 tree field_size_tree
;
14722 double_int deepest_bitpos
;
14723 double_int field_size_in_bits
;
14724 unsigned int type_align_in_bits
;
14725 unsigned int decl_align_in_bits
;
14726 double_int type_size_in_bits
;
14728 type
= field_type (decl
);
14729 type_size_in_bits
= double_int_type_size_in_bits (type
);
14730 type_align_in_bits
= simple_type_align_in_bits (type
);
14732 field_size_tree
= DECL_SIZE (decl
);
14734 /* The size could be unspecified if there was an error, or for
14735 a flexible array member. */
14736 if (!field_size_tree
)
14737 field_size_tree
= bitsize_zero_node
;
14739 /* If the size of the field is not constant, use the type size. */
14740 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14741 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14743 field_size_in_bits
= type_size_in_bits
;
14745 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14747 /* The GCC front-end doesn't make any attempt to keep track of the
14748 starting bit offset (relative to the start of the containing
14749 structure type) of the hypothetical "containing object" for a
14750 bit-field. Thus, when computing the byte offset value for the
14751 start of the "containing object" of a bit-field, we must deduce
14752 this information on our own. This can be rather tricky to do in
14753 some cases. For example, handling the following structure type
14754 definition when compiling for an i386/i486 target (which only
14755 aligns long long's to 32-bit boundaries) can be very tricky:
14757 struct S { int field1; long long field2:31; };
14759 Fortunately, there is a simple rule-of-thumb which can be used
14760 in such cases. When compiling for an i386/i486, GCC will
14761 allocate 8 bytes for the structure shown above. It decides to
14762 do this based upon one simple rule for bit-field allocation.
14763 GCC allocates each "containing object" for each bit-field at
14764 the first (i.e. lowest addressed) legitimate alignment boundary
14765 (based upon the required minimum alignment for the declared
14766 type of the field) which it can possibly use, subject to the
14767 condition that there is still enough available space remaining
14768 in the containing object (when allocated at the selected point)
14769 to fully accommodate all of the bits of the bit-field itself.
14771 This simple rule makes it obvious why GCC allocates 8 bytes for
14772 each object of the structure type shown above. When looking
14773 for a place to allocate the "containing object" for `field2',
14774 the compiler simply tries to allocate a 64-bit "containing
14775 object" at each successive 32-bit boundary (starting at zero)
14776 until it finds a place to allocate that 64- bit field such that
14777 at least 31 contiguous (and previously unallocated) bits remain
14778 within that selected 64 bit field. (As it turns out, for the
14779 example above, the compiler finds it is OK to allocate the
14780 "containing object" 64-bit field at bit-offset zero within the
14783 Here we attempt to work backwards from the limited set of facts
14784 we're given, and we try to deduce from those facts, where GCC
14785 must have believed that the containing object started (within
14786 the structure type). The value we deduce is then used (by the
14787 callers of this routine) to generate DW_AT_location and
14788 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14789 the case of DW_AT_location, regular fields as well). */
14791 /* Figure out the bit-distance from the start of the structure to
14792 the "deepest" bit of the bit-field. */
14793 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14795 /* This is the tricky part. Use some fancy footwork to deduce
14796 where the lowest addressed bit of the containing object must
14798 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14800 /* Round up to type_align by default. This works best for
14802 object_offset_in_bits
14803 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14805 if (object_offset_in_bits
.ugt (bitpos_int
))
14807 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14809 /* Round up to decl_align instead. */
14810 object_offset_in_bits
14811 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14815 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14816 object_offset_in_bits
= bitpos_int
;
14818 object_offset_in_bytes
14819 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14820 true, TRUNC_DIV_EXPR
);
14821 return object_offset_in_bytes
.to_shwi ();
14824 /* The following routines define various Dwarf attributes and any data
14825 associated with them. */
14827 /* Add a location description attribute value to a DIE.
14829 This emits location attributes suitable for whole variables and
14830 whole parameters. Note that the location attributes for struct fields are
14831 generated by the routine `data_member_location_attribute' below. */
14834 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14835 dw_loc_list_ref descr
)
14839 if (single_element_loc_list_p (descr
))
14840 add_AT_loc (die
, attr_kind
, descr
->expr
);
14842 add_AT_loc_list (die
, attr_kind
, descr
);
14845 /* Add DW_AT_accessibility attribute to DIE if needed. */
14848 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14850 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14851 children, otherwise the default is DW_ACCESS_public. In DWARF2
14852 the default has always been DW_ACCESS_public. */
14853 if (TREE_PROTECTED (decl
))
14854 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14855 else if (TREE_PRIVATE (decl
))
14857 if (dwarf_version
== 2
14858 || die
->die_parent
== NULL
14859 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14860 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14862 else if (dwarf_version
> 2
14864 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14865 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14868 /* Attach the specialized form of location attribute used for data members of
14869 struct and union types. In the special case of a FIELD_DECL node which
14870 represents a bit-field, the "offset" part of this special location
14871 descriptor must indicate the distance in bytes from the lowest-addressed
14872 byte of the containing struct or union type to the lowest-addressed byte of
14873 the "containing object" for the bit-field. (See the `field_byte_offset'
14876 For any given bit-field, the "containing object" is a hypothetical object
14877 (of some integral or enum type) within which the given bit-field lives. The
14878 type of this hypothetical "containing object" is always the same as the
14879 declared type of the individual bit-field itself (for GCC anyway... the
14880 DWARF spec doesn't actually mandate this). Note that it is the size (in
14881 bytes) of the hypothetical "containing object" which will be given in the
14882 DW_AT_byte_size attribute for this bit-field. (See the
14883 `byte_size_attribute' function below.) It is also used when calculating the
14884 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14885 function below.) */
14888 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14890 HOST_WIDE_INT offset
;
14891 dw_loc_descr_ref loc_descr
= 0;
14893 if (TREE_CODE (decl
) == TREE_BINFO
)
14895 /* We're working on the TAG_inheritance for a base class. */
14896 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14898 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14899 aren't at a fixed offset from all (sub)objects of the same
14900 type. We need to extract the appropriate offset from our
14901 vtable. The following dwarf expression means
14903 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14905 This is specific to the V3 ABI, of course. */
14907 dw_loc_descr_ref tmp
;
14909 /* Make a copy of the object address. */
14910 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14911 add_loc_descr (&loc_descr
, tmp
);
14913 /* Extract the vtable address. */
14914 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14915 add_loc_descr (&loc_descr
, tmp
);
14917 /* Calculate the address of the offset. */
14918 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
14919 gcc_assert (offset
< 0);
14921 tmp
= int_loc_descriptor (-offset
);
14922 add_loc_descr (&loc_descr
, tmp
);
14923 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14924 add_loc_descr (&loc_descr
, tmp
);
14926 /* Extract the offset. */
14927 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14928 add_loc_descr (&loc_descr
, tmp
);
14930 /* Add it to the object address. */
14931 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14932 add_loc_descr (&loc_descr
, tmp
);
14935 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
14938 offset
= field_byte_offset (decl
);
14942 if (dwarf_version
> 2)
14944 /* Don't need to output a location expression, just the constant. */
14946 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14948 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14953 enum dwarf_location_atom op
;
14955 /* The DWARF2 standard says that we should assume that the structure
14956 address is already on the stack, so we can specify a structure
14957 field address by using DW_OP_plus_uconst. */
14958 op
= DW_OP_plus_uconst
;
14959 loc_descr
= new_loc_descr (op
, offset
, 0);
14963 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14966 /* Writes integer values to dw_vec_const array. */
14969 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14973 *dest
++ = val
& 0xff;
14979 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14981 static HOST_WIDE_INT
14982 extract_int (const unsigned char *src
, unsigned int size
)
14984 HOST_WIDE_INT val
= 0;
14990 val
|= *--src
& 0xff;
14996 /* Writes double_int values to dw_vec_const array. */
14999 insert_double (double_int val
, unsigned char *dest
)
15001 unsigned char *p0
= dest
;
15002 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
15004 if (WORDS_BIG_ENDIAN
)
15010 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
15011 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
15014 /* Writes floating point values to dw_vec_const array. */
15017 insert_float (const_rtx rtl
, unsigned char *array
)
15019 REAL_VALUE_TYPE rv
;
15023 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15024 real_to_target (val
, &rv
, GET_MODE (rtl
));
15026 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15027 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15029 insert_int (val
[i
], 4, array
);
15034 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15035 does not have a "location" either in memory or in a register. These
15036 things can arise in GNU C when a constant is passed as an actual parameter
15037 to an inlined function. They can also arise in C++ where declared
15038 constants do not necessarily get memory "homes". */
15041 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15043 switch (GET_CODE (rtl
))
15047 HOST_WIDE_INT val
= INTVAL (rtl
);
15050 add_AT_int (die
, DW_AT_const_value
, val
);
15052 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15057 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15058 floating-point constant. A CONST_DOUBLE is used whenever the
15059 constant requires more than one word in order to be adequately
15062 enum machine_mode mode
= GET_MODE (rtl
);
15064 if (SCALAR_FLOAT_MODE_P (mode
))
15066 unsigned int length
= GET_MODE_SIZE (mode
);
15067 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15069 insert_float (rtl
, array
);
15070 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15073 add_AT_double (die
, DW_AT_const_value
,
15074 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15080 enum machine_mode mode
= GET_MODE (rtl
);
15081 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15082 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15083 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15084 (length
* elt_size
);
15088 switch (GET_MODE_CLASS (mode
))
15090 case MODE_VECTOR_INT
:
15091 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15093 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15094 double_int val
= rtx_to_double_int (elt
);
15096 if (elt_size
<= sizeof (HOST_WIDE_INT
))
15097 insert_int (val
.to_shwi (), elt_size
, p
);
15100 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
15101 insert_double (val
, p
);
15106 case MODE_VECTOR_FLOAT
:
15107 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15109 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15110 insert_float (elt
, p
);
15115 gcc_unreachable ();
15118 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15123 if (dwarf_version
>= 4 || !dwarf_strict
)
15125 dw_loc_descr_ref loc_result
;
15126 resolve_one_addr (&rtl
, NULL
);
15128 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15129 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15130 add_AT_loc (die
, DW_AT_location
, loc_result
);
15131 vec_safe_push (used_rtx_array
, rtl
);
15137 if (CONSTANT_P (XEXP (rtl
, 0)))
15138 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15141 if (!const_ok_for_output (rtl
))
15144 if (dwarf_version
>= 4 || !dwarf_strict
)
15149 /* In cases where an inlined instance of an inline function is passed
15150 the address of an `auto' variable (which is local to the caller) we
15151 can get a situation where the DECL_RTL of the artificial local
15152 variable (for the inlining) which acts as a stand-in for the
15153 corresponding formal parameter (of the inline function) will look
15154 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15155 exactly a compile-time constant expression, but it isn't the address
15156 of the (artificial) local variable either. Rather, it represents the
15157 *value* which the artificial local variable always has during its
15158 lifetime. We currently have no way to represent such quasi-constant
15159 values in Dwarf, so for now we just punt and generate nothing. */
15167 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15168 && MEM_READONLY_P (rtl
)
15169 && GET_MODE (rtl
) == BLKmode
)
15171 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15177 /* No other kinds of rtx should be possible here. */
15178 gcc_unreachable ();
15183 /* Determine whether the evaluation of EXPR references any variables
15184 or functions which aren't otherwise used (and therefore may not be
15187 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15188 void * data ATTRIBUTE_UNUSED
)
15190 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15191 *walk_subtrees
= 0;
15193 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15194 && ! TREE_ASM_WRITTEN (*tp
))
15196 /* ??? The C++ FE emits debug information for using decls, so
15197 putting gcc_unreachable here falls over. See PR31899. For now
15198 be conservative. */
15199 else if (!cgraph_global_info_ready
15200 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15202 else if (TREE_CODE (*tp
) == VAR_DECL
)
15204 varpool_node
*node
= varpool_get_node (*tp
);
15205 if (!node
|| !node
->definition
)
15208 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15209 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15211 /* The call graph machinery must have finished analyzing,
15212 optimizing and gimplifying the CU by now.
15213 So if *TP has no call graph node associated
15214 to it, it means *TP will not be emitted. */
15215 if (!cgraph_get_node (*tp
))
15218 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15224 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15225 for use in a later add_const_value_attribute call. */
15228 rtl_for_decl_init (tree init
, tree type
)
15230 rtx rtl
= NULL_RTX
;
15234 /* If a variable is initialized with a string constant without embedded
15235 zeros, build CONST_STRING. */
15236 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15238 tree enttype
= TREE_TYPE (type
);
15239 tree domain
= TYPE_DOMAIN (type
);
15240 enum machine_mode mode
= TYPE_MODE (enttype
);
15242 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15244 && integer_zerop (TYPE_MIN_VALUE (domain
))
15245 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15246 TREE_STRING_LENGTH (init
) - 1) == 0
15247 && ((size_t) TREE_STRING_LENGTH (init
)
15248 == strlen (TREE_STRING_POINTER (init
)) + 1))
15250 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15251 ggc_strdup (TREE_STRING_POINTER (init
)));
15252 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15253 MEM_READONLY_P (rtl
) = 1;
15256 /* Other aggregates, and complex values, could be represented using
15258 else if (AGGREGATE_TYPE_P (type
)
15259 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15260 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15261 || TREE_CODE (type
) == COMPLEX_TYPE
)
15263 /* Vectors only work if their mode is supported by the target.
15264 FIXME: generic vectors ought to work too. */
15265 else if (TREE_CODE (type
) == VECTOR_TYPE
15266 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15268 /* If the initializer is something that we know will expand into an
15269 immediate RTL constant, expand it now. We must be careful not to
15270 reference variables which won't be output. */
15271 else if (initializer_constant_valid_p (init
, type
)
15272 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15274 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15276 if (TREE_CODE (type
) == VECTOR_TYPE
)
15277 switch (TREE_CODE (init
))
15282 if (TREE_CONSTANT (init
))
15284 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15285 bool constant_p
= true;
15287 unsigned HOST_WIDE_INT ix
;
15289 /* Even when ctor is constant, it might contain non-*_CST
15290 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15291 belong into VECTOR_CST nodes. */
15292 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15293 if (!CONSTANT_CLASS_P (value
))
15295 constant_p
= false;
15301 init
= build_vector_from_ctor (type
, elts
);
15311 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15313 /* If expand_expr returns a MEM, it wasn't immediate. */
15314 gcc_assert (!rtl
|| !MEM_P (rtl
));
15320 /* Generate RTL for the variable DECL to represent its location. */
15323 rtl_for_decl_location (tree decl
)
15327 /* Here we have to decide where we are going to say the parameter "lives"
15328 (as far as the debugger is concerned). We only have a couple of
15329 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15331 DECL_RTL normally indicates where the parameter lives during most of the
15332 activation of the function. If optimization is enabled however, this
15333 could be either NULL or else a pseudo-reg. Both of those cases indicate
15334 that the parameter doesn't really live anywhere (as far as the code
15335 generation parts of GCC are concerned) during most of the function's
15336 activation. That will happen (for example) if the parameter is never
15337 referenced within the function.
15339 We could just generate a location descriptor here for all non-NULL
15340 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15341 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15342 where DECL_RTL is NULL or is a pseudo-reg.
15344 Note however that we can only get away with using DECL_INCOMING_RTL as
15345 a backup substitute for DECL_RTL in certain limited cases. In cases
15346 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15347 we can be sure that the parameter was passed using the same type as it is
15348 declared to have within the function, and that its DECL_INCOMING_RTL
15349 points us to a place where a value of that type is passed.
15351 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15352 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15353 because in these cases DECL_INCOMING_RTL points us to a value of some
15354 type which is *different* from the type of the parameter itself. Thus,
15355 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15356 such cases, the debugger would end up (for example) trying to fetch a
15357 `float' from a place which actually contains the first part of a
15358 `double'. That would lead to really incorrect and confusing
15359 output at debug-time.
15361 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15362 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15363 are a couple of exceptions however. On little-endian machines we can
15364 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15365 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15366 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15367 when (on a little-endian machine) a non-prototyped function has a
15368 parameter declared to be of type `short' or `char'. In such cases,
15369 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15370 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15371 passed `int' value. If the debugger then uses that address to fetch
15372 a `short' or a `char' (on a little-endian machine) the result will be
15373 the correct data, so we allow for such exceptional cases below.
15375 Note that our goal here is to describe the place where the given formal
15376 parameter lives during most of the function's activation (i.e. between the
15377 end of the prologue and the start of the epilogue). We'll do that as best
15378 as we can. Note however that if the given formal parameter is modified
15379 sometime during the execution of the function, then a stack backtrace (at
15380 debug-time) will show the function as having been called with the *new*
15381 value rather than the value which was originally passed in. This happens
15382 rarely enough that it is not a major problem, but it *is* a problem, and
15383 I'd like to fix it.
15385 A future version of dwarf2out.c may generate two additional attributes for
15386 any given DW_TAG_formal_parameter DIE which will describe the "passed
15387 type" and the "passed location" for the given formal parameter in addition
15388 to the attributes we now generate to indicate the "declared type" and the
15389 "active location" for each parameter. This additional set of attributes
15390 could be used by debuggers for stack backtraces. Separately, note that
15391 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15392 This happens (for example) for inlined-instances of inline function formal
15393 parameters which are never referenced. This really shouldn't be
15394 happening. All PARM_DECL nodes should get valid non-NULL
15395 DECL_INCOMING_RTL values. FIXME. */
15397 /* Use DECL_RTL as the "location" unless we find something better. */
15398 rtl
= DECL_RTL_IF_SET (decl
);
15400 /* When generating abstract instances, ignore everything except
15401 constants, symbols living in memory, and symbols living in
15402 fixed registers. */
15403 if (! reload_completed
)
15406 && (CONSTANT_P (rtl
)
15408 && CONSTANT_P (XEXP (rtl
, 0)))
15410 && TREE_CODE (decl
) == VAR_DECL
15411 && TREE_STATIC (decl
))))
15413 rtl
= targetm
.delegitimize_address (rtl
);
15418 else if (TREE_CODE (decl
) == PARM_DECL
)
15420 if (rtl
== NULL_RTX
15421 || is_pseudo_reg (rtl
)
15423 && is_pseudo_reg (XEXP (rtl
, 0))
15424 && DECL_INCOMING_RTL (decl
)
15425 && MEM_P (DECL_INCOMING_RTL (decl
))
15426 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15428 tree declared_type
= TREE_TYPE (decl
);
15429 tree passed_type
= DECL_ARG_TYPE (decl
);
15430 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15431 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15433 /* This decl represents a formal parameter which was optimized out.
15434 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15435 all cases where (rtl == NULL_RTX) just below. */
15436 if (dmode
== pmode
)
15437 rtl
= DECL_INCOMING_RTL (decl
);
15438 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15439 && SCALAR_INT_MODE_P (dmode
)
15440 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15441 && DECL_INCOMING_RTL (decl
))
15443 rtx inc
= DECL_INCOMING_RTL (decl
);
15446 else if (MEM_P (inc
))
15448 if (BYTES_BIG_ENDIAN
)
15449 rtl
= adjust_address_nv (inc
, dmode
,
15450 GET_MODE_SIZE (pmode
)
15451 - GET_MODE_SIZE (dmode
));
15458 /* If the parm was passed in registers, but lives on the stack, then
15459 make a big endian correction if the mode of the type of the
15460 parameter is not the same as the mode of the rtl. */
15461 /* ??? This is the same series of checks that are made in dbxout.c before
15462 we reach the big endian correction code there. It isn't clear if all
15463 of these checks are necessary here, but keeping them all is the safe
15465 else if (MEM_P (rtl
)
15466 && XEXP (rtl
, 0) != const0_rtx
15467 && ! CONSTANT_P (XEXP (rtl
, 0))
15468 /* Not passed in memory. */
15469 && !MEM_P (DECL_INCOMING_RTL (decl
))
15470 /* Not passed by invisible reference. */
15471 && (!REG_P (XEXP (rtl
, 0))
15472 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15473 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15474 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15475 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15478 /* Big endian correction check. */
15479 && BYTES_BIG_ENDIAN
15480 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15481 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15484 enum machine_mode addr_mode
= get_address_mode (rtl
);
15485 int offset
= (UNITS_PER_WORD
15486 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15488 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15489 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15492 else if (TREE_CODE (decl
) == VAR_DECL
15495 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15496 && BYTES_BIG_ENDIAN
)
15498 enum machine_mode addr_mode
= get_address_mode (rtl
);
15499 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15500 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15502 /* If a variable is declared "register" yet is smaller than
15503 a register, then if we store the variable to memory, it
15504 looks like we're storing a register-sized value, when in
15505 fact we are not. We need to adjust the offset of the
15506 storage location to reflect the actual value's bytes,
15507 else gdb will not be able to display it. */
15509 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15510 plus_constant (addr_mode
, XEXP (rtl
, 0),
15514 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15515 and will have been substituted directly into all expressions that use it.
15516 C does not have such a concept, but C++ and other languages do. */
15517 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15518 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15521 rtl
= targetm
.delegitimize_address (rtl
);
15523 /* If we don't look past the constant pool, we risk emitting a
15524 reference to a constant pool entry that isn't referenced from
15525 code, and thus is not emitted. */
15527 rtl
= avoid_constant_pool_reference (rtl
);
15529 /* Try harder to get a rtl. If this symbol ends up not being emitted
15530 in the current CU, resolve_addr will remove the expression referencing
15532 if (rtl
== NULL_RTX
15533 && TREE_CODE (decl
) == VAR_DECL
15534 && !DECL_EXTERNAL (decl
)
15535 && TREE_STATIC (decl
)
15536 && DECL_NAME (decl
)
15537 && !DECL_HARD_REGISTER (decl
)
15538 && DECL_MODE (decl
) != VOIDmode
)
15540 rtl
= make_decl_rtl_for_debug (decl
);
15542 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15543 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15550 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15551 returned. If so, the decl for the COMMON block is returned, and the
15552 value is the offset into the common block for the symbol. */
15555 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15557 tree val_expr
, cvar
;
15558 enum machine_mode mode
;
15559 HOST_WIDE_INT bitsize
, bitpos
;
15561 int unsignedp
, volatilep
= 0;
15563 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15564 it does not have a value (the offset into the common area), or if it
15565 is thread local (as opposed to global) then it isn't common, and shouldn't
15566 be handled as such. */
15567 if (TREE_CODE (decl
) != VAR_DECL
15568 || !TREE_STATIC (decl
)
15569 || !DECL_HAS_VALUE_EXPR_P (decl
)
15573 val_expr
= DECL_VALUE_EXPR (decl
);
15574 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15577 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15578 &mode
, &unsignedp
, &volatilep
, true);
15580 if (cvar
== NULL_TREE
15581 || TREE_CODE (cvar
) != VAR_DECL
15582 || DECL_ARTIFICIAL (cvar
)
15583 || !TREE_PUBLIC (cvar
))
15587 if (offset
!= NULL
)
15589 if (!tree_fits_shwi_p (offset
))
15591 *value
= tree_to_shwi (offset
);
15594 *value
+= bitpos
/ BITS_PER_UNIT
;
15599 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15600 data attribute for a variable or a parameter. We generate the
15601 DW_AT_const_value attribute only in those cases where the given variable
15602 or parameter does not have a true "location" either in memory or in a
15603 register. This can happen (for example) when a constant is passed as an
15604 actual argument in a call to an inline function. (It's possible that
15605 these things can crop up in other ways also.) Note that one type of
15606 constant value which can be passed into an inlined function is a constant
15607 pointer. This can happen for example if an actual argument in an inlined
15608 function call evaluates to a compile-time constant address.
15610 CACHE_P is true if it is worth caching the location list for DECL,
15611 so that future calls can reuse it rather than regenerate it from scratch.
15612 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15613 since we will need to refer to them each time the function is inlined. */
15616 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15617 enum dwarf_attribute attr
)
15620 dw_loc_list_ref list
;
15621 var_loc_list
*loc_list
;
15622 cached_dw_loc_list
*cache
;
15625 if (TREE_CODE (decl
) == ERROR_MARK
)
15628 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15629 || TREE_CODE (decl
) == RESULT_DECL
);
15631 /* Try to get some constant RTL for this decl, and use that as the value of
15634 rtl
= rtl_for_decl_location (decl
);
15635 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15636 && add_const_value_attribute (die
, rtl
))
15639 /* See if we have single element location list that is equivalent to
15640 a constant value. That way we are better to use add_const_value_attribute
15641 rather than expanding constant value equivalent. */
15642 loc_list
= lookup_decl_loc (decl
);
15645 && loc_list
->first
->next
== NULL
15646 && NOTE_P (loc_list
->first
->loc
)
15647 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15648 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15650 struct var_loc_node
*node
;
15652 node
= loc_list
->first
;
15653 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15654 if (GET_CODE (rtl
) == EXPR_LIST
)
15655 rtl
= XEXP (rtl
, 0);
15656 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15657 && add_const_value_attribute (die
, rtl
))
15660 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15661 list several times. See if we've already cached the contents. */
15663 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15667 cache
= (cached_dw_loc_list
*)
15668 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15670 list
= cache
->loc_list
;
15674 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15675 /* It is usually worth caching this result if the decl is from
15676 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15677 if (cache_p
&& list
&& list
->dw_loc_next
)
15679 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15680 DECL_UID (decl
), INSERT
);
15681 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15682 cache
->decl_id
= DECL_UID (decl
);
15683 cache
->loc_list
= list
;
15689 add_AT_location_description (die
, attr
, list
);
15692 /* None of that worked, so it must not really have a location;
15693 try adding a constant value attribute from the DECL_INITIAL. */
15694 return tree_add_const_value_attribute_for_decl (die
, decl
);
15697 /* Add VARIABLE and DIE into deferred locations list. */
15700 defer_location (tree variable
, dw_die_ref die
)
15702 deferred_locations entry
;
15703 entry
.variable
= variable
;
15705 vec_safe_push (deferred_locations_list
, entry
);
15708 /* Helper function for tree_add_const_value_attribute. Natively encode
15709 initializer INIT into an array. Return true if successful. */
15712 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15716 if (init
== NULL_TREE
)
15720 switch (TREE_CODE (init
))
15723 type
= TREE_TYPE (init
);
15724 if (TREE_CODE (type
) == ARRAY_TYPE
)
15726 tree enttype
= TREE_TYPE (type
);
15727 enum machine_mode mode
= TYPE_MODE (enttype
);
15729 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15731 if (int_size_in_bytes (type
) != size
)
15733 if (size
> TREE_STRING_LENGTH (init
))
15735 memcpy (array
, TREE_STRING_POINTER (init
),
15736 TREE_STRING_LENGTH (init
));
15737 memset (array
+ TREE_STRING_LENGTH (init
),
15738 '\0', size
- TREE_STRING_LENGTH (init
));
15741 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15746 type
= TREE_TYPE (init
);
15747 if (int_size_in_bytes (type
) != size
)
15749 if (TREE_CODE (type
) == ARRAY_TYPE
)
15751 HOST_WIDE_INT min_index
;
15752 unsigned HOST_WIDE_INT cnt
;
15753 int curpos
= 0, fieldsize
;
15754 constructor_elt
*ce
;
15756 if (TYPE_DOMAIN (type
) == NULL_TREE
15757 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
15760 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15761 if (fieldsize
<= 0)
15764 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
15765 memset (array
, '\0', size
);
15766 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15768 tree val
= ce
->value
;
15769 tree index
= ce
->index
;
15771 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15772 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
15775 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
15780 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15783 curpos
= pos
+ fieldsize
;
15784 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15786 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
15787 - tree_to_shwi (TREE_OPERAND (index
, 0));
15788 while (count
-- > 0)
15791 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15792 curpos
+= fieldsize
;
15795 gcc_assert (curpos
<= size
);
15799 else if (TREE_CODE (type
) == RECORD_TYPE
15800 || TREE_CODE (type
) == UNION_TYPE
)
15802 tree field
= NULL_TREE
;
15803 unsigned HOST_WIDE_INT cnt
;
15804 constructor_elt
*ce
;
15806 if (int_size_in_bytes (type
) != size
)
15809 if (TREE_CODE (type
) == RECORD_TYPE
)
15810 field
= TYPE_FIELDS (type
);
15812 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15814 tree val
= ce
->value
;
15815 int pos
, fieldsize
;
15817 if (ce
->index
!= 0)
15823 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15826 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15827 && TYPE_DOMAIN (TREE_TYPE (field
))
15828 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15830 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15831 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
15833 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
15834 pos
= int_byte_position (field
);
15835 gcc_assert (pos
+ fieldsize
<= size
);
15837 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15843 case VIEW_CONVERT_EXPR
:
15844 case NON_LVALUE_EXPR
:
15845 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15847 return native_encode_expr (init
, array
, size
) == size
;
15851 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15852 attribute is the const value T. */
15855 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15858 tree type
= TREE_TYPE (t
);
15861 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15865 gcc_assert (!DECL_P (init
));
15867 rtl
= rtl_for_decl_init (init
, type
);
15869 return add_const_value_attribute (die
, rtl
);
15870 /* If the host and target are sane, try harder. */
15871 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15872 && initializer_constant_valid_p (init
, type
))
15874 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15875 if (size
> 0 && (int) size
== size
)
15877 unsigned char *array
= (unsigned char *)
15878 ggc_alloc_cleared_atomic (size
);
15880 if (native_encode_initializer (init
, array
, size
))
15882 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15891 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15892 attribute is the const value of T, where T is an integral constant
15893 variable with static storage duration
15894 (so it can't be a PARM_DECL or a RESULT_DECL). */
15897 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15901 || (TREE_CODE (decl
) != VAR_DECL
15902 && TREE_CODE (decl
) != CONST_DECL
)
15903 || (TREE_CODE (decl
) == VAR_DECL
15904 && !TREE_STATIC (decl
)))
15907 if (TREE_READONLY (decl
)
15908 && ! TREE_THIS_VOLATILE (decl
)
15909 && DECL_INITIAL (decl
))
15914 /* Don't add DW_AT_const_value if abstract origin already has one. */
15915 if (get_AT (var_die
, DW_AT_const_value
))
15918 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15921 /* Convert the CFI instructions for the current function into a
15922 location list. This is used for DW_AT_frame_base when we targeting
15923 a dwarf2 consumer that does not support the dwarf3
15924 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15927 static dw_loc_list_ref
15928 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15932 dw_loc_list_ref list
, *list_tail
;
15934 dw_cfa_location last_cfa
, next_cfa
;
15935 const char *start_label
, *last_label
, *section
;
15936 dw_cfa_location remember
;
15939 gcc_assert (fde
!= NULL
);
15941 section
= secname_for_decl (current_function_decl
);
15945 memset (&next_cfa
, 0, sizeof (next_cfa
));
15946 next_cfa
.reg
= INVALID_REGNUM
;
15947 remember
= next_cfa
;
15949 start_label
= fde
->dw_fde_begin
;
15951 /* ??? Bald assumption that the CIE opcode list does not contain
15952 advance opcodes. */
15953 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15954 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15956 last_cfa
= next_cfa
;
15957 last_label
= start_label
;
15959 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15961 /* If the first partition contained no CFI adjustments, the
15962 CIE opcodes apply to the whole first partition. */
15963 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15964 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15965 list_tail
=&(*list_tail
)->dw_loc_next
;
15966 start_label
= last_label
= fde
->dw_fde_second_begin
;
15969 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15971 switch (cfi
->dw_cfi_opc
)
15973 case DW_CFA_set_loc
:
15974 case DW_CFA_advance_loc1
:
15975 case DW_CFA_advance_loc2
:
15976 case DW_CFA_advance_loc4
:
15977 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15979 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15980 start_label
, last_label
, section
);
15982 list_tail
= &(*list_tail
)->dw_loc_next
;
15983 last_cfa
= next_cfa
;
15984 start_label
= last_label
;
15986 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15989 case DW_CFA_advance_loc
:
15990 /* The encoding is complex enough that we should never emit this. */
15991 gcc_unreachable ();
15994 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15997 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15999 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16001 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16002 start_label
, last_label
, section
);
16004 list_tail
= &(*list_tail
)->dw_loc_next
;
16005 last_cfa
= next_cfa
;
16006 start_label
= last_label
;
16008 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16009 start_label
, fde
->dw_fde_end
, section
);
16010 list_tail
= &(*list_tail
)->dw_loc_next
;
16011 start_label
= last_label
= fde
->dw_fde_second_begin
;
16015 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16017 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16018 start_label
, last_label
, section
);
16019 list_tail
= &(*list_tail
)->dw_loc_next
;
16020 start_label
= last_label
;
16023 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16025 fde
->dw_fde_second_begin
16026 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16029 if (list
&& list
->dw_loc_next
)
16035 /* Compute a displacement from the "steady-state frame pointer" to the
16036 frame base (often the same as the CFA), and store it in
16037 frame_pointer_fb_offset. OFFSET is added to the displacement
16038 before the latter is negated. */
16041 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16045 #ifdef FRAME_POINTER_CFA_OFFSET
16046 reg
= frame_pointer_rtx
;
16047 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16049 reg
= arg_pointer_rtx
;
16050 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16053 elim
= (ira_use_lra_p
16054 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16055 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16056 if (GET_CODE (elim
) == PLUS
)
16058 offset
+= INTVAL (XEXP (elim
, 1));
16059 elim
= XEXP (elim
, 0);
16062 frame_pointer_fb_offset
= -offset
;
16064 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16065 in which to eliminate. This is because it's stack pointer isn't
16066 directly accessible as a register within the ISA. To work around
16067 this, assume that while we cannot provide a proper value for
16068 frame_pointer_fb_offset, we won't need one either. */
16069 frame_pointer_fb_offset_valid
16070 = ((SUPPORTS_STACK_ALIGNMENT
16071 && (elim
== hard_frame_pointer_rtx
16072 || elim
== stack_pointer_rtx
))
16073 || elim
== (frame_pointer_needed
16074 ? hard_frame_pointer_rtx
16075 : stack_pointer_rtx
));
16078 /* Generate a DW_AT_name attribute given some string value to be included as
16079 the value of the attribute. */
16082 add_name_attribute (dw_die_ref die
, const char *name_string
)
16084 if (name_string
!= NULL
&& *name_string
!= 0)
16086 if (demangle_name_func
)
16087 name_string
= (*demangle_name_func
) (name_string
);
16089 add_AT_string (die
, DW_AT_name
, name_string
);
16093 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16094 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16095 of TYPE accordingly.
16097 ??? This is a temporary measure until after we're able to generate
16098 regular DWARF for the complex Ada type system. */
16101 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16102 dw_die_ref context_die
)
16105 dw_die_ref dtype_die
;
16107 if (!lang_hooks
.types
.descriptive_type
)
16110 dtype
= lang_hooks
.types
.descriptive_type (type
);
16114 dtype_die
= lookup_type_die (dtype
);
16117 gen_type_die (dtype
, context_die
);
16118 dtype_die
= lookup_type_die (dtype
);
16119 gcc_assert (dtype_die
);
16122 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16125 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16127 static const char *
16128 comp_dir_string (void)
16132 static const char *cached_wd
= NULL
;
16134 if (cached_wd
!= NULL
)
16137 wd
= get_src_pwd ();
16141 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16145 wdlen
= strlen (wd
);
16146 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16148 wd1
[wdlen
] = DIR_SEPARATOR
;
16149 wd1
[wdlen
+ 1] = 0;
16153 cached_wd
= remap_debug_filename (wd
);
16157 /* Generate a DW_AT_comp_dir attribute for DIE. */
16160 add_comp_dir_attribute (dw_die_ref die
)
16162 const char * wd
= comp_dir_string ();
16164 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16167 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16171 lower_bound_default (void)
16173 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16178 case DW_LANG_C_plus_plus
:
16180 case DW_LANG_ObjC_plus_plus
:
16183 case DW_LANG_Fortran77
:
16184 case DW_LANG_Fortran90
:
16185 case DW_LANG_Fortran95
:
16189 case DW_LANG_Python
:
16190 return dwarf_version
>= 4 ? 0 : -1;
16191 case DW_LANG_Ada95
:
16192 case DW_LANG_Ada83
:
16193 case DW_LANG_Cobol74
:
16194 case DW_LANG_Cobol85
:
16195 case DW_LANG_Pascal83
:
16196 case DW_LANG_Modula2
:
16198 return dwarf_version
>= 4 ? 1 : -1;
16204 /* Given a tree node describing an array bound (either lower or upper) output
16205 a representation for that bound. */
16208 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16210 switch (TREE_CODE (bound
))
16215 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16218 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16221 /* Use the default if possible. */
16222 if (bound_attr
== DW_AT_lower_bound
16223 && tree_fits_shwi_p (bound
)
16224 && (dflt
= lower_bound_default ()) != -1
16225 && tree_to_shwi (bound
) == dflt
)
16228 /* If HOST_WIDE_INT is big enough then represent the bound as
16229 a constant value. We need to choose a form based on
16230 whether the type is signed or unsigned. We cannot just
16231 call add_AT_unsigned if the value itself is positive
16232 (add_AT_unsigned might add the unsigned value encoded as
16233 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16234 bounds type and then sign extend any unsigned values found
16235 for signed types. This is needed only for
16236 DW_AT_{lower,upper}_bound, since for most other attributes,
16237 consumers will treat DW_FORM_data[1248] as unsigned values,
16238 regardless of the underlying type. */
16239 else if (prec
<= HOST_BITS_PER_WIDE_INT
16240 || TREE_INT_CST_HIGH (bound
) == 0)
16242 if (TYPE_UNSIGNED (TREE_TYPE (bound
)))
16243 add_AT_unsigned (subrange_die
, bound_attr
,
16244 TREE_INT_CST_LOW (bound
));
16246 add_AT_int (subrange_die
, bound_attr
, TREE_INT_CST_LOW (bound
));
16249 /* Otherwise represent the bound as an unsigned value with
16250 the precision of its type. The precision and signedness
16251 of the type will be necessary to re-interpret it
16253 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16254 TREE_INT_CST_LOW (bound
));
16259 case VIEW_CONVERT_EXPR
:
16260 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16270 dw_die_ref decl_die
= lookup_decl_die (bound
);
16272 /* ??? Can this happen, or should the variable have been bound
16273 first? Probably it can, since I imagine that we try to create
16274 the types of parameters in the order in which they exist in
16275 the list, and won't have created a forward reference to a
16276 later parameter. */
16277 if (decl_die
!= NULL
)
16279 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16287 /* Otherwise try to create a stack operation procedure to
16288 evaluate the value of the array bound. */
16290 dw_die_ref ctx
, decl_die
;
16291 dw_loc_list_ref list
;
16293 list
= loc_list_from_tree (bound
, 2);
16294 if (list
== NULL
|| single_element_loc_list_p (list
))
16296 /* If DW_AT_*bound is not a reference nor constant, it is
16297 a DWARF expression rather than location description.
16298 For that loc_list_from_tree (bound, 0) is needed.
16299 If that fails to give a single element list,
16300 fall back to outputting this as a reference anyway. */
16301 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16302 if (list2
&& single_element_loc_list_p (list2
))
16304 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16311 if (current_function_decl
== 0)
16312 ctx
= comp_unit_die ();
16314 ctx
= lookup_decl_die (current_function_decl
);
16316 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16317 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16318 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16319 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16320 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16326 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16327 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16328 Note that the block of subscript information for an array type also
16329 includes information about the element type of the given array type. */
16332 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16334 unsigned dimension_number
;
16336 dw_die_ref subrange_die
;
16338 for (dimension_number
= 0;
16339 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16340 type
= TREE_TYPE (type
), dimension_number
++)
16342 tree domain
= TYPE_DOMAIN (type
);
16344 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16347 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16348 and (in GNU C only) variable bounds. Handle all three forms
16350 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16353 /* We have an array type with specified bounds. */
16354 lower
= TYPE_MIN_VALUE (domain
);
16355 upper
= TYPE_MAX_VALUE (domain
);
16357 /* Define the index type. */
16358 if (TREE_TYPE (domain
))
16360 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16361 TREE_TYPE field. We can't emit debug info for this
16362 because it is an unnamed integral type. */
16363 if (TREE_CODE (domain
) == INTEGER_TYPE
16364 && TYPE_NAME (domain
) == NULL_TREE
16365 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16366 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16369 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16373 /* ??? If upper is NULL, the array has unspecified length,
16374 but it does have a lower bound. This happens with Fortran
16376 Since the debugger is definitely going to need to know N
16377 to produce useful results, go ahead and output the lower
16378 bound solo, and hope the debugger can cope. */
16380 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16382 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16385 /* Otherwise we have an array type with an unspecified length. The
16386 DWARF-2 spec does not say how to handle this; let's just leave out the
16391 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16394 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16396 dw_die_ref decl_die
;
16397 HOST_WIDE_INT size
;
16399 switch (TREE_CODE (tree_node
))
16404 case ENUMERAL_TYPE
:
16407 case QUAL_UNION_TYPE
:
16408 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16409 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16411 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16414 size
= int_size_in_bytes (tree_node
);
16417 /* For a data member of a struct or union, the DW_AT_byte_size is
16418 generally given as the number of bytes normally allocated for an
16419 object of the *declared* type of the member itself. This is true
16420 even for bit-fields. */
16421 size
= int_size_in_bytes (field_type (tree_node
));
16424 gcc_unreachable ();
16427 /* Note that `size' might be -1 when we get to this point. If it is, that
16428 indicates that the byte size of the entity in question is variable. We
16429 have no good way of expressing this fact in Dwarf at the present time,
16430 when location description was not used by the caller code instead. */
16432 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16435 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16436 which specifies the distance in bits from the highest order bit of the
16437 "containing object" for the bit-field to the highest order bit of the
16440 For any given bit-field, the "containing object" is a hypothetical object
16441 (of some integral or enum type) within which the given bit-field lives. The
16442 type of this hypothetical "containing object" is always the same as the
16443 declared type of the individual bit-field itself. The determination of the
16444 exact location of the "containing object" for a bit-field is rather
16445 complicated. It's handled by the `field_byte_offset' function (above).
16447 Note that it is the size (in bytes) of the hypothetical "containing object"
16448 which will be given in the DW_AT_byte_size attribute for this bit-field.
16449 (See `byte_size_attribute' above). */
16452 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16454 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16455 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16456 HOST_WIDE_INT bitpos_int
;
16457 HOST_WIDE_INT highest_order_object_bit_offset
;
16458 HOST_WIDE_INT highest_order_field_bit_offset
;
16459 HOST_WIDE_INT bit_offset
;
16461 /* Must be a field and a bit field. */
16462 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16464 /* We can't yet handle bit-fields whose offsets are variable, so if we
16465 encounter such things, just return without generating any attribute
16466 whatsoever. Likewise for variable or too large size. */
16467 if (! tree_fits_shwi_p (bit_position (decl
))
16468 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
16471 bitpos_int
= int_bit_position (decl
);
16473 /* Note that the bit offset is always the distance (in bits) from the
16474 highest-order bit of the "containing object" to the highest-order bit of
16475 the bit-field itself. Since the "high-order end" of any object or field
16476 is different on big-endian and little-endian machines, the computation
16477 below must take account of these differences. */
16478 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16479 highest_order_field_bit_offset
= bitpos_int
;
16481 if (! BYTES_BIG_ENDIAN
)
16483 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
16484 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16488 = (! BYTES_BIG_ENDIAN
16489 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16490 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16492 if (bit_offset
< 0)
16493 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16495 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16498 /* For a FIELD_DECL node which represents a bit field, output an attribute
16499 which specifies the length in bits of the given field. */
16502 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16504 /* Must be a field and a bit field. */
16505 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16506 && DECL_BIT_FIELD_TYPE (decl
));
16508 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
16509 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
16512 /* If the compiled language is ANSI C, then add a 'prototyped'
16513 attribute, if arg types are given for the parameters of a function. */
16516 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16518 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16519 && prototype_p (func_type
))
16520 add_AT_flag (die
, DW_AT_prototyped
, 1);
16523 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16524 by looking in either the type declaration or object declaration
16527 static inline dw_die_ref
16528 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16530 dw_die_ref origin_die
= NULL
;
16532 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16534 /* We may have gotten separated from the block for the inlined
16535 function, if we're in an exception handler or some such; make
16536 sure that the abstract function has been written out.
16538 Doing this for nested functions is wrong, however; functions are
16539 distinct units, and our context might not even be inline. */
16543 fn
= TYPE_STUB_DECL (fn
);
16545 fn
= decl_function_context (fn
);
16547 dwarf2out_abstract_function (fn
);
16550 if (DECL_P (origin
))
16551 origin_die
= lookup_decl_die (origin
);
16552 else if (TYPE_P (origin
))
16553 origin_die
= lookup_type_die (origin
);
16555 /* XXX: Functions that are never lowered don't always have correct block
16556 trees (in the case of java, they simply have no block tree, in some other
16557 languages). For these functions, there is nothing we can really do to
16558 output correct debug info for inlined functions in all cases. Rather
16559 than die, we'll just produce deficient debug info now, in that we will
16560 have variables without a proper abstract origin. In the future, when all
16561 functions are lowered, we should re-add a gcc_assert (origin_die)
16565 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16569 /* We do not currently support the pure_virtual attribute. */
16572 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16574 if (DECL_VINDEX (func_decl
))
16576 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16578 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
16579 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16580 new_loc_descr (DW_OP_constu
,
16581 tree_to_shwi (DECL_VINDEX (func_decl
)),
16584 /* GNU extension: Record what type this method came from originally. */
16585 if (debug_info_level
> DINFO_LEVEL_TERSE
16586 && DECL_CONTEXT (func_decl
))
16587 add_AT_die_ref (die
, DW_AT_containing_type
,
16588 lookup_type_die (DECL_CONTEXT (func_decl
)));
16592 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16593 given decl. This used to be a vendor extension until after DWARF 4
16594 standardized it. */
16597 add_linkage_attr (dw_die_ref die
, tree decl
)
16599 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16601 /* Mimic what assemble_name_raw does with a leading '*'. */
16602 if (name
[0] == '*')
16605 if (dwarf_version
>= 4)
16606 add_AT_string (die
, DW_AT_linkage_name
, name
);
16608 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16611 /* Add source coordinate attributes for the given decl. */
16614 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16616 expanded_location s
;
16618 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16620 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16621 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16622 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16625 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16628 add_linkage_name (dw_die_ref die
, tree decl
)
16630 if (debug_info_level
> DINFO_LEVEL_TERSE
16631 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16632 && TREE_PUBLIC (decl
)
16633 && !DECL_ABSTRACT (decl
)
16634 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16635 && die
->die_tag
!= DW_TAG_member
)
16637 /* Defer until we have an assembler name set. */
16638 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16640 limbo_die_node
*asm_name
;
16642 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16643 asm_name
->die
= die
;
16644 asm_name
->created_for
= decl
;
16645 asm_name
->next
= deferred_asm_name
;
16646 deferred_asm_name
= asm_name
;
16648 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16649 add_linkage_attr (die
, decl
);
16653 /* Add a DW_AT_name attribute and source coordinate attribute for the
16654 given decl, but only if it actually has a name. */
16657 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16661 decl_name
= DECL_NAME (decl
);
16662 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16664 const char *name
= dwarf2_name (decl
, 0);
16666 add_name_attribute (die
, name
);
16667 if (! DECL_ARTIFICIAL (decl
))
16668 add_src_coords_attributes (die
, decl
);
16670 add_linkage_name (die
, decl
);
16673 #ifdef VMS_DEBUGGING_INFO
16674 /* Get the function's name, as described by its RTL. This may be different
16675 from the DECL_NAME name used in the source file. */
16676 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16678 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16679 XEXP (DECL_RTL (decl
), 0), false);
16680 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16682 #endif /* VMS_DEBUGGING_INFO */
16685 #ifdef VMS_DEBUGGING_INFO
16686 /* Output the debug main pointer die for VMS */
16689 dwarf2out_vms_debug_main_pointer (void)
16691 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16694 /* Allocate the VMS debug main subprogram die. */
16695 die
= ggc_alloc_cleared_die_node ();
16696 die
->die_tag
= DW_TAG_subprogram
;
16697 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16698 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16699 current_function_funcdef_no
);
16700 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16702 /* Make it the first child of comp_unit_die (). */
16703 die
->die_parent
= comp_unit_die ();
16704 if (comp_unit_die ()->die_child
)
16706 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16707 comp_unit_die ()->die_child
->die_sib
= die
;
16711 die
->die_sib
= die
;
16712 comp_unit_die ()->die_child
= die
;
16715 #endif /* VMS_DEBUGGING_INFO */
16717 /* Push a new declaration scope. */
16720 push_decl_scope (tree scope
)
16722 vec_safe_push (decl_scope_table
, scope
);
16725 /* Pop a declaration scope. */
16728 pop_decl_scope (void)
16730 decl_scope_table
->pop ();
16733 /* walk_tree helper function for uses_local_type, below. */
16736 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16739 *walk_subtrees
= 0;
16742 tree name
= TYPE_NAME (*tp
);
16743 if (name
&& DECL_P (name
) && decl_function_context (name
))
16749 /* If TYPE involves a function-local type (including a local typedef to a
16750 non-local type), returns that type; otherwise returns NULL_TREE. */
16753 uses_local_type (tree type
)
16755 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16759 /* Return the DIE for the scope that immediately contains this type.
16760 Non-named types that do not involve a function-local type get global
16761 scope. Named types nested in namespaces or other types get their
16762 containing scope. All other types (i.e. function-local named types) get
16763 the current active scope. */
16766 scope_die_for (tree t
, dw_die_ref context_die
)
16768 dw_die_ref scope_die
= NULL
;
16769 tree containing_scope
;
16771 /* Non-types always go in the current scope. */
16772 gcc_assert (TYPE_P (t
));
16774 /* Use the scope of the typedef, rather than the scope of the type
16776 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16777 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16779 containing_scope
= TYPE_CONTEXT (t
);
16781 /* Use the containing namespace if there is one. */
16782 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16784 if (context_die
== lookup_decl_die (containing_scope
))
16786 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16787 context_die
= get_context_die (containing_scope
);
16789 containing_scope
= NULL_TREE
;
16792 /* Ignore function type "scopes" from the C frontend. They mean that
16793 a tagged type is local to a parmlist of a function declarator, but
16794 that isn't useful to DWARF. */
16795 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16796 containing_scope
= NULL_TREE
;
16798 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16800 /* If T uses a local type keep it local as well, to avoid references
16801 to function-local DIEs from outside the function. */
16802 if (current_function_decl
&& uses_local_type (t
))
16803 scope_die
= context_die
;
16805 scope_die
= comp_unit_die ();
16807 else if (TYPE_P (containing_scope
))
16809 /* For types, we can just look up the appropriate DIE. */
16810 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16811 scope_die
= get_context_die (containing_scope
);
16814 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16815 if (scope_die
== NULL
)
16816 scope_die
= comp_unit_die ();
16820 scope_die
= context_die
;
16825 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16828 local_scope_p (dw_die_ref context_die
)
16830 for (; context_die
; context_die
= context_die
->die_parent
)
16831 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16832 || context_die
->die_tag
== DW_TAG_subprogram
)
16838 /* Returns nonzero if CONTEXT_DIE is a class. */
16841 class_scope_p (dw_die_ref context_die
)
16843 return (context_die
16844 && (context_die
->die_tag
== DW_TAG_structure_type
16845 || context_die
->die_tag
== DW_TAG_class_type
16846 || context_die
->die_tag
== DW_TAG_interface_type
16847 || context_die
->die_tag
== DW_TAG_union_type
));
16850 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16851 whether or not to treat a DIE in this context as a declaration. */
16854 class_or_namespace_scope_p (dw_die_ref context_die
)
16856 return (class_scope_p (context_die
)
16857 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16860 /* Many forms of DIEs require a "type description" attribute. This
16861 routine locates the proper "type descriptor" die for the type given
16862 by 'type', and adds a DW_AT_type attribute below the given die. */
16865 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16866 int decl_volatile
, dw_die_ref context_die
)
16868 enum tree_code code
= TREE_CODE (type
);
16869 dw_die_ref type_die
= NULL
;
16871 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16872 or fixed-point type, use the inner type. This is because we have no
16873 support for unnamed types in base_type_die. This can happen if this is
16874 an Ada subrange type. Correct solution is emit a subrange type die. */
16875 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16876 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16877 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16879 if (code
== ERROR_MARK
16880 /* Handle a special case. For functions whose return type is void, we
16881 generate *no* type attribute. (Note that no object may have type
16882 `void', so this only applies to function return types). */
16883 || code
== VOID_TYPE
)
16886 type_die
= modified_type_die (type
,
16887 decl_const
|| TYPE_READONLY (type
),
16888 decl_volatile
|| TYPE_VOLATILE (type
),
16891 if (type_die
!= NULL
)
16892 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16895 /* Given an object die, add the calling convention attribute for the
16896 function call type. */
16898 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16900 enum dwarf_calling_convention value
= DW_CC_normal
;
16902 value
= ((enum dwarf_calling_convention
)
16903 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16906 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16908 /* DWARF 2 doesn't provide a way to identify a program's source-level
16909 entry point. DW_AT_calling_convention attributes are only meant
16910 to describe functions' calling conventions. However, lacking a
16911 better way to signal the Fortran main program, we used this for
16912 a long time, following existing custom. Now, DWARF 4 has
16913 DW_AT_main_subprogram, which we add below, but some tools still
16914 rely on the old way, which we thus keep. */
16915 value
= DW_CC_program
;
16917 if (dwarf_version
>= 4 || !dwarf_strict
)
16918 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16921 /* Only add the attribute if the backend requests it, and
16922 is not DW_CC_normal. */
16923 if (value
&& (value
!= DW_CC_normal
))
16924 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16927 /* Given a tree pointer to a struct, class, union, or enum type node, return
16928 a pointer to the (string) tag name for the given type, or zero if the type
16929 was declared without a tag. */
16931 static const char *
16932 type_tag (const_tree type
)
16934 const char *name
= 0;
16936 if (TYPE_NAME (type
) != 0)
16940 /* Find the IDENTIFIER_NODE for the type name. */
16941 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16942 && !TYPE_NAMELESS (type
))
16943 t
= TYPE_NAME (type
);
16945 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16946 a TYPE_DECL node, regardless of whether or not a `typedef' was
16948 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16949 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16951 /* We want to be extra verbose. Don't call dwarf_name if
16952 DECL_NAME isn't set. The default hook for decl_printable_name
16953 doesn't like that, and in this context it's correct to return
16954 0, instead of "<anonymous>" or the like. */
16955 if (DECL_NAME (TYPE_NAME (type
))
16956 && !DECL_NAMELESS (TYPE_NAME (type
)))
16957 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16960 /* Now get the name as a string, or invent one. */
16961 if (!name
&& t
!= 0)
16962 name
= IDENTIFIER_POINTER (t
);
16965 return (name
== 0 || *name
== '\0') ? 0 : name
;
16968 /* Return the type associated with a data member, make a special check
16969 for bit field types. */
16972 member_declared_type (const_tree member
)
16974 return (DECL_BIT_FIELD_TYPE (member
)
16975 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16978 /* Get the decl's label, as described by its RTL. This may be different
16979 from the DECL_NAME name used in the source file. */
16982 static const char *
16983 decl_start_label (tree decl
)
16986 const char *fnname
;
16988 x
= DECL_RTL (decl
);
16989 gcc_assert (MEM_P (x
));
16992 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16994 fnname
= XSTR (x
, 0);
16999 /* These routines generate the internal representation of the DIE's for
17000 the compilation unit. Debugging information is collected by walking
17001 the declaration trees passed in from dwarf2out_decl(). */
17004 gen_array_type_die (tree type
, dw_die_ref context_die
)
17006 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17007 dw_die_ref array_die
;
17009 /* GNU compilers represent multidimensional array types as sequences of one
17010 dimensional array types whose element types are themselves array types.
17011 We sometimes squish that down to a single array_type DIE with multiple
17012 subscripts in the Dwarf debugging info. The draft Dwarf specification
17013 say that we are allowed to do this kind of compression in C, because
17014 there is no difference between an array of arrays and a multidimensional
17015 array. We don't do this for Ada to remain as close as possible to the
17016 actual representation, which is especially important against the language
17017 flexibilty wrt arrays of variable size. */
17019 bool collapse_nested_arrays
= !is_ada ();
17022 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17023 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17024 if (TYPE_STRING_FLAG (type
)
17025 && TREE_CODE (type
) == ARRAY_TYPE
17027 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17029 HOST_WIDE_INT size
;
17031 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17032 add_name_attribute (array_die
, type_tag (type
));
17033 equate_type_number_to_die (type
, array_die
);
17034 size
= int_size_in_bytes (type
);
17036 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17037 else if (TYPE_DOMAIN (type
) != NULL_TREE
17038 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17039 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17041 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17042 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
17044 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17045 if (loc
&& size
> 0)
17047 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17048 if (size
!= DWARF2_ADDR_SIZE
)
17049 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17055 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17056 add_name_attribute (array_die
, type_tag (type
));
17057 equate_type_number_to_die (type
, array_die
);
17059 if (TREE_CODE (type
) == VECTOR_TYPE
)
17060 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17062 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17064 && TREE_CODE (type
) == ARRAY_TYPE
17065 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17066 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17067 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17070 /* We default the array ordering. SDB will probably do
17071 the right things even if DW_AT_ordering is not present. It's not even
17072 an issue until we start to get into multidimensional arrays anyway. If
17073 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17074 then we'll have to put the DW_AT_ordering attribute back in. (But if
17075 and when we find out that we need to put these in, we will only do so
17076 for multidimensional arrays. */
17077 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17080 if (TREE_CODE (type
) == VECTOR_TYPE
)
17082 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17083 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17084 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17085 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17086 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17089 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17091 /* Add representation of the type of the elements of this array type and
17092 emit the corresponding DIE if we haven't done it already. */
17093 element_type
= TREE_TYPE (type
);
17094 if (collapse_nested_arrays
)
17095 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17097 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17099 element_type
= TREE_TYPE (element_type
);
17102 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17104 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17105 if (TYPE_ARTIFICIAL (type
))
17106 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17108 if (get_AT (array_die
, DW_AT_name
))
17109 add_pubtype (type
, array_die
);
17112 static dw_loc_descr_ref
17113 descr_info_loc (tree val
, tree base_decl
)
17115 HOST_WIDE_INT size
;
17116 dw_loc_descr_ref loc
, loc2
;
17117 enum dwarf_location_atom op
;
17119 if (val
== base_decl
)
17120 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17122 switch (TREE_CODE (val
))
17125 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17127 return loc_descriptor_from_tree (val
, 0);
17129 if (tree_fits_shwi_p (val
))
17130 return int_loc_descriptor (tree_to_shwi (val
));
17133 size
= int_size_in_bytes (TREE_TYPE (val
));
17136 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17139 if (size
== DWARF2_ADDR_SIZE
)
17140 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17142 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17144 case POINTER_PLUS_EXPR
:
17146 if (tree_fits_uhwi_p (TREE_OPERAND (val
, 1))
17147 && tree_to_uhwi (TREE_OPERAND (val
, 1)) < 16384)
17149 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17152 loc_descr_plus_const (&loc
, tree_to_shwi (TREE_OPERAND (val
, 1)));
17158 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17161 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17164 add_loc_descr (&loc
, loc2
);
17165 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17187 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17188 tree val
, tree base_decl
)
17190 dw_loc_descr_ref loc
;
17192 if (tree_fits_shwi_p (val
))
17194 add_AT_unsigned (die
, attr
, tree_to_shwi (val
));
17198 loc
= descr_info_loc (val
, base_decl
);
17202 add_AT_loc (die
, attr
, loc
);
17205 /* This routine generates DIE for array with hidden descriptor, details
17206 are filled into *info by a langhook. */
17209 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17210 dw_die_ref context_die
)
17212 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17213 dw_die_ref array_die
;
17216 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17217 add_name_attribute (array_die
, type_tag (type
));
17218 equate_type_number_to_die (type
, array_die
);
17220 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17222 && info
->ndimensions
>= 2)
17223 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17225 if (info
->data_location
)
17226 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17228 if (info
->associated
)
17229 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17231 if (info
->allocated
)
17232 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17235 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17237 dw_die_ref subrange_die
17238 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17240 if (info
->dimen
[dim
].lower_bound
)
17242 /* If it is the default value, omit it. */
17245 if (tree_fits_shwi_p (info
->dimen
[dim
].lower_bound
)
17246 && (dflt
= lower_bound_default ()) != -1
17247 && tree_to_shwi (info
->dimen
[dim
].lower_bound
) == dflt
)
17250 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17251 info
->dimen
[dim
].lower_bound
,
17254 if (info
->dimen
[dim
].upper_bound
)
17255 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17256 info
->dimen
[dim
].upper_bound
,
17258 if (info
->dimen
[dim
].stride
)
17259 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17260 info
->dimen
[dim
].stride
,
17264 gen_type_die (info
->element_type
, context_die
);
17265 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17267 if (get_AT (array_die
, DW_AT_name
))
17268 add_pubtype (type
, array_die
);
17273 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17275 tree origin
= decl_ultimate_origin (decl
);
17276 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17278 if (origin
!= NULL
)
17279 add_abstract_origin_attribute (decl_die
, origin
);
17282 add_name_and_src_coords_attributes (decl_die
, decl
);
17283 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17284 0, 0, context_die
);
17287 if (DECL_ABSTRACT (decl
))
17288 equate_decl_number_to_die (decl
, decl_die
);
17290 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17294 /* Walk through the list of incomplete types again, trying once more to
17295 emit full debugging info for them. */
17298 retry_incomplete_types (void)
17302 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17303 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17304 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17307 /* Determine what tag to use for a record type. */
17309 static enum dwarf_tag
17310 record_type_tag (tree type
)
17312 if (! lang_hooks
.types
.classify_record
)
17313 return DW_TAG_structure_type
;
17315 switch (lang_hooks
.types
.classify_record (type
))
17317 case RECORD_IS_STRUCT
:
17318 return DW_TAG_structure_type
;
17320 case RECORD_IS_CLASS
:
17321 return DW_TAG_class_type
;
17323 case RECORD_IS_INTERFACE
:
17324 if (dwarf_version
>= 3 || !dwarf_strict
)
17325 return DW_TAG_interface_type
;
17326 return DW_TAG_structure_type
;
17329 gcc_unreachable ();
17333 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17334 include all of the information about the enumeration values also. Each
17335 enumerated type name/value is listed as a child of the enumerated type
17339 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17341 dw_die_ref type_die
= lookup_type_die (type
);
17343 if (type_die
== NULL
)
17345 type_die
= new_die (DW_TAG_enumeration_type
,
17346 scope_die_for (type
, context_die
), type
);
17347 equate_type_number_to_die (type
, type_die
);
17348 add_name_attribute (type_die
, type_tag (type
));
17349 if (dwarf_version
>= 4 || !dwarf_strict
)
17351 if (ENUM_IS_SCOPED (type
))
17352 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17353 if (ENUM_IS_OPAQUE (type
))
17354 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17357 else if (! TYPE_SIZE (type
))
17360 remove_AT (type_die
, DW_AT_declaration
);
17362 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17363 given enum type is incomplete, do not generate the DW_AT_byte_size
17364 attribute or the DW_AT_element_list attribute. */
17365 if (TYPE_SIZE (type
))
17369 TREE_ASM_WRITTEN (type
) = 1;
17370 add_byte_size_attribute (type_die
, type
);
17371 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17373 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17374 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17377 /* If the first reference to this type was as the return type of an
17378 inline function, then it may not have a parent. Fix this now. */
17379 if (type_die
->die_parent
== NULL
)
17380 add_child_die (scope_die_for (type
, context_die
), type_die
);
17382 for (link
= TYPE_VALUES (type
);
17383 link
!= NULL
; link
= TREE_CHAIN (link
))
17385 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17386 tree value
= TREE_VALUE (link
);
17388 add_name_attribute (enum_die
,
17389 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17391 if (TREE_CODE (value
) == CONST_DECL
)
17392 value
= DECL_INITIAL (value
);
17394 if (simple_type_size_in_bits (TREE_TYPE (value
))
17395 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17397 /* For constant forms created by add_AT_unsigned DWARF
17398 consumers (GDB, elfutils, etc.) always zero extend
17399 the value. Only when the actual value is negative
17400 do we need to use add_AT_int to generate a constant
17401 form that can represent negative values. */
17402 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17403 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17404 add_AT_unsigned (enum_die
, DW_AT_const_value
,
17405 (unsigned HOST_WIDE_INT
) val
);
17407 add_AT_int (enum_die
, DW_AT_const_value
, val
);
17410 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17411 that here. TODO: This should be re-worked to use correct
17412 signed/unsigned double tags for all cases. */
17413 add_AT_double (enum_die
, DW_AT_const_value
,
17414 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17417 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17418 if (TYPE_ARTIFICIAL (type
))
17419 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17422 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17424 add_pubtype (type
, type_die
);
17429 /* Generate a DIE to represent either a real live formal parameter decl or to
17430 represent just the type of some formal parameter position in some function
17433 Note that this routine is a bit unusual because its argument may be a
17434 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17435 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17436 node. If it's the former then this function is being called to output a
17437 DIE to represent a formal parameter object (or some inlining thereof). If
17438 it's the latter, then this function is only being called to output a
17439 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17440 argument type of some subprogram type.
17441 If EMIT_NAME_P is true, name and source coordinate attributes
17445 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17446 dw_die_ref context_die
)
17448 tree node_or_origin
= node
? node
: origin
;
17449 tree ultimate_origin
;
17450 dw_die_ref parm_die
17451 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17453 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17455 case tcc_declaration
:
17456 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17457 if (node
|| ultimate_origin
)
17458 origin
= ultimate_origin
;
17459 if (origin
!= NULL
)
17460 add_abstract_origin_attribute (parm_die
, origin
);
17461 else if (emit_name_p
)
17462 add_name_and_src_coords_attributes (parm_die
, node
);
17464 || (! DECL_ABSTRACT (node_or_origin
)
17465 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17466 decl_function_context
17467 (node_or_origin
))))
17469 tree type
= TREE_TYPE (node_or_origin
);
17470 if (decl_by_reference_p (node_or_origin
))
17471 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17474 add_type_attribute (parm_die
, type
,
17475 TREE_READONLY (node_or_origin
),
17476 TREE_THIS_VOLATILE (node_or_origin
),
17479 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17480 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17482 if (node
&& node
!= origin
)
17483 equate_decl_number_to_die (node
, parm_die
);
17484 if (! DECL_ABSTRACT (node_or_origin
))
17485 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17486 node
== NULL
, DW_AT_location
);
17491 /* We were called with some kind of a ..._TYPE node. */
17492 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17496 gcc_unreachable ();
17502 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17503 children DW_TAG_formal_parameter DIEs representing the arguments of the
17506 PARM_PACK must be a function parameter pack.
17507 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17508 must point to the subsequent arguments of the function PACK_ARG belongs to.
17509 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17510 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17511 following the last one for which a DIE was generated. */
17514 gen_formal_parameter_pack_die (tree parm_pack
,
17516 dw_die_ref subr_die
,
17520 dw_die_ref parm_pack_die
;
17522 gcc_assert (parm_pack
17523 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17526 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17527 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17529 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17531 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17534 gen_formal_parameter_die (arg
, NULL
,
17535 false /* Don't emit name attribute. */,
17540 return parm_pack_die
;
17543 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17544 at the end of an (ANSI prototyped) formal parameters list. */
17547 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17549 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17552 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17553 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17554 parameters as specified in some function type specification (except for
17555 those which appear as part of a function *definition*). */
17558 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17561 tree formal_type
= NULL
;
17562 tree first_parm_type
;
17565 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17567 arg
= DECL_ARGUMENTS (function_or_method_type
);
17568 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17573 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17575 /* Make our first pass over the list of formal parameter types and output a
17576 DW_TAG_formal_parameter DIE for each one. */
17577 for (link
= first_parm_type
; link
; )
17579 dw_die_ref parm_die
;
17581 formal_type
= TREE_VALUE (link
);
17582 if (formal_type
== void_type_node
)
17585 /* Output a (nameless) DIE to represent the formal parameter itself. */
17586 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17587 true /* Emit name attribute. */,
17589 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17590 && link
== first_parm_type
)
17592 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17593 if (dwarf_version
>= 3 || !dwarf_strict
)
17594 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17596 else if (arg
&& DECL_ARTIFICIAL (arg
))
17597 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17599 link
= TREE_CHAIN (link
);
17601 arg
= DECL_CHAIN (arg
);
17604 /* If this function type has an ellipsis, add a
17605 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17606 if (formal_type
!= void_type_node
)
17607 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17609 /* Make our second (and final) pass over the list of formal parameter types
17610 and output DIEs to represent those types (as necessary). */
17611 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17612 link
&& TREE_VALUE (link
);
17613 link
= TREE_CHAIN (link
))
17614 gen_type_die (TREE_VALUE (link
), context_die
);
17617 /* We want to generate the DIE for TYPE so that we can generate the
17618 die for MEMBER, which has been defined; we will need to refer back
17619 to the member declaration nested within TYPE. If we're trying to
17620 generate minimal debug info for TYPE, processing TYPE won't do the
17621 trick; we need to attach the member declaration by hand. */
17624 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17626 gen_type_die (type
, context_die
);
17628 /* If we're trying to avoid duplicate debug info, we may not have
17629 emitted the member decl for this function. Emit it now. */
17630 if (TYPE_STUB_DECL (type
)
17631 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17632 && ! lookup_decl_die (member
))
17634 dw_die_ref type_die
;
17635 gcc_assert (!decl_ultimate_origin (member
));
17637 push_decl_scope (type
);
17638 type_die
= lookup_type_die_strip_naming_typedef (type
);
17639 if (TREE_CODE (member
) == FUNCTION_DECL
)
17640 gen_subprogram_die (member
, type_die
);
17641 else if (TREE_CODE (member
) == FIELD_DECL
)
17643 /* Ignore the nameless fields that are used to skip bits but handle
17644 C++ anonymous unions and structs. */
17645 if (DECL_NAME (member
) != NULL_TREE
17646 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17647 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17649 gen_type_die (member_declared_type (member
), type_die
);
17650 gen_field_die (member
, type_die
);
17654 gen_variable_die (member
, NULL_TREE
, type_die
);
17660 /* Forward declare these functions, because they are mutually recursive
17661 with their set_block_* pairing functions. */
17662 static void set_decl_origin_self (tree
);
17663 static void set_decl_abstract_flags (tree
, int);
17665 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17666 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17667 that it points to the node itself, thus indicating that the node is its
17668 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17669 the given node is NULL, recursively descend the decl/block tree which
17670 it is the root of, and for each other ..._DECL or BLOCK node contained
17671 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17672 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17673 values to point to themselves. */
17676 set_block_origin_self (tree stmt
)
17678 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17680 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17685 for (local_decl
= BLOCK_VARS (stmt
);
17686 local_decl
!= NULL_TREE
;
17687 local_decl
= DECL_CHAIN (local_decl
))
17688 if (! DECL_EXTERNAL (local_decl
))
17689 set_decl_origin_self (local_decl
); /* Potential recursion. */
17695 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17696 subblock
!= NULL_TREE
;
17697 subblock
= BLOCK_CHAIN (subblock
))
17698 set_block_origin_self (subblock
); /* Recurse. */
17703 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17704 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17705 node to so that it points to the node itself, thus indicating that the
17706 node represents its own (abstract) origin. Additionally, if the
17707 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17708 the decl/block tree of which the given node is the root of, and for
17709 each other ..._DECL or BLOCK node contained therein whose
17710 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17711 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17712 point to themselves. */
17715 set_decl_origin_self (tree decl
)
17717 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17719 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17720 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17724 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17725 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17726 if (DECL_INITIAL (decl
) != NULL_TREE
17727 && DECL_INITIAL (decl
) != error_mark_node
)
17728 set_block_origin_self (DECL_INITIAL (decl
));
17733 /* Given a pointer to some BLOCK node, and a boolean value to set the
17734 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17735 the given block, and for all local decls and all local sub-blocks
17736 (recursively) which are contained therein. */
17739 set_block_abstract_flags (tree stmt
, int setting
)
17745 BLOCK_ABSTRACT (stmt
) = setting
;
17747 for (local_decl
= BLOCK_VARS (stmt
);
17748 local_decl
!= NULL_TREE
;
17749 local_decl
= DECL_CHAIN (local_decl
))
17750 if (! DECL_EXTERNAL (local_decl
))
17751 set_decl_abstract_flags (local_decl
, setting
);
17753 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17755 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17756 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17757 || TREE_CODE (local_decl
) == PARM_DECL
)
17758 set_decl_abstract_flags (local_decl
, setting
);
17761 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17762 subblock
!= NULL_TREE
;
17763 subblock
= BLOCK_CHAIN (subblock
))
17764 set_block_abstract_flags (subblock
, setting
);
17767 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17768 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17769 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17770 set the abstract flags for all of the parameters, local vars, local
17771 blocks and sub-blocks (recursively) to the same setting. */
17774 set_decl_abstract_flags (tree decl
, int setting
)
17776 DECL_ABSTRACT (decl
) = setting
;
17777 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17781 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17782 DECL_ABSTRACT (arg
) = setting
;
17783 if (DECL_INITIAL (decl
) != NULL_TREE
17784 && DECL_INITIAL (decl
) != error_mark_node
)
17785 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17789 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17790 may later generate inlined and/or out-of-line instances of. */
17793 dwarf2out_abstract_function (tree decl
)
17795 dw_die_ref old_die
;
17799 htab_t old_decl_loc_table
;
17800 htab_t old_cached_dw_loc_list_table
;
17801 int old_call_site_count
, old_tail_call_site_count
;
17802 struct call_arg_loc_node
*old_call_arg_locations
;
17804 /* Make sure we have the actual abstract inline, not a clone. */
17805 decl
= DECL_ORIGIN (decl
);
17807 old_die
= lookup_decl_die (decl
);
17808 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17809 /* We've already generated the abstract instance. */
17812 /* We can be called while recursively when seeing block defining inlined subroutine
17813 DIE. Be sure to not clobber the outer location table nor use it or we would
17814 get locations in abstract instantces. */
17815 old_decl_loc_table
= decl_loc_table
;
17816 decl_loc_table
= NULL
;
17817 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17818 cached_dw_loc_list_table
= NULL
;
17819 old_call_arg_locations
= call_arg_locations
;
17820 call_arg_locations
= NULL
;
17821 old_call_site_count
= call_site_count
;
17822 call_site_count
= -1;
17823 old_tail_call_site_count
= tail_call_site_count
;
17824 tail_call_site_count
= -1;
17826 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17827 we don't get confused by DECL_ABSTRACT. */
17828 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17830 context
= decl_class_context (decl
);
17832 gen_type_die_for_member
17833 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17836 /* Pretend we've just finished compiling this function. */
17837 save_fn
= current_function_decl
;
17838 current_function_decl
= decl
;
17840 was_abstract
= DECL_ABSTRACT (decl
);
17841 set_decl_abstract_flags (decl
, 1);
17842 dwarf2out_decl (decl
);
17843 if (! was_abstract
)
17844 set_decl_abstract_flags (decl
, 0);
17846 current_function_decl
= save_fn
;
17847 decl_loc_table
= old_decl_loc_table
;
17848 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17849 call_arg_locations
= old_call_arg_locations
;
17850 call_site_count
= old_call_site_count
;
17851 tail_call_site_count
= old_tail_call_site_count
;
17854 /* Helper function of premark_used_types() which gets called through
17857 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17858 marked as unused by prune_unused_types. */
17861 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17866 type
= (tree
) *slot
;
17867 die
= lookup_type_die (type
);
17869 die
->die_perennial_p
= 1;
17873 /* Helper function of premark_types_used_by_global_vars which gets called
17874 through htab_traverse.
17876 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17877 marked as unused by prune_unused_types. The DIE of the type is marked
17878 only if the global variable using the type will actually be emitted. */
17881 premark_types_used_by_global_vars_helper (void **slot
,
17882 void *data ATTRIBUTE_UNUSED
)
17884 struct types_used_by_vars_entry
*entry
;
17887 entry
= (struct types_used_by_vars_entry
*) *slot
;
17888 gcc_assert (entry
->type
!= NULL
17889 && entry
->var_decl
!= NULL
);
17890 die
= lookup_type_die (entry
->type
);
17893 /* Ask cgraph if the global variable really is to be emitted.
17894 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17895 varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17896 if (node
&& node
->definition
)
17898 die
->die_perennial_p
= 1;
17899 /* Keep the parent DIEs as well. */
17900 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17901 die
->die_perennial_p
= 1;
17907 /* Mark all members of used_types_hash as perennial. */
17910 premark_used_types (struct function
*fun
)
17912 if (fun
&& fun
->used_types_hash
)
17913 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17916 /* Mark all members of types_used_by_vars_entry as perennial. */
17919 premark_types_used_by_global_vars (void)
17921 if (types_used_by_vars_hash
)
17922 htab_traverse (types_used_by_vars_hash
,
17923 premark_types_used_by_global_vars_helper
, NULL
);
17926 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17927 for CA_LOC call arg loc node. */
17930 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17931 struct call_arg_loc_node
*ca_loc
)
17933 dw_die_ref stmt_die
= NULL
, die
;
17934 tree block
= ca_loc
->block
;
17937 && block
!= DECL_INITIAL (decl
)
17938 && TREE_CODE (block
) == BLOCK
)
17940 if (block_map
.length () > BLOCK_NUMBER (block
))
17941 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17944 block
= BLOCK_SUPERCONTEXT (block
);
17946 if (stmt_die
== NULL
)
17947 stmt_die
= subr_die
;
17948 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17949 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17950 if (ca_loc
->tail_call_p
)
17951 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17952 if (ca_loc
->symbol_ref
)
17954 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17956 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17958 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17963 /* Generate a DIE to represent a declared function (either file-scope or
17967 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17969 tree origin
= decl_ultimate_origin (decl
);
17970 dw_die_ref subr_die
;
17972 dw_die_ref old_die
= lookup_decl_die (decl
);
17973 int declaration
= (current_function_decl
!= decl
17974 || class_or_namespace_scope_p (context_die
));
17976 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17978 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17979 started to generate the abstract instance of an inline, decided to output
17980 its containing class, and proceeded to emit the declaration of the inline
17981 from the member list for the class. If so, DECLARATION takes priority;
17982 we'll get back to the abstract instance when done with the class. */
17984 /* The class-scope declaration DIE must be the primary DIE. */
17985 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17988 gcc_assert (!old_die
);
17991 /* Now that the C++ front end lazily declares artificial member fns, we
17992 might need to retrofit the declaration into its class. */
17993 if (!declaration
&& !origin
&& !old_die
17994 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17995 && !class_or_namespace_scope_p (context_die
)
17996 && debug_info_level
> DINFO_LEVEL_TERSE
)
17997 old_die
= force_decl_die (decl
);
17999 if (origin
!= NULL
)
18001 gcc_assert (!declaration
|| local_scope_p (context_die
));
18003 /* Fixup die_parent for the abstract instance of a nested
18004 inline function. */
18005 if (old_die
&& old_die
->die_parent
== NULL
)
18006 add_child_die (context_die
, old_die
);
18008 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18009 add_abstract_origin_attribute (subr_die
, origin
);
18010 /* This is where the actual code for a cloned function is.
18011 Let's emit linkage name attribute for it. This helps
18012 debuggers to e.g, set breakpoints into
18013 constructors/destructors when the user asks "break
18015 add_linkage_name (subr_die
, decl
);
18019 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18020 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18022 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18023 /* We can have a normal definition following an inline one in the
18024 case of redefinition of GNU C extern inlines.
18025 It seems reasonable to use AT_specification in this case. */
18026 && !get_AT (old_die
, DW_AT_inline
))
18028 /* Detect and ignore this case, where we are trying to output
18029 something we have already output. */
18033 /* If the definition comes from the same place as the declaration,
18034 maybe use the old DIE. We always want the DIE for this function
18035 that has the *_pc attributes to be under comp_unit_die so the
18036 debugger can find it. We also need to do this for abstract
18037 instances of inlines, since the spec requires the out-of-line copy
18038 to have the same parent. For local class methods, this doesn't
18039 apply; we just use the old DIE. */
18040 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
18041 && (DECL_ARTIFICIAL (decl
)
18042 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18043 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18044 == (unsigned) s
.line
))))
18046 subr_die
= old_die
;
18048 /* Clear out the declaration attribute and the formal parameters.
18049 Do not remove all children, because it is possible that this
18050 declaration die was forced using force_decl_die(). In such
18051 cases die that forced declaration die (e.g. TAG_imported_module)
18052 is one of the children that we do not want to remove. */
18053 remove_AT (subr_die
, DW_AT_declaration
);
18054 remove_AT (subr_die
, DW_AT_object_pointer
);
18055 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18059 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18060 add_AT_specification (subr_die
, old_die
);
18061 add_pubname (decl
, subr_die
);
18062 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18063 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18064 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18065 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18067 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18068 emit the real type on the definition die. */
18069 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18071 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18072 if (die
== auto_die
|| die
== decltype_auto_die
)
18073 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18074 0, 0, context_die
);
18080 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18082 if (TREE_PUBLIC (decl
))
18083 add_AT_flag (subr_die
, DW_AT_external
, 1);
18085 add_name_and_src_coords_attributes (subr_die
, decl
);
18086 add_pubname (decl
, subr_die
);
18087 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18089 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18090 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18091 0, 0, context_die
);
18094 add_pure_or_virtual_attribute (subr_die
, decl
);
18095 if (DECL_ARTIFICIAL (decl
))
18096 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18098 add_accessibility_attribute (subr_die
, decl
);
18103 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18105 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18107 /* If this is an explicit function declaration then generate
18108 a DW_AT_explicit attribute. */
18109 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18110 && (dwarf_version
>= 3 || !dwarf_strict
))
18111 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18113 /* The first time we see a member function, it is in the context of
18114 the class to which it belongs. We make sure of this by emitting
18115 the class first. The next time is the definition, which is
18116 handled above. The two may come from the same source text.
18118 Note that force_decl_die() forces function declaration die. It is
18119 later reused to represent definition. */
18120 equate_decl_number_to_die (decl
, subr_die
);
18123 else if (DECL_ABSTRACT (decl
))
18125 if (DECL_DECLARED_INLINE_P (decl
))
18127 if (cgraph_function_possibly_inlined_p (decl
))
18128 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18130 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18134 if (cgraph_function_possibly_inlined_p (decl
))
18135 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18137 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18140 if (DECL_DECLARED_INLINE_P (decl
)
18141 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18142 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18144 equate_decl_number_to_die (decl
, subr_die
);
18146 else if (!DECL_EXTERNAL (decl
))
18148 HOST_WIDE_INT cfa_fb_offset
;
18149 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18151 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18152 equate_decl_number_to_die (decl
, subr_die
);
18154 gcc_checking_assert (fun
);
18155 if (!flag_reorder_blocks_and_partition
)
18157 dw_fde_ref fde
= fun
->fde
;
18158 if (fde
->dw_fde_begin
)
18160 /* We have already generated the labels. */
18161 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18162 fde
->dw_fde_end
, false);
18166 /* Create start/end labels and add the range. */
18167 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18168 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18169 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18170 current_function_funcdef_no
);
18171 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18172 current_function_funcdef_no
);
18173 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18177 #if VMS_DEBUGGING_INFO
18178 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18179 Section 2.3 Prologue and Epilogue Attributes:
18180 When a breakpoint is set on entry to a function, it is generally
18181 desirable for execution to be suspended, not on the very first
18182 instruction of the function, but rather at a point after the
18183 function's frame has been set up, after any language defined local
18184 declaration processing has been completed, and before execution of
18185 the first statement of the function begins. Debuggers generally
18186 cannot properly determine where this point is. Similarly for a
18187 breakpoint set on exit from a function. The prologue and epilogue
18188 attributes allow a compiler to communicate the location(s) to use. */
18191 if (fde
->dw_fde_vms_end_prologue
)
18192 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18193 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18195 if (fde
->dw_fde_vms_begin_epilogue
)
18196 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18197 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18204 /* Generate pubnames entries for the split function code ranges. */
18205 dw_fde_ref fde
= fun
->fde
;
18207 if (fde
->dw_fde_second_begin
)
18209 if (dwarf_version
>= 3 || !dwarf_strict
)
18211 /* We should use ranges for non-contiguous code section
18212 addresses. Use the actual code range for the initial
18213 section, since the HOT/COLD labels might precede an
18214 alignment offset. */
18215 bool range_list_added
= false;
18216 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18217 fde
->dw_fde_end
, &range_list_added
,
18219 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18220 fde
->dw_fde_second_end
,
18221 &range_list_added
, false);
18222 if (range_list_added
)
18227 /* There is no real support in DW2 for this .. so we make
18228 a work-around. First, emit the pub name for the segment
18229 containing the function label. Then make and emit a
18230 simplified subprogram DIE for the second segment with the
18231 name pre-fixed by __hot/cold_sect_of_. We use the same
18232 linkage name for the second die so that gdb will find both
18233 sections when given "b foo". */
18234 const char *name
= NULL
;
18235 tree decl_name
= DECL_NAME (decl
);
18236 dw_die_ref seg_die
;
18238 /* Do the 'primary' section. */
18239 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18240 fde
->dw_fde_end
, false);
18242 /* Build a minimal DIE for the secondary section. */
18243 seg_die
= new_die (DW_TAG_subprogram
,
18244 subr_die
->die_parent
, decl
);
18246 if (TREE_PUBLIC (decl
))
18247 add_AT_flag (seg_die
, DW_AT_external
, 1);
18249 if (decl_name
!= NULL
18250 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18252 name
= dwarf2_name (decl
, 1);
18253 if (! DECL_ARTIFICIAL (decl
))
18254 add_src_coords_attributes (seg_die
, decl
);
18256 add_linkage_name (seg_die
, decl
);
18258 gcc_assert (name
!= NULL
);
18259 add_pure_or_virtual_attribute (seg_die
, decl
);
18260 if (DECL_ARTIFICIAL (decl
))
18261 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18263 name
= concat ("__second_sect_of_", name
, NULL
);
18264 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18265 fde
->dw_fde_second_end
, false);
18266 add_name_attribute (seg_die
, name
);
18267 if (want_pubnames ())
18268 add_pubname_string (name
, seg_die
);
18272 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18276 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18278 /* We define the "frame base" as the function's CFA. This is more
18279 convenient for several reasons: (1) It's stable across the prologue
18280 and epilogue, which makes it better than just a frame pointer,
18281 (2) With dwarf3, there exists a one-byte encoding that allows us
18282 to reference the .debug_frame data by proxy, but failing that,
18283 (3) We can at least reuse the code inspection and interpretation
18284 code that determines the CFA position at various points in the
18286 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18288 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18289 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18293 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18294 if (list
->dw_loc_next
)
18295 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18297 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18300 /* Compute a displacement from the "steady-state frame pointer" to
18301 the CFA. The former is what all stack slots and argument slots
18302 will reference in the rtl; the latter is what we've told the
18303 debugger about. We'll need to adjust all frame_base references
18304 by this displacement. */
18305 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18307 if (fun
->static_chain_decl
)
18308 add_AT_location_description (subr_die
, DW_AT_static_link
,
18309 loc_list_from_tree (fun
->static_chain_decl
, 2));
18312 /* Generate child dies for template paramaters. */
18313 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18314 gen_generic_params_dies (decl
);
18316 /* Now output descriptions of the arguments for this function. This gets
18317 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18318 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18319 `...' at the end of the formal parameter list. In order to find out if
18320 there was a trailing ellipsis or not, we must instead look at the type
18321 associated with the FUNCTION_DECL. This will be a node of type
18322 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18323 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18324 an ellipsis at the end. */
18326 /* In the case where we are describing a mere function declaration, all we
18327 need to do here (and all we *can* do here) is to describe the *types* of
18328 its formal parameters. */
18329 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18331 else if (declaration
)
18332 gen_formal_types_die (decl
, subr_die
);
18335 /* Generate DIEs to represent all known formal parameters. */
18336 tree parm
= DECL_ARGUMENTS (decl
);
18337 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18338 tree generic_decl_parm
= generic_decl
18339 ? DECL_ARGUMENTS (generic_decl
)
18342 /* Now we want to walk the list of parameters of the function and
18343 emit their relevant DIEs.
18345 We consider the case of DECL being an instance of a generic function
18346 as well as it being a normal function.
18348 If DECL is an instance of a generic function we walk the
18349 parameters of the generic function declaration _and_ the parameters of
18350 DECL itself. This is useful because we want to emit specific DIEs for
18351 function parameter packs and those are declared as part of the
18352 generic function declaration. In that particular case,
18353 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18354 That DIE has children DIEs representing the set of arguments
18355 of the pack. Note that the set of pack arguments can be empty.
18356 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18359 Otherwise, we just consider the parameters of DECL. */
18360 while (generic_decl_parm
|| parm
)
18362 if (generic_decl_parm
18363 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18364 gen_formal_parameter_pack_die (generic_decl_parm
,
18369 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18371 if (parm
== DECL_ARGUMENTS (decl
)
18372 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18374 && (dwarf_version
>= 3 || !dwarf_strict
))
18375 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18377 parm
= DECL_CHAIN (parm
);
18380 if (generic_decl_parm
)
18381 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18384 /* Decide whether we need an unspecified_parameters DIE at the end.
18385 There are 2 more cases to do this for: 1) the ansi ... declaration -
18386 this is detectable when the end of the arg list is not a
18387 void_type_node 2) an unprototyped function declaration (not a
18388 definition). This just means that we have no info about the
18389 parameters at all. */
18390 if (prototype_p (TREE_TYPE (decl
)))
18392 /* This is the prototyped case, check for.... */
18393 if (stdarg_p (TREE_TYPE (decl
)))
18394 gen_unspecified_parameters_die (decl
, subr_die
);
18396 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18397 gen_unspecified_parameters_die (decl
, subr_die
);
18400 /* Output Dwarf info for all of the stuff within the body of the function
18401 (if it has one - it may be just a declaration). */
18402 outer_scope
= DECL_INITIAL (decl
);
18404 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18405 a function. This BLOCK actually represents the outermost binding contour
18406 for the function, i.e. the contour in which the function's formal
18407 parameters and labels get declared. Curiously, it appears that the front
18408 end doesn't actually put the PARM_DECL nodes for the current function onto
18409 the BLOCK_VARS list for this outer scope, but are strung off of the
18410 DECL_ARGUMENTS list for the function instead.
18412 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18413 the LABEL_DECL nodes for the function however, and we output DWARF info
18414 for those in decls_for_scope. Just within the `outer_scope' there will be
18415 a BLOCK node representing the function's outermost pair of curly braces,
18416 and any blocks used for the base and member initializers of a C++
18417 constructor function. */
18418 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18420 int call_site_note_count
= 0;
18421 int tail_call_site_note_count
= 0;
18423 /* Emit a DW_TAG_variable DIE for a named return value. */
18424 if (DECL_NAME (DECL_RESULT (decl
)))
18425 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18427 current_function_has_inlines
= 0;
18428 decls_for_scope (outer_scope
, subr_die
, 0);
18430 if (call_arg_locations
&& !dwarf_strict
)
18432 struct call_arg_loc_node
*ca_loc
;
18433 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18435 dw_die_ref die
= NULL
;
18436 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18439 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18440 arg
; arg
= next_arg
)
18442 dw_loc_descr_ref reg
, val
;
18443 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18444 dw_die_ref cdie
, tdie
= NULL
;
18446 next_arg
= XEXP (arg
, 1);
18447 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18449 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18450 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18451 && REGNO (XEXP (XEXP (arg
, 0), 0))
18452 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18453 next_arg
= XEXP (next_arg
, 1);
18454 if (mode
== VOIDmode
)
18456 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18457 if (mode
== VOIDmode
)
18458 mode
= GET_MODE (XEXP (arg
, 0));
18460 if (mode
== VOIDmode
|| mode
== BLKmode
)
18462 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18464 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18465 tloc
= XEXP (XEXP (arg
, 0), 1);
18468 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18469 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18471 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18472 tlocc
= XEXP (XEXP (arg
, 0), 1);
18476 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18477 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18478 VAR_INIT_STATUS_INITIALIZED
);
18479 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18481 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18482 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18483 get_address_mode (mem
),
18485 VAR_INIT_STATUS_INITIALIZED
);
18487 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18488 == DEBUG_PARAMETER_REF
)
18491 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18492 tdie
= lookup_decl_die (tdecl
);
18499 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18500 != DEBUG_PARAMETER_REF
)
18502 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18504 VAR_INIT_STATUS_INITIALIZED
);
18508 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18509 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18512 add_AT_loc (cdie
, DW_AT_location
, reg
);
18513 else if (tdie
!= NULL
)
18514 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18515 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18516 if (next_arg
!= XEXP (arg
, 1))
18518 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18519 if (mode
== VOIDmode
)
18520 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18521 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18524 VAR_INIT_STATUS_INITIALIZED
);
18526 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18530 && (ca_loc
->symbol_ref
|| tloc
))
18531 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18532 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18534 dw_loc_descr_ref tval
= NULL
;
18536 if (tloc
!= NULL_RTX
)
18537 tval
= mem_loc_descriptor (tloc
,
18538 GET_MODE (tloc
) == VOIDmode
18539 ? Pmode
: GET_MODE (tloc
),
18541 VAR_INIT_STATUS_INITIALIZED
);
18543 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18544 else if (tlocc
!= NULL_RTX
)
18546 tval
= mem_loc_descriptor (tlocc
,
18547 GET_MODE (tlocc
) == VOIDmode
18548 ? Pmode
: GET_MODE (tlocc
),
18550 VAR_INIT_STATUS_INITIALIZED
);
18552 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18558 call_site_note_count
++;
18559 if (ca_loc
->tail_call_p
)
18560 tail_call_site_note_count
++;
18564 call_arg_locations
= NULL
;
18565 call_arg_loc_last
= NULL
;
18566 if (tail_call_site_count
>= 0
18567 && tail_call_site_count
== tail_call_site_note_count
18570 if (call_site_count
>= 0
18571 && call_site_count
== call_site_note_count
)
18572 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18574 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18576 call_site_count
= -1;
18577 tail_call_site_count
= -1;
18580 if (subr_die
!= old_die
)
18581 /* Add the calling convention attribute if requested. */
18582 add_calling_convention_attribute (subr_die
, decl
);
18585 /* Returns a hash value for X (which really is a die_struct). */
18588 common_block_die_table_hash (const void *x
)
18590 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18591 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18594 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18595 as decl_id and die_parent of die_struct Y. */
18598 common_block_die_table_eq (const void *x
, const void *y
)
18600 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18601 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18602 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18605 /* Generate a DIE to represent a declared data object.
18606 Either DECL or ORIGIN must be non-null. */
18609 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18611 HOST_WIDE_INT off
= 0;
18613 tree decl_or_origin
= decl
? decl
: origin
;
18614 tree ultimate_origin
;
18615 dw_die_ref var_die
;
18616 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18617 dw_die_ref origin_die
;
18618 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18619 || class_or_namespace_scope_p (context_die
));
18620 bool specialization_p
= false;
18622 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18623 if (decl
|| ultimate_origin
)
18624 origin
= ultimate_origin
;
18625 com_decl
= fortran_common (decl_or_origin
, &off
);
18627 /* Symbol in common gets emitted as a child of the common block, in the form
18628 of a data member. */
18631 dw_die_ref com_die
;
18632 dw_loc_list_ref loc
;
18633 die_node com_die_arg
;
18635 var_die
= lookup_decl_die (decl_or_origin
);
18638 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18640 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18645 /* Optimize the common case. */
18646 if (single_element_loc_list_p (loc
)
18647 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18648 && loc
->expr
->dw_loc_next
== NULL
18649 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18652 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18653 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18654 = plus_constant (GET_MODE (x
), x
, off
);
18657 loc_list_plus_const (loc
, off
);
18659 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18660 remove_AT (var_die
, DW_AT_declaration
);
18666 if (common_block_die_table
== NULL
)
18667 common_block_die_table
18668 = htab_create_ggc (10, common_block_die_table_hash
,
18669 common_block_die_table_eq
, NULL
);
18671 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18672 com_die_arg
.die_parent
= context_die
;
18673 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18674 loc
= loc_list_from_tree (com_decl
, 2);
18675 if (com_die
== NULL
)
18678 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18681 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18682 add_name_and_src_coords_attributes (com_die
, com_decl
);
18685 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18686 /* Avoid sharing the same loc descriptor between
18687 DW_TAG_common_block and DW_TAG_variable. */
18688 loc
= loc_list_from_tree (com_decl
, 2);
18690 else if (DECL_EXTERNAL (decl
))
18691 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18692 if (want_pubnames ())
18693 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18694 com_die
->decl_id
= DECL_UID (com_decl
);
18695 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18696 *slot
= (void *) com_die
;
18698 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18700 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18701 loc
= loc_list_from_tree (com_decl
, 2);
18702 remove_AT (com_die
, DW_AT_declaration
);
18704 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18705 add_name_and_src_coords_attributes (var_die
, decl
);
18706 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18707 TREE_THIS_VOLATILE (decl
), context_die
);
18708 add_AT_flag (var_die
, DW_AT_external
, 1);
18713 /* Optimize the common case. */
18714 if (single_element_loc_list_p (loc
)
18715 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18716 && loc
->expr
->dw_loc_next
== NULL
18717 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18719 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18720 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18721 = plus_constant (GET_MODE (x
), x
, off
);
18724 loc_list_plus_const (loc
, off
);
18726 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18728 else if (DECL_EXTERNAL (decl
))
18729 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18730 equate_decl_number_to_die (decl
, var_die
);
18734 /* If the compiler emitted a definition for the DECL declaration
18735 and if we already emitted a DIE for it, don't emit a second
18736 DIE for it again. Allow re-declarations of DECLs that are
18737 inside functions, though. */
18738 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18741 /* For static data members, the declaration in the class is supposed
18742 to have DW_TAG_member tag; the specification should still be
18743 DW_TAG_variable referencing the DW_TAG_member DIE. */
18744 if (declaration
&& class_scope_p (context_die
))
18745 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18747 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18750 if (origin
!= NULL
)
18751 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18753 /* Loop unrolling can create multiple blocks that refer to the same
18754 static variable, so we must test for the DW_AT_declaration flag.
18756 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18757 copy decls and set the DECL_ABSTRACT flag on them instead of
18760 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18762 ??? The declare_in_namespace support causes us to get two DIEs for one
18763 variable, both of which are declarations. We want to avoid considering
18764 one to be a specification, so we must test that this DIE is not a
18766 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18767 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18769 /* This is a definition of a C++ class level static. */
18770 add_AT_specification (var_die
, old_die
);
18771 specialization_p
= true;
18772 if (DECL_NAME (decl
))
18774 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18775 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18777 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18778 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18780 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18781 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18783 if (old_die
->die_tag
== DW_TAG_member
)
18784 add_linkage_name (var_die
, decl
);
18788 add_name_and_src_coords_attributes (var_die
, decl
);
18790 if ((origin
== NULL
&& !specialization_p
)
18792 && !DECL_ABSTRACT (decl_or_origin
)
18793 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18794 decl_function_context
18795 (decl_or_origin
))))
18797 tree type
= TREE_TYPE (decl_or_origin
);
18799 if (decl_by_reference_p (decl_or_origin
))
18800 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18802 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18803 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18806 if (origin
== NULL
&& !specialization_p
)
18808 if (TREE_PUBLIC (decl
))
18809 add_AT_flag (var_die
, DW_AT_external
, 1);
18811 if (DECL_ARTIFICIAL (decl
))
18812 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18814 add_accessibility_attribute (var_die
, decl
);
18818 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18820 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18821 equate_decl_number_to_die (decl
, var_die
);
18824 && (! DECL_ABSTRACT (decl_or_origin
)
18825 /* Local static vars are shared between all clones/inlines,
18826 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18828 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18829 && TREE_STATIC (decl_or_origin
)
18830 && DECL_RTL_SET_P (decl_or_origin
)))
18831 /* When abstract origin already has DW_AT_location attribute, no need
18832 to add it again. */
18833 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18835 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18836 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18837 defer_location (decl_or_origin
, var_die
);
18839 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18840 decl
== NULL
, DW_AT_location
);
18841 add_pubname (decl_or_origin
, var_die
);
18844 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18847 /* Generate a DIE to represent a named constant. */
18850 gen_const_die (tree decl
, dw_die_ref context_die
)
18852 dw_die_ref const_die
;
18853 tree type
= TREE_TYPE (decl
);
18855 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18856 add_name_and_src_coords_attributes (const_die
, decl
);
18857 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18858 if (TREE_PUBLIC (decl
))
18859 add_AT_flag (const_die
, DW_AT_external
, 1);
18860 if (DECL_ARTIFICIAL (decl
))
18861 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18862 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18865 /* Generate a DIE to represent a label identifier. */
18868 gen_label_die (tree decl
, dw_die_ref context_die
)
18870 tree origin
= decl_ultimate_origin (decl
);
18871 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18873 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18875 if (origin
!= NULL
)
18876 add_abstract_origin_attribute (lbl_die
, origin
);
18878 add_name_and_src_coords_attributes (lbl_die
, decl
);
18880 if (DECL_ABSTRACT (decl
))
18881 equate_decl_number_to_die (decl
, lbl_die
);
18884 insn
= DECL_RTL_IF_SET (decl
);
18886 /* Deleted labels are programmer specified labels which have been
18887 eliminated because of various optimizations. We still emit them
18888 here so that it is possible to put breakpoints on them. */
18892 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18894 /* When optimization is enabled (via -O) some parts of the compiler
18895 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18896 represent source-level labels which were explicitly declared by
18897 the user. This really shouldn't be happening though, so catch
18898 it if it ever does happen. */
18899 gcc_assert (!INSN_DELETED_P (insn
));
18901 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18902 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18906 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18907 && CODE_LABEL_NUMBER (insn
) != -1)
18909 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18910 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18915 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18916 attributes to the DIE for a block STMT, to describe where the inlined
18917 function was called from. This is similar to add_src_coords_attributes. */
18920 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18922 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18924 if (dwarf_version
>= 3 || !dwarf_strict
)
18926 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18927 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18932 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18933 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18936 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18938 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18940 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18941 && (dwarf_version
>= 3 || !dwarf_strict
))
18943 tree chain
, superblock
= NULL_TREE
;
18945 dw_attr_ref attr
= NULL
;
18947 if (inlined_function_outer_scope_p (stmt
))
18949 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18950 BLOCK_NUMBER (stmt
));
18951 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18954 /* Optimize duplicate .debug_ranges lists or even tails of
18955 lists. If this BLOCK has same ranges as its supercontext,
18956 lookup DW_AT_ranges attribute in the supercontext (and
18957 recursively so), verify that the ranges_table contains the
18958 right values and use it instead of adding a new .debug_range. */
18959 for (chain
= stmt
, pdie
= die
;
18960 BLOCK_SAME_RANGE (chain
);
18961 chain
= BLOCK_SUPERCONTEXT (chain
))
18963 dw_attr_ref new_attr
;
18965 pdie
= pdie
->die_parent
;
18968 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18970 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18971 if (new_attr
== NULL
18972 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18975 superblock
= BLOCK_SUPERCONTEXT (chain
);
18978 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18979 / 2 / DWARF2_ADDR_SIZE
].num
18980 == BLOCK_NUMBER (superblock
))
18981 && BLOCK_FRAGMENT_CHAIN (superblock
))
18983 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18984 / 2 / DWARF2_ADDR_SIZE
;
18985 unsigned long supercnt
= 0, thiscnt
= 0;
18986 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18987 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18990 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18991 == BLOCK_NUMBER (chain
));
18993 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18994 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18995 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18997 gcc_assert (supercnt
>= thiscnt
);
18998 add_AT_range_list (die
, DW_AT_ranges
,
18999 ((off
+ supercnt
- thiscnt
)
19000 * 2 * DWARF2_ADDR_SIZE
),
19005 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19007 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19010 add_ranges (chain
);
19011 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19018 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19019 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19020 BLOCK_NUMBER (stmt
));
19021 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19022 BLOCK_NUMBER (stmt
));
19023 add_AT_low_high_pc (die
, label
, label_high
, false);
19027 /* Generate a DIE for a lexical block. */
19030 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19032 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19034 if (call_arg_locations
)
19036 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19037 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19038 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
19041 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19042 add_high_low_attributes (stmt
, stmt_die
);
19044 decls_for_scope (stmt
, stmt_die
, depth
);
19047 /* Generate a DIE for an inlined subprogram. */
19050 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
19054 /* The instance of function that is effectively being inlined shall not
19056 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19058 decl
= block_ultimate_origin (stmt
);
19060 /* Emit info for the abstract instance first, if we haven't yet. We
19061 must emit this even if the block is abstract, otherwise when we
19062 emit the block below (or elsewhere), we may end up trying to emit
19063 a die whose origin die hasn't been emitted, and crashing. */
19064 dwarf2out_abstract_function (decl
);
19066 if (! BLOCK_ABSTRACT (stmt
))
19068 dw_die_ref subr_die
19069 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19071 if (call_arg_locations
)
19073 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19074 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19075 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
19077 add_abstract_origin_attribute (subr_die
, decl
);
19078 if (TREE_ASM_WRITTEN (stmt
))
19079 add_high_low_attributes (stmt
, subr_die
);
19080 add_call_src_coords_attributes (stmt
, subr_die
);
19082 decls_for_scope (stmt
, subr_die
, depth
);
19083 current_function_has_inlines
= 1;
19087 /* Generate a DIE for a field in a record, or structure. */
19090 gen_field_die (tree decl
, dw_die_ref context_die
)
19092 dw_die_ref decl_die
;
19094 if (TREE_TYPE (decl
) == error_mark_node
)
19097 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19098 add_name_and_src_coords_attributes (decl_die
, decl
);
19099 add_type_attribute (decl_die
, member_declared_type (decl
),
19100 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19103 if (DECL_BIT_FIELD_TYPE (decl
))
19105 add_byte_size_attribute (decl_die
, decl
);
19106 add_bit_size_attribute (decl_die
, decl
);
19107 add_bit_offset_attribute (decl_die
, decl
);
19110 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19111 add_data_member_location_attribute (decl_die
, decl
);
19113 if (DECL_ARTIFICIAL (decl
))
19114 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19116 add_accessibility_attribute (decl_die
, decl
);
19118 /* Equate decl number to die, so that we can look up this decl later on. */
19119 equate_decl_number_to_die (decl
, decl_die
);
19123 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19124 Use modified_type_die instead.
19125 We keep this code here just in case these types of DIEs may be needed to
19126 represent certain things in other languages (e.g. Pascal) someday. */
19129 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19132 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19134 equate_type_number_to_die (type
, ptr_die
);
19135 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19136 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19139 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19140 Use modified_type_die instead.
19141 We keep this code here just in case these types of DIEs may be needed to
19142 represent certain things in other languages (e.g. Pascal) someday. */
19145 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19147 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19149 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19150 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19152 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19154 equate_type_number_to_die (type
, ref_die
);
19155 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19156 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19160 /* Generate a DIE for a pointer to a member type. */
19163 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19166 = new_die (DW_TAG_ptr_to_member_type
,
19167 scope_die_for (type
, context_die
), type
);
19169 equate_type_number_to_die (type
, ptr_die
);
19170 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19171 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19172 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19175 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19177 static char *producer_string
;
19179 /* Return a heap allocated producer string including command line options
19180 if -grecord-gcc-switches. */
19183 gen_producer_string (void)
19186 auto_vec
<dchar_p
> switches
;
19187 const char *language_string
= lang_hooks
.name
;
19188 char *producer
, *tail
;
19190 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19191 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19193 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19194 switch (save_decoded_options
[j
].opt_index
)
19201 case OPT_auxbase_strip
:
19210 case OPT_SPECIAL_unknown
:
19211 case OPT_SPECIAL_ignore
:
19212 case OPT_SPECIAL_program_name
:
19213 case OPT_SPECIAL_input_file
:
19214 case OPT_grecord_gcc_switches
:
19215 case OPT_gno_record_gcc_switches
:
19216 case OPT__output_pch_
:
19217 case OPT_fdiagnostics_show_location_
:
19218 case OPT_fdiagnostics_show_option
:
19219 case OPT_fdiagnostics_show_caret
:
19220 case OPT_fdiagnostics_color_
:
19221 case OPT_fverbose_asm
:
19223 case OPT__sysroot_
:
19225 case OPT_nostdinc__
:
19226 /* Ignore these. */
19229 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19230 & CL_NO_DWARF_RECORD
)
19232 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19234 switch (save_decoded_options
[j
].canonical_option
[0][1])
19241 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19248 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19249 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19253 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19255 sprintf (tail
, "%s %s", language_string
, version_string
);
19258 FOR_EACH_VEC_ELT (switches
, j
, p
)
19262 memcpy (tail
+ 1, p
, len
);
19270 /* Generate the DIE for the compilation unit. */
19273 gen_compile_unit_die (const char *filename
)
19276 const char *language_string
= lang_hooks
.name
;
19279 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19283 add_name_attribute (die
, filename
);
19284 /* Don't add cwd for <built-in>. */
19285 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19286 add_comp_dir_attribute (die
);
19289 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19291 /* If our producer is LTO try to figure out a common language to use
19292 from the global list of translation units. */
19293 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19297 const char *common_lang
= NULL
;
19299 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19301 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19304 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19305 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19307 else if (strncmp (common_lang
, "GNU C", 5) == 0
19308 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19309 /* Mixing C and C++ is ok, use C++ in that case. */
19310 common_lang
= "GNU C++";
19313 /* Fall back to C. */
19314 common_lang
= NULL
;
19320 language_string
= common_lang
;
19323 language
= DW_LANG_C89
;
19324 if (strcmp (language_string
, "GNU C++") == 0)
19325 language
= DW_LANG_C_plus_plus
;
19326 else if (strcmp (language_string
, "GNU F77") == 0)
19327 language
= DW_LANG_Fortran77
;
19328 else if (strcmp (language_string
, "GNU Pascal") == 0)
19329 language
= DW_LANG_Pascal83
;
19330 else if (dwarf_version
>= 3 || !dwarf_strict
)
19332 if (strcmp (language_string
, "GNU Ada") == 0)
19333 language
= DW_LANG_Ada95
;
19334 else if (strcmp (language_string
, "GNU Fortran") == 0)
19335 language
= DW_LANG_Fortran95
;
19336 else if (strcmp (language_string
, "GNU Java") == 0)
19337 language
= DW_LANG_Java
;
19338 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19339 language
= DW_LANG_ObjC
;
19340 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19341 language
= DW_LANG_ObjC_plus_plus
;
19342 else if (dwarf_version
>= 5 || !dwarf_strict
)
19344 if (strcmp (language_string
, "GNU Go") == 0)
19345 language
= DW_LANG_Go
;
19348 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19349 else if (strcmp (language_string
, "GNU Fortran") == 0)
19350 language
= DW_LANG_Fortran90
;
19352 add_AT_unsigned (die
, DW_AT_language
, language
);
19356 case DW_LANG_Fortran77
:
19357 case DW_LANG_Fortran90
:
19358 case DW_LANG_Fortran95
:
19359 /* Fortran has case insensitive identifiers and the front-end
19360 lowercases everything. */
19361 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19364 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19370 /* Generate the DIE for a base class. */
19373 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19375 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19377 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19378 add_data_member_location_attribute (die
, binfo
);
19380 if (BINFO_VIRTUAL_P (binfo
))
19381 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19383 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19384 children, otherwise the default is DW_ACCESS_public. In DWARF2
19385 the default has always been DW_ACCESS_private. */
19386 if (access
== access_public_node
)
19388 if (dwarf_version
== 2
19389 || context_die
->die_tag
== DW_TAG_class_type
)
19390 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19392 else if (access
== access_protected_node
)
19393 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19394 else if (dwarf_version
> 2
19395 && context_die
->die_tag
!= DW_TAG_class_type
)
19396 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19399 /* Generate a DIE for a class member. */
19402 gen_member_die (tree type
, dw_die_ref context_die
)
19405 tree binfo
= TYPE_BINFO (type
);
19408 /* If this is not an incomplete type, output descriptions of each of its
19409 members. Note that as we output the DIEs necessary to represent the
19410 members of this record or union type, we will also be trying to output
19411 DIEs to represent the *types* of those members. However the `type'
19412 function (above) will specifically avoid generating type DIEs for member
19413 types *within* the list of member DIEs for this (containing) type except
19414 for those types (of members) which are explicitly marked as also being
19415 members of this (containing) type themselves. The g++ front- end can
19416 force any given type to be treated as a member of some other (containing)
19417 type by setting the TYPE_CONTEXT of the given (member) type to point to
19418 the TREE node representing the appropriate (containing) type. */
19420 /* First output info about the base classes. */
19423 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19427 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19428 gen_inheritance_die (base
,
19429 (accesses
? (*accesses
)[i
] : access_public_node
),
19433 /* Now output info about the data members and type members. */
19434 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19436 /* If we thought we were generating minimal debug info for TYPE
19437 and then changed our minds, some of the member declarations
19438 may have already been defined. Don't define them again, but
19439 do put them in the right order. */
19441 child
= lookup_decl_die (member
);
19443 splice_child_die (context_die
, child
);
19445 gen_decl_die (member
, NULL
, context_die
);
19448 /* Now output info about the function members (if any). */
19449 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19451 /* Don't include clones in the member list. */
19452 if (DECL_ABSTRACT_ORIGIN (member
))
19455 child
= lookup_decl_die (member
);
19457 splice_child_die (context_die
, child
);
19459 gen_decl_die (member
, NULL
, context_die
);
19463 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19464 is set, we pretend that the type was never defined, so we only get the
19465 member DIEs needed by later specification DIEs. */
19468 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19469 enum debug_info_usage usage
)
19471 dw_die_ref type_die
= lookup_type_die (type
);
19472 dw_die_ref scope_die
= 0;
19474 int complete
= (TYPE_SIZE (type
)
19475 && (! TYPE_STUB_DECL (type
)
19476 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19477 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19478 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19480 if (type_die
&& ! complete
)
19483 if (TYPE_CONTEXT (type
) != NULL_TREE
19484 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19485 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19488 scope_die
= scope_die_for (type
, context_die
);
19490 /* Generate child dies for template paramaters. */
19491 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19492 schedule_generic_params_dies_gen (type
);
19494 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19495 /* First occurrence of type or toplevel definition of nested class. */
19497 dw_die_ref old_die
= type_die
;
19499 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19500 ? record_type_tag (type
) : DW_TAG_union_type
,
19502 equate_type_number_to_die (type
, type_die
);
19504 add_AT_specification (type_die
, old_die
);
19506 add_name_attribute (type_die
, type_tag (type
));
19509 remove_AT (type_die
, DW_AT_declaration
);
19511 /* If this type has been completed, then give it a byte_size attribute and
19512 then give a list of members. */
19513 if (complete
&& !ns_decl
)
19515 /* Prevent infinite recursion in cases where the type of some member of
19516 this type is expressed in terms of this type itself. */
19517 TREE_ASM_WRITTEN (type
) = 1;
19518 add_byte_size_attribute (type_die
, type
);
19519 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19521 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19522 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19525 /* If the first reference to this type was as the return type of an
19526 inline function, then it may not have a parent. Fix this now. */
19527 if (type_die
->die_parent
== NULL
)
19528 add_child_die (scope_die
, type_die
);
19530 push_decl_scope (type
);
19531 gen_member_die (type
, type_die
);
19534 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19535 if (TYPE_ARTIFICIAL (type
))
19536 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19538 /* GNU extension: Record what type our vtable lives in. */
19539 if (TYPE_VFIELD (type
))
19541 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19543 gen_type_die (vtype
, context_die
);
19544 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19545 lookup_type_die (vtype
));
19550 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19552 /* We don't need to do this for function-local types. */
19553 if (TYPE_STUB_DECL (type
)
19554 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19555 vec_safe_push (incomplete_types
, type
);
19558 if (get_AT (type_die
, DW_AT_name
))
19559 add_pubtype (type
, type_die
);
19562 /* Generate a DIE for a subroutine _type_. */
19565 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19567 tree return_type
= TREE_TYPE (type
);
19568 dw_die_ref subr_die
19569 = new_die (DW_TAG_subroutine_type
,
19570 scope_die_for (type
, context_die
), type
);
19572 equate_type_number_to_die (type
, subr_die
);
19573 add_prototyped_attribute (subr_die
, type
);
19574 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19575 gen_formal_types_die (type
, subr_die
);
19577 if (get_AT (subr_die
, DW_AT_name
))
19578 add_pubtype (type
, subr_die
);
19581 /* Generate a DIE for a type definition. */
19584 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19586 dw_die_ref type_die
;
19589 if (TREE_ASM_WRITTEN (decl
))
19592 TREE_ASM_WRITTEN (decl
) = 1;
19593 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19594 origin
= decl_ultimate_origin (decl
);
19595 if (origin
!= NULL
)
19596 add_abstract_origin_attribute (type_die
, origin
);
19601 add_name_and_src_coords_attributes (type_die
, decl
);
19602 if (DECL_ORIGINAL_TYPE (decl
))
19604 type
= DECL_ORIGINAL_TYPE (decl
);
19606 gcc_assert (type
!= TREE_TYPE (decl
));
19607 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19611 type
= TREE_TYPE (decl
);
19613 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19615 /* Here, we are in the case of decl being a typedef naming
19616 an anonymous type, e.g:
19617 typedef struct {...} foo;
19618 In that case TREE_TYPE (decl) is not a typedef variant
19619 type and TYPE_NAME of the anonymous type is set to the
19620 TYPE_DECL of the typedef. This construct is emitted by
19623 TYPE is the anonymous struct named by the typedef
19624 DECL. As we need the DW_AT_type attribute of the
19625 DW_TAG_typedef to point to the DIE of TYPE, let's
19626 generate that DIE right away. add_type_attribute
19627 called below will then pick (via lookup_type_die) that
19628 anonymous struct DIE. */
19629 if (!TREE_ASM_WRITTEN (type
))
19630 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19632 /* This is a GNU Extension. We are adding a
19633 DW_AT_linkage_name attribute to the DIE of the
19634 anonymous struct TYPE. The value of that attribute
19635 is the name of the typedef decl naming the anonymous
19636 struct. This greatly eases the work of consumers of
19637 this debug info. */
19638 add_linkage_attr (lookup_type_die (type
), decl
);
19642 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19643 TREE_THIS_VOLATILE (decl
), context_die
);
19645 if (is_naming_typedef_decl (decl
))
19646 /* We want that all subsequent calls to lookup_type_die with
19647 TYPE in argument yield the DW_TAG_typedef we have just
19649 equate_type_number_to_die (type
, type_die
);
19651 add_accessibility_attribute (type_die
, decl
);
19654 if (DECL_ABSTRACT (decl
))
19655 equate_decl_number_to_die (decl
, type_die
);
19657 if (get_AT (type_die
, DW_AT_name
))
19658 add_pubtype (decl
, type_die
);
19661 /* Generate a DIE for a struct, class, enum or union type. */
19664 gen_tagged_type_die (tree type
,
19665 dw_die_ref context_die
,
19666 enum debug_info_usage usage
)
19670 if (type
== NULL_TREE
19671 || !is_tagged_type (type
))
19674 /* If this is a nested type whose containing class hasn't been written
19675 out yet, writing it out will cover this one, too. This does not apply
19676 to instantiations of member class templates; they need to be added to
19677 the containing class as they are generated. FIXME: This hurts the
19678 idea of combining type decls from multiple TUs, since we can't predict
19679 what set of template instantiations we'll get. */
19680 if (TYPE_CONTEXT (type
)
19681 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19682 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19684 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19686 if (TREE_ASM_WRITTEN (type
))
19689 /* If that failed, attach ourselves to the stub. */
19690 push_decl_scope (TYPE_CONTEXT (type
));
19691 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19694 else if (TYPE_CONTEXT (type
) != NULL_TREE
19695 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19697 /* If this type is local to a function that hasn't been written
19698 out yet, use a NULL context for now; it will be fixed up in
19699 decls_for_scope. */
19700 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19701 /* A declaration DIE doesn't count; nested types need to go in the
19703 if (context_die
&& is_declaration_die (context_die
))
19704 context_die
= NULL
;
19709 context_die
= declare_in_namespace (type
, context_die
);
19713 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19715 /* This might have been written out by the call to
19716 declare_in_namespace. */
19717 if (!TREE_ASM_WRITTEN (type
))
19718 gen_enumeration_type_die (type
, context_die
);
19721 gen_struct_or_union_type_die (type
, context_die
, usage
);
19726 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19727 it up if it is ever completed. gen_*_type_die will set it for us
19728 when appropriate. */
19731 /* Generate a type description DIE. */
19734 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19735 enum debug_info_usage usage
)
19737 struct array_descr_info info
;
19739 if (type
== NULL_TREE
|| type
== error_mark_node
)
19742 if (TYPE_NAME (type
) != NULL_TREE
19743 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19744 && is_redundant_typedef (TYPE_NAME (type
))
19745 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19746 /* The DECL of this type is a typedef we don't want to emit debug
19747 info for but we want debug info for its underlying typedef.
19748 This can happen for e.g, the injected-class-name of a C++
19750 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19752 /* If TYPE is a typedef type variant, let's generate debug info
19753 for the parent typedef which TYPE is a type of. */
19754 if (typedef_variant_p (type
))
19756 if (TREE_ASM_WRITTEN (type
))
19759 /* Prevent broken recursion; we can't hand off to the same type. */
19760 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19762 /* Give typedefs the right scope. */
19763 context_die
= scope_die_for (type
, context_die
);
19765 TREE_ASM_WRITTEN (type
) = 1;
19767 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19771 /* If type is an anonymous tagged type named by a typedef, let's
19772 generate debug info for the typedef. */
19773 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19775 /* Use the DIE of the containing namespace as the parent DIE of
19776 the type description DIE we want to generate. */
19777 if (DECL_CONTEXT (TYPE_NAME (type
))
19778 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19779 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19781 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19785 /* If this is an array type with hidden descriptor, handle it first. */
19786 if (!TREE_ASM_WRITTEN (type
)
19787 && lang_hooks
.types
.get_array_descr_info
19788 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19789 && (dwarf_version
>= 3 || !dwarf_strict
))
19791 gen_descr_array_type_die (type
, &info
, context_die
);
19792 TREE_ASM_WRITTEN (type
) = 1;
19796 /* We are going to output a DIE to represent the unqualified version
19797 of this type (i.e. without any const or volatile qualifiers) so
19798 get the main variant (i.e. the unqualified version) of this type
19799 now. (Vectors are special because the debugging info is in the
19800 cloned type itself). */
19801 if (TREE_CODE (type
) != VECTOR_TYPE
)
19802 type
= type_main_variant (type
);
19804 if (TREE_ASM_WRITTEN (type
))
19807 switch (TREE_CODE (type
))
19813 case REFERENCE_TYPE
:
19814 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19815 ensures that the gen_type_die recursion will terminate even if the
19816 type is recursive. Recursive types are possible in Ada. */
19817 /* ??? We could perhaps do this for all types before the switch
19819 TREE_ASM_WRITTEN (type
) = 1;
19821 /* For these types, all that is required is that we output a DIE (or a
19822 set of DIEs) to represent the "basis" type. */
19823 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19824 DINFO_USAGE_IND_USE
);
19828 /* This code is used for C++ pointer-to-data-member types.
19829 Output a description of the relevant class type. */
19830 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19831 DINFO_USAGE_IND_USE
);
19833 /* Output a description of the type of the object pointed to. */
19834 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19835 DINFO_USAGE_IND_USE
);
19837 /* Now output a DIE to represent this pointer-to-data-member type
19839 gen_ptr_to_mbr_type_die (type
, context_die
);
19842 case FUNCTION_TYPE
:
19843 /* Force out return type (in case it wasn't forced out already). */
19844 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19845 DINFO_USAGE_DIR_USE
);
19846 gen_subroutine_type_die (type
, context_die
);
19850 /* Force out return type (in case it wasn't forced out already). */
19851 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19852 DINFO_USAGE_DIR_USE
);
19853 gen_subroutine_type_die (type
, context_die
);
19857 gen_array_type_die (type
, context_die
);
19861 gen_array_type_die (type
, context_die
);
19864 case ENUMERAL_TYPE
:
19867 case QUAL_UNION_TYPE
:
19868 gen_tagged_type_die (type
, context_die
, usage
);
19874 case FIXED_POINT_TYPE
:
19877 /* No DIEs needed for fundamental types. */
19882 /* Just use DW_TAG_unspecified_type. */
19884 dw_die_ref type_die
= lookup_type_die (type
);
19885 if (type_die
== NULL
)
19887 tree name
= TYPE_IDENTIFIER (type
);
19888 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
19890 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19891 equate_type_number_to_die (type
, type_die
);
19897 if (is_cxx_auto (type
))
19899 tree name
= TYPE_IDENTIFIER (type
);
19900 dw_die_ref
*die
= (name
== get_identifier ("auto")
19901 ? &auto_die
: &decltype_auto_die
);
19904 *die
= new_die (DW_TAG_unspecified_type
,
19905 comp_unit_die (), NULL_TREE
);
19906 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
19908 equate_type_number_to_die (type
, *die
);
19911 gcc_unreachable ();
19914 TREE_ASM_WRITTEN (type
) = 1;
19918 gen_type_die (tree type
, dw_die_ref context_die
)
19920 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19923 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19924 things which are local to the given block. */
19927 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19929 int must_output_die
= 0;
19932 /* Ignore blocks that are NULL. */
19933 if (stmt
== NULL_TREE
)
19936 inlined_func
= inlined_function_outer_scope_p (stmt
);
19938 /* If the block is one fragment of a non-contiguous block, do not
19939 process the variables, since they will have been done by the
19940 origin block. Do process subblocks. */
19941 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19945 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19946 gen_block_die (sub
, context_die
, depth
+ 1);
19951 /* Determine if we need to output any Dwarf DIEs at all to represent this
19954 /* The outer scopes for inlinings *must* always be represented. We
19955 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19956 must_output_die
= 1;
19959 /* Determine if this block directly contains any "significant"
19960 local declarations which we will need to output DIEs for. */
19961 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19962 /* We are not in terse mode so *any* local declaration counts
19963 as being a "significant" one. */
19964 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19965 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19966 && (TREE_USED (stmt
)
19967 || TREE_ASM_WRITTEN (stmt
)
19968 || BLOCK_ABSTRACT (stmt
)));
19969 else if ((TREE_USED (stmt
)
19970 || TREE_ASM_WRITTEN (stmt
)
19971 || BLOCK_ABSTRACT (stmt
))
19972 && !dwarf2out_ignore_block (stmt
))
19973 must_output_die
= 1;
19976 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19977 DIE for any block which contains no significant local declarations at
19978 all. Rather, in such cases we just call `decls_for_scope' so that any
19979 needed Dwarf info for any sub-blocks will get properly generated. Note
19980 that in terse mode, our definition of what constitutes a "significant"
19981 local declaration gets restricted to include only inlined function
19982 instances and local (nested) function definitions. */
19983 if (must_output_die
)
19987 /* If STMT block is abstract, that means we have been called
19988 indirectly from dwarf2out_abstract_function.
19989 That function rightfully marks the descendent blocks (of
19990 the abstract function it is dealing with) as being abstract,
19991 precisely to prevent us from emitting any
19992 DW_TAG_inlined_subroutine DIE as a descendent
19993 of an abstract function instance. So in that case, we should
19994 not call gen_inlined_subroutine_die.
19996 Later though, when cgraph asks dwarf2out to emit info
19997 for the concrete instance of the function decl into which
19998 the concrete instance of STMT got inlined, the later will lead
19999 to the generation of a DW_TAG_inlined_subroutine DIE. */
20000 if (! BLOCK_ABSTRACT (stmt
))
20001 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20004 gen_lexical_block_die (stmt
, context_die
, depth
);
20007 decls_for_scope (stmt
, context_die
, depth
);
20010 /* Process variable DECL (or variable with origin ORIGIN) within
20011 block STMT and add it to CONTEXT_DIE. */
20013 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20016 tree decl_or_origin
= decl
? decl
: origin
;
20018 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20019 die
= lookup_decl_die (decl_or_origin
);
20020 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20021 && TYPE_DECL_IS_STUB (decl_or_origin
))
20022 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20026 if (die
!= NULL
&& die
->die_parent
== NULL
)
20027 add_child_die (context_die
, die
);
20028 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20029 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20030 stmt
, context_die
);
20032 gen_decl_die (decl
, origin
, context_die
);
20035 /* Generate all of the decls declared within a given scope and (recursively)
20036 all of its sub-blocks. */
20039 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20045 /* Ignore NULL blocks. */
20046 if (stmt
== NULL_TREE
)
20049 /* Output the DIEs to represent all of the data objects and typedefs
20050 declared directly within this block but not within any nested
20051 sub-blocks. Also, nested function and tag DIEs have been
20052 generated with a parent of NULL; fix that up now. We don't
20053 have to do this if we're at -g1. */
20054 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20056 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20057 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20058 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20059 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20063 /* Even if we're at -g1, we need to process the subblocks in order to get
20064 inlined call information. */
20066 /* Output the DIEs to represent all sub-blocks (and the items declared
20067 therein) of this block. */
20068 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20070 subblocks
= BLOCK_CHAIN (subblocks
))
20071 gen_block_die (subblocks
, context_die
, depth
+ 1);
20074 /* Is this a typedef we can avoid emitting? */
20077 is_redundant_typedef (const_tree decl
)
20079 if (TYPE_DECL_IS_STUB (decl
))
20082 if (DECL_ARTIFICIAL (decl
)
20083 && DECL_CONTEXT (decl
)
20084 && is_tagged_type (DECL_CONTEXT (decl
))
20085 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20086 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20087 /* Also ignore the artificial member typedef for the class name. */
20093 /* Return TRUE if TYPE is a typedef that names a type for linkage
20094 purposes. This kind of typedefs is produced by the C++ FE for
20097 typedef struct {...} foo;
20099 In that case, there is no typedef variant type produced for foo.
20100 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20104 is_naming_typedef_decl (const_tree decl
)
20106 if (decl
== NULL_TREE
20107 || TREE_CODE (decl
) != TYPE_DECL
20108 || !is_tagged_type (TREE_TYPE (decl
))
20109 || DECL_IS_BUILTIN (decl
)
20110 || is_redundant_typedef (decl
)
20111 /* It looks like Ada produces TYPE_DECLs that are very similar
20112 to C++ naming typedefs but that have different
20113 semantics. Let's be specific to c++ for now. */
20117 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20118 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20119 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20120 != TYPE_NAME (TREE_TYPE (decl
))));
20123 /* Returns the DIE for a context. */
20125 static inline dw_die_ref
20126 get_context_die (tree context
)
20130 /* Find die that represents this context. */
20131 if (TYPE_P (context
))
20133 context
= TYPE_MAIN_VARIANT (context
);
20134 return strip_naming_typedef (context
, force_type_die (context
));
20137 return force_decl_die (context
);
20139 return comp_unit_die ();
20142 /* Returns the DIE for decl. A DIE will always be returned. */
20145 force_decl_die (tree decl
)
20147 dw_die_ref decl_die
;
20148 unsigned saved_external_flag
;
20149 tree save_fn
= NULL_TREE
;
20150 decl_die
= lookup_decl_die (decl
);
20153 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20155 decl_die
= lookup_decl_die (decl
);
20159 switch (TREE_CODE (decl
))
20161 case FUNCTION_DECL
:
20162 /* Clear current_function_decl, so that gen_subprogram_die thinks
20163 that this is a declaration. At this point, we just want to force
20164 declaration die. */
20165 save_fn
= current_function_decl
;
20166 current_function_decl
= NULL_TREE
;
20167 gen_subprogram_die (decl
, context_die
);
20168 current_function_decl
= save_fn
;
20172 /* Set external flag to force declaration die. Restore it after
20173 gen_decl_die() call. */
20174 saved_external_flag
= DECL_EXTERNAL (decl
);
20175 DECL_EXTERNAL (decl
) = 1;
20176 gen_decl_die (decl
, NULL
, context_die
);
20177 DECL_EXTERNAL (decl
) = saved_external_flag
;
20180 case NAMESPACE_DECL
:
20181 if (dwarf_version
>= 3 || !dwarf_strict
)
20182 dwarf2out_decl (decl
);
20184 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20185 decl_die
= comp_unit_die ();
20188 case TRANSLATION_UNIT_DECL
:
20189 decl_die
= comp_unit_die ();
20193 gcc_unreachable ();
20196 /* We should be able to find the DIE now. */
20198 decl_die
= lookup_decl_die (decl
);
20199 gcc_assert (decl_die
);
20205 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20206 always returned. */
20209 force_type_die (tree type
)
20211 dw_die_ref type_die
;
20213 type_die
= lookup_type_die (type
);
20216 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20218 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20219 TYPE_VOLATILE (type
), context_die
);
20220 gcc_assert (type_die
);
20225 /* Force out any required namespaces to be able to output DECL,
20226 and return the new context_die for it, if it's changed. */
20229 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20231 tree context
= (DECL_P (thing
)
20232 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20233 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20234 /* Force out the namespace. */
20235 context_die
= force_decl_die (context
);
20237 return context_die
;
20240 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20241 type) within its namespace, if appropriate.
20243 For compatibility with older debuggers, namespace DIEs only contain
20244 declarations; all definitions are emitted at CU scope. */
20247 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20249 dw_die_ref ns_context
;
20251 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20252 return context_die
;
20254 /* If this decl is from an inlined function, then don't try to emit it in its
20255 namespace, as we will get confused. It would have already been emitted
20256 when the abstract instance of the inline function was emitted anyways. */
20257 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20258 return context_die
;
20260 ns_context
= setup_namespace_context (thing
, context_die
);
20262 if (ns_context
!= context_die
)
20266 if (DECL_P (thing
))
20267 gen_decl_die (thing
, NULL
, ns_context
);
20269 gen_type_die (thing
, ns_context
);
20271 return context_die
;
20274 /* Generate a DIE for a namespace or namespace alias. */
20277 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20279 dw_die_ref namespace_die
;
20281 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20282 they are an alias of. */
20283 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20285 /* Output a real namespace or module. */
20286 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20287 namespace_die
= new_die (is_fortran ()
20288 ? DW_TAG_module
: DW_TAG_namespace
,
20289 context_die
, decl
);
20290 /* For Fortran modules defined in different CU don't add src coords. */
20291 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20293 const char *name
= dwarf2_name (decl
, 0);
20295 add_name_attribute (namespace_die
, name
);
20298 add_name_and_src_coords_attributes (namespace_die
, decl
);
20299 if (DECL_EXTERNAL (decl
))
20300 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20301 equate_decl_number_to_die (decl
, namespace_die
);
20305 /* Output a namespace alias. */
20307 /* Force out the namespace we are an alias of, if necessary. */
20308 dw_die_ref origin_die
20309 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20311 if (DECL_FILE_SCOPE_P (decl
)
20312 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20313 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20314 /* Now create the namespace alias DIE. */
20315 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20316 add_name_and_src_coords_attributes (namespace_die
, decl
);
20317 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20318 equate_decl_number_to_die (decl
, namespace_die
);
20320 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20321 if (want_pubnames ())
20322 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20325 /* Generate Dwarf debug information for a decl described by DECL.
20326 The return value is currently only meaningful for PARM_DECLs,
20327 for all other decls it returns NULL. */
20330 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20332 tree decl_or_origin
= decl
? decl
: origin
;
20333 tree class_origin
= NULL
, ultimate_origin
;
20335 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20338 switch (TREE_CODE (decl_or_origin
))
20344 if (!is_fortran () && !is_ada ())
20346 /* The individual enumerators of an enum type get output when we output
20347 the Dwarf representation of the relevant enum type itself. */
20351 /* Emit its type. */
20352 gen_type_die (TREE_TYPE (decl
), context_die
);
20354 /* And its containing namespace. */
20355 context_die
= declare_in_namespace (decl
, context_die
);
20357 gen_const_die (decl
, context_die
);
20360 case FUNCTION_DECL
:
20361 /* Don't output any DIEs to represent mere function declarations,
20362 unless they are class members or explicit block externs. */
20363 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20364 && DECL_FILE_SCOPE_P (decl_or_origin
)
20365 && (current_function_decl
== NULL_TREE
20366 || DECL_ARTIFICIAL (decl_or_origin
)))
20371 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20372 on local redeclarations of global functions. That seems broken. */
20373 if (current_function_decl
!= decl
)
20374 /* This is only a declaration. */;
20377 /* If we're emitting a clone, emit info for the abstract instance. */
20378 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20379 dwarf2out_abstract_function (origin
20380 ? DECL_ORIGIN (origin
)
20381 : DECL_ABSTRACT_ORIGIN (decl
));
20383 /* If we're emitting an out-of-line copy of an inline function,
20384 emit info for the abstract instance and set up to refer to it. */
20385 else if (cgraph_function_possibly_inlined_p (decl
)
20386 && ! DECL_ABSTRACT (decl
)
20387 && ! class_or_namespace_scope_p (context_die
)
20388 /* dwarf2out_abstract_function won't emit a die if this is just
20389 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20390 that case, because that works only if we have a die. */
20391 && DECL_INITIAL (decl
) != NULL_TREE
)
20393 dwarf2out_abstract_function (decl
);
20394 set_decl_origin_self (decl
);
20397 /* Otherwise we're emitting the primary DIE for this decl. */
20398 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20400 /* Before we describe the FUNCTION_DECL itself, make sure that we
20401 have its containing type. */
20403 origin
= decl_class_context (decl
);
20404 if (origin
!= NULL_TREE
)
20405 gen_type_die (origin
, context_die
);
20407 /* And its return type. */
20408 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20410 /* And its virtual context. */
20411 if (DECL_VINDEX (decl
) != NULL_TREE
)
20412 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20414 /* Make sure we have a member DIE for decl. */
20415 if (origin
!= NULL_TREE
)
20416 gen_type_die_for_member (origin
, decl
, context_die
);
20418 /* And its containing namespace. */
20419 context_die
= declare_in_namespace (decl
, context_die
);
20422 /* Now output a DIE to represent the function itself. */
20424 gen_subprogram_die (decl
, context_die
);
20428 /* If we are in terse mode, don't generate any DIEs to represent any
20429 actual typedefs. */
20430 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20433 /* In the special case of a TYPE_DECL node representing the declaration
20434 of some type tag, if the given TYPE_DECL is marked as having been
20435 instantiated from some other (original) TYPE_DECL node (e.g. one which
20436 was generated within the original definition of an inline function) we
20437 used to generate a special (abbreviated) DW_TAG_structure_type,
20438 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20439 should be actually referencing those DIEs, as variable DIEs with that
20440 type would be emitted already in the abstract origin, so it was always
20441 removed during unused type prunning. Don't add anything in this
20443 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20446 if (is_redundant_typedef (decl
))
20447 gen_type_die (TREE_TYPE (decl
), context_die
);
20449 /* Output a DIE to represent the typedef itself. */
20450 gen_typedef_die (decl
, context_die
);
20454 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20455 gen_label_die (decl
, context_die
);
20460 /* If we are in terse mode, don't generate any DIEs to represent any
20461 variable declarations or definitions. */
20462 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20465 /* Output any DIEs that are needed to specify the type of this data
20467 if (decl_by_reference_p (decl_or_origin
))
20468 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20470 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20472 /* And its containing type. */
20473 class_origin
= decl_class_context (decl_or_origin
);
20474 if (class_origin
!= NULL_TREE
)
20475 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20477 /* And its containing namespace. */
20478 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20480 /* Now output the DIE to represent the data object itself. This gets
20481 complicated because of the possibility that the VAR_DECL really
20482 represents an inlined instance of a formal parameter for an inline
20484 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20485 if (ultimate_origin
!= NULL_TREE
20486 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20487 gen_formal_parameter_die (decl
, origin
,
20488 true /* Emit name attribute. */,
20491 gen_variable_die (decl
, origin
, context_die
);
20495 /* Ignore the nameless fields that are used to skip bits but handle C++
20496 anonymous unions and structs. */
20497 if (DECL_NAME (decl
) != NULL_TREE
20498 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20499 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20501 gen_type_die (member_declared_type (decl
), context_die
);
20502 gen_field_die (decl
, context_die
);
20507 if (DECL_BY_REFERENCE (decl_or_origin
))
20508 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20510 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20511 return gen_formal_parameter_die (decl
, origin
,
20512 true /* Emit name attribute. */,
20515 case NAMESPACE_DECL
:
20516 case IMPORTED_DECL
:
20517 if (dwarf_version
>= 3 || !dwarf_strict
)
20518 gen_namespace_die (decl
, context_die
);
20521 case NAMELIST_DECL
:
20522 gen_namelist_decl (DECL_NAME (decl
), context_die
,
20523 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
20527 /* Probably some frontend-internal decl. Assume we don't care. */
20528 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20535 /* Output debug information for global decl DECL. Called from toplev.c after
20536 compilation proper has finished. */
20539 dwarf2out_global_decl (tree decl
)
20541 /* Output DWARF2 information for file-scope tentative data object
20542 declarations, file-scope (extern) function declarations (which
20543 had no corresponding body) and file-scope tagged type declarations
20544 and definitions which have not yet been forced out. */
20545 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20546 dwarf2out_decl (decl
);
20549 /* Output debug information for type decl DECL. Called from toplev.c
20550 and from language front ends (to record built-in types). */
20552 dwarf2out_type_decl (tree decl
, int local
)
20555 dwarf2out_decl (decl
);
20558 /* Output debug information for imported module or decl DECL.
20559 NAME is non-NULL name in the lexical block if the decl has been renamed.
20560 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20561 that DECL belongs to.
20562 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20564 dwarf2out_imported_module_or_decl_1 (tree decl
,
20566 tree lexical_block
,
20567 dw_die_ref lexical_block_die
)
20569 expanded_location xloc
;
20570 dw_die_ref imported_die
= NULL
;
20571 dw_die_ref at_import_die
;
20573 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20575 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20576 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20580 xloc
= expand_location (input_location
);
20582 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20584 at_import_die
= force_type_die (TREE_TYPE (decl
));
20585 /* For namespace N { typedef void T; } using N::T; base_type_die
20586 returns NULL, but DW_TAG_imported_declaration requires
20587 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20588 if (!at_import_die
)
20590 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20591 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20592 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20593 gcc_assert (at_import_die
);
20598 at_import_die
= lookup_decl_die (decl
);
20599 if (!at_import_die
)
20601 /* If we're trying to avoid duplicate debug info, we may not have
20602 emitted the member decl for this field. Emit it now. */
20603 if (TREE_CODE (decl
) == FIELD_DECL
)
20605 tree type
= DECL_CONTEXT (decl
);
20607 if (TYPE_CONTEXT (type
)
20608 && TYPE_P (TYPE_CONTEXT (type
))
20609 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20610 DINFO_USAGE_DIR_USE
))
20612 gen_type_die_for_member (type
, decl
,
20613 get_context_die (TYPE_CONTEXT (type
)));
20615 if (TREE_CODE (decl
) == NAMELIST_DECL
)
20616 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
20617 get_context_die (DECL_CONTEXT (decl
)),
20620 at_import_die
= force_decl_die (decl
);
20624 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20626 if (dwarf_version
>= 3 || !dwarf_strict
)
20627 imported_die
= new_die (DW_TAG_imported_module
,
20634 imported_die
= new_die (DW_TAG_imported_declaration
,
20638 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20639 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20641 add_AT_string (imported_die
, DW_AT_name
,
20642 IDENTIFIER_POINTER (name
));
20643 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20646 /* Output debug information for imported module or decl DECL.
20647 NAME is non-NULL name in context if the decl has been renamed.
20648 CHILD is true if decl is one of the renamed decls as part of
20649 importing whole module. */
20652 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20655 /* dw_die_ref at_import_die; */
20656 dw_die_ref scope_die
;
20658 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20663 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20664 We need decl DIE for reference and scope die. First, get DIE for the decl
20667 /* Get the scope die for decl context. Use comp_unit_die for global module
20668 or decl. If die is not found for non globals, force new die. */
20670 && TYPE_P (context
)
20671 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20674 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20677 scope_die
= get_context_die (context
);
20681 gcc_assert (scope_die
->die_child
);
20682 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20683 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20684 scope_die
= scope_die
->die_child
;
20687 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20688 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20692 /* Output debug information for namelists. */
20695 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
20697 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
20701 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20704 gcc_assert (scope_die
!= NULL
);
20705 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
20706 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
20708 /* If there are no item_decls, we have a nondefining namelist, e.g.
20709 with USE association; hence, set DW_AT_declaration. */
20710 if (item_decls
== NULL_TREE
)
20712 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
20716 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
20718 nml_item_ref_die
= lookup_decl_die (value
);
20719 if (!nml_item_ref_die
)
20720 nml_item_ref_die
= force_decl_die (value
);
20722 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
20723 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
20729 /* Write the debugging output for DECL. */
20732 dwarf2out_decl (tree decl
)
20734 dw_die_ref context_die
= comp_unit_die ();
20736 switch (TREE_CODE (decl
))
20741 case FUNCTION_DECL
:
20742 /* What we would really like to do here is to filter out all mere
20743 file-scope declarations of file-scope functions which are never
20744 referenced later within this translation unit (and keep all of ones
20745 that *are* referenced later on) but we aren't clairvoyant, so we have
20746 no idea which functions will be referenced in the future (i.e. later
20747 on within the current translation unit). So here we just ignore all
20748 file-scope function declarations which are not also definitions. If
20749 and when the debugger needs to know something about these functions,
20750 it will have to hunt around and find the DWARF information associated
20751 with the definition of the function.
20753 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20754 nodes represent definitions and which ones represent mere
20755 declarations. We have to check DECL_INITIAL instead. That's because
20756 the C front-end supports some weird semantics for "extern inline"
20757 function definitions. These can get inlined within the current
20758 translation unit (and thus, we need to generate Dwarf info for their
20759 abstract instances so that the Dwarf info for the concrete inlined
20760 instances can have something to refer to) but the compiler never
20761 generates any out-of-lines instances of such things (despite the fact
20762 that they *are* definitions).
20764 The important point is that the C front-end marks these "extern
20765 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20766 them anyway. Note that the C++ front-end also plays some similar games
20767 for inline function definitions appearing within include files which
20768 also contain `#pragma interface' pragmas.
20770 If we are called from dwarf2out_abstract_function output a DIE
20771 anyway. We can end up here this way with early inlining and LTO
20772 where the inlined function is output in a different LTRANS unit
20774 if (DECL_INITIAL (decl
) == NULL_TREE
20775 && ! DECL_ABSTRACT (decl
))
20778 /* If we're a nested function, initially use a parent of NULL; if we're
20779 a plain function, this will be fixed up in decls_for_scope. If
20780 we're a method, it will be ignored, since we already have a DIE. */
20781 if (decl_function_context (decl
)
20782 /* But if we're in terse mode, we don't care about scope. */
20783 && debug_info_level
> DINFO_LEVEL_TERSE
)
20784 context_die
= NULL
;
20788 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20789 declaration and if the declaration was never even referenced from
20790 within this entire compilation unit. We suppress these DIEs in
20791 order to save space in the .debug section (by eliminating entries
20792 which are probably useless). Note that we must not suppress
20793 block-local extern declarations (whether used or not) because that
20794 would screw-up the debugger's name lookup mechanism and cause it to
20795 miss things which really ought to be in scope at a given point. */
20796 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20799 /* For local statics lookup proper context die. */
20800 if (TREE_STATIC (decl
)
20801 && DECL_CONTEXT (decl
)
20802 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20803 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20805 /* If we are in terse mode, don't generate any DIEs to represent any
20806 variable declarations or definitions. */
20807 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20812 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20814 if (!is_fortran () && !is_ada ())
20816 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20817 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20820 case NAMESPACE_DECL
:
20821 case IMPORTED_DECL
:
20822 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20824 if (lookup_decl_die (decl
) != NULL
)
20829 /* Don't emit stubs for types unless they are needed by other DIEs. */
20830 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20833 /* Don't bother trying to generate any DIEs to represent any of the
20834 normal built-in types for the language we are compiling. */
20835 if (DECL_IS_BUILTIN (decl
))
20838 /* If we are in terse mode, don't generate any DIEs for types. */
20839 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20842 /* If we're a function-scope tag, initially use a parent of NULL;
20843 this will be fixed up in decls_for_scope. */
20844 if (decl_function_context (decl
))
20845 context_die
= NULL
;
20849 case NAMELIST_DECL
:
20856 gen_decl_die (decl
, NULL
, context_die
);
20859 /* Write the debugging output for DECL. */
20862 dwarf2out_function_decl (tree decl
)
20864 dwarf2out_decl (decl
);
20865 call_arg_locations
= NULL
;
20866 call_arg_loc_last
= NULL
;
20867 call_site_count
= -1;
20868 tail_call_site_count
= -1;
20869 block_map
.release ();
20870 htab_empty (decl_loc_table
);
20871 htab_empty (cached_dw_loc_list_table
);
20874 /* Output a marker (i.e. a label) for the beginning of the generated code for
20875 a lexical block. */
20878 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20879 unsigned int blocknum
)
20881 switch_to_section (current_function_section ());
20882 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20885 /* Output a marker (i.e. a label) for the end of the generated code for a
20889 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20891 switch_to_section (current_function_section ());
20892 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20895 /* Returns nonzero if it is appropriate not to emit any debugging
20896 information for BLOCK, because it doesn't contain any instructions.
20898 Don't allow this for blocks with nested functions or local classes
20899 as we would end up with orphans, and in the presence of scheduling
20900 we may end up calling them anyway. */
20903 dwarf2out_ignore_block (const_tree block
)
20908 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20909 if (TREE_CODE (decl
) == FUNCTION_DECL
20910 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20912 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20914 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20915 if (TREE_CODE (decl
) == FUNCTION_DECL
20916 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20923 /* Hash table routines for file_hash. */
20926 file_table_eq (const void *p1_p
, const void *p2_p
)
20928 const struct dwarf_file_data
*const p1
=
20929 (const struct dwarf_file_data
*) p1_p
;
20930 const char *const p2
= (const char *) p2_p
;
20931 return filename_cmp (p1
->filename
, p2
) == 0;
20935 file_table_hash (const void *p_p
)
20937 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20938 return htab_hash_string (p
->filename
);
20941 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20942 dwarf2out.c) and return its "index". The index of each (known) filename is
20943 just a unique number which is associated with only that one filename. We
20944 need such numbers for the sake of generating labels (in the .debug_sfnames
20945 section) and references to those files numbers (in the .debug_srcinfo
20946 and.debug_macinfo sections). If the filename given as an argument is not
20947 found in our current list, add it to the list and assign it the next
20948 available unique index number. In order to speed up searches, we remember
20949 the index of the filename was looked up last. This handles the majority of
20952 static struct dwarf_file_data
*
20953 lookup_filename (const char *file_name
)
20956 struct dwarf_file_data
* created
;
20958 /* Check to see if the file name that was searched on the previous
20959 call matches this file name. If so, return the index. */
20960 if (file_table_last_lookup
20961 && (file_name
== file_table_last_lookup
->filename
20962 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20963 return file_table_last_lookup
;
20965 /* Didn't match the previous lookup, search the table. */
20966 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20967 htab_hash_string (file_name
), INSERT
);
20969 return (struct dwarf_file_data
*) *slot
;
20971 created
= ggc_alloc_dwarf_file_data ();
20972 created
->filename
= file_name
;
20973 created
->emitted_number
= 0;
20978 /* If the assembler will construct the file table, then translate the compiler
20979 internal file table number into the assembler file table number, and emit
20980 a .file directive if we haven't already emitted one yet. The file table
20981 numbers are different because we prune debug info for unused variables and
20982 types, which may include filenames. */
20985 maybe_emit_file (struct dwarf_file_data
* fd
)
20987 if (! fd
->emitted_number
)
20989 if (last_emitted_file
)
20990 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20992 fd
->emitted_number
= 1;
20993 last_emitted_file
= fd
;
20995 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20997 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20998 output_quoted_string (asm_out_file
,
20999 remap_debug_filename (fd
->filename
));
21000 fputc ('\n', asm_out_file
);
21004 return fd
->emitted_number
;
21007 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21008 That generation should happen after function debug info has been
21009 generated. The value of the attribute is the constant value of ARG. */
21012 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21014 die_arg_entry entry
;
21019 if (!tmpl_value_parm_die_table
)
21020 vec_alloc (tmpl_value_parm_die_table
, 32);
21024 vec_safe_push (tmpl_value_parm_die_table
, entry
);
21027 /* Return TRUE if T is an instance of generic type, FALSE
21031 generic_type_p (tree t
)
21033 if (t
== NULL_TREE
|| !TYPE_P (t
))
21035 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
21038 /* Schedule the generation of the generic parameter dies for the
21039 instance of generic type T. The proper generation itself is later
21040 done by gen_scheduled_generic_parms_dies. */
21043 schedule_generic_params_dies_gen (tree t
)
21045 if (!generic_type_p (t
))
21048 if (!generic_type_instances
)
21049 vec_alloc (generic_type_instances
, 256);
21051 vec_safe_push (generic_type_instances
, t
);
21054 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21055 by append_entry_to_tmpl_value_parm_die_table. This function must
21056 be called after function DIEs have been generated. */
21059 gen_remaining_tmpl_value_param_die_attribute (void)
21061 if (tmpl_value_parm_die_table
)
21066 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
21067 tree_add_const_value_attribute (e
->die
, e
->arg
);
21071 /* Generate generic parameters DIEs for instances of generic types
21072 that have been previously scheduled by
21073 schedule_generic_params_dies_gen. This function must be called
21074 after all the types of the CU have been laid out. */
21077 gen_scheduled_generic_parms_dies (void)
21082 if (!generic_type_instances
)
21085 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
21086 if (COMPLETE_TYPE_P (t
))
21087 gen_generic_params_dies (t
);
21091 /* Replace DW_AT_name for the decl with name. */
21094 dwarf2out_set_name (tree decl
, tree name
)
21100 die
= TYPE_SYMTAB_DIE (decl
);
21104 dname
= dwarf2_name (name
, 0);
21108 attr
= get_AT (die
, DW_AT_name
);
21111 struct indirect_string_node
*node
;
21113 node
= find_AT_string (dname
);
21114 /* replace the string. */
21115 attr
->dw_attr_val
.v
.val_str
= node
;
21119 add_name_attribute (die
, dname
);
21122 /* True if before or during processing of the first function being emitted. */
21123 static bool in_first_function_p
= true;
21124 /* True if loc_note during dwarf2out_var_location call might still be
21125 before first real instruction at address equal to .Ltext0. */
21126 static bool maybe_at_text_label_p
= true;
21127 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
21128 static unsigned int first_loclabel_num_not_at_text_label
;
21130 /* Called by the final INSN scan whenever we see a var location. We
21131 use it to drop labels in the right places, and throw the location in
21132 our lookup table. */
21135 dwarf2out_var_location (rtx loc_note
)
21137 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21138 struct var_loc_node
*newloc
;
21139 rtx next_real
, next_note
;
21140 static const char *last_label
;
21141 static const char *last_postcall_label
;
21142 static bool last_in_cold_section_p
;
21143 static rtx expected_next_loc_note
;
21147 if (!NOTE_P (loc_note
))
21149 if (CALL_P (loc_note
))
21152 if (SIBLING_CALL_P (loc_note
))
21153 tail_call_site_count
++;
21158 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21159 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21162 /* Optimize processing a large consecutive sequence of location
21163 notes so we don't spend too much time in next_real_insn. If the
21164 next insn is another location note, remember the next_real_insn
21165 calculation for next time. */
21166 next_real
= cached_next_real_insn
;
21169 if (expected_next_loc_note
!= loc_note
)
21170 next_real
= NULL_RTX
;
21173 next_note
= NEXT_INSN (loc_note
);
21175 || INSN_DELETED_P (next_note
)
21176 || ! NOTE_P (next_note
)
21177 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21178 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21179 next_note
= NULL_RTX
;
21182 next_real
= next_real_insn (loc_note
);
21186 expected_next_loc_note
= next_note
;
21187 cached_next_real_insn
= next_real
;
21190 cached_next_real_insn
= NULL_RTX
;
21192 /* If there are no instructions which would be affected by this note,
21193 don't do anything. */
21195 && next_real
== NULL_RTX
21196 && !NOTE_DURING_CALL_P (loc_note
))
21199 if (next_real
== NULL_RTX
)
21200 next_real
= get_last_insn ();
21202 /* If there were any real insns between note we processed last time
21203 and this note (or if it is the first note), clear
21204 last_{,postcall_}label so that they are not reused this time. */
21205 if (last_var_location_insn
== NULL_RTX
21206 || last_var_location_insn
!= next_real
21207 || last_in_cold_section_p
!= in_cold_section_p
)
21210 last_postcall_label
= NULL
;
21215 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21216 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21217 NOTE_DURING_CALL_P (loc_note
)
21218 ? last_postcall_label
: last_label
);
21219 if (newloc
== NULL
)
21228 /* If there were no real insns between note we processed last time
21229 and this note, use the label we emitted last time. Otherwise
21230 create a new label and emit it. */
21231 if (last_label
== NULL
)
21233 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21234 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21236 last_label
= ggc_strdup (loclabel
);
21237 /* See if loclabel might be equal to .Ltext0. If yes,
21238 bump first_loclabel_num_not_at_text_label. */
21239 if (!have_multiple_function_sections
21240 && in_first_function_p
21241 && maybe_at_text_label_p
)
21243 static rtx last_start
;
21245 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21246 if (insn
== last_start
)
21248 else if (!NONDEBUG_INSN_P (insn
))
21252 rtx body
= PATTERN (insn
);
21253 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21255 /* Inline asm could occupy zero bytes. */
21256 else if (GET_CODE (body
) == ASM_INPUT
21257 || asm_noperands (body
) >= 0)
21259 #ifdef HAVE_attr_length
21260 else if (get_attr_min_length (insn
) == 0)
21265 /* Assume insn has non-zero length. */
21266 maybe_at_text_label_p
= false;
21270 if (maybe_at_text_label_p
)
21272 last_start
= loc_note
;
21273 first_loclabel_num_not_at_text_label
= loclabel_num
;
21280 struct call_arg_loc_node
*ca_loc
21281 = ggc_alloc_cleared_call_arg_loc_node ();
21282 rtx prev
= prev_real_insn (loc_note
), x
;
21283 ca_loc
->call_arg_loc_note
= loc_note
;
21284 ca_loc
->next
= NULL
;
21285 ca_loc
->label
= last_label
;
21288 || (NONJUMP_INSN_P (prev
)
21289 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21290 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21291 if (!CALL_P (prev
))
21292 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21293 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21294 x
= get_call_rtx_from (PATTERN (prev
));
21297 x
= XEXP (XEXP (x
, 0), 0);
21298 if (GET_CODE (x
) == SYMBOL_REF
21299 && SYMBOL_REF_DECL (x
)
21300 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21301 ca_loc
->symbol_ref
= x
;
21303 ca_loc
->block
= insn_scope (prev
);
21304 if (call_arg_locations
)
21305 call_arg_loc_last
->next
= ca_loc
;
21307 call_arg_locations
= ca_loc
;
21308 call_arg_loc_last
= ca_loc
;
21310 else if (!NOTE_DURING_CALL_P (loc_note
))
21311 newloc
->label
= last_label
;
21314 if (!last_postcall_label
)
21316 sprintf (loclabel
, "%s-1", last_label
);
21317 last_postcall_label
= ggc_strdup (loclabel
);
21319 newloc
->label
= last_postcall_label
;
21322 last_var_location_insn
= next_real
;
21323 last_in_cold_section_p
= in_cold_section_p
;
21326 /* Note in one location list that text section has changed. */
21329 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21331 var_loc_list
*list
= (var_loc_list
*) *slot
;
21333 list
->last_before_switch
21334 = list
->last
->next
? list
->last
->next
: list
->last
;
21338 /* Note in all location lists that text section has changed. */
21341 var_location_switch_text_section (void)
21343 if (decl_loc_table
== NULL
)
21346 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21349 /* Create a new line number table. */
21351 static dw_line_info_table
*
21352 new_line_info_table (void)
21354 dw_line_info_table
*table
;
21356 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21357 table
->file_num
= 1;
21358 table
->line_num
= 1;
21359 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21364 /* Lookup the "current" table into which we emit line info, so
21365 that we don't have to do it for every source line. */
21368 set_cur_line_info_table (section
*sec
)
21370 dw_line_info_table
*table
;
21372 if (sec
== text_section
)
21373 table
= text_section_line_info
;
21374 else if (sec
== cold_text_section
)
21376 table
= cold_text_section_line_info
;
21379 cold_text_section_line_info
= table
= new_line_info_table ();
21380 table
->end_label
= cold_end_label
;
21385 const char *end_label
;
21387 if (flag_reorder_blocks_and_partition
)
21389 if (in_cold_section_p
)
21390 end_label
= crtl
->subsections
.cold_section_end_label
;
21392 end_label
= crtl
->subsections
.hot_section_end_label
;
21396 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21397 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21398 current_function_funcdef_no
);
21399 end_label
= ggc_strdup (label
);
21402 table
= new_line_info_table ();
21403 table
->end_label
= end_label
;
21405 vec_safe_push (separate_line_info
, table
);
21408 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21409 table
->is_stmt
= (cur_line_info_table
21410 ? cur_line_info_table
->is_stmt
21411 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21412 cur_line_info_table
= table
;
21416 /* We need to reset the locations at the beginning of each
21417 function. We can't do this in the end_function hook, because the
21418 declarations that use the locations won't have been output when
21419 that hook is called. Also compute have_multiple_function_sections here. */
21422 dwarf2out_begin_function (tree fun
)
21424 section
*sec
= function_section (fun
);
21426 if (sec
!= text_section
)
21427 have_multiple_function_sections
= true;
21429 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21431 gcc_assert (current_function_decl
== fun
);
21432 cold_text_section
= unlikely_text_section ();
21433 switch_to_section (cold_text_section
);
21434 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21435 switch_to_section (sec
);
21438 dwarf2out_note_section_used ();
21439 call_site_count
= 0;
21440 tail_call_site_count
= 0;
21442 set_cur_line_info_table (sec
);
21445 /* Helper function of dwarf2out_end_function, called only after emitting
21446 the very first function into assembly. Check if some .debug_loc range
21447 might end with a .LVL* label that could be equal to .Ltext0.
21448 In that case we must force using absolute addresses in .debug_loc ranges,
21449 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21450 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21452 Set have_multiple_function_sections to true in that case and
21453 terminate htab traversal. */
21456 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21458 var_loc_list
*entry
;
21459 struct var_loc_node
*node
;
21461 entry
= (var_loc_list
*) *slot
;
21462 node
= entry
->first
;
21463 if (node
&& node
->next
&& node
->next
->label
)
21466 const char *label
= node
->next
->label
;
21467 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21469 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21471 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21472 if (strcmp (label
, loclabel
) == 0)
21474 have_multiple_function_sections
= true;
21482 /* Hook called after emitting a function into assembly.
21483 This does something only for the very first function emitted. */
21486 dwarf2out_end_function (unsigned int)
21488 if (in_first_function_p
21489 && !have_multiple_function_sections
21490 && first_loclabel_num_not_at_text_label
21492 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21494 in_first_function_p
= false;
21495 maybe_at_text_label_p
= false;
21498 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21501 push_dw_line_info_entry (dw_line_info_table
*table
,
21502 enum dw_line_info_opcode opcode
, unsigned int val
)
21504 dw_line_info_entry e
;
21507 vec_safe_push (table
->entries
, e
);
21510 /* Output a label to mark the beginning of a source code line entry
21511 and record information relating to this source line, in
21512 'line_info_table' for later output of the .debug_line section. */
21513 /* ??? The discriminator parameter ought to be unsigned. */
21516 dwarf2out_source_line (unsigned int line
, const char *filename
,
21517 int discriminator
, bool is_stmt
)
21519 unsigned int file_num
;
21520 dw_line_info_table
*table
;
21522 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21525 /* The discriminator column was added in dwarf4. Simplify the below
21526 by simply removing it if we're not supposed to output it. */
21527 if (dwarf_version
< 4 && dwarf_strict
)
21530 table
= cur_line_info_table
;
21531 file_num
= maybe_emit_file (lookup_filename (filename
));
21533 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21534 the debugger has used the second (possibly duplicate) line number
21535 at the beginning of the function to mark the end of the prologue.
21536 We could eliminate any other duplicates within the function. For
21537 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21538 that second line number entry. */
21539 /* Recall that this end-of-prologue indication is *not* the same thing
21540 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21541 to which the hook corresponds, follows the last insn that was
21542 emitted by gen_prologue. What we need is to precede the first insn
21543 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21544 insn that corresponds to something the user wrote. These may be
21545 very different locations once scheduling is enabled. */
21547 if (0 && file_num
== table
->file_num
21548 && line
== table
->line_num
21549 && discriminator
== table
->discrim_num
21550 && is_stmt
== table
->is_stmt
)
21553 switch_to_section (current_function_section ());
21555 /* If requested, emit something human-readable. */
21556 if (flag_debug_asm
)
21557 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21559 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21561 /* Emit the .loc directive understood by GNU as. */
21562 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21563 file_num, line, is_stmt, discriminator */
21564 fputs ("\t.loc ", asm_out_file
);
21565 fprint_ul (asm_out_file
, file_num
);
21566 putc (' ', asm_out_file
);
21567 fprint_ul (asm_out_file
, line
);
21568 putc (' ', asm_out_file
);
21569 putc ('0', asm_out_file
);
21571 if (is_stmt
!= table
->is_stmt
)
21573 fputs (" is_stmt ", asm_out_file
);
21574 putc (is_stmt
? '1' : '0', asm_out_file
);
21576 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21578 gcc_assert (discriminator
> 0);
21579 fputs (" discriminator ", asm_out_file
);
21580 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21582 putc ('\n', asm_out_file
);
21586 unsigned int label_num
= ++line_info_label_num
;
21588 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21590 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21591 if (file_num
!= table
->file_num
)
21592 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21593 if (discriminator
!= table
->discrim_num
)
21594 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21595 if (is_stmt
!= table
->is_stmt
)
21596 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21597 push_dw_line_info_entry (table
, LI_set_line
, line
);
21600 table
->file_num
= file_num
;
21601 table
->line_num
= line
;
21602 table
->discrim_num
= discriminator
;
21603 table
->is_stmt
= is_stmt
;
21604 table
->in_use
= true;
21607 /* Record the beginning of a new source file. */
21610 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21612 if (flag_eliminate_dwarf2_dups
)
21614 /* Record the beginning of the file for break_out_includes. */
21615 dw_die_ref bincl_die
;
21617 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21618 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21621 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21624 e
.code
= DW_MACINFO_start_file
;
21626 e
.info
= ggc_strdup (filename
);
21627 vec_safe_push (macinfo_table
, e
);
21631 /* Record the end of a source file. */
21634 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21636 if (flag_eliminate_dwarf2_dups
)
21637 /* Record the end of the file for break_out_includes. */
21638 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21640 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21643 e
.code
= DW_MACINFO_end_file
;
21646 vec_safe_push (macinfo_table
, e
);
21650 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21651 the tail part of the directive line, i.e. the part which is past the
21652 initial whitespace, #, whitespace, directive-name, whitespace part. */
21655 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21656 const char *buffer ATTRIBUTE_UNUSED
)
21658 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21661 /* Insert a dummy first entry to be able to optimize the whole
21662 predefined macro block using DW_MACRO_GNU_transparent_include. */
21663 if (macinfo_table
->is_empty () && lineno
<= 1)
21668 vec_safe_push (macinfo_table
, e
);
21670 e
.code
= DW_MACINFO_define
;
21672 e
.info
= ggc_strdup (buffer
);
21673 vec_safe_push (macinfo_table
, e
);
21677 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21678 the tail part of the directive line, i.e. the part which is past the
21679 initial whitespace, #, whitespace, directive-name, whitespace part. */
21682 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21683 const char *buffer ATTRIBUTE_UNUSED
)
21685 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21688 /* Insert a dummy first entry to be able to optimize the whole
21689 predefined macro block using DW_MACRO_GNU_transparent_include. */
21690 if (macinfo_table
->is_empty () && lineno
<= 1)
21695 vec_safe_push (macinfo_table
, e
);
21697 e
.code
= DW_MACINFO_undef
;
21699 e
.info
= ggc_strdup (buffer
);
21700 vec_safe_push (macinfo_table
, e
);
21704 /* Helpers to manipulate hash table of CUs. */
21706 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21708 typedef macinfo_entry value_type
;
21709 typedef macinfo_entry compare_type
;
21710 static inline hashval_t
hash (const value_type
*);
21711 static inline bool equal (const value_type
*, const compare_type
*);
21715 macinfo_entry_hasher::hash (const value_type
*entry
)
21717 return htab_hash_string (entry
->info
);
21721 macinfo_entry_hasher::equal (const value_type
*entry1
,
21722 const compare_type
*entry2
)
21724 return !strcmp (entry1
->info
, entry2
->info
);
21727 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21729 /* Output a single .debug_macinfo entry. */
21732 output_macinfo_op (macinfo_entry
*ref
)
21736 struct indirect_string_node
*node
;
21737 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21738 struct dwarf_file_data
*fd
;
21742 case DW_MACINFO_start_file
:
21743 fd
= lookup_filename (ref
->info
);
21744 file_num
= maybe_emit_file (fd
);
21745 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21746 dw2_asm_output_data_uleb128 (ref
->lineno
,
21747 "Included from line number %lu",
21748 (unsigned long) ref
->lineno
);
21749 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21751 case DW_MACINFO_end_file
:
21752 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21754 case DW_MACINFO_define
:
21755 case DW_MACINFO_undef
:
21756 len
= strlen (ref
->info
) + 1;
21758 && len
> DWARF_OFFSET_SIZE
21759 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21760 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21762 ref
->code
= ref
->code
== DW_MACINFO_define
21763 ? DW_MACRO_GNU_define_indirect
21764 : DW_MACRO_GNU_undef_indirect
;
21765 output_macinfo_op (ref
);
21768 dw2_asm_output_data (1, ref
->code
,
21769 ref
->code
== DW_MACINFO_define
21770 ? "Define macro" : "Undefine macro");
21771 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21772 (unsigned long) ref
->lineno
);
21773 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21775 case DW_MACRO_GNU_define_indirect
:
21776 case DW_MACRO_GNU_undef_indirect
:
21777 node
= find_AT_string (ref
->info
);
21779 && ((node
->form
== DW_FORM_strp
)
21780 || (node
->form
== DW_FORM_GNU_str_index
)));
21781 dw2_asm_output_data (1, ref
->code
,
21782 ref
->code
== DW_MACRO_GNU_define_indirect
21783 ? "Define macro indirect"
21784 : "Undefine macro indirect");
21785 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21786 (unsigned long) ref
->lineno
);
21787 if (node
->form
== DW_FORM_strp
)
21788 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21789 debug_str_section
, "The macro: \"%s\"",
21792 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21795 case DW_MACRO_GNU_transparent_include
:
21796 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21797 ASM_GENERATE_INTERNAL_LABEL (label
,
21798 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21799 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21802 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21803 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21808 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21809 other compilation unit .debug_macinfo sections. IDX is the first
21810 index of a define/undef, return the number of ops that should be
21811 emitted in a comdat .debug_macinfo section and emit
21812 a DW_MACRO_GNU_transparent_include entry referencing it.
21813 If the define/undef entry should be emitted normally, return 0. */
21816 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21817 macinfo_hash_type
*macinfo_htab
)
21819 macinfo_entry
*first
, *second
, *cur
, *inc
;
21820 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21821 unsigned char checksum
[16];
21822 struct md5_ctx ctx
;
21823 char *grp_name
, *tail
;
21825 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21826 macinfo_entry
**slot
;
21828 first
= &(*macinfo_table
)[idx
];
21829 second
= &(*macinfo_table
)[idx
+ 1];
21831 /* Optimize only if there are at least two consecutive define/undef ops,
21832 and either all of them are before first DW_MACINFO_start_file
21833 with lineno {0,1} (i.e. predefined macro block), or all of them are
21834 in some included header file. */
21835 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21837 if (vec_safe_is_empty (files
))
21839 if (first
->lineno
> 1 || second
->lineno
> 1)
21842 else if (first
->lineno
== 0)
21845 /* Find the last define/undef entry that can be grouped together
21846 with first and at the same time compute md5 checksum of their
21847 codes, linenumbers and strings. */
21848 md5_init_ctx (&ctx
);
21849 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21850 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21852 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21856 unsigned char code
= cur
->code
;
21857 md5_process_bytes (&code
, 1, &ctx
);
21858 checksum_uleb128 (cur
->lineno
, &ctx
);
21859 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21861 md5_finish_ctx (&ctx
, checksum
);
21864 /* From the containing include filename (if any) pick up just
21865 usable characters from its basename. */
21866 if (vec_safe_is_empty (files
))
21869 base
= lbasename (files
->last ().info
);
21870 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21871 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21872 encoded_filename_len
++;
21873 /* Count . at the end. */
21874 if (encoded_filename_len
)
21875 encoded_filename_len
++;
21877 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21878 linebuf_len
= strlen (linebuf
);
21880 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21881 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21883 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21884 tail
= grp_name
+ 4;
21885 if (encoded_filename_len
)
21887 for (i
= 0; base
[i
]; i
++)
21888 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21892 memcpy (tail
, linebuf
, linebuf_len
);
21893 tail
+= linebuf_len
;
21895 for (i
= 0; i
< 16; i
++)
21896 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21898 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21899 in the empty vector entry before the first define/undef. */
21900 inc
= &(*macinfo_table
)[idx
- 1];
21901 inc
->code
= DW_MACRO_GNU_transparent_include
;
21903 inc
->info
= ggc_strdup (grp_name
);
21904 if (!macinfo_htab
->is_created ())
21905 macinfo_htab
->create (10);
21906 /* Avoid emitting duplicates. */
21907 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21912 /* If such an entry has been used before, just emit
21913 a DW_MACRO_GNU_transparent_include op. */
21915 output_macinfo_op (inc
);
21916 /* And clear all macinfo_entry in the range to avoid emitting them
21917 in the second pass. */
21918 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21927 inc
->lineno
= macinfo_htab
->elements ();
21928 output_macinfo_op (inc
);
21933 /* Save any strings needed by the macinfo table in the debug str
21934 table. All strings must be collected into the table by the time
21935 index_string is called. */
21938 save_macinfo_strings (void)
21942 macinfo_entry
*ref
;
21944 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21948 /* Match the logic in output_macinfo_op to decide on
21949 indirect strings. */
21950 case DW_MACINFO_define
:
21951 case DW_MACINFO_undef
:
21952 len
= strlen (ref
->info
) + 1;
21954 && len
> DWARF_OFFSET_SIZE
21955 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21956 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21957 set_indirect_string (find_AT_string (ref
->info
));
21959 case DW_MACRO_GNU_define_indirect
:
21960 case DW_MACRO_GNU_undef_indirect
:
21961 set_indirect_string (find_AT_string (ref
->info
));
21969 /* Output macinfo section(s). */
21972 output_macinfo (void)
21975 unsigned long length
= vec_safe_length (macinfo_table
);
21976 macinfo_entry
*ref
;
21977 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21978 macinfo_hash_type macinfo_htab
;
21983 /* output_macinfo* uses these interchangeably. */
21984 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21985 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21986 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21987 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21989 /* For .debug_macro emit the section header. */
21992 dw2_asm_output_data (2, 4, "DWARF macro version number");
21993 if (DWARF_OFFSET_SIZE
== 8)
21994 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21996 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21997 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21998 (!dwarf_split_debug_info
? debug_line_section_label
21999 : debug_skeleton_line_section_label
),
22000 debug_line_section
, NULL
);
22003 /* In the first loop, it emits the primary .debug_macinfo section
22004 and after each emitted op the macinfo_entry is cleared.
22005 If a longer range of define/undef ops can be optimized using
22006 DW_MACRO_GNU_transparent_include, the
22007 DW_MACRO_GNU_transparent_include op is emitted and kept in
22008 the vector before the first define/undef in the range and the
22009 whole range of define/undef ops is not emitted and kept. */
22010 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22014 case DW_MACINFO_start_file
:
22015 vec_safe_push (files
, *ref
);
22017 case DW_MACINFO_end_file
:
22018 if (!vec_safe_is_empty (files
))
22021 case DW_MACINFO_define
:
22022 case DW_MACINFO_undef
:
22024 && HAVE_COMDAT_GROUP
22025 && vec_safe_length (files
) != 1
22028 && (*macinfo_table
)[i
- 1].code
== 0)
22030 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
22039 /* A dummy entry may be inserted at the beginning to be able
22040 to optimize the whole block of predefined macros. */
22046 output_macinfo_op (ref
);
22051 if (!macinfo_htab
.is_created ())
22054 macinfo_htab
.dispose ();
22056 /* If any DW_MACRO_GNU_transparent_include were used, on those
22057 DW_MACRO_GNU_transparent_include entries terminate the
22058 current chain and switch to a new comdat .debug_macinfo
22059 section and emit the define/undef entries within it. */
22060 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22065 case DW_MACRO_GNU_transparent_include
:
22067 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22068 tree comdat_key
= get_identifier (ref
->info
);
22069 /* Terminate the previous .debug_macinfo section. */
22070 dw2_asm_output_data (1, 0, "End compilation unit");
22071 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
22073 | SECTION_LINKONCE
,
22075 ASM_GENERATE_INTERNAL_LABEL (label
,
22076 DEBUG_MACRO_SECTION_LABEL
,
22078 ASM_OUTPUT_LABEL (asm_out_file
, label
);
22081 dw2_asm_output_data (2, 4, "DWARF macro version number");
22082 if (DWARF_OFFSET_SIZE
== 8)
22083 dw2_asm_output_data (1, 1, "Flags: 64-bit");
22085 dw2_asm_output_data (1, 0, "Flags: 32-bit");
22088 case DW_MACINFO_define
:
22089 case DW_MACINFO_undef
:
22090 output_macinfo_op (ref
);
22095 gcc_unreachable ();
22099 /* Set up for Dwarf output at the start of compilation. */
22102 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
22104 /* Allocate the file_table. */
22105 file_table
= htab_create_ggc (50, file_table_hash
,
22106 file_table_eq
, NULL
);
22108 /* Allocate the decl_die_table. */
22109 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
22110 decl_die_table_eq
, NULL
);
22112 /* Allocate the decl_loc_table. */
22113 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
22114 decl_loc_table_eq
, NULL
);
22116 /* Allocate the cached_dw_loc_list_table. */
22117 cached_dw_loc_list_table
22118 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
22119 cached_dw_loc_list_table_eq
, NULL
);
22121 /* Allocate the initial hunk of the decl_scope_table. */
22122 vec_alloc (decl_scope_table
, 256);
22124 /* Allocate the initial hunk of the abbrev_die_table. */
22125 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
22126 (ABBREV_DIE_TABLE_INCREMENT
);
22127 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22128 /* Zero-th entry is allocated, but unused. */
22129 abbrev_die_table_in_use
= 1;
22131 /* Allocate the pubtypes and pubnames vectors. */
22132 vec_alloc (pubname_table
, 32);
22133 vec_alloc (pubtype_table
, 32);
22135 vec_alloc (incomplete_types
, 64);
22137 vec_alloc (used_rtx_array
, 32);
22139 if (!dwarf_split_debug_info
)
22141 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22142 SECTION_DEBUG
, NULL
);
22143 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22144 SECTION_DEBUG
, NULL
);
22145 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22146 SECTION_DEBUG
, NULL
);
22150 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22151 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22152 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22153 SECTION_DEBUG
| SECTION_EXCLUDE
,
22155 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22156 SECTION_DEBUG
, NULL
);
22157 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22158 SECTION_DEBUG
, NULL
);
22159 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22160 SECTION_DEBUG
, NULL
);
22161 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22162 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22164 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22165 the main .o, but the skeleton_line goes into the split off dwo. */
22166 debug_skeleton_line_section
22167 = get_section (DEBUG_DWO_LINE_SECTION
,
22168 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22169 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22170 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22171 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22172 SECTION_DEBUG
| SECTION_EXCLUDE
,
22174 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22175 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22176 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22177 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22178 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22179 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22181 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22182 SECTION_DEBUG
, NULL
);
22183 debug_macinfo_section
= get_section (dwarf_strict
22184 ? DEBUG_MACINFO_SECTION
22185 : DEBUG_MACRO_SECTION
,
22186 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22187 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22188 SECTION_DEBUG
, NULL
);
22189 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22190 SECTION_DEBUG
, NULL
);
22191 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22192 SECTION_DEBUG
, NULL
);
22193 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22194 DEBUG_STR_SECTION_FLAGS
, NULL
);
22195 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22196 SECTION_DEBUG
, NULL
);
22197 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22198 SECTION_DEBUG
, NULL
);
22200 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22201 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22202 DEBUG_ABBREV_SECTION_LABEL
, 0);
22203 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22204 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22205 COLD_TEXT_SECTION_LABEL
, 0);
22206 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22208 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22209 DEBUG_INFO_SECTION_LABEL
, 0);
22210 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22211 DEBUG_LINE_SECTION_LABEL
, 0);
22212 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22213 DEBUG_RANGES_SECTION_LABEL
, 0);
22214 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22215 DEBUG_ADDR_SECTION_LABEL
, 0);
22216 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22218 ? DEBUG_MACINFO_SECTION_LABEL
22219 : DEBUG_MACRO_SECTION_LABEL
, 0);
22220 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22222 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22223 vec_alloc (macinfo_table
, 64);
22225 switch_to_section (text_section
);
22226 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22228 /* Make sure the line number table for .text always exists. */
22229 text_section_line_info
= new_line_info_table ();
22230 text_section_line_info
->end_label
= text_end_label
;
22233 /* Called before compile () starts outputtting functions, variables
22234 and toplevel asms into assembly. */
22237 dwarf2out_assembly_start (void)
22239 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22240 && dwarf2out_do_cfi_asm ()
22241 && (!(flag_unwind_tables
|| flag_exceptions
)
22242 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22243 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22246 /* A helper function for dwarf2out_finish called through
22247 htab_traverse. Assign a string its index. All strings must be
22248 collected into the table by the time index_string is called,
22249 because the indexing code relies on htab_traverse to traverse nodes
22250 in the same order for each run. */
22253 index_string (void **h
, void *v
)
22255 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22256 unsigned int *index
= (unsigned int *) v
;
22258 find_string_form (node
);
22259 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22261 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22262 node
->index
= *index
;
22268 /* A helper function for output_indirect_strings called through
22269 htab_traverse. Output the offset to a string and update the
22273 output_index_string_offset (void **h
, void *v
)
22275 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22276 unsigned int *offset
= (unsigned int *) v
;
22278 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22280 /* Assert that this node has been assigned an index. */
22281 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22282 && node
->index
!= NOT_INDEXED
);
22283 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22284 "indexed string 0x%x: %s", node
->index
, node
->str
);
22285 *offset
+= strlen (node
->str
) + 1;
22290 /* A helper function for dwarf2out_finish called through
22291 htab_traverse. Output the indexed string. */
22294 output_index_string (void **h
, void *v
)
22296 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22297 unsigned int *cur_idx
= (unsigned int *) v
;
22299 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22301 /* Assert that the strings are output in the same order as their
22302 indexes were assigned. */
22303 gcc_assert (*cur_idx
== node
->index
);
22304 assemble_string (node
->str
, strlen (node
->str
) + 1);
22310 /* A helper function for dwarf2out_finish called through
22311 htab_traverse. Emit one queued .debug_str string. */
22314 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22316 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22318 node
->form
= find_string_form (node
);
22319 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22321 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22322 assemble_string (node
->str
, strlen (node
->str
) + 1);
22328 /* Output the indexed string table. */
22331 output_indirect_strings (void)
22333 switch_to_section (debug_str_section
);
22334 if (!dwarf_split_debug_info
)
22335 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22338 unsigned int offset
= 0;
22339 unsigned int cur_idx
= 0;
22341 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22343 switch_to_section (debug_str_offsets_section
);
22344 htab_traverse_noresize (debug_str_hash
,
22345 output_index_string_offset
,
22347 switch_to_section (debug_str_dwo_section
);
22348 htab_traverse_noresize (debug_str_hash
,
22349 output_index_string
,
22354 /* Callback for htab_traverse to assign an index to an entry in the
22355 table, and to write that entry to the .debug_addr section. */
22358 output_addr_table_entry (void **slot
, void *data
)
22360 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22361 unsigned int *cur_index
= (unsigned int *)data
;
22363 if (entry
->refcount
== 0)
22365 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22366 || entry
->index
== NOT_INDEXED
);
22370 gcc_assert (entry
->index
== *cur_index
);
22373 switch (entry
->kind
)
22376 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22377 "0x%x", entry
->index
);
22379 case ate_kind_rtx_dtprel
:
22380 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22381 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22384 fputc ('\n', asm_out_file
);
22386 case ate_kind_label
:
22387 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22388 "0x%x", entry
->index
);
22391 gcc_unreachable ();
22396 /* Produce the .debug_addr section. */
22399 output_addr_table (void)
22401 unsigned int index
= 0;
22402 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22405 switch_to_section (debug_addr_section
);
22406 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22409 #if ENABLE_ASSERT_CHECKING
22410 /* Verify that all marks are clear. */
22413 verify_marks_clear (dw_die_ref die
)
22417 gcc_assert (! die
->die_mark
);
22418 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22420 #endif /* ENABLE_ASSERT_CHECKING */
22422 /* Clear the marks for a die and its children.
22423 Be cool if the mark isn't set. */
22426 prune_unmark_dies (dw_die_ref die
)
22432 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22435 /* Given DIE that we're marking as used, find any other dies
22436 it references as attributes and mark them as used. */
22439 prune_unused_types_walk_attribs (dw_die_ref die
)
22444 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22446 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22448 /* A reference to another DIE.
22449 Make sure that it will get emitted.
22450 If it was broken out into a comdat group, don't follow it. */
22451 if (! AT_ref (a
)->comdat_type_p
22452 || a
->dw_attr
== DW_AT_specification
)
22453 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22455 /* Set the string's refcount to 0 so that prune_unused_types_mark
22456 accounts properly for it. */
22457 if (AT_class (a
) == dw_val_class_str
)
22458 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22462 /* Mark the generic parameters and arguments children DIEs of DIE. */
22465 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22469 if (die
== NULL
|| die
->die_child
== NULL
)
22471 c
= die
->die_child
;
22474 if (is_template_parameter (c
))
22475 prune_unused_types_mark (c
, 1);
22477 } while (c
&& c
!= die
->die_child
);
22480 /* Mark DIE as being used. If DOKIDS is true, then walk down
22481 to DIE's children. */
22484 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22488 if (die
->die_mark
== 0)
22490 /* We haven't done this node yet. Mark it as used. */
22492 /* If this is the DIE of a generic type instantiation,
22493 mark the children DIEs that describe its generic parms and
22495 prune_unused_types_mark_generic_parms_dies (die
);
22497 /* We also have to mark its parents as used.
22498 (But we don't want to mark our parent's kids due to this,
22499 unless it is a class.) */
22500 if (die
->die_parent
)
22501 prune_unused_types_mark (die
->die_parent
,
22502 class_scope_p (die
->die_parent
));
22504 /* Mark any referenced nodes. */
22505 prune_unused_types_walk_attribs (die
);
22507 /* If this node is a specification,
22508 also mark the definition, if it exists. */
22509 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22510 prune_unused_types_mark (die
->die_definition
, 1);
22513 if (dokids
&& die
->die_mark
!= 2)
22515 /* We need to walk the children, but haven't done so yet.
22516 Remember that we've walked the kids. */
22519 /* If this is an array type, we need to make sure our
22520 kids get marked, even if they're types. If we're
22521 breaking out types into comdat sections, do this
22522 for all type definitions. */
22523 if (die
->die_tag
== DW_TAG_array_type
22524 || (use_debug_types
22525 && is_type_die (die
) && ! is_declaration_die (die
)))
22526 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22528 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22532 /* For local classes, look if any static member functions were emitted
22533 and if so, mark them. */
22536 prune_unused_types_walk_local_classes (dw_die_ref die
)
22540 if (die
->die_mark
== 2)
22543 switch (die
->die_tag
)
22545 case DW_TAG_structure_type
:
22546 case DW_TAG_union_type
:
22547 case DW_TAG_class_type
:
22550 case DW_TAG_subprogram
:
22551 if (!get_AT_flag (die
, DW_AT_declaration
)
22552 || die
->die_definition
!= NULL
)
22553 prune_unused_types_mark (die
, 1);
22560 /* Mark children. */
22561 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22564 /* Walk the tree DIE and mark types that we actually use. */
22567 prune_unused_types_walk (dw_die_ref die
)
22571 /* Don't do anything if this node is already marked and
22572 children have been marked as well. */
22573 if (die
->die_mark
== 2)
22576 switch (die
->die_tag
)
22578 case DW_TAG_structure_type
:
22579 case DW_TAG_union_type
:
22580 case DW_TAG_class_type
:
22581 if (die
->die_perennial_p
)
22584 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22585 if (c
->die_tag
== DW_TAG_subprogram
)
22588 /* Finding used static member functions inside of classes
22589 is needed just for local classes, because for other classes
22590 static member function DIEs with DW_AT_specification
22591 are emitted outside of the DW_TAG_*_type. If we ever change
22592 it, we'd need to call this even for non-local classes. */
22594 prune_unused_types_walk_local_classes (die
);
22596 /* It's a type node --- don't mark it. */
22599 case DW_TAG_const_type
:
22600 case DW_TAG_packed_type
:
22601 case DW_TAG_pointer_type
:
22602 case DW_TAG_reference_type
:
22603 case DW_TAG_rvalue_reference_type
:
22604 case DW_TAG_volatile_type
:
22605 case DW_TAG_typedef
:
22606 case DW_TAG_array_type
:
22607 case DW_TAG_interface_type
:
22608 case DW_TAG_friend
:
22609 case DW_TAG_variant_part
:
22610 case DW_TAG_enumeration_type
:
22611 case DW_TAG_subroutine_type
:
22612 case DW_TAG_string_type
:
22613 case DW_TAG_set_type
:
22614 case DW_TAG_subrange_type
:
22615 case DW_TAG_ptr_to_member_type
:
22616 case DW_TAG_file_type
:
22617 if (die
->die_perennial_p
)
22620 /* It's a type node --- don't mark it. */
22624 /* Mark everything else. */
22628 if (die
->die_mark
== 0)
22632 /* Now, mark any dies referenced from here. */
22633 prune_unused_types_walk_attribs (die
);
22638 /* Mark children. */
22639 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22642 /* Increment the string counts on strings referred to from DIE's
22646 prune_unused_types_update_strings (dw_die_ref die
)
22651 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22652 if (AT_class (a
) == dw_val_class_str
)
22654 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22656 /* Avoid unnecessarily putting strings that are used less than
22657 twice in the hash table. */
22659 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22662 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22663 htab_hash_string (s
->str
),
22665 gcc_assert (*slot
== NULL
);
22671 /* Remove from the tree DIE any dies that aren't marked. */
22674 prune_unused_types_prune (dw_die_ref die
)
22678 gcc_assert (die
->die_mark
);
22679 prune_unused_types_update_strings (die
);
22681 if (! die
->die_child
)
22684 c
= die
->die_child
;
22686 dw_die_ref prev
= c
;
22687 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22688 if (c
== die
->die_child
)
22690 /* No marked children between 'prev' and the end of the list. */
22692 /* No marked children at all. */
22693 die
->die_child
= NULL
;
22696 prev
->die_sib
= c
->die_sib
;
22697 die
->die_child
= prev
;
22702 if (c
!= prev
->die_sib
)
22704 prune_unused_types_prune (c
);
22705 } while (c
!= die
->die_child
);
22708 /* Remove dies representing declarations that we never use. */
22711 prune_unused_types (void)
22714 limbo_die_node
*node
;
22715 comdat_type_node
*ctnode
;
22717 dw_die_ref base_type
;
22719 #if ENABLE_ASSERT_CHECKING
22720 /* All the marks should already be clear. */
22721 verify_marks_clear (comp_unit_die ());
22722 for (node
= limbo_die_list
; node
; node
= node
->next
)
22723 verify_marks_clear (node
->die
);
22724 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22725 verify_marks_clear (ctnode
->root_die
);
22726 #endif /* ENABLE_ASSERT_CHECKING */
22728 /* Mark types that are used in global variables. */
22729 premark_types_used_by_global_vars ();
22731 /* Set the mark on nodes that are actually used. */
22732 prune_unused_types_walk (comp_unit_die ());
22733 for (node
= limbo_die_list
; node
; node
= node
->next
)
22734 prune_unused_types_walk (node
->die
);
22735 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22737 prune_unused_types_walk (ctnode
->root_die
);
22738 prune_unused_types_mark (ctnode
->type_die
, 1);
22741 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22742 are unusual in that they are pubnames that are the children of pubtypes.
22743 They should only be marked via their parent DW_TAG_enumeration_type die,
22744 not as roots in themselves. */
22745 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22746 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22747 prune_unused_types_mark (pub
->die
, 1);
22748 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22749 prune_unused_types_mark (base_type
, 1);
22751 if (debug_str_hash
)
22752 htab_empty (debug_str_hash
);
22753 if (skeleton_debug_str_hash
)
22754 htab_empty (skeleton_debug_str_hash
);
22755 prune_unused_types_prune (comp_unit_die ());
22756 for (node
= limbo_die_list
; node
; node
= node
->next
)
22757 prune_unused_types_prune (node
->die
);
22758 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22759 prune_unused_types_prune (ctnode
->root_die
);
22761 /* Leave the marks clear. */
22762 prune_unmark_dies (comp_unit_die ());
22763 for (node
= limbo_die_list
; node
; node
= node
->next
)
22764 prune_unmark_dies (node
->die
);
22765 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22766 prune_unmark_dies (ctnode
->root_die
);
22769 /* Set the parameter to true if there are any relative pathnames in
22772 file_table_relative_p (void ** slot
, void *param
)
22774 bool *p
= (bool *) param
;
22775 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22776 if (!IS_ABSOLUTE_PATH (d
->filename
))
22784 /* Helpers to manipulate hash table of comdat type units. */
22786 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22788 typedef comdat_type_node value_type
;
22789 typedef comdat_type_node compare_type
;
22790 static inline hashval_t
hash (const value_type
*);
22791 static inline bool equal (const value_type
*, const compare_type
*);
22795 comdat_type_hasher::hash (const value_type
*type_node
)
22798 memcpy (&h
, type_node
->signature
, sizeof (h
));
22803 comdat_type_hasher::equal (const value_type
*type_node_1
,
22804 const compare_type
*type_node_2
)
22806 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22807 DWARF_TYPE_SIGNATURE_SIZE
));
22810 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22811 to the location it would have been added, should we know its
22812 DECL_ASSEMBLER_NAME when we added other attributes. This will
22813 probably improve compactness of debug info, removing equivalent
22814 abbrevs, and hide any differences caused by deferring the
22815 computation of the assembler name, triggered by e.g. PCH. */
22818 move_linkage_attr (dw_die_ref die
)
22820 unsigned ix
= vec_safe_length (die
->die_attr
);
22821 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22823 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22824 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22828 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22830 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22834 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22836 die
->die_attr
->pop ();
22837 die
->die_attr
->quick_insert (ix
, linkage
);
22841 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22842 referenced from typed stack ops and count how often they are used. */
22845 mark_base_types (dw_loc_descr_ref loc
)
22847 dw_die_ref base_type
= NULL
;
22849 for (; loc
; loc
= loc
->dw_loc_next
)
22851 switch (loc
->dw_loc_opc
)
22853 case DW_OP_GNU_regval_type
:
22854 case DW_OP_GNU_deref_type
:
22855 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22857 case DW_OP_GNU_convert
:
22858 case DW_OP_GNU_reinterpret
:
22859 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22862 case DW_OP_GNU_const_type
:
22863 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22865 case DW_OP_GNU_entry_value
:
22866 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22871 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22872 if (base_type
->die_mark
)
22873 base_type
->die_mark
++;
22876 base_types
.safe_push (base_type
);
22877 base_type
->die_mark
= 1;
22882 /* Comparison function for sorting marked base types. */
22885 base_type_cmp (const void *x
, const void *y
)
22887 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22888 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22889 unsigned int byte_size1
, byte_size2
;
22890 unsigned int encoding1
, encoding2
;
22891 if (dx
->die_mark
> dy
->die_mark
)
22893 if (dx
->die_mark
< dy
->die_mark
)
22895 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22896 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22897 if (byte_size1
< byte_size2
)
22899 if (byte_size1
> byte_size2
)
22901 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22902 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22903 if (encoding1
< encoding2
)
22905 if (encoding1
> encoding2
)
22910 /* Move base types marked by mark_base_types as early as possible
22911 in the CU, sorted by decreasing usage count both to make the
22912 uleb128 references as small as possible and to make sure they
22913 will have die_offset already computed by calc_die_sizes when
22914 sizes of typed stack loc ops is computed. */
22917 move_marked_base_types (void)
22920 dw_die_ref base_type
, die
, c
;
22922 if (base_types
.is_empty ())
22925 /* Sort by decreasing usage count, they will be added again in that
22927 base_types
.qsort (base_type_cmp
);
22928 die
= comp_unit_die ();
22929 c
= die
->die_child
;
22932 dw_die_ref prev
= c
;
22934 while (c
->die_mark
)
22936 remove_child_with_prev (c
, prev
);
22937 /* As base types got marked, there must be at least
22938 one node other than DW_TAG_base_type. */
22939 gcc_assert (c
!= c
->die_sib
);
22943 while (c
!= die
->die_child
);
22944 gcc_assert (die
->die_child
);
22945 c
= die
->die_child
;
22946 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22948 base_type
->die_mark
= 0;
22949 base_type
->die_sib
= c
->die_sib
;
22950 c
->die_sib
= base_type
;
22955 /* Helper function for resolve_addr, attempt to resolve
22956 one CONST_STRING, return non-zero if not successful. Similarly verify that
22957 SYMBOL_REFs refer to variables emitted in the current CU. */
22960 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22964 if (GET_CODE (rtl
) == CONST_STRING
)
22966 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22967 tree t
= build_string (len
, XSTR (rtl
, 0));
22968 tree tlen
= size_int (len
- 1);
22970 = build_array_type (char_type_node
, build_index_type (tlen
));
22971 rtl
= lookup_constant_def (t
);
22972 if (!rtl
|| !MEM_P (rtl
))
22974 rtl
= XEXP (rtl
, 0);
22975 if (GET_CODE (rtl
) == SYMBOL_REF
22976 && SYMBOL_REF_DECL (rtl
)
22977 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22979 vec_safe_push (used_rtx_array
, rtl
);
22984 if (GET_CODE (rtl
) == SYMBOL_REF
22985 && SYMBOL_REF_DECL (rtl
))
22987 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22989 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22992 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22996 if (GET_CODE (rtl
) == CONST
22997 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
23003 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
23004 if possible, and create DW_TAG_dwarf_procedure that can be referenced
23005 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
23008 string_cst_pool_decl (tree t
)
23010 rtx rtl
= output_constant_def (t
, 1);
23011 unsigned char *array
;
23012 dw_loc_descr_ref l
;
23017 if (!rtl
|| !MEM_P (rtl
))
23019 rtl
= XEXP (rtl
, 0);
23020 if (GET_CODE (rtl
) != SYMBOL_REF
23021 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
23024 decl
= SYMBOL_REF_DECL (rtl
);
23025 if (!lookup_decl_die (decl
))
23027 len
= TREE_STRING_LENGTH (t
);
23028 vec_safe_push (used_rtx_array
, rtl
);
23029 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
23030 array
= (unsigned char *) ggc_alloc_atomic (len
);
23031 memcpy (array
, TREE_STRING_POINTER (t
), len
);
23032 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
23033 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
23034 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
23035 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
23036 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
23037 add_AT_loc (ref
, DW_AT_location
, l
);
23038 equate_decl_number_to_die (decl
, ref
);
23043 /* Helper function of resolve_addr_in_expr. LOC is
23044 a DW_OP_addr followed by DW_OP_stack_value, either at the start
23045 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
23046 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
23047 with DW_OP_GNU_implicit_pointer if possible
23048 and return true, if unsuccessful, return false. */
23051 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
23053 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
23054 HOST_WIDE_INT offset
= 0;
23055 dw_die_ref ref
= NULL
;
23058 if (GET_CODE (rtl
) == CONST
23059 && GET_CODE (XEXP (rtl
, 0)) == PLUS
23060 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
23062 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
23063 rtl
= XEXP (XEXP (rtl
, 0), 0);
23065 if (GET_CODE (rtl
) == CONST_STRING
)
23067 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23068 tree t
= build_string (len
, XSTR (rtl
, 0));
23069 tree tlen
= size_int (len
- 1);
23072 = build_array_type (char_type_node
, build_index_type (tlen
));
23073 rtl
= string_cst_pool_decl (t
);
23077 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
23079 decl
= SYMBOL_REF_DECL (rtl
);
23080 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
23082 ref
= lookup_decl_die (decl
);
23083 if (ref
&& (get_AT (ref
, DW_AT_location
)
23084 || get_AT (ref
, DW_AT_const_value
)))
23086 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
23087 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23088 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
23089 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23090 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23091 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23092 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
23100 /* Helper function for resolve_addr, handle one location
23101 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23102 the location list couldn't be resolved. */
23105 resolve_addr_in_expr (dw_loc_descr_ref loc
)
23107 dw_loc_descr_ref keep
= NULL
;
23108 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
23109 switch (loc
->dw_loc_opc
)
23112 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23115 || prev
->dw_loc_opc
== DW_OP_piece
23116 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
23117 && loc
->dw_loc_next
23118 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
23120 && optimize_one_addr_into_implicit_ptr (loc
))
23125 case DW_OP_GNU_addr_index
:
23126 case DW_OP_GNU_const_index
:
23127 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
23128 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
23129 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
23133 case DW_OP_const4u
:
23134 case DW_OP_const8u
:
23136 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23139 case DW_OP_plus_uconst
:
23140 if (size_of_loc_descr (loc
)
23141 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
23143 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
23145 dw_loc_descr_ref repl
23146 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
23147 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23148 add_loc_descr (&repl
, loc
->dw_loc_next
);
23152 case DW_OP_implicit_value
:
23153 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23154 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
23157 case DW_OP_GNU_implicit_pointer
:
23158 case DW_OP_GNU_parameter_ref
:
23159 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23162 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23165 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23166 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23167 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23170 case DW_OP_GNU_const_type
:
23171 case DW_OP_GNU_regval_type
:
23172 case DW_OP_GNU_deref_type
:
23173 case DW_OP_GNU_convert
:
23174 case DW_OP_GNU_reinterpret
:
23175 while (loc
->dw_loc_next
23176 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23178 dw_die_ref base1
, base2
;
23179 unsigned enc1
, enc2
, size1
, size2
;
23180 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23181 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23182 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23183 else if (loc
->dw_loc_oprnd1
.val_class
23184 == dw_val_class_unsigned_const
)
23187 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23188 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23189 == dw_val_class_unsigned_const
)
23191 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23192 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23193 && base2
->die_tag
== DW_TAG_base_type
);
23194 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23195 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23196 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23197 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23199 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23200 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23204 /* Optimize away next DW_OP_GNU_convert after
23205 adjusting LOC's base type die reference. */
23206 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23207 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23208 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23210 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23211 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23214 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23215 point typed stack entry. */
23216 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23217 keep
= loc
->dw_loc_next
;
23227 /* Helper function of resolve_addr. DIE had DW_AT_location of
23228 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23229 and DW_OP_addr couldn't be resolved. resolve_addr has already
23230 removed the DW_AT_location attribute. This function attempts to
23231 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23232 to it or DW_AT_const_value attribute, if possible. */
23235 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23237 if (TREE_CODE (decl
) != VAR_DECL
23238 || lookup_decl_die (decl
) != die
23239 || DECL_EXTERNAL (decl
)
23240 || !TREE_STATIC (decl
)
23241 || DECL_INITIAL (decl
) == NULL_TREE
23242 || DECL_P (DECL_INITIAL (decl
))
23243 || get_AT (die
, DW_AT_const_value
))
23246 tree init
= DECL_INITIAL (decl
);
23247 HOST_WIDE_INT offset
= 0;
23248 /* For variables that have been optimized away and thus
23249 don't have a memory location, see if we can emit
23250 DW_AT_const_value instead. */
23251 if (tree_add_const_value_attribute (die
, init
))
23255 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23256 and ADDR_EXPR refers to a decl that has DW_AT_location or
23257 DW_AT_const_value (but isn't addressable, otherwise
23258 resolving the original DW_OP_addr wouldn't fail), see if
23259 we can add DW_OP_GNU_implicit_pointer. */
23261 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23262 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
23264 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
23265 init
= TREE_OPERAND (init
, 0);
23268 if (TREE_CODE (init
) != ADDR_EXPR
)
23270 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23271 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23272 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23273 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23274 && TREE_OPERAND (init
, 0) != decl
))
23277 dw_loc_descr_ref l
;
23279 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23281 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23284 decl
= SYMBOL_REF_DECL (rtl
);
23287 decl
= TREE_OPERAND (init
, 0);
23288 ref
= lookup_decl_die (decl
);
23290 || (!get_AT (ref
, DW_AT_location
)
23291 && !get_AT (ref
, DW_AT_const_value
)))
23293 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23294 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23295 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23296 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23297 add_AT_loc (die
, DW_AT_location
, l
);
23301 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23302 an address in .rodata section if the string literal is emitted there,
23303 or remove the containing location list or replace DW_AT_const_value
23304 with DW_AT_location and empty location expression, if it isn't found
23305 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23306 to something that has been emitted in the current CU. */
23309 resolve_addr (dw_die_ref die
)
23313 dw_loc_list_ref
*curr
, *start
, loc
;
23316 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23317 switch (AT_class (a
))
23319 case dw_val_class_loc_list
:
23320 start
= curr
= AT_loc_list_ptr (a
);
23323 /* The same list can be referenced more than once. See if we have
23324 already recorded the result from a previous pass. */
23326 *curr
= loc
->dw_loc_next
;
23327 else if (!loc
->resolved_addr
)
23329 /* As things stand, we do not expect or allow one die to
23330 reference a suffix of another die's location list chain.
23331 References must be identical or completely separate.
23332 There is therefore no need to cache the result of this
23333 pass on any list other than the first; doing so
23334 would lead to unnecessary writes. */
23337 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23338 if (!resolve_addr_in_expr ((*curr
)->expr
))
23340 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23341 dw_loc_descr_ref l
= (*curr
)->expr
;
23343 if (next
&& (*curr
)->ll_symbol
)
23345 gcc_assert (!next
->ll_symbol
);
23346 next
->ll_symbol
= (*curr
)->ll_symbol
;
23348 if (dwarf_split_debug_info
)
23349 remove_loc_list_addr_table_entries (l
);
23354 mark_base_types ((*curr
)->expr
);
23355 curr
= &(*curr
)->dw_loc_next
;
23359 loc
->resolved_addr
= 1;
23363 loc
->dw_loc_next
= *start
;
23368 remove_AT (die
, a
->dw_attr
);
23372 case dw_val_class_loc
:
23374 dw_loc_descr_ref l
= AT_loc (a
);
23375 /* For -gdwarf-2 don't attempt to optimize
23376 DW_AT_data_member_location containing
23377 DW_OP_plus_uconst - older consumers might
23378 rely on it being that op instead of a more complex,
23379 but shorter, location description. */
23380 if ((dwarf_version
> 2
23381 || a
->dw_attr
!= DW_AT_data_member_location
23383 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23384 || l
->dw_loc_next
!= NULL
)
23385 && !resolve_addr_in_expr (l
))
23387 if (dwarf_split_debug_info
)
23388 remove_loc_list_addr_table_entries (l
);
23390 && l
->dw_loc_next
== NULL
23391 && l
->dw_loc_opc
== DW_OP_addr
23392 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23393 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23394 && a
->dw_attr
== DW_AT_location
)
23396 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23397 remove_AT (die
, a
->dw_attr
);
23399 optimize_location_into_implicit_ptr (die
, decl
);
23402 remove_AT (die
, a
->dw_attr
);
23406 mark_base_types (l
);
23409 case dw_val_class_addr
:
23410 if (a
->dw_attr
== DW_AT_const_value
23411 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23413 if (AT_index (a
) != NOT_INDEXED
)
23414 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23415 remove_AT (die
, a
->dw_attr
);
23418 if (die
->die_tag
== DW_TAG_GNU_call_site
23419 && a
->dw_attr
== DW_AT_abstract_origin
)
23421 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23422 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23424 && DECL_EXTERNAL (tdecl
)
23425 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23427 force_decl_die (tdecl
);
23428 tdie
= lookup_decl_die (tdecl
);
23432 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23433 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23434 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23438 if (AT_index (a
) != NOT_INDEXED
)
23439 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23440 remove_AT (die
, a
->dw_attr
);
23449 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23452 /* Helper routines for optimize_location_lists.
23453 This pass tries to share identical local lists in .debug_loc
23456 /* Iteratively hash operands of LOC opcode. */
23459 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23461 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23462 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23464 switch (loc
->dw_loc_opc
)
23466 case DW_OP_const4u
:
23467 case DW_OP_const8u
:
23471 case DW_OP_const1u
:
23472 case DW_OP_const1s
:
23473 case DW_OP_const2u
:
23474 case DW_OP_const2s
:
23475 case DW_OP_const4s
:
23476 case DW_OP_const8s
:
23480 case DW_OP_plus_uconst
:
23516 case DW_OP_deref_size
:
23517 case DW_OP_xderef_size
:
23518 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23525 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23526 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23527 hash
= iterative_hash_object (offset
, hash
);
23530 case DW_OP_implicit_value
:
23531 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23532 switch (val2
->val_class
)
23534 case dw_val_class_const
:
23535 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23537 case dw_val_class_vec
:
23539 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23540 unsigned int len
= val2
->v
.val_vec
.length
;
23542 hash
= iterative_hash_object (elt_size
, hash
);
23543 hash
= iterative_hash_object (len
, hash
);
23544 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23545 len
* elt_size
, hash
);
23548 case dw_val_class_const_double
:
23549 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23550 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23552 case dw_val_class_addr
:
23553 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23556 gcc_unreachable ();
23560 case DW_OP_bit_piece
:
23561 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23562 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23568 unsigned char dtprel
= 0xd1;
23569 hash
= iterative_hash_object (dtprel
, hash
);
23571 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23573 case DW_OP_GNU_addr_index
:
23574 case DW_OP_GNU_const_index
:
23578 unsigned char dtprel
= 0xd1;
23579 hash
= iterative_hash_object (dtprel
, hash
);
23581 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23584 case DW_OP_GNU_implicit_pointer
:
23585 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23587 case DW_OP_GNU_entry_value
:
23588 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23590 case DW_OP_GNU_regval_type
:
23591 case DW_OP_GNU_deref_type
:
23593 unsigned int byte_size
23594 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23595 unsigned int encoding
23596 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23597 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23598 hash
= iterative_hash_object (byte_size
, hash
);
23599 hash
= iterative_hash_object (encoding
, hash
);
23602 case DW_OP_GNU_convert
:
23603 case DW_OP_GNU_reinterpret
:
23604 if (val1
->val_class
== dw_val_class_unsigned_const
)
23606 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23610 case DW_OP_GNU_const_type
:
23612 unsigned int byte_size
23613 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23614 unsigned int encoding
23615 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23616 hash
= iterative_hash_object (byte_size
, hash
);
23617 hash
= iterative_hash_object (encoding
, hash
);
23618 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23620 hash
= iterative_hash_object (val2
->val_class
, hash
);
23621 switch (val2
->val_class
)
23623 case dw_val_class_const
:
23624 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23626 case dw_val_class_vec
:
23628 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23629 unsigned int len
= val2
->v
.val_vec
.length
;
23631 hash
= iterative_hash_object (elt_size
, hash
);
23632 hash
= iterative_hash_object (len
, hash
);
23633 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23634 len
* elt_size
, hash
);
23637 case dw_val_class_const_double
:
23638 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23639 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23642 gcc_unreachable ();
23648 /* Other codes have no operands. */
23654 /* Iteratively hash the whole DWARF location expression LOC. */
23656 static inline hashval_t
23657 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23659 dw_loc_descr_ref l
;
23660 bool sizes_computed
= false;
23661 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23662 size_of_locs (loc
);
23664 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23666 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23667 hash
= iterative_hash_object (opc
, hash
);
23668 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23670 size_of_locs (loc
);
23671 sizes_computed
= true;
23673 hash
= hash_loc_operands (l
, hash
);
23678 /* Compute hash of the whole location list LIST_HEAD. */
23681 hash_loc_list (dw_loc_list_ref list_head
)
23683 dw_loc_list_ref curr
= list_head
;
23684 hashval_t hash
= 0;
23686 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23688 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23689 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23691 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23693 hash
= hash_locs (curr
->expr
, hash
);
23695 list_head
->hash
= hash
;
23698 /* Return true if X and Y opcodes have the same operands. */
23701 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23703 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23704 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23705 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23706 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23708 switch (x
->dw_loc_opc
)
23710 case DW_OP_const4u
:
23711 case DW_OP_const8u
:
23715 case DW_OP_const1u
:
23716 case DW_OP_const1s
:
23717 case DW_OP_const2u
:
23718 case DW_OP_const2s
:
23719 case DW_OP_const4s
:
23720 case DW_OP_const8s
:
23724 case DW_OP_plus_uconst
:
23760 case DW_OP_deref_size
:
23761 case DW_OP_xderef_size
:
23762 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23765 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23766 can cause irrelevant differences in dw_loc_addr. */
23767 gcc_assert (valx1
->val_class
== dw_val_class_loc
23768 && valy1
->val_class
== dw_val_class_loc
23769 && (dwarf_split_debug_info
23770 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23771 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23772 case DW_OP_implicit_value
:
23773 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23774 || valx2
->val_class
!= valy2
->val_class
)
23776 switch (valx2
->val_class
)
23778 case dw_val_class_const
:
23779 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23780 case dw_val_class_vec
:
23781 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23782 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23783 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23784 valx2
->v
.val_vec
.elt_size
23785 * valx2
->v
.val_vec
.length
) == 0;
23786 case dw_val_class_const_double
:
23787 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23788 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23789 case dw_val_class_addr
:
23790 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23792 gcc_unreachable ();
23795 case DW_OP_bit_piece
:
23796 return valx1
->v
.val_int
== valy1
->v
.val_int
23797 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23800 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23801 case DW_OP_GNU_addr_index
:
23802 case DW_OP_GNU_const_index
:
23804 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23805 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23806 return rtx_equal_p (ax1
, ay1
);
23808 case DW_OP_GNU_implicit_pointer
:
23809 return valx1
->val_class
== dw_val_class_die_ref
23810 && valx1
->val_class
== valy1
->val_class
23811 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23812 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23813 case DW_OP_GNU_entry_value
:
23814 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23815 case DW_OP_GNU_const_type
:
23816 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23817 || valx2
->val_class
!= valy2
->val_class
)
23819 switch (valx2
->val_class
)
23821 case dw_val_class_const
:
23822 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23823 case dw_val_class_vec
:
23824 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23825 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23826 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23827 valx2
->v
.val_vec
.elt_size
23828 * valx2
->v
.val_vec
.length
) == 0;
23829 case dw_val_class_const_double
:
23830 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23831 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23833 gcc_unreachable ();
23835 case DW_OP_GNU_regval_type
:
23836 case DW_OP_GNU_deref_type
:
23837 return valx1
->v
.val_int
== valy1
->v
.val_int
23838 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23839 case DW_OP_GNU_convert
:
23840 case DW_OP_GNU_reinterpret
:
23841 if (valx1
->val_class
!= valy1
->val_class
)
23843 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23844 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23845 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23846 case DW_OP_GNU_parameter_ref
:
23847 return valx1
->val_class
== dw_val_class_die_ref
23848 && valx1
->val_class
== valy1
->val_class
23849 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23851 /* Other codes have no operands. */
23856 /* Return true if DWARF location expressions X and Y are the same. */
23859 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23861 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23862 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23863 || x
->dtprel
!= y
->dtprel
23864 || !compare_loc_operands (x
, y
))
23866 return x
== NULL
&& y
== NULL
;
23869 /* Hashtable helpers. */
23871 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23873 typedef dw_loc_list_struct value_type
;
23874 typedef dw_loc_list_struct compare_type
;
23875 static inline hashval_t
hash (const value_type
*);
23876 static inline bool equal (const value_type
*, const compare_type
*);
23879 /* Return precomputed hash of location list X. */
23882 loc_list_hasher::hash (const value_type
*x
)
23887 /* Return true if location lists A and B are the same. */
23890 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23894 if (a
->hash
!= b
->hash
)
23896 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23897 if (strcmp (a
->begin
, b
->begin
) != 0
23898 || strcmp (a
->end
, b
->end
) != 0
23899 || (a
->section
== NULL
) != (b
->section
== NULL
)
23900 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23901 || !compare_locs (a
->expr
, b
->expr
))
23903 return a
== NULL
&& b
== NULL
;
23906 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23909 /* Recursively optimize location lists referenced from DIE
23910 children and share them whenever possible. */
23913 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23918 dw_loc_list_struct
**slot
;
23920 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23921 if (AT_class (a
) == dw_val_class_loc_list
)
23923 dw_loc_list_ref list
= AT_loc_list (a
);
23924 /* TODO: perform some optimizations here, before hashing
23925 it and storing into the hash table. */
23926 hash_loc_list (list
);
23927 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23931 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23934 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23938 /* Recursively assign each location list a unique index into the debug_addr
23942 index_location_lists (dw_die_ref die
)
23948 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23949 if (AT_class (a
) == dw_val_class_loc_list
)
23951 dw_loc_list_ref list
= AT_loc_list (a
);
23952 dw_loc_list_ref curr
;
23953 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23955 /* Don't index an entry that has already been indexed
23956 or won't be output. */
23957 if (curr
->begin_entry
!= NULL
23958 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23962 = add_addr_table_entry (xstrdup (curr
->begin
),
23967 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23970 /* Optimize location lists referenced from DIE
23971 children and share them whenever possible. */
23974 optimize_location_lists (dw_die_ref die
)
23976 loc_list_hash_type htab
;
23978 optimize_location_lists_1 (die
, htab
);
23982 /* Output stuff that dwarf requires at the end of every file,
23983 and generate the DWARF-2 debugging info. */
23986 dwarf2out_finish (const char *filename
)
23988 limbo_die_node
*node
, *next_node
;
23989 comdat_type_node
*ctnode
;
23990 hash_table
<comdat_type_hasher
> comdat_type_table
;
23992 dw_die_ref main_comp_unit_die
;
23994 /* PCH might result in DW_AT_producer string being restored from the
23995 header compilation, so always fill it with empty string initially
23996 and overwrite only here. */
23997 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23998 producer_string
= gen_producer_string ();
23999 producer
->dw_attr_val
.v
.val_str
->refcount
--;
24000 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
24002 gen_scheduled_generic_parms_dies ();
24003 gen_remaining_tmpl_value_param_die_attribute ();
24005 /* Add the name for the main input file now. We delayed this from
24006 dwarf2out_init to avoid complications with PCH. */
24007 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
24008 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
24009 add_comp_dir_attribute (comp_unit_die ());
24010 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
24013 htab_traverse (file_table
, file_table_relative_p
, &p
);
24015 add_comp_dir_attribute (comp_unit_die ());
24018 if (deferred_locations_list
)
24019 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
24021 add_location_or_const_value_attribute (
24022 (*deferred_locations_list
)[i
].die
,
24023 (*deferred_locations_list
)[i
].variable
,
24028 /* Traverse the limbo die list, and add parent/child links. The only
24029 dies without parents that should be here are concrete instances of
24030 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
24031 For concrete instances, we can get the parent die from the abstract
24033 for (node
= limbo_die_list
; node
; node
= next_node
)
24035 dw_die_ref die
= node
->die
;
24036 next_node
= node
->next
;
24038 if (die
->die_parent
== NULL
)
24040 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
24042 if (origin
&& origin
->die_parent
)
24043 add_child_die (origin
->die_parent
, die
);
24044 else if (is_cu_die (die
))
24046 else if (seen_error ())
24047 /* It's OK to be confused by errors in the input. */
24048 add_child_die (comp_unit_die (), die
);
24051 /* In certain situations, the lexical block containing a
24052 nested function can be optimized away, which results
24053 in the nested function die being orphaned. Likewise
24054 with the return type of that nested function. Force
24055 this to be a child of the containing function.
24057 It may happen that even the containing function got fully
24058 inlined and optimized out. In that case we are lost and
24059 assign the empty child. This should not be big issue as
24060 the function is likely unreachable too. */
24061 gcc_assert (node
->created_for
);
24063 if (DECL_P (node
->created_for
))
24064 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
24065 else if (TYPE_P (node
->created_for
))
24066 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
24068 origin
= comp_unit_die ();
24070 add_child_die (origin
, die
);
24075 limbo_die_list
= NULL
;
24077 #if ENABLE_ASSERT_CHECKING
24079 dw_die_ref die
= comp_unit_die (), c
;
24080 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
24083 resolve_addr (comp_unit_die ());
24084 move_marked_base_types ();
24086 for (node
= deferred_asm_name
; node
; node
= node
->next
)
24088 tree decl
= node
->created_for
;
24089 /* When generating LTO bytecode we can not generate new assembler
24090 names at this point and all important decls got theirs via
24092 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
24093 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
24095 add_linkage_attr (node
->die
, decl
);
24096 move_linkage_attr (node
->die
);
24100 deferred_asm_name
= NULL
;
24102 /* Walk through the list of incomplete types again, trying once more to
24103 emit full debugging info for them. */
24104 retry_incomplete_types ();
24106 if (flag_eliminate_unused_debug_types
)
24107 prune_unused_types ();
24109 /* Generate separate COMDAT sections for type DIEs. */
24110 if (use_debug_types
)
24112 break_out_comdat_types (comp_unit_die ());
24114 /* Each new type_unit DIE was added to the limbo die list when created.
24115 Since these have all been added to comdat_type_list, clear the
24117 limbo_die_list
= NULL
;
24119 /* For each new comdat type unit, copy declarations for incomplete
24120 types to make the new unit self-contained (i.e., no direct
24121 references to the main compile unit). */
24122 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24123 copy_decls_for_unworthy_types (ctnode
->root_die
);
24124 copy_decls_for_unworthy_types (comp_unit_die ());
24126 /* In the process of copying declarations from one unit to another,
24127 we may have left some declarations behind that are no longer
24128 referenced. Prune them. */
24129 prune_unused_types ();
24132 /* Generate separate CUs for each of the include files we've seen.
24133 They will go into limbo_die_list. */
24134 if (flag_eliminate_dwarf2_dups
)
24135 break_out_includes (comp_unit_die ());
24137 /* Traverse the DIE's and add add sibling attributes to those DIE's
24138 that have children. */
24139 add_sibling_attributes (comp_unit_die ());
24140 for (node
= limbo_die_list
; node
; node
= node
->next
)
24141 add_sibling_attributes (node
->die
);
24142 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24143 add_sibling_attributes (ctnode
->root_die
);
24145 /* When splitting DWARF info, we put some attributes in the
24146 skeleton compile_unit DIE that remains in the .o, while
24147 most attributes go in the DWO compile_unit_die. */
24148 if (dwarf_split_debug_info
)
24149 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24151 main_comp_unit_die
= comp_unit_die ();
24153 /* Output a terminator label for the .text section. */
24154 switch_to_section (text_section
);
24155 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24156 if (cold_text_section
)
24158 switch_to_section (cold_text_section
);
24159 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24162 /* We can only use the low/high_pc attributes if all of the code was
24164 if (!have_multiple_function_sections
24165 || (dwarf_version
< 3 && dwarf_strict
))
24167 /* Don't add if the CU has no associated code. */
24168 if (text_section_used
)
24169 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24170 text_end_label
, true);
24176 bool range_list_added
= false;
24178 if (text_section_used
)
24179 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24180 text_end_label
, &range_list_added
, true);
24181 if (cold_text_section_used
)
24182 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24183 cold_end_label
, &range_list_added
, true);
24185 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24187 if (DECL_IGNORED_P (fde
->decl
))
24189 if (!fde
->in_std_section
)
24190 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24191 fde
->dw_fde_end
, &range_list_added
,
24193 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24194 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24195 fde
->dw_fde_second_end
, &range_list_added
,
24199 if (range_list_added
)
24201 /* We need to give .debug_loc and .debug_ranges an appropriate
24202 "base address". Use zero so that these addresses become
24203 absolute. Historically, we've emitted the unexpected
24204 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24205 Emit both to give time for other tools to adapt. */
24206 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24207 if (! dwarf_strict
&& dwarf_version
< 4)
24208 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24214 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24215 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24216 debug_line_section_label
);
24219 add_AT_macptr (comp_unit_die (),
24220 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24221 macinfo_section_label
);
24223 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
24225 /* optimize_location_lists calculates the size of the lists,
24226 so index them first, and assign indices to the entries.
24227 Although optimize_location_lists will remove entries from
24228 the table, it only does so for duplicates, and therefore
24229 only reduces ref_counts to 1. */
24230 unsigned int index
= 0;
24231 index_location_lists (comp_unit_die ());
24232 htab_traverse_noresize (addr_index_table
,
24233 index_addr_table_entry
, &index
);
24235 if (have_location_lists
)
24236 optimize_location_lists (comp_unit_die ());
24238 save_macinfo_strings ();
24240 if (dwarf_split_debug_info
)
24242 unsigned int index
= 0;
24244 /* Add attributes common to skeleton compile_units and
24245 type_units. Because these attributes include strings, it
24246 must be done before freezing the string table. Top-level
24247 skeleton die attrs are added when the skeleton type unit is
24248 created, so ensure it is created by this point. */
24249 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24250 (void) get_skeleton_type_unit ();
24251 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24254 /* Output all of the compilation units. We put the main one last so that
24255 the offsets are available to output_pubnames. */
24256 for (node
= limbo_die_list
; node
; node
= node
->next
)
24257 output_comp_unit (node
->die
, 0);
24259 comdat_type_table
.create (100);
24260 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24262 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24264 /* Don't output duplicate types. */
24265 if (*slot
!= HTAB_EMPTY_ENTRY
)
24268 /* Add a pointer to the line table for the main compilation unit
24269 so that the debugger can make sense of DW_AT_decl_file
24271 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24272 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24273 (!dwarf_split_debug_info
24274 ? debug_line_section_label
24275 : debug_skeleton_line_section_label
));
24277 output_comdat_type_unit (ctnode
);
24280 comdat_type_table
.dispose ();
24282 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24283 both the main_cu and all skeleton TUs. Making this call unconditional
24284 would end up either adding a second copy of the AT_pubnames attribute, or
24285 requiring a special case in add_top_level_skeleton_die_attrs. */
24286 if (!dwarf_split_debug_info
)
24287 add_AT_pubnames (comp_unit_die ());
24289 if (dwarf_split_debug_info
)
24292 unsigned char checksum
[16];
24293 struct md5_ctx ctx
;
24295 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24296 md5_init_ctx (&ctx
);
24298 die_checksum (comp_unit_die (), &ctx
, &mark
);
24299 unmark_all_dies (comp_unit_die ());
24300 md5_finish_ctx (&ctx
, checksum
);
24302 /* Use the first 8 bytes of the checksum as the dwo_id,
24303 and add it to both comp-unit DIEs. */
24304 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24305 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24307 /* Add the base offset of the ranges table to the skeleton
24309 if (ranges_table_in_use
)
24310 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24311 ranges_section_label
);
24313 switch_to_section (debug_addr_section
);
24314 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24315 output_addr_table ();
24318 /* Output the main compilation unit if non-empty or if .debug_macinfo
24319 or .debug_macro will be emitted. */
24320 output_comp_unit (comp_unit_die (), have_macinfo
);
24322 if (dwarf_split_debug_info
&& info_section_emitted
)
24323 output_skeleton_debug_sections (main_comp_unit_die
);
24325 /* Output the abbreviation table. */
24326 if (abbrev_die_table_in_use
!= 1)
24328 switch_to_section (debug_abbrev_section
);
24329 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24330 output_abbrev_section ();
24333 /* Output location list section if necessary. */
24334 if (have_location_lists
)
24336 /* Output the location lists info. */
24337 switch_to_section (debug_loc_section
);
24338 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24339 output_location_lists (comp_unit_die ());
24342 output_pubtables ();
24344 /* Output the address range information if a CU (.debug_info section)
24345 was emitted. We output an empty table even if we had no functions
24346 to put in it. This because the consumer has no way to tell the
24347 difference between an empty table that we omitted and failure to
24348 generate a table that would have contained data. */
24349 if (info_section_emitted
)
24351 unsigned long aranges_length
= size_of_aranges ();
24353 switch_to_section (debug_aranges_section
);
24354 output_aranges (aranges_length
);
24357 /* Output ranges section if necessary. */
24358 if (ranges_table_in_use
)
24360 switch_to_section (debug_ranges_section
);
24361 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24365 /* Have to end the macro section. */
24368 switch_to_section (debug_macinfo_section
);
24369 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24371 dw2_asm_output_data (1, 0, "End compilation unit");
24374 /* Output the source line correspondence table. We must do this
24375 even if there is no line information. Otherwise, on an empty
24376 translation unit, we will generate a present, but empty,
24377 .debug_info section. IRIX 6.5 `nm' will then complain when
24378 examining the file. This is done late so that any filenames
24379 used by the debug_info section are marked as 'used'. */
24380 switch_to_section (debug_line_section
);
24381 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24382 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24383 output_line_info (false);
24385 if (dwarf_split_debug_info
&& info_section_emitted
)
24387 switch_to_section (debug_skeleton_line_section
);
24388 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24389 output_line_info (true);
24392 /* If we emitted any indirect strings, output the string table too. */
24393 if (debug_str_hash
|| skeleton_debug_str_hash
)
24394 output_indirect_strings ();
24397 #include "gt-dwarf2out.h"