1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2013 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
64 #include "stringpool.h"
65 #include "stor-layout.h"
72 #include "hard-reg-set.h"
74 #include "insn-config.h"
81 #include "dwarf2out.h"
82 #include "dwarf2asm.h"
87 #include "diagnostic.h"
88 #include "tree-pretty-print.h"
91 #include "common/common-target.h"
92 #include "langhooks.h"
93 #include "hash-table.h"
100 #include "tree-dfa.h"
101 #include "gdb/gdb-index.h"
103 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
104 static rtx last_var_location_insn
;
105 static rtx cached_next_real_insn
;
107 #ifdef VMS_DEBUGGING_INFO
108 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
110 /* Define this macro to be a nonzero value if the directory specifications
111 which are output in the debug info should end with a separator. */
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
113 /* Define this macro to evaluate to a nonzero value if GCC should refrain
114 from generating indirect strings in DWARF2 debug information, for instance
115 if your target is stuck with an old version of GDB that is unable to
116 process them properly or uses VMS Debug. */
117 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
119 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
120 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
123 /* ??? Poison these here until it can be done generically. They've been
124 totally replaced in this file; make sure it stays that way. */
125 #undef DWARF2_UNWIND_INFO
126 #undef DWARF2_FRAME_INFO
127 #if (GCC_VERSION >= 3000)
128 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
131 /* The size of the target's pointer type. */
133 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
136 /* Array of RTXes referenced by the debugging information, which therefore
137 must be kept around forever. */
138 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
140 /* A pointer to the base of a list of incomplete types which might be
141 completed at some later time. incomplete_types_list needs to be a
142 vec<tree, va_gc> *because we want to tell the garbage collector about
144 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
146 /* A pointer to the base of a table of references to declaration
147 scopes. This table is a display which tracks the nesting
148 of declaration scopes at the current scope and containing
149 scopes. This table is used to find the proper place to
150 define type declaration DIE's. */
151 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
153 /* Pointers to various DWARF2 sections. */
154 static GTY(()) section
*debug_info_section
;
155 static GTY(()) section
*debug_skeleton_info_section
;
156 static GTY(()) section
*debug_abbrev_section
;
157 static GTY(()) section
*debug_skeleton_abbrev_section
;
158 static GTY(()) section
*debug_aranges_section
;
159 static GTY(()) section
*debug_addr_section
;
160 static GTY(()) section
*debug_macinfo_section
;
161 static GTY(()) section
*debug_line_section
;
162 static GTY(()) section
*debug_skeleton_line_section
;
163 static GTY(()) section
*debug_loc_section
;
164 static GTY(()) section
*debug_pubnames_section
;
165 static GTY(()) section
*debug_pubtypes_section
;
166 static GTY(()) section
*debug_str_section
;
167 static GTY(()) section
*debug_str_dwo_section
;
168 static GTY(()) section
*debug_str_offsets_section
;
169 static GTY(()) section
*debug_ranges_section
;
170 static GTY(()) section
*debug_frame_section
;
172 /* Maximum size (in bytes) of an artificially generated label. */
173 #define MAX_ARTIFICIAL_LABEL_BYTES 30
175 /* According to the (draft) DWARF 3 specification, the initial length
176 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
177 bytes are 0xffffffff, followed by the length stored in the next 8
180 However, the SGI/MIPS ABI uses an initial length which is equal to
181 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
183 #ifndef DWARF_INITIAL_LENGTH_SIZE
184 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
187 /* Round SIZE up to the nearest BOUNDARY. */
188 #define DWARF_ROUND(SIZE,BOUNDARY) \
189 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
191 /* CIE identifier. */
192 #if HOST_BITS_PER_WIDE_INT >= 64
193 #define DWARF_CIE_ID \
194 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
196 #define DWARF_CIE_ID DW_CIE_ID
200 /* A vector for a table that contains frame description
201 information for each routine. */
202 #define NOT_INDEXED (-1U)
203 #define NO_INDEX_ASSIGNED (-2U)
205 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
207 struct GTY(()) indirect_string_node
{
209 unsigned int refcount
;
210 enum dwarf_form form
;
215 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
217 /* With split_debug_info, both the comp_dir and dwo_name go in the
218 main object file, rather than the dwo, similar to the force_direct
219 parameter elsewhere but with additional complications:
221 1) The string is needed in both the main object file and the dwo.
222 That is, the comp_dir and dwo_name will appear in both places.
224 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
225 DW_FORM_GNU_str_index.
227 3) GCC chooses the form to use late, depending on the size and
230 Rather than forcing the all debug string handling functions and
231 callers to deal with these complications, simply use a separate,
232 special-cased string table for any attribute that should go in the
233 main object file. This limits the complexity to just the places
236 static GTY ((param_is (struct indirect_string_node
)))
237 htab_t skeleton_debug_str_hash
;
239 static GTY(()) int dw2_string_counter
;
241 /* True if the compilation unit places functions in more than one section. */
242 static GTY(()) bool have_multiple_function_sections
= false;
244 /* Whether the default text and cold text sections have been used at all. */
246 static GTY(()) bool text_section_used
= false;
247 static GTY(()) bool cold_text_section_used
= false;
249 /* The default cold text section. */
250 static GTY(()) section
*cold_text_section
;
252 /* Forward declarations for functions defined in this file. */
254 static char *stripattributes (const char *);
255 static void output_call_frame_info (int);
256 static void dwarf2out_note_section_used (void);
258 /* Personality decl of current unit. Used only when assembler does not support
260 static GTY(()) rtx current_unit_personality
;
262 /* Data and reference forms for relocatable data. */
263 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
264 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
266 #ifndef DEBUG_FRAME_SECTION
267 #define DEBUG_FRAME_SECTION ".debug_frame"
270 #ifndef FUNC_BEGIN_LABEL
271 #define FUNC_BEGIN_LABEL "LFB"
274 #ifndef FUNC_END_LABEL
275 #define FUNC_END_LABEL "LFE"
278 #ifndef PROLOGUE_END_LABEL
279 #define PROLOGUE_END_LABEL "LPE"
282 #ifndef EPILOGUE_BEGIN_LABEL
283 #define EPILOGUE_BEGIN_LABEL "LEB"
286 #ifndef FRAME_BEGIN_LABEL
287 #define FRAME_BEGIN_LABEL "Lframe"
289 #define CIE_AFTER_SIZE_LABEL "LSCIE"
290 #define CIE_END_LABEL "LECIE"
291 #define FDE_LABEL "LSFDE"
292 #define FDE_AFTER_SIZE_LABEL "LASFDE"
293 #define FDE_END_LABEL "LEFDE"
294 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
295 #define LINE_NUMBER_END_LABEL "LELT"
296 #define LN_PROLOG_AS_LABEL "LASLTP"
297 #define LN_PROLOG_END_LABEL "LELTP"
298 #define DIE_LABEL_PREFIX "DW"
300 /* Match the base name of a file to the base name of a compilation unit. */
303 matches_main_base (const char *path
)
305 /* Cache the last query. */
306 static const char *last_path
= NULL
;
307 static int last_match
= 0;
308 if (path
!= last_path
)
311 int length
= base_of_path (path
, &base
);
313 last_match
= (length
== main_input_baselength
314 && memcmp (base
, main_input_basename
, length
) == 0);
319 #ifdef DEBUG_DEBUG_STRUCT
322 dump_struct_debug (tree type
, enum debug_info_usage usage
,
323 enum debug_struct_file criterion
, int generic
,
324 int matches
, int result
)
326 /* Find the type name. */
327 tree type_decl
= TYPE_STUB_DECL (type
);
329 const char *name
= 0;
330 if (TREE_CODE (t
) == TYPE_DECL
)
333 name
= IDENTIFIER_POINTER (t
);
335 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
337 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
338 matches
? "bas" : "hdr",
339 generic
? "gen" : "ord",
340 usage
== DINFO_USAGE_DFN
? ";" :
341 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
343 (void*) type_decl
, name
);
346 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
347 dump_struct_debug (type, usage, criterion, generic, matches, result)
351 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
357 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
359 enum debug_struct_file criterion
;
361 bool generic
= lang_hooks
.types
.generic_p (type
);
364 criterion
= debug_struct_generic
[usage
];
366 criterion
= debug_struct_ordinary
[usage
];
368 if (criterion
== DINFO_STRUCT_FILE_NONE
)
369 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
370 if (criterion
== DINFO_STRUCT_FILE_ANY
)
371 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
373 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
375 if (type_decl
!= NULL
)
377 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
378 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
380 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
381 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
384 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
387 /* Return a pointer to a copy of the section string name S with all
388 attributes stripped off, and an asterisk prepended (for assemble_name). */
391 stripattributes (const char *s
)
393 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
398 while (*s
&& *s
!= ',')
405 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
406 switch to the data section instead, and write out a synthetic start label
407 for collect2 the first time around. */
410 switch_to_eh_frame_section (bool back
)
414 #ifdef EH_FRAME_SECTION_NAME
415 if (eh_frame_section
== 0)
419 if (EH_TABLES_CAN_BE_READ_ONLY
)
425 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
427 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
429 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
432 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
433 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
434 && (per_encoding
& 0x70) != DW_EH_PE_absptr
435 && (per_encoding
& 0x70) != DW_EH_PE_aligned
436 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
437 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
438 ? 0 : SECTION_WRITE
);
441 flags
= SECTION_WRITE
;
442 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
444 #endif /* EH_FRAME_SECTION_NAME */
446 if (eh_frame_section
)
447 switch_to_section (eh_frame_section
);
450 /* We have no special eh_frame section. Put the information in
451 the data section and emit special labels to guide collect2. */
452 switch_to_section (data_section
);
456 label
= get_file_function_name ("F");
457 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
458 targetm
.asm_out
.globalize_label (asm_out_file
,
459 IDENTIFIER_POINTER (label
));
460 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
465 /* Switch [BACK] to the eh or debug frame table section, depending on
469 switch_to_frame_table_section (int for_eh
, bool back
)
472 switch_to_eh_frame_section (back
);
475 if (!debug_frame_section
)
476 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
477 SECTION_DEBUG
, NULL
);
478 switch_to_section (debug_frame_section
);
482 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
484 enum dw_cfi_oprnd_type
485 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
490 case DW_CFA_GNU_window_save
:
491 case DW_CFA_remember_state
:
492 case DW_CFA_restore_state
:
493 return dw_cfi_oprnd_unused
;
496 case DW_CFA_advance_loc1
:
497 case DW_CFA_advance_loc2
:
498 case DW_CFA_advance_loc4
:
499 case DW_CFA_MIPS_advance_loc8
:
500 return dw_cfi_oprnd_addr
;
503 case DW_CFA_offset_extended
:
505 case DW_CFA_offset_extended_sf
:
506 case DW_CFA_def_cfa_sf
:
508 case DW_CFA_restore_extended
:
509 case DW_CFA_undefined
:
510 case DW_CFA_same_value
:
511 case DW_CFA_def_cfa_register
:
512 case DW_CFA_register
:
513 case DW_CFA_expression
:
514 return dw_cfi_oprnd_reg_num
;
516 case DW_CFA_def_cfa_offset
:
517 case DW_CFA_GNU_args_size
:
518 case DW_CFA_def_cfa_offset_sf
:
519 return dw_cfi_oprnd_offset
;
521 case DW_CFA_def_cfa_expression
:
522 return dw_cfi_oprnd_loc
;
529 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
531 enum dw_cfi_oprnd_type
532 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
537 case DW_CFA_def_cfa_sf
:
539 case DW_CFA_offset_extended_sf
:
540 case DW_CFA_offset_extended
:
541 return dw_cfi_oprnd_offset
;
543 case DW_CFA_register
:
544 return dw_cfi_oprnd_reg_num
;
546 case DW_CFA_expression
:
547 return dw_cfi_oprnd_loc
;
550 return dw_cfi_oprnd_unused
;
554 /* Output one FDE. */
557 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
558 char *section_start_label
, int fde_encoding
, char *augmentation
,
559 bool any_lsda_needed
, int lsda_encoding
)
561 const char *begin
, *end
;
562 static unsigned int j
;
565 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
567 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
569 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
570 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
571 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
572 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
573 " indicating 64-bit DWARF extension");
574 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
576 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
579 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
581 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
582 debug_frame_section
, "FDE CIE offset");
584 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
585 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
589 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
590 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
591 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
592 "FDE initial location");
593 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
594 end
, begin
, "FDE address range");
598 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
599 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
606 int size
= size_of_encoded_value (lsda_encoding
);
608 if (lsda_encoding
== DW_EH_PE_aligned
)
610 int offset
= ( 4 /* Length */
612 + 2 * size_of_encoded_value (fde_encoding
)
613 + 1 /* Augmentation size */ );
614 int pad
= -offset
& (PTR_SIZE
- 1);
617 gcc_assert (size_of_uleb128 (size
) == 1);
620 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
622 if (fde
->uses_eh_lsda
)
624 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
625 fde
->funcdef_number
);
626 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
627 gen_rtx_SYMBOL_REF (Pmode
, l1
),
629 "Language Specific Data Area");
633 if (lsda_encoding
== DW_EH_PE_aligned
)
634 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
635 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
636 "Language Specific Data Area (none)");
640 dw2_asm_output_data_uleb128 (0, "Augmentation size");
643 /* Loop through the Call Frame Instructions associated with this FDE. */
644 fde
->dw_fde_current_label
= begin
;
646 size_t from
, until
, i
;
649 until
= vec_safe_length (fde
->dw_fde_cfi
);
651 if (fde
->dw_fde_second_begin
== NULL
)
654 until
= fde
->dw_fde_switch_cfi_index
;
656 from
= fde
->dw_fde_switch_cfi_index
;
658 for (i
= from
; i
< until
; i
++)
659 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
662 /* If we are to emit a ref/link from function bodies to their frame tables,
663 do it now. This is typically performed to make sure that tables
664 associated with functions are dragged with them and not discarded in
665 garbage collecting links. We need to do this on a per function basis to
666 cope with -ffunction-sections. */
668 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
669 /* Switch to the function section, emit the ref to the tables, and
670 switch *back* into the table section. */
671 switch_to_section (function_section (fde
->decl
));
672 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
673 switch_to_frame_table_section (for_eh
, true);
676 /* Pad the FDE out to an address sized boundary. */
677 ASM_OUTPUT_ALIGN (asm_out_file
,
678 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
679 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
684 /* Return true if frame description entry FDE is needed for EH. */
687 fde_needed_for_eh_p (dw_fde_ref fde
)
689 if (flag_asynchronous_unwind_tables
)
692 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
695 if (fde
->uses_eh_lsda
)
698 /* If exceptions are enabled, we have collected nothrow info. */
699 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
705 /* Output the call frame information used to record information
706 that relates to calculating the frame pointer, and records the
707 location of saved registers. */
710 output_call_frame_info (int for_eh
)
715 char l1
[20], l2
[20], section_start_label
[20];
716 bool any_lsda_needed
= false;
717 char augmentation
[6];
718 int augmentation_size
;
719 int fde_encoding
= DW_EH_PE_absptr
;
720 int per_encoding
= DW_EH_PE_absptr
;
721 int lsda_encoding
= DW_EH_PE_absptr
;
723 rtx personality
= NULL
;
726 /* Don't emit a CIE if there won't be any FDEs. */
730 /* Nothing to do if the assembler's doing it all. */
731 if (dwarf2out_do_cfi_asm ())
734 /* If we don't have any functions we'll want to unwind out of, don't emit
735 any EH unwind information. If we make FDEs linkonce, we may have to
736 emit an empty label for an FDE that wouldn't otherwise be emitted. We
737 want to avoid having an FDE kept around when the function it refers to
738 is discarded. Example where this matters: a primary function template
739 in C++ requires EH information, an explicit specialization doesn't. */
742 bool any_eh_needed
= false;
744 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
746 if (fde
->uses_eh_lsda
)
747 any_eh_needed
= any_lsda_needed
= true;
748 else if (fde_needed_for_eh_p (fde
))
749 any_eh_needed
= true;
750 else if (TARGET_USES_WEAK_UNWIND_INFO
)
751 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
758 /* We're going to be generating comments, so turn on app. */
762 /* Switch to the proper frame section, first time. */
763 switch_to_frame_table_section (for_eh
, false);
765 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
766 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
768 /* Output the CIE. */
769 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
770 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
771 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
772 dw2_asm_output_data (4, 0xffffffff,
773 "Initial length escape value indicating 64-bit DWARF extension");
774 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
775 "Length of Common Information Entry");
776 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
778 /* Now that the CIE pointer is PC-relative for EH,
779 use 0 to identify the CIE. */
780 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
781 (for_eh
? 0 : DWARF_CIE_ID
),
782 "CIE Identifier Tag");
784 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
785 use CIE version 1, unless that would produce incorrect results
786 due to overflowing the return register column. */
787 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
789 if (return_reg
>= 256 || dwarf_version
> 2)
791 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
794 augmentation_size
= 0;
796 personality
= current_unit_personality
;
802 z Indicates that a uleb128 is present to size the
803 augmentation section.
804 L Indicates the encoding (and thus presence) of
805 an LSDA pointer in the FDE augmentation.
806 R Indicates a non-default pointer encoding for
808 P Indicates the presence of an encoding + language
809 personality routine in the CIE augmentation. */
811 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
812 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
813 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
815 p
= augmentation
+ 1;
819 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
820 assemble_external_libcall (personality
);
825 augmentation_size
+= 1;
827 if (fde_encoding
!= DW_EH_PE_absptr
)
830 augmentation_size
+= 1;
832 if (p
> augmentation
+ 1)
834 augmentation
[0] = 'z';
838 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
839 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
841 int offset
= ( 4 /* Length */
843 + 1 /* CIE version */
844 + strlen (augmentation
) + 1 /* Augmentation */
845 + size_of_uleb128 (1) /* Code alignment */
846 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
848 + 1 /* Augmentation size */
849 + 1 /* Personality encoding */ );
850 int pad
= -offset
& (PTR_SIZE
- 1);
852 augmentation_size
+= pad
;
854 /* Augmentations should be small, so there's scarce need to
855 iterate for a solution. Die if we exceed one uleb128 byte. */
856 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
860 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
861 if (dw_cie_version
>= 4)
863 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
864 dw2_asm_output_data (1, 0, "CIE Segment Size");
866 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
867 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
868 "CIE Data Alignment Factor");
870 if (dw_cie_version
== 1)
871 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
873 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
877 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
880 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
881 eh_data_format_name (per_encoding
));
882 dw2_asm_output_encoded_addr_rtx (per_encoding
,
888 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
889 eh_data_format_name (lsda_encoding
));
891 if (fde_encoding
!= DW_EH_PE_absptr
)
892 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
893 eh_data_format_name (fde_encoding
));
896 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
897 output_cfi (cfi
, NULL
, for_eh
);
899 /* Pad the CIE out to an address sized boundary. */
900 ASM_OUTPUT_ALIGN (asm_out_file
,
901 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
902 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
904 /* Loop through all of the FDE's. */
905 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
909 /* Don't emit EH unwind info for leaf functions that don't need it. */
910 if (for_eh
&& !fde_needed_for_eh_p (fde
))
913 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
914 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
915 augmentation
, any_lsda_needed
, lsda_encoding
);
918 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
919 dw2_asm_output_data (4, 0, "End of Table");
921 /* Turn off app to make assembly quicker. */
926 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
929 dwarf2out_do_cfi_startproc (bool second
)
933 rtx personality
= get_personality_function (current_function_decl
);
935 fprintf (asm_out_file
, "\t.cfi_startproc\n");
939 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
942 /* ??? The GAS support isn't entirely consistent. We have to
943 handle indirect support ourselves, but PC-relative is done
944 in the assembler. Further, the assembler can't handle any
945 of the weirder relocation types. */
946 if (enc
& DW_EH_PE_indirect
)
947 ref
= dw2_force_const_mem (ref
, true);
949 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
950 output_addr_const (asm_out_file
, ref
);
951 fputc ('\n', asm_out_file
);
954 if (crtl
->uses_eh_lsda
)
958 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
959 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
960 current_function_funcdef_no
);
961 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
962 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
964 if (enc
& DW_EH_PE_indirect
)
965 ref
= dw2_force_const_mem (ref
, true);
967 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
968 output_addr_const (asm_out_file
, ref
);
969 fputc ('\n', asm_out_file
);
973 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
974 this allocation may be done before pass_final. */
977 dwarf2out_alloc_current_fde (void)
981 fde
= ggc_alloc_cleared_dw_fde_node ();
982 fde
->decl
= current_function_decl
;
983 fde
->funcdef_number
= current_function_funcdef_no
;
984 fde
->fde_index
= vec_safe_length (fde_vec
);
985 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
986 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
987 fde
->nothrow
= crtl
->nothrow
;
988 fde
->drap_reg
= INVALID_REGNUM
;
989 fde
->vdrap_reg
= INVALID_REGNUM
;
991 /* Record the FDE associated with this function. */
993 vec_safe_push (fde_vec
, fde
);
998 /* Output a marker (i.e. a label) for the beginning of a function, before
1002 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1003 const char *file ATTRIBUTE_UNUSED
)
1005 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1011 current_function_func_begin_label
= NULL
;
1013 do_frame
= dwarf2out_do_frame ();
1015 /* ??? current_function_func_begin_label is also used by except.c for
1016 call-site information. We must emit this label if it might be used. */
1018 && (!flag_exceptions
1019 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1022 fnsec
= function_section (current_function_decl
);
1023 switch_to_section (fnsec
);
1024 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1025 current_function_funcdef_no
);
1026 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1027 current_function_funcdef_no
);
1028 dup_label
= xstrdup (label
);
1029 current_function_func_begin_label
= dup_label
;
1031 /* We can elide the fde allocation if we're not emitting debug info. */
1035 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1036 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1037 would include pass_dwarf2_frame. If we've not created the FDE yet,
1041 fde
= dwarf2out_alloc_current_fde ();
1043 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1044 fde
->dw_fde_begin
= dup_label
;
1045 fde
->dw_fde_current_label
= dup_label
;
1046 fde
->in_std_section
= (fnsec
== text_section
1047 || (cold_text_section
&& fnsec
== cold_text_section
));
1049 /* We only want to output line number information for the genuine dwarf2
1050 prologue case, not the eh frame case. */
1051 #ifdef DWARF2_DEBUGGING_INFO
1053 dwarf2out_source_line (line
, file
, 0, true);
1056 if (dwarf2out_do_cfi_asm ())
1057 dwarf2out_do_cfi_startproc (false);
1060 rtx personality
= get_personality_function (current_function_decl
);
1061 if (!current_unit_personality
)
1062 current_unit_personality
= personality
;
1064 /* We cannot keep a current personality per function as without CFI
1065 asm, at the point where we emit the CFI data, there is no current
1066 function anymore. */
1067 if (personality
&& current_unit_personality
!= personality
)
1068 sorry ("multiple EH personalities are supported only with assemblers "
1069 "supporting .cfi_personality directive");
1073 /* Output a marker (i.e. a label) for the end of the generated code
1074 for a function prologue. This gets called *after* the prologue code has
1078 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1079 const char *file ATTRIBUTE_UNUSED
)
1081 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1083 /* Output a label to mark the endpoint of the code generated for this
1085 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1086 current_function_funcdef_no
);
1087 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1088 current_function_funcdef_no
);
1089 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1092 /* Output a marker (i.e. a label) for the beginning of the generated code
1093 for a function epilogue. This gets called *before* the prologue code has
1097 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1098 const char *file ATTRIBUTE_UNUSED
)
1100 dw_fde_ref fde
= cfun
->fde
;
1101 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1103 if (fde
->dw_fde_vms_begin_epilogue
)
1106 /* Output a label to mark the endpoint of the code generated for this
1108 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1109 current_function_funcdef_no
);
1110 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1111 current_function_funcdef_no
);
1112 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1115 /* Output a marker (i.e. a label) for the absolute end of the generated code
1116 for a function definition. This gets called *after* the epilogue code has
1120 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1121 const char *file ATTRIBUTE_UNUSED
)
1124 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1126 last_var_location_insn
= NULL_RTX
;
1127 cached_next_real_insn
= NULL_RTX
;
1129 if (dwarf2out_do_cfi_asm ())
1130 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1132 /* Output a label to mark the endpoint of the code generated for this
1134 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1135 current_function_funcdef_no
);
1136 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1138 gcc_assert (fde
!= NULL
);
1139 if (fde
->dw_fde_second_begin
== NULL
)
1140 fde
->dw_fde_end
= xstrdup (label
);
1144 dwarf2out_frame_finish (void)
1146 /* Output call frame information. */
1147 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1148 output_call_frame_info (0);
1150 /* Output another copy for the unwinder. */
1151 if ((flag_unwind_tables
|| flag_exceptions
)
1152 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1153 output_call_frame_info (1);
1156 /* Note that the current function section is being used for code. */
1159 dwarf2out_note_section_used (void)
1161 section
*sec
= current_function_section ();
1162 if (sec
== text_section
)
1163 text_section_used
= true;
1164 else if (sec
== cold_text_section
)
1165 cold_text_section_used
= true;
1168 static void var_location_switch_text_section (void);
1169 static void set_cur_line_info_table (section
*);
1172 dwarf2out_switch_text_section (void)
1175 dw_fde_ref fde
= cfun
->fde
;
1177 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1179 if (!in_cold_section_p
)
1181 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1182 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1183 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1187 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1188 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1189 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1191 have_multiple_function_sections
= true;
1193 /* There is no need to mark used sections when not debugging. */
1194 if (cold_text_section
!= NULL
)
1195 dwarf2out_note_section_used ();
1197 if (dwarf2out_do_cfi_asm ())
1198 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1200 /* Now do the real section switch. */
1201 sect
= current_function_section ();
1202 switch_to_section (sect
);
1204 fde
->second_in_std_section
1205 = (sect
== text_section
1206 || (cold_text_section
&& sect
== cold_text_section
));
1208 if (dwarf2out_do_cfi_asm ())
1209 dwarf2out_do_cfi_startproc (true);
1211 var_location_switch_text_section ();
1213 if (cold_text_section
!= NULL
)
1214 set_cur_line_info_table (sect
);
1217 /* And now, the subset of the debugging information support code necessary
1218 for emitting location expressions. */
1220 /* Data about a single source file. */
1221 struct GTY(()) dwarf_file_data
{
1222 const char * filename
;
1226 typedef struct GTY(()) deferred_locations_struct
1230 } deferred_locations
;
1233 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1236 /* Describe an entry into the .debug_addr section. */
1240 ate_kind_rtx_dtprel
,
1244 typedef struct GTY(()) addr_table_entry_struct
{
1246 unsigned int refcount
;
1248 union addr_table_entry_struct_union
1250 rtx
GTY ((tag ("0"))) rtl
;
1251 char * GTY ((tag ("1"))) label
;
1253 GTY ((desc ("%1.kind"))) addr
;
1257 /* Location lists are ranges + location descriptions for that range,
1258 so you can track variables that are in different places over
1259 their entire life. */
1260 typedef struct GTY(()) dw_loc_list_struct
{
1261 dw_loc_list_ref dw_loc_next
;
1262 const char *begin
; /* Label and addr_entry for start of range */
1263 addr_table_entry
*begin_entry
;
1264 const char *end
; /* Label for end of range */
1265 char *ll_symbol
; /* Label for beginning of location list.
1266 Only on head of list */
1267 const char *section
; /* Section this loclist is relative to */
1268 dw_loc_descr_ref expr
;
1270 /* True if all addresses in this and subsequent lists are known to be
1273 /* True if this list has been replaced by dw_loc_next. */
1276 /* True if the range should be emitted even if begin and end
1281 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1283 /* Convert a DWARF stack opcode into its string name. */
1286 dwarf_stack_op_name (unsigned int op
)
1288 const char *name
= get_DW_OP_name (op
);
1293 return "OP_<unknown>";
1296 /* Return a pointer to a newly allocated location description. Location
1297 descriptions are simple expression terms that can be strung
1298 together to form more complicated location (address) descriptions. */
1300 static inline dw_loc_descr_ref
1301 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1302 unsigned HOST_WIDE_INT oprnd2
)
1304 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1306 descr
->dw_loc_opc
= op
;
1307 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1308 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1309 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1310 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1311 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1312 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1317 /* Return a pointer to a newly allocated location description for
1320 static inline dw_loc_descr_ref
1321 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1324 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1327 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1330 /* Add a location description term to a location description expression. */
1333 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1335 dw_loc_descr_ref
*d
;
1337 /* Find the end of the chain. */
1338 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1344 /* Compare two location operands for exact equality. */
1347 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1349 if (a
->val_class
!= b
->val_class
)
1351 switch (a
->val_class
)
1353 case dw_val_class_none
:
1355 case dw_val_class_addr
:
1356 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1358 case dw_val_class_offset
:
1359 case dw_val_class_unsigned_const
:
1360 case dw_val_class_const
:
1361 case dw_val_class_range_list
:
1362 case dw_val_class_lineptr
:
1363 case dw_val_class_macptr
:
1364 /* These are all HOST_WIDE_INT, signed or unsigned. */
1365 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1367 case dw_val_class_loc
:
1368 return a
->v
.val_loc
== b
->v
.val_loc
;
1369 case dw_val_class_loc_list
:
1370 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1371 case dw_val_class_die_ref
:
1372 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1373 case dw_val_class_fde_ref
:
1374 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1375 case dw_val_class_lbl_id
:
1376 case dw_val_class_high_pc
:
1377 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1378 case dw_val_class_str
:
1379 return a
->v
.val_str
== b
->v
.val_str
;
1380 case dw_val_class_flag
:
1381 return a
->v
.val_flag
== b
->v
.val_flag
;
1382 case dw_val_class_file
:
1383 return a
->v
.val_file
== b
->v
.val_file
;
1384 case dw_val_class_decl_ref
:
1385 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1387 case dw_val_class_const_double
:
1388 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1389 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1391 case dw_val_class_vec
:
1393 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1394 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1396 return (a_len
== b_len
1397 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1400 case dw_val_class_data8
:
1401 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1403 case dw_val_class_vms_delta
:
1404 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1405 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1410 /* Compare two location atoms for exact equality. */
1413 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1415 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1418 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1419 address size, but since we always allocate cleared storage it
1420 should be zero for other types of locations. */
1421 if (a
->dtprel
!= b
->dtprel
)
1424 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1425 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1428 /* Compare two complete location expressions for exact equality. */
1431 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1437 if (a
== NULL
|| b
== NULL
)
1439 if (!loc_descr_equal_p_1 (a
, b
))
1448 /* Add a constant OFFSET to a location expression. */
1451 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1453 dw_loc_descr_ref loc
;
1456 gcc_assert (*list_head
!= NULL
);
1461 /* Find the end of the chain. */
1462 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1466 if (loc
->dw_loc_opc
== DW_OP_fbreg
1467 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1468 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1469 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1470 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1472 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1473 offset. Don't optimize if an signed integer overflow would happen. */
1475 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1476 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1479 else if (offset
> 0)
1480 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1484 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1485 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1489 /* Add a constant OFFSET to a location list. */
1492 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1495 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1496 loc_descr_plus_const (&d
->expr
, offset
);
1499 #define DWARF_REF_SIZE \
1500 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1502 static unsigned long int get_base_type_offset (dw_die_ref
);
1504 /* Return the size of a location descriptor. */
1506 static unsigned long
1507 size_of_loc_descr (dw_loc_descr_ref loc
)
1509 unsigned long size
= 1;
1511 switch (loc
->dw_loc_opc
)
1514 size
+= DWARF2_ADDR_SIZE
;
1516 case DW_OP_GNU_addr_index
:
1517 case DW_OP_GNU_const_index
:
1518 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1519 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1538 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1541 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1546 case DW_OP_plus_uconst
:
1547 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1585 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1588 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1591 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1594 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1595 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1598 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1600 case DW_OP_bit_piece
:
1601 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1602 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1604 case DW_OP_deref_size
:
1605 case DW_OP_xderef_size
:
1614 case DW_OP_call_ref
:
1615 size
+= DWARF_REF_SIZE
;
1617 case DW_OP_implicit_value
:
1618 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1619 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1621 case DW_OP_GNU_implicit_pointer
:
1622 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1624 case DW_OP_GNU_entry_value
:
1626 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1627 size
+= size_of_uleb128 (op_size
) + op_size
;
1630 case DW_OP_GNU_const_type
:
1633 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1634 size
+= size_of_uleb128 (o
) + 1;
1635 switch (loc
->dw_loc_oprnd2
.val_class
)
1637 case dw_val_class_vec
:
1638 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1639 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1641 case dw_val_class_const
:
1642 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1644 case dw_val_class_const_double
:
1645 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1652 case DW_OP_GNU_regval_type
:
1655 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1656 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1657 + size_of_uleb128 (o
);
1660 case DW_OP_GNU_deref_type
:
1663 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1664 size
+= 1 + size_of_uleb128 (o
);
1667 case DW_OP_GNU_convert
:
1668 case DW_OP_GNU_reinterpret
:
1669 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1670 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1674 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1675 size
+= size_of_uleb128 (o
);
1678 case DW_OP_GNU_parameter_ref
:
1688 /* Return the size of a series of location descriptors. */
1691 size_of_locs (dw_loc_descr_ref loc
)
1696 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1697 field, to avoid writing to a PCH file. */
1698 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1700 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1702 size
+= size_of_loc_descr (l
);
1707 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1709 l
->dw_loc_addr
= size
;
1710 size
+= size_of_loc_descr (l
);
1716 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1717 static void get_ref_die_offset_label (char *, dw_die_ref
);
1718 static unsigned long int get_ref_die_offset (dw_die_ref
);
1720 /* Output location description stack opcode's operands (if any).
1721 The for_eh_or_skip parameter controls whether register numbers are
1722 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1723 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1724 info). This should be suppressed for the cases that have not been converted
1725 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1728 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1730 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1731 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1733 switch (loc
->dw_loc_opc
)
1735 #ifdef DWARF2_DEBUGGING_INFO
1738 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1743 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1744 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1746 fputc ('\n', asm_out_file
);
1751 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1756 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1757 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1759 fputc ('\n', asm_out_file
);
1764 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1765 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1772 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1773 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1775 dw2_asm_output_data (2, offset
, NULL
);
1778 case DW_OP_implicit_value
:
1779 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1780 switch (val2
->val_class
)
1782 case dw_val_class_const
:
1783 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1785 case dw_val_class_vec
:
1787 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1788 unsigned int len
= val2
->v
.val_vec
.length
;
1792 if (elt_size
> sizeof (HOST_WIDE_INT
))
1797 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1800 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1801 "fp or vector constant word %u", i
);
1804 case dw_val_class_const_double
:
1806 unsigned HOST_WIDE_INT first
, second
;
1808 if (WORDS_BIG_ENDIAN
)
1810 first
= val2
->v
.val_double
.high
;
1811 second
= val2
->v
.val_double
.low
;
1815 first
= val2
->v
.val_double
.low
;
1816 second
= val2
->v
.val_double
.high
;
1818 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1820 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1824 case dw_val_class_addr
:
1825 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1826 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1841 case DW_OP_implicit_value
:
1842 /* We currently don't make any attempt to make sure these are
1843 aligned properly like we do for the main unwind info, so
1844 don't support emitting things larger than a byte if we're
1845 only doing unwinding. */
1850 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1853 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1856 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1859 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1861 case DW_OP_plus_uconst
:
1862 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1896 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1900 unsigned r
= val1
->v
.val_unsigned
;
1901 if (for_eh_or_skip
>= 0)
1902 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1903 gcc_assert (size_of_uleb128 (r
)
1904 == size_of_uleb128 (val1
->v
.val_unsigned
));
1905 dw2_asm_output_data_uleb128 (r
, NULL
);
1909 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1913 unsigned r
= val1
->v
.val_unsigned
;
1914 if (for_eh_or_skip
>= 0)
1915 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1916 gcc_assert (size_of_uleb128 (r
)
1917 == size_of_uleb128 (val1
->v
.val_unsigned
));
1918 dw2_asm_output_data_uleb128 (r
, NULL
);
1919 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1923 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1925 case DW_OP_bit_piece
:
1926 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1927 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1929 case DW_OP_deref_size
:
1930 case DW_OP_xderef_size
:
1931 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1937 if (targetm
.asm_out
.output_dwarf_dtprel
)
1939 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1942 fputc ('\n', asm_out_file
);
1949 #ifdef DWARF2_DEBUGGING_INFO
1950 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1957 case DW_OP_GNU_addr_index
:
1958 case DW_OP_GNU_const_index
:
1959 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1960 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1961 "(index into .debug_addr)");
1964 case DW_OP_GNU_implicit_pointer
:
1966 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1967 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1968 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1969 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1970 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1971 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1975 case DW_OP_GNU_entry_value
:
1976 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1977 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1980 case DW_OP_GNU_const_type
:
1982 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1984 dw2_asm_output_data_uleb128 (o
, NULL
);
1985 switch (val2
->val_class
)
1987 case dw_val_class_const
:
1988 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1989 dw2_asm_output_data (1, l
, NULL
);
1990 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1992 case dw_val_class_vec
:
1994 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1995 unsigned int len
= val2
->v
.val_vec
.length
;
2000 dw2_asm_output_data (1, l
, NULL
);
2001 if (elt_size
> sizeof (HOST_WIDE_INT
))
2006 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2009 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2010 "fp or vector constant word %u", i
);
2013 case dw_val_class_const_double
:
2015 unsigned HOST_WIDE_INT first
, second
;
2016 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2018 dw2_asm_output_data (1, 2 * l
, NULL
);
2019 if (WORDS_BIG_ENDIAN
)
2021 first
= val2
->v
.val_double
.high
;
2022 second
= val2
->v
.val_double
.low
;
2026 first
= val2
->v
.val_double
.low
;
2027 second
= val2
->v
.val_double
.high
;
2029 dw2_asm_output_data (l
, first
, NULL
);
2030 dw2_asm_output_data (l
, second
, NULL
);
2038 case DW_OP_GNU_regval_type
:
2040 unsigned r
= val1
->v
.val_unsigned
;
2041 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2043 if (for_eh_or_skip
>= 0)
2045 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2046 gcc_assert (size_of_uleb128 (r
)
2047 == size_of_uleb128 (val1
->v
.val_unsigned
));
2049 dw2_asm_output_data_uleb128 (r
, NULL
);
2050 dw2_asm_output_data_uleb128 (o
, NULL
);
2053 case DW_OP_GNU_deref_type
:
2055 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2057 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2058 dw2_asm_output_data_uleb128 (o
, NULL
);
2061 case DW_OP_GNU_convert
:
2062 case DW_OP_GNU_reinterpret
:
2063 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2064 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2067 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2069 dw2_asm_output_data_uleb128 (o
, NULL
);
2073 case DW_OP_GNU_parameter_ref
:
2076 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2077 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2078 dw2_asm_output_data (4, o
, NULL
);
2083 /* Other codes have no operands. */
2088 /* Output a sequence of location operations.
2089 The for_eh_or_skip parameter controls whether register numbers are
2090 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2091 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2092 info). This should be suppressed for the cases that have not been converted
2093 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2096 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2098 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2100 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2101 /* Output the opcode. */
2102 if (for_eh_or_skip
>= 0
2103 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2105 unsigned r
= (opc
- DW_OP_breg0
);
2106 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2107 gcc_assert (r
<= 31);
2108 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2110 else if (for_eh_or_skip
>= 0
2111 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2113 unsigned r
= (opc
- DW_OP_reg0
);
2114 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2115 gcc_assert (r
<= 31);
2116 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2119 dw2_asm_output_data (1, opc
,
2120 "%s", dwarf_stack_op_name (opc
));
2122 /* Output the operand(s) (if any). */
2123 output_loc_operands (loc
, for_eh_or_skip
);
2127 /* Output location description stack opcode's operands (if any).
2128 The output is single bytes on a line, suitable for .cfi_escape. */
2131 output_loc_operands_raw (dw_loc_descr_ref loc
)
2133 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2134 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2136 switch (loc
->dw_loc_opc
)
2139 case DW_OP_GNU_addr_index
:
2140 case DW_OP_GNU_const_index
:
2141 case DW_OP_implicit_value
:
2142 /* We cannot output addresses in .cfi_escape, only bytes. */
2148 case DW_OP_deref_size
:
2149 case DW_OP_xderef_size
:
2150 fputc (',', asm_out_file
);
2151 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2156 fputc (',', asm_out_file
);
2157 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2162 fputc (',', asm_out_file
);
2163 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2168 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2169 fputc (',', asm_out_file
);
2170 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2178 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2179 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2181 fputc (',', asm_out_file
);
2182 dw2_asm_output_data_raw (2, offset
);
2188 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2189 gcc_assert (size_of_uleb128 (r
)
2190 == size_of_uleb128 (val1
->v
.val_unsigned
));
2191 fputc (',', asm_out_file
);
2192 dw2_asm_output_data_uleb128_raw (r
);
2197 case DW_OP_plus_uconst
:
2199 fputc (',', asm_out_file
);
2200 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2203 case DW_OP_bit_piece
:
2204 fputc (',', asm_out_file
);
2205 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2206 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2243 fputc (',', asm_out_file
);
2244 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2249 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2250 gcc_assert (size_of_uleb128 (r
)
2251 == size_of_uleb128 (val1
->v
.val_unsigned
));
2252 fputc (',', asm_out_file
);
2253 dw2_asm_output_data_uleb128_raw (r
);
2254 fputc (',', asm_out_file
);
2255 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2259 case DW_OP_GNU_implicit_pointer
:
2260 case DW_OP_GNU_entry_value
:
2261 case DW_OP_GNU_const_type
:
2262 case DW_OP_GNU_regval_type
:
2263 case DW_OP_GNU_deref_type
:
2264 case DW_OP_GNU_convert
:
2265 case DW_OP_GNU_reinterpret
:
2266 case DW_OP_GNU_parameter_ref
:
2271 /* Other codes have no operands. */
2277 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2281 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2282 /* Output the opcode. */
2283 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2285 unsigned r
= (opc
- DW_OP_breg0
);
2286 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2287 gcc_assert (r
<= 31);
2288 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2290 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2292 unsigned r
= (opc
- DW_OP_reg0
);
2293 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2294 gcc_assert (r
<= 31);
2295 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2297 /* Output the opcode. */
2298 fprintf (asm_out_file
, "%#x", opc
);
2299 output_loc_operands_raw (loc
);
2301 if (!loc
->dw_loc_next
)
2303 loc
= loc
->dw_loc_next
;
2305 fputc (',', asm_out_file
);
2309 /* This function builds a dwarf location descriptor sequence from a
2310 dw_cfa_location, adding the given OFFSET to the result of the
2313 struct dw_loc_descr_struct
*
2314 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2316 struct dw_loc_descr_struct
*head
, *tmp
;
2318 offset
+= cfa
->offset
;
2322 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2323 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2324 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2325 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2326 add_loc_descr (&head
, tmp
);
2329 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2330 add_loc_descr (&head
, tmp
);
2334 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2339 /* This function builds a dwarf location descriptor sequence for
2340 the address at OFFSET from the CFA when stack is aligned to
2343 struct dw_loc_descr_struct
*
2344 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2345 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2347 struct dw_loc_descr_struct
*head
;
2348 unsigned int dwarf_fp
2349 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2351 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2352 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2354 head
= new_reg_loc_descr (dwarf_fp
, 0);
2355 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2356 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2357 loc_descr_plus_const (&head
, offset
);
2360 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2364 /* And now, the support for symbolic debugging information. */
2366 /* .debug_str support. */
2367 static int output_indirect_string (void **, void *);
2369 static void dwarf2out_init (const char *);
2370 static void dwarf2out_finish (const char *);
2371 static void dwarf2out_assembly_start (void);
2372 static void dwarf2out_define (unsigned int, const char *);
2373 static void dwarf2out_undef (unsigned int, const char *);
2374 static void dwarf2out_start_source_file (unsigned, const char *);
2375 static void dwarf2out_end_source_file (unsigned);
2376 static void dwarf2out_function_decl (tree
);
2377 static void dwarf2out_begin_block (unsigned, unsigned);
2378 static void dwarf2out_end_block (unsigned, unsigned);
2379 static bool dwarf2out_ignore_block (const_tree
);
2380 static void dwarf2out_global_decl (tree
);
2381 static void dwarf2out_type_decl (tree
, int);
2382 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2383 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2385 static void dwarf2out_abstract_function (tree
);
2386 static void dwarf2out_var_location (rtx
);
2387 static void dwarf2out_begin_function (tree
);
2388 static void dwarf2out_end_function (unsigned int);
2389 static void dwarf2out_set_name (tree
, tree
);
2391 /* The debug hooks structure. */
2393 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2397 dwarf2out_assembly_start
,
2400 dwarf2out_start_source_file
,
2401 dwarf2out_end_source_file
,
2402 dwarf2out_begin_block
,
2403 dwarf2out_end_block
,
2404 dwarf2out_ignore_block
,
2405 dwarf2out_source_line
,
2406 dwarf2out_begin_prologue
,
2407 #if VMS_DEBUGGING_INFO
2408 dwarf2out_vms_end_prologue
,
2409 dwarf2out_vms_begin_epilogue
,
2411 debug_nothing_int_charstar
,
2412 debug_nothing_int_charstar
,
2414 dwarf2out_end_epilogue
,
2415 dwarf2out_begin_function
,
2416 dwarf2out_end_function
, /* end_function */
2417 dwarf2out_function_decl
, /* function_decl */
2418 dwarf2out_global_decl
,
2419 dwarf2out_type_decl
, /* type_decl */
2420 dwarf2out_imported_module_or_decl
,
2421 debug_nothing_tree
, /* deferred_inline_function */
2422 /* The DWARF 2 backend tries to reduce debugging bloat by not
2423 emitting the abstract description of inline functions until
2424 something tries to reference them. */
2425 dwarf2out_abstract_function
, /* outlining_inline_function */
2426 debug_nothing_rtx
, /* label */
2427 debug_nothing_int
, /* handle_pch */
2428 dwarf2out_var_location
,
2429 dwarf2out_switch_text_section
,
2431 1, /* start_end_main_source_file */
2432 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2435 /* NOTE: In the comments in this file, many references are made to
2436 "Debugging Information Entries". This term is abbreviated as `DIE'
2437 throughout the remainder of this file. */
2439 /* An internal representation of the DWARF output is built, and then
2440 walked to generate the DWARF debugging info. The walk of the internal
2441 representation is done after the entire program has been compiled.
2442 The types below are used to describe the internal representation. */
2444 /* Whether to put type DIEs into their own section .debug_types instead
2445 of making them part of the .debug_info section. Only supported for
2446 Dwarf V4 or higher and the user didn't disable them through
2447 -fno-debug-types-section. It is more efficient to put them in a
2448 separate comdat sections since the linker will then be able to
2449 remove duplicates. But not all tools support .debug_types sections
2452 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2454 /* Various DIE's use offsets relative to the beginning of the
2455 .debug_info section to refer to each other. */
2457 typedef long int dw_offset
;
2459 /* Define typedefs here to avoid circular dependencies. */
2461 typedef struct dw_attr_struct
*dw_attr_ref
;
2462 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2463 typedef struct pubname_struct
*pubname_ref
;
2464 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2465 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2466 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2468 /* The entries in the line_info table more-or-less mirror the opcodes
2469 that are used in the real dwarf line table. Arrays of these entries
2470 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2473 enum dw_line_info_opcode
{
2474 /* Emit DW_LNE_set_address; the operand is the label index. */
2477 /* Emit a row to the matrix with the given line. This may be done
2478 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2482 /* Emit a DW_LNS_set_file. */
2485 /* Emit a DW_LNS_set_column. */
2488 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2491 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2492 LI_set_prologue_end
,
2493 LI_set_epilogue_begin
,
2495 /* Emit a DW_LNE_set_discriminator. */
2496 LI_set_discriminator
2499 typedef struct GTY(()) dw_line_info_struct
{
2500 enum dw_line_info_opcode opcode
;
2502 } dw_line_info_entry
;
2505 typedef struct GTY(()) dw_line_info_table_struct
{
2506 /* The label that marks the end of this section. */
2507 const char *end_label
;
2509 /* The values for the last row of the matrix, as collected in the table.
2510 These are used to minimize the changes to the next row. */
2511 unsigned int file_num
;
2512 unsigned int line_num
;
2513 unsigned int column_num
;
2518 vec
<dw_line_info_entry
, va_gc
> *entries
;
2519 } dw_line_info_table
;
2521 typedef dw_line_info_table
*dw_line_info_table_p
;
2524 /* Each DIE attribute has a field specifying the attribute kind,
2525 a link to the next attribute in the chain, and an attribute value.
2526 Attributes are typically linked below the DIE they modify. */
2528 typedef struct GTY(()) dw_attr_struct
{
2529 enum dwarf_attribute dw_attr
;
2530 dw_val_node dw_attr_val
;
2535 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2536 The children of each node form a circular list linked by
2537 die_sib. die_child points to the node *before* the "first" child node. */
2539 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2540 union die_symbol_or_type_node
2542 const char * GTY ((tag ("0"))) die_symbol
;
2543 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2545 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2546 vec
<dw_attr_node
, va_gc
> *die_attr
;
2547 dw_die_ref die_parent
;
2548 dw_die_ref die_child
;
2550 dw_die_ref die_definition
; /* ref from a specification to its definition */
2551 dw_offset die_offset
;
2552 unsigned long die_abbrev
;
2554 unsigned int decl_id
;
2555 enum dwarf_tag die_tag
;
2556 /* Die is used and must not be pruned as unused. */
2557 BOOL_BITFIELD die_perennial_p
: 1;
2558 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2559 /* Lots of spare bits. */
2563 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2564 #define FOR_EACH_CHILD(die, c, expr) do { \
2565 c = die->die_child; \
2569 } while (c != die->die_child); \
2572 /* The pubname structure */
2574 typedef struct GTY(()) pubname_struct
{
2581 struct GTY(()) dw_ranges_struct
{
2582 /* If this is positive, it's a block number, otherwise it's a
2583 bitwise-negated index into dw_ranges_by_label. */
2587 /* A structure to hold a macinfo entry. */
2589 typedef struct GTY(()) macinfo_struct
{
2591 unsigned HOST_WIDE_INT lineno
;
2597 struct GTY(()) dw_ranges_by_label_struct
{
2602 /* The comdat type node structure. */
2603 typedef struct GTY(()) comdat_type_struct
2605 dw_die_ref root_die
;
2606 dw_die_ref type_die
;
2607 dw_die_ref skeleton_die
;
2608 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2609 struct comdat_type_struct
*next
;
2613 /* The limbo die list structure. */
2614 typedef struct GTY(()) limbo_die_struct
{
2617 struct limbo_die_struct
*next
;
2621 typedef struct skeleton_chain_struct
2625 struct skeleton_chain_struct
*parent
;
2627 skeleton_chain_node
;
2629 /* Define a macro which returns nonzero for a TYPE_DECL which was
2630 implicitly generated for a type.
2632 Note that, unlike the C front-end (which generates a NULL named
2633 TYPE_DECL node for each complete tagged type, each array type,
2634 and each function type node created) the C++ front-end generates
2635 a _named_ TYPE_DECL node for each tagged type node created.
2636 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2637 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2638 front-end, but for each type, tagged or not. */
2640 #define TYPE_DECL_IS_STUB(decl) \
2641 (DECL_NAME (decl) == NULL_TREE \
2642 || (DECL_ARTIFICIAL (decl) \
2643 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2644 /* This is necessary for stub decls that \
2645 appear in nested inline functions. */ \
2646 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2647 && (decl_ultimate_origin (decl) \
2648 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2650 /* Information concerning the compilation unit's programming
2651 language, and compiler version. */
2653 /* Fixed size portion of the DWARF compilation unit header. */
2654 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2655 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2657 /* Fixed size portion of the DWARF comdat type unit header. */
2658 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2659 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2660 + DWARF_OFFSET_SIZE)
2662 /* Fixed size portion of public names info. */
2663 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2665 /* Fixed size portion of the address range info. */
2666 #define DWARF_ARANGES_HEADER_SIZE \
2667 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2668 DWARF2_ADDR_SIZE * 2) \
2669 - DWARF_INITIAL_LENGTH_SIZE)
2671 /* Size of padding portion in the address range info. It must be
2672 aligned to twice the pointer size. */
2673 #define DWARF_ARANGES_PAD_SIZE \
2674 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2675 DWARF2_ADDR_SIZE * 2) \
2676 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2678 /* Use assembler line directives if available. */
2679 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2680 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2681 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2683 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2687 /* Minimum line offset in a special line info. opcode.
2688 This value was chosen to give a reasonable range of values. */
2689 #define DWARF_LINE_BASE -10
2691 /* First special line opcode - leave room for the standard opcodes. */
2692 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2694 /* Range of line offsets in a special line info. opcode. */
2695 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2697 /* Flag that indicates the initial value of the is_stmt_start flag.
2698 In the present implementation, we do not mark any lines as
2699 the beginning of a source statement, because that information
2700 is not made available by the GCC front-end. */
2701 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2703 /* Maximum number of operations per instruction bundle. */
2704 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2705 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2708 /* This location is used by calc_die_sizes() to keep track
2709 the offset of each DIE within the .debug_info section. */
2710 static unsigned long next_die_offset
;
2712 /* Record the root of the DIE's built for the current compilation unit. */
2713 static GTY(()) dw_die_ref single_comp_unit_die
;
2715 /* A list of type DIEs that have been separated into comdat sections. */
2716 static GTY(()) comdat_type_node
*comdat_type_list
;
2718 /* A list of DIEs with a NULL parent waiting to be relocated. */
2719 static GTY(()) limbo_die_node
*limbo_die_list
;
2721 /* A list of DIEs for which we may have to generate
2722 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2723 static GTY(()) limbo_die_node
*deferred_asm_name
;
2725 /* Filenames referenced by this compilation unit. */
2726 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2728 /* A hash table of references to DIE's that describe declarations.
2729 The key is a DECL_UID() which is a unique number identifying each decl. */
2730 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2732 /* A hash table of references to DIE's that describe COMMON blocks.
2733 The key is DECL_UID() ^ die_parent. */
2734 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2736 typedef struct GTY(()) die_arg_entry_struct
{
2742 /* Node of the variable location list. */
2743 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2744 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2745 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2746 in mode of the EXPR_LIST node and first EXPR_LIST operand
2747 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2748 location or NULL for padding. For larger bitsizes,
2749 mode is 0 and first operand is a CONCAT with bitsize
2750 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2751 NULL as second operand. */
2753 const char * GTY (()) label
;
2754 struct var_loc_node
* GTY (()) next
;
2757 /* Variable location list. */
2758 struct GTY (()) var_loc_list_def
{
2759 struct var_loc_node
* GTY (()) first
;
2761 /* Pointer to the last but one or last element of the
2762 chained list. If the list is empty, both first and
2763 last are NULL, if the list contains just one node
2764 or the last node certainly is not redundant, it points
2765 to the last node, otherwise points to the last but one.
2766 Do not mark it for GC because it is marked through the chain. */
2767 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2769 /* Pointer to the last element before section switch,
2770 if NULL, either sections weren't switched or first
2771 is after section switch. */
2772 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2774 /* DECL_UID of the variable decl. */
2775 unsigned int decl_id
;
2777 typedef struct var_loc_list_def var_loc_list
;
2779 /* Call argument location list. */
2780 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2781 rtx
GTY (()) call_arg_loc_note
;
2782 const char * GTY (()) label
;
2783 tree
GTY (()) block
;
2785 rtx
GTY (()) symbol_ref
;
2786 struct call_arg_loc_node
* GTY (()) next
;
2790 /* Table of decl location linked lists. */
2791 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2793 /* Head and tail of call_arg_loc chain. */
2794 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2795 static struct call_arg_loc_node
*call_arg_loc_last
;
2797 /* Number of call sites in the current function. */
2798 static int call_site_count
= -1;
2799 /* Number of tail call sites in the current function. */
2800 static int tail_call_site_count
= -1;
2802 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2804 static vec
<dw_die_ref
> block_map
;
2806 /* A cached location list. */
2807 struct GTY (()) cached_dw_loc_list_def
{
2808 /* The DECL_UID of the decl that this entry describes. */
2809 unsigned int decl_id
;
2811 /* The cached location list. */
2812 dw_loc_list_ref loc_list
;
2814 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2816 /* Table of cached location lists. */
2817 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2819 /* A pointer to the base of a list of references to DIE's that
2820 are uniquely identified by their tag, presence/absence of
2821 children DIE's, and list of attribute/value pairs. */
2822 static GTY((length ("abbrev_die_table_allocated")))
2823 dw_die_ref
*abbrev_die_table
;
2825 /* Number of elements currently allocated for abbrev_die_table. */
2826 static GTY(()) unsigned abbrev_die_table_allocated
;
2828 /* Number of elements in type_die_table currently in use. */
2829 static GTY(()) unsigned abbrev_die_table_in_use
;
2831 /* Size (in elements) of increments by which we may expand the
2832 abbrev_die_table. */
2833 #define ABBREV_DIE_TABLE_INCREMENT 256
2835 /* A global counter for generating labels for line number data. */
2836 static unsigned int line_info_label_num
;
2838 /* The current table to which we should emit line number information
2839 for the current function. This will be set up at the beginning of
2840 assembly for the function. */
2841 static dw_line_info_table
*cur_line_info_table
;
2843 /* The two default tables of line number info. */
2844 static GTY(()) dw_line_info_table
*text_section_line_info
;
2845 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2847 /* The set of all non-default tables of line number info. */
2848 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2850 /* A flag to tell pubnames/types export if there is an info section to
2852 static bool info_section_emitted
;
2854 /* A pointer to the base of a table that contains a list of publicly
2855 accessible names. */
2856 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2858 /* A pointer to the base of a table that contains a list of publicly
2859 accessible types. */
2860 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2862 /* A pointer to the base of a table that contains a list of macro
2863 defines/undefines (and file start/end markers). */
2864 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2866 /* True if .debug_macinfo or .debug_macros section is going to be
2868 #define have_macinfo \
2869 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2870 && !macinfo_table->is_empty ())
2872 /* Array of dies for which we should generate .debug_ranges info. */
2873 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2875 /* Number of elements currently allocated for ranges_table. */
2876 static GTY(()) unsigned ranges_table_allocated
;
2878 /* Number of elements in ranges_table currently in use. */
2879 static GTY(()) unsigned ranges_table_in_use
;
2881 /* Array of pairs of labels referenced in ranges_table. */
2882 static GTY ((length ("ranges_by_label_allocated")))
2883 dw_ranges_by_label_ref ranges_by_label
;
2885 /* Number of elements currently allocated for ranges_by_label. */
2886 static GTY(()) unsigned ranges_by_label_allocated
;
2888 /* Number of elements in ranges_by_label currently in use. */
2889 static GTY(()) unsigned ranges_by_label_in_use
;
2891 /* Size (in elements) of increments by which we may expand the
2893 #define RANGES_TABLE_INCREMENT 64
2895 /* Whether we have location lists that need outputting */
2896 static GTY(()) bool have_location_lists
;
2898 /* Unique label counter. */
2899 static GTY(()) unsigned int loclabel_num
;
2901 /* Unique label counter for point-of-call tables. */
2902 static GTY(()) unsigned int poc_label_num
;
2904 /* Record whether the function being analyzed contains inlined functions. */
2905 static int current_function_has_inlines
;
2907 /* The last file entry emitted by maybe_emit_file(). */
2908 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2910 /* Number of internal labels generated by gen_internal_sym(). */
2911 static GTY(()) int label_num
;
2913 /* Cached result of previous call to lookup_filename. */
2914 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2916 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2918 /* Instances of generic types for which we need to generate debug
2919 info that describe their generic parameters and arguments. That
2920 generation needs to happen once all types are properly laid out so
2921 we do it at the end of compilation. */
2922 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2924 /* Offset from the "steady-state frame pointer" to the frame base,
2925 within the current function. */
2926 static HOST_WIDE_INT frame_pointer_fb_offset
;
2927 static bool frame_pointer_fb_offset_valid
;
2929 static vec
<dw_die_ref
> base_types
;
2931 /* Forward declarations for functions defined in this file. */
2933 static int is_pseudo_reg (const_rtx
);
2934 static tree
type_main_variant (tree
);
2935 static int is_tagged_type (const_tree
);
2936 static const char *dwarf_tag_name (unsigned);
2937 static const char *dwarf_attr_name (unsigned);
2938 static const char *dwarf_form_name (unsigned);
2939 static tree
decl_ultimate_origin (const_tree
);
2940 static tree
decl_class_context (tree
);
2941 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2942 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2943 static inline unsigned int AT_index (dw_attr_ref
);
2944 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2945 static inline unsigned AT_flag (dw_attr_ref
);
2946 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2947 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2948 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2949 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2950 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2951 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2952 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2953 unsigned int, unsigned char *);
2954 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2955 static hashval_t
debug_str_do_hash (const void *);
2956 static int debug_str_eq (const void *, const void *);
2957 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2958 static inline const char *AT_string (dw_attr_ref
);
2959 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2960 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2961 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2962 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2963 static inline int AT_ref_external (dw_attr_ref
);
2964 static inline void set_AT_ref_external (dw_attr_ref
, int);
2965 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2966 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2967 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2968 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2970 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2971 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2972 static void remove_addr_table_entry (addr_table_entry
*);
2973 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2974 static inline rtx
AT_addr (dw_attr_ref
);
2975 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2976 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2977 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2978 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2979 unsigned HOST_WIDE_INT
);
2980 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2981 unsigned long, bool);
2982 static inline const char *AT_lbl (dw_attr_ref
);
2983 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2984 static const char *get_AT_low_pc (dw_die_ref
);
2985 static const char *get_AT_hi_pc (dw_die_ref
);
2986 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2987 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2988 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2989 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2990 static bool is_cxx (void);
2991 static bool is_fortran (void);
2992 static bool is_ada (void);
2993 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2994 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2995 static void add_child_die (dw_die_ref
, dw_die_ref
);
2996 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2997 static dw_die_ref
lookup_type_die (tree
);
2998 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2999 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3000 static void equate_type_number_to_die (tree
, dw_die_ref
);
3001 static hashval_t
decl_die_table_hash (const void *);
3002 static int decl_die_table_eq (const void *, const void *);
3003 static dw_die_ref
lookup_decl_die (tree
);
3004 static hashval_t
common_block_die_table_hash (const void *);
3005 static int common_block_die_table_eq (const void *, const void *);
3006 static hashval_t
decl_loc_table_hash (const void *);
3007 static int decl_loc_table_eq (const void *, const void *);
3008 static var_loc_list
*lookup_decl_loc (const_tree
);
3009 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3010 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3011 static void print_spaces (FILE *);
3012 static void print_die (dw_die_ref
, FILE *);
3013 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3014 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3015 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3016 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3017 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3018 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3019 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3020 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3021 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3022 struct md5_ctx
*, int *);
3023 struct checksum_attributes
;
3024 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3025 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3026 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3027 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3028 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3029 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3030 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3031 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3032 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3033 static void compute_section_prefix (dw_die_ref
);
3034 static int is_type_die (dw_die_ref
);
3035 static int is_comdat_die (dw_die_ref
);
3036 static int is_symbol_die (dw_die_ref
);
3037 static inline bool is_template_instantiation (dw_die_ref
);
3038 static void assign_symbol_names (dw_die_ref
);
3039 static void break_out_includes (dw_die_ref
);
3040 static int is_declaration_die (dw_die_ref
);
3041 static int should_move_die_to_comdat (dw_die_ref
);
3042 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3043 static dw_die_ref
clone_die (dw_die_ref
);
3044 static dw_die_ref
clone_tree (dw_die_ref
);
3045 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3046 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3047 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3048 static dw_die_ref
generate_skeleton (dw_die_ref
);
3049 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3052 static void break_out_comdat_types (dw_die_ref
);
3053 static void copy_decls_for_unworthy_types (dw_die_ref
);
3055 static void add_sibling_attributes (dw_die_ref
);
3056 static void output_location_lists (dw_die_ref
);
3057 static int constant_size (unsigned HOST_WIDE_INT
);
3058 static unsigned long size_of_die (dw_die_ref
);
3059 static void calc_die_sizes (dw_die_ref
);
3060 static void calc_base_type_die_sizes (void);
3061 static void mark_dies (dw_die_ref
);
3062 static void unmark_dies (dw_die_ref
);
3063 static void unmark_all_dies (dw_die_ref
);
3064 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3065 static unsigned long size_of_aranges (void);
3066 static enum dwarf_form
value_format (dw_attr_ref
);
3067 static void output_value_format (dw_attr_ref
);
3068 static void output_abbrev_section (void);
3069 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3070 static void output_die_symbol (dw_die_ref
);
3071 static void output_die (dw_die_ref
);
3072 static void output_compilation_unit_header (void);
3073 static void output_comp_unit (dw_die_ref
, int);
3074 static void output_comdat_type_unit (comdat_type_node
*);
3075 static const char *dwarf2_name (tree
, int);
3076 static void add_pubname (tree
, dw_die_ref
);
3077 static void add_enumerator_pubname (const char *, dw_die_ref
);
3078 static void add_pubname_string (const char *, dw_die_ref
);
3079 static void add_pubtype (tree
, dw_die_ref
);
3080 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3081 static void output_aranges (unsigned long);
3082 static unsigned int add_ranges_num (int);
3083 static unsigned int add_ranges (const_tree
);
3084 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3086 static void output_ranges (void);
3087 static dw_line_info_table
*new_line_info_table (void);
3088 static void output_line_info (bool);
3089 static void output_file_names (void);
3090 static dw_die_ref
base_type_die (tree
);
3091 static int is_base_type (tree
);
3092 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3093 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3094 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3095 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3096 static int type_is_enum (const_tree
);
3097 static unsigned int dbx_reg_number (const_rtx
);
3098 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3099 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3100 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3101 enum var_init_status
);
3102 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3103 enum var_init_status
);
3104 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3105 enum var_init_status
);
3106 static int is_based_loc (const_rtx
);
3107 static int resolve_one_addr (rtx
*, void *);
3108 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3109 enum var_init_status
);
3110 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3111 enum var_init_status
);
3112 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3113 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3114 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3115 static tree
field_type (const_tree
);
3116 static unsigned int simple_type_align_in_bits (const_tree
);
3117 static unsigned int simple_decl_align_in_bits (const_tree
);
3118 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3119 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3120 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3122 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3123 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3124 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3125 static void insert_double (double_int
, unsigned char *);
3126 static void insert_float (const_rtx
, unsigned char *);
3127 static rtx
rtl_for_decl_location (tree
);
3128 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3129 enum dwarf_attribute
);
3130 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3131 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3132 static void add_name_attribute (dw_die_ref
, const char *);
3133 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3134 static void add_comp_dir_attribute (dw_die_ref
);
3135 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3136 static void add_subscript_info (dw_die_ref
, tree
, bool);
3137 static void add_byte_size_attribute (dw_die_ref
, tree
);
3138 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3139 static void add_bit_size_attribute (dw_die_ref
, tree
);
3140 static void add_prototyped_attribute (dw_die_ref
, tree
);
3141 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3142 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3143 static void add_src_coords_attributes (dw_die_ref
, tree
);
3144 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3145 static void push_decl_scope (tree
);
3146 static void pop_decl_scope (void);
3147 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3148 static inline int local_scope_p (dw_die_ref
);
3149 static inline int class_scope_p (dw_die_ref
);
3150 static inline int class_or_namespace_scope_p (dw_die_ref
);
3151 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3152 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3153 static const char *type_tag (const_tree
);
3154 static tree
member_declared_type (const_tree
);
3156 static const char *decl_start_label (tree
);
3158 static void gen_array_type_die (tree
, dw_die_ref
);
3159 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3161 static void gen_entry_point_die (tree
, dw_die_ref
);
3163 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3164 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3165 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3166 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3167 static void gen_formal_types_die (tree
, dw_die_ref
);
3168 static void gen_subprogram_die (tree
, dw_die_ref
);
3169 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3170 static void gen_const_die (tree
, dw_die_ref
);
3171 static void gen_label_die (tree
, dw_die_ref
);
3172 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3173 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3174 static void gen_field_die (tree
, dw_die_ref
);
3175 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3176 static dw_die_ref
gen_compile_unit_die (const char *);
3177 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3178 static void gen_member_die (tree
, dw_die_ref
);
3179 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3180 enum debug_info_usage
);
3181 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3182 static void gen_typedef_die (tree
, dw_die_ref
);
3183 static void gen_type_die (tree
, dw_die_ref
);
3184 static void gen_block_die (tree
, dw_die_ref
, int);
3185 static void decls_for_scope (tree
, dw_die_ref
, int);
3186 static inline int is_redundant_typedef (const_tree
);
3187 static bool is_naming_typedef_decl (const_tree
);
3188 static inline dw_die_ref
get_context_die (tree
);
3189 static void gen_namespace_die (tree
, dw_die_ref
);
3190 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3191 static dw_die_ref
force_decl_die (tree
);
3192 static dw_die_ref
force_type_die (tree
);
3193 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3194 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3195 static struct dwarf_file_data
* lookup_filename (const char *);
3196 static void retry_incomplete_types (void);
3197 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3198 static void gen_generic_params_dies (tree
);
3199 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3200 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3201 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3202 static int file_info_cmp (const void *, const void *);
3203 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3204 const char *, const char *);
3205 static void output_loc_list (dw_loc_list_ref
);
3206 static char *gen_internal_sym (const char *);
3207 static bool want_pubnames (void);
3209 static void prune_unmark_dies (dw_die_ref
);
3210 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3211 static void prune_unused_types_mark (dw_die_ref
, int);
3212 static void prune_unused_types_walk (dw_die_ref
);
3213 static void prune_unused_types_walk_attribs (dw_die_ref
);
3214 static void prune_unused_types_prune (dw_die_ref
);
3215 static void prune_unused_types (void);
3216 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3217 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3218 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3219 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3220 const char *, const char *);
3221 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3222 static void gen_remaining_tmpl_value_param_die_attribute (void);
3223 static bool generic_type_p (tree
);
3224 static void schedule_generic_params_dies_gen (tree t
);
3225 static void gen_scheduled_generic_parms_dies (void);
3227 static const char *comp_dir_string (void);
3229 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3231 /* enum for tracking thread-local variables whose address is really an offset
3232 relative to the TLS pointer, which will need link-time relocation, but will
3233 not need relocation by the DWARF consumer. */
3241 /* Return the operator to use for an address of a variable. For dtprel_true, we
3242 use DW_OP_const*. For regular variables, which need both link-time
3243 relocation and consumer-level relocation (e.g., to account for shared objects
3244 loaded at a random address), we use DW_OP_addr*. */
3246 static inline enum dwarf_location_atom
3247 dw_addr_op (enum dtprel_bool dtprel
)
3249 if (dtprel
== dtprel_true
)
3250 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3251 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3253 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3256 /* Return a pointer to a newly allocated address location description. If
3257 dwarf_split_debug_info is true, then record the address with the appropriate
3259 static inline dw_loc_descr_ref
3260 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3262 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3264 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3265 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3266 ref
->dtprel
= dtprel
;
3267 if (dwarf_split_debug_info
)
3268 ref
->dw_loc_oprnd1
.val_entry
3269 = add_addr_table_entry (addr
,
3270 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3272 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3277 /* Section names used to hold DWARF debugging information. */
3279 #ifndef DEBUG_INFO_SECTION
3280 #define DEBUG_INFO_SECTION ".debug_info"
3282 #ifndef DEBUG_DWO_INFO_SECTION
3283 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3285 #ifndef DEBUG_ABBREV_SECTION
3286 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3288 #ifndef DEBUG_DWO_ABBREV_SECTION
3289 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3291 #ifndef DEBUG_ARANGES_SECTION
3292 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3294 #ifndef DEBUG_ADDR_SECTION
3295 #define DEBUG_ADDR_SECTION ".debug_addr"
3297 #ifndef DEBUG_NORM_MACINFO_SECTION
3298 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3300 #ifndef DEBUG_DWO_MACINFO_SECTION
3301 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3303 #ifndef DEBUG_MACINFO_SECTION
3304 #define DEBUG_MACINFO_SECTION \
3305 (!dwarf_split_debug_info \
3306 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3308 #ifndef DEBUG_NORM_MACRO_SECTION
3309 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3311 #ifndef DEBUG_DWO_MACRO_SECTION
3312 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3314 #ifndef DEBUG_MACRO_SECTION
3315 #define DEBUG_MACRO_SECTION \
3316 (!dwarf_split_debug_info \
3317 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3319 #ifndef DEBUG_LINE_SECTION
3320 #define DEBUG_LINE_SECTION ".debug_line"
3322 #ifndef DEBUG_DWO_LINE_SECTION
3323 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3325 #ifndef DEBUG_LOC_SECTION
3326 #define DEBUG_LOC_SECTION ".debug_loc"
3328 #ifndef DEBUG_DWO_LOC_SECTION
3329 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3331 #ifndef DEBUG_PUBNAMES_SECTION
3332 #define DEBUG_PUBNAMES_SECTION \
3333 ((debug_generate_pub_sections == 2) \
3334 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3336 #ifndef DEBUG_PUBTYPES_SECTION
3337 #define DEBUG_PUBTYPES_SECTION \
3338 ((debug_generate_pub_sections == 2) \
3339 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3341 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3342 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3343 #ifndef DEBUG_STR_OFFSETS_SECTION
3344 #define DEBUG_STR_OFFSETS_SECTION \
3345 (!dwarf_split_debug_info \
3346 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3348 #ifndef DEBUG_STR_DWO_SECTION
3349 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3351 #ifndef DEBUG_STR_SECTION
3352 #define DEBUG_STR_SECTION ".debug_str"
3354 #ifndef DEBUG_RANGES_SECTION
3355 #define DEBUG_RANGES_SECTION ".debug_ranges"
3358 /* Standard ELF section names for compiled code and data. */
3359 #ifndef TEXT_SECTION_NAME
3360 #define TEXT_SECTION_NAME ".text"
3363 /* Section flags for .debug_macinfo/.debug_macro section. */
3364 #define DEBUG_MACRO_SECTION_FLAGS \
3365 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3367 /* Section flags for .debug_str section. */
3368 #define DEBUG_STR_SECTION_FLAGS \
3369 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3370 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3373 /* Section flags for .debug_str.dwo section. */
3374 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3376 /* Labels we insert at beginning sections we can reference instead of
3377 the section names themselves. */
3379 #ifndef TEXT_SECTION_LABEL
3380 #define TEXT_SECTION_LABEL "Ltext"
3382 #ifndef COLD_TEXT_SECTION_LABEL
3383 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3385 #ifndef DEBUG_LINE_SECTION_LABEL
3386 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3388 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3389 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3391 #ifndef DEBUG_INFO_SECTION_LABEL
3392 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3394 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3395 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3397 #ifndef DEBUG_ABBREV_SECTION_LABEL
3398 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3400 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3401 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3403 #ifndef DEBUG_ADDR_SECTION_LABEL
3404 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3406 #ifndef DEBUG_LOC_SECTION_LABEL
3407 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3409 #ifndef DEBUG_RANGES_SECTION_LABEL
3410 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3412 #ifndef DEBUG_MACINFO_SECTION_LABEL
3413 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3415 #ifndef DEBUG_MACRO_SECTION_LABEL
3416 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3418 #define SKELETON_COMP_DIE_ABBREV 1
3419 #define SKELETON_TYPE_DIE_ABBREV 2
3421 /* Definitions of defaults for formats and names of various special
3422 (artificial) labels which may be generated within this file (when the -g
3423 options is used and DWARF2_DEBUGGING_INFO is in effect.
3424 If necessary, these may be overridden from within the tm.h file, but
3425 typically, overriding these defaults is unnecessary. */
3427 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3428 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3429 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3430 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3431 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3432 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3433 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3434 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3435 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3436 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3437 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3438 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3439 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3440 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3442 #ifndef TEXT_END_LABEL
3443 #define TEXT_END_LABEL "Letext"
3445 #ifndef COLD_END_LABEL
3446 #define COLD_END_LABEL "Letext_cold"
3448 #ifndef BLOCK_BEGIN_LABEL
3449 #define BLOCK_BEGIN_LABEL "LBB"
3451 #ifndef BLOCK_END_LABEL
3452 #define BLOCK_END_LABEL "LBE"
3454 #ifndef LINE_CODE_LABEL
3455 #define LINE_CODE_LABEL "LM"
3459 /* Return the root of the DIE's built for the current compilation unit. */
3461 comp_unit_die (void)
3463 if (!single_comp_unit_die
)
3464 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3465 return single_comp_unit_die
;
3468 /* We allow a language front-end to designate a function that is to be
3469 called to "demangle" any name before it is put into a DIE. */
3471 static const char *(*demangle_name_func
) (const char *);
3474 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3476 demangle_name_func
= func
;
3479 /* Test if rtl node points to a pseudo register. */
3482 is_pseudo_reg (const_rtx rtl
)
3484 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3485 || (GET_CODE (rtl
) == SUBREG
3486 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3489 /* Return a reference to a type, with its const and volatile qualifiers
3493 type_main_variant (tree type
)
3495 type
= TYPE_MAIN_VARIANT (type
);
3497 /* ??? There really should be only one main variant among any group of
3498 variants of a given type (and all of the MAIN_VARIANT values for all
3499 members of the group should point to that one type) but sometimes the C
3500 front-end messes this up for array types, so we work around that bug
3502 if (TREE_CODE (type
) == ARRAY_TYPE
)
3503 while (type
!= TYPE_MAIN_VARIANT (type
))
3504 type
= TYPE_MAIN_VARIANT (type
);
3509 /* Return nonzero if the given type node represents a tagged type. */
3512 is_tagged_type (const_tree type
)
3514 enum tree_code code
= TREE_CODE (type
);
3516 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3517 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3520 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3523 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3525 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3528 /* Return die_offset of a DIE reference to a base type. */
3530 static unsigned long int
3531 get_base_type_offset (dw_die_ref ref
)
3533 if (ref
->die_offset
)
3534 return ref
->die_offset
;
3535 if (comp_unit_die ()->die_abbrev
)
3537 calc_base_type_die_sizes ();
3538 gcc_assert (ref
->die_offset
);
3540 return ref
->die_offset
;
3543 /* Return die_offset of a DIE reference other than base type. */
3545 static unsigned long int
3546 get_ref_die_offset (dw_die_ref ref
)
3548 gcc_assert (ref
->die_offset
);
3549 return ref
->die_offset
;
3552 /* Convert a DIE tag into its string name. */
3555 dwarf_tag_name (unsigned int tag
)
3557 const char *name
= get_DW_TAG_name (tag
);
3562 return "DW_TAG_<unknown>";
3565 /* Convert a DWARF attribute code into its string name. */
3568 dwarf_attr_name (unsigned int attr
)
3574 #if VMS_DEBUGGING_INFO
3575 case DW_AT_HP_prologue
:
3576 return "DW_AT_HP_prologue";
3578 case DW_AT_MIPS_loop_unroll_factor
:
3579 return "DW_AT_MIPS_loop_unroll_factor";
3582 #if VMS_DEBUGGING_INFO
3583 case DW_AT_HP_epilogue
:
3584 return "DW_AT_HP_epilogue";
3586 case DW_AT_MIPS_stride
:
3587 return "DW_AT_MIPS_stride";
3591 name
= get_DW_AT_name (attr
);
3596 return "DW_AT_<unknown>";
3599 /* Convert a DWARF value form code into its string name. */
3602 dwarf_form_name (unsigned int form
)
3604 const char *name
= get_DW_FORM_name (form
);
3609 return "DW_FORM_<unknown>";
3612 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3613 instance of an inlined instance of a decl which is local to an inline
3614 function, so we have to trace all of the way back through the origin chain
3615 to find out what sort of node actually served as the original seed for the
3619 decl_ultimate_origin (const_tree decl
)
3621 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3624 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3625 nodes in the function to point to themselves; ignore that if
3626 we're trying to output the abstract instance of this function. */
3627 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3630 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3631 most distant ancestor, this should never happen. */
3632 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3634 return DECL_ABSTRACT_ORIGIN (decl
);
3637 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3638 of a virtual function may refer to a base class, so we check the 'this'
3642 decl_class_context (tree decl
)
3644 tree context
= NULL_TREE
;
3646 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3647 context
= DECL_CONTEXT (decl
);
3649 context
= TYPE_MAIN_VARIANT
3650 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3652 if (context
&& !TYPE_P (context
))
3653 context
= NULL_TREE
;
3658 /* Add an attribute/value pair to a DIE. */
3661 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3663 /* Maybe this should be an assert? */
3667 vec_safe_reserve (die
->die_attr
, 1);
3668 vec_safe_push (die
->die_attr
, *attr
);
3671 static inline enum dw_val_class
3672 AT_class (dw_attr_ref a
)
3674 return a
->dw_attr_val
.val_class
;
3677 /* Return the index for any attribute that will be referenced with a
3678 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3679 are stored in dw_attr_val.v.val_str for reference counting
3682 static inline unsigned int
3683 AT_index (dw_attr_ref a
)
3685 if (AT_class (a
) == dw_val_class_str
)
3686 return a
->dw_attr_val
.v
.val_str
->index
;
3687 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3688 return a
->dw_attr_val
.val_entry
->index
;
3692 /* Add a flag value attribute to a DIE. */
3695 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3699 attr
.dw_attr
= attr_kind
;
3700 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3701 attr
.dw_attr_val
.val_entry
= NULL
;
3702 attr
.dw_attr_val
.v
.val_flag
= flag
;
3703 add_dwarf_attr (die
, &attr
);
3706 static inline unsigned
3707 AT_flag (dw_attr_ref a
)
3709 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3710 return a
->dw_attr_val
.v
.val_flag
;
3713 /* Add a signed integer attribute value to a DIE. */
3716 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3720 attr
.dw_attr
= attr_kind
;
3721 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3722 attr
.dw_attr_val
.val_entry
= NULL
;
3723 attr
.dw_attr_val
.v
.val_int
= int_val
;
3724 add_dwarf_attr (die
, &attr
);
3727 static inline HOST_WIDE_INT
3728 AT_int (dw_attr_ref a
)
3730 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3731 return a
->dw_attr_val
.v
.val_int
;
3734 /* Add an unsigned integer attribute value to a DIE. */
3737 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3738 unsigned HOST_WIDE_INT unsigned_val
)
3742 attr
.dw_attr
= attr_kind
;
3743 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3744 attr
.dw_attr_val
.val_entry
= NULL
;
3745 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3746 add_dwarf_attr (die
, &attr
);
3749 static inline unsigned HOST_WIDE_INT
3750 AT_unsigned (dw_attr_ref a
)
3752 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3753 return a
->dw_attr_val
.v
.val_unsigned
;
3756 /* Add an unsigned double integer attribute value to a DIE. */
3759 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3760 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3764 attr
.dw_attr
= attr_kind
;
3765 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3766 attr
.dw_attr_val
.val_entry
= NULL
;
3767 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3768 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3769 add_dwarf_attr (die
, &attr
);
3772 /* Add a floating point attribute value to a DIE and return it. */
3775 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3776 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3780 attr
.dw_attr
= attr_kind
;
3781 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3782 attr
.dw_attr_val
.val_entry
= NULL
;
3783 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3784 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3785 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3786 add_dwarf_attr (die
, &attr
);
3789 /* Add an 8-byte data attribute value to a DIE. */
3792 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3793 unsigned char data8
[8])
3797 attr
.dw_attr
= attr_kind
;
3798 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3799 attr
.dw_attr_val
.val_entry
= NULL
;
3800 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3801 add_dwarf_attr (die
, &attr
);
3804 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3805 dwarf_split_debug_info, address attributes in dies destined for the
3806 final executable have force_direct set to avoid using indexed
3810 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3816 lbl_id
= xstrdup (lbl_low
);
3817 attr
.dw_attr
= DW_AT_low_pc
;
3818 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3819 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3820 if (dwarf_split_debug_info
&& !force_direct
)
3821 attr
.dw_attr_val
.val_entry
3822 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3824 attr
.dw_attr_val
.val_entry
= NULL
;
3825 add_dwarf_attr (die
, &attr
);
3827 attr
.dw_attr
= DW_AT_high_pc
;
3828 if (dwarf_version
< 4)
3829 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3831 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3832 lbl_id
= xstrdup (lbl_high
);
3833 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3834 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3835 && dwarf_split_debug_info
&& !force_direct
)
3836 attr
.dw_attr_val
.val_entry
3837 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3839 attr
.dw_attr_val
.val_entry
= NULL
;
3840 add_dwarf_attr (die
, &attr
);
3843 /* Hash and equality functions for debug_str_hash. */
3846 debug_str_do_hash (const void *x
)
3848 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3852 debug_str_eq (const void *x1
, const void *x2
)
3854 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3855 (const char *)x2
) == 0;
3858 /* Add STR to the given string hash table. */
3860 static struct indirect_string_node
*
3861 find_AT_string_in_table (const char *str
, htab_t table
)
3863 struct indirect_string_node
*node
;
3866 slot
= htab_find_slot_with_hash (table
, str
,
3867 htab_hash_string (str
), INSERT
);
3870 node
= ggc_alloc_cleared_indirect_string_node ();
3871 node
->str
= ggc_strdup (str
);
3875 node
= (struct indirect_string_node
*) *slot
;
3881 /* Add STR to the indirect string hash table. */
3883 static struct indirect_string_node
*
3884 find_AT_string (const char *str
)
3886 if (! debug_str_hash
)
3887 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3888 debug_str_eq
, NULL
);
3890 return find_AT_string_in_table (str
, debug_str_hash
);
3893 /* Add a string attribute value to a DIE. */
3896 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3899 struct indirect_string_node
*node
;
3901 node
= find_AT_string (str
);
3903 attr
.dw_attr
= attr_kind
;
3904 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3905 attr
.dw_attr_val
.val_entry
= NULL
;
3906 attr
.dw_attr_val
.v
.val_str
= node
;
3907 add_dwarf_attr (die
, &attr
);
3910 static inline const char *
3911 AT_string (dw_attr_ref a
)
3913 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3914 return a
->dw_attr_val
.v
.val_str
->str
;
3917 /* Call this function directly to bypass AT_string_form's logic to put
3918 the string inline in the die. */
3921 set_indirect_string (struct indirect_string_node
*node
)
3924 /* Already indirect is a no op. */
3925 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3927 gcc_assert (node
->label
);
3930 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3931 ++dw2_string_counter
;
3932 node
->label
= xstrdup (label
);
3934 if (!dwarf_split_debug_info
)
3936 node
->form
= DW_FORM_strp
;
3937 node
->index
= NOT_INDEXED
;
3941 node
->form
= DW_FORM_GNU_str_index
;
3942 node
->index
= NO_INDEX_ASSIGNED
;
3946 /* Find out whether a string should be output inline in DIE
3947 or out-of-line in .debug_str section. */
3949 static enum dwarf_form
3950 find_string_form (struct indirect_string_node
*node
)
3957 len
= strlen (node
->str
) + 1;
3959 /* If the string is shorter or equal to the size of the reference, it is
3960 always better to put it inline. */
3961 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3962 return node
->form
= DW_FORM_string
;
3964 /* If we cannot expect the linker to merge strings in .debug_str
3965 section, only put it into .debug_str if it is worth even in this
3967 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3968 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3969 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3970 return node
->form
= DW_FORM_string
;
3972 set_indirect_string (node
);
3977 /* Find out whether the string referenced from the attribute should be
3978 output inline in DIE or out-of-line in .debug_str section. */
3980 static enum dwarf_form
3981 AT_string_form (dw_attr_ref a
)
3983 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3984 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3987 /* Add a DIE reference attribute value to a DIE. */
3990 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3994 #ifdef ENABLE_CHECKING
3995 gcc_assert (targ_die
!= NULL
);
3997 /* With LTO we can end up trying to reference something we didn't create
3998 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3999 if (targ_die
== NULL
)
4003 attr
.dw_attr
= attr_kind
;
4004 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4005 attr
.dw_attr_val
.val_entry
= NULL
;
4006 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4007 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4008 add_dwarf_attr (die
, &attr
);
4011 /* Change DIE reference REF to point to NEW_DIE instead. */
4014 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4016 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4017 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4018 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4021 /* Add an AT_specification attribute to a DIE, and also make the back
4022 pointer from the specification to the definition. */
4025 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4027 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4028 gcc_assert (!targ_die
->die_definition
);
4029 targ_die
->die_definition
= die
;
4032 static inline dw_die_ref
4033 AT_ref (dw_attr_ref a
)
4035 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4036 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4040 AT_ref_external (dw_attr_ref a
)
4042 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4043 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4049 set_AT_ref_external (dw_attr_ref a
, int i
)
4051 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4052 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4055 /* Add an FDE reference attribute value to a DIE. */
4058 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4062 attr
.dw_attr
= attr_kind
;
4063 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4064 attr
.dw_attr_val
.val_entry
= NULL
;
4065 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4066 add_dwarf_attr (die
, &attr
);
4069 /* Add a location description attribute value to a DIE. */
4072 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4076 attr
.dw_attr
= attr_kind
;
4077 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4078 attr
.dw_attr_val
.val_entry
= NULL
;
4079 attr
.dw_attr_val
.v
.val_loc
= loc
;
4080 add_dwarf_attr (die
, &attr
);
4083 static inline dw_loc_descr_ref
4084 AT_loc (dw_attr_ref a
)
4086 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4087 return a
->dw_attr_val
.v
.val_loc
;
4091 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4095 attr
.dw_attr
= attr_kind
;
4096 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4097 attr
.dw_attr_val
.val_entry
= NULL
;
4098 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4099 add_dwarf_attr (die
, &attr
);
4100 have_location_lists
= true;
4103 static inline dw_loc_list_ref
4104 AT_loc_list (dw_attr_ref a
)
4106 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4107 return a
->dw_attr_val
.v
.val_loc_list
;
4110 static inline dw_loc_list_ref
*
4111 AT_loc_list_ptr (dw_attr_ref a
)
4113 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4114 return &a
->dw_attr_val
.v
.val_loc_list
;
4117 /* Table of entries into the .debug_addr section. */
4119 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4121 /* Hash an address_table_entry. */
4124 addr_table_entry_do_hash (const void *x
)
4126 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4130 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4131 case ate_kind_rtx_dtprel
:
4132 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4133 case ate_kind_label
:
4134 return htab_hash_string (a
->addr
.label
);
4140 /* Determine equality for two address_table_entries. */
4143 addr_table_entry_eq (const void *x1
, const void *x2
)
4145 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4146 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4148 if (a1
->kind
!= a2
->kind
)
4153 case ate_kind_rtx_dtprel
:
4154 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4155 case ate_kind_label
:
4156 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4162 /* Initialize an addr_table_entry. */
4165 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4171 case ate_kind_rtx_dtprel
:
4172 e
->addr
.rtl
= (rtx
) addr
;
4174 case ate_kind_label
:
4175 e
->addr
.label
= (char *) addr
;
4179 e
->index
= NO_INDEX_ASSIGNED
;
4182 /* Add attr to the address table entry to the table. Defer setting an
4183 index until output time. */
4185 static addr_table_entry
*
4186 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4188 addr_table_entry
*node
;
4189 addr_table_entry finder
;
4192 gcc_assert (dwarf_split_debug_info
);
4193 if (! addr_index_table
)
4194 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4195 addr_table_entry_eq
, NULL
);
4196 init_addr_table_entry (&finder
, kind
, addr
);
4197 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4199 if (*slot
== HTAB_EMPTY_ENTRY
)
4201 node
= ggc_alloc_cleared_addr_table_entry ();
4202 init_addr_table_entry (node
, kind
, addr
);
4206 node
= (addr_table_entry
*) *slot
;
4212 /* Remove an entry from the addr table by decrementing its refcount.
4213 Strictly, decrementing the refcount would be enough, but the
4214 assertion that the entry is actually in the table has found
4218 remove_addr_table_entry (addr_table_entry
*entry
)
4220 addr_table_entry
*node
;
4222 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4223 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4224 /* After an index is assigned, the table is frozen. */
4225 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4229 /* Given a location list, remove all addresses it refers to from the
4233 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4235 for (; descr
; descr
= descr
->dw_loc_next
)
4236 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4238 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4239 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4243 /* A helper function for dwarf2out_finish called through
4244 htab_traverse. Assign an addr_table_entry its index. All entries
4245 must be collected into the table when this function is called,
4246 because the indexing code relies on htab_traverse to traverse nodes
4247 in the same order for each run. */
4250 index_addr_table_entry (void **h
, void *v
)
4252 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4253 unsigned int *index
= (unsigned int *) v
;
4255 /* Don't index unreferenced nodes. */
4256 if (node
->refcount
== 0)
4259 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4260 node
->index
= *index
;
4266 /* Add an address constant attribute value to a DIE. When using
4267 dwarf_split_debug_info, address attributes in dies destined for the
4268 final executable should be direct references--setting the parameter
4269 force_direct ensures this behavior. */
4272 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4277 attr
.dw_attr
= attr_kind
;
4278 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4279 attr
.dw_attr_val
.v
.val_addr
= addr
;
4280 if (dwarf_split_debug_info
&& !force_direct
)
4281 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4283 attr
.dw_attr_val
.val_entry
= NULL
;
4284 add_dwarf_attr (die
, &attr
);
4287 /* Get the RTX from to an address DIE attribute. */
4290 AT_addr (dw_attr_ref a
)
4292 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4293 return a
->dw_attr_val
.v
.val_addr
;
4296 /* Add a file attribute value to a DIE. */
4299 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4300 struct dwarf_file_data
*fd
)
4304 attr
.dw_attr
= attr_kind
;
4305 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4306 attr
.dw_attr_val
.val_entry
= NULL
;
4307 attr
.dw_attr_val
.v
.val_file
= fd
;
4308 add_dwarf_attr (die
, &attr
);
4311 /* Get the dwarf_file_data from a file DIE attribute. */
4313 static inline struct dwarf_file_data
*
4314 AT_file (dw_attr_ref a
)
4316 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4317 return a
->dw_attr_val
.v
.val_file
;
4320 /* Add a vms delta attribute value to a DIE. */
4323 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4324 const char *lbl1
, const char *lbl2
)
4328 attr
.dw_attr
= attr_kind
;
4329 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4330 attr
.dw_attr_val
.val_entry
= NULL
;
4331 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4332 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4333 add_dwarf_attr (die
, &attr
);
4336 /* Add a label identifier attribute value to a DIE. */
4339 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4344 attr
.dw_attr
= attr_kind
;
4345 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4346 attr
.dw_attr_val
.val_entry
= NULL
;
4347 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4348 if (dwarf_split_debug_info
)
4349 attr
.dw_attr_val
.val_entry
4350 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4352 add_dwarf_attr (die
, &attr
);
4355 /* Add a section offset attribute value to a DIE, an offset into the
4356 debug_line section. */
4359 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4364 attr
.dw_attr
= attr_kind
;
4365 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4366 attr
.dw_attr_val
.val_entry
= NULL
;
4367 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4368 add_dwarf_attr (die
, &attr
);
4371 /* Add a section offset attribute value to a DIE, an offset into the
4372 debug_macinfo section. */
4375 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4380 attr
.dw_attr
= attr_kind
;
4381 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4382 attr
.dw_attr_val
.val_entry
= NULL
;
4383 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4384 add_dwarf_attr (die
, &attr
);
4387 /* Add an offset attribute value to a DIE. */
4390 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4391 unsigned HOST_WIDE_INT offset
)
4395 attr
.dw_attr
= attr_kind
;
4396 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4397 attr
.dw_attr_val
.val_entry
= NULL
;
4398 attr
.dw_attr_val
.v
.val_offset
= offset
;
4399 add_dwarf_attr (die
, &attr
);
4402 /* Add a range_list attribute value to a DIE. When using
4403 dwarf_split_debug_info, address attributes in dies destined for the
4404 final executable should be direct references--setting the parameter
4405 force_direct ensures this behavior. */
4407 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4408 #define RELOCATED_OFFSET (NULL)
4411 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4412 long unsigned int offset
, bool force_direct
)
4416 attr
.dw_attr
= attr_kind
;
4417 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4418 /* For the range_list attribute, use val_entry to store whether the
4419 offset should follow split-debug-info or normal semantics. This
4420 value is read in output_range_list_offset. */
4421 if (dwarf_split_debug_info
&& !force_direct
)
4422 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4424 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4425 attr
.dw_attr_val
.v
.val_offset
= offset
;
4426 add_dwarf_attr (die
, &attr
);
4429 /* Return the start label of a delta attribute. */
4431 static inline const char *
4432 AT_vms_delta1 (dw_attr_ref a
)
4434 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4435 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4438 /* Return the end label of a delta attribute. */
4440 static inline const char *
4441 AT_vms_delta2 (dw_attr_ref a
)
4443 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4444 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4447 static inline const char *
4448 AT_lbl (dw_attr_ref a
)
4450 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4451 || AT_class (a
) == dw_val_class_lineptr
4452 || AT_class (a
) == dw_val_class_macptr
4453 || AT_class (a
) == dw_val_class_high_pc
));
4454 return a
->dw_attr_val
.v
.val_lbl_id
;
4457 /* Get the attribute of type attr_kind. */
4460 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4464 dw_die_ref spec
= NULL
;
4469 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4470 if (a
->dw_attr
== attr_kind
)
4472 else if (a
->dw_attr
== DW_AT_specification
4473 || a
->dw_attr
== DW_AT_abstract_origin
)
4477 return get_AT (spec
, attr_kind
);
4482 /* Returns the parent of the declaration of DIE. */
4485 get_die_parent (dw_die_ref die
)
4492 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4493 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4496 return die
->die_parent
;
4499 /* Return the "low pc" attribute value, typically associated with a subprogram
4500 DIE. Return null if the "low pc" attribute is either not present, or if it
4501 cannot be represented as an assembler label identifier. */
4503 static inline const char *
4504 get_AT_low_pc (dw_die_ref die
)
4506 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4508 return a
? AT_lbl (a
) : NULL
;
4511 /* Return the "high pc" attribute value, typically associated with a subprogram
4512 DIE. Return null if the "high pc" attribute is either not present, or if it
4513 cannot be represented as an assembler label identifier. */
4515 static inline const char *
4516 get_AT_hi_pc (dw_die_ref die
)
4518 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4520 return a
? AT_lbl (a
) : NULL
;
4523 /* Return the value of the string attribute designated by ATTR_KIND, or
4524 NULL if it is not present. */
4526 static inline const char *
4527 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4529 dw_attr_ref a
= get_AT (die
, attr_kind
);
4531 return a
? AT_string (a
) : NULL
;
4534 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4535 if it is not present. */
4538 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4540 dw_attr_ref a
= get_AT (die
, attr_kind
);
4542 return a
? AT_flag (a
) : 0;
4545 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4546 if it is not present. */
4548 static inline unsigned
4549 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4551 dw_attr_ref a
= get_AT (die
, attr_kind
);
4553 return a
? AT_unsigned (a
) : 0;
4556 static inline dw_die_ref
4557 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4559 dw_attr_ref a
= get_AT (die
, attr_kind
);
4561 return a
? AT_ref (a
) : NULL
;
4564 static inline struct dwarf_file_data
*
4565 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4567 dw_attr_ref a
= get_AT (die
, attr_kind
);
4569 return a
? AT_file (a
) : NULL
;
4572 /* Return TRUE if the language is C++. */
4577 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4579 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4582 /* Return TRUE if the language is Java. */
4587 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4589 return lang
== DW_LANG_Java
;
4592 /* Return TRUE if the language is Fortran. */
4597 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4599 return (lang
== DW_LANG_Fortran77
4600 || lang
== DW_LANG_Fortran90
4601 || lang
== DW_LANG_Fortran95
);
4604 /* Return TRUE if the language is Ada. */
4609 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4611 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4614 /* Remove the specified attribute if present. */
4617 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4625 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4626 if (a
->dw_attr
== attr_kind
)
4628 if (AT_class (a
) == dw_val_class_str
)
4629 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4630 a
->dw_attr_val
.v
.val_str
->refcount
--;
4632 /* vec::ordered_remove should help reduce the number of abbrevs
4634 die
->die_attr
->ordered_remove (ix
);
4639 /* Remove CHILD from its parent. PREV must have the property that
4640 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4643 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4645 gcc_assert (child
->die_parent
== prev
->die_parent
);
4646 gcc_assert (prev
->die_sib
== child
);
4649 gcc_assert (child
->die_parent
->die_child
== child
);
4653 prev
->die_sib
= child
->die_sib
;
4654 if (child
->die_parent
->die_child
== child
)
4655 child
->die_parent
->die_child
= prev
;
4658 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4659 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4662 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4664 dw_die_ref parent
= old_child
->die_parent
;
4666 gcc_assert (parent
== prev
->die_parent
);
4667 gcc_assert (prev
->die_sib
== old_child
);
4669 new_child
->die_parent
= parent
;
4670 if (prev
== old_child
)
4672 gcc_assert (parent
->die_child
== old_child
);
4673 new_child
->die_sib
= new_child
;
4677 prev
->die_sib
= new_child
;
4678 new_child
->die_sib
= old_child
->die_sib
;
4680 if (old_child
->die_parent
->die_child
== old_child
)
4681 old_child
->die_parent
->die_child
= new_child
;
4684 /* Move all children from OLD_PARENT to NEW_PARENT. */
4687 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4690 new_parent
->die_child
= old_parent
->die_child
;
4691 old_parent
->die_child
= NULL
;
4692 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4695 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4699 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4705 dw_die_ref prev
= c
;
4707 while (c
->die_tag
== tag
)
4709 remove_child_with_prev (c
, prev
);
4710 /* Might have removed every child. */
4711 if (c
== c
->die_sib
)
4715 } while (c
!= die
->die_child
);
4718 /* Add a CHILD_DIE as the last child of DIE. */
4721 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4723 /* FIXME this should probably be an assert. */
4724 if (! die
|| ! child_die
)
4726 gcc_assert (die
!= child_die
);
4728 child_die
->die_parent
= die
;
4731 child_die
->die_sib
= die
->die_child
->die_sib
;
4732 die
->die_child
->die_sib
= child_die
;
4735 child_die
->die_sib
= child_die
;
4736 die
->die_child
= child_die
;
4739 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4740 is the specification, to the end of PARENT's list of children.
4741 This is done by removing and re-adding it. */
4744 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4748 /* We want the declaration DIE from inside the class, not the
4749 specification DIE at toplevel. */
4750 if (child
->die_parent
!= parent
)
4752 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4758 gcc_assert (child
->die_parent
== parent
4759 || (child
->die_parent
4760 == get_AT_ref (parent
, DW_AT_specification
)));
4762 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4763 if (p
->die_sib
== child
)
4765 remove_child_with_prev (child
, p
);
4769 add_child_die (parent
, child
);
4772 /* Return a pointer to a newly created DIE node. */
4774 static inline dw_die_ref
4775 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4777 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4779 die
->die_tag
= tag_value
;
4781 if (parent_die
!= NULL
)
4782 add_child_die (parent_die
, die
);
4785 limbo_die_node
*limbo_node
;
4787 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4788 limbo_node
->die
= die
;
4789 limbo_node
->created_for
= t
;
4790 limbo_node
->next
= limbo_die_list
;
4791 limbo_die_list
= limbo_node
;
4797 /* Return the DIE associated with the given type specifier. */
4799 static inline dw_die_ref
4800 lookup_type_die (tree type
)
4802 return TYPE_SYMTAB_DIE (type
);
4805 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4806 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4807 anonymous type instead the one of the naming typedef. */
4809 static inline dw_die_ref
4810 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4813 && TREE_CODE (type
) == RECORD_TYPE
4815 && type_die
->die_tag
== DW_TAG_typedef
4816 && is_naming_typedef_decl (TYPE_NAME (type
)))
4817 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4821 /* Like lookup_type_die, but if type is an anonymous type named by a
4822 typedef[1], return the DIE of the anonymous type instead the one of
4823 the naming typedef. This is because in gen_typedef_die, we did
4824 equate the anonymous struct named by the typedef with the DIE of
4825 the naming typedef. So by default, lookup_type_die on an anonymous
4826 struct yields the DIE of the naming typedef.
4828 [1]: Read the comment of is_naming_typedef_decl to learn about what
4829 a naming typedef is. */
4831 static inline dw_die_ref
4832 lookup_type_die_strip_naming_typedef (tree type
)
4834 dw_die_ref die
= lookup_type_die (type
);
4835 return strip_naming_typedef (type
, die
);
4838 /* Equate a DIE to a given type specifier. */
4841 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4843 TYPE_SYMTAB_DIE (type
) = type_die
;
4846 /* Returns a hash value for X (which really is a die_struct). */
4849 decl_die_table_hash (const void *x
)
4851 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4854 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4857 decl_die_table_eq (const void *x
, const void *y
)
4859 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4862 /* Return the DIE associated with a given declaration. */
4864 static inline dw_die_ref
4865 lookup_decl_die (tree decl
)
4867 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4870 /* Returns a hash value for X (which really is a var_loc_list). */
4873 decl_loc_table_hash (const void *x
)
4875 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4878 /* Return nonzero if decl_id of var_loc_list X is the same as
4882 decl_loc_table_eq (const void *x
, const void *y
)
4884 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4887 /* Return the var_loc list associated with a given declaration. */
4889 static inline var_loc_list
*
4890 lookup_decl_loc (const_tree decl
)
4892 if (!decl_loc_table
)
4894 return (var_loc_list
*)
4895 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4898 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4901 cached_dw_loc_list_table_hash (const void *x
)
4903 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4906 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4910 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4912 return (((const cached_dw_loc_list
*) x
)->decl_id
4913 == DECL_UID ((const_tree
) y
));
4916 /* Equate a DIE to a particular declaration. */
4919 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4921 unsigned int decl_id
= DECL_UID (decl
);
4924 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4926 decl_die
->decl_id
= decl_id
;
4929 /* Return how many bits covers PIECE EXPR_LIST. */
4932 decl_piece_bitsize (rtx piece
)
4934 int ret
= (int) GET_MODE (piece
);
4937 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4938 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4939 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4942 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4945 decl_piece_varloc_ptr (rtx piece
)
4947 if ((int) GET_MODE (piece
))
4948 return &XEXP (piece
, 0);
4950 return &XEXP (XEXP (piece
, 0), 1);
4953 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4954 Next is the chain of following piece nodes. */
4957 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4959 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4960 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4962 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4967 /* Return rtx that should be stored into loc field for
4968 LOC_NOTE and BITPOS/BITSIZE. */
4971 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4972 HOST_WIDE_INT bitsize
)
4976 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4978 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4983 /* This function either modifies location piece list *DEST in
4984 place (if SRC and INNER is NULL), or copies location piece list
4985 *SRC to *DEST while modifying it. Location BITPOS is modified
4986 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4987 not copied and if needed some padding around it is added.
4988 When modifying in place, DEST should point to EXPR_LIST where
4989 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4990 to the start of the whole list and INNER points to the EXPR_LIST
4991 where earlier pieces cover PIECE_BITPOS bits. */
4994 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4995 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4996 HOST_WIDE_INT bitsize
, rtx loc_note
)
4999 bool copy
= inner
!= NULL
;
5003 /* First copy all nodes preceding the current bitpos. */
5004 while (src
!= inner
)
5006 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5007 decl_piece_bitsize (*src
), NULL_RTX
);
5008 dest
= &XEXP (*dest
, 1);
5009 src
= &XEXP (*src
, 1);
5012 /* Add padding if needed. */
5013 if (bitpos
!= piece_bitpos
)
5015 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5016 copy
? NULL_RTX
: *dest
);
5017 dest
= &XEXP (*dest
, 1);
5019 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5022 /* A piece with correct bitpos and bitsize already exist,
5023 just update the location for it and return. */
5024 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5027 /* Add the piece that changed. */
5028 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5029 dest
= &XEXP (*dest
, 1);
5030 /* Skip over pieces that overlap it. */
5031 diff
= bitpos
- piece_bitpos
+ bitsize
;
5034 while (diff
> 0 && *src
)
5037 diff
-= decl_piece_bitsize (piece
);
5039 src
= &XEXP (piece
, 1);
5042 *src
= XEXP (piece
, 1);
5043 free_EXPR_LIST_node (piece
);
5046 /* Add padding if needed. */
5047 if (diff
< 0 && *src
)
5051 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5052 dest
= &XEXP (*dest
, 1);
5056 /* Finally copy all nodes following it. */
5059 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5060 decl_piece_bitsize (*src
), NULL_RTX
);
5061 dest
= &XEXP (*dest
, 1);
5062 src
= &XEXP (*src
, 1);
5066 /* Add a variable location node to the linked list for DECL. */
5068 static struct var_loc_node
*
5069 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5071 unsigned int decl_id
;
5074 struct var_loc_node
*loc
= NULL
;
5075 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5077 if (TREE_CODE (decl
) == VAR_DECL
5078 && DECL_HAS_DEBUG_EXPR_P (decl
))
5080 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5081 if (handled_component_p (realdecl
)
5082 || (TREE_CODE (realdecl
) == MEM_REF
5083 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5085 HOST_WIDE_INT maxsize
;
5088 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5089 if (!DECL_P (innerdecl
)
5090 || DECL_IGNORED_P (innerdecl
)
5091 || TREE_STATIC (innerdecl
)
5093 || bitpos
+ bitsize
> 256
5094 || bitsize
!= maxsize
)
5100 decl_id
= DECL_UID (decl
);
5101 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5104 temp
= ggc_alloc_cleared_var_loc_list ();
5105 temp
->decl_id
= decl_id
;
5109 temp
= (var_loc_list
*) *slot
;
5111 /* For PARM_DECLs try to keep around the original incoming value,
5112 even if that means we'll emit a zero-range .debug_loc entry. */
5114 && temp
->first
== temp
->last
5115 && TREE_CODE (decl
) == PARM_DECL
5116 && NOTE_P (temp
->first
->loc
)
5117 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5118 && DECL_INCOMING_RTL (decl
)
5119 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5120 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5121 == GET_CODE (DECL_INCOMING_RTL (decl
))
5122 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5124 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5125 NOTE_VAR_LOCATION_LOC (loc_note
))
5126 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5127 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5129 loc
= ggc_alloc_cleared_var_loc_node ();
5130 temp
->first
->next
= loc
;
5132 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5134 else if (temp
->last
)
5136 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5137 rtx
*piece_loc
= NULL
, last_loc_note
;
5138 int piece_bitpos
= 0;
5142 gcc_assert (last
->next
== NULL
);
5144 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5146 piece_loc
= &last
->loc
;
5149 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5150 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5152 piece_bitpos
+= cur_bitsize
;
5153 piece_loc
= &XEXP (*piece_loc
, 1);
5157 /* TEMP->LAST here is either pointer to the last but one or
5158 last element in the chained list, LAST is pointer to the
5160 if (label
&& strcmp (last
->label
, label
) == 0)
5162 /* For SRA optimized variables if there weren't any real
5163 insns since last note, just modify the last node. */
5164 if (piece_loc
!= NULL
)
5166 adjust_piece_list (piece_loc
, NULL
, NULL
,
5167 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5170 /* If the last note doesn't cover any instructions, remove it. */
5171 if (temp
->last
!= last
)
5173 temp
->last
->next
= NULL
;
5176 gcc_assert (strcmp (last
->label
, label
) != 0);
5180 gcc_assert (temp
->first
== temp
->last
5181 || (temp
->first
->next
== temp
->last
5182 && TREE_CODE (decl
) == PARM_DECL
));
5183 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5184 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5188 if (bitsize
== -1 && NOTE_P (last
->loc
))
5189 last_loc_note
= last
->loc
;
5190 else if (piece_loc
!= NULL
5191 && *piece_loc
!= NULL_RTX
5192 && piece_bitpos
== bitpos
5193 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5194 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5196 last_loc_note
= NULL_RTX
;
5197 /* If the current location is the same as the end of the list,
5198 and either both or neither of the locations is uninitialized,
5199 we have nothing to do. */
5200 if (last_loc_note
== NULL_RTX
5201 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5202 NOTE_VAR_LOCATION_LOC (loc_note
)))
5203 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5204 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5205 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5206 == VAR_INIT_STATUS_UNINITIALIZED
)
5207 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5208 == VAR_INIT_STATUS_UNINITIALIZED
))))
5210 /* Add LOC to the end of list and update LAST. If the last
5211 element of the list has been removed above, reuse its
5212 memory for the new node, otherwise allocate a new one. */
5216 memset (loc
, '\0', sizeof (*loc
));
5219 loc
= ggc_alloc_cleared_var_loc_node ();
5220 if (bitsize
== -1 || piece_loc
== NULL
)
5221 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5223 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5224 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5226 /* Ensure TEMP->LAST will point either to the new last but one
5227 element of the chain, or to the last element in it. */
5228 if (last
!= temp
->last
)
5236 loc
= ggc_alloc_cleared_var_loc_node ();
5239 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5244 /* Keep track of the number of spaces used to indent the
5245 output of the debugging routines that print the structure of
5246 the DIE internal representation. */
5247 static int print_indent
;
5249 /* Indent the line the number of spaces given by print_indent. */
5252 print_spaces (FILE *outfile
)
5254 fprintf (outfile
, "%*s", print_indent
, "");
5257 /* Print a type signature in hex. */
5260 print_signature (FILE *outfile
, char *sig
)
5264 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5265 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5268 /* Print the information associated with a given DIE, and its children.
5269 This routine is a debugging aid only. */
5272 print_die (dw_die_ref die
, FILE *outfile
)
5278 print_spaces (outfile
);
5279 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5280 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5282 print_spaces (outfile
);
5283 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5284 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5285 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5287 if (die
->comdat_type_p
)
5289 print_spaces (outfile
);
5290 fprintf (outfile
, " signature: ");
5291 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5292 fprintf (outfile
, "\n");
5295 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5297 print_spaces (outfile
);
5298 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5300 switch (AT_class (a
))
5302 case dw_val_class_addr
:
5303 fprintf (outfile
, "address");
5305 case dw_val_class_offset
:
5306 fprintf (outfile
, "offset");
5308 case dw_val_class_loc
:
5309 fprintf (outfile
, "location descriptor");
5311 case dw_val_class_loc_list
:
5312 fprintf (outfile
, "location list -> label:%s",
5313 AT_loc_list (a
)->ll_symbol
);
5315 case dw_val_class_range_list
:
5316 fprintf (outfile
, "range list");
5318 case dw_val_class_const
:
5319 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5321 case dw_val_class_unsigned_const
:
5322 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5324 case dw_val_class_const_double
:
5325 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5326 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5327 a
->dw_attr_val
.v
.val_double
.high
,
5328 a
->dw_attr_val
.v
.val_double
.low
);
5330 case dw_val_class_vec
:
5331 fprintf (outfile
, "floating-point or vector constant");
5333 case dw_val_class_flag
:
5334 fprintf (outfile
, "%u", AT_flag (a
));
5336 case dw_val_class_die_ref
:
5337 if (AT_ref (a
) != NULL
)
5339 if (AT_ref (a
)->comdat_type_p
)
5341 fprintf (outfile
, "die -> signature: ");
5342 print_signature (outfile
,
5343 AT_ref (a
)->die_id
.die_type_node
->signature
);
5345 else if (AT_ref (a
)->die_id
.die_symbol
)
5346 fprintf (outfile
, "die -> label: %s",
5347 AT_ref (a
)->die_id
.die_symbol
);
5349 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5350 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5353 fprintf (outfile
, "die -> <null>");
5355 case dw_val_class_vms_delta
:
5356 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5357 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5359 case dw_val_class_lbl_id
:
5360 case dw_val_class_lineptr
:
5361 case dw_val_class_macptr
:
5362 case dw_val_class_high_pc
:
5363 fprintf (outfile
, "label: %s", AT_lbl (a
));
5365 case dw_val_class_str
:
5366 if (AT_string (a
) != NULL
)
5367 fprintf (outfile
, "\"%s\"", AT_string (a
));
5369 fprintf (outfile
, "<null>");
5371 case dw_val_class_file
:
5372 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5373 AT_file (a
)->emitted_number
);
5375 case dw_val_class_data8
:
5379 for (i
= 0; i
< 8; i
++)
5380 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5387 fprintf (outfile
, "\n");
5390 if (die
->die_child
!= NULL
)
5393 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5396 if (print_indent
== 0)
5397 fprintf (outfile
, "\n");
5400 /* Print the information collected for a given DIE. */
5403 debug_dwarf_die (dw_die_ref die
)
5405 print_die (die
, stderr
);
5409 debug (die_struct
&ref
)
5411 print_die (&ref
, stderr
);
5415 debug (die_struct
*ptr
)
5420 fprintf (stderr
, "<nil>\n");
5424 /* Print all DWARF information collected for the compilation unit.
5425 This routine is a debugging aid only. */
5431 print_die (comp_unit_die (), stderr
);
5434 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5435 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5436 DIE that marks the start of the DIEs for this include file. */
5439 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5441 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5442 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5444 new_unit
->die_sib
= old_unit
;
5448 /* Close an include-file CU and reopen the enclosing one. */
5451 pop_compile_unit (dw_die_ref old_unit
)
5453 dw_die_ref new_unit
= old_unit
->die_sib
;
5455 old_unit
->die_sib
= NULL
;
5459 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5460 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5461 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5463 /* Calculate the checksum of a location expression. */
5466 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5471 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5473 hash
= hash_loc_operands (loc
, hash
);
5477 /* Calculate the checksum of an attribute. */
5480 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5482 dw_loc_descr_ref loc
;
5485 CHECKSUM (at
->dw_attr
);
5487 /* We don't care that this was compiled with a different compiler
5488 snapshot; if the output is the same, that's what matters. */
5489 if (at
->dw_attr
== DW_AT_producer
)
5492 switch (AT_class (at
))
5494 case dw_val_class_const
:
5495 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5497 case dw_val_class_unsigned_const
:
5498 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5500 case dw_val_class_const_double
:
5501 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5503 case dw_val_class_vec
:
5504 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5505 (at
->dw_attr_val
.v
.val_vec
.length
5506 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5508 case dw_val_class_flag
:
5509 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5511 case dw_val_class_str
:
5512 CHECKSUM_STRING (AT_string (at
));
5515 case dw_val_class_addr
:
5517 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5518 CHECKSUM_STRING (XSTR (r
, 0));
5521 case dw_val_class_offset
:
5522 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5525 case dw_val_class_loc
:
5526 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5527 loc_checksum (loc
, ctx
);
5530 case dw_val_class_die_ref
:
5531 die_checksum (AT_ref (at
), ctx
, mark
);
5534 case dw_val_class_fde_ref
:
5535 case dw_val_class_vms_delta
:
5536 case dw_val_class_lbl_id
:
5537 case dw_val_class_lineptr
:
5538 case dw_val_class_macptr
:
5539 case dw_val_class_high_pc
:
5542 case dw_val_class_file
:
5543 CHECKSUM_STRING (AT_file (at
)->filename
);
5546 case dw_val_class_data8
:
5547 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5555 /* Calculate the checksum of a DIE. */
5558 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5564 /* To avoid infinite recursion. */
5567 CHECKSUM (die
->die_mark
);
5570 die
->die_mark
= ++(*mark
);
5572 CHECKSUM (die
->die_tag
);
5574 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5575 attr_checksum (a
, ctx
, mark
);
5577 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5581 #undef CHECKSUM_BLOCK
5582 #undef CHECKSUM_STRING
5584 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5585 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5586 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5587 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5588 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5589 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5590 #define CHECKSUM_ATTR(FOO) \
5591 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5593 /* Calculate the checksum of a number in signed LEB128 format. */
5596 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5603 byte
= (value
& 0x7f);
5605 more
= !((value
== 0 && (byte
& 0x40) == 0)
5606 || (value
== -1 && (byte
& 0x40) != 0));
5615 /* Calculate the checksum of a number in unsigned LEB128 format. */
5618 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5622 unsigned char byte
= (value
& 0x7f);
5625 /* More bytes to follow. */
5633 /* Checksum the context of the DIE. This adds the names of any
5634 surrounding namespaces or structures to the checksum. */
5637 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5641 int tag
= die
->die_tag
;
5643 if (tag
!= DW_TAG_namespace
5644 && tag
!= DW_TAG_structure_type
5645 && tag
!= DW_TAG_class_type
)
5648 name
= get_AT_string (die
, DW_AT_name
);
5650 spec
= get_AT_ref (die
, DW_AT_specification
);
5654 if (die
->die_parent
!= NULL
)
5655 checksum_die_context (die
->die_parent
, ctx
);
5657 CHECKSUM_ULEB128 ('C');
5658 CHECKSUM_ULEB128 (tag
);
5660 CHECKSUM_STRING (name
);
5663 /* Calculate the checksum of a location expression. */
5666 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5668 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5669 were emitted as a DW_FORM_sdata instead of a location expression. */
5670 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5672 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5673 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5677 /* Otherwise, just checksum the raw location expression. */
5682 CHECKSUM_ULEB128 (loc
->dtprel
);
5683 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5684 hash
= hash_loc_operands (loc
, hash
);
5686 loc
= loc
->dw_loc_next
;
5690 /* Calculate the checksum of an attribute. */
5693 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5694 struct md5_ctx
*ctx
, int *mark
)
5696 dw_loc_descr_ref loc
;
5699 if (AT_class (at
) == dw_val_class_die_ref
)
5701 dw_die_ref target_die
= AT_ref (at
);
5703 /* For pointer and reference types, we checksum only the (qualified)
5704 name of the target type (if there is a name). For friend entries,
5705 we checksum only the (qualified) name of the target type or function.
5706 This allows the checksum to remain the same whether the target type
5707 is complete or not. */
5708 if ((at
->dw_attr
== DW_AT_type
5709 && (tag
== DW_TAG_pointer_type
5710 || tag
== DW_TAG_reference_type
5711 || tag
== DW_TAG_rvalue_reference_type
5712 || tag
== DW_TAG_ptr_to_member_type
))
5713 || (at
->dw_attr
== DW_AT_friend
5714 && tag
== DW_TAG_friend
))
5716 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5718 if (name_attr
!= NULL
)
5720 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5724 CHECKSUM_ULEB128 ('N');
5725 CHECKSUM_ULEB128 (at
->dw_attr
);
5726 if (decl
->die_parent
!= NULL
)
5727 checksum_die_context (decl
->die_parent
, ctx
);
5728 CHECKSUM_ULEB128 ('E');
5729 CHECKSUM_STRING (AT_string (name_attr
));
5734 /* For all other references to another DIE, we check to see if the
5735 target DIE has already been visited. If it has, we emit a
5736 backward reference; if not, we descend recursively. */
5737 if (target_die
->die_mark
> 0)
5739 CHECKSUM_ULEB128 ('R');
5740 CHECKSUM_ULEB128 (at
->dw_attr
);
5741 CHECKSUM_ULEB128 (target_die
->die_mark
);
5745 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5749 target_die
->die_mark
= ++(*mark
);
5750 CHECKSUM_ULEB128 ('T');
5751 CHECKSUM_ULEB128 (at
->dw_attr
);
5752 if (decl
->die_parent
!= NULL
)
5753 checksum_die_context (decl
->die_parent
, ctx
);
5754 die_checksum_ordered (target_die
, ctx
, mark
);
5759 CHECKSUM_ULEB128 ('A');
5760 CHECKSUM_ULEB128 (at
->dw_attr
);
5762 switch (AT_class (at
))
5764 case dw_val_class_const
:
5765 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5766 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5769 case dw_val_class_unsigned_const
:
5770 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5771 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5774 case dw_val_class_const_double
:
5775 CHECKSUM_ULEB128 (DW_FORM_block
);
5776 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5777 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5780 case dw_val_class_vec
:
5781 CHECKSUM_ULEB128 (DW_FORM_block
);
5782 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5783 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5784 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5785 (at
->dw_attr_val
.v
.val_vec
.length
5786 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5789 case dw_val_class_flag
:
5790 CHECKSUM_ULEB128 (DW_FORM_flag
);
5791 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5794 case dw_val_class_str
:
5795 CHECKSUM_ULEB128 (DW_FORM_string
);
5796 CHECKSUM_STRING (AT_string (at
));
5799 case dw_val_class_addr
:
5801 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5802 CHECKSUM_ULEB128 (DW_FORM_string
);
5803 CHECKSUM_STRING (XSTR (r
, 0));
5806 case dw_val_class_offset
:
5807 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5808 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5811 case dw_val_class_loc
:
5812 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5813 loc_checksum_ordered (loc
, ctx
);
5816 case dw_val_class_fde_ref
:
5817 case dw_val_class_lbl_id
:
5818 case dw_val_class_lineptr
:
5819 case dw_val_class_macptr
:
5820 case dw_val_class_high_pc
:
5823 case dw_val_class_file
:
5824 CHECKSUM_ULEB128 (DW_FORM_string
);
5825 CHECKSUM_STRING (AT_file (at
)->filename
);
5828 case dw_val_class_data8
:
5829 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5837 struct checksum_attributes
5839 dw_attr_ref at_name
;
5840 dw_attr_ref at_type
;
5841 dw_attr_ref at_friend
;
5842 dw_attr_ref at_accessibility
;
5843 dw_attr_ref at_address_class
;
5844 dw_attr_ref at_allocated
;
5845 dw_attr_ref at_artificial
;
5846 dw_attr_ref at_associated
;
5847 dw_attr_ref at_binary_scale
;
5848 dw_attr_ref at_bit_offset
;
5849 dw_attr_ref at_bit_size
;
5850 dw_attr_ref at_bit_stride
;
5851 dw_attr_ref at_byte_size
;
5852 dw_attr_ref at_byte_stride
;
5853 dw_attr_ref at_const_value
;
5854 dw_attr_ref at_containing_type
;
5855 dw_attr_ref at_count
;
5856 dw_attr_ref at_data_location
;
5857 dw_attr_ref at_data_member_location
;
5858 dw_attr_ref at_decimal_scale
;
5859 dw_attr_ref at_decimal_sign
;
5860 dw_attr_ref at_default_value
;
5861 dw_attr_ref at_digit_count
;
5862 dw_attr_ref at_discr
;
5863 dw_attr_ref at_discr_list
;
5864 dw_attr_ref at_discr_value
;
5865 dw_attr_ref at_encoding
;
5866 dw_attr_ref at_endianity
;
5867 dw_attr_ref at_explicit
;
5868 dw_attr_ref at_is_optional
;
5869 dw_attr_ref at_location
;
5870 dw_attr_ref at_lower_bound
;
5871 dw_attr_ref at_mutable
;
5872 dw_attr_ref at_ordering
;
5873 dw_attr_ref at_picture_string
;
5874 dw_attr_ref at_prototyped
;
5875 dw_attr_ref at_small
;
5876 dw_attr_ref at_segment
;
5877 dw_attr_ref at_string_length
;
5878 dw_attr_ref at_threads_scaled
;
5879 dw_attr_ref at_upper_bound
;
5880 dw_attr_ref at_use_location
;
5881 dw_attr_ref at_use_UTF8
;
5882 dw_attr_ref at_variable_parameter
;
5883 dw_attr_ref at_virtuality
;
5884 dw_attr_ref at_visibility
;
5885 dw_attr_ref at_vtable_elem_location
;
5888 /* Collect the attributes that we will want to use for the checksum. */
5891 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5896 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5907 attrs
->at_friend
= a
;
5909 case DW_AT_accessibility
:
5910 attrs
->at_accessibility
= a
;
5912 case DW_AT_address_class
:
5913 attrs
->at_address_class
= a
;
5915 case DW_AT_allocated
:
5916 attrs
->at_allocated
= a
;
5918 case DW_AT_artificial
:
5919 attrs
->at_artificial
= a
;
5921 case DW_AT_associated
:
5922 attrs
->at_associated
= a
;
5924 case DW_AT_binary_scale
:
5925 attrs
->at_binary_scale
= a
;
5927 case DW_AT_bit_offset
:
5928 attrs
->at_bit_offset
= a
;
5930 case DW_AT_bit_size
:
5931 attrs
->at_bit_size
= a
;
5933 case DW_AT_bit_stride
:
5934 attrs
->at_bit_stride
= a
;
5936 case DW_AT_byte_size
:
5937 attrs
->at_byte_size
= a
;
5939 case DW_AT_byte_stride
:
5940 attrs
->at_byte_stride
= a
;
5942 case DW_AT_const_value
:
5943 attrs
->at_const_value
= a
;
5945 case DW_AT_containing_type
:
5946 attrs
->at_containing_type
= a
;
5949 attrs
->at_count
= a
;
5951 case DW_AT_data_location
:
5952 attrs
->at_data_location
= a
;
5954 case DW_AT_data_member_location
:
5955 attrs
->at_data_member_location
= a
;
5957 case DW_AT_decimal_scale
:
5958 attrs
->at_decimal_scale
= a
;
5960 case DW_AT_decimal_sign
:
5961 attrs
->at_decimal_sign
= a
;
5963 case DW_AT_default_value
:
5964 attrs
->at_default_value
= a
;
5966 case DW_AT_digit_count
:
5967 attrs
->at_digit_count
= a
;
5970 attrs
->at_discr
= a
;
5972 case DW_AT_discr_list
:
5973 attrs
->at_discr_list
= a
;
5975 case DW_AT_discr_value
:
5976 attrs
->at_discr_value
= a
;
5978 case DW_AT_encoding
:
5979 attrs
->at_encoding
= a
;
5981 case DW_AT_endianity
:
5982 attrs
->at_endianity
= a
;
5984 case DW_AT_explicit
:
5985 attrs
->at_explicit
= a
;
5987 case DW_AT_is_optional
:
5988 attrs
->at_is_optional
= a
;
5990 case DW_AT_location
:
5991 attrs
->at_location
= a
;
5993 case DW_AT_lower_bound
:
5994 attrs
->at_lower_bound
= a
;
5997 attrs
->at_mutable
= a
;
5999 case DW_AT_ordering
:
6000 attrs
->at_ordering
= a
;
6002 case DW_AT_picture_string
:
6003 attrs
->at_picture_string
= a
;
6005 case DW_AT_prototyped
:
6006 attrs
->at_prototyped
= a
;
6009 attrs
->at_small
= a
;
6012 attrs
->at_segment
= a
;
6014 case DW_AT_string_length
:
6015 attrs
->at_string_length
= a
;
6017 case DW_AT_threads_scaled
:
6018 attrs
->at_threads_scaled
= a
;
6020 case DW_AT_upper_bound
:
6021 attrs
->at_upper_bound
= a
;
6023 case DW_AT_use_location
:
6024 attrs
->at_use_location
= a
;
6026 case DW_AT_use_UTF8
:
6027 attrs
->at_use_UTF8
= a
;
6029 case DW_AT_variable_parameter
:
6030 attrs
->at_variable_parameter
= a
;
6032 case DW_AT_virtuality
:
6033 attrs
->at_virtuality
= a
;
6035 case DW_AT_visibility
:
6036 attrs
->at_visibility
= a
;
6038 case DW_AT_vtable_elem_location
:
6039 attrs
->at_vtable_elem_location
= a
;
6047 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6050 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6054 struct checksum_attributes attrs
;
6056 CHECKSUM_ULEB128 ('D');
6057 CHECKSUM_ULEB128 (die
->die_tag
);
6059 memset (&attrs
, 0, sizeof (attrs
));
6061 decl
= get_AT_ref (die
, DW_AT_specification
);
6063 collect_checksum_attributes (&attrs
, decl
);
6064 collect_checksum_attributes (&attrs
, die
);
6066 CHECKSUM_ATTR (attrs
.at_name
);
6067 CHECKSUM_ATTR (attrs
.at_accessibility
);
6068 CHECKSUM_ATTR (attrs
.at_address_class
);
6069 CHECKSUM_ATTR (attrs
.at_allocated
);
6070 CHECKSUM_ATTR (attrs
.at_artificial
);
6071 CHECKSUM_ATTR (attrs
.at_associated
);
6072 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6073 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6074 CHECKSUM_ATTR (attrs
.at_bit_size
);
6075 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6076 CHECKSUM_ATTR (attrs
.at_byte_size
);
6077 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6078 CHECKSUM_ATTR (attrs
.at_const_value
);
6079 CHECKSUM_ATTR (attrs
.at_containing_type
);
6080 CHECKSUM_ATTR (attrs
.at_count
);
6081 CHECKSUM_ATTR (attrs
.at_data_location
);
6082 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6083 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6084 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6085 CHECKSUM_ATTR (attrs
.at_default_value
);
6086 CHECKSUM_ATTR (attrs
.at_digit_count
);
6087 CHECKSUM_ATTR (attrs
.at_discr
);
6088 CHECKSUM_ATTR (attrs
.at_discr_list
);
6089 CHECKSUM_ATTR (attrs
.at_discr_value
);
6090 CHECKSUM_ATTR (attrs
.at_encoding
);
6091 CHECKSUM_ATTR (attrs
.at_endianity
);
6092 CHECKSUM_ATTR (attrs
.at_explicit
);
6093 CHECKSUM_ATTR (attrs
.at_is_optional
);
6094 CHECKSUM_ATTR (attrs
.at_location
);
6095 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6096 CHECKSUM_ATTR (attrs
.at_mutable
);
6097 CHECKSUM_ATTR (attrs
.at_ordering
);
6098 CHECKSUM_ATTR (attrs
.at_picture_string
);
6099 CHECKSUM_ATTR (attrs
.at_prototyped
);
6100 CHECKSUM_ATTR (attrs
.at_small
);
6101 CHECKSUM_ATTR (attrs
.at_segment
);
6102 CHECKSUM_ATTR (attrs
.at_string_length
);
6103 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6104 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6105 CHECKSUM_ATTR (attrs
.at_use_location
);
6106 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6107 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6108 CHECKSUM_ATTR (attrs
.at_virtuality
);
6109 CHECKSUM_ATTR (attrs
.at_visibility
);
6110 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6111 CHECKSUM_ATTR (attrs
.at_type
);
6112 CHECKSUM_ATTR (attrs
.at_friend
);
6114 /* Checksum the child DIEs. */
6117 dw_attr_ref name_attr
;
6120 name_attr
= get_AT (c
, DW_AT_name
);
6121 if (is_template_instantiation (c
))
6123 /* Ignore instantiations of member type and function templates. */
6125 else if (name_attr
!= NULL
6126 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6128 /* Use a shallow checksum for named nested types and member
6130 CHECKSUM_ULEB128 ('S');
6131 CHECKSUM_ULEB128 (c
->die_tag
);
6132 CHECKSUM_STRING (AT_string (name_attr
));
6136 /* Use a deep checksum for other children. */
6137 /* Mark this DIE so it gets processed when unmarking. */
6138 if (c
->die_mark
== 0)
6140 die_checksum_ordered (c
, ctx
, mark
);
6142 } while (c
!= die
->die_child
);
6144 CHECKSUM_ULEB128 (0);
6147 /* Add a type name and tag to a hash. */
6149 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6151 CHECKSUM_ULEB128 (tag
);
6152 CHECKSUM_STRING (name
);
6156 #undef CHECKSUM_STRING
6157 #undef CHECKSUM_ATTR
6158 #undef CHECKSUM_LEB128
6159 #undef CHECKSUM_ULEB128
6161 /* Generate the type signature for DIE. This is computed by generating an
6162 MD5 checksum over the DIE's tag, its relevant attributes, and its
6163 children. Attributes that are references to other DIEs are processed
6164 by recursion, using the MARK field to prevent infinite recursion.
6165 If the DIE is nested inside a namespace or another type, we also
6166 need to include that context in the signature. The lower 64 bits
6167 of the resulting MD5 checksum comprise the signature. */
6170 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6174 unsigned char checksum
[16];
6179 name
= get_AT_string (die
, DW_AT_name
);
6180 decl
= get_AT_ref (die
, DW_AT_specification
);
6181 parent
= get_die_parent (die
);
6183 /* First, compute a signature for just the type name (and its surrounding
6184 context, if any. This is stored in the type unit DIE for link-time
6185 ODR (one-definition rule) checking. */
6187 if (is_cxx () && name
!= NULL
)
6189 md5_init_ctx (&ctx
);
6191 /* Checksum the names of surrounding namespaces and structures. */
6193 checksum_die_context (parent
, &ctx
);
6195 /* Checksum the current DIE. */
6196 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6197 md5_finish_ctx (&ctx
, checksum
);
6199 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6202 /* Next, compute the complete type signature. */
6204 md5_init_ctx (&ctx
);
6206 die
->die_mark
= mark
;
6208 /* Checksum the names of surrounding namespaces and structures. */
6210 checksum_die_context (parent
, &ctx
);
6212 /* Checksum the DIE and its children. */
6213 die_checksum_ordered (die
, &ctx
, &mark
);
6214 unmark_all_dies (die
);
6215 md5_finish_ctx (&ctx
, checksum
);
6217 /* Store the signature in the type node and link the type DIE and the
6218 type node together. */
6219 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6220 DWARF_TYPE_SIGNATURE_SIZE
);
6221 die
->comdat_type_p
= true;
6222 die
->die_id
.die_type_node
= type_node
;
6223 type_node
->type_die
= die
;
6225 /* If the DIE is a specification, link its declaration to the type node
6229 decl
->comdat_type_p
= true;
6230 decl
->die_id
.die_type_node
= type_node
;
6234 /* Do the location expressions look same? */
6236 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6238 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6239 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6240 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6243 /* Do the values look the same? */
6245 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6247 dw_loc_descr_ref loc1
, loc2
;
6250 if (v1
->val_class
!= v2
->val_class
)
6253 switch (v1
->val_class
)
6255 case dw_val_class_const
:
6256 return v1
->v
.val_int
== v2
->v
.val_int
;
6257 case dw_val_class_unsigned_const
:
6258 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6259 case dw_val_class_const_double
:
6260 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6261 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6262 case dw_val_class_vec
:
6263 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6264 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6266 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6267 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6270 case dw_val_class_flag
:
6271 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6272 case dw_val_class_str
:
6273 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6275 case dw_val_class_addr
:
6276 r1
= v1
->v
.val_addr
;
6277 r2
= v2
->v
.val_addr
;
6278 if (GET_CODE (r1
) != GET_CODE (r2
))
6280 return !rtx_equal_p (r1
, r2
);
6282 case dw_val_class_offset
:
6283 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6285 case dw_val_class_loc
:
6286 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6288 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6289 if (!same_loc_p (loc1
, loc2
, mark
))
6291 return !loc1
&& !loc2
;
6293 case dw_val_class_die_ref
:
6294 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6296 case dw_val_class_fde_ref
:
6297 case dw_val_class_vms_delta
:
6298 case dw_val_class_lbl_id
:
6299 case dw_val_class_lineptr
:
6300 case dw_val_class_macptr
:
6301 case dw_val_class_high_pc
:
6304 case dw_val_class_file
:
6305 return v1
->v
.val_file
== v2
->v
.val_file
;
6307 case dw_val_class_data8
:
6308 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6315 /* Do the attributes look the same? */
6318 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6320 if (at1
->dw_attr
!= at2
->dw_attr
)
6323 /* We don't care that this was compiled with a different compiler
6324 snapshot; if the output is the same, that's what matters. */
6325 if (at1
->dw_attr
== DW_AT_producer
)
6328 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6331 /* Do the dies look the same? */
6334 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6340 /* To avoid infinite recursion. */
6342 return die1
->die_mark
== die2
->die_mark
;
6343 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6345 if (die1
->die_tag
!= die2
->die_tag
)
6348 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6351 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6352 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6355 c1
= die1
->die_child
;
6356 c2
= die2
->die_child
;
6365 if (!same_die_p (c1
, c2
, mark
))
6369 if (c1
== die1
->die_child
)
6371 if (c2
== die2
->die_child
)
6381 /* Do the dies look the same? Wrapper around same_die_p. */
6384 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6387 int ret
= same_die_p (die1
, die2
, &mark
);
6389 unmark_all_dies (die1
);
6390 unmark_all_dies (die2
);
6395 /* The prefix to attach to symbols on DIEs in the current comdat debug
6397 static const char *comdat_symbol_id
;
6399 /* The index of the current symbol within the current comdat CU. */
6400 static unsigned int comdat_symbol_number
;
6402 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6403 children, and set comdat_symbol_id accordingly. */
6406 compute_section_prefix (dw_die_ref unit_die
)
6408 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6409 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6410 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6413 unsigned char checksum
[16];
6416 /* Compute the checksum of the DIE, then append part of it as hex digits to
6417 the name filename of the unit. */
6419 md5_init_ctx (&ctx
);
6421 die_checksum (unit_die
, &ctx
, &mark
);
6422 unmark_all_dies (unit_die
);
6423 md5_finish_ctx (&ctx
, checksum
);
6425 sprintf (name
, "%s.", base
);
6426 clean_symbol_name (name
);
6428 p
= name
+ strlen (name
);
6429 for (i
= 0; i
< 4; i
++)
6431 sprintf (p
, "%.2x", checksum
[i
]);
6435 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6436 comdat_symbol_number
= 0;
6439 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6442 is_type_die (dw_die_ref die
)
6444 switch (die
->die_tag
)
6446 case DW_TAG_array_type
:
6447 case DW_TAG_class_type
:
6448 case DW_TAG_interface_type
:
6449 case DW_TAG_enumeration_type
:
6450 case DW_TAG_pointer_type
:
6451 case DW_TAG_reference_type
:
6452 case DW_TAG_rvalue_reference_type
:
6453 case DW_TAG_string_type
:
6454 case DW_TAG_structure_type
:
6455 case DW_TAG_subroutine_type
:
6456 case DW_TAG_union_type
:
6457 case DW_TAG_ptr_to_member_type
:
6458 case DW_TAG_set_type
:
6459 case DW_TAG_subrange_type
:
6460 case DW_TAG_base_type
:
6461 case DW_TAG_const_type
:
6462 case DW_TAG_file_type
:
6463 case DW_TAG_packed_type
:
6464 case DW_TAG_volatile_type
:
6465 case DW_TAG_typedef
:
6472 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6473 Basically, we want to choose the bits that are likely to be shared between
6474 compilations (types) and leave out the bits that are specific to individual
6475 compilations (functions). */
6478 is_comdat_die (dw_die_ref c
)
6480 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6481 we do for stabs. The advantage is a greater likelihood of sharing between
6482 objects that don't include headers in the same order (and therefore would
6483 put the base types in a different comdat). jason 8/28/00 */
6485 if (c
->die_tag
== DW_TAG_base_type
)
6488 if (c
->die_tag
== DW_TAG_pointer_type
6489 || c
->die_tag
== DW_TAG_reference_type
6490 || c
->die_tag
== DW_TAG_rvalue_reference_type
6491 || c
->die_tag
== DW_TAG_const_type
6492 || c
->die_tag
== DW_TAG_volatile_type
)
6494 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6496 return t
? is_comdat_die (t
) : 0;
6499 return is_type_die (c
);
6502 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6503 compilation unit. */
6506 is_symbol_die (dw_die_ref c
)
6508 return (is_type_die (c
)
6509 || is_declaration_die (c
)
6510 || c
->die_tag
== DW_TAG_namespace
6511 || c
->die_tag
== DW_TAG_module
);
6514 /* Returns true iff C is a compile-unit DIE. */
6517 is_cu_die (dw_die_ref c
)
6519 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6522 /* Returns true iff C is a unit DIE of some sort. */
6525 is_unit_die (dw_die_ref c
)
6527 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6528 || c
->die_tag
== DW_TAG_partial_unit
6529 || c
->die_tag
== DW_TAG_type_unit
);
6532 /* Returns true iff C is a namespace DIE. */
6535 is_namespace_die (dw_die_ref c
)
6537 return c
&& c
->die_tag
== DW_TAG_namespace
;
6540 /* Returns true iff C is a class or structure DIE. */
6543 is_class_die (dw_die_ref c
)
6545 return c
&& (c
->die_tag
== DW_TAG_class_type
6546 || c
->die_tag
== DW_TAG_structure_type
);
6549 /* Return non-zero if this DIE is a template parameter. */
6552 is_template_parameter (dw_die_ref die
)
6554 switch (die
->die_tag
)
6556 case DW_TAG_template_type_param
:
6557 case DW_TAG_template_value_param
:
6558 case DW_TAG_GNU_template_template_param
:
6559 case DW_TAG_GNU_template_parameter_pack
:
6566 /* Return non-zero if this DIE represents a template instantiation. */
6569 is_template_instantiation (dw_die_ref die
)
6573 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6575 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6580 gen_internal_sym (const char *prefix
)
6584 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6585 return xstrdup (buf
);
6588 /* Assign symbols to all worthy DIEs under DIE. */
6591 assign_symbol_names (dw_die_ref die
)
6595 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6597 if (comdat_symbol_id
)
6599 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6601 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6602 comdat_symbol_id
, comdat_symbol_number
++);
6603 die
->die_id
.die_symbol
= xstrdup (p
);
6606 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6609 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6612 struct cu_hash_table_entry
6615 unsigned min_comdat_num
, max_comdat_num
;
6616 struct cu_hash_table_entry
*next
;
6619 /* Helpers to manipulate hash table of CUs. */
6621 struct cu_hash_table_entry_hasher
6623 typedef cu_hash_table_entry value_type
;
6624 typedef die_struct compare_type
;
6625 static inline hashval_t
hash (const value_type
*);
6626 static inline bool equal (const value_type
*, const compare_type
*);
6627 static inline void remove (value_type
*);
6631 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6633 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6637 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6638 const compare_type
*entry2
)
6640 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6644 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6646 struct cu_hash_table_entry
*next
;
6656 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6658 /* Check whether we have already seen this CU and set up SYM_NUM
6661 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6663 struct cu_hash_table_entry dummy
;
6664 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6666 dummy
.max_comdat_num
= 0;
6668 slot
= htable
.find_slot_with_hash (cu
,
6669 htab_hash_string (cu
->die_id
.die_symbol
),
6673 for (; entry
; last
= entry
, entry
= entry
->next
)
6675 if (same_die_p_wrap (cu
, entry
->cu
))
6681 *sym_num
= entry
->min_comdat_num
;
6685 entry
= XCNEW (struct cu_hash_table_entry
);
6687 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6688 entry
->next
= *slot
;
6694 /* Record SYM_NUM to record of CU in HTABLE. */
6696 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6697 unsigned int sym_num
)
6699 struct cu_hash_table_entry
**slot
, *entry
;
6701 slot
= htable
.find_slot_with_hash (cu
,
6702 htab_hash_string (cu
->die_id
.die_symbol
),
6706 entry
->max_comdat_num
= sym_num
;
6709 /* Traverse the DIE (which is always comp_unit_die), and set up
6710 additional compilation units for each of the include files we see
6711 bracketed by BINCL/EINCL. */
6714 break_out_includes (dw_die_ref die
)
6717 dw_die_ref unit
= NULL
;
6718 limbo_die_node
*node
, **pnode
;
6719 cu_hash_type cu_hash_table
;
6723 dw_die_ref prev
= c
;
6725 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6726 || (unit
&& is_comdat_die (c
)))
6728 dw_die_ref next
= c
->die_sib
;
6730 /* This DIE is for a secondary CU; remove it from the main one. */
6731 remove_child_with_prev (c
, prev
);
6733 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6734 unit
= push_new_compile_unit (unit
, c
);
6735 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6736 unit
= pop_compile_unit (unit
);
6738 add_child_die (unit
, c
);
6740 if (c
== die
->die_child
)
6743 } while (c
!= die
->die_child
);
6746 /* We can only use this in debugging, since the frontend doesn't check
6747 to make sure that we leave every include file we enter. */
6751 assign_symbol_names (die
);
6752 cu_hash_table
.create (10);
6753 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6759 compute_section_prefix (node
->die
);
6760 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6761 &comdat_symbol_number
);
6762 assign_symbol_names (node
->die
);
6764 *pnode
= node
->next
;
6767 pnode
= &node
->next
;
6768 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6769 comdat_symbol_number
);
6772 cu_hash_table
.dispose ();
6775 /* Return non-zero if this DIE is a declaration. */
6778 is_declaration_die (dw_die_ref die
)
6783 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6784 if (a
->dw_attr
== DW_AT_declaration
)
6790 /* Return non-zero if this DIE is nested inside a subprogram. */
6793 is_nested_in_subprogram (dw_die_ref die
)
6795 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6799 return local_scope_p (decl
);
6802 /* Return non-zero if this DIE contains a defining declaration of a
6806 contains_subprogram_definition (dw_die_ref die
)
6810 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6812 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6816 /* Return non-zero if this is a type DIE that should be moved to a
6817 COMDAT .debug_types section. */
6820 should_move_die_to_comdat (dw_die_ref die
)
6822 switch (die
->die_tag
)
6824 case DW_TAG_class_type
:
6825 case DW_TAG_structure_type
:
6826 case DW_TAG_enumeration_type
:
6827 case DW_TAG_union_type
:
6828 /* Don't move declarations, inlined instances, or types nested in a
6830 if (is_declaration_die (die
)
6831 || get_AT (die
, DW_AT_abstract_origin
)
6832 || is_nested_in_subprogram (die
))
6834 /* A type definition should never contain a subprogram definition. */
6835 gcc_assert (!contains_subprogram_definition (die
));
6837 case DW_TAG_array_type
:
6838 case DW_TAG_interface_type
:
6839 case DW_TAG_pointer_type
:
6840 case DW_TAG_reference_type
:
6841 case DW_TAG_rvalue_reference_type
:
6842 case DW_TAG_string_type
:
6843 case DW_TAG_subroutine_type
:
6844 case DW_TAG_ptr_to_member_type
:
6845 case DW_TAG_set_type
:
6846 case DW_TAG_subrange_type
:
6847 case DW_TAG_base_type
:
6848 case DW_TAG_const_type
:
6849 case DW_TAG_file_type
:
6850 case DW_TAG_packed_type
:
6851 case DW_TAG_volatile_type
:
6852 case DW_TAG_typedef
:
6858 /* Make a clone of DIE. */
6861 clone_die (dw_die_ref die
)
6867 clone
= ggc_alloc_cleared_die_node ();
6868 clone
->die_tag
= die
->die_tag
;
6870 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6871 add_dwarf_attr (clone
, a
);
6876 /* Make a clone of the tree rooted at DIE. */
6879 clone_tree (dw_die_ref die
)
6882 dw_die_ref clone
= clone_die (die
);
6884 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6889 /* Make a clone of DIE as a declaration. */
6892 clone_as_declaration (dw_die_ref die
)
6899 /* If the DIE is already a declaration, just clone it. */
6900 if (is_declaration_die (die
))
6901 return clone_die (die
);
6903 /* If the DIE is a specification, just clone its declaration DIE. */
6904 decl
= get_AT_ref (die
, DW_AT_specification
);
6907 clone
= clone_die (decl
);
6908 if (die
->comdat_type_p
)
6909 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6913 clone
= ggc_alloc_cleared_die_node ();
6914 clone
->die_tag
= die
->die_tag
;
6916 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6918 /* We don't want to copy over all attributes.
6919 For example we don't want DW_AT_byte_size because otherwise we will no
6920 longer have a declaration and GDB will treat it as a definition. */
6924 case DW_AT_artificial
:
6925 case DW_AT_containing_type
:
6926 case DW_AT_external
:
6929 case DW_AT_virtuality
:
6930 case DW_AT_linkage_name
:
6931 case DW_AT_MIPS_linkage_name
:
6932 add_dwarf_attr (clone
, a
);
6934 case DW_AT_byte_size
:
6940 if (die
->comdat_type_p
)
6941 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6943 add_AT_flag (clone
, DW_AT_declaration
, 1);
6948 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6950 struct decl_table_entry
6956 /* Helpers to manipulate hash table of copied declarations. */
6958 /* Hashtable helpers. */
6960 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6962 typedef decl_table_entry value_type
;
6963 typedef die_struct compare_type
;
6964 static inline hashval_t
hash (const value_type
*);
6965 static inline bool equal (const value_type
*, const compare_type
*);
6969 decl_table_entry_hasher::hash (const value_type
*entry
)
6971 return htab_hash_pointer (entry
->orig
);
6975 decl_table_entry_hasher::equal (const value_type
*entry1
,
6976 const compare_type
*entry2
)
6978 return entry1
->orig
== entry2
;
6981 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6983 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6984 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6985 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6986 to check if the ancestor has already been copied into UNIT. */
6989 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6991 dw_die_ref parent
= die
->die_parent
;
6992 dw_die_ref new_parent
= unit
;
6994 decl_table_entry
**slot
= NULL
;
6995 struct decl_table_entry
*entry
= NULL
;
6997 if (decl_table
.is_created ())
6999 /* Check if the entry has already been copied to UNIT. */
7000 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
7002 if (*slot
!= HTAB_EMPTY_ENTRY
)
7008 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7009 entry
= XCNEW (struct decl_table_entry
);
7017 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7020 if (!is_unit_die (parent
))
7021 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7024 copy
= clone_as_declaration (die
);
7025 add_child_die (new_parent
, copy
);
7027 if (decl_table
.is_created ())
7029 /* Record the pointer to the copy. */
7035 /* Copy the declaration context to the new type unit DIE. This includes
7036 any surrounding namespace or type declarations. If the DIE has an
7037 AT_specification attribute, it also includes attributes and children
7038 attached to the specification, and returns a pointer to the original
7039 parent of the declaration DIE. Returns NULL otherwise. */
7042 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7045 dw_die_ref new_decl
;
7046 dw_die_ref orig_parent
= NULL
;
7048 decl
= get_AT_ref (die
, DW_AT_specification
);
7057 /* The original DIE will be changed to a declaration, and must
7058 be moved to be a child of the original declaration DIE. */
7059 orig_parent
= decl
->die_parent
;
7061 /* Copy the type node pointer from the new DIE to the original
7062 declaration DIE so we can forward references later. */
7063 decl
->comdat_type_p
= true;
7064 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7066 remove_AT (die
, DW_AT_specification
);
7068 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7070 if (a
->dw_attr
!= DW_AT_name
7071 && a
->dw_attr
!= DW_AT_declaration
7072 && a
->dw_attr
!= DW_AT_external
)
7073 add_dwarf_attr (die
, a
);
7076 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7079 if (decl
->die_parent
!= NULL
7080 && !is_unit_die (decl
->die_parent
))
7082 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7083 if (new_decl
!= NULL
)
7085 remove_AT (new_decl
, DW_AT_signature
);
7086 add_AT_specification (die
, new_decl
);
7093 /* Generate the skeleton ancestor tree for the given NODE, then clone
7094 the DIE and add the clone into the tree. */
7097 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7099 if (node
->new_die
!= NULL
)
7102 node
->new_die
= clone_as_declaration (node
->old_die
);
7104 if (node
->parent
!= NULL
)
7106 generate_skeleton_ancestor_tree (node
->parent
);
7107 add_child_die (node
->parent
->new_die
, node
->new_die
);
7111 /* Generate a skeleton tree of DIEs containing any declarations that are
7112 found in the original tree. We traverse the tree looking for declaration
7113 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7116 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7118 skeleton_chain_node node
;
7121 dw_die_ref prev
= NULL
;
7122 dw_die_ref next
= NULL
;
7124 node
.parent
= parent
;
7126 first
= c
= parent
->old_die
->die_child
;
7130 if (prev
== NULL
|| prev
->die_sib
== c
)
7133 next
= (c
== first
? NULL
: c
->die_sib
);
7135 node
.new_die
= NULL
;
7136 if (is_declaration_die (c
))
7138 if (is_template_instantiation (c
))
7140 /* Instantiated templates do not need to be cloned into the
7141 type unit. Just move the DIE and its children back to
7142 the skeleton tree (in the main CU). */
7143 remove_child_with_prev (c
, prev
);
7144 add_child_die (parent
->new_die
, c
);
7149 /* Clone the existing DIE, move the original to the skeleton
7150 tree (which is in the main CU), and put the clone, with
7151 all the original's children, where the original came from
7152 (which is about to be moved to the type unit). */
7153 dw_die_ref clone
= clone_die (c
);
7154 move_all_children (c
, clone
);
7156 replace_child (c
, clone
, prev
);
7157 generate_skeleton_ancestor_tree (parent
);
7158 add_child_die (parent
->new_die
, c
);
7163 generate_skeleton_bottom_up (&node
);
7164 } while (next
!= NULL
);
7167 /* Wrapper function for generate_skeleton_bottom_up. */
7170 generate_skeleton (dw_die_ref die
)
7172 skeleton_chain_node node
;
7175 node
.new_die
= NULL
;
7178 /* If this type definition is nested inside another type,
7179 and is not an instantiation of a template, always leave
7180 at least a declaration in its place. */
7181 if (die
->die_parent
!= NULL
7182 && is_type_die (die
->die_parent
)
7183 && !is_template_instantiation (die
))
7184 node
.new_die
= clone_as_declaration (die
);
7186 generate_skeleton_bottom_up (&node
);
7187 return node
.new_die
;
7190 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7191 declaration. The original DIE is moved to a new compile unit so that
7192 existing references to it follow it to the new location. If any of the
7193 original DIE's descendants is a declaration, we need to replace the
7194 original DIE with a skeleton tree and move the declarations back into the
7198 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7201 dw_die_ref skeleton
, orig_parent
;
7203 /* Copy the declaration context to the type unit DIE. If the returned
7204 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7206 orig_parent
= copy_declaration_context (unit
, child
);
7208 skeleton
= generate_skeleton (child
);
7209 if (skeleton
== NULL
)
7210 remove_child_with_prev (child
, prev
);
7213 skeleton
->comdat_type_p
= true;
7214 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7216 /* If the original DIE was a specification, we need to put
7217 the skeleton under the parent DIE of the declaration.
7218 This leaves the original declaration in the tree, but
7219 it will be pruned later since there are no longer any
7220 references to it. */
7221 if (orig_parent
!= NULL
)
7223 remove_child_with_prev (child
, prev
);
7224 add_child_die (orig_parent
, skeleton
);
7227 replace_child (child
, skeleton
, prev
);
7233 /* Traverse the DIE and set up additional .debug_types sections for each
7234 type worthy of being placed in a COMDAT section. */
7237 break_out_comdat_types (dw_die_ref die
)
7241 dw_die_ref prev
= NULL
;
7242 dw_die_ref next
= NULL
;
7243 dw_die_ref unit
= NULL
;
7245 first
= c
= die
->die_child
;
7249 if (prev
== NULL
|| prev
->die_sib
== c
)
7252 next
= (c
== first
? NULL
: c
->die_sib
);
7253 if (should_move_die_to_comdat (c
))
7255 dw_die_ref replacement
;
7256 comdat_type_node_ref type_node
;
7258 /* Break out nested types into their own type units. */
7259 break_out_comdat_types (c
);
7261 /* Create a new type unit DIE as the root for the new tree, and
7262 add it to the list of comdat types. */
7263 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7264 add_AT_unsigned (unit
, DW_AT_language
,
7265 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7266 type_node
= ggc_alloc_cleared_comdat_type_node ();
7267 type_node
->root_die
= unit
;
7268 type_node
->next
= comdat_type_list
;
7269 comdat_type_list
= type_node
;
7271 /* Generate the type signature. */
7272 generate_type_signature (c
, type_node
);
7274 /* Copy the declaration context, attributes, and children of the
7275 declaration into the new type unit DIE, then remove this DIE
7276 from the main CU (or replace it with a skeleton if necessary). */
7277 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7278 type_node
->skeleton_die
= replacement
;
7280 /* Add the DIE to the new compunit. */
7281 add_child_die (unit
, c
);
7283 if (replacement
!= NULL
)
7286 else if (c
->die_tag
== DW_TAG_namespace
7287 || c
->die_tag
== DW_TAG_class_type
7288 || c
->die_tag
== DW_TAG_structure_type
7289 || c
->die_tag
== DW_TAG_union_type
)
7291 /* Look for nested types that can be broken out. */
7292 break_out_comdat_types (c
);
7294 } while (next
!= NULL
);
7297 /* Like clone_tree, but additionally enter all the children into
7298 the hash table decl_table. */
7301 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7304 dw_die_ref clone
= clone_die (die
);
7305 struct decl_table_entry
*entry
;
7306 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7307 htab_hash_pointer (die
), INSERT
);
7308 /* Assert that DIE isn't in the hash table yet. If it would be there
7309 before, the ancestors would be necessarily there as well, therefore
7310 clone_tree_hash wouldn't be called. */
7311 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7312 entry
= XCNEW (struct decl_table_entry
);
7314 entry
->copy
= clone
;
7317 FOR_EACH_CHILD (die
, c
,
7318 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7323 /* Walk the DIE and its children, looking for references to incomplete
7324 or trivial types that are unmarked (i.e., that are not in the current
7328 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7334 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7336 if (AT_class (a
) == dw_val_class_die_ref
)
7338 dw_die_ref targ
= AT_ref (a
);
7339 decl_table_entry
**slot
;
7340 struct decl_table_entry
*entry
;
7342 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7345 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7348 if (*slot
!= HTAB_EMPTY_ENTRY
)
7350 /* TARG has already been copied, so we just need to
7351 modify the reference to point to the copy. */
7353 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7357 dw_die_ref parent
= unit
;
7358 dw_die_ref copy
= clone_die (targ
);
7360 /* Record in DECL_TABLE that TARG has been copied.
7361 Need to do this now, before the recursive call,
7362 because DECL_TABLE may be expanded and SLOT
7363 would no longer be a valid pointer. */
7364 entry
= XCNEW (struct decl_table_entry
);
7369 FOR_EACH_CHILD (targ
, c
,
7370 add_child_die (copy
,
7371 clone_tree_hash (c
, decl_table
)));
7373 /* Make sure the cloned tree is marked as part of the
7377 /* If TARG has surrounding context, copy its ancestor tree
7378 into the new type unit. */
7379 if (targ
->die_parent
!= NULL
7380 && !is_unit_die (targ
->die_parent
))
7381 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7384 add_child_die (parent
, copy
);
7385 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7387 /* Make sure the newly-copied DIE is walked. If it was
7388 installed in a previously-added context, it won't
7389 get visited otherwise. */
7392 /* Find the highest point of the newly-added tree,
7393 mark each node along the way, and walk from there. */
7394 parent
->die_mark
= 1;
7395 while (parent
->die_parent
7396 && parent
->die_parent
->die_mark
== 0)
7398 parent
= parent
->die_parent
;
7399 parent
->die_mark
= 1;
7401 copy_decls_walk (unit
, parent
, decl_table
);
7407 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7410 /* Copy declarations for "unworthy" types into the new comdat section.
7411 Incomplete types, modified types, and certain other types aren't broken
7412 out into comdat sections of their own, so they don't have a signature,
7413 and we need to copy the declaration into the same section so that we
7414 don't have an external reference. */
7417 copy_decls_for_unworthy_types (dw_die_ref unit
)
7419 decl_hash_type decl_table
;
7422 decl_table
.create (10);
7423 copy_decls_walk (unit
, unit
, decl_table
);
7424 decl_table
.dispose ();
7428 /* Traverse the DIE and add a sibling attribute if it may have the
7429 effect of speeding up access to siblings. To save some space,
7430 avoid generating sibling attributes for DIE's without children. */
7433 add_sibling_attributes (dw_die_ref die
)
7437 if (! die
->die_child
)
7440 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7441 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7443 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7446 /* Output all location lists for the DIE and its children. */
7449 output_location_lists (dw_die_ref die
)
7455 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7456 if (AT_class (a
) == dw_val_class_loc_list
)
7457 output_loc_list (AT_loc_list (a
));
7459 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7462 /* We want to limit the number of external references, because they are
7463 larger than local references: a relocation takes multiple words, and
7464 even a sig8 reference is always eight bytes, whereas a local reference
7465 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7466 So if we encounter multiple external references to the same type DIE, we
7467 make a local typedef stub for it and redirect all references there.
7469 This is the element of the hash table for keeping track of these
7479 /* Hashtable helpers. */
7481 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7483 typedef external_ref value_type
;
7484 typedef external_ref compare_type
;
7485 static inline hashval_t
hash (const value_type
*);
7486 static inline bool equal (const value_type
*, const compare_type
*);
7490 external_ref_hasher::hash (const value_type
*r
)
7492 dw_die_ref die
= r
->type
;
7495 /* We can't use the address of the DIE for hashing, because
7496 that will make the order of the stub DIEs non-deterministic. */
7497 if (! die
->comdat_type_p
)
7498 /* We have a symbol; use it to compute a hash. */
7499 h
= htab_hash_string (die
->die_id
.die_symbol
);
7502 /* We have a type signature; use a subset of the bits as the hash.
7503 The 8-byte signature is at least as large as hashval_t. */
7504 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7505 memcpy (&h
, type_node
->signature
, sizeof (h
));
7511 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7513 return r1
->type
== r2
->type
;
7516 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7518 /* Return a pointer to the external_ref for references to DIE. */
7520 static struct external_ref
*
7521 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7523 struct external_ref ref
, *ref_p
;
7524 external_ref
**slot
;
7527 slot
= map
.find_slot (&ref
, INSERT
);
7528 if (*slot
!= HTAB_EMPTY_ENTRY
)
7531 ref_p
= XCNEW (struct external_ref
);
7537 /* Subroutine of optimize_external_refs, below.
7539 If we see a type skeleton, record it as our stub. If we see external
7540 references, remember how many we've seen. */
7543 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7548 struct external_ref
*ref_p
;
7550 if (is_type_die (die
)
7551 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7553 /* This is a local skeleton; use it for local references. */
7554 ref_p
= lookup_external_ref (map
, c
);
7558 /* Scan the DIE references, and remember any that refer to DIEs from
7559 other CUs (i.e. those which are not marked). */
7560 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7561 if (AT_class (a
) == dw_val_class_die_ref
7562 && (c
= AT_ref (a
))->die_mark
== 0
7565 ref_p
= lookup_external_ref (map
, c
);
7569 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7572 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7573 points to an external_ref, DATA is the CU we're processing. If we don't
7574 already have a local stub, and we have multiple refs, build a stub. */
7577 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7579 struct external_ref
*ref_p
= *slot
;
7581 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7583 /* We have multiple references to this type, so build a small stub.
7584 Both of these forms are a bit dodgy from the perspective of the
7585 DWARF standard, since technically they should have names. */
7586 dw_die_ref cu
= data
;
7587 dw_die_ref type
= ref_p
->type
;
7588 dw_die_ref stub
= NULL
;
7590 if (type
->comdat_type_p
)
7592 /* If we refer to this type via sig8, use AT_signature. */
7593 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7594 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7598 /* Otherwise, use a typedef with no name. */
7599 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7600 add_AT_die_ref (stub
, DW_AT_type
, type
);
7609 /* DIE is a unit; look through all the DIE references to see if there are
7610 any external references to types, and if so, create local stubs for
7611 them which will be applied in build_abbrev_table. This is useful because
7612 references to local DIEs are smaller. */
7614 static external_ref_hash_type
7615 optimize_external_refs (dw_die_ref die
)
7617 external_ref_hash_type map
;
7619 optimize_external_refs_1 (die
, map
);
7620 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7624 /* The format of each DIE (and its attribute value pairs) is encoded in an
7625 abbreviation table. This routine builds the abbreviation table and assigns
7626 a unique abbreviation id for each abbreviation entry. The children of each
7627 die are visited recursively. */
7630 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7632 unsigned long abbrev_id
;
7633 unsigned int n_alloc
;
7638 /* Scan the DIE references, and replace any that refer to
7639 DIEs from other CUs (i.e. those which are not marked) with
7640 the local stubs we built in optimize_external_refs. */
7641 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7642 if (AT_class (a
) == dw_val_class_die_ref
7643 && (c
= AT_ref (a
))->die_mark
== 0)
7645 struct external_ref
*ref_p
;
7646 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7648 ref_p
= lookup_external_ref (extern_map
, c
);
7649 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7650 change_AT_die_ref (a
, ref_p
->stub
);
7652 /* We aren't changing this reference, so mark it external. */
7653 set_AT_ref_external (a
, 1);
7656 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7658 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7659 dw_attr_ref die_a
, abbrev_a
;
7663 if (abbrev
->die_tag
!= die
->die_tag
)
7665 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7668 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7671 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7673 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7674 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7675 || (value_format (abbrev_a
) != value_format (die_a
)))
7685 if (abbrev_id
>= abbrev_die_table_in_use
)
7687 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7689 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7690 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7693 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7694 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7695 abbrev_die_table_allocated
= n_alloc
;
7698 ++abbrev_die_table_in_use
;
7699 abbrev_die_table
[abbrev_id
] = die
;
7702 die
->die_abbrev
= abbrev_id
;
7703 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7706 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7709 constant_size (unsigned HOST_WIDE_INT value
)
7716 log
= floor_log2 (value
);
7719 log
= 1 << (floor_log2 (log
) + 1);
7724 /* Return the size of a DIE as it is represented in the
7725 .debug_info section. */
7727 static unsigned long
7728 size_of_die (dw_die_ref die
)
7730 unsigned long size
= 0;
7733 enum dwarf_form form
;
7735 size
+= size_of_uleb128 (die
->die_abbrev
);
7736 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7738 switch (AT_class (a
))
7740 case dw_val_class_addr
:
7741 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7743 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7744 size
+= size_of_uleb128 (AT_index (a
));
7747 size
+= DWARF2_ADDR_SIZE
;
7749 case dw_val_class_offset
:
7750 size
+= DWARF_OFFSET_SIZE
;
7752 case dw_val_class_loc
:
7754 unsigned long lsize
= size_of_locs (AT_loc (a
));
7757 if (dwarf_version
>= 4)
7758 size
+= size_of_uleb128 (lsize
);
7760 size
+= constant_size (lsize
);
7764 case dw_val_class_loc_list
:
7765 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7767 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7768 size
+= size_of_uleb128 (AT_index (a
));
7771 size
+= DWARF_OFFSET_SIZE
;
7773 case dw_val_class_range_list
:
7774 size
+= DWARF_OFFSET_SIZE
;
7776 case dw_val_class_const
:
7777 size
+= size_of_sleb128 (AT_int (a
));
7779 case dw_val_class_unsigned_const
:
7781 int csize
= constant_size (AT_unsigned (a
));
7782 if (dwarf_version
== 3
7783 && a
->dw_attr
== DW_AT_data_member_location
7785 size
+= size_of_uleb128 (AT_unsigned (a
));
7790 case dw_val_class_const_double
:
7791 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7792 if (HOST_BITS_PER_WIDE_INT
>= 64)
7795 case dw_val_class_vec
:
7796 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7797 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7798 + a
->dw_attr_val
.v
.val_vec
.length
7799 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7801 case dw_val_class_flag
:
7802 if (dwarf_version
>= 4)
7803 /* Currently all add_AT_flag calls pass in 1 as last argument,
7804 so DW_FORM_flag_present can be used. If that ever changes,
7805 we'll need to use DW_FORM_flag and have some optimization
7806 in build_abbrev_table that will change those to
7807 DW_FORM_flag_present if it is set to 1 in all DIEs using
7808 the same abbrev entry. */
7809 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7813 case dw_val_class_die_ref
:
7814 if (AT_ref_external (a
))
7816 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7817 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7818 is sized by target address length, whereas in DWARF3
7819 it's always sized as an offset. */
7820 if (use_debug_types
)
7821 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7822 else if (dwarf_version
== 2)
7823 size
+= DWARF2_ADDR_SIZE
;
7825 size
+= DWARF_OFFSET_SIZE
;
7828 size
+= DWARF_OFFSET_SIZE
;
7830 case dw_val_class_fde_ref
:
7831 size
+= DWARF_OFFSET_SIZE
;
7833 case dw_val_class_lbl_id
:
7834 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7836 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7837 size
+= size_of_uleb128 (AT_index (a
));
7840 size
+= DWARF2_ADDR_SIZE
;
7842 case dw_val_class_lineptr
:
7843 case dw_val_class_macptr
:
7844 size
+= DWARF_OFFSET_SIZE
;
7846 case dw_val_class_str
:
7847 form
= AT_string_form (a
);
7848 if (form
== DW_FORM_strp
)
7849 size
+= DWARF_OFFSET_SIZE
;
7850 else if (form
== DW_FORM_GNU_str_index
)
7851 size
+= size_of_uleb128 (AT_index (a
));
7853 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7855 case dw_val_class_file
:
7856 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7858 case dw_val_class_data8
:
7861 case dw_val_class_vms_delta
:
7862 size
+= DWARF_OFFSET_SIZE
;
7864 case dw_val_class_high_pc
:
7865 size
+= DWARF2_ADDR_SIZE
;
7875 /* Size the debugging information associated with a given DIE. Visits the
7876 DIE's children recursively. Updates the global variable next_die_offset, on
7877 each time through. Uses the current value of next_die_offset to update the
7878 die_offset field in each DIE. */
7881 calc_die_sizes (dw_die_ref die
)
7885 gcc_assert (die
->die_offset
== 0
7886 || (unsigned long int) die
->die_offset
== next_die_offset
);
7887 die
->die_offset
= next_die_offset
;
7888 next_die_offset
+= size_of_die (die
);
7890 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7892 if (die
->die_child
!= NULL
)
7893 /* Count the null byte used to terminate sibling lists. */
7894 next_die_offset
+= 1;
7897 /* Size just the base type children at the start of the CU.
7898 This is needed because build_abbrev needs to size locs
7899 and sizing of type based stack ops needs to know die_offset
7900 values for the base types. */
7903 calc_base_type_die_sizes (void)
7905 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7907 dw_die_ref base_type
;
7908 #if ENABLE_ASSERT_CHECKING
7909 dw_die_ref prev
= comp_unit_die ()->die_child
;
7912 die_offset
+= size_of_die (comp_unit_die ());
7913 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7915 #if ENABLE_ASSERT_CHECKING
7916 gcc_assert (base_type
->die_offset
== 0
7917 && prev
->die_sib
== base_type
7918 && base_type
->die_child
== NULL
7919 && base_type
->die_abbrev
);
7922 base_type
->die_offset
= die_offset
;
7923 die_offset
+= size_of_die (base_type
);
7927 /* Set the marks for a die and its children. We do this so
7928 that we know whether or not a reference needs to use FORM_ref_addr; only
7929 DIEs in the same CU will be marked. We used to clear out the offset
7930 and use that as the flag, but ran into ordering problems. */
7933 mark_dies (dw_die_ref die
)
7937 gcc_assert (!die
->die_mark
);
7940 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7943 /* Clear the marks for a die and its children. */
7946 unmark_dies (dw_die_ref die
)
7950 if (! use_debug_types
)
7951 gcc_assert (die
->die_mark
);
7954 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7957 /* Clear the marks for a die, its children and referred dies. */
7960 unmark_all_dies (dw_die_ref die
)
7970 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7972 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7973 if (AT_class (a
) == dw_val_class_die_ref
)
7974 unmark_all_dies (AT_ref (a
));
7977 /* Calculate if the entry should appear in the final output file. It may be
7978 from a pruned a type. */
7981 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
7983 /* By limiting gnu pubnames to definitions only, gold can generate a
7984 gdb index without entries for declarations, which don't include
7985 enough information to be useful. */
7986 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
7989 if (table
== pubname_table
)
7991 /* Enumerator names are part of the pubname table, but the
7992 parent DW_TAG_enumeration_type die may have been pruned.
7993 Don't output them if that is the case. */
7994 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
7995 (p
->die
->die_parent
== NULL
7996 || !p
->die
->die_parent
->die_perennial_p
))
7999 /* Everything else in the pubname table is included. */
8003 /* The pubtypes table shouldn't include types that have been
8005 return (p
->die
->die_offset
!= 0
8006 || !flag_eliminate_unused_debug_types
);
8009 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8010 generated for the compilation unit. */
8012 static unsigned long
8013 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8018 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8020 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8021 FOR_EACH_VEC_ELT (*names
, i
, p
)
8022 if (include_pubname_in_output (names
, p
))
8023 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8025 size
+= DWARF_OFFSET_SIZE
;
8029 /* Return the size of the information in the .debug_aranges section. */
8031 static unsigned long
8032 size_of_aranges (void)
8036 size
= DWARF_ARANGES_HEADER_SIZE
;
8038 /* Count the address/length pair for this compilation unit. */
8039 if (text_section_used
)
8040 size
+= 2 * DWARF2_ADDR_SIZE
;
8041 if (cold_text_section_used
)
8042 size
+= 2 * DWARF2_ADDR_SIZE
;
8043 if (have_multiple_function_sections
)
8048 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8050 if (DECL_IGNORED_P (fde
->decl
))
8052 if (!fde
->in_std_section
)
8053 size
+= 2 * DWARF2_ADDR_SIZE
;
8054 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8055 size
+= 2 * DWARF2_ADDR_SIZE
;
8059 /* Count the two zero words used to terminated the address range table. */
8060 size
+= 2 * DWARF2_ADDR_SIZE
;
8064 /* Select the encoding of an attribute value. */
8066 static enum dwarf_form
8067 value_format (dw_attr_ref a
)
8069 switch (AT_class (a
))
8071 case dw_val_class_addr
:
8072 /* Only very few attributes allow DW_FORM_addr. */
8077 case DW_AT_entry_pc
:
8078 case DW_AT_trampoline
:
8079 return (AT_index (a
) == NOT_INDEXED
8080 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8084 switch (DWARF2_ADDR_SIZE
)
8087 return DW_FORM_data1
;
8089 return DW_FORM_data2
;
8091 return DW_FORM_data4
;
8093 return DW_FORM_data8
;
8097 case dw_val_class_range_list
:
8098 case dw_val_class_loc_list
:
8099 if (dwarf_version
>= 4)
8100 return DW_FORM_sec_offset
;
8102 case dw_val_class_vms_delta
:
8103 case dw_val_class_offset
:
8104 switch (DWARF_OFFSET_SIZE
)
8107 return DW_FORM_data4
;
8109 return DW_FORM_data8
;
8113 case dw_val_class_loc
:
8114 if (dwarf_version
>= 4)
8115 return DW_FORM_exprloc
;
8116 switch (constant_size (size_of_locs (AT_loc (a
))))
8119 return DW_FORM_block1
;
8121 return DW_FORM_block2
;
8123 return DW_FORM_block4
;
8127 case dw_val_class_const
:
8128 return DW_FORM_sdata
;
8129 case dw_val_class_unsigned_const
:
8130 switch (constant_size (AT_unsigned (a
)))
8133 return DW_FORM_data1
;
8135 return DW_FORM_data2
;
8137 /* In DWARF3 DW_AT_data_member_location with
8138 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8139 constant, so we need to use DW_FORM_udata if we need
8140 a large constant. */
8141 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8142 return DW_FORM_udata
;
8143 return DW_FORM_data4
;
8145 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8146 return DW_FORM_udata
;
8147 return DW_FORM_data8
;
8151 case dw_val_class_const_double
:
8152 switch (HOST_BITS_PER_WIDE_INT
)
8155 return DW_FORM_data2
;
8157 return DW_FORM_data4
;
8159 return DW_FORM_data8
;
8162 return DW_FORM_block1
;
8164 case dw_val_class_vec
:
8165 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8166 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8169 return DW_FORM_block1
;
8171 return DW_FORM_block2
;
8173 return DW_FORM_block4
;
8177 case dw_val_class_flag
:
8178 if (dwarf_version
>= 4)
8180 /* Currently all add_AT_flag calls pass in 1 as last argument,
8181 so DW_FORM_flag_present can be used. If that ever changes,
8182 we'll need to use DW_FORM_flag and have some optimization
8183 in build_abbrev_table that will change those to
8184 DW_FORM_flag_present if it is set to 1 in all DIEs using
8185 the same abbrev entry. */
8186 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8187 return DW_FORM_flag_present
;
8189 return DW_FORM_flag
;
8190 case dw_val_class_die_ref
:
8191 if (AT_ref_external (a
))
8192 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8195 case dw_val_class_fde_ref
:
8196 return DW_FORM_data
;
8197 case dw_val_class_lbl_id
:
8198 return (AT_index (a
) == NOT_INDEXED
8199 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8200 case dw_val_class_lineptr
:
8201 case dw_val_class_macptr
:
8202 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8203 case dw_val_class_str
:
8204 return AT_string_form (a
);
8205 case dw_val_class_file
:
8206 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8209 return DW_FORM_data1
;
8211 return DW_FORM_data2
;
8213 return DW_FORM_data4
;
8218 case dw_val_class_data8
:
8219 return DW_FORM_data8
;
8221 case dw_val_class_high_pc
:
8222 switch (DWARF2_ADDR_SIZE
)
8225 return DW_FORM_data1
;
8227 return DW_FORM_data2
;
8229 return DW_FORM_data4
;
8231 return DW_FORM_data8
;
8241 /* Output the encoding of an attribute value. */
8244 output_value_format (dw_attr_ref a
)
8246 enum dwarf_form form
= value_format (a
);
8248 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8251 /* Given a die and id, produce the appropriate abbreviations. */
8254 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8259 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8260 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8261 dwarf_tag_name (abbrev
->die_tag
));
8263 if (abbrev
->die_child
!= NULL
)
8264 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8266 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8268 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8270 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8271 dwarf_attr_name (a_attr
->dw_attr
));
8272 output_value_format (a_attr
);
8275 dw2_asm_output_data (1, 0, NULL
);
8276 dw2_asm_output_data (1, 0, NULL
);
8280 /* Output the .debug_abbrev section which defines the DIE abbreviation
8284 output_abbrev_section (void)
8286 unsigned long abbrev_id
;
8288 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8289 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8291 /* Terminate the table. */
8292 dw2_asm_output_data (1, 0, NULL
);
8295 /* Output a symbol we can use to refer to this DIE from another CU. */
8298 output_die_symbol (dw_die_ref die
)
8300 const char *sym
= die
->die_id
.die_symbol
;
8302 gcc_assert (!die
->comdat_type_p
);
8307 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8308 /* We make these global, not weak; if the target doesn't support
8309 .linkonce, it doesn't support combining the sections, so debugging
8311 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8313 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8316 /* Return a new location list, given the begin and end range, and the
8319 static inline dw_loc_list_ref
8320 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8321 const char *section
)
8323 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8325 retlist
->begin
= begin
;
8326 retlist
->begin_entry
= NULL
;
8328 retlist
->expr
= expr
;
8329 retlist
->section
= section
;
8334 /* Generate a new internal symbol for this location list node, if it
8335 hasn't got one yet. */
8338 gen_llsym (dw_loc_list_ref list
)
8340 gcc_assert (!list
->ll_symbol
);
8341 list
->ll_symbol
= gen_internal_sym ("LLST");
8344 /* Output the location list given to us. */
8347 output_loc_list (dw_loc_list_ref list_head
)
8349 dw_loc_list_ref curr
= list_head
;
8351 if (list_head
->emitted
)
8353 list_head
->emitted
= true;
8355 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8357 /* Walk the location list, and output each range + expression. */
8358 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8361 /* Don't output an entry that starts and ends at the same address. */
8362 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8364 size
= size_of_locs (curr
->expr
);
8365 /* If the expression is too large, drop it on the floor. We could
8366 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8367 in the expression, but >= 64KB expressions for a single value
8368 in a single range are unlikely very useful. */
8371 if (dwarf_split_debug_info
)
8373 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8374 "Location list start/length entry (%s)",
8375 list_head
->ll_symbol
);
8376 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8377 "Location list range start index (%s)",
8379 /* The length field is 4 bytes. If we ever need to support
8380 an 8-byte length, we can add a new DW_LLE code or fall back
8381 to DW_LLE_GNU_start_end_entry. */
8382 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8383 "Location list range length (%s)",
8384 list_head
->ll_symbol
);
8386 else if (!have_multiple_function_sections
)
8388 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8389 "Location list begin address (%s)",
8390 list_head
->ll_symbol
);
8391 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8392 "Location list end address (%s)",
8393 list_head
->ll_symbol
);
8397 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8398 "Location list begin address (%s)",
8399 list_head
->ll_symbol
);
8400 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8401 "Location list end address (%s)",
8402 list_head
->ll_symbol
);
8405 /* Output the block length for this list of location operations. */
8406 gcc_assert (size
<= 0xffff);
8407 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8409 output_loc_sequence (curr
->expr
, -1);
8412 if (dwarf_split_debug_info
)
8413 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8414 "Location list terminator (%s)",
8415 list_head
->ll_symbol
);
8418 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8419 "Location list terminator begin (%s)",
8420 list_head
->ll_symbol
);
8421 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8422 "Location list terminator end (%s)",
8423 list_head
->ll_symbol
);
8427 /* Output a range_list offset into the debug_range section. Emit a
8428 relocated reference if val_entry is NULL, otherwise, emit an
8429 indirect reference. */
8432 output_range_list_offset (dw_attr_ref a
)
8434 const char *name
= dwarf_attr_name (a
->dw_attr
);
8436 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8438 char *p
= strchr (ranges_section_label
, '\0');
8439 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8440 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8441 debug_ranges_section
, "%s", name
);
8445 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8446 "%s (offset from %s)", name
, ranges_section_label
);
8449 /* Output the offset into the debug_loc section. */
8452 output_loc_list_offset (dw_attr_ref a
)
8454 char *sym
= AT_loc_list (a
)->ll_symbol
;
8457 if (dwarf_split_debug_info
)
8458 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8459 "%s", dwarf_attr_name (a
->dw_attr
));
8461 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8462 "%s", dwarf_attr_name (a
->dw_attr
));
8465 /* Output an attribute's index or value appropriately. */
8468 output_attr_index_or_value (dw_attr_ref a
)
8470 const char *name
= dwarf_attr_name (a
->dw_attr
);
8472 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8474 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8477 switch (AT_class (a
))
8479 case dw_val_class_addr
:
8480 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8482 case dw_val_class_high_pc
:
8483 case dw_val_class_lbl_id
:
8484 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8486 case dw_val_class_loc_list
:
8487 output_loc_list_offset (a
);
8494 /* Output a type signature. */
8497 output_signature (const char *sig
, const char *name
)
8501 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8502 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8505 /* Output the DIE and its attributes. Called recursively to generate
8506 the definitions of each child DIE. */
8509 output_die (dw_die_ref die
)
8516 /* If someone in another CU might refer to us, set up a symbol for
8517 them to point to. */
8518 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8519 output_die_symbol (die
);
8521 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8522 (unsigned long)die
->die_offset
,
8523 dwarf_tag_name (die
->die_tag
));
8525 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8527 const char *name
= dwarf_attr_name (a
->dw_attr
);
8529 switch (AT_class (a
))
8531 case dw_val_class_addr
:
8532 output_attr_index_or_value (a
);
8535 case dw_val_class_offset
:
8536 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8540 case dw_val_class_range_list
:
8541 output_range_list_offset (a
);
8544 case dw_val_class_loc
:
8545 size
= size_of_locs (AT_loc (a
));
8547 /* Output the block length for this list of location operations. */
8548 if (dwarf_version
>= 4)
8549 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8551 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8553 output_loc_sequence (AT_loc (a
), -1);
8556 case dw_val_class_const
:
8557 /* ??? It would be slightly more efficient to use a scheme like is
8558 used for unsigned constants below, but gdb 4.x does not sign
8559 extend. Gdb 5.x does sign extend. */
8560 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8563 case dw_val_class_unsigned_const
:
8565 int csize
= constant_size (AT_unsigned (a
));
8566 if (dwarf_version
== 3
8567 && a
->dw_attr
== DW_AT_data_member_location
8569 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8571 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8575 case dw_val_class_const_double
:
8577 unsigned HOST_WIDE_INT first
, second
;
8579 if (HOST_BITS_PER_WIDE_INT
>= 64)
8580 dw2_asm_output_data (1,
8581 HOST_BITS_PER_DOUBLE_INT
8582 / HOST_BITS_PER_CHAR
,
8585 if (WORDS_BIG_ENDIAN
)
8587 first
= a
->dw_attr_val
.v
.val_double
.high
;
8588 second
= a
->dw_attr_val
.v
.val_double
.low
;
8592 first
= a
->dw_attr_val
.v
.val_double
.low
;
8593 second
= a
->dw_attr_val
.v
.val_double
.high
;
8596 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8598 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8603 case dw_val_class_vec
:
8605 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8606 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8610 dw2_asm_output_data (constant_size (len
* elt_size
),
8611 len
* elt_size
, "%s", name
);
8612 if (elt_size
> sizeof (HOST_WIDE_INT
))
8617 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8620 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8621 "fp or vector constant word %u", i
);
8625 case dw_val_class_flag
:
8626 if (dwarf_version
>= 4)
8628 /* Currently all add_AT_flag calls pass in 1 as last argument,
8629 so DW_FORM_flag_present can be used. If that ever changes,
8630 we'll need to use DW_FORM_flag and have some optimization
8631 in build_abbrev_table that will change those to
8632 DW_FORM_flag_present if it is set to 1 in all DIEs using
8633 the same abbrev entry. */
8634 gcc_assert (AT_flag (a
) == 1);
8636 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8637 ASM_COMMENT_START
, name
);
8640 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8643 case dw_val_class_loc_list
:
8644 output_attr_index_or_value (a
);
8647 case dw_val_class_die_ref
:
8648 if (AT_ref_external (a
))
8650 if (AT_ref (a
)->comdat_type_p
)
8652 comdat_type_node_ref type_node
=
8653 AT_ref (a
)->die_id
.die_type_node
;
8655 gcc_assert (type_node
);
8656 output_signature (type_node
->signature
, name
);
8660 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8664 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8665 length, whereas in DWARF3 it's always sized as an
8667 if (dwarf_version
== 2)
8668 size
= DWARF2_ADDR_SIZE
;
8670 size
= DWARF_OFFSET_SIZE
;
8671 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8677 gcc_assert (AT_ref (a
)->die_offset
);
8678 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8683 case dw_val_class_fde_ref
:
8687 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8688 a
->dw_attr_val
.v
.val_fde_index
* 2);
8689 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8694 case dw_val_class_vms_delta
:
8695 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8696 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8700 case dw_val_class_lbl_id
:
8701 output_attr_index_or_value (a
);
8704 case dw_val_class_lineptr
:
8705 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8706 debug_line_section
, "%s", name
);
8709 case dw_val_class_macptr
:
8710 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8711 debug_macinfo_section
, "%s", name
);
8714 case dw_val_class_str
:
8715 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8716 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8717 a
->dw_attr_val
.v
.val_str
->label
,
8719 "%s: \"%s\"", name
, AT_string (a
));
8720 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8721 dw2_asm_output_data_uleb128 (AT_index (a
),
8722 "%s: \"%s\"", name
, AT_string (a
));
8724 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8727 case dw_val_class_file
:
8729 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8731 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8732 a
->dw_attr_val
.v
.val_file
->filename
);
8736 case dw_val_class_data8
:
8740 for (i
= 0; i
< 8; i
++)
8741 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8742 i
== 0 ? "%s" : NULL
, name
);
8746 case dw_val_class_high_pc
:
8747 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8748 get_AT_low_pc (die
), "DW_AT_high_pc");
8756 FOR_EACH_CHILD (die
, c
, output_die (c
));
8758 /* Add null byte to terminate sibling list. */
8759 if (die
->die_child
!= NULL
)
8760 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8761 (unsigned long) die
->die_offset
);
8764 /* Output the compilation unit that appears at the beginning of the
8765 .debug_info section, and precedes the DIE descriptions. */
8768 output_compilation_unit_header (void)
8770 int ver
= dwarf_version
;
8772 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8773 dw2_asm_output_data (4, 0xffffffff,
8774 "Initial length escape value indicating 64-bit DWARF extension");
8775 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8776 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8777 "Length of Compilation Unit Info");
8778 dw2_asm_output_data (2, ver
, "DWARF version number");
8779 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8780 debug_abbrev_section
,
8781 "Offset Into Abbrev. Section");
8782 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8785 /* Output the compilation unit DIE and its children. */
8788 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8790 const char *secname
, *oldsym
;
8792 external_ref_hash_type extern_map
;
8794 /* Unless we are outputting main CU, we may throw away empty ones. */
8795 if (!output_if_empty
&& die
->die_child
== NULL
)
8798 /* Even if there are no children of this DIE, we must output the information
8799 about the compilation unit. Otherwise, on an empty translation unit, we
8800 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8801 will then complain when examining the file. First mark all the DIEs in
8802 this CU so we know which get local refs. */
8805 extern_map
= optimize_external_refs (die
);
8807 build_abbrev_table (die
, extern_map
);
8809 extern_map
.dispose ();
8811 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8812 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8813 calc_die_sizes (die
);
8815 oldsym
= die
->die_id
.die_symbol
;
8818 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8820 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8822 die
->die_id
.die_symbol
= NULL
;
8823 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8827 switch_to_section (debug_info_section
);
8828 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8829 info_section_emitted
= true;
8832 /* Output debugging information. */
8833 output_compilation_unit_header ();
8836 /* Leave the marks on the main CU, so we can check them in
8841 die
->die_id
.die_symbol
= oldsym
;
8845 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8846 and .debug_pubtypes. This is configured per-target, but can be
8847 overridden by the -gpubnames or -gno-pubnames options. */
8850 want_pubnames (void)
8852 if (debug_generate_pub_sections
!= -1)
8853 return debug_generate_pub_sections
;
8854 return targetm
.want_debug_pub_sections
;
8857 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8860 add_AT_pubnames (dw_die_ref die
)
8862 if (want_pubnames ())
8863 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8866 /* Add a string attribute value to a skeleton DIE. */
8869 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8873 struct indirect_string_node
*node
;
8875 if (! skeleton_debug_str_hash
)
8876 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8877 debug_str_eq
, NULL
);
8879 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8880 find_string_form (node
);
8881 if (node
->form
== DW_FORM_GNU_str_index
)
8882 node
->form
= DW_FORM_strp
;
8884 attr
.dw_attr
= attr_kind
;
8885 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8886 attr
.dw_attr_val
.val_entry
= NULL
;
8887 attr
.dw_attr_val
.v
.val_str
= node
;
8888 add_dwarf_attr (die
, &attr
);
8891 /* Helper function to generate top-level dies for skeleton debug_info and
8895 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8897 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8898 const char *comp_dir
= comp_dir_string ();
8900 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8901 if (comp_dir
!= NULL
)
8902 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8903 add_AT_pubnames (die
);
8904 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8907 /* Return the single type-unit die for skeleton type units. */
8910 get_skeleton_type_unit (void)
8912 /* For dwarf_split_debug_sections with use_type info, all type units in the
8913 skeleton sections have identical dies (but different headers). This
8914 single die will be output many times. */
8916 static dw_die_ref skeleton_type_unit
= NULL
;
8918 if (skeleton_type_unit
== NULL
)
8920 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8921 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8922 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8924 return skeleton_type_unit
;
8927 /* Output skeleton debug sections that point to the dwo file. */
8930 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8932 /* These attributes will be found in the full debug_info section. */
8933 remove_AT (comp_unit
, DW_AT_producer
);
8934 remove_AT (comp_unit
, DW_AT_language
);
8936 switch_to_section (debug_skeleton_info_section
);
8937 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8939 /* Produce the skeleton compilation-unit header. This one differs enough from
8940 a normal CU header that it's better not to call output_compilation_unit
8942 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8943 dw2_asm_output_data (4, 0xffffffff,
8944 "Initial length escape value indicating 64-bit DWARF extension");
8946 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8947 DWARF_COMPILE_UNIT_HEADER_SIZE
8948 - DWARF_INITIAL_LENGTH_SIZE
8949 + size_of_die (comp_unit
),
8950 "Length of Compilation Unit Info");
8951 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8952 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8953 debug_abbrev_section
,
8954 "Offset Into Abbrev. Section");
8955 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8957 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8958 output_die (comp_unit
);
8960 /* Build the skeleton debug_abbrev section. */
8961 switch_to_section (debug_skeleton_abbrev_section
);
8962 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8964 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8965 if (use_debug_types
)
8966 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8968 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8971 /* Output a comdat type unit DIE and its children. */
8974 output_comdat_type_unit (comdat_type_node
*node
)
8976 const char *secname
;
8979 #if defined (OBJECT_FORMAT_ELF)
8982 external_ref_hash_type extern_map
;
8984 /* First mark all the DIEs in this CU so we know which get local refs. */
8985 mark_dies (node
->root_die
);
8987 extern_map
= optimize_external_refs (node
->root_die
);
8989 build_abbrev_table (node
->root_die
, extern_map
);
8991 extern_map
.dispose ();
8993 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8994 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8995 calc_die_sizes (node
->root_die
);
8997 #if defined (OBJECT_FORMAT_ELF)
8998 if (!dwarf_split_debug_info
)
8999 secname
= ".debug_types";
9001 secname
= ".debug_types.dwo";
9003 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9004 sprintf (tmp
, "wt.");
9005 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9006 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9007 comdat_key
= get_identifier (tmp
);
9008 targetm
.asm_out
.named_section (secname
,
9009 SECTION_DEBUG
| SECTION_LINKONCE
,
9012 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9013 sprintf (tmp
, ".gnu.linkonce.wt.");
9014 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9015 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9017 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9020 /* Output debugging information. */
9021 output_compilation_unit_header ();
9022 output_signature (node
->signature
, "Type Signature");
9023 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9024 "Offset to Type DIE");
9025 output_die (node
->root_die
);
9027 unmark_dies (node
->root_die
);
9029 #if defined (OBJECT_FORMAT_ELF)
9030 if (dwarf_split_debug_info
)
9032 /* Produce the skeleton type-unit header. */
9033 const char *secname
= ".debug_types";
9035 targetm
.asm_out
.named_section (secname
,
9036 SECTION_DEBUG
| SECTION_LINKONCE
,
9038 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9039 dw2_asm_output_data (4, 0xffffffff,
9040 "Initial length escape value indicating 64-bit DWARF extension");
9042 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9043 DWARF_COMPILE_UNIT_HEADER_SIZE
9044 - DWARF_INITIAL_LENGTH_SIZE
9045 + size_of_die (get_skeleton_type_unit ())
9046 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9047 "Length of Type Unit Info");
9048 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9049 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9050 debug_skeleton_abbrev_section_label
,
9051 debug_abbrev_section
,
9052 "Offset Into Abbrev. Section");
9053 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9054 output_signature (node
->signature
, "Type Signature");
9055 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9057 output_die (get_skeleton_type_unit ());
9062 /* Return the DWARF2/3 pubname associated with a decl. */
9065 dwarf2_name (tree decl
, int scope
)
9067 if (DECL_NAMELESS (decl
))
9069 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9072 /* Add a new entry to .debug_pubnames if appropriate. */
9075 add_pubname_string (const char *str
, dw_die_ref die
)
9080 e
.name
= xstrdup (str
);
9081 vec_safe_push (pubname_table
, e
);
9085 add_pubname (tree decl
, dw_die_ref die
)
9087 if (!want_pubnames ())
9090 /* Don't add items to the table when we expect that the consumer will have
9091 just read the enclosing die. For example, if the consumer is looking at a
9092 class_member, it will either be inside the class already, or will have just
9093 looked up the class to find the member. Either way, searching the class is
9094 faster than searching the index. */
9095 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9096 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9098 const char *name
= dwarf2_name (decl
, 1);
9101 add_pubname_string (name
, die
);
9105 /* Add an enumerator to the pubnames section. */
9108 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9112 gcc_assert (scope_name
);
9113 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9115 vec_safe_push (pubname_table
, e
);
9118 /* Add a new entry to .debug_pubtypes if appropriate. */
9121 add_pubtype (tree decl
, dw_die_ref die
)
9125 if (!want_pubnames ())
9128 if ((TREE_PUBLIC (decl
)
9129 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9130 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9133 const char *scope_name
= "";
9134 const char *sep
= is_cxx () ? "::" : ".";
9137 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9138 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9140 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9141 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9142 scope_name
= concat (scope_name
, sep
, NULL
);
9148 name
= type_tag (decl
);
9150 name
= lang_hooks
.dwarf_name (decl
, 1);
9152 /* If we don't have a name for the type, there's no point in adding
9154 if (name
!= NULL
&& name
[0] != '\0')
9157 e
.name
= concat (scope_name
, name
, NULL
);
9158 vec_safe_push (pubtype_table
, e
);
9161 /* Although it might be more consistent to add the pubinfo for the
9162 enumerators as their dies are created, they should only be added if the
9163 enum type meets the criteria above. So rather than re-check the parent
9164 enum type whenever an enumerator die is created, just output them all
9165 here. This isn't protected by the name conditional because anonymous
9166 enums don't have names. */
9167 if (die
->die_tag
== DW_TAG_enumeration_type
)
9171 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9176 /* Output a single entry in the pubnames table. */
9179 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9181 dw_die_ref die
= entry
->die
;
9182 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9184 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9186 if (debug_generate_pub_sections
== 2)
9188 /* This logic follows gdb's method for determining the value of the flag
9190 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9191 switch (die
->die_tag
)
9193 case DW_TAG_typedef
:
9194 case DW_TAG_base_type
:
9195 case DW_TAG_subrange_type
:
9196 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9197 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9199 case DW_TAG_enumerator
:
9200 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9201 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9202 if (!is_cxx () && !is_java ())
9203 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9205 case DW_TAG_subprogram
:
9206 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9207 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9209 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9211 case DW_TAG_constant
:
9212 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9213 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9214 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9216 case DW_TAG_variable
:
9217 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9218 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9219 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9221 case DW_TAG_namespace
:
9222 case DW_TAG_imported_declaration
:
9223 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9225 case DW_TAG_class_type
:
9226 case DW_TAG_interface_type
:
9227 case DW_TAG_structure_type
:
9228 case DW_TAG_union_type
:
9229 case DW_TAG_enumeration_type
:
9230 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9231 if (!is_cxx () && !is_java ())
9232 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9235 /* An unusual tag. Leave the flag-byte empty. */
9238 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9242 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9246 /* Output the public names table used to speed up access to externally
9247 visible names; or the public types table used to find type definitions. */
9250 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9253 unsigned long pubnames_length
= size_of_pubnames (names
);
9256 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9257 dw2_asm_output_data (4, 0xffffffff,
9258 "Initial length escape value indicating 64-bit DWARF extension");
9259 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9261 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9262 dw2_asm_output_data (2, 2, "DWARF Version");
9264 if (dwarf_split_debug_info
)
9265 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9266 debug_skeleton_info_section
,
9267 "Offset of Compilation Unit Info");
9269 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9271 "Offset of Compilation Unit Info");
9272 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9273 "Compilation Unit Length");
9275 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9277 if (include_pubname_in_output (names
, pub
))
9279 dw_offset die_offset
= pub
->die
->die_offset
;
9281 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9282 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9283 gcc_assert (pub
->die
->die_mark
);
9285 /* If we're putting types in their own .debug_types sections,
9286 the .debug_pubtypes table will still point to the compile
9287 unit (not the type unit), so we want to use the offset of
9288 the skeleton DIE (if there is one). */
9289 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9291 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9293 if (type_node
!= NULL
)
9294 die_offset
= (type_node
->skeleton_die
!= NULL
9295 ? type_node
->skeleton_die
->die_offset
9299 output_pubname (die_offset
, pub
);
9303 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9306 /* Output public names and types tables if necessary. */
9309 output_pubtables (void)
9311 if (!want_pubnames () || !info_section_emitted
)
9314 switch_to_section (debug_pubnames_section
);
9315 output_pubnames (pubname_table
);
9316 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9317 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9318 simply won't look for the section. */
9319 switch_to_section (debug_pubtypes_section
);
9320 output_pubnames (pubtype_table
);
9324 /* Output the information that goes into the .debug_aranges table.
9325 Namely, define the beginning and ending address range of the
9326 text section generated for this compilation unit. */
9329 output_aranges (unsigned long aranges_length
)
9333 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9334 dw2_asm_output_data (4, 0xffffffff,
9335 "Initial length escape value indicating 64-bit DWARF extension");
9336 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9337 "Length of Address Ranges Info");
9338 /* Version number for aranges is still 2, even in DWARF3. */
9339 dw2_asm_output_data (2, 2, "DWARF Version");
9340 if (dwarf_split_debug_info
)
9341 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9342 debug_skeleton_info_section
,
9343 "Offset of Compilation Unit Info");
9345 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9347 "Offset of Compilation Unit Info");
9348 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9349 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9351 /* We need to align to twice the pointer size here. */
9352 if (DWARF_ARANGES_PAD_SIZE
)
9354 /* Pad using a 2 byte words so that padding is correct for any
9356 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9357 2 * DWARF2_ADDR_SIZE
);
9358 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9359 dw2_asm_output_data (2, 0, NULL
);
9362 /* It is necessary not to output these entries if the sections were
9363 not used; if the sections were not used, the length will be 0 and
9364 the address may end up as 0 if the section is discarded by ld
9365 --gc-sections, leaving an invalid (0, 0) entry that can be
9366 confused with the terminator. */
9367 if (text_section_used
)
9369 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9370 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9371 text_section_label
, "Length");
9373 if (cold_text_section_used
)
9375 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9377 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9378 cold_text_section_label
, "Length");
9381 if (have_multiple_function_sections
)
9386 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9388 if (DECL_IGNORED_P (fde
->decl
))
9390 if (!fde
->in_std_section
)
9392 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9394 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9395 fde
->dw_fde_begin
, "Length");
9397 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9399 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9401 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9402 fde
->dw_fde_second_begin
, "Length");
9407 /* Output the terminator words. */
9408 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9409 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9412 /* Add a new entry to .debug_ranges. Return the offset at which it
9416 add_ranges_num (int num
)
9418 unsigned int in_use
= ranges_table_in_use
;
9420 if (in_use
== ranges_table_allocated
)
9422 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9423 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9424 ranges_table_allocated
);
9425 memset (ranges_table
+ ranges_table_in_use
, 0,
9426 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9429 ranges_table
[in_use
].num
= num
;
9430 ranges_table_in_use
= in_use
+ 1;
9432 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9435 /* Add a new entry to .debug_ranges corresponding to a block, or a
9436 range terminator if BLOCK is NULL. */
9439 add_ranges (const_tree block
)
9441 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9444 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9445 When using dwarf_split_debug_info, address attributes in dies destined
9446 for the final executable should be direct references--setting the
9447 parameter force_direct ensures this behavior. */
9450 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9451 bool *added
, bool force_direct
)
9453 unsigned int in_use
= ranges_by_label_in_use
;
9454 unsigned int offset
;
9456 if (in_use
== ranges_by_label_allocated
)
9458 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9459 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9461 ranges_by_label_allocated
);
9462 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9463 RANGES_TABLE_INCREMENT
9464 * sizeof (struct dw_ranges_by_label_struct
));
9467 ranges_by_label
[in_use
].begin
= begin
;
9468 ranges_by_label
[in_use
].end
= end
;
9469 ranges_by_label_in_use
= in_use
+ 1;
9471 offset
= add_ranges_num (-(int)in_use
- 1);
9474 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9480 output_ranges (void)
9483 static const char *const start_fmt
= "Offset %#x";
9484 const char *fmt
= start_fmt
;
9486 for (i
= 0; i
< ranges_table_in_use
; i
++)
9488 int block_num
= ranges_table
[i
].num
;
9492 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9493 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9495 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9496 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9498 /* If all code is in the text section, then the compilation
9499 unit base address defaults to DW_AT_low_pc, which is the
9500 base of the text section. */
9501 if (!have_multiple_function_sections
)
9503 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9505 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9506 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9507 text_section_label
, NULL
);
9510 /* Otherwise, the compilation unit base address is zero,
9511 which allows us to use absolute addresses, and not worry
9512 about whether the target supports cross-section
9516 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9517 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9518 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9524 /* Negative block_num stands for an index into ranges_by_label. */
9525 else if (block_num
< 0)
9527 int lab_idx
= - block_num
- 1;
9529 if (!have_multiple_function_sections
)
9533 /* If we ever use add_ranges_by_labels () for a single
9534 function section, all we have to do is to take out
9536 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9537 ranges_by_label
[lab_idx
].begin
,
9539 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9540 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9541 ranges_by_label
[lab_idx
].end
,
9542 text_section_label
, NULL
);
9547 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9548 ranges_by_label
[lab_idx
].begin
,
9549 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9550 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9551 ranges_by_label
[lab_idx
].end
,
9557 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9558 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9564 /* Data structure containing information about input files. */
9567 const char *path
; /* Complete file name. */
9568 const char *fname
; /* File name part. */
9569 int length
; /* Length of entire string. */
9570 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9571 int dir_idx
; /* Index in directory table. */
9574 /* Data structure containing information about directories with source
9578 const char *path
; /* Path including directory name. */
9579 int length
; /* Path length. */
9580 int prefix
; /* Index of directory entry which is a prefix. */
9581 int count
; /* Number of files in this directory. */
9582 int dir_idx
; /* Index of directory used as base. */
9585 /* Callback function for file_info comparison. We sort by looking at
9586 the directories in the path. */
9589 file_info_cmp (const void *p1
, const void *p2
)
9591 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9592 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9593 const unsigned char *cp1
;
9594 const unsigned char *cp2
;
9596 /* Take care of file names without directories. We need to make sure that
9597 we return consistent values to qsort since some will get confused if
9598 we return the same value when identical operands are passed in opposite
9599 orders. So if neither has a directory, return 0 and otherwise return
9600 1 or -1 depending on which one has the directory. */
9601 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9602 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9604 cp1
= (const unsigned char *) s1
->path
;
9605 cp2
= (const unsigned char *) s2
->path
;
9611 /* Reached the end of the first path? If so, handle like above. */
9612 if ((cp1
== (const unsigned char *) s1
->fname
)
9613 || (cp2
== (const unsigned char *) s2
->fname
))
9614 return ((cp2
== (const unsigned char *) s2
->fname
)
9615 - (cp1
== (const unsigned char *) s1
->fname
));
9617 /* Character of current path component the same? */
9618 else if (*cp1
!= *cp2
)
9623 struct file_name_acquire_data
9625 struct file_info
*files
;
9630 /* Traversal function for the hash table. */
9633 file_name_acquire (void ** slot
, void *data
)
9635 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9636 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9637 struct file_info
*fi
;
9640 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9642 if (! d
->emitted_number
)
9645 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9647 fi
= fnad
->files
+ fnad
->used_files
++;
9649 /* Skip all leading "./". */
9651 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9654 /* Create a new array entry. */
9656 fi
->length
= strlen (f
);
9659 /* Search for the file name part. */
9660 f
= strrchr (f
, DIR_SEPARATOR
);
9661 #if defined (DIR_SEPARATOR_2)
9663 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9667 if (f
== NULL
|| f
< g
)
9673 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9677 /* Output the directory table and the file name table. We try to minimize
9678 the total amount of memory needed. A heuristic is used to avoid large
9679 slowdowns with many input files. */
9682 output_file_names (void)
9684 struct file_name_acquire_data fnad
;
9686 struct file_info
*files
;
9687 struct dir_info
*dirs
;
9695 if (!last_emitted_file
)
9697 dw2_asm_output_data (1, 0, "End directory table");
9698 dw2_asm_output_data (1, 0, "End file name table");
9702 numfiles
= last_emitted_file
->emitted_number
;
9704 /* Allocate the various arrays we need. */
9705 files
= XALLOCAVEC (struct file_info
, numfiles
);
9706 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9709 fnad
.used_files
= 0;
9710 fnad
.max_files
= numfiles
;
9711 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9712 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9714 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9716 /* Find all the different directories used. */
9717 dirs
[0].path
= files
[0].path
;
9718 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9719 dirs
[0].prefix
= -1;
9721 dirs
[0].dir_idx
= 0;
9722 files
[0].dir_idx
= 0;
9725 for (i
= 1; i
< numfiles
; i
++)
9726 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9727 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9728 dirs
[ndirs
- 1].length
) == 0)
9730 /* Same directory as last entry. */
9731 files
[i
].dir_idx
= ndirs
- 1;
9732 ++dirs
[ndirs
- 1].count
;
9738 /* This is a new directory. */
9739 dirs
[ndirs
].path
= files
[i
].path
;
9740 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9741 dirs
[ndirs
].count
= 1;
9742 dirs
[ndirs
].dir_idx
= ndirs
;
9743 files
[i
].dir_idx
= ndirs
;
9745 /* Search for a prefix. */
9746 dirs
[ndirs
].prefix
= -1;
9747 for (j
= 0; j
< ndirs
; j
++)
9748 if (dirs
[j
].length
< dirs
[ndirs
].length
9749 && dirs
[j
].length
> 1
9750 && (dirs
[ndirs
].prefix
== -1
9751 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9752 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9753 dirs
[ndirs
].prefix
= j
;
9758 /* Now to the actual work. We have to find a subset of the directories which
9759 allow expressing the file name using references to the directory table
9760 with the least amount of characters. We do not do an exhaustive search
9761 where we would have to check out every combination of every single
9762 possible prefix. Instead we use a heuristic which provides nearly optimal
9763 results in most cases and never is much off. */
9764 saved
= XALLOCAVEC (int, ndirs
);
9765 savehere
= XALLOCAVEC (int, ndirs
);
9767 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9768 for (i
= 0; i
< ndirs
; i
++)
9773 /* We can always save some space for the current directory. But this
9774 does not mean it will be enough to justify adding the directory. */
9775 savehere
[i
] = dirs
[i
].length
;
9776 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9778 for (j
= i
+ 1; j
< ndirs
; j
++)
9781 if (saved
[j
] < dirs
[i
].length
)
9783 /* Determine whether the dirs[i] path is a prefix of the
9788 while (k
!= -1 && k
!= (int) i
)
9793 /* Yes it is. We can possibly save some memory by
9794 writing the filenames in dirs[j] relative to
9796 savehere
[j
] = dirs
[i
].length
;
9797 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9802 /* Check whether we can save enough to justify adding the dirs[i]
9804 if (total
> dirs
[i
].length
+ 1)
9806 /* It's worthwhile adding. */
9807 for (j
= i
; j
< ndirs
; j
++)
9808 if (savehere
[j
] > 0)
9810 /* Remember how much we saved for this directory so far. */
9811 saved
[j
] = savehere
[j
];
9813 /* Remember the prefix directory. */
9814 dirs
[j
].dir_idx
= i
;
9819 /* Emit the directory name table. */
9820 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9821 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9822 dw2_asm_output_nstring (dirs
[i
].path
,
9824 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9825 "Directory Entry: %#x", i
+ idx_offset
);
9827 dw2_asm_output_data (1, 0, "End directory table");
9829 /* We have to emit them in the order of emitted_number since that's
9830 used in the debug info generation. To do this efficiently we
9831 generate a back-mapping of the indices first. */
9832 backmap
= XALLOCAVEC (int, numfiles
);
9833 for (i
= 0; i
< numfiles
; i
++)
9834 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9836 /* Now write all the file names. */
9837 for (i
= 0; i
< numfiles
; i
++)
9839 int file_idx
= backmap
[i
];
9840 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9842 #ifdef VMS_DEBUGGING_INFO
9843 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9845 /* Setting these fields can lead to debugger miscomparisons,
9846 but VMS Debug requires them to be set correctly. */
9851 int maxfilelen
= strlen (files
[file_idx
].path
)
9852 + dirs
[dir_idx
].length
9853 + MAX_VMS_VERSION_LEN
+ 1;
9854 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9856 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9857 snprintf (filebuf
, maxfilelen
, "%s;%d",
9858 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9860 dw2_asm_output_nstring
9861 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9863 /* Include directory index. */
9864 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9866 /* Modification time. */
9867 dw2_asm_output_data_uleb128
9868 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9872 /* File length in bytes. */
9873 dw2_asm_output_data_uleb128
9874 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9878 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9879 "File Entry: %#x", (unsigned) i
+ 1);
9881 /* Include directory index. */
9882 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9884 /* Modification time. */
9885 dw2_asm_output_data_uleb128 (0, NULL
);
9887 /* File length in bytes. */
9888 dw2_asm_output_data_uleb128 (0, NULL
);
9889 #endif /* VMS_DEBUGGING_INFO */
9892 dw2_asm_output_data (1, 0, "End file name table");
9896 /* Output one line number table into the .debug_line section. */
9899 output_one_line_info_table (dw_line_info_table
*table
)
9901 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9902 unsigned int current_line
= 1;
9903 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9904 dw_line_info_entry
*ent
;
9907 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9909 switch (ent
->opcode
)
9911 case LI_set_address
:
9912 /* ??? Unfortunately, we have little choice here currently, and
9913 must always use the most general form. GCC does not know the
9914 address delta itself, so we can't use DW_LNS_advance_pc. Many
9915 ports do have length attributes which will give an upper bound
9916 on the address range. We could perhaps use length attributes
9917 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9918 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9920 /* This can handle any delta. This takes
9921 4+DWARF2_ADDR_SIZE bytes. */
9922 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9923 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9924 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9925 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9929 if (ent
->val
== current_line
)
9931 /* We still need to start a new row, so output a copy insn. */
9932 dw2_asm_output_data (1, DW_LNS_copy
,
9933 "copy line %u", current_line
);
9937 int line_offset
= ent
->val
- current_line
;
9938 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9940 current_line
= ent
->val
;
9941 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9943 /* This can handle deltas from -10 to 234, using the current
9944 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9945 This takes 1 byte. */
9946 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9947 "line %u", current_line
);
9951 /* This can handle any delta. This takes at least 4 bytes,
9952 depending on the value being encoded. */
9953 dw2_asm_output_data (1, DW_LNS_advance_line
,
9954 "advance to line %u", current_line
);
9955 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9956 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9962 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9963 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9967 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9968 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9971 case LI_negate_stmt
:
9972 current_is_stmt
= !current_is_stmt
;
9973 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9974 "is_stmt %d", current_is_stmt
);
9977 case LI_set_prologue_end
:
9978 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9979 "set prologue end");
9982 case LI_set_epilogue_begin
:
9983 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9984 "set epilogue begin");
9987 case LI_set_discriminator
:
9988 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9989 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9990 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9991 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9996 /* Emit debug info for the address of the end of the table. */
9997 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9998 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9999 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10000 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10002 dw2_asm_output_data (1, 0, "end sequence");
10003 dw2_asm_output_data_uleb128 (1, NULL
);
10004 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10007 /* Output the source line number correspondence information. This
10008 information goes into the .debug_line section. */
10011 output_line_info (bool prologue_only
)
10013 char l1
[20], l2
[20], p1
[20], p2
[20];
10014 int ver
= dwarf_version
;
10015 bool saw_one
= false;
10018 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10019 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10020 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10021 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10023 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10024 dw2_asm_output_data (4, 0xffffffff,
10025 "Initial length escape value indicating 64-bit DWARF extension");
10026 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10027 "Length of Source Line Info");
10028 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10030 dw2_asm_output_data (2, ver
, "DWARF Version");
10031 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10032 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10034 /* Define the architecture-dependent minimum instruction length (in bytes).
10035 In this implementation of DWARF, this field is used for information
10036 purposes only. Since GCC generates assembly language, we have no
10037 a priori knowledge of how many instruction bytes are generated for each
10038 source line, and therefore can use only the DW_LNE_set_address and
10039 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10040 this as '1', which is "correct enough" for all architectures,
10041 and don't let the target override. */
10042 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10045 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10046 "Maximum Operations Per Instruction");
10047 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10048 "Default is_stmt_start flag");
10049 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10050 "Line Base Value (Special Opcodes)");
10051 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10052 "Line Range Value (Special Opcodes)");
10053 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10054 "Special Opcode Base");
10056 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10061 case DW_LNS_advance_pc
:
10062 case DW_LNS_advance_line
:
10063 case DW_LNS_set_file
:
10064 case DW_LNS_set_column
:
10065 case DW_LNS_fixed_advance_pc
:
10066 case DW_LNS_set_isa
:
10074 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10078 /* Write out the information about the files we use. */
10079 output_file_names ();
10080 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10083 /* Output the marker for the end of the line number info. */
10084 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10088 if (separate_line_info
)
10090 dw_line_info_table
*table
;
10093 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10096 output_one_line_info_table (table
);
10100 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10102 output_one_line_info_table (cold_text_section_line_info
);
10106 /* ??? Some Darwin linkers crash on a .debug_line section with no
10107 sequences. Further, merely a DW_LNE_end_sequence entry is not
10108 sufficient -- the address column must also be initialized.
10109 Make sure to output at least one set_address/end_sequence pair,
10110 choosing .text since that section is always present. */
10111 if (text_section_line_info
->in_use
|| !saw_one
)
10112 output_one_line_info_table (text_section_line_info
);
10114 /* Output the marker for the end of the line number info. */
10115 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10118 /* Given a pointer to a tree node for some base type, return a pointer to
10119 a DIE that describes the given type.
10121 This routine must only be called for GCC type nodes that correspond to
10122 Dwarf base (fundamental) types. */
10125 base_type_die (tree type
)
10127 dw_die_ref base_type_result
;
10128 enum dwarf_type encoding
;
10130 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10133 /* If this is a subtype that should not be emitted as a subrange type,
10134 use the base type. See subrange_type_for_debug_p. */
10135 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10136 type
= TREE_TYPE (type
);
10138 switch (TREE_CODE (type
))
10141 if ((dwarf_version
>= 4 || !dwarf_strict
)
10142 && TYPE_NAME (type
)
10143 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10144 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10145 && DECL_NAME (TYPE_NAME (type
)))
10147 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10148 if (strcmp (name
, "char16_t") == 0
10149 || strcmp (name
, "char32_t") == 0)
10151 encoding
= DW_ATE_UTF
;
10155 if (TYPE_STRING_FLAG (type
))
10157 if (TYPE_UNSIGNED (type
))
10158 encoding
= DW_ATE_unsigned_char
;
10160 encoding
= DW_ATE_signed_char
;
10162 else if (TYPE_UNSIGNED (type
))
10163 encoding
= DW_ATE_unsigned
;
10165 encoding
= DW_ATE_signed
;
10169 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10171 if (dwarf_version
>= 3 || !dwarf_strict
)
10172 encoding
= DW_ATE_decimal_float
;
10174 encoding
= DW_ATE_lo_user
;
10177 encoding
= DW_ATE_float
;
10180 case FIXED_POINT_TYPE
:
10181 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10182 encoding
= DW_ATE_lo_user
;
10183 else if (TYPE_UNSIGNED (type
))
10184 encoding
= DW_ATE_unsigned_fixed
;
10186 encoding
= DW_ATE_signed_fixed
;
10189 /* Dwarf2 doesn't know anything about complex ints, so use
10190 a user defined type for it. */
10192 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10193 encoding
= DW_ATE_complex_float
;
10195 encoding
= DW_ATE_lo_user
;
10199 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10200 encoding
= DW_ATE_boolean
;
10204 /* No other TREE_CODEs are Dwarf fundamental types. */
10205 gcc_unreachable ();
10208 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10210 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10211 int_size_in_bytes (type
));
10212 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10213 add_pubtype (type
, base_type_result
);
10215 return base_type_result
;
10218 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10219 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10222 is_base_type (tree type
)
10224 switch (TREE_CODE (type
))
10230 case FIXED_POINT_TYPE
:
10238 case QUAL_UNION_TYPE
:
10239 case ENUMERAL_TYPE
:
10240 case FUNCTION_TYPE
:
10243 case REFERENCE_TYPE
:
10251 gcc_unreachable ();
10257 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10258 node, return the size in bits for the type if it is a constant, or else
10259 return the alignment for the type if the type's size is not constant, or
10260 else return BITS_PER_WORD if the type actually turns out to be an
10261 ERROR_MARK node. */
10263 static inline unsigned HOST_WIDE_INT
10264 simple_type_size_in_bits (const_tree type
)
10266 if (TREE_CODE (type
) == ERROR_MARK
)
10267 return BITS_PER_WORD
;
10268 else if (TYPE_SIZE (type
) == NULL_TREE
)
10270 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10271 return tree_to_uhwi (TYPE_SIZE (type
));
10273 return TYPE_ALIGN (type
);
10276 /* Similarly, but return a double_int instead of UHWI. */
10278 static inline double_int
10279 double_int_type_size_in_bits (const_tree type
)
10281 if (TREE_CODE (type
) == ERROR_MARK
)
10282 return double_int::from_uhwi (BITS_PER_WORD
);
10283 else if (TYPE_SIZE (type
) == NULL_TREE
)
10284 return double_int_zero
;
10285 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10286 return tree_to_double_int (TYPE_SIZE (type
));
10288 return double_int::from_uhwi (TYPE_ALIGN (type
));
10291 /* Given a pointer to a tree node for a subrange type, return a pointer
10292 to a DIE that describes the given type. */
10295 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10297 dw_die_ref subrange_die
;
10298 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10300 if (context_die
== NULL
)
10301 context_die
= comp_unit_die ();
10303 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10305 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10307 /* The size of the subrange type and its base type do not match,
10308 so we need to generate a size attribute for the subrange type. */
10309 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10313 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10315 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10317 return subrange_die
;
10320 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10321 entry that chains various modifiers in front of the given type. */
10324 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10325 dw_die_ref context_die
)
10327 enum tree_code code
= TREE_CODE (type
);
10328 dw_die_ref mod_type_die
;
10329 dw_die_ref sub_die
= NULL
;
10330 tree item_type
= NULL
;
10331 tree qualified_type
;
10332 tree name
, low
, high
;
10333 dw_die_ref mod_scope
;
10335 if (code
== ERROR_MARK
)
10338 /* See if we already have the appropriately qualified variant of
10341 = get_qualified_type (type
,
10342 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10343 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10345 if (qualified_type
== sizetype
10346 && TYPE_NAME (qualified_type
)
10347 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10349 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10351 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10352 && TYPE_PRECISION (t
)
10353 == TYPE_PRECISION (qualified_type
)
10354 && TYPE_UNSIGNED (t
)
10355 == TYPE_UNSIGNED (qualified_type
));
10356 qualified_type
= t
;
10359 /* If we do, then we can just use its DIE, if it exists. */
10360 if (qualified_type
)
10362 mod_type_die
= lookup_type_die (qualified_type
);
10364 return mod_type_die
;
10367 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10369 /* Handle C typedef types. */
10370 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10371 && !DECL_ARTIFICIAL (name
))
10373 tree dtype
= TREE_TYPE (name
);
10375 if (qualified_type
== dtype
)
10377 /* For a named type, use the typedef. */
10378 gen_type_die (qualified_type
, context_die
);
10379 return lookup_type_die (qualified_type
);
10381 else if (is_const_type
< TYPE_READONLY (dtype
)
10382 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10383 || (is_const_type
<= TYPE_READONLY (dtype
)
10384 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10385 && DECL_ORIGINAL_TYPE (name
) != type
))
10386 /* cv-unqualified version of named type. Just use the unnamed
10387 type to which it refers. */
10388 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10389 is_const_type
, is_volatile_type
,
10391 /* Else cv-qualified version of named type; fall through. */
10394 mod_scope
= scope_die_for (type
, context_die
);
10397 /* If both is_const_type and is_volatile_type, prefer the path
10398 which leads to a qualified type. */
10399 && (!is_volatile_type
10400 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10401 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10403 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10404 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10406 else if (is_volatile_type
)
10408 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10409 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10411 else if (code
== POINTER_TYPE
)
10413 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10414 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10415 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10416 item_type
= TREE_TYPE (type
);
10417 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10418 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10419 TYPE_ADDR_SPACE (item_type
));
10421 else if (code
== REFERENCE_TYPE
)
10423 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10424 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10427 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10428 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10429 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10430 item_type
= TREE_TYPE (type
);
10431 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10432 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10433 TYPE_ADDR_SPACE (item_type
));
10435 else if (code
== INTEGER_TYPE
10436 && TREE_TYPE (type
) != NULL_TREE
10437 && subrange_type_for_debug_p (type
, &low
, &high
))
10439 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10440 item_type
= TREE_TYPE (type
);
10442 else if (is_base_type (type
))
10443 mod_type_die
= base_type_die (type
);
10446 gen_type_die (type
, context_die
);
10448 /* We have to get the type_main_variant here (and pass that to the
10449 `lookup_type_die' routine) because the ..._TYPE node we have
10450 might simply be a *copy* of some original type node (where the
10451 copy was created to help us keep track of typedef names) and
10452 that copy might have a different TYPE_UID from the original
10454 if (TREE_CODE (type
) != VECTOR_TYPE
)
10455 return lookup_type_die (type_main_variant (type
));
10457 /* Vectors have the debugging information in the type,
10458 not the main variant. */
10459 return lookup_type_die (type
);
10462 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10463 don't output a DW_TAG_typedef, since there isn't one in the
10464 user's program; just attach a DW_AT_name to the type.
10465 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10466 if the base type already has the same name. */
10468 && ((TREE_CODE (name
) != TYPE_DECL
10469 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10470 || (!is_const_type
&& !is_volatile_type
)))
10471 || (TREE_CODE (name
) == TYPE_DECL
10472 && TREE_TYPE (name
) == qualified_type
10473 && DECL_NAME (name
))))
10475 if (TREE_CODE (name
) == TYPE_DECL
)
10476 /* Could just call add_name_and_src_coords_attributes here,
10477 but since this is a builtin type it doesn't have any
10478 useful source coordinates anyway. */
10479 name
= DECL_NAME (name
);
10480 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10482 /* This probably indicates a bug. */
10483 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10485 name
= TYPE_NAME (type
);
10487 && TREE_CODE (name
) == TYPE_DECL
)
10488 name
= DECL_NAME (name
);
10489 add_name_attribute (mod_type_die
,
10490 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10493 if (qualified_type
)
10494 equate_type_number_to_die (qualified_type
, mod_type_die
);
10497 /* We must do this after the equate_type_number_to_die call, in case
10498 this is a recursive type. This ensures that the modified_type_die
10499 recursion will terminate even if the type is recursive. Recursive
10500 types are possible in Ada. */
10501 sub_die
= modified_type_die (item_type
,
10502 TYPE_READONLY (item_type
),
10503 TYPE_VOLATILE (item_type
),
10506 if (sub_die
!= NULL
)
10507 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10509 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10510 if (TYPE_ARTIFICIAL (type
))
10511 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10513 return mod_type_die
;
10516 /* Generate DIEs for the generic parameters of T.
10517 T must be either a generic type or a generic function.
10518 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10521 gen_generic_params_dies (tree t
)
10525 dw_die_ref die
= NULL
;
10528 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10532 die
= lookup_type_die (t
);
10533 else if (DECL_P (t
))
10534 die
= lookup_decl_die (t
);
10538 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10540 /* T has no generic parameter. It means T is neither a generic type
10541 or function. End of story. */
10544 parms_num
= TREE_VEC_LENGTH (parms
);
10545 args
= lang_hooks
.get_innermost_generic_args (t
);
10546 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10547 non_default
= int_cst_value (TREE_CHAIN (args
));
10549 non_default
= TREE_VEC_LENGTH (args
);
10550 for (i
= 0; i
< parms_num
; i
++)
10552 tree parm
, arg
, arg_pack_elems
;
10553 dw_die_ref parm_die
;
10555 parm
= TREE_VEC_ELT (parms
, i
);
10556 arg
= TREE_VEC_ELT (args
, i
);
10557 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10558 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10560 if (parm
&& TREE_VALUE (parm
) && arg
)
10562 /* If PARM represents a template parameter pack,
10563 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10564 by DW_TAG_template_*_parameter DIEs for the argument
10565 pack elements of ARG. Note that ARG would then be
10566 an argument pack. */
10567 if (arg_pack_elems
)
10568 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10572 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10573 true /* emit name */, die
);
10574 if (i
>= non_default
)
10575 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10580 /* Create and return a DIE for PARM which should be
10581 the representation of a generic type parameter.
10582 For instance, in the C++ front end, PARM would be a template parameter.
10583 ARG is the argument to PARM.
10584 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10586 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10587 as a child node. */
10590 generic_parameter_die (tree parm
, tree arg
,
10592 dw_die_ref parent_die
)
10594 dw_die_ref tmpl_die
= NULL
;
10595 const char *name
= NULL
;
10597 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10600 /* We support non-type generic parameters and arguments,
10601 type generic parameters and arguments, as well as
10602 generic generic parameters (a.k.a. template template parameters in C++)
10604 if (TREE_CODE (parm
) == PARM_DECL
)
10605 /* PARM is a nontype generic parameter */
10606 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10607 else if (TREE_CODE (parm
) == TYPE_DECL
)
10608 /* PARM is a type generic parameter. */
10609 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10610 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10611 /* PARM is a generic generic parameter.
10612 Its DIE is a GNU extension. It shall have a
10613 DW_AT_name attribute to represent the name of the template template
10614 parameter, and a DW_AT_GNU_template_name attribute to represent the
10615 name of the template template argument. */
10616 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10619 gcc_unreachable ();
10625 /* If PARM is a generic parameter pack, it means we are
10626 emitting debug info for a template argument pack element.
10627 In other terms, ARG is a template argument pack element.
10628 In that case, we don't emit any DW_AT_name attribute for
10632 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10634 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10637 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10639 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10640 TMPL_DIE should have a child DW_AT_type attribute that is set
10641 to the type of the argument to PARM, which is ARG.
10642 If PARM is a type generic parameter, TMPL_DIE should have a
10643 child DW_AT_type that is set to ARG. */
10644 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10645 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10646 TREE_THIS_VOLATILE (tmpl_type
),
10651 /* So TMPL_DIE is a DIE representing a
10652 a generic generic template parameter, a.k.a template template
10653 parameter in C++ and arg is a template. */
10655 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10656 to the name of the argument. */
10657 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10659 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10662 if (TREE_CODE (parm
) == PARM_DECL
)
10663 /* So PARM is a non-type generic parameter.
10664 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10665 attribute of TMPL_DIE which value represents the value
10667 We must be careful here:
10668 The value of ARG might reference some function decls.
10669 We might currently be emitting debug info for a generic
10670 type and types are emitted before function decls, we don't
10671 know if the function decls referenced by ARG will actually be
10672 emitted after cgraph computations.
10673 So must defer the generation of the DW_AT_const_value to
10674 after cgraph is ready. */
10675 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10681 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10682 PARM_PACK must be a template parameter pack. The returned DIE
10683 will be child DIE of PARENT_DIE. */
10686 template_parameter_pack_die (tree parm_pack
,
10687 tree parm_pack_args
,
10688 dw_die_ref parent_die
)
10693 gcc_assert (parent_die
&& parm_pack
);
10695 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10696 add_name_and_src_coords_attributes (die
, parm_pack
);
10697 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10698 generic_parameter_die (parm_pack
,
10699 TREE_VEC_ELT (parm_pack_args
, j
),
10700 false /* Don't emit DW_AT_name */,
10705 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10706 an enumerated type. */
10709 type_is_enum (const_tree type
)
10711 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10714 /* Return the DBX register number described by a given RTL node. */
10716 static unsigned int
10717 dbx_reg_number (const_rtx rtl
)
10719 unsigned regno
= REGNO (rtl
);
10721 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10723 #ifdef LEAF_REG_REMAP
10724 if (crtl
->uses_only_leaf_regs
)
10726 int leaf_reg
= LEAF_REG_REMAP (regno
);
10727 if (leaf_reg
!= -1)
10728 regno
= (unsigned) leaf_reg
;
10732 regno
= DBX_REGISTER_NUMBER (regno
);
10733 gcc_assert (regno
!= INVALID_REGNUM
);
10737 /* Optionally add a DW_OP_piece term to a location description expression.
10738 DW_OP_piece is only added if the location description expression already
10739 doesn't end with DW_OP_piece. */
10742 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10744 dw_loc_descr_ref loc
;
10746 if (*list_head
!= NULL
)
10748 /* Find the end of the chain. */
10749 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10752 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10753 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10757 /* Return a location descriptor that designates a machine register or
10758 zero if there is none. */
10760 static dw_loc_descr_ref
10761 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10765 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10768 /* We only use "frame base" when we're sure we're talking about the
10769 post-prologue local stack frame. We do this by *not* running
10770 register elimination until this point, and recognizing the special
10771 argument pointer and soft frame pointer rtx's.
10772 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10773 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10774 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10776 dw_loc_descr_ref result
= NULL
;
10778 if (dwarf_version
>= 4 || !dwarf_strict
)
10780 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10783 add_loc_descr (&result
,
10784 new_loc_descr (DW_OP_stack_value
, 0, 0));
10789 regs
= targetm
.dwarf_register_span (rtl
);
10791 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10792 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10795 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10796 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10798 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10802 /* Return a location descriptor that designates a machine register for
10803 a given hard register number. */
10805 static dw_loc_descr_ref
10806 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10808 dw_loc_descr_ref reg_loc_descr
;
10812 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10814 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10816 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10817 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10819 return reg_loc_descr
;
10822 /* Given an RTL of a register, return a location descriptor that
10823 designates a value that spans more than one register. */
10825 static dw_loc_descr_ref
10826 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10827 enum var_init_status initialized
)
10830 dw_loc_descr_ref loc_result
= NULL
;
10832 /* Simple, contiguous registers. */
10833 if (regs
== NULL_RTX
)
10835 unsigned reg
= REGNO (rtl
);
10838 #ifdef LEAF_REG_REMAP
10839 if (crtl
->uses_only_leaf_regs
)
10841 int leaf_reg
= LEAF_REG_REMAP (reg
);
10842 if (leaf_reg
!= -1)
10843 reg
= (unsigned) leaf_reg
;
10847 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10848 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10850 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10855 dw_loc_descr_ref t
;
10857 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10858 VAR_INIT_STATUS_INITIALIZED
);
10859 add_loc_descr (&loc_result
, t
);
10860 add_loc_descr_op_piece (&loc_result
, size
);
10866 /* Now onto stupid register sets in non contiguous locations. */
10868 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10870 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10873 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10875 dw_loc_descr_ref t
;
10877 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
10878 VAR_INIT_STATUS_INITIALIZED
);
10879 add_loc_descr (&loc_result
, t
);
10880 add_loc_descr_op_piece (&loc_result
, size
);
10883 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10884 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10888 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10890 /* Return a location descriptor that designates a constant i,
10891 as a compound operation from constant (i >> shift), constant shift
10894 static dw_loc_descr_ref
10895 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10897 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10898 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10899 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10903 /* Return a location descriptor that designates a constant. */
10905 static dw_loc_descr_ref
10906 int_loc_descriptor (HOST_WIDE_INT i
)
10908 enum dwarf_location_atom op
;
10910 /* Pick the smallest representation of a constant, rather than just
10911 defaulting to the LEB encoding. */
10914 int clz
= clz_hwi (i
);
10915 int ctz
= ctz_hwi (i
);
10917 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10918 else if (i
<= 0xff)
10919 op
= DW_OP_const1u
;
10920 else if (i
<= 0xffff)
10921 op
= DW_OP_const2u
;
10922 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10923 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10924 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10925 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10926 while DW_OP_const4u is 5 bytes. */
10927 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10928 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10929 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10930 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10931 while DW_OP_const4u is 5 bytes. */
10932 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10933 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10934 op
= DW_OP_const4u
;
10935 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10936 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10937 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10938 while DW_OP_constu of constant >= 0x100000000 takes at least
10940 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10941 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10942 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10943 >= HOST_BITS_PER_WIDE_INT
)
10944 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10945 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10946 while DW_OP_constu takes in this case at least 6 bytes. */
10947 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10948 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10949 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10950 && size_of_uleb128 (i
) > 6)
10951 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10952 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10959 op
= DW_OP_const1s
;
10960 else if (i
>= -0x8000)
10961 op
= DW_OP_const2s
;
10962 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10964 if (size_of_int_loc_descriptor (i
) < 5)
10966 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10967 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10970 op
= DW_OP_const4s
;
10974 if (size_of_int_loc_descriptor (i
)
10975 < (unsigned long) 1 + size_of_sleb128 (i
))
10977 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10978 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10985 return new_loc_descr (op
, i
, 0);
10988 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10989 without actually allocating it. */
10991 static unsigned long
10992 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10994 return size_of_int_loc_descriptor (i
>> shift
)
10995 + size_of_int_loc_descriptor (shift
)
10999 /* Return size_of_locs (int_loc_descriptor (i)) without
11000 actually allocating it. */
11002 static unsigned long
11003 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11012 else if (i
<= 0xff)
11014 else if (i
<= 0xffff)
11018 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11019 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11020 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11022 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11023 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11024 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11026 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11028 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11029 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11030 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11031 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11033 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11034 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11035 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11037 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11038 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11040 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11049 else if (i
>= -0x8000)
11051 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11053 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11055 s
= size_of_int_loc_descriptor (-i
) + 1;
11063 unsigned long r
= 1 + size_of_sleb128 (i
);
11064 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11066 s
= size_of_int_loc_descriptor (-i
) + 1;
11075 /* Return loc description representing "address" of integer value.
11076 This can appear only as toplevel expression. */
11078 static dw_loc_descr_ref
11079 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11082 dw_loc_descr_ref loc_result
= NULL
;
11084 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11087 litsize
= size_of_int_loc_descriptor (i
);
11088 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11089 is more compact. For DW_OP_stack_value we need:
11090 litsize + 1 (DW_OP_stack_value)
11091 and for DW_OP_implicit_value:
11092 1 (DW_OP_implicit_value) + 1 (length) + size. */
11093 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11095 loc_result
= int_loc_descriptor (i
);
11096 add_loc_descr (&loc_result
,
11097 new_loc_descr (DW_OP_stack_value
, 0, 0));
11101 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11103 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11104 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11108 /* Return a location descriptor that designates a base+offset location. */
11110 static dw_loc_descr_ref
11111 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11112 enum var_init_status initialized
)
11114 unsigned int regno
;
11115 dw_loc_descr_ref result
;
11116 dw_fde_ref fde
= cfun
->fde
;
11118 /* We only use "frame base" when we're sure we're talking about the
11119 post-prologue local stack frame. We do this by *not* running
11120 register elimination until this point, and recognizing the special
11121 argument pointer and soft frame pointer rtx's. */
11122 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11124 rtx elim
= (ira_use_lra_p
11125 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11126 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11130 if (GET_CODE (elim
) == PLUS
)
11132 offset
+= INTVAL (XEXP (elim
, 1));
11133 elim
= XEXP (elim
, 0);
11135 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11136 && (elim
== hard_frame_pointer_rtx
11137 || elim
== stack_pointer_rtx
))
11138 || elim
== (frame_pointer_needed
11139 ? hard_frame_pointer_rtx
11140 : stack_pointer_rtx
));
11142 /* If drap register is used to align stack, use frame
11143 pointer + offset to access stack variables. If stack
11144 is aligned without drap, use stack pointer + offset to
11145 access stack variables. */
11146 if (crtl
->stack_realign_tried
11147 && reg
== frame_pointer_rtx
)
11150 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11151 ? HARD_FRAME_POINTER_REGNUM
11153 return new_reg_loc_descr (base_reg
, offset
);
11156 gcc_assert (frame_pointer_fb_offset_valid
);
11157 offset
+= frame_pointer_fb_offset
;
11158 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11162 regno
= REGNO (reg
);
11163 #ifdef LEAF_REG_REMAP
11164 if (crtl
->uses_only_leaf_regs
)
11166 int leaf_reg
= LEAF_REG_REMAP (regno
);
11167 if (leaf_reg
!= -1)
11168 regno
= (unsigned) leaf_reg
;
11171 regno
= DWARF_FRAME_REGNUM (regno
);
11173 if (!optimize
&& fde
11174 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11176 /* Use cfa+offset to represent the location of arguments passed
11177 on the stack when drap is used to align stack.
11178 Only do this when not optimizing, for optimized code var-tracking
11179 is supposed to track where the arguments live and the register
11180 used as vdrap or drap in some spot might be used for something
11181 else in other part of the routine. */
11182 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11186 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11189 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11191 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11192 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11197 /* Return true if this RTL expression describes a base+offset calculation. */
11200 is_based_loc (const_rtx rtl
)
11202 return (GET_CODE (rtl
) == PLUS
11203 && ((REG_P (XEXP (rtl
, 0))
11204 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11205 && CONST_INT_P (XEXP (rtl
, 1)))));
11208 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11211 static dw_loc_descr_ref
11212 tls_mem_loc_descriptor (rtx mem
)
11215 dw_loc_descr_ref loc_result
;
11217 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11220 base
= get_base_address (MEM_EXPR (mem
));
11222 || TREE_CODE (base
) != VAR_DECL
11223 || !DECL_THREAD_LOCAL_P (base
))
11226 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11227 if (loc_result
== NULL
)
11230 if (MEM_OFFSET (mem
))
11231 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11236 /* Output debug info about reason why we failed to expand expression as dwarf
11240 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11242 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11244 fprintf (dump_file
, "Failed to expand as dwarf: ");
11246 print_generic_expr (dump_file
, expr
, dump_flags
);
11249 fprintf (dump_file
, "\n");
11250 print_rtl (dump_file
, rtl
);
11252 fprintf (dump_file
, "\nReason: %s\n", reason
);
11256 /* Helper function for const_ok_for_output, called either directly
11257 or via for_each_rtx. */
11260 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11264 if (GET_CODE (rtl
) == UNSPEC
)
11266 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11267 we can't express it in the debug info. */
11268 #ifdef ENABLE_CHECKING
11269 /* Don't complain about TLS UNSPECs, those are just too hard to
11270 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11271 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11272 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11273 if (XVECLEN (rtl
, 0) == 0
11274 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11275 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11276 inform (current_function_decl
11277 ? DECL_SOURCE_LOCATION (current_function_decl
)
11278 : UNKNOWN_LOCATION
,
11279 #if NUM_UNSPEC_VALUES > 0
11280 "non-delegitimized UNSPEC %s (%d) found in variable location",
11281 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11282 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11285 "non-delegitimized UNSPEC %d found in variable location",
11289 expansion_failed (NULL_TREE
, rtl
,
11290 "UNSPEC hasn't been delegitimized.\n");
11294 if (targetm
.const_not_ok_for_debug_p (rtl
))
11296 expansion_failed (NULL_TREE
, rtl
,
11297 "Expression rejected for debug by the backend.\n");
11301 if (GET_CODE (rtl
) != SYMBOL_REF
)
11304 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11307 get_pool_constant_mark (rtl
, &marked
);
11308 /* If all references to this pool constant were optimized away,
11309 it was not output and thus we can't represent it. */
11312 expansion_failed (NULL_TREE
, rtl
,
11313 "Constant was removed from constant pool.\n");
11318 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11321 /* Avoid references to external symbols in debug info, on several targets
11322 the linker might even refuse to link when linking a shared library,
11323 and in many other cases the relocations for .debug_info/.debug_loc are
11324 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11325 to be defined within the same shared library or executable are fine. */
11326 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11328 tree decl
= SYMBOL_REF_DECL (rtl
);
11330 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11332 expansion_failed (NULL_TREE
, rtl
,
11333 "Symbol not defined in current TU.\n");
11341 /* Return true if constant RTL can be emitted in DW_OP_addr or
11342 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11343 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11346 const_ok_for_output (rtx rtl
)
11348 if (GET_CODE (rtl
) == SYMBOL_REF
)
11349 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11351 if (GET_CODE (rtl
) == CONST
)
11352 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11357 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11358 if possible, NULL otherwise. */
11361 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11363 dw_die_ref type_die
;
11364 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11368 switch (TREE_CODE (type
))
11376 type_die
= lookup_type_die (type
);
11378 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11379 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11384 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11385 type matching MODE, or, if MODE is narrower than or as wide as
11386 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11389 static dw_loc_descr_ref
11390 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11392 enum machine_mode outer_mode
= mode
;
11393 dw_die_ref type_die
;
11394 dw_loc_descr_ref cvt
;
11396 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11398 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11401 type_die
= base_type_for_mode (outer_mode
, 1);
11402 if (type_die
== NULL
)
11404 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11405 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11406 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11407 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11408 add_loc_descr (&op
, cvt
);
11412 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11414 static dw_loc_descr_ref
11415 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11416 dw_loc_descr_ref op1
)
11418 dw_loc_descr_ref ret
= op0
;
11419 add_loc_descr (&ret
, op1
);
11420 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11421 if (STORE_FLAG_VALUE
!= 1)
11423 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11424 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11429 /* Return location descriptor for signed comparison OP RTL. */
11431 static dw_loc_descr_ref
11432 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11433 enum machine_mode mem_mode
)
11435 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11436 dw_loc_descr_ref op0
, op1
;
11439 if (op_mode
== VOIDmode
)
11440 op_mode
= GET_MODE (XEXP (rtl
, 1));
11441 if (op_mode
== VOIDmode
)
11445 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11446 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11449 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11450 VAR_INIT_STATUS_INITIALIZED
);
11451 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11452 VAR_INIT_STATUS_INITIALIZED
);
11454 if (op0
== NULL
|| op1
== NULL
)
11457 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11458 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11459 return compare_loc_descriptor (op
, op0
, op1
);
11461 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11463 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11464 dw_loc_descr_ref cvt
;
11466 if (type_die
== NULL
)
11468 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11469 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11470 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11471 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11472 add_loc_descr (&op0
, cvt
);
11473 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11474 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11475 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11476 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11477 add_loc_descr (&op1
, cvt
);
11478 return compare_loc_descriptor (op
, op0
, op1
);
11481 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11482 /* For eq/ne, if the operands are known to be zero-extended,
11483 there is no need to do the fancy shifting up. */
11484 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11486 dw_loc_descr_ref last0
, last1
;
11487 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11489 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11491 /* deref_size zero extends, and for constants we can check
11492 whether they are zero extended or not. */
11493 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11494 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11495 || (CONST_INT_P (XEXP (rtl
, 0))
11496 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11497 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11498 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11499 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11500 || (CONST_INT_P (XEXP (rtl
, 1))
11501 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11502 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11503 return compare_loc_descriptor (op
, op0
, op1
);
11505 /* EQ/NE comparison against constant in narrower type than
11506 DWARF2_ADDR_SIZE can be performed either as
11507 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11510 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11511 DW_OP_{eq,ne}. Pick whatever is shorter. */
11512 if (CONST_INT_P (XEXP (rtl
, 1))
11513 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11514 && (size_of_int_loc_descriptor (shift
) + 1
11515 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11516 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11517 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11518 & GET_MODE_MASK (op_mode
))))
11520 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11521 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11522 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11523 & GET_MODE_MASK (op_mode
));
11524 return compare_loc_descriptor (op
, op0
, op1
);
11527 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11528 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11529 if (CONST_INT_P (XEXP (rtl
, 1)))
11530 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11533 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11534 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11536 return compare_loc_descriptor (op
, op0
, op1
);
11539 /* Return location descriptor for unsigned comparison OP RTL. */
11541 static dw_loc_descr_ref
11542 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11543 enum machine_mode mem_mode
)
11545 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11546 dw_loc_descr_ref op0
, op1
;
11548 if (op_mode
== VOIDmode
)
11549 op_mode
= GET_MODE (XEXP (rtl
, 1));
11550 if (op_mode
== VOIDmode
)
11552 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11555 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11558 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11559 VAR_INIT_STATUS_INITIALIZED
);
11560 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11561 VAR_INIT_STATUS_INITIALIZED
);
11563 if (op0
== NULL
|| op1
== NULL
)
11566 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11568 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11569 dw_loc_descr_ref last0
, last1
;
11570 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11572 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11574 if (CONST_INT_P (XEXP (rtl
, 0)))
11575 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11576 /* deref_size zero extends, so no need to mask it again. */
11577 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11578 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11580 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11581 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11583 if (CONST_INT_P (XEXP (rtl
, 1)))
11584 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11585 /* deref_size zero extends, so no need to mask it again. */
11586 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11587 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11589 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11590 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11593 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11595 HOST_WIDE_INT bias
= 1;
11596 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11597 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11598 if (CONST_INT_P (XEXP (rtl
, 1)))
11599 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11600 + INTVAL (XEXP (rtl
, 1)));
11602 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11605 return compare_loc_descriptor (op
, op0
, op1
);
11608 /* Return location descriptor for {U,S}{MIN,MAX}. */
11610 static dw_loc_descr_ref
11611 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11612 enum machine_mode mem_mode
)
11614 enum dwarf_location_atom op
;
11615 dw_loc_descr_ref op0
, op1
, ret
;
11616 dw_loc_descr_ref bra_node
, drop_node
;
11619 && (GET_MODE_CLASS (mode
) != MODE_INT
11620 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11623 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11624 VAR_INIT_STATUS_INITIALIZED
);
11625 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11626 VAR_INIT_STATUS_INITIALIZED
);
11628 if (op0
== NULL
|| op1
== NULL
)
11631 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11632 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11633 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11634 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11636 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11638 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11639 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11640 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11641 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11642 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11644 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11646 HOST_WIDE_INT bias
= 1;
11647 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11648 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11649 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11652 else if (GET_MODE_CLASS (mode
) == MODE_INT
11653 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11655 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11656 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11657 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11658 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11659 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11661 else if (GET_MODE_CLASS (mode
) == MODE_INT
11662 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11664 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11665 dw_loc_descr_ref cvt
;
11666 if (type_die
== NULL
)
11668 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11669 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11670 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11671 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11672 add_loc_descr (&op0
, cvt
);
11673 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11674 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11675 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11676 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11677 add_loc_descr (&op1
, cvt
);
11680 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11685 add_loc_descr (&ret
, op1
);
11686 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11687 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11688 add_loc_descr (&ret
, bra_node
);
11689 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11690 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11691 add_loc_descr (&ret
, drop_node
);
11692 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11693 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11694 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11695 && GET_MODE_CLASS (mode
) == MODE_INT
11696 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11697 ret
= convert_descriptor_to_mode (mode
, ret
);
11701 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11702 but after converting arguments to type_die, afterwards
11703 convert back to unsigned. */
11705 static dw_loc_descr_ref
11706 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11707 enum machine_mode mode
, enum machine_mode mem_mode
)
11709 dw_loc_descr_ref cvt
, op0
, op1
;
11711 if (type_die
== NULL
)
11713 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11714 VAR_INIT_STATUS_INITIALIZED
);
11715 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11716 VAR_INIT_STATUS_INITIALIZED
);
11717 if (op0
== NULL
|| op1
== NULL
)
11719 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11720 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11721 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11722 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11723 add_loc_descr (&op0
, cvt
);
11724 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11725 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11726 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11727 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11728 add_loc_descr (&op1
, cvt
);
11729 add_loc_descr (&op0
, op1
);
11730 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11731 return convert_descriptor_to_mode (mode
, op0
);
11734 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11735 const0 is DW_OP_lit0 or corresponding typed constant,
11736 const1 is DW_OP_lit1 or corresponding typed constant
11737 and constMSB is constant with just the MSB bit set
11739 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11740 L1: const0 DW_OP_swap
11741 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11742 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11747 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11748 L1: const0 DW_OP_swap
11749 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11750 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11755 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11756 L1: const1 DW_OP_swap
11757 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11758 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11762 static dw_loc_descr_ref
11763 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11764 enum machine_mode mem_mode
)
11766 dw_loc_descr_ref op0
, ret
, tmp
;
11767 HOST_WIDE_INT valv
;
11768 dw_loc_descr_ref l1jump
, l1label
;
11769 dw_loc_descr_ref l2jump
, l2label
;
11770 dw_loc_descr_ref l3jump
, l3label
;
11771 dw_loc_descr_ref l4jump
, l4label
;
11774 if (GET_MODE_CLASS (mode
) != MODE_INT
11775 || GET_MODE (XEXP (rtl
, 0)) != mode
11776 || (GET_CODE (rtl
) == CLZ
11777 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11780 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11781 VAR_INIT_STATUS_INITIALIZED
);
11785 if (GET_CODE (rtl
) == CLZ
)
11787 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11788 valv
= GET_MODE_BITSIZE (mode
);
11790 else if (GET_CODE (rtl
) == FFS
)
11792 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11793 valv
= GET_MODE_BITSIZE (mode
);
11794 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11795 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11796 add_loc_descr (&ret
, l1jump
);
11797 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11798 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11799 VAR_INIT_STATUS_INITIALIZED
);
11802 add_loc_descr (&ret
, tmp
);
11803 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11804 add_loc_descr (&ret
, l4jump
);
11805 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11806 ? const1_rtx
: const0_rtx
,
11808 VAR_INIT_STATUS_INITIALIZED
);
11809 if (l1label
== NULL
)
11811 add_loc_descr (&ret
, l1label
);
11812 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11813 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11814 add_loc_descr (&ret
, l2label
);
11815 if (GET_CODE (rtl
) != CLZ
)
11817 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11818 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11819 << (GET_MODE_BITSIZE (mode
) - 1));
11821 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11822 << (GET_MODE_BITSIZE (mode
)
11823 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11824 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11825 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11826 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11827 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11829 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11830 VAR_INIT_STATUS_INITIALIZED
);
11833 add_loc_descr (&ret
, tmp
);
11834 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11835 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11836 add_loc_descr (&ret
, l3jump
);
11837 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11838 VAR_INIT_STATUS_INITIALIZED
);
11841 add_loc_descr (&ret
, tmp
);
11842 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11843 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11844 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11845 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11846 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11847 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11848 add_loc_descr (&ret
, l2jump
);
11849 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11850 add_loc_descr (&ret
, l3label
);
11851 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11852 add_loc_descr (&ret
, l4label
);
11853 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11854 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11855 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11856 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11857 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11858 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11859 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11860 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11864 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11865 const1 is DW_OP_lit1 or corresponding typed constant):
11867 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11868 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11872 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11873 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11876 static dw_loc_descr_ref
11877 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11878 enum machine_mode mem_mode
)
11880 dw_loc_descr_ref op0
, ret
, tmp
;
11881 dw_loc_descr_ref l1jump
, l1label
;
11882 dw_loc_descr_ref l2jump
, l2label
;
11884 if (GET_MODE_CLASS (mode
) != MODE_INT
11885 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11888 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11889 VAR_INIT_STATUS_INITIALIZED
);
11893 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11894 VAR_INIT_STATUS_INITIALIZED
);
11897 add_loc_descr (&ret
, tmp
);
11898 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11899 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11900 add_loc_descr (&ret
, l1label
);
11901 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11902 add_loc_descr (&ret
, l2jump
);
11903 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11904 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11905 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11906 VAR_INIT_STATUS_INITIALIZED
);
11909 add_loc_descr (&ret
, tmp
);
11910 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11911 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11912 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11913 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11914 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11915 VAR_INIT_STATUS_INITIALIZED
);
11916 add_loc_descr (&ret
, tmp
);
11917 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11918 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11919 add_loc_descr (&ret
, l1jump
);
11920 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11921 add_loc_descr (&ret
, l2label
);
11922 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11923 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11924 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11925 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11929 /* BSWAP (constS is initial shift count, either 56 or 24):
11931 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11932 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11933 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11934 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11935 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11937 static dw_loc_descr_ref
11938 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11939 enum machine_mode mem_mode
)
11941 dw_loc_descr_ref op0
, ret
, tmp
;
11942 dw_loc_descr_ref l1jump
, l1label
;
11943 dw_loc_descr_ref l2jump
, l2label
;
11945 if (GET_MODE_CLASS (mode
) != MODE_INT
11946 || BITS_PER_UNIT
!= 8
11947 || (GET_MODE_BITSIZE (mode
) != 32
11948 && GET_MODE_BITSIZE (mode
) != 64))
11951 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11952 VAR_INIT_STATUS_INITIALIZED
);
11957 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11959 VAR_INIT_STATUS_INITIALIZED
);
11962 add_loc_descr (&ret
, tmp
);
11963 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11964 VAR_INIT_STATUS_INITIALIZED
);
11967 add_loc_descr (&ret
, tmp
);
11968 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11969 add_loc_descr (&ret
, l1label
);
11970 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11972 VAR_INIT_STATUS_INITIALIZED
);
11973 add_loc_descr (&ret
, tmp
);
11974 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11975 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11976 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11977 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11978 VAR_INIT_STATUS_INITIALIZED
);
11981 add_loc_descr (&ret
, tmp
);
11982 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11983 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11984 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11985 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11986 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11987 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11988 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11989 VAR_INIT_STATUS_INITIALIZED
);
11990 add_loc_descr (&ret
, tmp
);
11991 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11992 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11993 add_loc_descr (&ret
, l2jump
);
11994 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11995 VAR_INIT_STATUS_INITIALIZED
);
11996 add_loc_descr (&ret
, tmp
);
11997 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11998 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11999 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12000 add_loc_descr (&ret
, l1jump
);
12001 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12002 add_loc_descr (&ret
, l2label
);
12003 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12004 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12005 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12006 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12007 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12008 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12012 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12013 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12014 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12015 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12017 ROTATERT is similar:
12018 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12019 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12020 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12022 static dw_loc_descr_ref
12023 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12024 enum machine_mode mem_mode
)
12026 rtx rtlop1
= XEXP (rtl
, 1);
12027 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12030 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12033 if (GET_MODE (rtlop1
) != VOIDmode
12034 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12035 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12036 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12037 VAR_INIT_STATUS_INITIALIZED
);
12038 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12039 VAR_INIT_STATUS_INITIALIZED
);
12040 if (op0
== NULL
|| op1
== NULL
)
12042 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12043 for (i
= 0; i
< 2; i
++)
12045 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12046 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12048 VAR_INIT_STATUS_INITIALIZED
);
12049 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12050 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12052 : HOST_BITS_PER_WIDE_INT
== 64
12053 ? DW_OP_const8u
: DW_OP_constu
,
12054 GET_MODE_MASK (mode
), 0);
12057 if (mask
[i
] == NULL
)
12059 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12062 add_loc_descr (&ret
, op1
);
12063 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12064 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12065 if (GET_CODE (rtl
) == ROTATERT
)
12067 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12068 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12069 GET_MODE_BITSIZE (mode
), 0));
12071 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12072 if (mask
[0] != NULL
)
12073 add_loc_descr (&ret
, mask
[0]);
12074 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12075 if (mask
[1] != NULL
)
12077 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12078 add_loc_descr (&ret
, mask
[1]);
12079 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12081 if (GET_CODE (rtl
) == ROTATE
)
12083 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12084 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12085 GET_MODE_BITSIZE (mode
), 0));
12087 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12088 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12092 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12093 for DEBUG_PARAMETER_REF RTL. */
12095 static dw_loc_descr_ref
12096 parameter_ref_descriptor (rtx rtl
)
12098 dw_loc_descr_ref ret
;
12103 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12104 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12105 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12108 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12109 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12110 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12114 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12115 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12120 /* The following routine converts the RTL for a variable or parameter
12121 (resident in memory) into an equivalent Dwarf representation of a
12122 mechanism for getting the address of that same variable onto the top of a
12123 hypothetical "address evaluation" stack.
12125 When creating memory location descriptors, we are effectively transforming
12126 the RTL for a memory-resident object into its Dwarf postfix expression
12127 equivalent. This routine recursively descends an RTL tree, turning
12128 it into Dwarf postfix code as it goes.
12130 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12132 MEM_MODE is the mode of the memory reference, needed to handle some
12133 autoincrement addressing modes.
12135 Return 0 if we can't represent the location. */
12138 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12139 enum machine_mode mem_mode
,
12140 enum var_init_status initialized
)
12142 dw_loc_descr_ref mem_loc_result
= NULL
;
12143 enum dwarf_location_atom op
;
12144 dw_loc_descr_ref op0
, op1
;
12145 rtx inner
= NULL_RTX
;
12147 if (mode
== VOIDmode
)
12148 mode
= GET_MODE (rtl
);
12150 /* Note that for a dynamically sized array, the location we will generate a
12151 description of here will be the lowest numbered location which is
12152 actually within the array. That's *not* necessarily the same as the
12153 zeroth element of the array. */
12155 rtl
= targetm
.delegitimize_address (rtl
);
12157 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12160 switch (GET_CODE (rtl
))
12165 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12168 /* The case of a subreg may arise when we have a local (register)
12169 variable or a formal (register) parameter which doesn't quite fill
12170 up an entire register. For now, just assume that it is
12171 legitimate to make the Dwarf info refer to the whole register which
12172 contains the given subreg. */
12173 if (!subreg_lowpart_p (rtl
))
12175 inner
= SUBREG_REG (rtl
);
12177 if (inner
== NULL_RTX
)
12178 inner
= XEXP (rtl
, 0);
12179 if (GET_MODE_CLASS (mode
) == MODE_INT
12180 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12181 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12182 #ifdef POINTERS_EXTEND_UNSIGNED
12183 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12186 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12188 mem_loc_result
= mem_loc_descriptor (inner
,
12190 mem_mode
, initialized
);
12195 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12197 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12198 && (GET_MODE_CLASS (mode
) != MODE_INT
12199 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12203 dw_die_ref type_die
;
12204 dw_loc_descr_ref cvt
;
12206 mem_loc_result
= mem_loc_descriptor (inner
,
12208 mem_mode
, initialized
);
12209 if (mem_loc_result
== NULL
)
12211 type_die
= base_type_for_mode (mode
,
12212 GET_MODE_CLASS (mode
) == MODE_INT
);
12213 if (type_die
== NULL
)
12215 mem_loc_result
= NULL
;
12218 if (GET_MODE_SIZE (mode
)
12219 != GET_MODE_SIZE (GET_MODE (inner
)))
12220 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12222 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12223 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12224 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12225 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12226 add_loc_descr (&mem_loc_result
, cvt
);
12231 if (GET_MODE_CLASS (mode
) != MODE_INT
12232 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12233 && rtl
!= arg_pointer_rtx
12234 && rtl
!= frame_pointer_rtx
12235 #ifdef POINTERS_EXTEND_UNSIGNED
12236 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12240 dw_die_ref type_die
;
12241 unsigned int dbx_regnum
;
12245 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12247 type_die
= base_type_for_mode (mode
,
12248 GET_MODE_CLASS (mode
) == MODE_INT
);
12249 if (type_die
== NULL
)
12252 dbx_regnum
= dbx_reg_number (rtl
);
12253 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12255 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12257 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12258 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12259 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12262 /* Whenever a register number forms a part of the description of the
12263 method for calculating the (dynamic) address of a memory resident
12264 object, DWARF rules require the register number be referred to as
12265 a "base register". This distinction is not based in any way upon
12266 what category of register the hardware believes the given register
12267 belongs to. This is strictly DWARF terminology we're dealing with
12268 here. Note that in cases where the location of a memory-resident
12269 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12270 OP_CONST (0)) the actual DWARF location descriptor that we generate
12271 may just be OP_BASEREG (basereg). This may look deceptively like
12272 the object in question was allocated to a register (rather than in
12273 memory) so DWARF consumers need to be aware of the subtle
12274 distinction between OP_REG and OP_BASEREG. */
12275 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12276 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12277 else if (stack_realign_drap
12279 && crtl
->args
.internal_arg_pointer
== rtl
12280 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12282 /* If RTL is internal_arg_pointer, which has been optimized
12283 out, use DRAP instead. */
12284 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12285 VAR_INIT_STATUS_INITIALIZED
);
12291 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12293 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12294 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12297 else if (GET_CODE (rtl
) == ZERO_EXTEND
12298 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12299 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12300 < HOST_BITS_PER_WIDE_INT
12301 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12302 to expand zero extend as two shifts instead of
12304 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12306 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12307 mem_loc_result
= op0
;
12308 add_loc_descr (&mem_loc_result
,
12309 int_loc_descriptor (GET_MODE_MASK (imode
)));
12310 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12312 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12314 int shift
= DWARF2_ADDR_SIZE
12315 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12316 shift
*= BITS_PER_UNIT
;
12317 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12321 mem_loc_result
= op0
;
12322 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12323 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12324 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12325 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12327 else if (!dwarf_strict
)
12329 dw_die_ref type_die1
, type_die2
;
12330 dw_loc_descr_ref cvt
;
12332 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12333 GET_CODE (rtl
) == ZERO_EXTEND
);
12334 if (type_die1
== NULL
)
12336 type_die2
= base_type_for_mode (mode
, 1);
12337 if (type_die2
== NULL
)
12339 mem_loc_result
= op0
;
12340 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12341 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12342 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12343 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12344 add_loc_descr (&mem_loc_result
, cvt
);
12345 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12346 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12347 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12348 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12349 add_loc_descr (&mem_loc_result
, cvt
);
12355 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12356 if (new_rtl
!= rtl
)
12358 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12360 if (mem_loc_result
!= NULL
)
12361 return mem_loc_result
;
12364 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12365 get_address_mode (rtl
), mode
,
12366 VAR_INIT_STATUS_INITIALIZED
);
12367 if (mem_loc_result
== NULL
)
12368 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12369 if (mem_loc_result
!= NULL
)
12371 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12372 || GET_MODE_CLASS (mode
) != MODE_INT
)
12374 dw_die_ref type_die
;
12375 dw_loc_descr_ref deref
;
12380 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12381 if (type_die
== NULL
)
12383 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12384 GET_MODE_SIZE (mode
), 0);
12385 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12386 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12387 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12388 add_loc_descr (&mem_loc_result
, deref
);
12390 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12391 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12393 add_loc_descr (&mem_loc_result
,
12394 new_loc_descr (DW_OP_deref_size
,
12395 GET_MODE_SIZE (mode
), 0));
12400 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12403 /* Some ports can transform a symbol ref into a label ref, because
12404 the symbol ref is too far away and has to be dumped into a constant
12408 if (GET_MODE_CLASS (mode
) != MODE_INT
12409 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12410 #ifdef POINTERS_EXTEND_UNSIGNED
12411 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12415 if (GET_CODE (rtl
) == SYMBOL_REF
12416 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12418 dw_loc_descr_ref temp
;
12420 /* If this is not defined, we have no way to emit the data. */
12421 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12424 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12426 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12427 add_loc_descr (&mem_loc_result
, temp
);
12432 if (!const_ok_for_output (rtl
))
12436 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12437 vec_safe_push (used_rtx_array
, rtl
);
12443 case DEBUG_IMPLICIT_PTR
:
12444 expansion_failed (NULL_TREE
, rtl
,
12445 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12451 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12453 if (GET_MODE_CLASS (mode
) != MODE_INT
12454 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12455 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12456 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12459 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12460 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12462 op0
= one_reg_loc_descriptor (dbx_regnum
,
12463 VAR_INIT_STATUS_INITIALIZED
);
12466 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12467 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12469 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12470 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12471 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12475 gcc_unreachable ();
12478 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12479 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12480 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12483 case DEBUG_PARAMETER_REF
:
12484 mem_loc_result
= parameter_ref_descriptor (rtl
);
12488 /* Extract the PLUS expression nested inside and fall into
12489 PLUS code below. */
12490 rtl
= XEXP (rtl
, 1);
12495 /* Turn these into a PLUS expression and fall into the PLUS code
12497 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12498 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12499 ? GET_MODE_UNIT_SIZE (mem_mode
)
12500 : -GET_MODE_UNIT_SIZE (mem_mode
),
12503 /* ... fall through ... */
12507 if (is_based_loc (rtl
)
12508 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12509 || XEXP (rtl
, 0) == arg_pointer_rtx
12510 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12511 && GET_MODE_CLASS (mode
) == MODE_INT
)
12512 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12513 INTVAL (XEXP (rtl
, 1)),
12514 VAR_INIT_STATUS_INITIALIZED
);
12517 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12518 VAR_INIT_STATUS_INITIALIZED
);
12519 if (mem_loc_result
== 0)
12522 if (CONST_INT_P (XEXP (rtl
, 1))
12523 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12524 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12527 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12528 VAR_INIT_STATUS_INITIALIZED
);
12531 add_loc_descr (&mem_loc_result
, op1
);
12532 add_loc_descr (&mem_loc_result
,
12533 new_loc_descr (DW_OP_plus
, 0, 0));
12538 /* If a pseudo-reg is optimized away, it is possible for it to
12539 be replaced with a MEM containing a multiply or shift. */
12550 && GET_MODE_CLASS (mode
) == MODE_INT
12551 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12553 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12554 base_type_for_mode (mode
, 0),
12578 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12580 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12581 VAR_INIT_STATUS_INITIALIZED
);
12583 rtx rtlop1
= XEXP (rtl
, 1);
12584 if (GET_MODE (rtlop1
) != VOIDmode
12585 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12586 < GET_MODE_BITSIZE (mode
))
12587 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12588 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12589 VAR_INIT_STATUS_INITIALIZED
);
12592 if (op0
== 0 || op1
== 0)
12595 mem_loc_result
= op0
;
12596 add_loc_descr (&mem_loc_result
, op1
);
12597 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12613 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12614 VAR_INIT_STATUS_INITIALIZED
);
12615 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12616 VAR_INIT_STATUS_INITIALIZED
);
12618 if (op0
== 0 || op1
== 0)
12621 mem_loc_result
= op0
;
12622 add_loc_descr (&mem_loc_result
, op1
);
12623 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12627 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12629 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12630 base_type_for_mode (mode
, 0),
12635 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12636 VAR_INIT_STATUS_INITIALIZED
);
12637 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12638 VAR_INIT_STATUS_INITIALIZED
);
12640 if (op0
== 0 || op1
== 0)
12643 mem_loc_result
= op0
;
12644 add_loc_descr (&mem_loc_result
, op1
);
12645 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12646 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12647 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12648 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12649 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12653 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12655 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12660 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12661 base_type_for_mode (mode
, 1),
12679 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12680 VAR_INIT_STATUS_INITIALIZED
);
12685 mem_loc_result
= op0
;
12686 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12690 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12691 #ifdef POINTERS_EXTEND_UNSIGNED
12693 && mem_mode
!= VOIDmode
12694 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12698 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12702 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12703 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12705 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12706 enum machine_mode amode
;
12707 if (type_die
== NULL
)
12709 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12711 if (INTVAL (rtl
) >= 0
12712 && amode
!= BLKmode
12713 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12714 /* const DW_OP_GNU_convert <XXX> vs.
12715 DW_OP_GNU_const_type <XXX, 1, const>. */
12716 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12717 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12719 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12720 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12721 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12722 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12723 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12724 add_loc_descr (&mem_loc_result
, op0
);
12725 return mem_loc_result
;
12727 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12729 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12730 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12731 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12732 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12733 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12736 mem_loc_result
->dw_loc_oprnd2
.val_class
12737 = dw_val_class_const_double
;
12738 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12739 = double_int::from_shwi (INTVAL (rtl
));
12747 dw_die_ref type_die
;
12749 /* Note that a CONST_DOUBLE rtx could represent either an integer
12750 or a floating-point constant. A CONST_DOUBLE is used whenever
12751 the constant requires more than one word in order to be
12752 adequately represented. We output CONST_DOUBLEs as blocks. */
12753 if (mode
== VOIDmode
12754 || (GET_MODE (rtl
) == VOIDmode
12755 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12757 type_die
= base_type_for_mode (mode
,
12758 GET_MODE_CLASS (mode
) == MODE_INT
);
12759 if (type_die
== NULL
)
12761 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12762 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12763 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12764 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12765 if (SCALAR_FLOAT_MODE_P (mode
))
12767 unsigned int length
= GET_MODE_SIZE (mode
);
12768 unsigned char *array
12769 = (unsigned char*) ggc_alloc_atomic (length
);
12771 insert_float (rtl
, array
);
12772 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12773 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12774 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12775 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12779 mem_loc_result
->dw_loc_oprnd2
.val_class
12780 = dw_val_class_const_double
;
12781 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12782 = rtx_to_double_int (rtl
);
12788 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12792 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12796 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12800 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12804 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12808 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12812 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12816 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12820 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12824 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12829 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12834 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12839 if (CONST_INT_P (XEXP (rtl
, 1))
12840 && CONST_INT_P (XEXP (rtl
, 2))
12841 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12842 + (unsigned) INTVAL (XEXP (rtl
, 2))
12843 <= GET_MODE_BITSIZE (mode
))
12844 && GET_MODE_CLASS (mode
) == MODE_INT
12845 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12846 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12849 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12850 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12853 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12857 mem_loc_result
= op0
;
12858 size
= INTVAL (XEXP (rtl
, 1));
12859 shift
= INTVAL (XEXP (rtl
, 2));
12860 if (BITS_BIG_ENDIAN
)
12861 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12863 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12865 add_loc_descr (&mem_loc_result
,
12866 int_loc_descriptor (DWARF2_ADDR_SIZE
12868 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12870 if (size
!= (int) DWARF2_ADDR_SIZE
)
12872 add_loc_descr (&mem_loc_result
,
12873 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12874 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12881 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12882 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12883 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12884 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12885 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12886 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12887 VAR_INIT_STATUS_INITIALIZED
);
12888 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12889 VAR_INIT_STATUS_INITIALIZED
);
12890 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12893 mem_loc_result
= op1
;
12894 add_loc_descr (&mem_loc_result
, op2
);
12895 add_loc_descr (&mem_loc_result
, op0
);
12896 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12897 add_loc_descr (&mem_loc_result
, bra_node
);
12898 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12899 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12900 add_loc_descr (&mem_loc_result
, drop_node
);
12901 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12902 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12907 case FLOAT_TRUNCATE
:
12909 case UNSIGNED_FLOAT
:
12914 dw_die_ref type_die
;
12915 dw_loc_descr_ref cvt
;
12917 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12918 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12921 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12922 && (GET_CODE (rtl
) == FLOAT
12923 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12924 <= DWARF2_ADDR_SIZE
))
12926 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12927 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12928 if (type_die
== NULL
)
12930 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12931 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12932 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12933 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12934 add_loc_descr (&op0
, cvt
);
12936 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12937 if (type_die
== NULL
)
12939 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12940 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12941 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12942 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12943 add_loc_descr (&op0
, cvt
);
12944 if (GET_MODE_CLASS (mode
) == MODE_INT
12945 && (GET_CODE (rtl
) == FIX
12946 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12948 op0
= convert_descriptor_to_mode (mode
, op0
);
12952 mem_loc_result
= op0
;
12959 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12964 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12968 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12973 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12977 /* In theory, we could implement the above. */
12978 /* DWARF cannot represent the unsigned compare operations
13003 case FRACT_CONVERT
:
13004 case UNSIGNED_FRACT_CONVERT
:
13006 case UNSIGNED_SAT_FRACT
:
13012 case VEC_DUPLICATE
:
13016 case STRICT_LOW_PART
:
13021 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13022 can't express it in the debug info. This can happen e.g. with some
13027 resolve_one_addr (&rtl
, NULL
);
13031 #ifdef ENABLE_CHECKING
13032 print_rtl (stderr
, rtl
);
13033 gcc_unreachable ();
13039 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13040 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13042 return mem_loc_result
;
13045 /* Return a descriptor that describes the concatenation of two locations.
13046 This is typically a complex variable. */
13048 static dw_loc_descr_ref
13049 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13051 dw_loc_descr_ref cc_loc_result
= NULL
;
13052 dw_loc_descr_ref x0_ref
13053 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13054 dw_loc_descr_ref x1_ref
13055 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13057 if (x0_ref
== 0 || x1_ref
== 0)
13060 cc_loc_result
= x0_ref
;
13061 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13063 add_loc_descr (&cc_loc_result
, x1_ref
);
13064 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13066 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13067 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13069 return cc_loc_result
;
13072 /* Return a descriptor that describes the concatenation of N
13075 static dw_loc_descr_ref
13076 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13079 dw_loc_descr_ref cc_loc_result
= NULL
;
13080 unsigned int n
= XVECLEN (concatn
, 0);
13082 for (i
= 0; i
< n
; ++i
)
13084 dw_loc_descr_ref ref
;
13085 rtx x
= XVECEXP (concatn
, 0, i
);
13087 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13091 add_loc_descr (&cc_loc_result
, ref
);
13092 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13095 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13096 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13098 return cc_loc_result
;
13101 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13102 for DEBUG_IMPLICIT_PTR RTL. */
13104 static dw_loc_descr_ref
13105 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13107 dw_loc_descr_ref ret
;
13112 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13113 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13114 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13115 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13116 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13117 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13120 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13121 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13122 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13126 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13127 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13132 /* Output a proper Dwarf location descriptor for a variable or parameter
13133 which is either allocated in a register or in a memory location. For a
13134 register, we just generate an OP_REG and the register number. For a
13135 memory location we provide a Dwarf postfix expression describing how to
13136 generate the (dynamic) address of the object onto the address stack.
13138 MODE is mode of the decl if this loc_descriptor is going to be used in
13139 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13140 allowed, VOIDmode otherwise.
13142 If we don't know how to describe it, return 0. */
13144 static dw_loc_descr_ref
13145 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13146 enum var_init_status initialized
)
13148 dw_loc_descr_ref loc_result
= NULL
;
13150 switch (GET_CODE (rtl
))
13153 /* The case of a subreg may arise when we have a local (register)
13154 variable or a formal (register) parameter which doesn't quite fill
13155 up an entire register. For now, just assume that it is
13156 legitimate to make the Dwarf info refer to the whole register which
13157 contains the given subreg. */
13158 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13159 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13160 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13166 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13170 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13171 GET_MODE (rtl
), initialized
);
13172 if (loc_result
== NULL
)
13173 loc_result
= tls_mem_loc_descriptor (rtl
);
13174 if (loc_result
== NULL
)
13176 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13177 if (new_rtl
!= rtl
)
13178 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13183 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13188 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13193 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13195 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13196 if (GET_CODE (loc
) == EXPR_LIST
)
13197 loc
= XEXP (loc
, 0);
13198 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13202 rtl
= XEXP (rtl
, 1);
13207 rtvec par_elems
= XVEC (rtl
, 0);
13208 int num_elem
= GET_NUM_ELEM (par_elems
);
13209 enum machine_mode mode
;
13212 /* Create the first one, so we have something to add to. */
13213 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13214 VOIDmode
, initialized
);
13215 if (loc_result
== NULL
)
13217 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13218 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13219 for (i
= 1; i
< num_elem
; i
++)
13221 dw_loc_descr_ref temp
;
13223 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13224 VOIDmode
, initialized
);
13227 add_loc_descr (&loc_result
, temp
);
13228 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13229 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13235 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13236 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13241 if (mode
== VOIDmode
)
13242 mode
= GET_MODE (rtl
);
13244 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13246 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13248 /* Note that a CONST_DOUBLE rtx could represent either an integer
13249 or a floating-point constant. A CONST_DOUBLE is used whenever
13250 the constant requires more than one word in order to be
13251 adequately represented. We output CONST_DOUBLEs as blocks. */
13252 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13253 GET_MODE_SIZE (mode
), 0);
13254 if (SCALAR_FLOAT_MODE_P (mode
))
13256 unsigned int length
= GET_MODE_SIZE (mode
);
13257 unsigned char *array
13258 = (unsigned char*) ggc_alloc_atomic (length
);
13260 insert_float (rtl
, array
);
13261 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13262 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13263 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13264 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13268 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13269 loc_result
->dw_loc_oprnd2
.v
.val_double
13270 = rtx_to_double_int (rtl
);
13276 if (mode
== VOIDmode
)
13277 mode
= GET_MODE (rtl
);
13279 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13281 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13282 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13283 unsigned char *array
= (unsigned char *)
13284 ggc_alloc_atomic (length
* elt_size
);
13288 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13289 switch (GET_MODE_CLASS (mode
))
13291 case MODE_VECTOR_INT
:
13292 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13294 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13295 double_int val
= rtx_to_double_int (elt
);
13297 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13298 insert_int (val
.to_shwi (), elt_size
, p
);
13301 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13302 insert_double (val
, p
);
13307 case MODE_VECTOR_FLOAT
:
13308 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13310 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13311 insert_float (elt
, p
);
13316 gcc_unreachable ();
13319 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13320 length
* elt_size
, 0);
13321 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13322 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13323 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13324 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13329 if (mode
== VOIDmode
13330 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13331 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13332 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13334 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13339 if (!const_ok_for_output (rtl
))
13342 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13343 && (dwarf_version
>= 4 || !dwarf_strict
))
13345 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13346 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13347 vec_safe_push (used_rtx_array
, rtl
);
13351 case DEBUG_IMPLICIT_PTR
:
13352 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13356 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13357 && CONST_INT_P (XEXP (rtl
, 1)))
13360 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13366 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13367 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13368 && dwarf_version
>= 4)
13369 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13371 /* Value expression. */
13372 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13374 add_loc_descr (&loc_result
,
13375 new_loc_descr (DW_OP_stack_value
, 0, 0));
13383 /* We need to figure out what section we should use as the base for the
13384 address ranges where a given location is valid.
13385 1. If this particular DECL has a section associated with it, use that.
13386 2. If this function has a section associated with it, use that.
13387 3. Otherwise, use the text section.
13388 XXX: If you split a variable across multiple sections, we won't notice. */
13390 static const char *
13391 secname_for_decl (const_tree decl
)
13393 const char *secname
;
13395 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13397 tree sectree
= DECL_SECTION_NAME (decl
);
13398 secname
= TREE_STRING_POINTER (sectree
);
13400 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13402 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13403 secname
= TREE_STRING_POINTER (sectree
);
13405 else if (cfun
&& in_cold_section_p
)
13406 secname
= crtl
->subsections
.cold_section_label
;
13408 secname
= text_section_label
;
13413 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13416 decl_by_reference_p (tree decl
)
13418 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13419 || TREE_CODE (decl
) == VAR_DECL
)
13420 && DECL_BY_REFERENCE (decl
));
13423 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13426 static dw_loc_descr_ref
13427 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13428 enum var_init_status initialized
)
13430 int have_address
= 0;
13431 dw_loc_descr_ref descr
;
13432 enum machine_mode mode
;
13434 if (want_address
!= 2)
13436 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13438 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13440 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13441 if (GET_CODE (varloc
) == EXPR_LIST
)
13442 varloc
= XEXP (varloc
, 0);
13443 mode
= GET_MODE (varloc
);
13444 if (MEM_P (varloc
))
13446 rtx addr
= XEXP (varloc
, 0);
13447 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13448 mode
, initialized
);
13453 rtx x
= avoid_constant_pool_reference (varloc
);
13455 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13460 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13467 if (GET_CODE (varloc
) == VAR_LOCATION
)
13468 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13470 mode
= DECL_MODE (loc
);
13471 descr
= loc_descriptor (varloc
, mode
, initialized
);
13478 if (want_address
== 2 && !have_address
13479 && (dwarf_version
>= 4 || !dwarf_strict
))
13481 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13483 expansion_failed (loc
, NULL_RTX
,
13484 "DWARF address size mismatch");
13487 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13490 /* Show if we can't fill the request for an address. */
13491 if (want_address
&& !have_address
)
13493 expansion_failed (loc
, NULL_RTX
,
13494 "Want address and only have value");
13498 /* If we've got an address and don't want one, dereference. */
13499 if (!want_address
&& have_address
)
13501 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13502 enum dwarf_location_atom op
;
13504 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13506 expansion_failed (loc
, NULL_RTX
,
13507 "DWARF address size mismatch");
13510 else if (size
== DWARF2_ADDR_SIZE
)
13513 op
= DW_OP_deref_size
;
13515 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13521 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13522 if it is not possible. */
13524 static dw_loc_descr_ref
13525 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13527 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13528 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13529 else if (dwarf_version
>= 3 || !dwarf_strict
)
13530 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13535 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13536 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13538 static dw_loc_descr_ref
13539 dw_sra_loc_expr (tree decl
, rtx loc
)
13542 unsigned int padsize
= 0;
13543 dw_loc_descr_ref descr
, *descr_tail
;
13544 unsigned HOST_WIDE_INT decl_size
;
13546 enum var_init_status initialized
;
13548 if (DECL_SIZE (decl
) == NULL
13549 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
13552 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
13554 descr_tail
= &descr
;
13556 for (p
= loc
; p
; p
= XEXP (p
, 1))
13558 unsigned int bitsize
= decl_piece_bitsize (p
);
13559 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13560 dw_loc_descr_ref cur_descr
;
13561 dw_loc_descr_ref
*tail
, last
= NULL
;
13562 unsigned int opsize
= 0;
13564 if (loc_note
== NULL_RTX
13565 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13567 padsize
+= bitsize
;
13570 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13571 varloc
= NOTE_VAR_LOCATION (loc_note
);
13572 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13573 if (cur_descr
== NULL
)
13575 padsize
+= bitsize
;
13579 /* Check that cur_descr either doesn't use
13580 DW_OP_*piece operations, or their sum is equal
13581 to bitsize. Otherwise we can't embed it. */
13582 for (tail
= &cur_descr
; *tail
!= NULL
;
13583 tail
= &(*tail
)->dw_loc_next
)
13584 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13586 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13590 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13592 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13596 if (last
!= NULL
&& opsize
!= bitsize
)
13598 padsize
+= bitsize
;
13599 /* Discard the current piece of the descriptor and release any
13600 addr_table entries it uses. */
13601 remove_loc_list_addr_table_entries (cur_descr
);
13605 /* If there is a hole, add DW_OP_*piece after empty DWARF
13606 expression, which means that those bits are optimized out. */
13609 if (padsize
> decl_size
)
13611 remove_loc_list_addr_table_entries (cur_descr
);
13612 goto discard_descr
;
13614 decl_size
-= padsize
;
13615 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13616 if (*descr_tail
== NULL
)
13618 remove_loc_list_addr_table_entries (cur_descr
);
13619 goto discard_descr
;
13621 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13624 *descr_tail
= cur_descr
;
13626 if (bitsize
> decl_size
)
13627 goto discard_descr
;
13628 decl_size
-= bitsize
;
13631 HOST_WIDE_INT offset
= 0;
13632 if (GET_CODE (varloc
) == VAR_LOCATION
13633 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13635 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13636 if (GET_CODE (varloc
) == EXPR_LIST
)
13637 varloc
= XEXP (varloc
, 0);
13641 if (GET_CODE (varloc
) == CONST
13642 || GET_CODE (varloc
) == SIGN_EXTEND
13643 || GET_CODE (varloc
) == ZERO_EXTEND
)
13644 varloc
= XEXP (varloc
, 0);
13645 else if (GET_CODE (varloc
) == SUBREG
)
13646 varloc
= SUBREG_REG (varloc
);
13651 /* DW_OP_bit_size offset should be zero for register
13652 or implicit location descriptions and empty location
13653 descriptions, but for memory addresses needs big endian
13655 if (MEM_P (varloc
))
13657 unsigned HOST_WIDE_INT memsize
13658 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13659 if (memsize
!= bitsize
)
13661 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13662 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13663 goto discard_descr
;
13664 if (memsize
< bitsize
)
13665 goto discard_descr
;
13666 if (BITS_BIG_ENDIAN
)
13667 offset
= memsize
- bitsize
;
13671 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13672 if (*descr_tail
== NULL
)
13673 goto discard_descr
;
13674 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13678 /* If there were any non-empty expressions, add padding till the end of
13680 if (descr
!= NULL
&& decl_size
!= 0)
13682 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13683 if (*descr_tail
== NULL
)
13684 goto discard_descr
;
13689 /* Discard the descriptor and release any addr_table entries it uses. */
13690 remove_loc_list_addr_table_entries (descr
);
13694 /* Return the dwarf representation of the location list LOC_LIST of
13695 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13698 static dw_loc_list_ref
13699 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13701 const char *endname
, *secname
;
13703 enum var_init_status initialized
;
13704 struct var_loc_node
*node
;
13705 dw_loc_descr_ref descr
;
13706 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13707 dw_loc_list_ref list
= NULL
;
13708 dw_loc_list_ref
*listp
= &list
;
13710 /* Now that we know what section we are using for a base,
13711 actually construct the list of locations.
13712 The first location information is what is passed to the
13713 function that creates the location list, and the remaining
13714 locations just get added on to that list.
13715 Note that we only know the start address for a location
13716 (IE location changes), so to build the range, we use
13717 the range [current location start, next location start].
13718 This means we have to special case the last node, and generate
13719 a range of [last location start, end of function label]. */
13721 secname
= secname_for_decl (decl
);
13723 for (node
= loc_list
->first
; node
; node
= node
->next
)
13724 if (GET_CODE (node
->loc
) == EXPR_LIST
13725 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13727 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13729 /* This requires DW_OP_{,bit_}piece, which is not usable
13730 inside DWARF expressions. */
13731 if (want_address
!= 2)
13733 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13739 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13740 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13741 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13745 bool range_across_switch
= false;
13746 /* If section switch happens in between node->label
13747 and node->next->label (or end of function) and
13748 we can't emit it as a single entry list,
13749 emit two ranges, first one ending at the end
13750 of first partition and second one starting at the
13751 beginning of second partition. */
13752 if (node
== loc_list
->last_before_switch
13753 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13754 && current_function_decl
)
13756 endname
= cfun
->fde
->dw_fde_end
;
13757 range_across_switch
= true;
13759 /* The variable has a location between NODE->LABEL and
13760 NODE->NEXT->LABEL. */
13761 else if (node
->next
)
13762 endname
= node
->next
->label
;
13763 /* If the variable has a location at the last label
13764 it keeps its location until the end of function. */
13765 else if (!current_function_decl
)
13766 endname
= text_end_label
;
13769 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13770 current_function_funcdef_no
);
13771 endname
= ggc_strdup (label_id
);
13774 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13775 if (TREE_CODE (decl
) == PARM_DECL
13776 && node
== loc_list
->first
13777 && NOTE_P (node
->loc
)
13778 && strcmp (node
->label
, endname
) == 0)
13779 (*listp
)->force
= true;
13780 listp
= &(*listp
)->dw_loc_next
;
13782 if (range_across_switch
)
13784 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13785 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13788 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13789 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13790 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13793 gcc_assert (descr
);
13794 /* The variable has a location between NODE->LABEL and
13795 NODE->NEXT->LABEL. */
13797 endname
= node
->next
->label
;
13799 endname
= cfun
->fde
->dw_fde_second_end
;
13800 *listp
= new_loc_list (descr
,
13801 cfun
->fde
->dw_fde_second_begin
,
13803 listp
= &(*listp
)->dw_loc_next
;
13808 /* Try to avoid the overhead of a location list emitting a location
13809 expression instead, but only if we didn't have more than one
13810 location entry in the first place. If some entries were not
13811 representable, we don't want to pretend a single entry that was
13812 applies to the entire scope in which the variable is
13814 if (list
&& loc_list
->first
->next
)
13820 /* Return if the loc_list has only single element and thus can be represented
13821 as location description. */
13824 single_element_loc_list_p (dw_loc_list_ref list
)
13826 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13827 return !list
->ll_symbol
;
13830 /* To each location in list LIST add loc descr REF. */
13833 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13835 dw_loc_descr_ref copy
;
13836 add_loc_descr (&list
->expr
, ref
);
13837 list
= list
->dw_loc_next
;
13840 copy
= ggc_alloc_dw_loc_descr_node ();
13841 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13842 add_loc_descr (&list
->expr
, copy
);
13843 while (copy
->dw_loc_next
)
13845 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13846 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13847 copy
->dw_loc_next
= new_copy
;
13850 list
= list
->dw_loc_next
;
13854 /* Given two lists RET and LIST
13855 produce location list that is result of adding expression in LIST
13856 to expression in RET on each position in program.
13857 Might be destructive on both RET and LIST.
13859 TODO: We handle only simple cases of RET or LIST having at most one
13860 element. General case would inolve sorting the lists in program order
13861 and merging them that will need some additional work.
13862 Adding that will improve quality of debug info especially for SRA-ed
13866 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13875 if (!list
->dw_loc_next
)
13877 add_loc_descr_to_each (*ret
, list
->expr
);
13880 if (!(*ret
)->dw_loc_next
)
13882 add_loc_descr_to_each (list
, (*ret
)->expr
);
13886 expansion_failed (NULL_TREE
, NULL_RTX
,
13887 "Don't know how to merge two non-trivial"
13888 " location lists.\n");
13893 /* LOC is constant expression. Try a luck, look it up in constant
13894 pool and return its loc_descr of its address. */
13896 static dw_loc_descr_ref
13897 cst_pool_loc_descr (tree loc
)
13899 /* Get an RTL for this, if something has been emitted. */
13900 rtx rtl
= lookup_constant_def (loc
);
13902 if (!rtl
|| !MEM_P (rtl
))
13907 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13909 /* TODO: We might get more coverage if we was actually delaying expansion
13910 of all expressions till end of compilation when constant pools are fully
13912 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13914 expansion_failed (loc
, NULL_RTX
,
13915 "CST value in contant pool but not marked.");
13918 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13919 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13922 /* Return dw_loc_list representing address of addr_expr LOC
13923 by looking for inner INDIRECT_REF expression and turning
13924 it into simple arithmetics. */
13926 static dw_loc_list_ref
13927 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13930 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13931 enum machine_mode mode
;
13932 int unsignedp
, volatilep
= 0;
13933 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13935 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13936 &bitsize
, &bitpos
, &offset
, &mode
,
13937 &unsignedp
, &volatilep
, false);
13939 if (bitpos
% BITS_PER_UNIT
)
13941 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13944 if (!INDIRECT_REF_P (obj
))
13946 expansion_failed (obj
,
13947 NULL_RTX
, "no indirect ref in inner refrence");
13950 if (!offset
&& !bitpos
)
13951 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13953 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13954 && (dwarf_version
>= 4 || !dwarf_strict
))
13956 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13961 /* Variable offset. */
13962 list_ret1
= loc_list_from_tree (offset
, 0);
13963 if (list_ret1
== 0)
13965 add_loc_list (&list_ret
, list_ret1
);
13968 add_loc_descr_to_each (list_ret
,
13969 new_loc_descr (DW_OP_plus
, 0, 0));
13971 bytepos
= bitpos
/ BITS_PER_UNIT
;
13973 add_loc_descr_to_each (list_ret
,
13974 new_loc_descr (DW_OP_plus_uconst
,
13976 else if (bytepos
< 0)
13977 loc_list_plus_const (list_ret
, bytepos
);
13978 add_loc_descr_to_each (list_ret
,
13979 new_loc_descr (DW_OP_stack_value
, 0, 0));
13985 /* Generate Dwarf location list representing LOC.
13986 If WANT_ADDRESS is false, expression computing LOC will be computed
13987 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13988 if WANT_ADDRESS is 2, expression computing address useable in location
13989 will be returned (i.e. DW_OP_reg can be used
13990 to refer to register values). */
13992 static dw_loc_list_ref
13993 loc_list_from_tree (tree loc
, int want_address
)
13995 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13996 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13997 int have_address
= 0;
13998 enum dwarf_location_atom op
;
14000 /* ??? Most of the time we do not take proper care for sign/zero
14001 extending the values properly. Hopefully this won't be a real
14004 switch (TREE_CODE (loc
))
14007 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14010 case PLACEHOLDER_EXPR
:
14011 /* This case involves extracting fields from an object to determine the
14012 position of other fields. We don't try to encode this here. The
14013 only user of this is Ada, which encodes the needed information using
14014 the names of types. */
14015 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14019 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14020 /* There are no opcodes for these operations. */
14023 case PREINCREMENT_EXPR
:
14024 case PREDECREMENT_EXPR
:
14025 case POSTINCREMENT_EXPR
:
14026 case POSTDECREMENT_EXPR
:
14027 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14028 /* There are no opcodes for these operations. */
14032 /* If we already want an address, see if there is INDIRECT_REF inside
14033 e.g. for &this->field. */
14036 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14037 (loc
, want_address
== 2);
14040 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14041 && (ret
= cst_pool_loc_descr (loc
)))
14044 /* Otherwise, process the argument and look for the address. */
14045 if (!list_ret
&& !ret
)
14046 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14050 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14056 if (DECL_THREAD_LOCAL_P (loc
))
14059 enum dwarf_location_atom tls_op
;
14060 enum dtprel_bool dtprel
= dtprel_false
;
14062 if (targetm
.have_tls
)
14064 /* If this is not defined, we have no way to emit the
14066 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14069 /* The way DW_OP_GNU_push_tls_address is specified, we
14070 can only look up addresses of objects in the current
14071 module. We used DW_OP_addr as first op, but that's
14072 wrong, because DW_OP_addr is relocated by the debug
14073 info consumer, while DW_OP_GNU_push_tls_address
14074 operand shouldn't be. */
14075 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14077 dtprel
= dtprel_true
;
14078 tls_op
= DW_OP_GNU_push_tls_address
;
14082 if (!targetm
.emutls
.debug_form_tls_address
14083 || !(dwarf_version
>= 3 || !dwarf_strict
))
14085 /* We stuffed the control variable into the DECL_VALUE_EXPR
14086 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14087 no longer appear in gimple code. We used the control
14088 variable in specific so that we could pick it up here. */
14089 loc
= DECL_VALUE_EXPR (loc
);
14090 tls_op
= DW_OP_form_tls_address
;
14093 rtl
= rtl_for_decl_location (loc
);
14094 if (rtl
== NULL_RTX
)
14099 rtl
= XEXP (rtl
, 0);
14100 if (! CONSTANT_P (rtl
))
14103 ret
= new_addr_loc_descr (rtl
, dtprel
);
14104 ret1
= new_loc_descr (tls_op
, 0, 0);
14105 add_loc_descr (&ret
, ret1
);
14114 if (DECL_HAS_VALUE_EXPR_P (loc
))
14115 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14119 case FUNCTION_DECL
:
14122 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14124 if (loc_list
&& loc_list
->first
)
14126 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14127 have_address
= want_address
!= 0;
14130 rtl
= rtl_for_decl_location (loc
);
14131 if (rtl
== NULL_RTX
)
14133 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14136 else if (CONST_INT_P (rtl
))
14138 HOST_WIDE_INT val
= INTVAL (rtl
);
14139 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14140 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14141 ret
= int_loc_descriptor (val
);
14143 else if (GET_CODE (rtl
) == CONST_STRING
)
14145 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14148 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14149 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14152 enum machine_mode mode
, mem_mode
;
14154 /* Certain constructs can only be represented at top-level. */
14155 if (want_address
== 2)
14157 ret
= loc_descriptor (rtl
, VOIDmode
,
14158 VAR_INIT_STATUS_INITIALIZED
);
14163 mode
= GET_MODE (rtl
);
14164 mem_mode
= VOIDmode
;
14168 mode
= get_address_mode (rtl
);
14169 rtl
= XEXP (rtl
, 0);
14172 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14173 VAR_INIT_STATUS_INITIALIZED
);
14176 expansion_failed (loc
, rtl
,
14177 "failed to produce loc descriptor for rtl");
14184 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14188 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14192 case COMPOUND_EXPR
:
14193 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14196 case VIEW_CONVERT_EXPR
:
14199 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14201 case COMPONENT_REF
:
14202 case BIT_FIELD_REF
:
14204 case ARRAY_RANGE_REF
:
14205 case REALPART_EXPR
:
14206 case IMAGPART_EXPR
:
14209 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14210 enum machine_mode mode
;
14211 int unsignedp
, volatilep
= 0;
14213 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14214 &unsignedp
, &volatilep
, false);
14216 gcc_assert (obj
!= loc
);
14218 list_ret
= loc_list_from_tree (obj
,
14220 && !bitpos
&& !offset
? 2 : 1);
14221 /* TODO: We can extract value of the small expression via shifting even
14222 for nonzero bitpos. */
14225 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14227 expansion_failed (loc
, NULL_RTX
,
14228 "bitfield access");
14232 if (offset
!= NULL_TREE
)
14234 /* Variable offset. */
14235 list_ret1
= loc_list_from_tree (offset
, 0);
14236 if (list_ret1
== 0)
14238 add_loc_list (&list_ret
, list_ret1
);
14241 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14244 bytepos
= bitpos
/ BITS_PER_UNIT
;
14246 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14247 else if (bytepos
< 0)
14248 loc_list_plus_const (list_ret
, bytepos
);
14255 if ((want_address
|| !tree_fits_shwi_p (loc
))
14256 && (ret
= cst_pool_loc_descr (loc
)))
14258 else if (want_address
== 2
14259 && tree_fits_shwi_p (loc
)
14260 && (ret
= address_of_int_loc_descriptor
14261 (int_size_in_bytes (TREE_TYPE (loc
)),
14262 tree_to_shwi (loc
))))
14264 else if (tree_fits_shwi_p (loc
))
14265 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14268 expansion_failed (loc
, NULL_RTX
,
14269 "Integer operand is not host integer");
14278 if ((ret
= cst_pool_loc_descr (loc
)))
14281 /* We can construct small constants here using int_loc_descriptor. */
14282 expansion_failed (loc
, NULL_RTX
,
14283 "constructor or constant not in constant pool");
14286 case TRUTH_AND_EXPR
:
14287 case TRUTH_ANDIF_EXPR
:
14292 case TRUTH_XOR_EXPR
:
14297 case TRUTH_OR_EXPR
:
14298 case TRUTH_ORIF_EXPR
:
14303 case FLOOR_DIV_EXPR
:
14304 case CEIL_DIV_EXPR
:
14305 case ROUND_DIV_EXPR
:
14306 case TRUNC_DIV_EXPR
:
14307 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14316 case FLOOR_MOD_EXPR
:
14317 case CEIL_MOD_EXPR
:
14318 case ROUND_MOD_EXPR
:
14319 case TRUNC_MOD_EXPR
:
14320 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14325 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14326 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14327 if (list_ret
== 0 || list_ret1
== 0)
14330 add_loc_list (&list_ret
, list_ret1
);
14333 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14334 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14335 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14336 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14337 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14349 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14352 case POINTER_PLUS_EXPR
:
14354 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14356 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14360 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14368 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14375 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14382 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14389 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14404 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14405 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14406 if (list_ret
== 0 || list_ret1
== 0)
14409 add_loc_list (&list_ret
, list_ret1
);
14412 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14415 case TRUTH_NOT_EXPR
:
14429 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14433 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14439 const enum tree_code code
=
14440 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14442 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14443 build2 (code
, integer_type_node
,
14444 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14445 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14448 /* ... fall through ... */
14452 dw_loc_descr_ref lhs
14453 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14454 dw_loc_list_ref rhs
14455 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14456 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14458 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14459 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14462 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14463 add_loc_descr_to_each (list_ret
, bra_node
);
14465 add_loc_list (&list_ret
, rhs
);
14466 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14467 add_loc_descr_to_each (list_ret
, jump_node
);
14469 add_loc_descr_to_each (list_ret
, lhs
);
14470 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14471 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14473 /* ??? Need a node to point the skip at. Use a nop. */
14474 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14475 add_loc_descr_to_each (list_ret
, tmp
);
14476 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14477 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14481 case FIX_TRUNC_EXPR
:
14485 /* Leave front-end specific codes as simply unknown. This comes
14486 up, for instance, with the C STMT_EXPR. */
14487 if ((unsigned int) TREE_CODE (loc
)
14488 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14490 expansion_failed (loc
, NULL_RTX
,
14491 "language specific tree node");
14495 #ifdef ENABLE_CHECKING
14496 /* Otherwise this is a generic code; we should just lists all of
14497 these explicitly. We forgot one. */
14498 gcc_unreachable ();
14500 /* In a release build, we want to degrade gracefully: better to
14501 generate incomplete debugging information than to crash. */
14506 if (!ret
&& !list_ret
)
14509 if (want_address
== 2 && !have_address
14510 && (dwarf_version
>= 4 || !dwarf_strict
))
14512 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14514 expansion_failed (loc
, NULL_RTX
,
14515 "DWARF address size mismatch");
14519 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14521 add_loc_descr_to_each (list_ret
,
14522 new_loc_descr (DW_OP_stack_value
, 0, 0));
14525 /* Show if we can't fill the request for an address. */
14526 if (want_address
&& !have_address
)
14528 expansion_failed (loc
, NULL_RTX
,
14529 "Want address and only have value");
14533 gcc_assert (!ret
|| !list_ret
);
14535 /* If we've got an address and don't want one, dereference. */
14536 if (!want_address
&& have_address
)
14538 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14540 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14542 expansion_failed (loc
, NULL_RTX
,
14543 "DWARF address size mismatch");
14546 else if (size
== DWARF2_ADDR_SIZE
)
14549 op
= DW_OP_deref_size
;
14552 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14554 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14557 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14562 /* Same as above but return only single location expression. */
14563 static dw_loc_descr_ref
14564 loc_descriptor_from_tree (tree loc
, int want_address
)
14566 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14569 if (ret
->dw_loc_next
)
14571 expansion_failed (loc
, NULL_RTX
,
14572 "Location list where only loc descriptor needed");
14578 /* Given a value, round it up to the lowest multiple of `boundary'
14579 which is not less than the value itself. */
14581 static inline HOST_WIDE_INT
14582 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14584 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14587 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14588 pointer to the declared type for the relevant field variable, or return
14589 `integer_type_node' if the given node turns out to be an
14590 ERROR_MARK node. */
14593 field_type (const_tree decl
)
14597 if (TREE_CODE (decl
) == ERROR_MARK
)
14598 return integer_type_node
;
14600 type
= DECL_BIT_FIELD_TYPE (decl
);
14601 if (type
== NULL_TREE
)
14602 type
= TREE_TYPE (decl
);
14607 /* Given a pointer to a tree node, return the alignment in bits for
14608 it, or else return BITS_PER_WORD if the node actually turns out to
14609 be an ERROR_MARK node. */
14611 static inline unsigned
14612 simple_type_align_in_bits (const_tree type
)
14614 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14617 static inline unsigned
14618 simple_decl_align_in_bits (const_tree decl
)
14620 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14623 /* Return the result of rounding T up to ALIGN. */
14625 static inline double_int
14626 round_up_to_align (double_int t
, unsigned int align
)
14628 double_int alignd
= double_int::from_uhwi (align
);
14630 t
+= double_int_minus_one
;
14631 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14636 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14637 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14638 or return 0 if we are unable to determine what that offset is, either
14639 because the argument turns out to be a pointer to an ERROR_MARK node, or
14640 because the offset is actually variable. (We can't handle the latter case
14643 static HOST_WIDE_INT
14644 field_byte_offset (const_tree decl
)
14646 double_int object_offset_in_bits
;
14647 double_int object_offset_in_bytes
;
14648 double_int bitpos_int
;
14650 if (TREE_CODE (decl
) == ERROR_MARK
)
14653 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14655 /* We cannot yet cope with fields whose positions are variable, so
14656 for now, when we see such things, we simply return 0. Someday, we may
14657 be able to handle such cases, but it will be damn difficult. */
14658 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14661 bitpos_int
= tree_to_double_int (bit_position (decl
));
14663 #ifdef PCC_BITFIELD_TYPE_MATTERS
14664 if (PCC_BITFIELD_TYPE_MATTERS
)
14667 tree field_size_tree
;
14668 double_int deepest_bitpos
;
14669 double_int field_size_in_bits
;
14670 unsigned int type_align_in_bits
;
14671 unsigned int decl_align_in_bits
;
14672 double_int type_size_in_bits
;
14674 type
= field_type (decl
);
14675 type_size_in_bits
= double_int_type_size_in_bits (type
);
14676 type_align_in_bits
= simple_type_align_in_bits (type
);
14678 field_size_tree
= DECL_SIZE (decl
);
14680 /* The size could be unspecified if there was an error, or for
14681 a flexible array member. */
14682 if (!field_size_tree
)
14683 field_size_tree
= bitsize_zero_node
;
14685 /* If the size of the field is not constant, use the type size. */
14686 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14687 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14689 field_size_in_bits
= type_size_in_bits
;
14691 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14693 /* The GCC front-end doesn't make any attempt to keep track of the
14694 starting bit offset (relative to the start of the containing
14695 structure type) of the hypothetical "containing object" for a
14696 bit-field. Thus, when computing the byte offset value for the
14697 start of the "containing object" of a bit-field, we must deduce
14698 this information on our own. This can be rather tricky to do in
14699 some cases. For example, handling the following structure type
14700 definition when compiling for an i386/i486 target (which only
14701 aligns long long's to 32-bit boundaries) can be very tricky:
14703 struct S { int field1; long long field2:31; };
14705 Fortunately, there is a simple rule-of-thumb which can be used
14706 in such cases. When compiling for an i386/i486, GCC will
14707 allocate 8 bytes for the structure shown above. It decides to
14708 do this based upon one simple rule for bit-field allocation.
14709 GCC allocates each "containing object" for each bit-field at
14710 the first (i.e. lowest addressed) legitimate alignment boundary
14711 (based upon the required minimum alignment for the declared
14712 type of the field) which it can possibly use, subject to the
14713 condition that there is still enough available space remaining
14714 in the containing object (when allocated at the selected point)
14715 to fully accommodate all of the bits of the bit-field itself.
14717 This simple rule makes it obvious why GCC allocates 8 bytes for
14718 each object of the structure type shown above. When looking
14719 for a place to allocate the "containing object" for `field2',
14720 the compiler simply tries to allocate a 64-bit "containing
14721 object" at each successive 32-bit boundary (starting at zero)
14722 until it finds a place to allocate that 64- bit field such that
14723 at least 31 contiguous (and previously unallocated) bits remain
14724 within that selected 64 bit field. (As it turns out, for the
14725 example above, the compiler finds it is OK to allocate the
14726 "containing object" 64-bit field at bit-offset zero within the
14729 Here we attempt to work backwards from the limited set of facts
14730 we're given, and we try to deduce from those facts, where GCC
14731 must have believed that the containing object started (within
14732 the structure type). The value we deduce is then used (by the
14733 callers of this routine) to generate DW_AT_location and
14734 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14735 the case of DW_AT_location, regular fields as well). */
14737 /* Figure out the bit-distance from the start of the structure to
14738 the "deepest" bit of the bit-field. */
14739 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14741 /* This is the tricky part. Use some fancy footwork to deduce
14742 where the lowest addressed bit of the containing object must
14744 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14746 /* Round up to type_align by default. This works best for
14748 object_offset_in_bits
14749 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14751 if (object_offset_in_bits
.ugt (bitpos_int
))
14753 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14755 /* Round up to decl_align instead. */
14756 object_offset_in_bits
14757 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14761 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14762 object_offset_in_bits
= bitpos_int
;
14764 object_offset_in_bytes
14765 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14766 true, TRUNC_DIV_EXPR
);
14767 return object_offset_in_bytes
.to_shwi ();
14770 /* The following routines define various Dwarf attributes and any data
14771 associated with them. */
14773 /* Add a location description attribute value to a DIE.
14775 This emits location attributes suitable for whole variables and
14776 whole parameters. Note that the location attributes for struct fields are
14777 generated by the routine `data_member_location_attribute' below. */
14780 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14781 dw_loc_list_ref descr
)
14785 if (single_element_loc_list_p (descr
))
14786 add_AT_loc (die
, attr_kind
, descr
->expr
);
14788 add_AT_loc_list (die
, attr_kind
, descr
);
14791 /* Add DW_AT_accessibility attribute to DIE if needed. */
14794 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14796 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14797 children, otherwise the default is DW_ACCESS_public. In DWARF2
14798 the default has always been DW_ACCESS_public. */
14799 if (TREE_PROTECTED (decl
))
14800 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14801 else if (TREE_PRIVATE (decl
))
14803 if (dwarf_version
== 2
14804 || die
->die_parent
== NULL
14805 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14806 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14808 else if (dwarf_version
> 2
14810 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14811 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14814 /* Attach the specialized form of location attribute used for data members of
14815 struct and union types. In the special case of a FIELD_DECL node which
14816 represents a bit-field, the "offset" part of this special location
14817 descriptor must indicate the distance in bytes from the lowest-addressed
14818 byte of the containing struct or union type to the lowest-addressed byte of
14819 the "containing object" for the bit-field. (See the `field_byte_offset'
14822 For any given bit-field, the "containing object" is a hypothetical object
14823 (of some integral or enum type) within which the given bit-field lives. The
14824 type of this hypothetical "containing object" is always the same as the
14825 declared type of the individual bit-field itself (for GCC anyway... the
14826 DWARF spec doesn't actually mandate this). Note that it is the size (in
14827 bytes) of the hypothetical "containing object" which will be given in the
14828 DW_AT_byte_size attribute for this bit-field. (See the
14829 `byte_size_attribute' function below.) It is also used when calculating the
14830 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14831 function below.) */
14834 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14836 HOST_WIDE_INT offset
;
14837 dw_loc_descr_ref loc_descr
= 0;
14839 if (TREE_CODE (decl
) == TREE_BINFO
)
14841 /* We're working on the TAG_inheritance for a base class. */
14842 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14844 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14845 aren't at a fixed offset from all (sub)objects of the same
14846 type. We need to extract the appropriate offset from our
14847 vtable. The following dwarf expression means
14849 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14851 This is specific to the V3 ABI, of course. */
14853 dw_loc_descr_ref tmp
;
14855 /* Make a copy of the object address. */
14856 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14857 add_loc_descr (&loc_descr
, tmp
);
14859 /* Extract the vtable address. */
14860 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14861 add_loc_descr (&loc_descr
, tmp
);
14863 /* Calculate the address of the offset. */
14864 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
14865 gcc_assert (offset
< 0);
14867 tmp
= int_loc_descriptor (-offset
);
14868 add_loc_descr (&loc_descr
, tmp
);
14869 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14870 add_loc_descr (&loc_descr
, tmp
);
14872 /* Extract the offset. */
14873 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14874 add_loc_descr (&loc_descr
, tmp
);
14876 /* Add it to the object address. */
14877 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14878 add_loc_descr (&loc_descr
, tmp
);
14881 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
14884 offset
= field_byte_offset (decl
);
14888 if (dwarf_version
> 2)
14890 /* Don't need to output a location expression, just the constant. */
14892 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14894 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14899 enum dwarf_location_atom op
;
14901 /* The DWARF2 standard says that we should assume that the structure
14902 address is already on the stack, so we can specify a structure
14903 field address by using DW_OP_plus_uconst. */
14904 op
= DW_OP_plus_uconst
;
14905 loc_descr
= new_loc_descr (op
, offset
, 0);
14909 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14912 /* Writes integer values to dw_vec_const array. */
14915 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14919 *dest
++ = val
& 0xff;
14925 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14927 static HOST_WIDE_INT
14928 extract_int (const unsigned char *src
, unsigned int size
)
14930 HOST_WIDE_INT val
= 0;
14936 val
|= *--src
& 0xff;
14942 /* Writes double_int values to dw_vec_const array. */
14945 insert_double (double_int val
, unsigned char *dest
)
14947 unsigned char *p0
= dest
;
14948 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14950 if (WORDS_BIG_ENDIAN
)
14956 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14957 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14960 /* Writes floating point values to dw_vec_const array. */
14963 insert_float (const_rtx rtl
, unsigned char *array
)
14965 REAL_VALUE_TYPE rv
;
14969 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14970 real_to_target (val
, &rv
, GET_MODE (rtl
));
14972 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14973 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14975 insert_int (val
[i
], 4, array
);
14980 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14981 does not have a "location" either in memory or in a register. These
14982 things can arise in GNU C when a constant is passed as an actual parameter
14983 to an inlined function. They can also arise in C++ where declared
14984 constants do not necessarily get memory "homes". */
14987 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14989 switch (GET_CODE (rtl
))
14993 HOST_WIDE_INT val
= INTVAL (rtl
);
14996 add_AT_int (die
, DW_AT_const_value
, val
);
14998 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15003 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15004 floating-point constant. A CONST_DOUBLE is used whenever the
15005 constant requires more than one word in order to be adequately
15008 enum machine_mode mode
= GET_MODE (rtl
);
15010 if (SCALAR_FLOAT_MODE_P (mode
))
15012 unsigned int length
= GET_MODE_SIZE (mode
);
15013 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15015 insert_float (rtl
, array
);
15016 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15019 add_AT_double (die
, DW_AT_const_value
,
15020 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15026 enum machine_mode mode
= GET_MODE (rtl
);
15027 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15028 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15029 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15030 (length
* elt_size
);
15034 switch (GET_MODE_CLASS (mode
))
15036 case MODE_VECTOR_INT
:
15037 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15039 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15040 double_int val
= rtx_to_double_int (elt
);
15042 if (elt_size
<= sizeof (HOST_WIDE_INT
))
15043 insert_int (val
.to_shwi (), elt_size
, p
);
15046 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
15047 insert_double (val
, p
);
15052 case MODE_VECTOR_FLOAT
:
15053 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15055 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15056 insert_float (elt
, p
);
15061 gcc_unreachable ();
15064 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15069 if (dwarf_version
>= 4 || !dwarf_strict
)
15071 dw_loc_descr_ref loc_result
;
15072 resolve_one_addr (&rtl
, NULL
);
15074 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15075 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15076 add_AT_loc (die
, DW_AT_location
, loc_result
);
15077 vec_safe_push (used_rtx_array
, rtl
);
15083 if (CONSTANT_P (XEXP (rtl
, 0)))
15084 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15087 if (!const_ok_for_output (rtl
))
15090 if (dwarf_version
>= 4 || !dwarf_strict
)
15095 /* In cases where an inlined instance of an inline function is passed
15096 the address of an `auto' variable (which is local to the caller) we
15097 can get a situation where the DECL_RTL of the artificial local
15098 variable (for the inlining) which acts as a stand-in for the
15099 corresponding formal parameter (of the inline function) will look
15100 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15101 exactly a compile-time constant expression, but it isn't the address
15102 of the (artificial) local variable either. Rather, it represents the
15103 *value* which the artificial local variable always has during its
15104 lifetime. We currently have no way to represent such quasi-constant
15105 values in Dwarf, so for now we just punt and generate nothing. */
15113 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15114 && MEM_READONLY_P (rtl
)
15115 && GET_MODE (rtl
) == BLKmode
)
15117 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15123 /* No other kinds of rtx should be possible here. */
15124 gcc_unreachable ();
15129 /* Determine whether the evaluation of EXPR references any variables
15130 or functions which aren't otherwise used (and therefore may not be
15133 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15134 void * data ATTRIBUTE_UNUSED
)
15136 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15137 *walk_subtrees
= 0;
15139 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15140 && ! TREE_ASM_WRITTEN (*tp
))
15142 /* ??? The C++ FE emits debug information for using decls, so
15143 putting gcc_unreachable here falls over. See PR31899. For now
15144 be conservative. */
15145 else if (!cgraph_global_info_ready
15146 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15148 else if (TREE_CODE (*tp
) == VAR_DECL
)
15150 struct varpool_node
*node
= varpool_get_node (*tp
);
15151 if (!node
|| !node
->definition
)
15154 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15155 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15157 /* The call graph machinery must have finished analyzing,
15158 optimizing and gimplifying the CU by now.
15159 So if *TP has no call graph node associated
15160 to it, it means *TP will not be emitted. */
15161 if (!cgraph_get_node (*tp
))
15164 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15170 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15171 for use in a later add_const_value_attribute call. */
15174 rtl_for_decl_init (tree init
, tree type
)
15176 rtx rtl
= NULL_RTX
;
15180 /* If a variable is initialized with a string constant without embedded
15181 zeros, build CONST_STRING. */
15182 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15184 tree enttype
= TREE_TYPE (type
);
15185 tree domain
= TYPE_DOMAIN (type
);
15186 enum machine_mode mode
= TYPE_MODE (enttype
);
15188 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15190 && integer_zerop (TYPE_MIN_VALUE (domain
))
15191 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15192 TREE_STRING_LENGTH (init
) - 1) == 0
15193 && ((size_t) TREE_STRING_LENGTH (init
)
15194 == strlen (TREE_STRING_POINTER (init
)) + 1))
15196 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15197 ggc_strdup (TREE_STRING_POINTER (init
)));
15198 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15199 MEM_READONLY_P (rtl
) = 1;
15202 /* Other aggregates, and complex values, could be represented using
15204 else if (AGGREGATE_TYPE_P (type
)
15205 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15206 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15207 || TREE_CODE (type
) == COMPLEX_TYPE
)
15209 /* Vectors only work if their mode is supported by the target.
15210 FIXME: generic vectors ought to work too. */
15211 else if (TREE_CODE (type
) == VECTOR_TYPE
15212 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15214 /* If the initializer is something that we know will expand into an
15215 immediate RTL constant, expand it now. We must be careful not to
15216 reference variables which won't be output. */
15217 else if (initializer_constant_valid_p (init
, type
)
15218 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15220 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15222 if (TREE_CODE (type
) == VECTOR_TYPE
)
15223 switch (TREE_CODE (init
))
15228 if (TREE_CONSTANT (init
))
15230 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15231 bool constant_p
= true;
15233 unsigned HOST_WIDE_INT ix
;
15235 /* Even when ctor is constant, it might contain non-*_CST
15236 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15237 belong into VECTOR_CST nodes. */
15238 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15239 if (!CONSTANT_CLASS_P (value
))
15241 constant_p
= false;
15247 init
= build_vector_from_ctor (type
, elts
);
15257 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15259 /* If expand_expr returns a MEM, it wasn't immediate. */
15260 gcc_assert (!rtl
|| !MEM_P (rtl
));
15266 /* Generate RTL for the variable DECL to represent its location. */
15269 rtl_for_decl_location (tree decl
)
15273 /* Here we have to decide where we are going to say the parameter "lives"
15274 (as far as the debugger is concerned). We only have a couple of
15275 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15277 DECL_RTL normally indicates where the parameter lives during most of the
15278 activation of the function. If optimization is enabled however, this
15279 could be either NULL or else a pseudo-reg. Both of those cases indicate
15280 that the parameter doesn't really live anywhere (as far as the code
15281 generation parts of GCC are concerned) during most of the function's
15282 activation. That will happen (for example) if the parameter is never
15283 referenced within the function.
15285 We could just generate a location descriptor here for all non-NULL
15286 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15287 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15288 where DECL_RTL is NULL or is a pseudo-reg.
15290 Note however that we can only get away with using DECL_INCOMING_RTL as
15291 a backup substitute for DECL_RTL in certain limited cases. In cases
15292 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15293 we can be sure that the parameter was passed using the same type as it is
15294 declared to have within the function, and that its DECL_INCOMING_RTL
15295 points us to a place where a value of that type is passed.
15297 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15298 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15299 because in these cases DECL_INCOMING_RTL points us to a value of some
15300 type which is *different* from the type of the parameter itself. Thus,
15301 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15302 such cases, the debugger would end up (for example) trying to fetch a
15303 `float' from a place which actually contains the first part of a
15304 `double'. That would lead to really incorrect and confusing
15305 output at debug-time.
15307 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15308 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15309 are a couple of exceptions however. On little-endian machines we can
15310 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15311 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15312 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15313 when (on a little-endian machine) a non-prototyped function has a
15314 parameter declared to be of type `short' or `char'. In such cases,
15315 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15316 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15317 passed `int' value. If the debugger then uses that address to fetch
15318 a `short' or a `char' (on a little-endian machine) the result will be
15319 the correct data, so we allow for such exceptional cases below.
15321 Note that our goal here is to describe the place where the given formal
15322 parameter lives during most of the function's activation (i.e. between the
15323 end of the prologue and the start of the epilogue). We'll do that as best
15324 as we can. Note however that if the given formal parameter is modified
15325 sometime during the execution of the function, then a stack backtrace (at
15326 debug-time) will show the function as having been called with the *new*
15327 value rather than the value which was originally passed in. This happens
15328 rarely enough that it is not a major problem, but it *is* a problem, and
15329 I'd like to fix it.
15331 A future version of dwarf2out.c may generate two additional attributes for
15332 any given DW_TAG_formal_parameter DIE which will describe the "passed
15333 type" and the "passed location" for the given formal parameter in addition
15334 to the attributes we now generate to indicate the "declared type" and the
15335 "active location" for each parameter. This additional set of attributes
15336 could be used by debuggers for stack backtraces. Separately, note that
15337 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15338 This happens (for example) for inlined-instances of inline function formal
15339 parameters which are never referenced. This really shouldn't be
15340 happening. All PARM_DECL nodes should get valid non-NULL
15341 DECL_INCOMING_RTL values. FIXME. */
15343 /* Use DECL_RTL as the "location" unless we find something better. */
15344 rtl
= DECL_RTL_IF_SET (decl
);
15346 /* When generating abstract instances, ignore everything except
15347 constants, symbols living in memory, and symbols living in
15348 fixed registers. */
15349 if (! reload_completed
)
15352 && (CONSTANT_P (rtl
)
15354 && CONSTANT_P (XEXP (rtl
, 0)))
15356 && TREE_CODE (decl
) == VAR_DECL
15357 && TREE_STATIC (decl
))))
15359 rtl
= targetm
.delegitimize_address (rtl
);
15364 else if (TREE_CODE (decl
) == PARM_DECL
)
15366 if (rtl
== NULL_RTX
15367 || is_pseudo_reg (rtl
)
15369 && is_pseudo_reg (XEXP (rtl
, 0))
15370 && DECL_INCOMING_RTL (decl
)
15371 && MEM_P (DECL_INCOMING_RTL (decl
))
15372 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15374 tree declared_type
= TREE_TYPE (decl
);
15375 tree passed_type
= DECL_ARG_TYPE (decl
);
15376 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15377 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15379 /* This decl represents a formal parameter which was optimized out.
15380 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15381 all cases where (rtl == NULL_RTX) just below. */
15382 if (dmode
== pmode
)
15383 rtl
= DECL_INCOMING_RTL (decl
);
15384 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15385 && SCALAR_INT_MODE_P (dmode
)
15386 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15387 && DECL_INCOMING_RTL (decl
))
15389 rtx inc
= DECL_INCOMING_RTL (decl
);
15392 else if (MEM_P (inc
))
15394 if (BYTES_BIG_ENDIAN
)
15395 rtl
= adjust_address_nv (inc
, dmode
,
15396 GET_MODE_SIZE (pmode
)
15397 - GET_MODE_SIZE (dmode
));
15404 /* If the parm was passed in registers, but lives on the stack, then
15405 make a big endian correction if the mode of the type of the
15406 parameter is not the same as the mode of the rtl. */
15407 /* ??? This is the same series of checks that are made in dbxout.c before
15408 we reach the big endian correction code there. It isn't clear if all
15409 of these checks are necessary here, but keeping them all is the safe
15411 else if (MEM_P (rtl
)
15412 && XEXP (rtl
, 0) != const0_rtx
15413 && ! CONSTANT_P (XEXP (rtl
, 0))
15414 /* Not passed in memory. */
15415 && !MEM_P (DECL_INCOMING_RTL (decl
))
15416 /* Not passed by invisible reference. */
15417 && (!REG_P (XEXP (rtl
, 0))
15418 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15419 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15420 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15421 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15424 /* Big endian correction check. */
15425 && BYTES_BIG_ENDIAN
15426 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15427 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15430 enum machine_mode addr_mode
= get_address_mode (rtl
);
15431 int offset
= (UNITS_PER_WORD
15432 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15434 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15435 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15438 else if (TREE_CODE (decl
) == VAR_DECL
15441 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15442 && BYTES_BIG_ENDIAN
)
15444 enum machine_mode addr_mode
= get_address_mode (rtl
);
15445 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15446 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15448 /* If a variable is declared "register" yet is smaller than
15449 a register, then if we store the variable to memory, it
15450 looks like we're storing a register-sized value, when in
15451 fact we are not. We need to adjust the offset of the
15452 storage location to reflect the actual value's bytes,
15453 else gdb will not be able to display it. */
15455 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15456 plus_constant (addr_mode
, XEXP (rtl
, 0),
15460 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15461 and will have been substituted directly into all expressions that use it.
15462 C does not have such a concept, but C++ and other languages do. */
15463 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15464 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15467 rtl
= targetm
.delegitimize_address (rtl
);
15469 /* If we don't look past the constant pool, we risk emitting a
15470 reference to a constant pool entry that isn't referenced from
15471 code, and thus is not emitted. */
15473 rtl
= avoid_constant_pool_reference (rtl
);
15475 /* Try harder to get a rtl. If this symbol ends up not being emitted
15476 in the current CU, resolve_addr will remove the expression referencing
15478 if (rtl
== NULL_RTX
15479 && TREE_CODE (decl
) == VAR_DECL
15480 && !DECL_EXTERNAL (decl
)
15481 && TREE_STATIC (decl
)
15482 && DECL_NAME (decl
)
15483 && !DECL_HARD_REGISTER (decl
)
15484 && DECL_MODE (decl
) != VOIDmode
)
15486 rtl
= make_decl_rtl_for_debug (decl
);
15488 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15489 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15496 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15497 returned. If so, the decl for the COMMON block is returned, and the
15498 value is the offset into the common block for the symbol. */
15501 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15503 tree val_expr
, cvar
;
15504 enum machine_mode mode
;
15505 HOST_WIDE_INT bitsize
, bitpos
;
15507 int unsignedp
, volatilep
= 0;
15509 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15510 it does not have a value (the offset into the common area), or if it
15511 is thread local (as opposed to global) then it isn't common, and shouldn't
15512 be handled as such. */
15513 if (TREE_CODE (decl
) != VAR_DECL
15514 || !TREE_STATIC (decl
)
15515 || !DECL_HAS_VALUE_EXPR_P (decl
)
15519 val_expr
= DECL_VALUE_EXPR (decl
);
15520 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15523 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15524 &mode
, &unsignedp
, &volatilep
, true);
15526 if (cvar
== NULL_TREE
15527 || TREE_CODE (cvar
) != VAR_DECL
15528 || DECL_ARTIFICIAL (cvar
)
15529 || !TREE_PUBLIC (cvar
))
15533 if (offset
!= NULL
)
15535 if (!tree_fits_shwi_p (offset
))
15537 *value
= tree_to_shwi (offset
);
15540 *value
+= bitpos
/ BITS_PER_UNIT
;
15545 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15546 data attribute for a variable or a parameter. We generate the
15547 DW_AT_const_value attribute only in those cases where the given variable
15548 or parameter does not have a true "location" either in memory or in a
15549 register. This can happen (for example) when a constant is passed as an
15550 actual argument in a call to an inline function. (It's possible that
15551 these things can crop up in other ways also.) Note that one type of
15552 constant value which can be passed into an inlined function is a constant
15553 pointer. This can happen for example if an actual argument in an inlined
15554 function call evaluates to a compile-time constant address.
15556 CACHE_P is true if it is worth caching the location list for DECL,
15557 so that future calls can reuse it rather than regenerate it from scratch.
15558 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15559 since we will need to refer to them each time the function is inlined. */
15562 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15563 enum dwarf_attribute attr
)
15566 dw_loc_list_ref list
;
15567 var_loc_list
*loc_list
;
15568 cached_dw_loc_list
*cache
;
15571 if (TREE_CODE (decl
) == ERROR_MARK
)
15574 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15575 || TREE_CODE (decl
) == RESULT_DECL
);
15577 /* Try to get some constant RTL for this decl, and use that as the value of
15580 rtl
= rtl_for_decl_location (decl
);
15581 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15582 && add_const_value_attribute (die
, rtl
))
15585 /* See if we have single element location list that is equivalent to
15586 a constant value. That way we are better to use add_const_value_attribute
15587 rather than expanding constant value equivalent. */
15588 loc_list
= lookup_decl_loc (decl
);
15591 && loc_list
->first
->next
== NULL
15592 && NOTE_P (loc_list
->first
->loc
)
15593 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15594 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15596 struct var_loc_node
*node
;
15598 node
= loc_list
->first
;
15599 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15600 if (GET_CODE (rtl
) == EXPR_LIST
)
15601 rtl
= XEXP (rtl
, 0);
15602 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15603 && add_const_value_attribute (die
, rtl
))
15606 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15607 list several times. See if we've already cached the contents. */
15609 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15613 cache
= (cached_dw_loc_list
*)
15614 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15616 list
= cache
->loc_list
;
15620 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15621 /* It is usually worth caching this result if the decl is from
15622 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15623 if (cache_p
&& list
&& list
->dw_loc_next
)
15625 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15626 DECL_UID (decl
), INSERT
);
15627 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15628 cache
->decl_id
= DECL_UID (decl
);
15629 cache
->loc_list
= list
;
15635 add_AT_location_description (die
, attr
, list
);
15638 /* None of that worked, so it must not really have a location;
15639 try adding a constant value attribute from the DECL_INITIAL. */
15640 return tree_add_const_value_attribute_for_decl (die
, decl
);
15643 /* Add VARIABLE and DIE into deferred locations list. */
15646 defer_location (tree variable
, dw_die_ref die
)
15648 deferred_locations entry
;
15649 entry
.variable
= variable
;
15651 vec_safe_push (deferred_locations_list
, entry
);
15654 /* Helper function for tree_add_const_value_attribute. Natively encode
15655 initializer INIT into an array. Return true if successful. */
15658 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15662 if (init
== NULL_TREE
)
15666 switch (TREE_CODE (init
))
15669 type
= TREE_TYPE (init
);
15670 if (TREE_CODE (type
) == ARRAY_TYPE
)
15672 tree enttype
= TREE_TYPE (type
);
15673 enum machine_mode mode
= TYPE_MODE (enttype
);
15675 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15677 if (int_size_in_bytes (type
) != size
)
15679 if (size
> TREE_STRING_LENGTH (init
))
15681 memcpy (array
, TREE_STRING_POINTER (init
),
15682 TREE_STRING_LENGTH (init
));
15683 memset (array
+ TREE_STRING_LENGTH (init
),
15684 '\0', size
- TREE_STRING_LENGTH (init
));
15687 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15692 type
= TREE_TYPE (init
);
15693 if (int_size_in_bytes (type
) != size
)
15695 if (TREE_CODE (type
) == ARRAY_TYPE
)
15697 HOST_WIDE_INT min_index
;
15698 unsigned HOST_WIDE_INT cnt
;
15699 int curpos
= 0, fieldsize
;
15700 constructor_elt
*ce
;
15702 if (TYPE_DOMAIN (type
) == NULL_TREE
15703 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
15706 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15707 if (fieldsize
<= 0)
15710 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
15711 memset (array
, '\0', size
);
15712 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15714 tree val
= ce
->value
;
15715 tree index
= ce
->index
;
15717 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15718 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
15721 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
15726 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15729 curpos
= pos
+ fieldsize
;
15730 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15732 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
15733 - tree_to_shwi (TREE_OPERAND (index
, 0));
15734 while (count
-- > 0)
15737 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15738 curpos
+= fieldsize
;
15741 gcc_assert (curpos
<= size
);
15745 else if (TREE_CODE (type
) == RECORD_TYPE
15746 || TREE_CODE (type
) == UNION_TYPE
)
15748 tree field
= NULL_TREE
;
15749 unsigned HOST_WIDE_INT cnt
;
15750 constructor_elt
*ce
;
15752 if (int_size_in_bytes (type
) != size
)
15755 if (TREE_CODE (type
) == RECORD_TYPE
)
15756 field
= TYPE_FIELDS (type
);
15758 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15760 tree val
= ce
->value
;
15761 int pos
, fieldsize
;
15763 if (ce
->index
!= 0)
15769 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15772 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15773 && TYPE_DOMAIN (TREE_TYPE (field
))
15774 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15776 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15777 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
15779 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
15780 pos
= int_byte_position (field
);
15781 gcc_assert (pos
+ fieldsize
<= size
);
15783 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15789 case VIEW_CONVERT_EXPR
:
15790 case NON_LVALUE_EXPR
:
15791 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15793 return native_encode_expr (init
, array
, size
) == size
;
15797 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15798 attribute is the const value T. */
15801 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15804 tree type
= TREE_TYPE (t
);
15807 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15811 gcc_assert (!DECL_P (init
));
15813 rtl
= rtl_for_decl_init (init
, type
);
15815 return add_const_value_attribute (die
, rtl
);
15816 /* If the host and target are sane, try harder. */
15817 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15818 && initializer_constant_valid_p (init
, type
))
15820 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15821 if (size
> 0 && (int) size
== size
)
15823 unsigned char *array
= (unsigned char *)
15824 ggc_alloc_cleared_atomic (size
);
15826 if (native_encode_initializer (init
, array
, size
))
15828 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15837 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15838 attribute is the const value of T, where T is an integral constant
15839 variable with static storage duration
15840 (so it can't be a PARM_DECL or a RESULT_DECL). */
15843 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15847 || (TREE_CODE (decl
) != VAR_DECL
15848 && TREE_CODE (decl
) != CONST_DECL
)
15849 || (TREE_CODE (decl
) == VAR_DECL
15850 && !TREE_STATIC (decl
)))
15853 if (TREE_READONLY (decl
)
15854 && ! TREE_THIS_VOLATILE (decl
)
15855 && DECL_INITIAL (decl
))
15860 /* Don't add DW_AT_const_value if abstract origin already has one. */
15861 if (get_AT (var_die
, DW_AT_const_value
))
15864 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15867 /* Convert the CFI instructions for the current function into a
15868 location list. This is used for DW_AT_frame_base when we targeting
15869 a dwarf2 consumer that does not support the dwarf3
15870 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15873 static dw_loc_list_ref
15874 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15878 dw_loc_list_ref list
, *list_tail
;
15880 dw_cfa_location last_cfa
, next_cfa
;
15881 const char *start_label
, *last_label
, *section
;
15882 dw_cfa_location remember
;
15885 gcc_assert (fde
!= NULL
);
15887 section
= secname_for_decl (current_function_decl
);
15891 memset (&next_cfa
, 0, sizeof (next_cfa
));
15892 next_cfa
.reg
= INVALID_REGNUM
;
15893 remember
= next_cfa
;
15895 start_label
= fde
->dw_fde_begin
;
15897 /* ??? Bald assumption that the CIE opcode list does not contain
15898 advance opcodes. */
15899 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15900 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15902 last_cfa
= next_cfa
;
15903 last_label
= start_label
;
15905 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15907 /* If the first partition contained no CFI adjustments, the
15908 CIE opcodes apply to the whole first partition. */
15909 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15910 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15911 list_tail
=&(*list_tail
)->dw_loc_next
;
15912 start_label
= last_label
= fde
->dw_fde_second_begin
;
15915 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15917 switch (cfi
->dw_cfi_opc
)
15919 case DW_CFA_set_loc
:
15920 case DW_CFA_advance_loc1
:
15921 case DW_CFA_advance_loc2
:
15922 case DW_CFA_advance_loc4
:
15923 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15925 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15926 start_label
, last_label
, section
);
15928 list_tail
= &(*list_tail
)->dw_loc_next
;
15929 last_cfa
= next_cfa
;
15930 start_label
= last_label
;
15932 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15935 case DW_CFA_advance_loc
:
15936 /* The encoding is complex enough that we should never emit this. */
15937 gcc_unreachable ();
15940 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15943 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15945 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15947 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15948 start_label
, last_label
, section
);
15950 list_tail
= &(*list_tail
)->dw_loc_next
;
15951 last_cfa
= next_cfa
;
15952 start_label
= last_label
;
15954 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15955 start_label
, fde
->dw_fde_end
, section
);
15956 list_tail
= &(*list_tail
)->dw_loc_next
;
15957 start_label
= last_label
= fde
->dw_fde_second_begin
;
15961 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15963 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15964 start_label
, last_label
, section
);
15965 list_tail
= &(*list_tail
)->dw_loc_next
;
15966 start_label
= last_label
;
15969 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15971 fde
->dw_fde_second_begin
15972 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15975 if (list
&& list
->dw_loc_next
)
15981 /* Compute a displacement from the "steady-state frame pointer" to the
15982 frame base (often the same as the CFA), and store it in
15983 frame_pointer_fb_offset. OFFSET is added to the displacement
15984 before the latter is negated. */
15987 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15991 #ifdef FRAME_POINTER_CFA_OFFSET
15992 reg
= frame_pointer_rtx
;
15993 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15995 reg
= arg_pointer_rtx
;
15996 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15999 elim
= (ira_use_lra_p
16000 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16001 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16002 if (GET_CODE (elim
) == PLUS
)
16004 offset
+= INTVAL (XEXP (elim
, 1));
16005 elim
= XEXP (elim
, 0);
16008 frame_pointer_fb_offset
= -offset
;
16010 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16011 in which to eliminate. This is because it's stack pointer isn't
16012 directly accessible as a register within the ISA. To work around
16013 this, assume that while we cannot provide a proper value for
16014 frame_pointer_fb_offset, we won't need one either. */
16015 frame_pointer_fb_offset_valid
16016 = ((SUPPORTS_STACK_ALIGNMENT
16017 && (elim
== hard_frame_pointer_rtx
16018 || elim
== stack_pointer_rtx
))
16019 || elim
== (frame_pointer_needed
16020 ? hard_frame_pointer_rtx
16021 : stack_pointer_rtx
));
16024 /* Generate a DW_AT_name attribute given some string value to be included as
16025 the value of the attribute. */
16028 add_name_attribute (dw_die_ref die
, const char *name_string
)
16030 if (name_string
!= NULL
&& *name_string
!= 0)
16032 if (demangle_name_func
)
16033 name_string
= (*demangle_name_func
) (name_string
);
16035 add_AT_string (die
, DW_AT_name
, name_string
);
16039 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16040 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16041 of TYPE accordingly.
16043 ??? This is a temporary measure until after we're able to generate
16044 regular DWARF for the complex Ada type system. */
16047 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16048 dw_die_ref context_die
)
16051 dw_die_ref dtype_die
;
16053 if (!lang_hooks
.types
.descriptive_type
)
16056 dtype
= lang_hooks
.types
.descriptive_type (type
);
16060 dtype_die
= lookup_type_die (dtype
);
16063 gen_type_die (dtype
, context_die
);
16064 dtype_die
= lookup_type_die (dtype
);
16065 gcc_assert (dtype_die
);
16068 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16071 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16073 static const char *
16074 comp_dir_string (void)
16078 static const char *cached_wd
= NULL
;
16080 if (cached_wd
!= NULL
)
16083 wd
= get_src_pwd ();
16087 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16091 wdlen
= strlen (wd
);
16092 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16094 wd1
[wdlen
] = DIR_SEPARATOR
;
16095 wd1
[wdlen
+ 1] = 0;
16099 cached_wd
= remap_debug_filename (wd
);
16103 /* Generate a DW_AT_comp_dir attribute for DIE. */
16106 add_comp_dir_attribute (dw_die_ref die
)
16108 const char * wd
= comp_dir_string ();
16110 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16113 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16117 lower_bound_default (void)
16119 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16124 case DW_LANG_C_plus_plus
:
16126 case DW_LANG_ObjC_plus_plus
:
16129 case DW_LANG_Fortran77
:
16130 case DW_LANG_Fortran90
:
16131 case DW_LANG_Fortran95
:
16135 case DW_LANG_Python
:
16136 return dwarf_version
>= 4 ? 0 : -1;
16137 case DW_LANG_Ada95
:
16138 case DW_LANG_Ada83
:
16139 case DW_LANG_Cobol74
:
16140 case DW_LANG_Cobol85
:
16141 case DW_LANG_Pascal83
:
16142 case DW_LANG_Modula2
:
16144 return dwarf_version
>= 4 ? 1 : -1;
16150 /* Given a tree node describing an array bound (either lower or upper) output
16151 a representation for that bound. */
16154 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16156 switch (TREE_CODE (bound
))
16161 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16164 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16167 /* Use the default if possible. */
16168 if (bound_attr
== DW_AT_lower_bound
16169 && tree_fits_shwi_p (bound
)
16170 && (dflt
= lower_bound_default ()) != -1
16171 && tree_to_shwi (bound
) == dflt
)
16174 /* Otherwise represent the bound as an unsigned value with the
16175 precision of its type. The precision and signedness of the
16176 type will be necessary to re-interpret it unambiguously. */
16177 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16179 unsigned HOST_WIDE_INT mask
16180 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16181 add_AT_unsigned (subrange_die
, bound_attr
,
16182 TREE_INT_CST_LOW (bound
) & mask
);
16184 else if (prec
== HOST_BITS_PER_WIDE_INT
16185 || TREE_INT_CST_HIGH (bound
) == 0)
16186 add_AT_unsigned (subrange_die
, bound_attr
,
16187 TREE_INT_CST_LOW (bound
));
16189 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16190 TREE_INT_CST_LOW (bound
));
16195 case VIEW_CONVERT_EXPR
:
16196 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16206 dw_die_ref decl_die
= lookup_decl_die (bound
);
16208 /* ??? Can this happen, or should the variable have been bound
16209 first? Probably it can, since I imagine that we try to create
16210 the types of parameters in the order in which they exist in
16211 the list, and won't have created a forward reference to a
16212 later parameter. */
16213 if (decl_die
!= NULL
)
16215 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16223 /* Otherwise try to create a stack operation procedure to
16224 evaluate the value of the array bound. */
16226 dw_die_ref ctx
, decl_die
;
16227 dw_loc_list_ref list
;
16229 list
= loc_list_from_tree (bound
, 2);
16230 if (list
== NULL
|| single_element_loc_list_p (list
))
16232 /* If DW_AT_*bound is not a reference nor constant, it is
16233 a DWARF expression rather than location description.
16234 For that loc_list_from_tree (bound, 0) is needed.
16235 If that fails to give a single element list,
16236 fall back to outputting this as a reference anyway. */
16237 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16238 if (list2
&& single_element_loc_list_p (list2
))
16240 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16247 if (current_function_decl
== 0)
16248 ctx
= comp_unit_die ();
16250 ctx
= lookup_decl_die (current_function_decl
);
16252 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16253 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16254 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16255 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16256 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16262 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16263 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16264 Note that the block of subscript information for an array type also
16265 includes information about the element type of the given array type. */
16268 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16270 unsigned dimension_number
;
16272 dw_die_ref subrange_die
;
16274 for (dimension_number
= 0;
16275 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16276 type
= TREE_TYPE (type
), dimension_number
++)
16278 tree domain
= TYPE_DOMAIN (type
);
16280 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16283 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16284 and (in GNU C only) variable bounds. Handle all three forms
16286 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16289 /* We have an array type with specified bounds. */
16290 lower
= TYPE_MIN_VALUE (domain
);
16291 upper
= TYPE_MAX_VALUE (domain
);
16293 /* Define the index type. */
16294 if (TREE_TYPE (domain
))
16296 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16297 TREE_TYPE field. We can't emit debug info for this
16298 because it is an unnamed integral type. */
16299 if (TREE_CODE (domain
) == INTEGER_TYPE
16300 && TYPE_NAME (domain
) == NULL_TREE
16301 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16302 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16305 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16309 /* ??? If upper is NULL, the array has unspecified length,
16310 but it does have a lower bound. This happens with Fortran
16312 Since the debugger is definitely going to need to know N
16313 to produce useful results, go ahead and output the lower
16314 bound solo, and hope the debugger can cope. */
16316 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16318 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16321 /* Otherwise we have an array type with an unspecified length. The
16322 DWARF-2 spec does not say how to handle this; let's just leave out the
16327 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16330 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16332 dw_die_ref decl_die
;
16333 HOST_WIDE_INT size
;
16335 switch (TREE_CODE (tree_node
))
16340 case ENUMERAL_TYPE
:
16343 case QUAL_UNION_TYPE
:
16344 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16345 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16347 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16350 size
= int_size_in_bytes (tree_node
);
16353 /* For a data member of a struct or union, the DW_AT_byte_size is
16354 generally given as the number of bytes normally allocated for an
16355 object of the *declared* type of the member itself. This is true
16356 even for bit-fields. */
16357 size
= int_size_in_bytes (field_type (tree_node
));
16360 gcc_unreachable ();
16363 /* Note that `size' might be -1 when we get to this point. If it is, that
16364 indicates that the byte size of the entity in question is variable. We
16365 have no good way of expressing this fact in Dwarf at the present time,
16366 when location description was not used by the caller code instead. */
16368 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16371 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16372 which specifies the distance in bits from the highest order bit of the
16373 "containing object" for the bit-field to the highest order bit of the
16376 For any given bit-field, the "containing object" is a hypothetical object
16377 (of some integral or enum type) within which the given bit-field lives. The
16378 type of this hypothetical "containing object" is always the same as the
16379 declared type of the individual bit-field itself. The determination of the
16380 exact location of the "containing object" for a bit-field is rather
16381 complicated. It's handled by the `field_byte_offset' function (above).
16383 Note that it is the size (in bytes) of the hypothetical "containing object"
16384 which will be given in the DW_AT_byte_size attribute for this bit-field.
16385 (See `byte_size_attribute' above). */
16388 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16390 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16391 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16392 HOST_WIDE_INT bitpos_int
;
16393 HOST_WIDE_INT highest_order_object_bit_offset
;
16394 HOST_WIDE_INT highest_order_field_bit_offset
;
16395 HOST_WIDE_INT bit_offset
;
16397 /* Must be a field and a bit field. */
16398 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16400 /* We can't yet handle bit-fields whose offsets are variable, so if we
16401 encounter such things, just return without generating any attribute
16402 whatsoever. Likewise for variable or too large size. */
16403 if (! tree_fits_shwi_p (bit_position (decl
))
16404 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
16407 bitpos_int
= int_bit_position (decl
);
16409 /* Note that the bit offset is always the distance (in bits) from the
16410 highest-order bit of the "containing object" to the highest-order bit of
16411 the bit-field itself. Since the "high-order end" of any object or field
16412 is different on big-endian and little-endian machines, the computation
16413 below must take account of these differences. */
16414 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16415 highest_order_field_bit_offset
= bitpos_int
;
16417 if (! BYTES_BIG_ENDIAN
)
16419 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
16420 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16424 = (! BYTES_BIG_ENDIAN
16425 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16426 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16428 if (bit_offset
< 0)
16429 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16431 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16434 /* For a FIELD_DECL node which represents a bit field, output an attribute
16435 which specifies the length in bits of the given field. */
16438 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16440 /* Must be a field and a bit field. */
16441 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16442 && DECL_BIT_FIELD_TYPE (decl
));
16444 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
16445 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
16448 /* If the compiled language is ANSI C, then add a 'prototyped'
16449 attribute, if arg types are given for the parameters of a function. */
16452 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16454 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16455 && prototype_p (func_type
))
16456 add_AT_flag (die
, DW_AT_prototyped
, 1);
16459 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16460 by looking in either the type declaration or object declaration
16463 static inline dw_die_ref
16464 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16466 dw_die_ref origin_die
= NULL
;
16468 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16470 /* We may have gotten separated from the block for the inlined
16471 function, if we're in an exception handler or some such; make
16472 sure that the abstract function has been written out.
16474 Doing this for nested functions is wrong, however; functions are
16475 distinct units, and our context might not even be inline. */
16479 fn
= TYPE_STUB_DECL (fn
);
16481 fn
= decl_function_context (fn
);
16483 dwarf2out_abstract_function (fn
);
16486 if (DECL_P (origin
))
16487 origin_die
= lookup_decl_die (origin
);
16488 else if (TYPE_P (origin
))
16489 origin_die
= lookup_type_die (origin
);
16491 /* XXX: Functions that are never lowered don't always have correct block
16492 trees (in the case of java, they simply have no block tree, in some other
16493 languages). For these functions, there is nothing we can really do to
16494 output correct debug info for inlined functions in all cases. Rather
16495 than die, we'll just produce deficient debug info now, in that we will
16496 have variables without a proper abstract origin. In the future, when all
16497 functions are lowered, we should re-add a gcc_assert (origin_die)
16501 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16505 /* We do not currently support the pure_virtual attribute. */
16508 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16510 if (DECL_VINDEX (func_decl
))
16512 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16514 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
16515 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16516 new_loc_descr (DW_OP_constu
,
16517 tree_to_shwi (DECL_VINDEX (func_decl
)),
16520 /* GNU extension: Record what type this method came from originally. */
16521 if (debug_info_level
> DINFO_LEVEL_TERSE
16522 && DECL_CONTEXT (func_decl
))
16523 add_AT_die_ref (die
, DW_AT_containing_type
,
16524 lookup_type_die (DECL_CONTEXT (func_decl
)));
16528 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16529 given decl. This used to be a vendor extension until after DWARF 4
16530 standardized it. */
16533 add_linkage_attr (dw_die_ref die
, tree decl
)
16535 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16537 /* Mimic what assemble_name_raw does with a leading '*'. */
16538 if (name
[0] == '*')
16541 if (dwarf_version
>= 4)
16542 add_AT_string (die
, DW_AT_linkage_name
, name
);
16544 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16547 /* Add source coordinate attributes for the given decl. */
16550 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16552 expanded_location s
;
16554 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16556 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16557 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16558 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16561 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16564 add_linkage_name (dw_die_ref die
, tree decl
)
16566 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16567 && TREE_PUBLIC (decl
)
16568 && !DECL_ABSTRACT (decl
)
16569 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16570 && die
->die_tag
!= DW_TAG_member
)
16572 /* Defer until we have an assembler name set. */
16573 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16575 limbo_die_node
*asm_name
;
16577 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16578 asm_name
->die
= die
;
16579 asm_name
->created_for
= decl
;
16580 asm_name
->next
= deferred_asm_name
;
16581 deferred_asm_name
= asm_name
;
16583 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16584 add_linkage_attr (die
, decl
);
16588 /* Add a DW_AT_name attribute and source coordinate attribute for the
16589 given decl, but only if it actually has a name. */
16592 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16596 decl_name
= DECL_NAME (decl
);
16597 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16599 const char *name
= dwarf2_name (decl
, 0);
16601 add_name_attribute (die
, name
);
16602 if (! DECL_ARTIFICIAL (decl
))
16603 add_src_coords_attributes (die
, decl
);
16605 add_linkage_name (die
, decl
);
16608 #ifdef VMS_DEBUGGING_INFO
16609 /* Get the function's name, as described by its RTL. This may be different
16610 from the DECL_NAME name used in the source file. */
16611 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16613 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16614 XEXP (DECL_RTL (decl
), 0), false);
16615 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16617 #endif /* VMS_DEBUGGING_INFO */
16620 #ifdef VMS_DEBUGGING_INFO
16621 /* Output the debug main pointer die for VMS */
16624 dwarf2out_vms_debug_main_pointer (void)
16626 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16629 /* Allocate the VMS debug main subprogram die. */
16630 die
= ggc_alloc_cleared_die_node ();
16631 die
->die_tag
= DW_TAG_subprogram
;
16632 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16633 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16634 current_function_funcdef_no
);
16635 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16637 /* Make it the first child of comp_unit_die (). */
16638 die
->die_parent
= comp_unit_die ();
16639 if (comp_unit_die ()->die_child
)
16641 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16642 comp_unit_die ()->die_child
->die_sib
= die
;
16646 die
->die_sib
= die
;
16647 comp_unit_die ()->die_child
= die
;
16650 #endif /* VMS_DEBUGGING_INFO */
16652 /* Push a new declaration scope. */
16655 push_decl_scope (tree scope
)
16657 vec_safe_push (decl_scope_table
, scope
);
16660 /* Pop a declaration scope. */
16663 pop_decl_scope (void)
16665 decl_scope_table
->pop ();
16668 /* walk_tree helper function for uses_local_type, below. */
16671 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16674 *walk_subtrees
= 0;
16677 tree name
= TYPE_NAME (*tp
);
16678 if (name
&& DECL_P (name
) && decl_function_context (name
))
16684 /* If TYPE involves a function-local type (including a local typedef to a
16685 non-local type), returns that type; otherwise returns NULL_TREE. */
16688 uses_local_type (tree type
)
16690 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16694 /* Return the DIE for the scope that immediately contains this type.
16695 Non-named types that do not involve a function-local type get global
16696 scope. Named types nested in namespaces or other types get their
16697 containing scope. All other types (i.e. function-local named types) get
16698 the current active scope. */
16701 scope_die_for (tree t
, dw_die_ref context_die
)
16703 dw_die_ref scope_die
= NULL
;
16704 tree containing_scope
;
16706 /* Non-types always go in the current scope. */
16707 gcc_assert (TYPE_P (t
));
16709 /* Use the scope of the typedef, rather than the scope of the type
16711 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16712 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16714 containing_scope
= TYPE_CONTEXT (t
);
16716 /* Use the containing namespace if there is one. */
16717 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16719 if (context_die
== lookup_decl_die (containing_scope
))
16721 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16722 context_die
= get_context_die (containing_scope
);
16724 containing_scope
= NULL_TREE
;
16727 /* Ignore function type "scopes" from the C frontend. They mean that
16728 a tagged type is local to a parmlist of a function declarator, but
16729 that isn't useful to DWARF. */
16730 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16731 containing_scope
= NULL_TREE
;
16733 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16735 /* If T uses a local type keep it local as well, to avoid references
16736 to function-local DIEs from outside the function. */
16737 if (current_function_decl
&& uses_local_type (t
))
16738 scope_die
= context_die
;
16740 scope_die
= comp_unit_die ();
16742 else if (TYPE_P (containing_scope
))
16744 /* For types, we can just look up the appropriate DIE. */
16745 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16746 scope_die
= get_context_die (containing_scope
);
16749 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16750 if (scope_die
== NULL
)
16751 scope_die
= comp_unit_die ();
16755 scope_die
= context_die
;
16760 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16763 local_scope_p (dw_die_ref context_die
)
16765 for (; context_die
; context_die
= context_die
->die_parent
)
16766 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16767 || context_die
->die_tag
== DW_TAG_subprogram
)
16773 /* Returns nonzero if CONTEXT_DIE is a class. */
16776 class_scope_p (dw_die_ref context_die
)
16778 return (context_die
16779 && (context_die
->die_tag
== DW_TAG_structure_type
16780 || context_die
->die_tag
== DW_TAG_class_type
16781 || context_die
->die_tag
== DW_TAG_interface_type
16782 || context_die
->die_tag
== DW_TAG_union_type
));
16785 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16786 whether or not to treat a DIE in this context as a declaration. */
16789 class_or_namespace_scope_p (dw_die_ref context_die
)
16791 return (class_scope_p (context_die
)
16792 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16795 /* Many forms of DIEs require a "type description" attribute. This
16796 routine locates the proper "type descriptor" die for the type given
16797 by 'type', and adds a DW_AT_type attribute below the given die. */
16800 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16801 int decl_volatile
, dw_die_ref context_die
)
16803 enum tree_code code
= TREE_CODE (type
);
16804 dw_die_ref type_die
= NULL
;
16806 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16807 or fixed-point type, use the inner type. This is because we have no
16808 support for unnamed types in base_type_die. This can happen if this is
16809 an Ada subrange type. Correct solution is emit a subrange type die. */
16810 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16811 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16812 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16814 if (code
== ERROR_MARK
16815 /* Handle a special case. For functions whose return type is void, we
16816 generate *no* type attribute. (Note that no object may have type
16817 `void', so this only applies to function return types). */
16818 || code
== VOID_TYPE
)
16821 type_die
= modified_type_die (type
,
16822 decl_const
|| TYPE_READONLY (type
),
16823 decl_volatile
|| TYPE_VOLATILE (type
),
16826 if (type_die
!= NULL
)
16827 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16830 /* Given an object die, add the calling convention attribute for the
16831 function call type. */
16833 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16835 enum dwarf_calling_convention value
= DW_CC_normal
;
16837 value
= ((enum dwarf_calling_convention
)
16838 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16841 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16843 /* DWARF 2 doesn't provide a way to identify a program's source-level
16844 entry point. DW_AT_calling_convention attributes are only meant
16845 to describe functions' calling conventions. However, lacking a
16846 better way to signal the Fortran main program, we used this for
16847 a long time, following existing custom. Now, DWARF 4 has
16848 DW_AT_main_subprogram, which we add below, but some tools still
16849 rely on the old way, which we thus keep. */
16850 value
= DW_CC_program
;
16852 if (dwarf_version
>= 4 || !dwarf_strict
)
16853 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16856 /* Only add the attribute if the backend requests it, and
16857 is not DW_CC_normal. */
16858 if (value
&& (value
!= DW_CC_normal
))
16859 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16862 /* Given a tree pointer to a struct, class, union, or enum type node, return
16863 a pointer to the (string) tag name for the given type, or zero if the type
16864 was declared without a tag. */
16866 static const char *
16867 type_tag (const_tree type
)
16869 const char *name
= 0;
16871 if (TYPE_NAME (type
) != 0)
16875 /* Find the IDENTIFIER_NODE for the type name. */
16876 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16877 && !TYPE_NAMELESS (type
))
16878 t
= TYPE_NAME (type
);
16880 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16881 a TYPE_DECL node, regardless of whether or not a `typedef' was
16883 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16884 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16886 /* We want to be extra verbose. Don't call dwarf_name if
16887 DECL_NAME isn't set. The default hook for decl_printable_name
16888 doesn't like that, and in this context it's correct to return
16889 0, instead of "<anonymous>" or the like. */
16890 if (DECL_NAME (TYPE_NAME (type
))
16891 && !DECL_NAMELESS (TYPE_NAME (type
)))
16892 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16895 /* Now get the name as a string, or invent one. */
16896 if (!name
&& t
!= 0)
16897 name
= IDENTIFIER_POINTER (t
);
16900 return (name
== 0 || *name
== '\0') ? 0 : name
;
16903 /* Return the type associated with a data member, make a special check
16904 for bit field types. */
16907 member_declared_type (const_tree member
)
16909 return (DECL_BIT_FIELD_TYPE (member
)
16910 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16913 /* Get the decl's label, as described by its RTL. This may be different
16914 from the DECL_NAME name used in the source file. */
16917 static const char *
16918 decl_start_label (tree decl
)
16921 const char *fnname
;
16923 x
= DECL_RTL (decl
);
16924 gcc_assert (MEM_P (x
));
16927 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16929 fnname
= XSTR (x
, 0);
16934 /* These routines generate the internal representation of the DIE's for
16935 the compilation unit. Debugging information is collected by walking
16936 the declaration trees passed in from dwarf2out_decl(). */
16939 gen_array_type_die (tree type
, dw_die_ref context_die
)
16941 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16942 dw_die_ref array_die
;
16944 /* GNU compilers represent multidimensional array types as sequences of one
16945 dimensional array types whose element types are themselves array types.
16946 We sometimes squish that down to a single array_type DIE with multiple
16947 subscripts in the Dwarf debugging info. The draft Dwarf specification
16948 say that we are allowed to do this kind of compression in C, because
16949 there is no difference between an array of arrays and a multidimensional
16950 array. We don't do this for Ada to remain as close as possible to the
16951 actual representation, which is especially important against the language
16952 flexibilty wrt arrays of variable size. */
16954 bool collapse_nested_arrays
= !is_ada ();
16957 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16958 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16959 if (TYPE_STRING_FLAG (type
)
16960 && TREE_CODE (type
) == ARRAY_TYPE
16962 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16964 HOST_WIDE_INT size
;
16966 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16967 add_name_attribute (array_die
, type_tag (type
));
16968 equate_type_number_to_die (type
, array_die
);
16969 size
= int_size_in_bytes (type
);
16971 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16972 else if (TYPE_DOMAIN (type
) != NULL_TREE
16973 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16974 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16976 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16977 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16979 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16980 if (loc
&& size
> 0)
16982 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16983 if (size
!= DWARF2_ADDR_SIZE
)
16984 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16990 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16991 add_name_attribute (array_die
, type_tag (type
));
16992 equate_type_number_to_die (type
, array_die
);
16994 if (TREE_CODE (type
) == VECTOR_TYPE
)
16995 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16997 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16999 && TREE_CODE (type
) == ARRAY_TYPE
17000 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17001 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17002 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17005 /* We default the array ordering. SDB will probably do
17006 the right things even if DW_AT_ordering is not present. It's not even
17007 an issue until we start to get into multidimensional arrays anyway. If
17008 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17009 then we'll have to put the DW_AT_ordering attribute back in. (But if
17010 and when we find out that we need to put these in, we will only do so
17011 for multidimensional arrays. */
17012 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17015 if (TREE_CODE (type
) == VECTOR_TYPE
)
17017 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17018 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17019 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17020 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17021 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17024 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17026 /* Add representation of the type of the elements of this array type and
17027 emit the corresponding DIE if we haven't done it already. */
17028 element_type
= TREE_TYPE (type
);
17029 if (collapse_nested_arrays
)
17030 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17032 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17034 element_type
= TREE_TYPE (element_type
);
17037 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17039 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17040 if (TYPE_ARTIFICIAL (type
))
17041 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17043 if (get_AT (array_die
, DW_AT_name
))
17044 add_pubtype (type
, array_die
);
17047 static dw_loc_descr_ref
17048 descr_info_loc (tree val
, tree base_decl
)
17050 HOST_WIDE_INT size
;
17051 dw_loc_descr_ref loc
, loc2
;
17052 enum dwarf_location_atom op
;
17054 if (val
== base_decl
)
17055 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17057 switch (TREE_CODE (val
))
17060 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17062 return loc_descriptor_from_tree (val
, 0);
17064 if (tree_fits_shwi_p (val
))
17065 return int_loc_descriptor (tree_to_shwi (val
));
17068 size
= int_size_in_bytes (TREE_TYPE (val
));
17071 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17074 if (size
== DWARF2_ADDR_SIZE
)
17075 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17077 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17079 case POINTER_PLUS_EXPR
:
17081 if (tree_fits_uhwi_p (TREE_OPERAND (val
, 1))
17082 && tree_to_uhwi (TREE_OPERAND (val
, 1)) < 16384)
17084 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17087 loc_descr_plus_const (&loc
, tree_to_shwi (TREE_OPERAND (val
, 1)));
17093 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17096 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17099 add_loc_descr (&loc
, loc2
);
17100 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17122 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17123 tree val
, tree base_decl
)
17125 dw_loc_descr_ref loc
;
17127 if (tree_fits_shwi_p (val
))
17129 add_AT_unsigned (die
, attr
, tree_to_shwi (val
));
17133 loc
= descr_info_loc (val
, base_decl
);
17137 add_AT_loc (die
, attr
, loc
);
17140 /* This routine generates DIE for array with hidden descriptor, details
17141 are filled into *info by a langhook. */
17144 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17145 dw_die_ref context_die
)
17147 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17148 dw_die_ref array_die
;
17151 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17152 add_name_attribute (array_die
, type_tag (type
));
17153 equate_type_number_to_die (type
, array_die
);
17155 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17157 && info
->ndimensions
>= 2)
17158 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17160 if (info
->data_location
)
17161 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17163 if (info
->associated
)
17164 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17166 if (info
->allocated
)
17167 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17170 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17172 dw_die_ref subrange_die
17173 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17175 if (info
->dimen
[dim
].lower_bound
)
17177 /* If it is the default value, omit it. */
17180 if (tree_fits_shwi_p (info
->dimen
[dim
].lower_bound
)
17181 && (dflt
= lower_bound_default ()) != -1
17182 && tree_to_shwi (info
->dimen
[dim
].lower_bound
) == dflt
)
17185 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17186 info
->dimen
[dim
].lower_bound
,
17189 if (info
->dimen
[dim
].upper_bound
)
17190 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17191 info
->dimen
[dim
].upper_bound
,
17193 if (info
->dimen
[dim
].stride
)
17194 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17195 info
->dimen
[dim
].stride
,
17199 gen_type_die (info
->element_type
, context_die
);
17200 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17202 if (get_AT (array_die
, DW_AT_name
))
17203 add_pubtype (type
, array_die
);
17208 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17210 tree origin
= decl_ultimate_origin (decl
);
17211 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17213 if (origin
!= NULL
)
17214 add_abstract_origin_attribute (decl_die
, origin
);
17217 add_name_and_src_coords_attributes (decl_die
, decl
);
17218 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17219 0, 0, context_die
);
17222 if (DECL_ABSTRACT (decl
))
17223 equate_decl_number_to_die (decl
, decl_die
);
17225 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17229 /* Walk through the list of incomplete types again, trying once more to
17230 emit full debugging info for them. */
17233 retry_incomplete_types (void)
17237 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17238 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17239 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17242 /* Determine what tag to use for a record type. */
17244 static enum dwarf_tag
17245 record_type_tag (tree type
)
17247 if (! lang_hooks
.types
.classify_record
)
17248 return DW_TAG_structure_type
;
17250 switch (lang_hooks
.types
.classify_record (type
))
17252 case RECORD_IS_STRUCT
:
17253 return DW_TAG_structure_type
;
17255 case RECORD_IS_CLASS
:
17256 return DW_TAG_class_type
;
17258 case RECORD_IS_INTERFACE
:
17259 if (dwarf_version
>= 3 || !dwarf_strict
)
17260 return DW_TAG_interface_type
;
17261 return DW_TAG_structure_type
;
17264 gcc_unreachable ();
17268 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17269 include all of the information about the enumeration values also. Each
17270 enumerated type name/value is listed as a child of the enumerated type
17274 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17276 dw_die_ref type_die
= lookup_type_die (type
);
17278 if (type_die
== NULL
)
17280 type_die
= new_die (DW_TAG_enumeration_type
,
17281 scope_die_for (type
, context_die
), type
);
17282 equate_type_number_to_die (type
, type_die
);
17283 add_name_attribute (type_die
, type_tag (type
));
17284 if (dwarf_version
>= 4 || !dwarf_strict
)
17286 if (ENUM_IS_SCOPED (type
))
17287 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17288 if (ENUM_IS_OPAQUE (type
))
17289 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17292 else if (! TYPE_SIZE (type
))
17295 remove_AT (type_die
, DW_AT_declaration
);
17297 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17298 given enum type is incomplete, do not generate the DW_AT_byte_size
17299 attribute or the DW_AT_element_list attribute. */
17300 if (TYPE_SIZE (type
))
17304 TREE_ASM_WRITTEN (type
) = 1;
17305 add_byte_size_attribute (type_die
, type
);
17306 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17308 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17309 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17312 /* If the first reference to this type was as the return type of an
17313 inline function, then it may not have a parent. Fix this now. */
17314 if (type_die
->die_parent
== NULL
)
17315 add_child_die (scope_die_for (type
, context_die
), type_die
);
17317 for (link
= TYPE_VALUES (type
);
17318 link
!= NULL
; link
= TREE_CHAIN (link
))
17320 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17321 tree value
= TREE_VALUE (link
);
17323 add_name_attribute (enum_die
,
17324 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17326 if (TREE_CODE (value
) == CONST_DECL
)
17327 value
= DECL_INITIAL (value
);
17329 if (simple_type_size_in_bits (TREE_TYPE (value
))
17330 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17331 /* DWARF2 does not provide a way of indicating whether or
17332 not enumeration constants are signed or unsigned. GDB
17333 always assumes the values are signed, so we output all
17334 values as if they were signed. That means that
17335 enumeration constants with very large unsigned values
17336 will appear to have negative values in the debugger.
17338 TODO: the above comment is wrong, DWARF2 does provide
17339 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17340 This should be re-worked to use correct signed/unsigned
17341 int/double tags for all cases, instead of always treating as
17343 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17345 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17347 add_AT_double (enum_die
, DW_AT_const_value
,
17348 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17351 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17352 if (TYPE_ARTIFICIAL (type
))
17353 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17356 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17358 add_pubtype (type
, type_die
);
17363 /* Generate a DIE to represent either a real live formal parameter decl or to
17364 represent just the type of some formal parameter position in some function
17367 Note that this routine is a bit unusual because its argument may be a
17368 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17369 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17370 node. If it's the former then this function is being called to output a
17371 DIE to represent a formal parameter object (or some inlining thereof). If
17372 it's the latter, then this function is only being called to output a
17373 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17374 argument type of some subprogram type.
17375 If EMIT_NAME_P is true, name and source coordinate attributes
17379 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17380 dw_die_ref context_die
)
17382 tree node_or_origin
= node
? node
: origin
;
17383 tree ultimate_origin
;
17384 dw_die_ref parm_die
17385 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17387 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17389 case tcc_declaration
:
17390 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17391 if (node
|| ultimate_origin
)
17392 origin
= ultimate_origin
;
17393 if (origin
!= NULL
)
17394 add_abstract_origin_attribute (parm_die
, origin
);
17395 else if (emit_name_p
)
17396 add_name_and_src_coords_attributes (parm_die
, node
);
17398 || (! DECL_ABSTRACT (node_or_origin
)
17399 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17400 decl_function_context
17401 (node_or_origin
))))
17403 tree type
= TREE_TYPE (node_or_origin
);
17404 if (decl_by_reference_p (node_or_origin
))
17405 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17408 add_type_attribute (parm_die
, type
,
17409 TREE_READONLY (node_or_origin
),
17410 TREE_THIS_VOLATILE (node_or_origin
),
17413 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17414 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17416 if (node
&& node
!= origin
)
17417 equate_decl_number_to_die (node
, parm_die
);
17418 if (! DECL_ABSTRACT (node_or_origin
))
17419 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17420 node
== NULL
, DW_AT_location
);
17425 /* We were called with some kind of a ..._TYPE node. */
17426 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17430 gcc_unreachable ();
17436 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17437 children DW_TAG_formal_parameter DIEs representing the arguments of the
17440 PARM_PACK must be a function parameter pack.
17441 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17442 must point to the subsequent arguments of the function PACK_ARG belongs to.
17443 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17444 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17445 following the last one for which a DIE was generated. */
17448 gen_formal_parameter_pack_die (tree parm_pack
,
17450 dw_die_ref subr_die
,
17454 dw_die_ref parm_pack_die
;
17456 gcc_assert (parm_pack
17457 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17460 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17461 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17463 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17465 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17468 gen_formal_parameter_die (arg
, NULL
,
17469 false /* Don't emit name attribute. */,
17474 return parm_pack_die
;
17477 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17478 at the end of an (ANSI prototyped) formal parameters list. */
17481 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17483 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17486 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17487 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17488 parameters as specified in some function type specification (except for
17489 those which appear as part of a function *definition*). */
17492 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17495 tree formal_type
= NULL
;
17496 tree first_parm_type
;
17499 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17501 arg
= DECL_ARGUMENTS (function_or_method_type
);
17502 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17507 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17509 /* Make our first pass over the list of formal parameter types and output a
17510 DW_TAG_formal_parameter DIE for each one. */
17511 for (link
= first_parm_type
; link
; )
17513 dw_die_ref parm_die
;
17515 formal_type
= TREE_VALUE (link
);
17516 if (formal_type
== void_type_node
)
17519 /* Output a (nameless) DIE to represent the formal parameter itself. */
17520 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17521 true /* Emit name attribute. */,
17523 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17524 && link
== first_parm_type
)
17526 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17527 if (dwarf_version
>= 3 || !dwarf_strict
)
17528 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17530 else if (arg
&& DECL_ARTIFICIAL (arg
))
17531 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17533 link
= TREE_CHAIN (link
);
17535 arg
= DECL_CHAIN (arg
);
17538 /* If this function type has an ellipsis, add a
17539 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17540 if (formal_type
!= void_type_node
)
17541 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17543 /* Make our second (and final) pass over the list of formal parameter types
17544 and output DIEs to represent those types (as necessary). */
17545 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17546 link
&& TREE_VALUE (link
);
17547 link
= TREE_CHAIN (link
))
17548 gen_type_die (TREE_VALUE (link
), context_die
);
17551 /* We want to generate the DIE for TYPE so that we can generate the
17552 die for MEMBER, which has been defined; we will need to refer back
17553 to the member declaration nested within TYPE. If we're trying to
17554 generate minimal debug info for TYPE, processing TYPE won't do the
17555 trick; we need to attach the member declaration by hand. */
17558 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17560 gen_type_die (type
, context_die
);
17562 /* If we're trying to avoid duplicate debug info, we may not have
17563 emitted the member decl for this function. Emit it now. */
17564 if (TYPE_STUB_DECL (type
)
17565 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17566 && ! lookup_decl_die (member
))
17568 dw_die_ref type_die
;
17569 gcc_assert (!decl_ultimate_origin (member
));
17571 push_decl_scope (type
);
17572 type_die
= lookup_type_die_strip_naming_typedef (type
);
17573 if (TREE_CODE (member
) == FUNCTION_DECL
)
17574 gen_subprogram_die (member
, type_die
);
17575 else if (TREE_CODE (member
) == FIELD_DECL
)
17577 /* Ignore the nameless fields that are used to skip bits but handle
17578 C++ anonymous unions and structs. */
17579 if (DECL_NAME (member
) != NULL_TREE
17580 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17581 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17583 gen_type_die (member_declared_type (member
), type_die
);
17584 gen_field_die (member
, type_die
);
17588 gen_variable_die (member
, NULL_TREE
, type_die
);
17594 /* Forward declare these functions, because they are mutually recursive
17595 with their set_block_* pairing functions. */
17596 static void set_decl_origin_self (tree
);
17597 static void set_decl_abstract_flags (tree
, int);
17599 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17600 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17601 that it points to the node itself, thus indicating that the node is its
17602 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17603 the given node is NULL, recursively descend the decl/block tree which
17604 it is the root of, and for each other ..._DECL or BLOCK node contained
17605 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17606 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17607 values to point to themselves. */
17610 set_block_origin_self (tree stmt
)
17612 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17614 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17619 for (local_decl
= BLOCK_VARS (stmt
);
17620 local_decl
!= NULL_TREE
;
17621 local_decl
= DECL_CHAIN (local_decl
))
17622 if (! DECL_EXTERNAL (local_decl
))
17623 set_decl_origin_self (local_decl
); /* Potential recursion. */
17629 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17630 subblock
!= NULL_TREE
;
17631 subblock
= BLOCK_CHAIN (subblock
))
17632 set_block_origin_self (subblock
); /* Recurse. */
17637 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17638 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17639 node to so that it points to the node itself, thus indicating that the
17640 node represents its own (abstract) origin. Additionally, if the
17641 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17642 the decl/block tree of which the given node is the root of, and for
17643 each other ..._DECL or BLOCK node contained therein whose
17644 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17645 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17646 point to themselves. */
17649 set_decl_origin_self (tree decl
)
17651 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17653 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17654 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17658 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17659 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17660 if (DECL_INITIAL (decl
) != NULL_TREE
17661 && DECL_INITIAL (decl
) != error_mark_node
)
17662 set_block_origin_self (DECL_INITIAL (decl
));
17667 /* Given a pointer to some BLOCK node, and a boolean value to set the
17668 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17669 the given block, and for all local decls and all local sub-blocks
17670 (recursively) which are contained therein. */
17673 set_block_abstract_flags (tree stmt
, int setting
)
17679 BLOCK_ABSTRACT (stmt
) = setting
;
17681 for (local_decl
= BLOCK_VARS (stmt
);
17682 local_decl
!= NULL_TREE
;
17683 local_decl
= DECL_CHAIN (local_decl
))
17684 if (! DECL_EXTERNAL (local_decl
))
17685 set_decl_abstract_flags (local_decl
, setting
);
17687 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17689 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17690 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17691 || TREE_CODE (local_decl
) == PARM_DECL
)
17692 set_decl_abstract_flags (local_decl
, setting
);
17695 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17696 subblock
!= NULL_TREE
;
17697 subblock
= BLOCK_CHAIN (subblock
))
17698 set_block_abstract_flags (subblock
, setting
);
17701 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17702 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17703 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17704 set the abstract flags for all of the parameters, local vars, local
17705 blocks and sub-blocks (recursively) to the same setting. */
17708 set_decl_abstract_flags (tree decl
, int setting
)
17710 DECL_ABSTRACT (decl
) = setting
;
17711 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17715 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17716 DECL_ABSTRACT (arg
) = setting
;
17717 if (DECL_INITIAL (decl
) != NULL_TREE
17718 && DECL_INITIAL (decl
) != error_mark_node
)
17719 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17723 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17724 may later generate inlined and/or out-of-line instances of. */
17727 dwarf2out_abstract_function (tree decl
)
17729 dw_die_ref old_die
;
17733 htab_t old_decl_loc_table
;
17734 htab_t old_cached_dw_loc_list_table
;
17735 int old_call_site_count
, old_tail_call_site_count
;
17736 struct call_arg_loc_node
*old_call_arg_locations
;
17738 /* Make sure we have the actual abstract inline, not a clone. */
17739 decl
= DECL_ORIGIN (decl
);
17741 old_die
= lookup_decl_die (decl
);
17742 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17743 /* We've already generated the abstract instance. */
17746 /* We can be called while recursively when seeing block defining inlined subroutine
17747 DIE. Be sure to not clobber the outer location table nor use it or we would
17748 get locations in abstract instantces. */
17749 old_decl_loc_table
= decl_loc_table
;
17750 decl_loc_table
= NULL
;
17751 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17752 cached_dw_loc_list_table
= NULL
;
17753 old_call_arg_locations
= call_arg_locations
;
17754 call_arg_locations
= NULL
;
17755 old_call_site_count
= call_site_count
;
17756 call_site_count
= -1;
17757 old_tail_call_site_count
= tail_call_site_count
;
17758 tail_call_site_count
= -1;
17760 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17761 we don't get confused by DECL_ABSTRACT. */
17762 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17764 context
= decl_class_context (decl
);
17766 gen_type_die_for_member
17767 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17770 /* Pretend we've just finished compiling this function. */
17771 save_fn
= current_function_decl
;
17772 current_function_decl
= decl
;
17774 was_abstract
= DECL_ABSTRACT (decl
);
17775 set_decl_abstract_flags (decl
, 1);
17776 dwarf2out_decl (decl
);
17777 if (! was_abstract
)
17778 set_decl_abstract_flags (decl
, 0);
17780 current_function_decl
= save_fn
;
17781 decl_loc_table
= old_decl_loc_table
;
17782 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17783 call_arg_locations
= old_call_arg_locations
;
17784 call_site_count
= old_call_site_count
;
17785 tail_call_site_count
= old_tail_call_site_count
;
17788 /* Helper function of premark_used_types() which gets called through
17791 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17792 marked as unused by prune_unused_types. */
17795 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17800 type
= (tree
) *slot
;
17801 die
= lookup_type_die (type
);
17803 die
->die_perennial_p
= 1;
17807 /* Helper function of premark_types_used_by_global_vars which gets called
17808 through htab_traverse.
17810 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17811 marked as unused by prune_unused_types. The DIE of the type is marked
17812 only if the global variable using the type will actually be emitted. */
17815 premark_types_used_by_global_vars_helper (void **slot
,
17816 void *data ATTRIBUTE_UNUSED
)
17818 struct types_used_by_vars_entry
*entry
;
17821 entry
= (struct types_used_by_vars_entry
*) *slot
;
17822 gcc_assert (entry
->type
!= NULL
17823 && entry
->var_decl
!= NULL
);
17824 die
= lookup_type_die (entry
->type
);
17827 /* Ask cgraph if the global variable really is to be emitted.
17828 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17829 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17830 if (node
&& node
->definition
)
17832 die
->die_perennial_p
= 1;
17833 /* Keep the parent DIEs as well. */
17834 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17835 die
->die_perennial_p
= 1;
17841 /* Mark all members of used_types_hash as perennial. */
17844 premark_used_types (struct function
*fun
)
17846 if (fun
&& fun
->used_types_hash
)
17847 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17850 /* Mark all members of types_used_by_vars_entry as perennial. */
17853 premark_types_used_by_global_vars (void)
17855 if (types_used_by_vars_hash
)
17856 htab_traverse (types_used_by_vars_hash
,
17857 premark_types_used_by_global_vars_helper
, NULL
);
17860 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17861 for CA_LOC call arg loc node. */
17864 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17865 struct call_arg_loc_node
*ca_loc
)
17867 dw_die_ref stmt_die
= NULL
, die
;
17868 tree block
= ca_loc
->block
;
17871 && block
!= DECL_INITIAL (decl
)
17872 && TREE_CODE (block
) == BLOCK
)
17874 if (block_map
.length () > BLOCK_NUMBER (block
))
17875 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17878 block
= BLOCK_SUPERCONTEXT (block
);
17880 if (stmt_die
== NULL
)
17881 stmt_die
= subr_die
;
17882 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17883 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17884 if (ca_loc
->tail_call_p
)
17885 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17886 if (ca_loc
->symbol_ref
)
17888 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17890 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17892 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17897 /* Generate a DIE to represent a declared function (either file-scope or
17901 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17903 tree origin
= decl_ultimate_origin (decl
);
17904 dw_die_ref subr_die
;
17906 dw_die_ref old_die
= lookup_decl_die (decl
);
17907 int declaration
= (current_function_decl
!= decl
17908 || class_or_namespace_scope_p (context_die
));
17910 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17912 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17913 started to generate the abstract instance of an inline, decided to output
17914 its containing class, and proceeded to emit the declaration of the inline
17915 from the member list for the class. If so, DECLARATION takes priority;
17916 we'll get back to the abstract instance when done with the class. */
17918 /* The class-scope declaration DIE must be the primary DIE. */
17919 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17922 gcc_assert (!old_die
);
17925 /* Now that the C++ front end lazily declares artificial member fns, we
17926 might need to retrofit the declaration into its class. */
17927 if (!declaration
&& !origin
&& !old_die
17928 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17929 && !class_or_namespace_scope_p (context_die
)
17930 && debug_info_level
> DINFO_LEVEL_TERSE
)
17931 old_die
= force_decl_die (decl
);
17933 if (origin
!= NULL
)
17935 gcc_assert (!declaration
|| local_scope_p (context_die
));
17937 /* Fixup die_parent for the abstract instance of a nested
17938 inline function. */
17939 if (old_die
&& old_die
->die_parent
== NULL
)
17940 add_child_die (context_die
, old_die
);
17942 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17943 add_abstract_origin_attribute (subr_die
, origin
);
17944 /* This is where the actual code for a cloned function is.
17945 Let's emit linkage name attribute for it. This helps
17946 debuggers to e.g, set breakpoints into
17947 constructors/destructors when the user asks "break
17949 add_linkage_name (subr_die
, decl
);
17953 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17954 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17956 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17957 /* We can have a normal definition following an inline one in the
17958 case of redefinition of GNU C extern inlines.
17959 It seems reasonable to use AT_specification in this case. */
17960 && !get_AT (old_die
, DW_AT_inline
))
17962 /* Detect and ignore this case, where we are trying to output
17963 something we have already output. */
17967 /* If the definition comes from the same place as the declaration,
17968 maybe use the old DIE. We always want the DIE for this function
17969 that has the *_pc attributes to be under comp_unit_die so the
17970 debugger can find it. We also need to do this for abstract
17971 instances of inlines, since the spec requires the out-of-line copy
17972 to have the same parent. For local class methods, this doesn't
17973 apply; we just use the old DIE. */
17974 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17975 && (DECL_ARTIFICIAL (decl
)
17976 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17977 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17978 == (unsigned) s
.line
))))
17980 subr_die
= old_die
;
17982 /* Clear out the declaration attribute and the formal parameters.
17983 Do not remove all children, because it is possible that this
17984 declaration die was forced using force_decl_die(). In such
17985 cases die that forced declaration die (e.g. TAG_imported_module)
17986 is one of the children that we do not want to remove. */
17987 remove_AT (subr_die
, DW_AT_declaration
);
17988 remove_AT (subr_die
, DW_AT_object_pointer
);
17989 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17993 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17994 add_AT_specification (subr_die
, old_die
);
17995 add_pubname (decl
, subr_die
);
17996 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17997 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17998 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17999 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18004 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18006 if (TREE_PUBLIC (decl
))
18007 add_AT_flag (subr_die
, DW_AT_external
, 1);
18009 add_name_and_src_coords_attributes (subr_die
, decl
);
18010 add_pubname (decl
, subr_die
);
18011 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18013 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18014 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18015 0, 0, context_die
);
18018 add_pure_or_virtual_attribute (subr_die
, decl
);
18019 if (DECL_ARTIFICIAL (decl
))
18020 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18022 add_accessibility_attribute (subr_die
, decl
);
18027 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18029 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18031 /* If this is an explicit function declaration then generate
18032 a DW_AT_explicit attribute. */
18033 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18034 && (dwarf_version
>= 3 || !dwarf_strict
))
18035 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18037 /* The first time we see a member function, it is in the context of
18038 the class to which it belongs. We make sure of this by emitting
18039 the class first. The next time is the definition, which is
18040 handled above. The two may come from the same source text.
18042 Note that force_decl_die() forces function declaration die. It is
18043 later reused to represent definition. */
18044 equate_decl_number_to_die (decl
, subr_die
);
18047 else if (DECL_ABSTRACT (decl
))
18049 if (DECL_DECLARED_INLINE_P (decl
))
18051 if (cgraph_function_possibly_inlined_p (decl
))
18052 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18054 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18058 if (cgraph_function_possibly_inlined_p (decl
))
18059 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18061 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18064 if (DECL_DECLARED_INLINE_P (decl
)
18065 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18066 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18068 equate_decl_number_to_die (decl
, subr_die
);
18070 else if (!DECL_EXTERNAL (decl
))
18072 HOST_WIDE_INT cfa_fb_offset
;
18073 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18075 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18076 equate_decl_number_to_die (decl
, subr_die
);
18078 gcc_checking_assert (fun
);
18079 if (!flag_reorder_blocks_and_partition
)
18081 dw_fde_ref fde
= fun
->fde
;
18082 if (fde
->dw_fde_begin
)
18084 /* We have already generated the labels. */
18085 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18086 fde
->dw_fde_end
, false);
18090 /* Create start/end labels and add the range. */
18091 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18092 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18093 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18094 current_function_funcdef_no
);
18095 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18096 current_function_funcdef_no
);
18097 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18101 #if VMS_DEBUGGING_INFO
18102 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18103 Section 2.3 Prologue and Epilogue Attributes:
18104 When a breakpoint is set on entry to a function, it is generally
18105 desirable for execution to be suspended, not on the very first
18106 instruction of the function, but rather at a point after the
18107 function's frame has been set up, after any language defined local
18108 declaration processing has been completed, and before execution of
18109 the first statement of the function begins. Debuggers generally
18110 cannot properly determine where this point is. Similarly for a
18111 breakpoint set on exit from a function. The prologue and epilogue
18112 attributes allow a compiler to communicate the location(s) to use. */
18115 if (fde
->dw_fde_vms_end_prologue
)
18116 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18117 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18119 if (fde
->dw_fde_vms_begin_epilogue
)
18120 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18121 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18128 /* Generate pubnames entries for the split function code ranges. */
18129 dw_fde_ref fde
= fun
->fde
;
18131 if (fde
->dw_fde_second_begin
)
18133 if (dwarf_version
>= 3 || !dwarf_strict
)
18135 /* We should use ranges for non-contiguous code section
18136 addresses. Use the actual code range for the initial
18137 section, since the HOT/COLD labels might precede an
18138 alignment offset. */
18139 bool range_list_added
= false;
18140 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18141 fde
->dw_fde_end
, &range_list_added
,
18143 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18144 fde
->dw_fde_second_end
,
18145 &range_list_added
, false);
18146 if (range_list_added
)
18151 /* There is no real support in DW2 for this .. so we make
18152 a work-around. First, emit the pub name for the segment
18153 containing the function label. Then make and emit a
18154 simplified subprogram DIE for the second segment with the
18155 name pre-fixed by __hot/cold_sect_of_. We use the same
18156 linkage name for the second die so that gdb will find both
18157 sections when given "b foo". */
18158 const char *name
= NULL
;
18159 tree decl_name
= DECL_NAME (decl
);
18160 dw_die_ref seg_die
;
18162 /* Do the 'primary' section. */
18163 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18164 fde
->dw_fde_end
, false);
18166 /* Build a minimal DIE for the secondary section. */
18167 seg_die
= new_die (DW_TAG_subprogram
,
18168 subr_die
->die_parent
, decl
);
18170 if (TREE_PUBLIC (decl
))
18171 add_AT_flag (seg_die
, DW_AT_external
, 1);
18173 if (decl_name
!= NULL
18174 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18176 name
= dwarf2_name (decl
, 1);
18177 if (! DECL_ARTIFICIAL (decl
))
18178 add_src_coords_attributes (seg_die
, decl
);
18180 add_linkage_name (seg_die
, decl
);
18182 gcc_assert (name
!= NULL
);
18183 add_pure_or_virtual_attribute (seg_die
, decl
);
18184 if (DECL_ARTIFICIAL (decl
))
18185 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18187 name
= concat ("__second_sect_of_", name
, NULL
);
18188 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18189 fde
->dw_fde_second_end
, false);
18190 add_name_attribute (seg_die
, name
);
18191 if (want_pubnames ())
18192 add_pubname_string (name
, seg_die
);
18196 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18200 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18202 /* We define the "frame base" as the function's CFA. This is more
18203 convenient for several reasons: (1) It's stable across the prologue
18204 and epilogue, which makes it better than just a frame pointer,
18205 (2) With dwarf3, there exists a one-byte encoding that allows us
18206 to reference the .debug_frame data by proxy, but failing that,
18207 (3) We can at least reuse the code inspection and interpretation
18208 code that determines the CFA position at various points in the
18210 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18212 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18213 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18217 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18218 if (list
->dw_loc_next
)
18219 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18221 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18224 /* Compute a displacement from the "steady-state frame pointer" to
18225 the CFA. The former is what all stack slots and argument slots
18226 will reference in the rtl; the latter is what we've told the
18227 debugger about. We'll need to adjust all frame_base references
18228 by this displacement. */
18229 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18231 if (fun
->static_chain_decl
)
18232 add_AT_location_description (subr_die
, DW_AT_static_link
,
18233 loc_list_from_tree (fun
->static_chain_decl
, 2));
18236 /* Generate child dies for template paramaters. */
18237 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18238 gen_generic_params_dies (decl
);
18240 /* Now output descriptions of the arguments for this function. This gets
18241 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18242 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18243 `...' at the end of the formal parameter list. In order to find out if
18244 there was a trailing ellipsis or not, we must instead look at the type
18245 associated with the FUNCTION_DECL. This will be a node of type
18246 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18247 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18248 an ellipsis at the end. */
18250 /* In the case where we are describing a mere function declaration, all we
18251 need to do here (and all we *can* do here) is to describe the *types* of
18252 its formal parameters. */
18253 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18255 else if (declaration
)
18256 gen_formal_types_die (decl
, subr_die
);
18259 /* Generate DIEs to represent all known formal parameters. */
18260 tree parm
= DECL_ARGUMENTS (decl
);
18261 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18262 tree generic_decl_parm
= generic_decl
18263 ? DECL_ARGUMENTS (generic_decl
)
18266 /* Now we want to walk the list of parameters of the function and
18267 emit their relevant DIEs.
18269 We consider the case of DECL being an instance of a generic function
18270 as well as it being a normal function.
18272 If DECL is an instance of a generic function we walk the
18273 parameters of the generic function declaration _and_ the parameters of
18274 DECL itself. This is useful because we want to emit specific DIEs for
18275 function parameter packs and those are declared as part of the
18276 generic function declaration. In that particular case,
18277 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18278 That DIE has children DIEs representing the set of arguments
18279 of the pack. Note that the set of pack arguments can be empty.
18280 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18283 Otherwise, we just consider the parameters of DECL. */
18284 while (generic_decl_parm
|| parm
)
18286 if (generic_decl_parm
18287 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18288 gen_formal_parameter_pack_die (generic_decl_parm
,
18293 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18295 if (parm
== DECL_ARGUMENTS (decl
)
18296 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18298 && (dwarf_version
>= 3 || !dwarf_strict
))
18299 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18301 parm
= DECL_CHAIN (parm
);
18304 if (generic_decl_parm
)
18305 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18308 /* Decide whether we need an unspecified_parameters DIE at the end.
18309 There are 2 more cases to do this for: 1) the ansi ... declaration -
18310 this is detectable when the end of the arg list is not a
18311 void_type_node 2) an unprototyped function declaration (not a
18312 definition). This just means that we have no info about the
18313 parameters at all. */
18314 if (prototype_p (TREE_TYPE (decl
)))
18316 /* This is the prototyped case, check for.... */
18317 if (stdarg_p (TREE_TYPE (decl
)))
18318 gen_unspecified_parameters_die (decl
, subr_die
);
18320 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18321 gen_unspecified_parameters_die (decl
, subr_die
);
18324 /* Output Dwarf info for all of the stuff within the body of the function
18325 (if it has one - it may be just a declaration). */
18326 outer_scope
= DECL_INITIAL (decl
);
18328 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18329 a function. This BLOCK actually represents the outermost binding contour
18330 for the function, i.e. the contour in which the function's formal
18331 parameters and labels get declared. Curiously, it appears that the front
18332 end doesn't actually put the PARM_DECL nodes for the current function onto
18333 the BLOCK_VARS list for this outer scope, but are strung off of the
18334 DECL_ARGUMENTS list for the function instead.
18336 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18337 the LABEL_DECL nodes for the function however, and we output DWARF info
18338 for those in decls_for_scope. Just within the `outer_scope' there will be
18339 a BLOCK node representing the function's outermost pair of curly braces,
18340 and any blocks used for the base and member initializers of a C++
18341 constructor function. */
18342 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18344 int call_site_note_count
= 0;
18345 int tail_call_site_note_count
= 0;
18347 /* Emit a DW_TAG_variable DIE for a named return value. */
18348 if (DECL_NAME (DECL_RESULT (decl
)))
18349 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18351 current_function_has_inlines
= 0;
18352 decls_for_scope (outer_scope
, subr_die
, 0);
18354 if (call_arg_locations
&& !dwarf_strict
)
18356 struct call_arg_loc_node
*ca_loc
;
18357 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18359 dw_die_ref die
= NULL
;
18360 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18363 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18364 arg
; arg
= next_arg
)
18366 dw_loc_descr_ref reg
, val
;
18367 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18368 dw_die_ref cdie
, tdie
= NULL
;
18370 next_arg
= XEXP (arg
, 1);
18371 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18373 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18374 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18375 && REGNO (XEXP (XEXP (arg
, 0), 0))
18376 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18377 next_arg
= XEXP (next_arg
, 1);
18378 if (mode
== VOIDmode
)
18380 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18381 if (mode
== VOIDmode
)
18382 mode
= GET_MODE (XEXP (arg
, 0));
18384 if (mode
== VOIDmode
|| mode
== BLKmode
)
18386 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18388 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18389 tloc
= XEXP (XEXP (arg
, 0), 1);
18392 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18393 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18395 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18396 tlocc
= XEXP (XEXP (arg
, 0), 1);
18400 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18401 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18402 VAR_INIT_STATUS_INITIALIZED
);
18403 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18405 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18406 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18407 get_address_mode (mem
),
18409 VAR_INIT_STATUS_INITIALIZED
);
18411 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18412 == DEBUG_PARAMETER_REF
)
18415 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18416 tdie
= lookup_decl_die (tdecl
);
18423 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18424 != DEBUG_PARAMETER_REF
)
18426 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18428 VAR_INIT_STATUS_INITIALIZED
);
18432 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18433 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18436 add_AT_loc (cdie
, DW_AT_location
, reg
);
18437 else if (tdie
!= NULL
)
18438 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18439 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18440 if (next_arg
!= XEXP (arg
, 1))
18442 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18443 if (mode
== VOIDmode
)
18444 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18445 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18448 VAR_INIT_STATUS_INITIALIZED
);
18450 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18454 && (ca_loc
->symbol_ref
|| tloc
))
18455 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18456 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18458 dw_loc_descr_ref tval
= NULL
;
18460 if (tloc
!= NULL_RTX
)
18461 tval
= mem_loc_descriptor (tloc
,
18462 GET_MODE (tloc
) == VOIDmode
18463 ? Pmode
: GET_MODE (tloc
),
18465 VAR_INIT_STATUS_INITIALIZED
);
18467 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18468 else if (tlocc
!= NULL_RTX
)
18470 tval
= mem_loc_descriptor (tlocc
,
18471 GET_MODE (tlocc
) == VOIDmode
18472 ? Pmode
: GET_MODE (tlocc
),
18474 VAR_INIT_STATUS_INITIALIZED
);
18476 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18482 call_site_note_count
++;
18483 if (ca_loc
->tail_call_p
)
18484 tail_call_site_note_count
++;
18488 call_arg_locations
= NULL
;
18489 call_arg_loc_last
= NULL
;
18490 if (tail_call_site_count
>= 0
18491 && tail_call_site_count
== tail_call_site_note_count
18494 if (call_site_count
>= 0
18495 && call_site_count
== call_site_note_count
)
18496 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18498 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18500 call_site_count
= -1;
18501 tail_call_site_count
= -1;
18503 /* Add the calling convention attribute if requested. */
18504 add_calling_convention_attribute (subr_die
, decl
);
18508 /* Returns a hash value for X (which really is a die_struct). */
18511 common_block_die_table_hash (const void *x
)
18513 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18514 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18517 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18518 as decl_id and die_parent of die_struct Y. */
18521 common_block_die_table_eq (const void *x
, const void *y
)
18523 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18524 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18525 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18528 /* Generate a DIE to represent a declared data object.
18529 Either DECL or ORIGIN must be non-null. */
18532 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18534 HOST_WIDE_INT off
= 0;
18536 tree decl_or_origin
= decl
? decl
: origin
;
18537 tree ultimate_origin
;
18538 dw_die_ref var_die
;
18539 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18540 dw_die_ref origin_die
;
18541 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18542 || class_or_namespace_scope_p (context_die
));
18543 bool specialization_p
= false;
18545 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18546 if (decl
|| ultimate_origin
)
18547 origin
= ultimate_origin
;
18548 com_decl
= fortran_common (decl_or_origin
, &off
);
18550 /* Symbol in common gets emitted as a child of the common block, in the form
18551 of a data member. */
18554 dw_die_ref com_die
;
18555 dw_loc_list_ref loc
;
18556 die_node com_die_arg
;
18558 var_die
= lookup_decl_die (decl_or_origin
);
18561 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18563 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18568 /* Optimize the common case. */
18569 if (single_element_loc_list_p (loc
)
18570 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18571 && loc
->expr
->dw_loc_next
== NULL
18572 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18575 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18576 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18577 = plus_constant (GET_MODE (x
), x
, off
);
18580 loc_list_plus_const (loc
, off
);
18582 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18583 remove_AT (var_die
, DW_AT_declaration
);
18589 if (common_block_die_table
== NULL
)
18590 common_block_die_table
18591 = htab_create_ggc (10, common_block_die_table_hash
,
18592 common_block_die_table_eq
, NULL
);
18594 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18595 com_die_arg
.die_parent
= context_die
;
18596 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18597 loc
= loc_list_from_tree (com_decl
, 2);
18598 if (com_die
== NULL
)
18601 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18604 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18605 add_name_and_src_coords_attributes (com_die
, com_decl
);
18608 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18609 /* Avoid sharing the same loc descriptor between
18610 DW_TAG_common_block and DW_TAG_variable. */
18611 loc
= loc_list_from_tree (com_decl
, 2);
18613 else if (DECL_EXTERNAL (decl
))
18614 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18615 if (want_pubnames ())
18616 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18617 com_die
->decl_id
= DECL_UID (com_decl
);
18618 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18619 *slot
= (void *) com_die
;
18621 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18623 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18624 loc
= loc_list_from_tree (com_decl
, 2);
18625 remove_AT (com_die
, DW_AT_declaration
);
18627 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18628 add_name_and_src_coords_attributes (var_die
, decl
);
18629 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18630 TREE_THIS_VOLATILE (decl
), context_die
);
18631 add_AT_flag (var_die
, DW_AT_external
, 1);
18636 /* Optimize the common case. */
18637 if (single_element_loc_list_p (loc
)
18638 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18639 && loc
->expr
->dw_loc_next
== NULL
18640 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18642 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18643 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18644 = plus_constant (GET_MODE (x
), x
, off
);
18647 loc_list_plus_const (loc
, off
);
18649 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18651 else if (DECL_EXTERNAL (decl
))
18652 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18653 equate_decl_number_to_die (decl
, var_die
);
18657 /* If the compiler emitted a definition for the DECL declaration
18658 and if we already emitted a DIE for it, don't emit a second
18659 DIE for it again. Allow re-declarations of DECLs that are
18660 inside functions, though. */
18661 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18664 /* For static data members, the declaration in the class is supposed
18665 to have DW_TAG_member tag; the specification should still be
18666 DW_TAG_variable referencing the DW_TAG_member DIE. */
18667 if (declaration
&& class_scope_p (context_die
))
18668 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18670 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18673 if (origin
!= NULL
)
18674 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18676 /* Loop unrolling can create multiple blocks that refer to the same
18677 static variable, so we must test for the DW_AT_declaration flag.
18679 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18680 copy decls and set the DECL_ABSTRACT flag on them instead of
18683 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18685 ??? The declare_in_namespace support causes us to get two DIEs for one
18686 variable, both of which are declarations. We want to avoid considering
18687 one to be a specification, so we must test that this DIE is not a
18689 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18690 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18692 /* This is a definition of a C++ class level static. */
18693 add_AT_specification (var_die
, old_die
);
18694 specialization_p
= true;
18695 if (DECL_NAME (decl
))
18697 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18698 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18700 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18701 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18703 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18704 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18706 if (old_die
->die_tag
== DW_TAG_member
)
18707 add_linkage_name (var_die
, decl
);
18711 add_name_and_src_coords_attributes (var_die
, decl
);
18713 if ((origin
== NULL
&& !specialization_p
)
18715 && !DECL_ABSTRACT (decl_or_origin
)
18716 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18717 decl_function_context
18718 (decl_or_origin
))))
18720 tree type
= TREE_TYPE (decl_or_origin
);
18722 if (decl_by_reference_p (decl_or_origin
))
18723 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18725 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18726 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18729 if (origin
== NULL
&& !specialization_p
)
18731 if (TREE_PUBLIC (decl
))
18732 add_AT_flag (var_die
, DW_AT_external
, 1);
18734 if (DECL_ARTIFICIAL (decl
))
18735 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18737 add_accessibility_attribute (var_die
, decl
);
18741 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18743 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18744 equate_decl_number_to_die (decl
, var_die
);
18747 && (! DECL_ABSTRACT (decl_or_origin
)
18748 /* Local static vars are shared between all clones/inlines,
18749 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18751 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18752 && TREE_STATIC (decl_or_origin
)
18753 && DECL_RTL_SET_P (decl_or_origin
)))
18754 /* When abstract origin already has DW_AT_location attribute, no need
18755 to add it again. */
18756 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18758 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18759 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18760 defer_location (decl_or_origin
, var_die
);
18762 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18763 decl
== NULL
, DW_AT_location
);
18764 add_pubname (decl_or_origin
, var_die
);
18767 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18770 /* Generate a DIE to represent a named constant. */
18773 gen_const_die (tree decl
, dw_die_ref context_die
)
18775 dw_die_ref const_die
;
18776 tree type
= TREE_TYPE (decl
);
18778 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18779 add_name_and_src_coords_attributes (const_die
, decl
);
18780 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18781 if (TREE_PUBLIC (decl
))
18782 add_AT_flag (const_die
, DW_AT_external
, 1);
18783 if (DECL_ARTIFICIAL (decl
))
18784 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18785 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18788 /* Generate a DIE to represent a label identifier. */
18791 gen_label_die (tree decl
, dw_die_ref context_die
)
18793 tree origin
= decl_ultimate_origin (decl
);
18794 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18796 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18798 if (origin
!= NULL
)
18799 add_abstract_origin_attribute (lbl_die
, origin
);
18801 add_name_and_src_coords_attributes (lbl_die
, decl
);
18803 if (DECL_ABSTRACT (decl
))
18804 equate_decl_number_to_die (decl
, lbl_die
);
18807 insn
= DECL_RTL_IF_SET (decl
);
18809 /* Deleted labels are programmer specified labels which have been
18810 eliminated because of various optimizations. We still emit them
18811 here so that it is possible to put breakpoints on them. */
18815 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18817 /* When optimization is enabled (via -O) some parts of the compiler
18818 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18819 represent source-level labels which were explicitly declared by
18820 the user. This really shouldn't be happening though, so catch
18821 it if it ever does happen. */
18822 gcc_assert (!INSN_DELETED_P (insn
));
18824 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18825 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18829 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18830 && CODE_LABEL_NUMBER (insn
) != -1)
18832 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18833 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18838 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18839 attributes to the DIE for a block STMT, to describe where the inlined
18840 function was called from. This is similar to add_src_coords_attributes. */
18843 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18845 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18847 if (dwarf_version
>= 3 || !dwarf_strict
)
18849 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18850 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18855 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18856 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18859 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18861 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18863 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18864 && (dwarf_version
>= 3 || !dwarf_strict
))
18866 tree chain
, superblock
= NULL_TREE
;
18868 dw_attr_ref attr
= NULL
;
18870 if (inlined_function_outer_scope_p (stmt
))
18872 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18873 BLOCK_NUMBER (stmt
));
18874 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18877 /* Optimize duplicate .debug_ranges lists or even tails of
18878 lists. If this BLOCK has same ranges as its supercontext,
18879 lookup DW_AT_ranges attribute in the supercontext (and
18880 recursively so), verify that the ranges_table contains the
18881 right values and use it instead of adding a new .debug_range. */
18882 for (chain
= stmt
, pdie
= die
;
18883 BLOCK_SAME_RANGE (chain
);
18884 chain
= BLOCK_SUPERCONTEXT (chain
))
18886 dw_attr_ref new_attr
;
18888 pdie
= pdie
->die_parent
;
18891 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18893 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18894 if (new_attr
== NULL
18895 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18898 superblock
= BLOCK_SUPERCONTEXT (chain
);
18901 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18902 / 2 / DWARF2_ADDR_SIZE
].num
18903 == BLOCK_NUMBER (superblock
))
18904 && BLOCK_FRAGMENT_CHAIN (superblock
))
18906 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18907 / 2 / DWARF2_ADDR_SIZE
;
18908 unsigned long supercnt
= 0, thiscnt
= 0;
18909 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18910 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18913 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18914 == BLOCK_NUMBER (chain
));
18916 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18917 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18918 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18920 gcc_assert (supercnt
>= thiscnt
);
18921 add_AT_range_list (die
, DW_AT_ranges
,
18922 ((off
+ supercnt
- thiscnt
)
18923 * 2 * DWARF2_ADDR_SIZE
),
18928 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18930 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18933 add_ranges (chain
);
18934 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18941 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18942 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18943 BLOCK_NUMBER (stmt
));
18944 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18945 BLOCK_NUMBER (stmt
));
18946 add_AT_low_high_pc (die
, label
, label_high
, false);
18950 /* Generate a DIE for a lexical block. */
18953 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18955 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18957 if (call_arg_locations
)
18959 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18960 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18961 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18964 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18965 add_high_low_attributes (stmt
, stmt_die
);
18967 decls_for_scope (stmt
, stmt_die
, depth
);
18970 /* Generate a DIE for an inlined subprogram. */
18973 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18977 /* The instance of function that is effectively being inlined shall not
18979 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18981 decl
= block_ultimate_origin (stmt
);
18983 /* Emit info for the abstract instance first, if we haven't yet. We
18984 must emit this even if the block is abstract, otherwise when we
18985 emit the block below (or elsewhere), we may end up trying to emit
18986 a die whose origin die hasn't been emitted, and crashing. */
18987 dwarf2out_abstract_function (decl
);
18989 if (! BLOCK_ABSTRACT (stmt
))
18991 dw_die_ref subr_die
18992 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18994 if (call_arg_locations
)
18996 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18997 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18998 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
19000 add_abstract_origin_attribute (subr_die
, decl
);
19001 if (TREE_ASM_WRITTEN (stmt
))
19002 add_high_low_attributes (stmt
, subr_die
);
19003 add_call_src_coords_attributes (stmt
, subr_die
);
19005 decls_for_scope (stmt
, subr_die
, depth
);
19006 current_function_has_inlines
= 1;
19010 /* Generate a DIE for a field in a record, or structure. */
19013 gen_field_die (tree decl
, dw_die_ref context_die
)
19015 dw_die_ref decl_die
;
19017 if (TREE_TYPE (decl
) == error_mark_node
)
19020 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19021 add_name_and_src_coords_attributes (decl_die
, decl
);
19022 add_type_attribute (decl_die
, member_declared_type (decl
),
19023 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19026 if (DECL_BIT_FIELD_TYPE (decl
))
19028 add_byte_size_attribute (decl_die
, decl
);
19029 add_bit_size_attribute (decl_die
, decl
);
19030 add_bit_offset_attribute (decl_die
, decl
);
19033 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19034 add_data_member_location_attribute (decl_die
, decl
);
19036 if (DECL_ARTIFICIAL (decl
))
19037 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19039 add_accessibility_attribute (decl_die
, decl
);
19041 /* Equate decl number to die, so that we can look up this decl later on. */
19042 equate_decl_number_to_die (decl
, decl_die
);
19046 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19047 Use modified_type_die instead.
19048 We keep this code here just in case these types of DIEs may be needed to
19049 represent certain things in other languages (e.g. Pascal) someday. */
19052 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19055 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19057 equate_type_number_to_die (type
, ptr_die
);
19058 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19059 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19062 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19063 Use modified_type_die instead.
19064 We keep this code here just in case these types of DIEs may be needed to
19065 represent certain things in other languages (e.g. Pascal) someday. */
19068 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19070 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19072 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19073 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19075 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19077 equate_type_number_to_die (type
, ref_die
);
19078 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19079 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19083 /* Generate a DIE for a pointer to a member type. */
19086 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19089 = new_die (DW_TAG_ptr_to_member_type
,
19090 scope_die_for (type
, context_die
), type
);
19092 equate_type_number_to_die (type
, ptr_die
);
19093 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19094 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19095 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19098 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19100 static char *producer_string
;
19102 /* Return a heap allocated producer string including command line options
19103 if -grecord-gcc-switches. */
19106 gen_producer_string (void)
19109 vec
<dchar_p
> switches
= vNULL
;
19110 const char *language_string
= lang_hooks
.name
;
19111 char *producer
, *tail
;
19113 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19114 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19116 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19117 switch (save_decoded_options
[j
].opt_index
)
19124 case OPT_auxbase_strip
:
19133 case OPT_SPECIAL_unknown
:
19134 case OPT_SPECIAL_ignore
:
19135 case OPT_SPECIAL_program_name
:
19136 case OPT_SPECIAL_input_file
:
19137 case OPT_grecord_gcc_switches
:
19138 case OPT_gno_record_gcc_switches
:
19139 case OPT__output_pch_
:
19140 case OPT_fdiagnostics_show_location_
:
19141 case OPT_fdiagnostics_show_option
:
19142 case OPT_fdiagnostics_show_caret
:
19143 case OPT_fdiagnostics_color_
:
19144 case OPT_fverbose_asm
:
19146 case OPT__sysroot_
:
19148 case OPT_nostdinc__
:
19149 /* Ignore these. */
19152 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19153 & CL_NO_DWARF_RECORD
)
19155 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19157 switch (save_decoded_options
[j
].canonical_option
[0][1])
19164 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19171 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19172 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19176 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19178 sprintf (tail
, "%s %s", language_string
, version_string
);
19181 FOR_EACH_VEC_ELT (switches
, j
, p
)
19185 memcpy (tail
+ 1, p
, len
);
19190 switches
.release ();
19194 /* Generate the DIE for the compilation unit. */
19197 gen_compile_unit_die (const char *filename
)
19200 const char *language_string
= lang_hooks
.name
;
19203 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19207 add_name_attribute (die
, filename
);
19208 /* Don't add cwd for <built-in>. */
19209 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19210 add_comp_dir_attribute (die
);
19213 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19215 /* If our producer is LTO try to figure out a common language to use
19216 from the global list of translation units. */
19217 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19221 const char *common_lang
= NULL
;
19223 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19225 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19228 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19229 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19231 else if (strncmp (common_lang
, "GNU C", 5) == 0
19232 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19233 /* Mixing C and C++ is ok, use C++ in that case. */
19234 common_lang
= "GNU C++";
19237 /* Fall back to C. */
19238 common_lang
= NULL
;
19244 language_string
= common_lang
;
19247 language
= DW_LANG_C89
;
19248 if (strcmp (language_string
, "GNU C++") == 0)
19249 language
= DW_LANG_C_plus_plus
;
19250 else if (strcmp (language_string
, "GNU F77") == 0)
19251 language
= DW_LANG_Fortran77
;
19252 else if (strcmp (language_string
, "GNU Pascal") == 0)
19253 language
= DW_LANG_Pascal83
;
19254 else if (dwarf_version
>= 3 || !dwarf_strict
)
19256 if (strcmp (language_string
, "GNU Ada") == 0)
19257 language
= DW_LANG_Ada95
;
19258 else if (strcmp (language_string
, "GNU Fortran") == 0)
19259 language
= DW_LANG_Fortran95
;
19260 else if (strcmp (language_string
, "GNU Java") == 0)
19261 language
= DW_LANG_Java
;
19262 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19263 language
= DW_LANG_ObjC
;
19264 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19265 language
= DW_LANG_ObjC_plus_plus
;
19266 else if (dwarf_version
>= 5 || !dwarf_strict
)
19268 if (strcmp (language_string
, "GNU Go") == 0)
19269 language
= DW_LANG_Go
;
19272 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19273 else if (strcmp (language_string
, "GNU Fortran") == 0)
19274 language
= DW_LANG_Fortran90
;
19276 add_AT_unsigned (die
, DW_AT_language
, language
);
19280 case DW_LANG_Fortran77
:
19281 case DW_LANG_Fortran90
:
19282 case DW_LANG_Fortran95
:
19283 /* Fortran has case insensitive identifiers and the front-end
19284 lowercases everything. */
19285 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19288 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19294 /* Generate the DIE for a base class. */
19297 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19299 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19301 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19302 add_data_member_location_attribute (die
, binfo
);
19304 if (BINFO_VIRTUAL_P (binfo
))
19305 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19307 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19308 children, otherwise the default is DW_ACCESS_public. In DWARF2
19309 the default has always been DW_ACCESS_private. */
19310 if (access
== access_public_node
)
19312 if (dwarf_version
== 2
19313 || context_die
->die_tag
== DW_TAG_class_type
)
19314 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19316 else if (access
== access_protected_node
)
19317 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19318 else if (dwarf_version
> 2
19319 && context_die
->die_tag
!= DW_TAG_class_type
)
19320 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19323 /* Generate a DIE for a class member. */
19326 gen_member_die (tree type
, dw_die_ref context_die
)
19329 tree binfo
= TYPE_BINFO (type
);
19332 /* If this is not an incomplete type, output descriptions of each of its
19333 members. Note that as we output the DIEs necessary to represent the
19334 members of this record or union type, we will also be trying to output
19335 DIEs to represent the *types* of those members. However the `type'
19336 function (above) will specifically avoid generating type DIEs for member
19337 types *within* the list of member DIEs for this (containing) type except
19338 for those types (of members) which are explicitly marked as also being
19339 members of this (containing) type themselves. The g++ front- end can
19340 force any given type to be treated as a member of some other (containing)
19341 type by setting the TYPE_CONTEXT of the given (member) type to point to
19342 the TREE node representing the appropriate (containing) type. */
19344 /* First output info about the base classes. */
19347 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19351 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19352 gen_inheritance_die (base
,
19353 (accesses
? (*accesses
)[i
] : access_public_node
),
19357 /* Now output info about the data members and type members. */
19358 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19360 /* If we thought we were generating minimal debug info for TYPE
19361 and then changed our minds, some of the member declarations
19362 may have already been defined. Don't define them again, but
19363 do put them in the right order. */
19365 child
= lookup_decl_die (member
);
19367 splice_child_die (context_die
, child
);
19369 gen_decl_die (member
, NULL
, context_die
);
19372 /* Now output info about the function members (if any). */
19373 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19375 /* Don't include clones in the member list. */
19376 if (DECL_ABSTRACT_ORIGIN (member
))
19379 child
= lookup_decl_die (member
);
19381 splice_child_die (context_die
, child
);
19383 gen_decl_die (member
, NULL
, context_die
);
19387 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19388 is set, we pretend that the type was never defined, so we only get the
19389 member DIEs needed by later specification DIEs. */
19392 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19393 enum debug_info_usage usage
)
19395 dw_die_ref type_die
= lookup_type_die (type
);
19396 dw_die_ref scope_die
= 0;
19398 int complete
= (TYPE_SIZE (type
)
19399 && (! TYPE_STUB_DECL (type
)
19400 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19401 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19402 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19404 if (type_die
&& ! complete
)
19407 if (TYPE_CONTEXT (type
) != NULL_TREE
19408 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19409 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19412 scope_die
= scope_die_for (type
, context_die
);
19414 /* Generate child dies for template paramaters. */
19415 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19416 schedule_generic_params_dies_gen (type
);
19418 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19419 /* First occurrence of type or toplevel definition of nested class. */
19421 dw_die_ref old_die
= type_die
;
19423 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19424 ? record_type_tag (type
) : DW_TAG_union_type
,
19426 equate_type_number_to_die (type
, type_die
);
19428 add_AT_specification (type_die
, old_die
);
19430 add_name_attribute (type_die
, type_tag (type
));
19433 remove_AT (type_die
, DW_AT_declaration
);
19435 /* If this type has been completed, then give it a byte_size attribute and
19436 then give a list of members. */
19437 if (complete
&& !ns_decl
)
19439 /* Prevent infinite recursion in cases where the type of some member of
19440 this type is expressed in terms of this type itself. */
19441 TREE_ASM_WRITTEN (type
) = 1;
19442 add_byte_size_attribute (type_die
, type
);
19443 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19445 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19446 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19449 /* If the first reference to this type was as the return type of an
19450 inline function, then it may not have a parent. Fix this now. */
19451 if (type_die
->die_parent
== NULL
)
19452 add_child_die (scope_die
, type_die
);
19454 push_decl_scope (type
);
19455 gen_member_die (type
, type_die
);
19458 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19459 if (TYPE_ARTIFICIAL (type
))
19460 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19462 /* GNU extension: Record what type our vtable lives in. */
19463 if (TYPE_VFIELD (type
))
19465 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19467 gen_type_die (vtype
, context_die
);
19468 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19469 lookup_type_die (vtype
));
19474 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19476 /* We don't need to do this for function-local types. */
19477 if (TYPE_STUB_DECL (type
)
19478 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19479 vec_safe_push (incomplete_types
, type
);
19482 if (get_AT (type_die
, DW_AT_name
))
19483 add_pubtype (type
, type_die
);
19486 /* Generate a DIE for a subroutine _type_. */
19489 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19491 tree return_type
= TREE_TYPE (type
);
19492 dw_die_ref subr_die
19493 = new_die (DW_TAG_subroutine_type
,
19494 scope_die_for (type
, context_die
), type
);
19496 equate_type_number_to_die (type
, subr_die
);
19497 add_prototyped_attribute (subr_die
, type
);
19498 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19499 gen_formal_types_die (type
, subr_die
);
19501 if (get_AT (subr_die
, DW_AT_name
))
19502 add_pubtype (type
, subr_die
);
19505 /* Generate a DIE for a type definition. */
19508 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19510 dw_die_ref type_die
;
19513 if (TREE_ASM_WRITTEN (decl
))
19516 TREE_ASM_WRITTEN (decl
) = 1;
19517 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19518 origin
= decl_ultimate_origin (decl
);
19519 if (origin
!= NULL
)
19520 add_abstract_origin_attribute (type_die
, origin
);
19525 add_name_and_src_coords_attributes (type_die
, decl
);
19526 if (DECL_ORIGINAL_TYPE (decl
))
19528 type
= DECL_ORIGINAL_TYPE (decl
);
19530 gcc_assert (type
!= TREE_TYPE (decl
));
19531 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19535 type
= TREE_TYPE (decl
);
19537 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19539 /* Here, we are in the case of decl being a typedef naming
19540 an anonymous type, e.g:
19541 typedef struct {...} foo;
19542 In that case TREE_TYPE (decl) is not a typedef variant
19543 type and TYPE_NAME of the anonymous type is set to the
19544 TYPE_DECL of the typedef. This construct is emitted by
19547 TYPE is the anonymous struct named by the typedef
19548 DECL. As we need the DW_AT_type attribute of the
19549 DW_TAG_typedef to point to the DIE of TYPE, let's
19550 generate that DIE right away. add_type_attribute
19551 called below will then pick (via lookup_type_die) that
19552 anonymous struct DIE. */
19553 if (!TREE_ASM_WRITTEN (type
))
19554 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19556 /* This is a GNU Extension. We are adding a
19557 DW_AT_linkage_name attribute to the DIE of the
19558 anonymous struct TYPE. The value of that attribute
19559 is the name of the typedef decl naming the anonymous
19560 struct. This greatly eases the work of consumers of
19561 this debug info. */
19562 add_linkage_attr (lookup_type_die (type
), decl
);
19566 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19567 TREE_THIS_VOLATILE (decl
), context_die
);
19569 if (is_naming_typedef_decl (decl
))
19570 /* We want that all subsequent calls to lookup_type_die with
19571 TYPE in argument yield the DW_TAG_typedef we have just
19573 equate_type_number_to_die (type
, type_die
);
19575 add_accessibility_attribute (type_die
, decl
);
19578 if (DECL_ABSTRACT (decl
))
19579 equate_decl_number_to_die (decl
, type_die
);
19581 if (get_AT (type_die
, DW_AT_name
))
19582 add_pubtype (decl
, type_die
);
19585 /* Generate a DIE for a struct, class, enum or union type. */
19588 gen_tagged_type_die (tree type
,
19589 dw_die_ref context_die
,
19590 enum debug_info_usage usage
)
19594 if (type
== NULL_TREE
19595 || !is_tagged_type (type
))
19598 /* If this is a nested type whose containing class hasn't been written
19599 out yet, writing it out will cover this one, too. This does not apply
19600 to instantiations of member class templates; they need to be added to
19601 the containing class as they are generated. FIXME: This hurts the
19602 idea of combining type decls from multiple TUs, since we can't predict
19603 what set of template instantiations we'll get. */
19604 if (TYPE_CONTEXT (type
)
19605 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19606 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19608 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19610 if (TREE_ASM_WRITTEN (type
))
19613 /* If that failed, attach ourselves to the stub. */
19614 push_decl_scope (TYPE_CONTEXT (type
));
19615 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19618 else if (TYPE_CONTEXT (type
) != NULL_TREE
19619 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19621 /* If this type is local to a function that hasn't been written
19622 out yet, use a NULL context for now; it will be fixed up in
19623 decls_for_scope. */
19624 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19625 /* A declaration DIE doesn't count; nested types need to go in the
19627 if (context_die
&& is_declaration_die (context_die
))
19628 context_die
= NULL
;
19633 context_die
= declare_in_namespace (type
, context_die
);
19637 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19639 /* This might have been written out by the call to
19640 declare_in_namespace. */
19641 if (!TREE_ASM_WRITTEN (type
))
19642 gen_enumeration_type_die (type
, context_die
);
19645 gen_struct_or_union_type_die (type
, context_die
, usage
);
19650 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19651 it up if it is ever completed. gen_*_type_die will set it for us
19652 when appropriate. */
19655 /* Generate a type description DIE. */
19658 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19659 enum debug_info_usage usage
)
19661 struct array_descr_info info
;
19663 if (type
== NULL_TREE
|| type
== error_mark_node
)
19666 if (TYPE_NAME (type
) != NULL_TREE
19667 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19668 && is_redundant_typedef (TYPE_NAME (type
))
19669 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19670 /* The DECL of this type is a typedef we don't want to emit debug
19671 info for but we want debug info for its underlying typedef.
19672 This can happen for e.g, the injected-class-name of a C++
19674 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19676 /* If TYPE is a typedef type variant, let's generate debug info
19677 for the parent typedef which TYPE is a type of. */
19678 if (typedef_variant_p (type
))
19680 if (TREE_ASM_WRITTEN (type
))
19683 /* Prevent broken recursion; we can't hand off to the same type. */
19684 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19686 /* Give typedefs the right scope. */
19687 context_die
= scope_die_for (type
, context_die
);
19689 TREE_ASM_WRITTEN (type
) = 1;
19691 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19695 /* If type is an anonymous tagged type named by a typedef, let's
19696 generate debug info for the typedef. */
19697 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19699 /* Use the DIE of the containing namespace as the parent DIE of
19700 the type description DIE we want to generate. */
19701 if (DECL_CONTEXT (TYPE_NAME (type
))
19702 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19703 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19705 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19709 /* If this is an array type with hidden descriptor, handle it first. */
19710 if (!TREE_ASM_WRITTEN (type
)
19711 && lang_hooks
.types
.get_array_descr_info
19712 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19713 && (dwarf_version
>= 3 || !dwarf_strict
))
19715 gen_descr_array_type_die (type
, &info
, context_die
);
19716 TREE_ASM_WRITTEN (type
) = 1;
19720 /* We are going to output a DIE to represent the unqualified version
19721 of this type (i.e. without any const or volatile qualifiers) so
19722 get the main variant (i.e. the unqualified version) of this type
19723 now. (Vectors are special because the debugging info is in the
19724 cloned type itself). */
19725 if (TREE_CODE (type
) != VECTOR_TYPE
)
19726 type
= type_main_variant (type
);
19728 if (TREE_ASM_WRITTEN (type
))
19731 switch (TREE_CODE (type
))
19737 case REFERENCE_TYPE
:
19738 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19739 ensures that the gen_type_die recursion will terminate even if the
19740 type is recursive. Recursive types are possible in Ada. */
19741 /* ??? We could perhaps do this for all types before the switch
19743 TREE_ASM_WRITTEN (type
) = 1;
19745 /* For these types, all that is required is that we output a DIE (or a
19746 set of DIEs) to represent the "basis" type. */
19747 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19748 DINFO_USAGE_IND_USE
);
19752 /* This code is used for C++ pointer-to-data-member types.
19753 Output a description of the relevant class type. */
19754 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19755 DINFO_USAGE_IND_USE
);
19757 /* Output a description of the type of the object pointed to. */
19758 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19759 DINFO_USAGE_IND_USE
);
19761 /* Now output a DIE to represent this pointer-to-data-member type
19763 gen_ptr_to_mbr_type_die (type
, context_die
);
19766 case FUNCTION_TYPE
:
19767 /* Force out return type (in case it wasn't forced out already). */
19768 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19769 DINFO_USAGE_DIR_USE
);
19770 gen_subroutine_type_die (type
, context_die
);
19774 /* Force out return type (in case it wasn't forced out already). */
19775 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19776 DINFO_USAGE_DIR_USE
);
19777 gen_subroutine_type_die (type
, context_die
);
19781 gen_array_type_die (type
, context_die
);
19785 gen_array_type_die (type
, context_die
);
19788 case ENUMERAL_TYPE
:
19791 case QUAL_UNION_TYPE
:
19792 gen_tagged_type_die (type
, context_die
, usage
);
19798 case FIXED_POINT_TYPE
:
19801 /* No DIEs needed for fundamental types. */
19806 /* Just use DW_TAG_unspecified_type. */
19808 dw_die_ref type_die
= lookup_type_die (type
);
19809 if (type_die
== NULL
)
19811 tree name
= TYPE_NAME (type
);
19812 if (TREE_CODE (name
) == TYPE_DECL
)
19813 name
= DECL_NAME (name
);
19814 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19815 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19816 equate_type_number_to_die (type
, type_die
);
19822 gcc_unreachable ();
19825 TREE_ASM_WRITTEN (type
) = 1;
19829 gen_type_die (tree type
, dw_die_ref context_die
)
19831 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19834 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19835 things which are local to the given block. */
19838 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19840 int must_output_die
= 0;
19843 /* Ignore blocks that are NULL. */
19844 if (stmt
== NULL_TREE
)
19847 inlined_func
= inlined_function_outer_scope_p (stmt
);
19849 /* If the block is one fragment of a non-contiguous block, do not
19850 process the variables, since they will have been done by the
19851 origin block. Do process subblocks. */
19852 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19856 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19857 gen_block_die (sub
, context_die
, depth
+ 1);
19862 /* Determine if we need to output any Dwarf DIEs at all to represent this
19865 /* The outer scopes for inlinings *must* always be represented. We
19866 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19867 must_output_die
= 1;
19870 /* Determine if this block directly contains any "significant"
19871 local declarations which we will need to output DIEs for. */
19872 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19873 /* We are not in terse mode so *any* local declaration counts
19874 as being a "significant" one. */
19875 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19876 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19877 && (TREE_USED (stmt
)
19878 || TREE_ASM_WRITTEN (stmt
)
19879 || BLOCK_ABSTRACT (stmt
)));
19880 else if ((TREE_USED (stmt
)
19881 || TREE_ASM_WRITTEN (stmt
)
19882 || BLOCK_ABSTRACT (stmt
))
19883 && !dwarf2out_ignore_block (stmt
))
19884 must_output_die
= 1;
19887 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19888 DIE for any block which contains no significant local declarations at
19889 all. Rather, in such cases we just call `decls_for_scope' so that any
19890 needed Dwarf info for any sub-blocks will get properly generated. Note
19891 that in terse mode, our definition of what constitutes a "significant"
19892 local declaration gets restricted to include only inlined function
19893 instances and local (nested) function definitions. */
19894 if (must_output_die
)
19898 /* If STMT block is abstract, that means we have been called
19899 indirectly from dwarf2out_abstract_function.
19900 That function rightfully marks the descendent blocks (of
19901 the abstract function it is dealing with) as being abstract,
19902 precisely to prevent us from emitting any
19903 DW_TAG_inlined_subroutine DIE as a descendent
19904 of an abstract function instance. So in that case, we should
19905 not call gen_inlined_subroutine_die.
19907 Later though, when cgraph asks dwarf2out to emit info
19908 for the concrete instance of the function decl into which
19909 the concrete instance of STMT got inlined, the later will lead
19910 to the generation of a DW_TAG_inlined_subroutine DIE. */
19911 if (! BLOCK_ABSTRACT (stmt
))
19912 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19915 gen_lexical_block_die (stmt
, context_die
, depth
);
19918 decls_for_scope (stmt
, context_die
, depth
);
19921 /* Process variable DECL (or variable with origin ORIGIN) within
19922 block STMT and add it to CONTEXT_DIE. */
19924 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19927 tree decl_or_origin
= decl
? decl
: origin
;
19929 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19930 die
= lookup_decl_die (decl_or_origin
);
19931 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19932 && TYPE_DECL_IS_STUB (decl_or_origin
))
19933 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19937 if (die
!= NULL
&& die
->die_parent
== NULL
)
19938 add_child_die (context_die
, die
);
19939 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19940 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19941 stmt
, context_die
);
19943 gen_decl_die (decl
, origin
, context_die
);
19946 /* Generate all of the decls declared within a given scope and (recursively)
19947 all of its sub-blocks. */
19950 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19956 /* Ignore NULL blocks. */
19957 if (stmt
== NULL_TREE
)
19960 /* Output the DIEs to represent all of the data objects and typedefs
19961 declared directly within this block but not within any nested
19962 sub-blocks. Also, nested function and tag DIEs have been
19963 generated with a parent of NULL; fix that up now. */
19964 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19965 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19966 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19967 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19970 /* If we're at -g1, we're not interested in subblocks. */
19971 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19974 /* Output the DIEs to represent all sub-blocks (and the items declared
19975 therein) of this block. */
19976 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19978 subblocks
= BLOCK_CHAIN (subblocks
))
19979 gen_block_die (subblocks
, context_die
, depth
+ 1);
19982 /* Is this a typedef we can avoid emitting? */
19985 is_redundant_typedef (const_tree decl
)
19987 if (TYPE_DECL_IS_STUB (decl
))
19990 if (DECL_ARTIFICIAL (decl
)
19991 && DECL_CONTEXT (decl
)
19992 && is_tagged_type (DECL_CONTEXT (decl
))
19993 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19994 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19995 /* Also ignore the artificial member typedef for the class name. */
20001 /* Return TRUE if TYPE is a typedef that names a type for linkage
20002 purposes. This kind of typedefs is produced by the C++ FE for
20005 typedef struct {...} foo;
20007 In that case, there is no typedef variant type produced for foo.
20008 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20012 is_naming_typedef_decl (const_tree decl
)
20014 if (decl
== NULL_TREE
20015 || TREE_CODE (decl
) != TYPE_DECL
20016 || !is_tagged_type (TREE_TYPE (decl
))
20017 || DECL_IS_BUILTIN (decl
)
20018 || is_redundant_typedef (decl
)
20019 /* It looks like Ada produces TYPE_DECLs that are very similar
20020 to C++ naming typedefs but that have different
20021 semantics. Let's be specific to c++ for now. */
20025 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20026 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20027 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20028 != TYPE_NAME (TREE_TYPE (decl
))));
20031 /* Returns the DIE for a context. */
20033 static inline dw_die_ref
20034 get_context_die (tree context
)
20038 /* Find die that represents this context. */
20039 if (TYPE_P (context
))
20041 context
= TYPE_MAIN_VARIANT (context
);
20042 return strip_naming_typedef (context
, force_type_die (context
));
20045 return force_decl_die (context
);
20047 return comp_unit_die ();
20050 /* Returns the DIE for decl. A DIE will always be returned. */
20053 force_decl_die (tree decl
)
20055 dw_die_ref decl_die
;
20056 unsigned saved_external_flag
;
20057 tree save_fn
= NULL_TREE
;
20058 decl_die
= lookup_decl_die (decl
);
20061 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20063 decl_die
= lookup_decl_die (decl
);
20067 switch (TREE_CODE (decl
))
20069 case FUNCTION_DECL
:
20070 /* Clear current_function_decl, so that gen_subprogram_die thinks
20071 that this is a declaration. At this point, we just want to force
20072 declaration die. */
20073 save_fn
= current_function_decl
;
20074 current_function_decl
= NULL_TREE
;
20075 gen_subprogram_die (decl
, context_die
);
20076 current_function_decl
= save_fn
;
20080 /* Set external flag to force declaration die. Restore it after
20081 gen_decl_die() call. */
20082 saved_external_flag
= DECL_EXTERNAL (decl
);
20083 DECL_EXTERNAL (decl
) = 1;
20084 gen_decl_die (decl
, NULL
, context_die
);
20085 DECL_EXTERNAL (decl
) = saved_external_flag
;
20088 case NAMESPACE_DECL
:
20089 if (dwarf_version
>= 3 || !dwarf_strict
)
20090 dwarf2out_decl (decl
);
20092 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20093 decl_die
= comp_unit_die ();
20096 case TRANSLATION_UNIT_DECL
:
20097 decl_die
= comp_unit_die ();
20101 gcc_unreachable ();
20104 /* We should be able to find the DIE now. */
20106 decl_die
= lookup_decl_die (decl
);
20107 gcc_assert (decl_die
);
20113 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20114 always returned. */
20117 force_type_die (tree type
)
20119 dw_die_ref type_die
;
20121 type_die
= lookup_type_die (type
);
20124 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20126 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20127 TYPE_VOLATILE (type
), context_die
);
20128 gcc_assert (type_die
);
20133 /* Force out any required namespaces to be able to output DECL,
20134 and return the new context_die for it, if it's changed. */
20137 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20139 tree context
= (DECL_P (thing
)
20140 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20141 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20142 /* Force out the namespace. */
20143 context_die
= force_decl_die (context
);
20145 return context_die
;
20148 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20149 type) within its namespace, if appropriate.
20151 For compatibility with older debuggers, namespace DIEs only contain
20152 declarations; all definitions are emitted at CU scope. */
20155 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20157 dw_die_ref ns_context
;
20159 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20160 return context_die
;
20162 /* If this decl is from an inlined function, then don't try to emit it in its
20163 namespace, as we will get confused. It would have already been emitted
20164 when the abstract instance of the inline function was emitted anyways. */
20165 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20166 return context_die
;
20168 ns_context
= setup_namespace_context (thing
, context_die
);
20170 if (ns_context
!= context_die
)
20174 if (DECL_P (thing
))
20175 gen_decl_die (thing
, NULL
, ns_context
);
20177 gen_type_die (thing
, ns_context
);
20179 return context_die
;
20182 /* Generate a DIE for a namespace or namespace alias. */
20185 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20187 dw_die_ref namespace_die
;
20189 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20190 they are an alias of. */
20191 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20193 /* Output a real namespace or module. */
20194 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20195 namespace_die
= new_die (is_fortran ()
20196 ? DW_TAG_module
: DW_TAG_namespace
,
20197 context_die
, decl
);
20198 /* For Fortran modules defined in different CU don't add src coords. */
20199 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20201 const char *name
= dwarf2_name (decl
, 0);
20203 add_name_attribute (namespace_die
, name
);
20206 add_name_and_src_coords_attributes (namespace_die
, decl
);
20207 if (DECL_EXTERNAL (decl
))
20208 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20209 equate_decl_number_to_die (decl
, namespace_die
);
20213 /* Output a namespace alias. */
20215 /* Force out the namespace we are an alias of, if necessary. */
20216 dw_die_ref origin_die
20217 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20219 if (DECL_FILE_SCOPE_P (decl
)
20220 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20221 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20222 /* Now create the namespace alias DIE. */
20223 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20224 add_name_and_src_coords_attributes (namespace_die
, decl
);
20225 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20226 equate_decl_number_to_die (decl
, namespace_die
);
20228 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20229 if (want_pubnames ())
20230 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20233 /* Generate Dwarf debug information for a decl described by DECL.
20234 The return value is currently only meaningful for PARM_DECLs,
20235 for all other decls it returns NULL. */
20238 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20240 tree decl_or_origin
= decl
? decl
: origin
;
20241 tree class_origin
= NULL
, ultimate_origin
;
20243 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20246 switch (TREE_CODE (decl_or_origin
))
20252 if (!is_fortran () && !is_ada ())
20254 /* The individual enumerators of an enum type get output when we output
20255 the Dwarf representation of the relevant enum type itself. */
20259 /* Emit its type. */
20260 gen_type_die (TREE_TYPE (decl
), context_die
);
20262 /* And its containing namespace. */
20263 context_die
= declare_in_namespace (decl
, context_die
);
20265 gen_const_die (decl
, context_die
);
20268 case FUNCTION_DECL
:
20269 /* Don't output any DIEs to represent mere function declarations,
20270 unless they are class members or explicit block externs. */
20271 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20272 && DECL_FILE_SCOPE_P (decl_or_origin
)
20273 && (current_function_decl
== NULL_TREE
20274 || DECL_ARTIFICIAL (decl_or_origin
)))
20279 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20280 on local redeclarations of global functions. That seems broken. */
20281 if (current_function_decl
!= decl
)
20282 /* This is only a declaration. */;
20285 /* If we're emitting a clone, emit info for the abstract instance. */
20286 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20287 dwarf2out_abstract_function (origin
20288 ? DECL_ORIGIN (origin
)
20289 : DECL_ABSTRACT_ORIGIN (decl
));
20291 /* If we're emitting an out-of-line copy of an inline function,
20292 emit info for the abstract instance and set up to refer to it. */
20293 else if (cgraph_function_possibly_inlined_p (decl
)
20294 && ! DECL_ABSTRACT (decl
)
20295 && ! class_or_namespace_scope_p (context_die
)
20296 /* dwarf2out_abstract_function won't emit a die if this is just
20297 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20298 that case, because that works only if we have a die. */
20299 && DECL_INITIAL (decl
) != NULL_TREE
)
20301 dwarf2out_abstract_function (decl
);
20302 set_decl_origin_self (decl
);
20305 /* Otherwise we're emitting the primary DIE for this decl. */
20306 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20308 /* Before we describe the FUNCTION_DECL itself, make sure that we
20309 have its containing type. */
20311 origin
= decl_class_context (decl
);
20312 if (origin
!= NULL_TREE
)
20313 gen_type_die (origin
, context_die
);
20315 /* And its return type. */
20316 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20318 /* And its virtual context. */
20319 if (DECL_VINDEX (decl
) != NULL_TREE
)
20320 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20322 /* Make sure we have a member DIE for decl. */
20323 if (origin
!= NULL_TREE
)
20324 gen_type_die_for_member (origin
, decl
, context_die
);
20326 /* And its containing namespace. */
20327 context_die
= declare_in_namespace (decl
, context_die
);
20330 /* Now output a DIE to represent the function itself. */
20332 gen_subprogram_die (decl
, context_die
);
20336 /* If we are in terse mode, don't generate any DIEs to represent any
20337 actual typedefs. */
20338 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20341 /* In the special case of a TYPE_DECL node representing the declaration
20342 of some type tag, if the given TYPE_DECL is marked as having been
20343 instantiated from some other (original) TYPE_DECL node (e.g. one which
20344 was generated within the original definition of an inline function) we
20345 used to generate a special (abbreviated) DW_TAG_structure_type,
20346 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20347 should be actually referencing those DIEs, as variable DIEs with that
20348 type would be emitted already in the abstract origin, so it was always
20349 removed during unused type prunning. Don't add anything in this
20351 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20354 if (is_redundant_typedef (decl
))
20355 gen_type_die (TREE_TYPE (decl
), context_die
);
20357 /* Output a DIE to represent the typedef itself. */
20358 gen_typedef_die (decl
, context_die
);
20362 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20363 gen_label_die (decl
, context_die
);
20368 /* If we are in terse mode, don't generate any DIEs to represent any
20369 variable declarations or definitions. */
20370 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20373 /* Output any DIEs that are needed to specify the type of this data
20375 if (decl_by_reference_p (decl_or_origin
))
20376 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20378 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20380 /* And its containing type. */
20381 class_origin
= decl_class_context (decl_or_origin
);
20382 if (class_origin
!= NULL_TREE
)
20383 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20385 /* And its containing namespace. */
20386 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20388 /* Now output the DIE to represent the data object itself. This gets
20389 complicated because of the possibility that the VAR_DECL really
20390 represents an inlined instance of a formal parameter for an inline
20392 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20393 if (ultimate_origin
!= NULL_TREE
20394 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20395 gen_formal_parameter_die (decl
, origin
,
20396 true /* Emit name attribute. */,
20399 gen_variable_die (decl
, origin
, context_die
);
20403 /* Ignore the nameless fields that are used to skip bits but handle C++
20404 anonymous unions and structs. */
20405 if (DECL_NAME (decl
) != NULL_TREE
20406 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20407 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20409 gen_type_die (member_declared_type (decl
), context_die
);
20410 gen_field_die (decl
, context_die
);
20415 if (DECL_BY_REFERENCE (decl_or_origin
))
20416 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20418 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20419 return gen_formal_parameter_die (decl
, origin
,
20420 true /* Emit name attribute. */,
20423 case NAMESPACE_DECL
:
20424 case IMPORTED_DECL
:
20425 if (dwarf_version
>= 3 || !dwarf_strict
)
20426 gen_namespace_die (decl
, context_die
);
20430 /* Probably some frontend-internal decl. Assume we don't care. */
20431 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20438 /* Output debug information for global decl DECL. Called from toplev.c after
20439 compilation proper has finished. */
20442 dwarf2out_global_decl (tree decl
)
20444 /* Output DWARF2 information for file-scope tentative data object
20445 declarations, file-scope (extern) function declarations (which
20446 had no corresponding body) and file-scope tagged type declarations
20447 and definitions which have not yet been forced out. */
20448 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20449 dwarf2out_decl (decl
);
20452 /* Output debug information for type decl DECL. Called from toplev.c
20453 and from language front ends (to record built-in types). */
20455 dwarf2out_type_decl (tree decl
, int local
)
20458 dwarf2out_decl (decl
);
20461 /* Output debug information for imported module or decl DECL.
20462 NAME is non-NULL name in the lexical block if the decl has been renamed.
20463 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20464 that DECL belongs to.
20465 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20467 dwarf2out_imported_module_or_decl_1 (tree decl
,
20469 tree lexical_block
,
20470 dw_die_ref lexical_block_die
)
20472 expanded_location xloc
;
20473 dw_die_ref imported_die
= NULL
;
20474 dw_die_ref at_import_die
;
20476 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20478 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20479 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20483 xloc
= expand_location (input_location
);
20485 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20487 at_import_die
= force_type_die (TREE_TYPE (decl
));
20488 /* For namespace N { typedef void T; } using N::T; base_type_die
20489 returns NULL, but DW_TAG_imported_declaration requires
20490 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20491 if (!at_import_die
)
20493 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20494 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20495 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20496 gcc_assert (at_import_die
);
20501 at_import_die
= lookup_decl_die (decl
);
20502 if (!at_import_die
)
20504 /* If we're trying to avoid duplicate debug info, we may not have
20505 emitted the member decl for this field. Emit it now. */
20506 if (TREE_CODE (decl
) == FIELD_DECL
)
20508 tree type
= DECL_CONTEXT (decl
);
20510 if (TYPE_CONTEXT (type
)
20511 && TYPE_P (TYPE_CONTEXT (type
))
20512 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20513 DINFO_USAGE_DIR_USE
))
20515 gen_type_die_for_member (type
, decl
,
20516 get_context_die (TYPE_CONTEXT (type
)));
20518 at_import_die
= force_decl_die (decl
);
20522 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20524 if (dwarf_version
>= 3 || !dwarf_strict
)
20525 imported_die
= new_die (DW_TAG_imported_module
,
20532 imported_die
= new_die (DW_TAG_imported_declaration
,
20536 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20537 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20539 add_AT_string (imported_die
, DW_AT_name
,
20540 IDENTIFIER_POINTER (name
));
20541 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20544 /* Output debug information for imported module or decl DECL.
20545 NAME is non-NULL name in context if the decl has been renamed.
20546 CHILD is true if decl is one of the renamed decls as part of
20547 importing whole module. */
20550 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20553 /* dw_die_ref at_import_die; */
20554 dw_die_ref scope_die
;
20556 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20561 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20562 We need decl DIE for reference and scope die. First, get DIE for the decl
20565 /* Get the scope die for decl context. Use comp_unit_die for global module
20566 or decl. If die is not found for non globals, force new die. */
20568 && TYPE_P (context
)
20569 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20572 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20575 scope_die
= get_context_die (context
);
20579 gcc_assert (scope_die
->die_child
);
20580 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20581 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20582 scope_die
= scope_die
->die_child
;
20585 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20586 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20590 /* Write the debugging output for DECL. */
20593 dwarf2out_decl (tree decl
)
20595 dw_die_ref context_die
= comp_unit_die ();
20597 switch (TREE_CODE (decl
))
20602 case FUNCTION_DECL
:
20603 /* What we would really like to do here is to filter out all mere
20604 file-scope declarations of file-scope functions which are never
20605 referenced later within this translation unit (and keep all of ones
20606 that *are* referenced later on) but we aren't clairvoyant, so we have
20607 no idea which functions will be referenced in the future (i.e. later
20608 on within the current translation unit). So here we just ignore all
20609 file-scope function declarations which are not also definitions. If
20610 and when the debugger needs to know something about these functions,
20611 it will have to hunt around and find the DWARF information associated
20612 with the definition of the function.
20614 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20615 nodes represent definitions and which ones represent mere
20616 declarations. We have to check DECL_INITIAL instead. That's because
20617 the C front-end supports some weird semantics for "extern inline"
20618 function definitions. These can get inlined within the current
20619 translation unit (and thus, we need to generate Dwarf info for their
20620 abstract instances so that the Dwarf info for the concrete inlined
20621 instances can have something to refer to) but the compiler never
20622 generates any out-of-lines instances of such things (despite the fact
20623 that they *are* definitions).
20625 The important point is that the C front-end marks these "extern
20626 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20627 them anyway. Note that the C++ front-end also plays some similar games
20628 for inline function definitions appearing within include files which
20629 also contain `#pragma interface' pragmas.
20631 If we are called from dwarf2out_abstract_function output a DIE
20632 anyway. We can end up here this way with early inlining and LTO
20633 where the inlined function is output in a different LTRANS unit
20635 if (DECL_INITIAL (decl
) == NULL_TREE
20636 && ! DECL_ABSTRACT (decl
))
20639 /* If we're a nested function, initially use a parent of NULL; if we're
20640 a plain function, this will be fixed up in decls_for_scope. If
20641 we're a method, it will be ignored, since we already have a DIE. */
20642 if (decl_function_context (decl
)
20643 /* But if we're in terse mode, we don't care about scope. */
20644 && debug_info_level
> DINFO_LEVEL_TERSE
)
20645 context_die
= NULL
;
20649 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20650 declaration and if the declaration was never even referenced from
20651 within this entire compilation unit. We suppress these DIEs in
20652 order to save space in the .debug section (by eliminating entries
20653 which are probably useless). Note that we must not suppress
20654 block-local extern declarations (whether used or not) because that
20655 would screw-up the debugger's name lookup mechanism and cause it to
20656 miss things which really ought to be in scope at a given point. */
20657 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20660 /* For local statics lookup proper context die. */
20661 if (TREE_STATIC (decl
)
20662 && DECL_CONTEXT (decl
)
20663 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20664 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20666 /* If we are in terse mode, don't generate any DIEs to represent any
20667 variable declarations or definitions. */
20668 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20673 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20675 if (!is_fortran () && !is_ada ())
20677 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20678 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20681 case NAMESPACE_DECL
:
20682 case IMPORTED_DECL
:
20683 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20685 if (lookup_decl_die (decl
) != NULL
)
20690 /* Don't emit stubs for types unless they are needed by other DIEs. */
20691 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20694 /* Don't bother trying to generate any DIEs to represent any of the
20695 normal built-in types for the language we are compiling. */
20696 if (DECL_IS_BUILTIN (decl
))
20699 /* If we are in terse mode, don't generate any DIEs for types. */
20700 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20703 /* If we're a function-scope tag, initially use a parent of NULL;
20704 this will be fixed up in decls_for_scope. */
20705 if (decl_function_context (decl
))
20706 context_die
= NULL
;
20714 gen_decl_die (decl
, NULL
, context_die
);
20717 /* Write the debugging output for DECL. */
20720 dwarf2out_function_decl (tree decl
)
20722 dwarf2out_decl (decl
);
20723 call_arg_locations
= NULL
;
20724 call_arg_loc_last
= NULL
;
20725 call_site_count
= -1;
20726 tail_call_site_count
= -1;
20727 block_map
.release ();
20728 htab_empty (decl_loc_table
);
20729 htab_empty (cached_dw_loc_list_table
);
20732 /* Output a marker (i.e. a label) for the beginning of the generated code for
20733 a lexical block. */
20736 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20737 unsigned int blocknum
)
20739 switch_to_section (current_function_section ());
20740 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20743 /* Output a marker (i.e. a label) for the end of the generated code for a
20747 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20749 switch_to_section (current_function_section ());
20750 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20753 /* Returns nonzero if it is appropriate not to emit any debugging
20754 information for BLOCK, because it doesn't contain any instructions.
20756 Don't allow this for blocks with nested functions or local classes
20757 as we would end up with orphans, and in the presence of scheduling
20758 we may end up calling them anyway. */
20761 dwarf2out_ignore_block (const_tree block
)
20766 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20767 if (TREE_CODE (decl
) == FUNCTION_DECL
20768 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20770 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20772 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20773 if (TREE_CODE (decl
) == FUNCTION_DECL
20774 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20781 /* Hash table routines for file_hash. */
20784 file_table_eq (const void *p1_p
, const void *p2_p
)
20786 const struct dwarf_file_data
*const p1
=
20787 (const struct dwarf_file_data
*) p1_p
;
20788 const char *const p2
= (const char *) p2_p
;
20789 return filename_cmp (p1
->filename
, p2
) == 0;
20793 file_table_hash (const void *p_p
)
20795 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20796 return htab_hash_string (p
->filename
);
20799 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20800 dwarf2out.c) and return its "index". The index of each (known) filename is
20801 just a unique number which is associated with only that one filename. We
20802 need such numbers for the sake of generating labels (in the .debug_sfnames
20803 section) and references to those files numbers (in the .debug_srcinfo
20804 and.debug_macinfo sections). If the filename given as an argument is not
20805 found in our current list, add it to the list and assign it the next
20806 available unique index number. In order to speed up searches, we remember
20807 the index of the filename was looked up last. This handles the majority of
20810 static struct dwarf_file_data
*
20811 lookup_filename (const char *file_name
)
20814 struct dwarf_file_data
* created
;
20816 /* Check to see if the file name that was searched on the previous
20817 call matches this file name. If so, return the index. */
20818 if (file_table_last_lookup
20819 && (file_name
== file_table_last_lookup
->filename
20820 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20821 return file_table_last_lookup
;
20823 /* Didn't match the previous lookup, search the table. */
20824 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20825 htab_hash_string (file_name
), INSERT
);
20827 return (struct dwarf_file_data
*) *slot
;
20829 created
= ggc_alloc_dwarf_file_data ();
20830 created
->filename
= file_name
;
20831 created
->emitted_number
= 0;
20836 /* If the assembler will construct the file table, then translate the compiler
20837 internal file table number into the assembler file table number, and emit
20838 a .file directive if we haven't already emitted one yet. The file table
20839 numbers are different because we prune debug info for unused variables and
20840 types, which may include filenames. */
20843 maybe_emit_file (struct dwarf_file_data
* fd
)
20845 if (! fd
->emitted_number
)
20847 if (last_emitted_file
)
20848 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20850 fd
->emitted_number
= 1;
20851 last_emitted_file
= fd
;
20853 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20855 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20856 output_quoted_string (asm_out_file
,
20857 remap_debug_filename (fd
->filename
));
20858 fputc ('\n', asm_out_file
);
20862 return fd
->emitted_number
;
20865 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20866 That generation should happen after function debug info has been
20867 generated. The value of the attribute is the constant value of ARG. */
20870 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20872 die_arg_entry entry
;
20877 if (!tmpl_value_parm_die_table
)
20878 vec_alloc (tmpl_value_parm_die_table
, 32);
20882 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20885 /* Return TRUE if T is an instance of generic type, FALSE
20889 generic_type_p (tree t
)
20891 if (t
== NULL_TREE
|| !TYPE_P (t
))
20893 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20896 /* Schedule the generation of the generic parameter dies for the
20897 instance of generic type T. The proper generation itself is later
20898 done by gen_scheduled_generic_parms_dies. */
20901 schedule_generic_params_dies_gen (tree t
)
20903 if (!generic_type_p (t
))
20906 if (!generic_type_instances
)
20907 vec_alloc (generic_type_instances
, 256);
20909 vec_safe_push (generic_type_instances
, t
);
20912 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20913 by append_entry_to_tmpl_value_parm_die_table. This function must
20914 be called after function DIEs have been generated. */
20917 gen_remaining_tmpl_value_param_die_attribute (void)
20919 if (tmpl_value_parm_die_table
)
20924 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20925 tree_add_const_value_attribute (e
->die
, e
->arg
);
20929 /* Generate generic parameters DIEs for instances of generic types
20930 that have been previously scheduled by
20931 schedule_generic_params_dies_gen. This function must be called
20932 after all the types of the CU have been laid out. */
20935 gen_scheduled_generic_parms_dies (void)
20940 if (!generic_type_instances
)
20943 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20944 if (COMPLETE_TYPE_P (t
))
20945 gen_generic_params_dies (t
);
20949 /* Replace DW_AT_name for the decl with name. */
20952 dwarf2out_set_name (tree decl
, tree name
)
20958 die
= TYPE_SYMTAB_DIE (decl
);
20962 dname
= dwarf2_name (name
, 0);
20966 attr
= get_AT (die
, DW_AT_name
);
20969 struct indirect_string_node
*node
;
20971 node
= find_AT_string (dname
);
20972 /* replace the string. */
20973 attr
->dw_attr_val
.v
.val_str
= node
;
20977 add_name_attribute (die
, dname
);
20980 /* True if before or during processing of the first function being emitted. */
20981 static bool in_first_function_p
= true;
20982 /* True if loc_note during dwarf2out_var_location call might still be
20983 before first real instruction at address equal to .Ltext0. */
20984 static bool maybe_at_text_label_p
= true;
20985 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20986 static unsigned int first_loclabel_num_not_at_text_label
;
20988 /* Called by the final INSN scan whenever we see a var location. We
20989 use it to drop labels in the right places, and throw the location in
20990 our lookup table. */
20993 dwarf2out_var_location (rtx loc_note
)
20995 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20996 struct var_loc_node
*newloc
;
20997 rtx next_real
, next_note
;
20998 static const char *last_label
;
20999 static const char *last_postcall_label
;
21000 static bool last_in_cold_section_p
;
21001 static rtx expected_next_loc_note
;
21005 if (!NOTE_P (loc_note
))
21007 if (CALL_P (loc_note
))
21010 if (SIBLING_CALL_P (loc_note
))
21011 tail_call_site_count
++;
21016 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21017 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21020 /* Optimize processing a large consecutive sequence of location
21021 notes so we don't spend too much time in next_real_insn. If the
21022 next insn is another location note, remember the next_real_insn
21023 calculation for next time. */
21024 next_real
= cached_next_real_insn
;
21027 if (expected_next_loc_note
!= loc_note
)
21028 next_real
= NULL_RTX
;
21031 next_note
= NEXT_INSN (loc_note
);
21033 || INSN_DELETED_P (next_note
)
21034 || ! NOTE_P (next_note
)
21035 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21036 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21037 next_note
= NULL_RTX
;
21040 next_real
= next_real_insn (loc_note
);
21044 expected_next_loc_note
= next_note
;
21045 cached_next_real_insn
= next_real
;
21048 cached_next_real_insn
= NULL_RTX
;
21050 /* If there are no instructions which would be affected by this note,
21051 don't do anything. */
21053 && next_real
== NULL_RTX
21054 && !NOTE_DURING_CALL_P (loc_note
))
21057 if (next_real
== NULL_RTX
)
21058 next_real
= get_last_insn ();
21060 /* If there were any real insns between note we processed last time
21061 and this note (or if it is the first note), clear
21062 last_{,postcall_}label so that they are not reused this time. */
21063 if (last_var_location_insn
== NULL_RTX
21064 || last_var_location_insn
!= next_real
21065 || last_in_cold_section_p
!= in_cold_section_p
)
21068 last_postcall_label
= NULL
;
21073 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21074 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21075 NOTE_DURING_CALL_P (loc_note
)
21076 ? last_postcall_label
: last_label
);
21077 if (newloc
== NULL
)
21086 /* If there were no real insns between note we processed last time
21087 and this note, use the label we emitted last time. Otherwise
21088 create a new label and emit it. */
21089 if (last_label
== NULL
)
21091 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21092 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21094 last_label
= ggc_strdup (loclabel
);
21095 /* See if loclabel might be equal to .Ltext0. If yes,
21096 bump first_loclabel_num_not_at_text_label. */
21097 if (!have_multiple_function_sections
21098 && in_first_function_p
21099 && maybe_at_text_label_p
)
21101 static rtx last_start
;
21103 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21104 if (insn
== last_start
)
21106 else if (!NONDEBUG_INSN_P (insn
))
21110 rtx body
= PATTERN (insn
);
21111 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21113 /* Inline asm could occupy zero bytes. */
21114 else if (GET_CODE (body
) == ASM_INPUT
21115 || asm_noperands (body
) >= 0)
21117 #ifdef HAVE_attr_length
21118 else if (get_attr_min_length (insn
) == 0)
21123 /* Assume insn has non-zero length. */
21124 maybe_at_text_label_p
= false;
21128 if (maybe_at_text_label_p
)
21130 last_start
= loc_note
;
21131 first_loclabel_num_not_at_text_label
= loclabel_num
;
21138 struct call_arg_loc_node
*ca_loc
21139 = ggc_alloc_cleared_call_arg_loc_node ();
21140 rtx prev
= prev_real_insn (loc_note
), x
;
21141 ca_loc
->call_arg_loc_note
= loc_note
;
21142 ca_loc
->next
= NULL
;
21143 ca_loc
->label
= last_label
;
21146 || (NONJUMP_INSN_P (prev
)
21147 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21148 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21149 if (!CALL_P (prev
))
21150 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21151 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21152 x
= get_call_rtx_from (PATTERN (prev
));
21155 x
= XEXP (XEXP (x
, 0), 0);
21156 if (GET_CODE (x
) == SYMBOL_REF
21157 && SYMBOL_REF_DECL (x
)
21158 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21159 ca_loc
->symbol_ref
= x
;
21161 ca_loc
->block
= insn_scope (prev
);
21162 if (call_arg_locations
)
21163 call_arg_loc_last
->next
= ca_loc
;
21165 call_arg_locations
= ca_loc
;
21166 call_arg_loc_last
= ca_loc
;
21168 else if (!NOTE_DURING_CALL_P (loc_note
))
21169 newloc
->label
= last_label
;
21172 if (!last_postcall_label
)
21174 sprintf (loclabel
, "%s-1", last_label
);
21175 last_postcall_label
= ggc_strdup (loclabel
);
21177 newloc
->label
= last_postcall_label
;
21180 last_var_location_insn
= next_real
;
21181 last_in_cold_section_p
= in_cold_section_p
;
21184 /* Note in one location list that text section has changed. */
21187 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21189 var_loc_list
*list
= (var_loc_list
*) *slot
;
21191 list
->last_before_switch
21192 = list
->last
->next
? list
->last
->next
: list
->last
;
21196 /* Note in all location lists that text section has changed. */
21199 var_location_switch_text_section (void)
21201 if (decl_loc_table
== NULL
)
21204 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21207 /* Create a new line number table. */
21209 static dw_line_info_table
*
21210 new_line_info_table (void)
21212 dw_line_info_table
*table
;
21214 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21215 table
->file_num
= 1;
21216 table
->line_num
= 1;
21217 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21222 /* Lookup the "current" table into which we emit line info, so
21223 that we don't have to do it for every source line. */
21226 set_cur_line_info_table (section
*sec
)
21228 dw_line_info_table
*table
;
21230 if (sec
== text_section
)
21231 table
= text_section_line_info
;
21232 else if (sec
== cold_text_section
)
21234 table
= cold_text_section_line_info
;
21237 cold_text_section_line_info
= table
= new_line_info_table ();
21238 table
->end_label
= cold_end_label
;
21243 const char *end_label
;
21245 if (flag_reorder_blocks_and_partition
)
21247 if (in_cold_section_p
)
21248 end_label
= crtl
->subsections
.cold_section_end_label
;
21250 end_label
= crtl
->subsections
.hot_section_end_label
;
21254 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21255 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21256 current_function_funcdef_no
);
21257 end_label
= ggc_strdup (label
);
21260 table
= new_line_info_table ();
21261 table
->end_label
= end_label
;
21263 vec_safe_push (separate_line_info
, table
);
21266 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21267 table
->is_stmt
= (cur_line_info_table
21268 ? cur_line_info_table
->is_stmt
21269 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21270 cur_line_info_table
= table
;
21274 /* We need to reset the locations at the beginning of each
21275 function. We can't do this in the end_function hook, because the
21276 declarations that use the locations won't have been output when
21277 that hook is called. Also compute have_multiple_function_sections here. */
21280 dwarf2out_begin_function (tree fun
)
21282 section
*sec
= function_section (fun
);
21284 if (sec
!= text_section
)
21285 have_multiple_function_sections
= true;
21287 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21289 gcc_assert (current_function_decl
== fun
);
21290 cold_text_section
= unlikely_text_section ();
21291 switch_to_section (cold_text_section
);
21292 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21293 switch_to_section (sec
);
21296 dwarf2out_note_section_used ();
21297 call_site_count
= 0;
21298 tail_call_site_count
= 0;
21300 set_cur_line_info_table (sec
);
21303 /* Helper function of dwarf2out_end_function, called only after emitting
21304 the very first function into assembly. Check if some .debug_loc range
21305 might end with a .LVL* label that could be equal to .Ltext0.
21306 In that case we must force using absolute addresses in .debug_loc ranges,
21307 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21308 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21310 Set have_multiple_function_sections to true in that case and
21311 terminate htab traversal. */
21314 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21316 var_loc_list
*entry
;
21317 struct var_loc_node
*node
;
21319 entry
= (var_loc_list
*) *slot
;
21320 node
= entry
->first
;
21321 if (node
&& node
->next
&& node
->next
->label
)
21324 const char *label
= node
->next
->label
;
21325 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21327 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21329 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21330 if (strcmp (label
, loclabel
) == 0)
21332 have_multiple_function_sections
= true;
21340 /* Hook called after emitting a function into assembly.
21341 This does something only for the very first function emitted. */
21344 dwarf2out_end_function (unsigned int)
21346 if (in_first_function_p
21347 && !have_multiple_function_sections
21348 && first_loclabel_num_not_at_text_label
21350 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21352 in_first_function_p
= false;
21353 maybe_at_text_label_p
= false;
21356 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21359 push_dw_line_info_entry (dw_line_info_table
*table
,
21360 enum dw_line_info_opcode opcode
, unsigned int val
)
21362 dw_line_info_entry e
;
21365 vec_safe_push (table
->entries
, e
);
21368 /* Output a label to mark the beginning of a source code line entry
21369 and record information relating to this source line, in
21370 'line_info_table' for later output of the .debug_line section. */
21371 /* ??? The discriminator parameter ought to be unsigned. */
21374 dwarf2out_source_line (unsigned int line
, const char *filename
,
21375 int discriminator
, bool is_stmt
)
21377 unsigned int file_num
;
21378 dw_line_info_table
*table
;
21380 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21383 /* The discriminator column was added in dwarf4. Simplify the below
21384 by simply removing it if we're not supposed to output it. */
21385 if (dwarf_version
< 4 && dwarf_strict
)
21388 table
= cur_line_info_table
;
21389 file_num
= maybe_emit_file (lookup_filename (filename
));
21391 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21392 the debugger has used the second (possibly duplicate) line number
21393 at the beginning of the function to mark the end of the prologue.
21394 We could eliminate any other duplicates within the function. For
21395 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21396 that second line number entry. */
21397 /* Recall that this end-of-prologue indication is *not* the same thing
21398 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21399 to which the hook corresponds, follows the last insn that was
21400 emitted by gen_prologue. What we need is to precede the first insn
21401 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21402 insn that corresponds to something the user wrote. These may be
21403 very different locations once scheduling is enabled. */
21405 if (0 && file_num
== table
->file_num
21406 && line
== table
->line_num
21407 && discriminator
== table
->discrim_num
21408 && is_stmt
== table
->is_stmt
)
21411 switch_to_section (current_function_section ());
21413 /* If requested, emit something human-readable. */
21414 if (flag_debug_asm
)
21415 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21417 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21419 /* Emit the .loc directive understood by GNU as. */
21420 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21421 file_num, line, is_stmt, discriminator */
21422 fputs ("\t.loc ", asm_out_file
);
21423 fprint_ul (asm_out_file
, file_num
);
21424 putc (' ', asm_out_file
);
21425 fprint_ul (asm_out_file
, line
);
21426 putc (' ', asm_out_file
);
21427 putc ('0', asm_out_file
);
21429 if (is_stmt
!= table
->is_stmt
)
21431 fputs (" is_stmt ", asm_out_file
);
21432 putc (is_stmt
? '1' : '0', asm_out_file
);
21434 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21436 gcc_assert (discriminator
> 0);
21437 fputs (" discriminator ", asm_out_file
);
21438 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21440 putc ('\n', asm_out_file
);
21444 unsigned int label_num
= ++line_info_label_num
;
21446 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21448 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21449 if (file_num
!= table
->file_num
)
21450 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21451 if (discriminator
!= table
->discrim_num
)
21452 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21453 if (is_stmt
!= table
->is_stmt
)
21454 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21455 push_dw_line_info_entry (table
, LI_set_line
, line
);
21458 table
->file_num
= file_num
;
21459 table
->line_num
= line
;
21460 table
->discrim_num
= discriminator
;
21461 table
->is_stmt
= is_stmt
;
21462 table
->in_use
= true;
21465 /* Record the beginning of a new source file. */
21468 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21470 if (flag_eliminate_dwarf2_dups
)
21472 /* Record the beginning of the file for break_out_includes. */
21473 dw_die_ref bincl_die
;
21475 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21476 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21479 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21482 e
.code
= DW_MACINFO_start_file
;
21484 e
.info
= ggc_strdup (filename
);
21485 vec_safe_push (macinfo_table
, e
);
21489 /* Record the end of a source file. */
21492 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21494 if (flag_eliminate_dwarf2_dups
)
21495 /* Record the end of the file for break_out_includes. */
21496 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21498 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21501 e
.code
= DW_MACINFO_end_file
;
21504 vec_safe_push (macinfo_table
, e
);
21508 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21509 the tail part of the directive line, i.e. the part which is past the
21510 initial whitespace, #, whitespace, directive-name, whitespace part. */
21513 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21514 const char *buffer ATTRIBUTE_UNUSED
)
21516 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21519 /* Insert a dummy first entry to be able to optimize the whole
21520 predefined macro block using DW_MACRO_GNU_transparent_include. */
21521 if (macinfo_table
->is_empty () && lineno
<= 1)
21526 vec_safe_push (macinfo_table
, e
);
21528 e
.code
= DW_MACINFO_define
;
21530 e
.info
= ggc_strdup (buffer
);
21531 vec_safe_push (macinfo_table
, e
);
21535 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21536 the tail part of the directive line, i.e. the part which is past the
21537 initial whitespace, #, whitespace, directive-name, whitespace part. */
21540 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21541 const char *buffer ATTRIBUTE_UNUSED
)
21543 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21546 /* Insert a dummy first entry to be able to optimize the whole
21547 predefined macro block using DW_MACRO_GNU_transparent_include. */
21548 if (macinfo_table
->is_empty () && lineno
<= 1)
21553 vec_safe_push (macinfo_table
, e
);
21555 e
.code
= DW_MACINFO_undef
;
21557 e
.info
= ggc_strdup (buffer
);
21558 vec_safe_push (macinfo_table
, e
);
21562 /* Helpers to manipulate hash table of CUs. */
21564 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21566 typedef macinfo_entry value_type
;
21567 typedef macinfo_entry compare_type
;
21568 static inline hashval_t
hash (const value_type
*);
21569 static inline bool equal (const value_type
*, const compare_type
*);
21573 macinfo_entry_hasher::hash (const value_type
*entry
)
21575 return htab_hash_string (entry
->info
);
21579 macinfo_entry_hasher::equal (const value_type
*entry1
,
21580 const compare_type
*entry2
)
21582 return !strcmp (entry1
->info
, entry2
->info
);
21585 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21587 /* Output a single .debug_macinfo entry. */
21590 output_macinfo_op (macinfo_entry
*ref
)
21594 struct indirect_string_node
*node
;
21595 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21596 struct dwarf_file_data
*fd
;
21600 case DW_MACINFO_start_file
:
21601 fd
= lookup_filename (ref
->info
);
21602 file_num
= maybe_emit_file (fd
);
21603 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21604 dw2_asm_output_data_uleb128 (ref
->lineno
,
21605 "Included from line number %lu",
21606 (unsigned long) ref
->lineno
);
21607 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21609 case DW_MACINFO_end_file
:
21610 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21612 case DW_MACINFO_define
:
21613 case DW_MACINFO_undef
:
21614 len
= strlen (ref
->info
) + 1;
21616 && len
> DWARF_OFFSET_SIZE
21617 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21618 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21620 ref
->code
= ref
->code
== DW_MACINFO_define
21621 ? DW_MACRO_GNU_define_indirect
21622 : DW_MACRO_GNU_undef_indirect
;
21623 output_macinfo_op (ref
);
21626 dw2_asm_output_data (1, ref
->code
,
21627 ref
->code
== DW_MACINFO_define
21628 ? "Define macro" : "Undefine macro");
21629 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21630 (unsigned long) ref
->lineno
);
21631 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21633 case DW_MACRO_GNU_define_indirect
:
21634 case DW_MACRO_GNU_undef_indirect
:
21635 node
= find_AT_string (ref
->info
);
21637 && ((node
->form
== DW_FORM_strp
)
21638 || (node
->form
== DW_FORM_GNU_str_index
)));
21639 dw2_asm_output_data (1, ref
->code
,
21640 ref
->code
== DW_MACRO_GNU_define_indirect
21641 ? "Define macro indirect"
21642 : "Undefine macro indirect");
21643 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21644 (unsigned long) ref
->lineno
);
21645 if (node
->form
== DW_FORM_strp
)
21646 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21647 debug_str_section
, "The macro: \"%s\"",
21650 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21653 case DW_MACRO_GNU_transparent_include
:
21654 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21655 ASM_GENERATE_INTERNAL_LABEL (label
,
21656 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21657 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21660 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21661 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21666 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21667 other compilation unit .debug_macinfo sections. IDX is the first
21668 index of a define/undef, return the number of ops that should be
21669 emitted in a comdat .debug_macinfo section and emit
21670 a DW_MACRO_GNU_transparent_include entry referencing it.
21671 If the define/undef entry should be emitted normally, return 0. */
21674 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21675 macinfo_hash_type
*macinfo_htab
)
21677 macinfo_entry
*first
, *second
, *cur
, *inc
;
21678 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21679 unsigned char checksum
[16];
21680 struct md5_ctx ctx
;
21681 char *grp_name
, *tail
;
21683 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21684 macinfo_entry
**slot
;
21686 first
= &(*macinfo_table
)[idx
];
21687 second
= &(*macinfo_table
)[idx
+ 1];
21689 /* Optimize only if there are at least two consecutive define/undef ops,
21690 and either all of them are before first DW_MACINFO_start_file
21691 with lineno {0,1} (i.e. predefined macro block), or all of them are
21692 in some included header file. */
21693 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21695 if (vec_safe_is_empty (files
))
21697 if (first
->lineno
> 1 || second
->lineno
> 1)
21700 else if (first
->lineno
== 0)
21703 /* Find the last define/undef entry that can be grouped together
21704 with first and at the same time compute md5 checksum of their
21705 codes, linenumbers and strings. */
21706 md5_init_ctx (&ctx
);
21707 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21708 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21710 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21714 unsigned char code
= cur
->code
;
21715 md5_process_bytes (&code
, 1, &ctx
);
21716 checksum_uleb128 (cur
->lineno
, &ctx
);
21717 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21719 md5_finish_ctx (&ctx
, checksum
);
21722 /* From the containing include filename (if any) pick up just
21723 usable characters from its basename. */
21724 if (vec_safe_is_empty (files
))
21727 base
= lbasename (files
->last ().info
);
21728 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21729 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21730 encoded_filename_len
++;
21731 /* Count . at the end. */
21732 if (encoded_filename_len
)
21733 encoded_filename_len
++;
21735 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21736 linebuf_len
= strlen (linebuf
);
21738 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21739 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21741 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21742 tail
= grp_name
+ 4;
21743 if (encoded_filename_len
)
21745 for (i
= 0; base
[i
]; i
++)
21746 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21750 memcpy (tail
, linebuf
, linebuf_len
);
21751 tail
+= linebuf_len
;
21753 for (i
= 0; i
< 16; i
++)
21754 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21756 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21757 in the empty vector entry before the first define/undef. */
21758 inc
= &(*macinfo_table
)[idx
- 1];
21759 inc
->code
= DW_MACRO_GNU_transparent_include
;
21761 inc
->info
= ggc_strdup (grp_name
);
21762 if (!macinfo_htab
->is_created ())
21763 macinfo_htab
->create (10);
21764 /* Avoid emitting duplicates. */
21765 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21770 /* If such an entry has been used before, just emit
21771 a DW_MACRO_GNU_transparent_include op. */
21773 output_macinfo_op (inc
);
21774 /* And clear all macinfo_entry in the range to avoid emitting them
21775 in the second pass. */
21776 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21785 inc
->lineno
= macinfo_htab
->elements ();
21786 output_macinfo_op (inc
);
21791 /* Save any strings needed by the macinfo table in the debug str
21792 table. All strings must be collected into the table by the time
21793 index_string is called. */
21796 save_macinfo_strings (void)
21800 macinfo_entry
*ref
;
21802 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21806 /* Match the logic in output_macinfo_op to decide on
21807 indirect strings. */
21808 case DW_MACINFO_define
:
21809 case DW_MACINFO_undef
:
21810 len
= strlen (ref
->info
) + 1;
21812 && len
> DWARF_OFFSET_SIZE
21813 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21814 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21815 set_indirect_string (find_AT_string (ref
->info
));
21817 case DW_MACRO_GNU_define_indirect
:
21818 case DW_MACRO_GNU_undef_indirect
:
21819 set_indirect_string (find_AT_string (ref
->info
));
21827 /* Output macinfo section(s). */
21830 output_macinfo (void)
21833 unsigned long length
= vec_safe_length (macinfo_table
);
21834 macinfo_entry
*ref
;
21835 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21836 macinfo_hash_type macinfo_htab
;
21841 /* output_macinfo* uses these interchangeably. */
21842 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21843 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21844 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21845 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21847 /* For .debug_macro emit the section header. */
21850 dw2_asm_output_data (2, 4, "DWARF macro version number");
21851 if (DWARF_OFFSET_SIZE
== 8)
21852 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21854 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21855 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21856 (!dwarf_split_debug_info
? debug_line_section_label
21857 : debug_skeleton_line_section_label
),
21858 debug_line_section
, NULL
);
21861 /* In the first loop, it emits the primary .debug_macinfo section
21862 and after each emitted op the macinfo_entry is cleared.
21863 If a longer range of define/undef ops can be optimized using
21864 DW_MACRO_GNU_transparent_include, the
21865 DW_MACRO_GNU_transparent_include op is emitted and kept in
21866 the vector before the first define/undef in the range and the
21867 whole range of define/undef ops is not emitted and kept. */
21868 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21872 case DW_MACINFO_start_file
:
21873 vec_safe_push (files
, *ref
);
21875 case DW_MACINFO_end_file
:
21876 if (!vec_safe_is_empty (files
))
21879 case DW_MACINFO_define
:
21880 case DW_MACINFO_undef
:
21882 && HAVE_COMDAT_GROUP
21883 && vec_safe_length (files
) != 1
21886 && (*macinfo_table
)[i
- 1].code
== 0)
21888 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21897 /* A dummy entry may be inserted at the beginning to be able
21898 to optimize the whole block of predefined macros. */
21904 output_macinfo_op (ref
);
21909 if (!macinfo_htab
.is_created ())
21912 macinfo_htab
.dispose ();
21914 /* If any DW_MACRO_GNU_transparent_include were used, on those
21915 DW_MACRO_GNU_transparent_include entries terminate the
21916 current chain and switch to a new comdat .debug_macinfo
21917 section and emit the define/undef entries within it. */
21918 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21923 case DW_MACRO_GNU_transparent_include
:
21925 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21926 tree comdat_key
= get_identifier (ref
->info
);
21927 /* Terminate the previous .debug_macinfo section. */
21928 dw2_asm_output_data (1, 0, "End compilation unit");
21929 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21931 | SECTION_LINKONCE
,
21933 ASM_GENERATE_INTERNAL_LABEL (label
,
21934 DEBUG_MACRO_SECTION_LABEL
,
21936 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21939 dw2_asm_output_data (2, 4, "DWARF macro version number");
21940 if (DWARF_OFFSET_SIZE
== 8)
21941 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21943 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21946 case DW_MACINFO_define
:
21947 case DW_MACINFO_undef
:
21948 output_macinfo_op (ref
);
21953 gcc_unreachable ();
21957 /* Set up for Dwarf output at the start of compilation. */
21960 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21962 /* Allocate the file_table. */
21963 file_table
= htab_create_ggc (50, file_table_hash
,
21964 file_table_eq
, NULL
);
21966 /* Allocate the decl_die_table. */
21967 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21968 decl_die_table_eq
, NULL
);
21970 /* Allocate the decl_loc_table. */
21971 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21972 decl_loc_table_eq
, NULL
);
21974 /* Allocate the cached_dw_loc_list_table. */
21975 cached_dw_loc_list_table
21976 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21977 cached_dw_loc_list_table_eq
, NULL
);
21979 /* Allocate the initial hunk of the decl_scope_table. */
21980 vec_alloc (decl_scope_table
, 256);
21982 /* Allocate the initial hunk of the abbrev_die_table. */
21983 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21984 (ABBREV_DIE_TABLE_INCREMENT
);
21985 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21986 /* Zero-th entry is allocated, but unused. */
21987 abbrev_die_table_in_use
= 1;
21989 /* Allocate the pubtypes and pubnames vectors. */
21990 vec_alloc (pubname_table
, 32);
21991 vec_alloc (pubtype_table
, 32);
21993 vec_alloc (incomplete_types
, 64);
21995 vec_alloc (used_rtx_array
, 32);
21997 if (!dwarf_split_debug_info
)
21999 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22000 SECTION_DEBUG
, NULL
);
22001 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22002 SECTION_DEBUG
, NULL
);
22003 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22004 SECTION_DEBUG
, NULL
);
22008 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22009 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22010 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22011 SECTION_DEBUG
| SECTION_EXCLUDE
,
22013 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22014 SECTION_DEBUG
, NULL
);
22015 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22016 SECTION_DEBUG
, NULL
);
22017 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22018 SECTION_DEBUG
, NULL
);
22019 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22020 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22022 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22023 the main .o, but the skeleton_line goes into the split off dwo. */
22024 debug_skeleton_line_section
22025 = get_section (DEBUG_DWO_LINE_SECTION
,
22026 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22027 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22028 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22029 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22030 SECTION_DEBUG
| SECTION_EXCLUDE
,
22032 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22033 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22034 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22035 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22036 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22037 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22039 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22040 SECTION_DEBUG
, NULL
);
22041 debug_macinfo_section
= get_section (dwarf_strict
22042 ? DEBUG_MACINFO_SECTION
22043 : DEBUG_MACRO_SECTION
,
22044 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22045 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22046 SECTION_DEBUG
, NULL
);
22047 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22048 SECTION_DEBUG
, NULL
);
22049 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22050 SECTION_DEBUG
, NULL
);
22051 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22052 DEBUG_STR_SECTION_FLAGS
, NULL
);
22053 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22054 SECTION_DEBUG
, NULL
);
22055 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22056 SECTION_DEBUG
, NULL
);
22058 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22059 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22060 DEBUG_ABBREV_SECTION_LABEL
, 0);
22061 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22062 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22063 COLD_TEXT_SECTION_LABEL
, 0);
22064 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22066 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22067 DEBUG_INFO_SECTION_LABEL
, 0);
22068 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22069 DEBUG_LINE_SECTION_LABEL
, 0);
22070 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22071 DEBUG_RANGES_SECTION_LABEL
, 0);
22072 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22073 DEBUG_ADDR_SECTION_LABEL
, 0);
22074 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22076 ? DEBUG_MACINFO_SECTION_LABEL
22077 : DEBUG_MACRO_SECTION_LABEL
, 0);
22078 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22080 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22081 vec_alloc (macinfo_table
, 64);
22083 switch_to_section (text_section
);
22084 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22086 /* Make sure the line number table for .text always exists. */
22087 text_section_line_info
= new_line_info_table ();
22088 text_section_line_info
->end_label
= text_end_label
;
22091 /* Called before compile () starts outputtting functions, variables
22092 and toplevel asms into assembly. */
22095 dwarf2out_assembly_start (void)
22097 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22098 && dwarf2out_do_cfi_asm ()
22099 && (!(flag_unwind_tables
|| flag_exceptions
)
22100 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22101 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22104 /* A helper function for dwarf2out_finish called through
22105 htab_traverse. Assign a string its index. All strings must be
22106 collected into the table by the time index_string is called,
22107 because the indexing code relies on htab_traverse to traverse nodes
22108 in the same order for each run. */
22111 index_string (void **h
, void *v
)
22113 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22114 unsigned int *index
= (unsigned int *) v
;
22116 find_string_form (node
);
22117 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22119 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22120 node
->index
= *index
;
22126 /* A helper function for output_indirect_strings called through
22127 htab_traverse. Output the offset to a string and update the
22131 output_index_string_offset (void **h
, void *v
)
22133 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22134 unsigned int *offset
= (unsigned int *) v
;
22136 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22138 /* Assert that this node has been assigned an index. */
22139 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22140 && node
->index
!= NOT_INDEXED
);
22141 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22142 "indexed string 0x%x: %s", node
->index
, node
->str
);
22143 *offset
+= strlen (node
->str
) + 1;
22148 /* A helper function for dwarf2out_finish called through
22149 htab_traverse. Output the indexed string. */
22152 output_index_string (void **h
, void *v
)
22154 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22155 unsigned int *cur_idx
= (unsigned int *) v
;
22157 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22159 /* Assert that the strings are output in the same order as their
22160 indexes were assigned. */
22161 gcc_assert (*cur_idx
== node
->index
);
22162 assemble_string (node
->str
, strlen (node
->str
) + 1);
22168 /* A helper function for dwarf2out_finish called through
22169 htab_traverse. Emit one queued .debug_str string. */
22172 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22174 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22176 node
->form
= find_string_form (node
);
22177 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22179 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22180 assemble_string (node
->str
, strlen (node
->str
) + 1);
22186 /* Output the indexed string table. */
22189 output_indirect_strings (void)
22191 switch_to_section (debug_str_section
);
22192 if (!dwarf_split_debug_info
)
22193 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22196 unsigned int offset
= 0;
22197 unsigned int cur_idx
= 0;
22199 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22201 switch_to_section (debug_str_offsets_section
);
22202 htab_traverse_noresize (debug_str_hash
,
22203 output_index_string_offset
,
22205 switch_to_section (debug_str_dwo_section
);
22206 htab_traverse_noresize (debug_str_hash
,
22207 output_index_string
,
22212 /* Callback for htab_traverse to assign an index to an entry in the
22213 table, and to write that entry to the .debug_addr section. */
22216 output_addr_table_entry (void **slot
, void *data
)
22218 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22219 unsigned int *cur_index
= (unsigned int *)data
;
22221 if (entry
->refcount
== 0)
22223 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22224 || entry
->index
== NOT_INDEXED
);
22228 gcc_assert (entry
->index
== *cur_index
);
22231 switch (entry
->kind
)
22234 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22235 "0x%x", entry
->index
);
22237 case ate_kind_rtx_dtprel
:
22238 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22239 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22242 fputc ('\n', asm_out_file
);
22244 case ate_kind_label
:
22245 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22246 "0x%x", entry
->index
);
22249 gcc_unreachable ();
22254 /* Produce the .debug_addr section. */
22257 output_addr_table (void)
22259 unsigned int index
= 0;
22260 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22263 switch_to_section (debug_addr_section
);
22264 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22267 #if ENABLE_ASSERT_CHECKING
22268 /* Verify that all marks are clear. */
22271 verify_marks_clear (dw_die_ref die
)
22275 gcc_assert (! die
->die_mark
);
22276 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22278 #endif /* ENABLE_ASSERT_CHECKING */
22280 /* Clear the marks for a die and its children.
22281 Be cool if the mark isn't set. */
22284 prune_unmark_dies (dw_die_ref die
)
22290 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22293 /* Given DIE that we're marking as used, find any other dies
22294 it references as attributes and mark them as used. */
22297 prune_unused_types_walk_attribs (dw_die_ref die
)
22302 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22304 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22306 /* A reference to another DIE.
22307 Make sure that it will get emitted.
22308 If it was broken out into a comdat group, don't follow it. */
22309 if (! AT_ref (a
)->comdat_type_p
22310 || a
->dw_attr
== DW_AT_specification
)
22311 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22313 /* Set the string's refcount to 0 so that prune_unused_types_mark
22314 accounts properly for it. */
22315 if (AT_class (a
) == dw_val_class_str
)
22316 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22320 /* Mark the generic parameters and arguments children DIEs of DIE. */
22323 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22327 if (die
== NULL
|| die
->die_child
== NULL
)
22329 c
= die
->die_child
;
22332 if (is_template_parameter (c
))
22333 prune_unused_types_mark (c
, 1);
22335 } while (c
&& c
!= die
->die_child
);
22338 /* Mark DIE as being used. If DOKIDS is true, then walk down
22339 to DIE's children. */
22342 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22346 if (die
->die_mark
== 0)
22348 /* We haven't done this node yet. Mark it as used. */
22350 /* If this is the DIE of a generic type instantiation,
22351 mark the children DIEs that describe its generic parms and
22353 prune_unused_types_mark_generic_parms_dies (die
);
22355 /* We also have to mark its parents as used.
22356 (But we don't want to mark our parent's kids due to this,
22357 unless it is a class.) */
22358 if (die
->die_parent
)
22359 prune_unused_types_mark (die
->die_parent
,
22360 class_scope_p (die
->die_parent
));
22362 /* Mark any referenced nodes. */
22363 prune_unused_types_walk_attribs (die
);
22365 /* If this node is a specification,
22366 also mark the definition, if it exists. */
22367 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22368 prune_unused_types_mark (die
->die_definition
, 1);
22371 if (dokids
&& die
->die_mark
!= 2)
22373 /* We need to walk the children, but haven't done so yet.
22374 Remember that we've walked the kids. */
22377 /* If this is an array type, we need to make sure our
22378 kids get marked, even if they're types. If we're
22379 breaking out types into comdat sections, do this
22380 for all type definitions. */
22381 if (die
->die_tag
== DW_TAG_array_type
22382 || (use_debug_types
22383 && is_type_die (die
) && ! is_declaration_die (die
)))
22384 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22386 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22390 /* For local classes, look if any static member functions were emitted
22391 and if so, mark them. */
22394 prune_unused_types_walk_local_classes (dw_die_ref die
)
22398 if (die
->die_mark
== 2)
22401 switch (die
->die_tag
)
22403 case DW_TAG_structure_type
:
22404 case DW_TAG_union_type
:
22405 case DW_TAG_class_type
:
22408 case DW_TAG_subprogram
:
22409 if (!get_AT_flag (die
, DW_AT_declaration
)
22410 || die
->die_definition
!= NULL
)
22411 prune_unused_types_mark (die
, 1);
22418 /* Mark children. */
22419 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22422 /* Walk the tree DIE and mark types that we actually use. */
22425 prune_unused_types_walk (dw_die_ref die
)
22429 /* Don't do anything if this node is already marked and
22430 children have been marked as well. */
22431 if (die
->die_mark
== 2)
22434 switch (die
->die_tag
)
22436 case DW_TAG_structure_type
:
22437 case DW_TAG_union_type
:
22438 case DW_TAG_class_type
:
22439 if (die
->die_perennial_p
)
22442 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22443 if (c
->die_tag
== DW_TAG_subprogram
)
22446 /* Finding used static member functions inside of classes
22447 is needed just for local classes, because for other classes
22448 static member function DIEs with DW_AT_specification
22449 are emitted outside of the DW_TAG_*_type. If we ever change
22450 it, we'd need to call this even for non-local classes. */
22452 prune_unused_types_walk_local_classes (die
);
22454 /* It's a type node --- don't mark it. */
22457 case DW_TAG_const_type
:
22458 case DW_TAG_packed_type
:
22459 case DW_TAG_pointer_type
:
22460 case DW_TAG_reference_type
:
22461 case DW_TAG_rvalue_reference_type
:
22462 case DW_TAG_volatile_type
:
22463 case DW_TAG_typedef
:
22464 case DW_TAG_array_type
:
22465 case DW_TAG_interface_type
:
22466 case DW_TAG_friend
:
22467 case DW_TAG_variant_part
:
22468 case DW_TAG_enumeration_type
:
22469 case DW_TAG_subroutine_type
:
22470 case DW_TAG_string_type
:
22471 case DW_TAG_set_type
:
22472 case DW_TAG_subrange_type
:
22473 case DW_TAG_ptr_to_member_type
:
22474 case DW_TAG_file_type
:
22475 if (die
->die_perennial_p
)
22478 /* It's a type node --- don't mark it. */
22482 /* Mark everything else. */
22486 if (die
->die_mark
== 0)
22490 /* Now, mark any dies referenced from here. */
22491 prune_unused_types_walk_attribs (die
);
22496 /* Mark children. */
22497 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22500 /* Increment the string counts on strings referred to from DIE's
22504 prune_unused_types_update_strings (dw_die_ref die
)
22509 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22510 if (AT_class (a
) == dw_val_class_str
)
22512 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22514 /* Avoid unnecessarily putting strings that are used less than
22515 twice in the hash table. */
22517 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22520 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22521 htab_hash_string (s
->str
),
22523 gcc_assert (*slot
== NULL
);
22529 /* Remove from the tree DIE any dies that aren't marked. */
22532 prune_unused_types_prune (dw_die_ref die
)
22536 gcc_assert (die
->die_mark
);
22537 prune_unused_types_update_strings (die
);
22539 if (! die
->die_child
)
22542 c
= die
->die_child
;
22544 dw_die_ref prev
= c
;
22545 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22546 if (c
== die
->die_child
)
22548 /* No marked children between 'prev' and the end of the list. */
22550 /* No marked children at all. */
22551 die
->die_child
= NULL
;
22554 prev
->die_sib
= c
->die_sib
;
22555 die
->die_child
= prev
;
22560 if (c
!= prev
->die_sib
)
22562 prune_unused_types_prune (c
);
22563 } while (c
!= die
->die_child
);
22566 /* Remove dies representing declarations that we never use. */
22569 prune_unused_types (void)
22572 limbo_die_node
*node
;
22573 comdat_type_node
*ctnode
;
22575 dw_die_ref base_type
;
22577 #if ENABLE_ASSERT_CHECKING
22578 /* All the marks should already be clear. */
22579 verify_marks_clear (comp_unit_die ());
22580 for (node
= limbo_die_list
; node
; node
= node
->next
)
22581 verify_marks_clear (node
->die
);
22582 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22583 verify_marks_clear (ctnode
->root_die
);
22584 #endif /* ENABLE_ASSERT_CHECKING */
22586 /* Mark types that are used in global variables. */
22587 premark_types_used_by_global_vars ();
22589 /* Set the mark on nodes that are actually used. */
22590 prune_unused_types_walk (comp_unit_die ());
22591 for (node
= limbo_die_list
; node
; node
= node
->next
)
22592 prune_unused_types_walk (node
->die
);
22593 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22595 prune_unused_types_walk (ctnode
->root_die
);
22596 prune_unused_types_mark (ctnode
->type_die
, 1);
22599 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22600 are unusual in that they are pubnames that are the children of pubtypes.
22601 They should only be marked via their parent DW_TAG_enumeration_type die,
22602 not as roots in themselves. */
22603 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22604 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22605 prune_unused_types_mark (pub
->die
, 1);
22606 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22607 prune_unused_types_mark (base_type
, 1);
22609 if (debug_str_hash
)
22610 htab_empty (debug_str_hash
);
22611 if (skeleton_debug_str_hash
)
22612 htab_empty (skeleton_debug_str_hash
);
22613 prune_unused_types_prune (comp_unit_die ());
22614 for (node
= limbo_die_list
; node
; node
= node
->next
)
22615 prune_unused_types_prune (node
->die
);
22616 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22617 prune_unused_types_prune (ctnode
->root_die
);
22619 /* Leave the marks clear. */
22620 prune_unmark_dies (comp_unit_die ());
22621 for (node
= limbo_die_list
; node
; node
= node
->next
)
22622 prune_unmark_dies (node
->die
);
22623 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22624 prune_unmark_dies (ctnode
->root_die
);
22627 /* Set the parameter to true if there are any relative pathnames in
22630 file_table_relative_p (void ** slot
, void *param
)
22632 bool *p
= (bool *) param
;
22633 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22634 if (!IS_ABSOLUTE_PATH (d
->filename
))
22642 /* Helpers to manipulate hash table of comdat type units. */
22644 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22646 typedef comdat_type_node value_type
;
22647 typedef comdat_type_node compare_type
;
22648 static inline hashval_t
hash (const value_type
*);
22649 static inline bool equal (const value_type
*, const compare_type
*);
22653 comdat_type_hasher::hash (const value_type
*type_node
)
22656 memcpy (&h
, type_node
->signature
, sizeof (h
));
22661 comdat_type_hasher::equal (const value_type
*type_node_1
,
22662 const compare_type
*type_node_2
)
22664 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22665 DWARF_TYPE_SIGNATURE_SIZE
));
22668 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22669 to the location it would have been added, should we know its
22670 DECL_ASSEMBLER_NAME when we added other attributes. This will
22671 probably improve compactness of debug info, removing equivalent
22672 abbrevs, and hide any differences caused by deferring the
22673 computation of the assembler name, triggered by e.g. PCH. */
22676 move_linkage_attr (dw_die_ref die
)
22678 unsigned ix
= vec_safe_length (die
->die_attr
);
22679 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22681 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22682 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22686 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22688 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22692 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22694 die
->die_attr
->pop ();
22695 die
->die_attr
->quick_insert (ix
, linkage
);
22699 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22700 referenced from typed stack ops and count how often they are used. */
22703 mark_base_types (dw_loc_descr_ref loc
)
22705 dw_die_ref base_type
= NULL
;
22707 for (; loc
; loc
= loc
->dw_loc_next
)
22709 switch (loc
->dw_loc_opc
)
22711 case DW_OP_GNU_regval_type
:
22712 case DW_OP_GNU_deref_type
:
22713 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22715 case DW_OP_GNU_convert
:
22716 case DW_OP_GNU_reinterpret
:
22717 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22720 case DW_OP_GNU_const_type
:
22721 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22723 case DW_OP_GNU_entry_value
:
22724 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22729 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22730 if (base_type
->die_mark
)
22731 base_type
->die_mark
++;
22734 base_types
.safe_push (base_type
);
22735 base_type
->die_mark
= 1;
22740 /* Comparison function for sorting marked base types. */
22743 base_type_cmp (const void *x
, const void *y
)
22745 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22746 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22747 unsigned int byte_size1
, byte_size2
;
22748 unsigned int encoding1
, encoding2
;
22749 if (dx
->die_mark
> dy
->die_mark
)
22751 if (dx
->die_mark
< dy
->die_mark
)
22753 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22754 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22755 if (byte_size1
< byte_size2
)
22757 if (byte_size1
> byte_size2
)
22759 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22760 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22761 if (encoding1
< encoding2
)
22763 if (encoding1
> encoding2
)
22768 /* Move base types marked by mark_base_types as early as possible
22769 in the CU, sorted by decreasing usage count both to make the
22770 uleb128 references as small as possible and to make sure they
22771 will have die_offset already computed by calc_die_sizes when
22772 sizes of typed stack loc ops is computed. */
22775 move_marked_base_types (void)
22778 dw_die_ref base_type
, die
, c
;
22780 if (base_types
.is_empty ())
22783 /* Sort by decreasing usage count, they will be added again in that
22785 base_types
.qsort (base_type_cmp
);
22786 die
= comp_unit_die ();
22787 c
= die
->die_child
;
22790 dw_die_ref prev
= c
;
22792 while (c
->die_mark
)
22794 remove_child_with_prev (c
, prev
);
22795 /* As base types got marked, there must be at least
22796 one node other than DW_TAG_base_type. */
22797 gcc_assert (c
!= c
->die_sib
);
22801 while (c
!= die
->die_child
);
22802 gcc_assert (die
->die_child
);
22803 c
= die
->die_child
;
22804 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22806 base_type
->die_mark
= 0;
22807 base_type
->die_sib
= c
->die_sib
;
22808 c
->die_sib
= base_type
;
22813 /* Helper function for resolve_addr, attempt to resolve
22814 one CONST_STRING, return non-zero if not successful. Similarly verify that
22815 SYMBOL_REFs refer to variables emitted in the current CU. */
22818 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22822 if (GET_CODE (rtl
) == CONST_STRING
)
22824 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22825 tree t
= build_string (len
, XSTR (rtl
, 0));
22826 tree tlen
= size_int (len
- 1);
22828 = build_array_type (char_type_node
, build_index_type (tlen
));
22829 rtl
= lookup_constant_def (t
);
22830 if (!rtl
|| !MEM_P (rtl
))
22832 rtl
= XEXP (rtl
, 0);
22833 if (GET_CODE (rtl
) == SYMBOL_REF
22834 && SYMBOL_REF_DECL (rtl
)
22835 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22837 vec_safe_push (used_rtx_array
, rtl
);
22842 if (GET_CODE (rtl
) == SYMBOL_REF
22843 && SYMBOL_REF_DECL (rtl
))
22845 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22847 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22850 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22854 if (GET_CODE (rtl
) == CONST
22855 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22861 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22862 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22863 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22866 string_cst_pool_decl (tree t
)
22868 rtx rtl
= output_constant_def (t
, 1);
22869 unsigned char *array
;
22870 dw_loc_descr_ref l
;
22875 if (!rtl
|| !MEM_P (rtl
))
22877 rtl
= XEXP (rtl
, 0);
22878 if (GET_CODE (rtl
) != SYMBOL_REF
22879 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22882 decl
= SYMBOL_REF_DECL (rtl
);
22883 if (!lookup_decl_die (decl
))
22885 len
= TREE_STRING_LENGTH (t
);
22886 vec_safe_push (used_rtx_array
, rtl
);
22887 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22888 array
= (unsigned char *) ggc_alloc_atomic (len
);
22889 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22890 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22891 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22892 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22893 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22894 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22895 add_AT_loc (ref
, DW_AT_location
, l
);
22896 equate_decl_number_to_die (decl
, ref
);
22901 /* Helper function of resolve_addr_in_expr. LOC is
22902 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22903 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22904 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22905 with DW_OP_GNU_implicit_pointer if possible
22906 and return true, if unsuccessful, return false. */
22909 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22911 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22912 HOST_WIDE_INT offset
= 0;
22913 dw_die_ref ref
= NULL
;
22916 if (GET_CODE (rtl
) == CONST
22917 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22918 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22920 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22921 rtl
= XEXP (XEXP (rtl
, 0), 0);
22923 if (GET_CODE (rtl
) == CONST_STRING
)
22925 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22926 tree t
= build_string (len
, XSTR (rtl
, 0));
22927 tree tlen
= size_int (len
- 1);
22930 = build_array_type (char_type_node
, build_index_type (tlen
));
22931 rtl
= string_cst_pool_decl (t
);
22935 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22937 decl
= SYMBOL_REF_DECL (rtl
);
22938 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22940 ref
= lookup_decl_die (decl
);
22941 if (ref
&& (get_AT (ref
, DW_AT_location
)
22942 || get_AT (ref
, DW_AT_const_value
)))
22944 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22945 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22946 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22947 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22948 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22949 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22950 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22958 /* Helper function for resolve_addr, handle one location
22959 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22960 the location list couldn't be resolved. */
22963 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22965 dw_loc_descr_ref keep
= NULL
;
22966 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22967 switch (loc
->dw_loc_opc
)
22970 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22973 || prev
->dw_loc_opc
== DW_OP_piece
22974 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22975 && loc
->dw_loc_next
22976 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22978 && optimize_one_addr_into_implicit_ptr (loc
))
22983 case DW_OP_GNU_addr_index
:
22984 case DW_OP_GNU_const_index
:
22985 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22986 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22987 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22991 case DW_OP_const4u
:
22992 case DW_OP_const8u
:
22994 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22997 case DW_OP_plus_uconst
:
22998 if (size_of_loc_descr (loc
)
22999 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
23001 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
23003 dw_loc_descr_ref repl
23004 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
23005 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23006 add_loc_descr (&repl
, loc
->dw_loc_next
);
23010 case DW_OP_implicit_value
:
23011 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23012 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
23015 case DW_OP_GNU_implicit_pointer
:
23016 case DW_OP_GNU_parameter_ref
:
23017 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23020 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23023 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23024 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23025 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23028 case DW_OP_GNU_const_type
:
23029 case DW_OP_GNU_regval_type
:
23030 case DW_OP_GNU_deref_type
:
23031 case DW_OP_GNU_convert
:
23032 case DW_OP_GNU_reinterpret
:
23033 while (loc
->dw_loc_next
23034 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23036 dw_die_ref base1
, base2
;
23037 unsigned enc1
, enc2
, size1
, size2
;
23038 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23039 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23040 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23041 else if (loc
->dw_loc_oprnd1
.val_class
23042 == dw_val_class_unsigned_const
)
23045 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23046 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23047 == dw_val_class_unsigned_const
)
23049 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23050 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23051 && base2
->die_tag
== DW_TAG_base_type
);
23052 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23053 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23054 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23055 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23057 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23058 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23062 /* Optimize away next DW_OP_GNU_convert after
23063 adjusting LOC's base type die reference. */
23064 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23065 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23066 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23068 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23069 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23072 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23073 point typed stack entry. */
23074 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23075 keep
= loc
->dw_loc_next
;
23085 /* Helper function of resolve_addr. DIE had DW_AT_location of
23086 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23087 and DW_OP_addr couldn't be resolved. resolve_addr has already
23088 removed the DW_AT_location attribute. This function attempts to
23089 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23090 to it or DW_AT_const_value attribute, if possible. */
23093 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23095 if (TREE_CODE (decl
) != VAR_DECL
23096 || lookup_decl_die (decl
) != die
23097 || DECL_EXTERNAL (decl
)
23098 || !TREE_STATIC (decl
)
23099 || DECL_INITIAL (decl
) == NULL_TREE
23100 || DECL_P (DECL_INITIAL (decl
))
23101 || get_AT (die
, DW_AT_const_value
))
23104 tree init
= DECL_INITIAL (decl
);
23105 HOST_WIDE_INT offset
= 0;
23106 /* For variables that have been optimized away and thus
23107 don't have a memory location, see if we can emit
23108 DW_AT_const_value instead. */
23109 if (tree_add_const_value_attribute (die
, init
))
23113 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23114 and ADDR_EXPR refers to a decl that has DW_AT_location or
23115 DW_AT_const_value (but isn't addressable, otherwise
23116 resolving the original DW_OP_addr wouldn't fail), see if
23117 we can add DW_OP_GNU_implicit_pointer. */
23119 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23120 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
23122 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
23123 init
= TREE_OPERAND (init
, 0);
23126 if (TREE_CODE (init
) != ADDR_EXPR
)
23128 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23129 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23130 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23131 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23132 && TREE_OPERAND (init
, 0) != decl
))
23135 dw_loc_descr_ref l
;
23137 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23139 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23142 decl
= SYMBOL_REF_DECL (rtl
);
23145 decl
= TREE_OPERAND (init
, 0);
23146 ref
= lookup_decl_die (decl
);
23148 || (!get_AT (ref
, DW_AT_location
)
23149 && !get_AT (ref
, DW_AT_const_value
)))
23151 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23152 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23153 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23154 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23155 add_AT_loc (die
, DW_AT_location
, l
);
23159 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23160 an address in .rodata section if the string literal is emitted there,
23161 or remove the containing location list or replace DW_AT_const_value
23162 with DW_AT_location and empty location expression, if it isn't found
23163 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23164 to something that has been emitted in the current CU. */
23167 resolve_addr (dw_die_ref die
)
23171 dw_loc_list_ref
*curr
, *start
, loc
;
23174 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23175 switch (AT_class (a
))
23177 case dw_val_class_loc_list
:
23178 start
= curr
= AT_loc_list_ptr (a
);
23181 /* The same list can be referenced more than once. See if we have
23182 already recorded the result from a previous pass. */
23184 *curr
= loc
->dw_loc_next
;
23185 else if (!loc
->resolved_addr
)
23187 /* As things stand, we do not expect or allow one die to
23188 reference a suffix of another die's location list chain.
23189 References must be identical or completely separate.
23190 There is therefore no need to cache the result of this
23191 pass on any list other than the first; doing so
23192 would lead to unnecessary writes. */
23195 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23196 if (!resolve_addr_in_expr ((*curr
)->expr
))
23198 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23199 dw_loc_descr_ref l
= (*curr
)->expr
;
23201 if (next
&& (*curr
)->ll_symbol
)
23203 gcc_assert (!next
->ll_symbol
);
23204 next
->ll_symbol
= (*curr
)->ll_symbol
;
23206 if (dwarf_split_debug_info
)
23207 remove_loc_list_addr_table_entries (l
);
23212 mark_base_types ((*curr
)->expr
);
23213 curr
= &(*curr
)->dw_loc_next
;
23217 loc
->resolved_addr
= 1;
23221 loc
->dw_loc_next
= *start
;
23226 remove_AT (die
, a
->dw_attr
);
23230 case dw_val_class_loc
:
23232 dw_loc_descr_ref l
= AT_loc (a
);
23233 /* For -gdwarf-2 don't attempt to optimize
23234 DW_AT_data_member_location containing
23235 DW_OP_plus_uconst - older consumers might
23236 rely on it being that op instead of a more complex,
23237 but shorter, location description. */
23238 if ((dwarf_version
> 2
23239 || a
->dw_attr
!= DW_AT_data_member_location
23241 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23242 || l
->dw_loc_next
!= NULL
)
23243 && !resolve_addr_in_expr (l
))
23245 if (dwarf_split_debug_info
)
23246 remove_loc_list_addr_table_entries (l
);
23248 && l
->dw_loc_next
== NULL
23249 && l
->dw_loc_opc
== DW_OP_addr
23250 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23251 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23252 && a
->dw_attr
== DW_AT_location
)
23254 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23255 remove_AT (die
, a
->dw_attr
);
23257 optimize_location_into_implicit_ptr (die
, decl
);
23260 remove_AT (die
, a
->dw_attr
);
23264 mark_base_types (l
);
23267 case dw_val_class_addr
:
23268 if (a
->dw_attr
== DW_AT_const_value
23269 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23271 if (AT_index (a
) != NOT_INDEXED
)
23272 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23273 remove_AT (die
, a
->dw_attr
);
23276 if (die
->die_tag
== DW_TAG_GNU_call_site
23277 && a
->dw_attr
== DW_AT_abstract_origin
)
23279 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23280 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23282 && DECL_EXTERNAL (tdecl
)
23283 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23285 force_decl_die (tdecl
);
23286 tdie
= lookup_decl_die (tdecl
);
23290 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23291 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23292 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23296 if (AT_index (a
) != NOT_INDEXED
)
23297 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23298 remove_AT (die
, a
->dw_attr
);
23307 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23310 /* Helper routines for optimize_location_lists.
23311 This pass tries to share identical local lists in .debug_loc
23314 /* Iteratively hash operands of LOC opcode. */
23317 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23319 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23320 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23322 switch (loc
->dw_loc_opc
)
23324 case DW_OP_const4u
:
23325 case DW_OP_const8u
:
23329 case DW_OP_const1u
:
23330 case DW_OP_const1s
:
23331 case DW_OP_const2u
:
23332 case DW_OP_const2s
:
23333 case DW_OP_const4s
:
23334 case DW_OP_const8s
:
23338 case DW_OP_plus_uconst
:
23374 case DW_OP_deref_size
:
23375 case DW_OP_xderef_size
:
23376 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23383 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23384 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23385 hash
= iterative_hash_object (offset
, hash
);
23388 case DW_OP_implicit_value
:
23389 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23390 switch (val2
->val_class
)
23392 case dw_val_class_const
:
23393 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23395 case dw_val_class_vec
:
23397 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23398 unsigned int len
= val2
->v
.val_vec
.length
;
23400 hash
= iterative_hash_object (elt_size
, hash
);
23401 hash
= iterative_hash_object (len
, hash
);
23402 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23403 len
* elt_size
, hash
);
23406 case dw_val_class_const_double
:
23407 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23408 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23410 case dw_val_class_addr
:
23411 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23414 gcc_unreachable ();
23418 case DW_OP_bit_piece
:
23419 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23420 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23426 unsigned char dtprel
= 0xd1;
23427 hash
= iterative_hash_object (dtprel
, hash
);
23429 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23431 case DW_OP_GNU_addr_index
:
23432 case DW_OP_GNU_const_index
:
23436 unsigned char dtprel
= 0xd1;
23437 hash
= iterative_hash_object (dtprel
, hash
);
23439 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23442 case DW_OP_GNU_implicit_pointer
:
23443 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23445 case DW_OP_GNU_entry_value
:
23446 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23448 case DW_OP_GNU_regval_type
:
23449 case DW_OP_GNU_deref_type
:
23451 unsigned int byte_size
23452 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23453 unsigned int encoding
23454 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23455 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23456 hash
= iterative_hash_object (byte_size
, hash
);
23457 hash
= iterative_hash_object (encoding
, hash
);
23460 case DW_OP_GNU_convert
:
23461 case DW_OP_GNU_reinterpret
:
23462 if (val1
->val_class
== dw_val_class_unsigned_const
)
23464 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23468 case DW_OP_GNU_const_type
:
23470 unsigned int byte_size
23471 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23472 unsigned int encoding
23473 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23474 hash
= iterative_hash_object (byte_size
, hash
);
23475 hash
= iterative_hash_object (encoding
, hash
);
23476 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23478 hash
= iterative_hash_object (val2
->val_class
, hash
);
23479 switch (val2
->val_class
)
23481 case dw_val_class_const
:
23482 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23484 case dw_val_class_vec
:
23486 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23487 unsigned int len
= val2
->v
.val_vec
.length
;
23489 hash
= iterative_hash_object (elt_size
, hash
);
23490 hash
= iterative_hash_object (len
, hash
);
23491 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23492 len
* elt_size
, hash
);
23495 case dw_val_class_const_double
:
23496 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23497 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23500 gcc_unreachable ();
23506 /* Other codes have no operands. */
23512 /* Iteratively hash the whole DWARF location expression LOC. */
23514 static inline hashval_t
23515 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23517 dw_loc_descr_ref l
;
23518 bool sizes_computed
= false;
23519 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23520 size_of_locs (loc
);
23522 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23524 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23525 hash
= iterative_hash_object (opc
, hash
);
23526 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23528 size_of_locs (loc
);
23529 sizes_computed
= true;
23531 hash
= hash_loc_operands (l
, hash
);
23536 /* Compute hash of the whole location list LIST_HEAD. */
23539 hash_loc_list (dw_loc_list_ref list_head
)
23541 dw_loc_list_ref curr
= list_head
;
23542 hashval_t hash
= 0;
23544 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23546 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23547 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23549 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23551 hash
= hash_locs (curr
->expr
, hash
);
23553 list_head
->hash
= hash
;
23556 /* Return true if X and Y opcodes have the same operands. */
23559 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23561 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23562 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23563 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23564 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23566 switch (x
->dw_loc_opc
)
23568 case DW_OP_const4u
:
23569 case DW_OP_const8u
:
23573 case DW_OP_const1u
:
23574 case DW_OP_const1s
:
23575 case DW_OP_const2u
:
23576 case DW_OP_const2s
:
23577 case DW_OP_const4s
:
23578 case DW_OP_const8s
:
23582 case DW_OP_plus_uconst
:
23618 case DW_OP_deref_size
:
23619 case DW_OP_xderef_size
:
23620 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23623 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23624 can cause irrelevant differences in dw_loc_addr. */
23625 gcc_assert (valx1
->val_class
== dw_val_class_loc
23626 && valy1
->val_class
== dw_val_class_loc
23627 && (dwarf_split_debug_info
23628 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23629 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23630 case DW_OP_implicit_value
:
23631 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23632 || valx2
->val_class
!= valy2
->val_class
)
23634 switch (valx2
->val_class
)
23636 case dw_val_class_const
:
23637 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23638 case dw_val_class_vec
:
23639 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23640 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23641 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23642 valx2
->v
.val_vec
.elt_size
23643 * valx2
->v
.val_vec
.length
) == 0;
23644 case dw_val_class_const_double
:
23645 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23646 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23647 case dw_val_class_addr
:
23648 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23650 gcc_unreachable ();
23653 case DW_OP_bit_piece
:
23654 return valx1
->v
.val_int
== valy1
->v
.val_int
23655 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23658 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23659 case DW_OP_GNU_addr_index
:
23660 case DW_OP_GNU_const_index
:
23662 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23663 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23664 return rtx_equal_p (ax1
, ay1
);
23666 case DW_OP_GNU_implicit_pointer
:
23667 return valx1
->val_class
== dw_val_class_die_ref
23668 && valx1
->val_class
== valy1
->val_class
23669 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23670 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23671 case DW_OP_GNU_entry_value
:
23672 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23673 case DW_OP_GNU_const_type
:
23674 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23675 || valx2
->val_class
!= valy2
->val_class
)
23677 switch (valx2
->val_class
)
23679 case dw_val_class_const
:
23680 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23681 case dw_val_class_vec
:
23682 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23683 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23684 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23685 valx2
->v
.val_vec
.elt_size
23686 * valx2
->v
.val_vec
.length
) == 0;
23687 case dw_val_class_const_double
:
23688 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23689 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23691 gcc_unreachable ();
23693 case DW_OP_GNU_regval_type
:
23694 case DW_OP_GNU_deref_type
:
23695 return valx1
->v
.val_int
== valy1
->v
.val_int
23696 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23697 case DW_OP_GNU_convert
:
23698 case DW_OP_GNU_reinterpret
:
23699 if (valx1
->val_class
!= valy1
->val_class
)
23701 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23702 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23703 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23704 case DW_OP_GNU_parameter_ref
:
23705 return valx1
->val_class
== dw_val_class_die_ref
23706 && valx1
->val_class
== valy1
->val_class
23707 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23709 /* Other codes have no operands. */
23714 /* Return true if DWARF location expressions X and Y are the same. */
23717 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23719 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23720 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23721 || x
->dtprel
!= y
->dtprel
23722 || !compare_loc_operands (x
, y
))
23724 return x
== NULL
&& y
== NULL
;
23727 /* Hashtable helpers. */
23729 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23731 typedef dw_loc_list_struct value_type
;
23732 typedef dw_loc_list_struct compare_type
;
23733 static inline hashval_t
hash (const value_type
*);
23734 static inline bool equal (const value_type
*, const compare_type
*);
23737 /* Return precomputed hash of location list X. */
23740 loc_list_hasher::hash (const value_type
*x
)
23745 /* Return true if location lists A and B are the same. */
23748 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23752 if (a
->hash
!= b
->hash
)
23754 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23755 if (strcmp (a
->begin
, b
->begin
) != 0
23756 || strcmp (a
->end
, b
->end
) != 0
23757 || (a
->section
== NULL
) != (b
->section
== NULL
)
23758 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23759 || !compare_locs (a
->expr
, b
->expr
))
23761 return a
== NULL
&& b
== NULL
;
23764 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23767 /* Recursively optimize location lists referenced from DIE
23768 children and share them whenever possible. */
23771 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23776 dw_loc_list_struct
**slot
;
23778 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23779 if (AT_class (a
) == dw_val_class_loc_list
)
23781 dw_loc_list_ref list
= AT_loc_list (a
);
23782 /* TODO: perform some optimizations here, before hashing
23783 it and storing into the hash table. */
23784 hash_loc_list (list
);
23785 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23789 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23792 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23796 /* Recursively assign each location list a unique index into the debug_addr
23800 index_location_lists (dw_die_ref die
)
23806 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23807 if (AT_class (a
) == dw_val_class_loc_list
)
23809 dw_loc_list_ref list
= AT_loc_list (a
);
23810 dw_loc_list_ref curr
;
23811 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23813 /* Don't index an entry that has already been indexed
23814 or won't be output. */
23815 if (curr
->begin_entry
!= NULL
23816 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23820 = add_addr_table_entry (xstrdup (curr
->begin
),
23825 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23828 /* Optimize location lists referenced from DIE
23829 children and share them whenever possible. */
23832 optimize_location_lists (dw_die_ref die
)
23834 loc_list_hash_type htab
;
23836 optimize_location_lists_1 (die
, htab
);
23840 /* Output stuff that dwarf requires at the end of every file,
23841 and generate the DWARF-2 debugging info. */
23844 dwarf2out_finish (const char *filename
)
23846 limbo_die_node
*node
, *next_node
;
23847 comdat_type_node
*ctnode
;
23848 hash_table
<comdat_type_hasher
> comdat_type_table
;
23850 dw_die_ref main_comp_unit_die
;
23852 /* PCH might result in DW_AT_producer string being restored from the
23853 header compilation, so always fill it with empty string initially
23854 and overwrite only here. */
23855 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23856 producer_string
= gen_producer_string ();
23857 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23858 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23860 gen_scheduled_generic_parms_dies ();
23861 gen_remaining_tmpl_value_param_die_attribute ();
23863 /* Add the name for the main input file now. We delayed this from
23864 dwarf2out_init to avoid complications with PCH. */
23865 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23866 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23867 add_comp_dir_attribute (comp_unit_die ());
23868 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23871 htab_traverse (file_table
, file_table_relative_p
, &p
);
23873 add_comp_dir_attribute (comp_unit_die ());
23876 if (deferred_locations_list
)
23877 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23879 add_location_or_const_value_attribute (
23880 (*deferred_locations_list
)[i
].die
,
23881 (*deferred_locations_list
)[i
].variable
,
23886 /* Traverse the limbo die list, and add parent/child links. The only
23887 dies without parents that should be here are concrete instances of
23888 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23889 For concrete instances, we can get the parent die from the abstract
23891 for (node
= limbo_die_list
; node
; node
= next_node
)
23893 dw_die_ref die
= node
->die
;
23894 next_node
= node
->next
;
23896 if (die
->die_parent
== NULL
)
23898 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23900 if (origin
&& origin
->die_parent
)
23901 add_child_die (origin
->die_parent
, die
);
23902 else if (is_cu_die (die
))
23904 else if (seen_error ())
23905 /* It's OK to be confused by errors in the input. */
23906 add_child_die (comp_unit_die (), die
);
23909 /* In certain situations, the lexical block containing a
23910 nested function can be optimized away, which results
23911 in the nested function die being orphaned. Likewise
23912 with the return type of that nested function. Force
23913 this to be a child of the containing function.
23915 It may happen that even the containing function got fully
23916 inlined and optimized out. In that case we are lost and
23917 assign the empty child. This should not be big issue as
23918 the function is likely unreachable too. */
23919 gcc_assert (node
->created_for
);
23921 if (DECL_P (node
->created_for
))
23922 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23923 else if (TYPE_P (node
->created_for
))
23924 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23926 origin
= comp_unit_die ();
23928 add_child_die (origin
, die
);
23933 limbo_die_list
= NULL
;
23935 #if ENABLE_ASSERT_CHECKING
23937 dw_die_ref die
= comp_unit_die (), c
;
23938 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23941 resolve_addr (comp_unit_die ());
23942 move_marked_base_types ();
23944 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23946 tree decl
= node
->created_for
;
23947 /* When generating LTO bytecode we can not generate new assembler
23948 names at this point and all important decls got theirs via
23950 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23951 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23953 add_linkage_attr (node
->die
, decl
);
23954 move_linkage_attr (node
->die
);
23958 deferred_asm_name
= NULL
;
23960 /* Walk through the list of incomplete types again, trying once more to
23961 emit full debugging info for them. */
23962 retry_incomplete_types ();
23964 if (flag_eliminate_unused_debug_types
)
23965 prune_unused_types ();
23967 /* Generate separate COMDAT sections for type DIEs. */
23968 if (use_debug_types
)
23970 break_out_comdat_types (comp_unit_die ());
23972 /* Each new type_unit DIE was added to the limbo die list when created.
23973 Since these have all been added to comdat_type_list, clear the
23975 limbo_die_list
= NULL
;
23977 /* For each new comdat type unit, copy declarations for incomplete
23978 types to make the new unit self-contained (i.e., no direct
23979 references to the main compile unit). */
23980 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23981 copy_decls_for_unworthy_types (ctnode
->root_die
);
23982 copy_decls_for_unworthy_types (comp_unit_die ());
23984 /* In the process of copying declarations from one unit to another,
23985 we may have left some declarations behind that are no longer
23986 referenced. Prune them. */
23987 prune_unused_types ();
23990 /* Generate separate CUs for each of the include files we've seen.
23991 They will go into limbo_die_list. */
23992 if (flag_eliminate_dwarf2_dups
)
23993 break_out_includes (comp_unit_die ());
23995 /* Traverse the DIE's and add add sibling attributes to those DIE's
23996 that have children. */
23997 add_sibling_attributes (comp_unit_die ());
23998 for (node
= limbo_die_list
; node
; node
= node
->next
)
23999 add_sibling_attributes (node
->die
);
24000 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24001 add_sibling_attributes (ctnode
->root_die
);
24003 /* When splitting DWARF info, we put some attributes in the
24004 skeleton compile_unit DIE that remains in the .o, while
24005 most attributes go in the DWO compile_unit_die. */
24006 if (dwarf_split_debug_info
)
24007 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24009 main_comp_unit_die
= comp_unit_die ();
24011 /* Output a terminator label for the .text section. */
24012 switch_to_section (text_section
);
24013 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24014 if (cold_text_section
)
24016 switch_to_section (cold_text_section
);
24017 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24020 /* We can only use the low/high_pc attributes if all of the code was
24022 if (!have_multiple_function_sections
24023 || (dwarf_version
< 3 && dwarf_strict
))
24025 /* Don't add if the CU has no associated code. */
24026 if (text_section_used
)
24027 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24028 text_end_label
, true);
24034 bool range_list_added
= false;
24036 if (text_section_used
)
24037 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24038 text_end_label
, &range_list_added
, true);
24039 if (cold_text_section_used
)
24040 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24041 cold_end_label
, &range_list_added
, true);
24043 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24045 if (DECL_IGNORED_P (fde
->decl
))
24047 if (!fde
->in_std_section
)
24048 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24049 fde
->dw_fde_end
, &range_list_added
,
24051 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24052 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24053 fde
->dw_fde_second_end
, &range_list_added
,
24057 if (range_list_added
)
24059 /* We need to give .debug_loc and .debug_ranges an appropriate
24060 "base address". Use zero so that these addresses become
24061 absolute. Historically, we've emitted the unexpected
24062 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24063 Emit both to give time for other tools to adapt. */
24064 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24065 if (! dwarf_strict
&& dwarf_version
< 4)
24066 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24072 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
24073 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24074 debug_line_section_label
);
24077 add_AT_macptr (comp_unit_die (),
24078 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24079 macinfo_section_label
);
24081 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
24083 /* optimize_location_lists calculates the size of the lists,
24084 so index them first, and assign indices to the entries.
24085 Although optimize_location_lists will remove entries from
24086 the table, it only does so for duplicates, and therefore
24087 only reduces ref_counts to 1. */
24088 unsigned int index
= 0;
24089 index_location_lists (comp_unit_die ());
24090 htab_traverse_noresize (addr_index_table
,
24091 index_addr_table_entry
, &index
);
24093 if (have_location_lists
)
24094 optimize_location_lists (comp_unit_die ());
24096 save_macinfo_strings ();
24098 if (dwarf_split_debug_info
)
24100 unsigned int index
= 0;
24102 /* Add attributes common to skeleton compile_units and
24103 type_units. Because these attributes include strings, it
24104 must be done before freezing the string table. Top-level
24105 skeleton die attrs are added when the skeleton type unit is
24106 created, so ensure it is created by this point. */
24107 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24108 (void) get_skeleton_type_unit ();
24109 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24112 /* Output all of the compilation units. We put the main one last so that
24113 the offsets are available to output_pubnames. */
24114 for (node
= limbo_die_list
; node
; node
= node
->next
)
24115 output_comp_unit (node
->die
, 0);
24117 comdat_type_table
.create (100);
24118 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24120 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24122 /* Don't output duplicate types. */
24123 if (*slot
!= HTAB_EMPTY_ENTRY
)
24126 /* Add a pointer to the line table for the main compilation unit
24127 so that the debugger can make sense of DW_AT_decl_file
24129 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
24130 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24131 (!dwarf_split_debug_info
24132 ? debug_line_section_label
24133 : debug_skeleton_line_section_label
));
24135 output_comdat_type_unit (ctnode
);
24138 comdat_type_table
.dispose ();
24140 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24141 both the main_cu and all skeleton TUs. Making this call unconditional
24142 would end up either adding a second copy of the AT_pubnames attribute, or
24143 requiring a special case in add_top_level_skeleton_die_attrs. */
24144 if (!dwarf_split_debug_info
)
24145 add_AT_pubnames (comp_unit_die ());
24147 if (dwarf_split_debug_info
)
24150 unsigned char checksum
[16];
24151 struct md5_ctx ctx
;
24153 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24154 md5_init_ctx (&ctx
);
24156 die_checksum (comp_unit_die (), &ctx
, &mark
);
24157 unmark_all_dies (comp_unit_die ());
24158 md5_finish_ctx (&ctx
, checksum
);
24160 /* Use the first 8 bytes of the checksum as the dwo_id,
24161 and add it to both comp-unit DIEs. */
24162 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24163 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24165 /* Add the base offset of the ranges table to the skeleton
24167 if (ranges_table_in_use
)
24168 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24169 ranges_section_label
);
24171 switch_to_section (debug_addr_section
);
24172 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24173 output_addr_table ();
24176 /* Output the main compilation unit if non-empty or if .debug_macinfo
24177 or .debug_macro will be emitted. */
24178 output_comp_unit (comp_unit_die (), have_macinfo
);
24180 if (dwarf_split_debug_info
&& info_section_emitted
)
24181 output_skeleton_debug_sections (main_comp_unit_die
);
24183 /* Output the abbreviation table. */
24184 if (abbrev_die_table_in_use
!= 1)
24186 switch_to_section (debug_abbrev_section
);
24187 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24188 output_abbrev_section ();
24191 /* Output location list section if necessary. */
24192 if (have_location_lists
)
24194 /* Output the location lists info. */
24195 switch_to_section (debug_loc_section
);
24196 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24197 output_location_lists (comp_unit_die ());
24200 output_pubtables ();
24202 /* Output the address range information if a CU (.debug_info section)
24203 was emitted. We output an empty table even if we had no functions
24204 to put in it. This because the consumer has no way to tell the
24205 difference between an empty table that we omitted and failure to
24206 generate a table that would have contained data. */
24207 if (info_section_emitted
)
24209 unsigned long aranges_length
= size_of_aranges ();
24211 switch_to_section (debug_aranges_section
);
24212 output_aranges (aranges_length
);
24215 /* Output ranges section if necessary. */
24216 if (ranges_table_in_use
)
24218 switch_to_section (debug_ranges_section
);
24219 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24223 /* Have to end the macro section. */
24226 switch_to_section (debug_macinfo_section
);
24227 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24229 dw2_asm_output_data (1, 0, "End compilation unit");
24232 /* Output the source line correspondence table. We must do this
24233 even if there is no line information. Otherwise, on an empty
24234 translation unit, we will generate a present, but empty,
24235 .debug_info section. IRIX 6.5 `nm' will then complain when
24236 examining the file. This is done late so that any filenames
24237 used by the debug_info section are marked as 'used'. */
24238 switch_to_section (debug_line_section
);
24239 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24240 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24241 output_line_info (false);
24243 if (dwarf_split_debug_info
&& info_section_emitted
)
24245 switch_to_section (debug_skeleton_line_section
);
24246 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24247 output_line_info (true);
24250 /* If we emitted any indirect strings, output the string table too. */
24251 if (debug_str_hash
|| skeleton_debug_str_hash
)
24252 output_indirect_strings ();
24255 #include "gt-dwarf2out.h"