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) \
356 /* Get the number of HOST_WIDE_INTs needed to represent the precision
360 get_full_len (const wide_int
&op
)
362 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
363 / HOST_BITS_PER_WIDE_INT
);
367 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
369 enum debug_struct_file criterion
;
371 bool generic
= lang_hooks
.types
.generic_p (type
);
374 criterion
= debug_struct_generic
[usage
];
376 criterion
= debug_struct_ordinary
[usage
];
378 if (criterion
== DINFO_STRUCT_FILE_NONE
)
379 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
380 if (criterion
== DINFO_STRUCT_FILE_ANY
)
381 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
383 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
385 if (type_decl
!= NULL
)
387 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
388 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
390 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
391 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
394 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
397 /* Return a pointer to a copy of the section string name S with all
398 attributes stripped off, and an asterisk prepended (for assemble_name). */
401 stripattributes (const char *s
)
403 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
408 while (*s
&& *s
!= ',')
415 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
416 switch to the data section instead, and write out a synthetic start label
417 for collect2 the first time around. */
420 switch_to_eh_frame_section (bool back
)
424 #ifdef EH_FRAME_SECTION_NAME
425 if (eh_frame_section
== 0)
429 if (EH_TABLES_CAN_BE_READ_ONLY
)
435 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
437 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
439 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
442 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
443 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
444 && (per_encoding
& 0x70) != DW_EH_PE_absptr
445 && (per_encoding
& 0x70) != DW_EH_PE_aligned
446 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
447 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
448 ? 0 : SECTION_WRITE
);
451 flags
= SECTION_WRITE
;
452 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
454 #endif /* EH_FRAME_SECTION_NAME */
456 if (eh_frame_section
)
457 switch_to_section (eh_frame_section
);
460 /* We have no special eh_frame section. Put the information in
461 the data section and emit special labels to guide collect2. */
462 switch_to_section (data_section
);
466 label
= get_file_function_name ("F");
467 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
468 targetm
.asm_out
.globalize_label (asm_out_file
,
469 IDENTIFIER_POINTER (label
));
470 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
475 /* Switch [BACK] to the eh or debug frame table section, depending on
479 switch_to_frame_table_section (int for_eh
, bool back
)
482 switch_to_eh_frame_section (back
);
485 if (!debug_frame_section
)
486 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
487 SECTION_DEBUG
, NULL
);
488 switch_to_section (debug_frame_section
);
492 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
494 enum dw_cfi_oprnd_type
495 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
500 case DW_CFA_GNU_window_save
:
501 case DW_CFA_remember_state
:
502 case DW_CFA_restore_state
:
503 return dw_cfi_oprnd_unused
;
506 case DW_CFA_advance_loc1
:
507 case DW_CFA_advance_loc2
:
508 case DW_CFA_advance_loc4
:
509 case DW_CFA_MIPS_advance_loc8
:
510 return dw_cfi_oprnd_addr
;
513 case DW_CFA_offset_extended
:
515 case DW_CFA_offset_extended_sf
:
516 case DW_CFA_def_cfa_sf
:
518 case DW_CFA_restore_extended
:
519 case DW_CFA_undefined
:
520 case DW_CFA_same_value
:
521 case DW_CFA_def_cfa_register
:
522 case DW_CFA_register
:
523 case DW_CFA_expression
:
524 return dw_cfi_oprnd_reg_num
;
526 case DW_CFA_def_cfa_offset
:
527 case DW_CFA_GNU_args_size
:
528 case DW_CFA_def_cfa_offset_sf
:
529 return dw_cfi_oprnd_offset
;
531 case DW_CFA_def_cfa_expression
:
532 return dw_cfi_oprnd_loc
;
539 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
541 enum dw_cfi_oprnd_type
542 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
547 case DW_CFA_def_cfa_sf
:
549 case DW_CFA_offset_extended_sf
:
550 case DW_CFA_offset_extended
:
551 return dw_cfi_oprnd_offset
;
553 case DW_CFA_register
:
554 return dw_cfi_oprnd_reg_num
;
556 case DW_CFA_expression
:
557 return dw_cfi_oprnd_loc
;
560 return dw_cfi_oprnd_unused
;
564 /* Output one FDE. */
567 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
568 char *section_start_label
, int fde_encoding
, char *augmentation
,
569 bool any_lsda_needed
, int lsda_encoding
)
571 const char *begin
, *end
;
572 static unsigned int j
;
575 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
577 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
579 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
580 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
581 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
582 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
583 " indicating 64-bit DWARF extension");
584 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
586 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
589 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
591 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
592 debug_frame_section
, "FDE CIE offset");
594 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
595 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
599 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
600 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
601 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
602 "FDE initial location");
603 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
604 end
, begin
, "FDE address range");
608 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
609 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
616 int size
= size_of_encoded_value (lsda_encoding
);
618 if (lsda_encoding
== DW_EH_PE_aligned
)
620 int offset
= ( 4 /* Length */
622 + 2 * size_of_encoded_value (fde_encoding
)
623 + 1 /* Augmentation size */ );
624 int pad
= -offset
& (PTR_SIZE
- 1);
627 gcc_assert (size_of_uleb128 (size
) == 1);
630 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
632 if (fde
->uses_eh_lsda
)
634 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
635 fde
->funcdef_number
);
636 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
637 gen_rtx_SYMBOL_REF (Pmode
, l1
),
639 "Language Specific Data Area");
643 if (lsda_encoding
== DW_EH_PE_aligned
)
644 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
645 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
646 "Language Specific Data Area (none)");
650 dw2_asm_output_data_uleb128 (0, "Augmentation size");
653 /* Loop through the Call Frame Instructions associated with this FDE. */
654 fde
->dw_fde_current_label
= begin
;
656 size_t from
, until
, i
;
659 until
= vec_safe_length (fde
->dw_fde_cfi
);
661 if (fde
->dw_fde_second_begin
== NULL
)
664 until
= fde
->dw_fde_switch_cfi_index
;
666 from
= fde
->dw_fde_switch_cfi_index
;
668 for (i
= from
; i
< until
; i
++)
669 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
672 /* If we are to emit a ref/link from function bodies to their frame tables,
673 do it now. This is typically performed to make sure that tables
674 associated with functions are dragged with them and not discarded in
675 garbage collecting links. We need to do this on a per function basis to
676 cope with -ffunction-sections. */
678 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
679 /* Switch to the function section, emit the ref to the tables, and
680 switch *back* into the table section. */
681 switch_to_section (function_section (fde
->decl
));
682 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
683 switch_to_frame_table_section (for_eh
, true);
686 /* Pad the FDE out to an address sized boundary. */
687 ASM_OUTPUT_ALIGN (asm_out_file
,
688 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
689 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
694 /* Return true if frame description entry FDE is needed for EH. */
697 fde_needed_for_eh_p (dw_fde_ref fde
)
699 if (flag_asynchronous_unwind_tables
)
702 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
705 if (fde
->uses_eh_lsda
)
708 /* If exceptions are enabled, we have collected nothrow info. */
709 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
715 /* Output the call frame information used to record information
716 that relates to calculating the frame pointer, and records the
717 location of saved registers. */
720 output_call_frame_info (int for_eh
)
725 char l1
[20], l2
[20], section_start_label
[20];
726 bool any_lsda_needed
= false;
727 char augmentation
[6];
728 int augmentation_size
;
729 int fde_encoding
= DW_EH_PE_absptr
;
730 int per_encoding
= DW_EH_PE_absptr
;
731 int lsda_encoding
= DW_EH_PE_absptr
;
733 rtx personality
= NULL
;
736 /* Don't emit a CIE if there won't be any FDEs. */
740 /* Nothing to do if the assembler's doing it all. */
741 if (dwarf2out_do_cfi_asm ())
744 /* If we don't have any functions we'll want to unwind out of, don't emit
745 any EH unwind information. If we make FDEs linkonce, we may have to
746 emit an empty label for an FDE that wouldn't otherwise be emitted. We
747 want to avoid having an FDE kept around when the function it refers to
748 is discarded. Example where this matters: a primary function template
749 in C++ requires EH information, an explicit specialization doesn't. */
752 bool any_eh_needed
= false;
754 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
756 if (fde
->uses_eh_lsda
)
757 any_eh_needed
= any_lsda_needed
= true;
758 else if (fde_needed_for_eh_p (fde
))
759 any_eh_needed
= true;
760 else if (TARGET_USES_WEAK_UNWIND_INFO
)
761 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
768 /* We're going to be generating comments, so turn on app. */
772 /* Switch to the proper frame section, first time. */
773 switch_to_frame_table_section (for_eh
, false);
775 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
776 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
778 /* Output the CIE. */
779 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
780 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
781 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
782 dw2_asm_output_data (4, 0xffffffff,
783 "Initial length escape value indicating 64-bit DWARF extension");
784 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
785 "Length of Common Information Entry");
786 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
788 /* Now that the CIE pointer is PC-relative for EH,
789 use 0 to identify the CIE. */
790 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
791 (for_eh
? 0 : DWARF_CIE_ID
),
792 "CIE Identifier Tag");
794 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
795 use CIE version 1, unless that would produce incorrect results
796 due to overflowing the return register column. */
797 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
799 if (return_reg
>= 256 || dwarf_version
> 2)
801 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
804 augmentation_size
= 0;
806 personality
= current_unit_personality
;
812 z Indicates that a uleb128 is present to size the
813 augmentation section.
814 L Indicates the encoding (and thus presence) of
815 an LSDA pointer in the FDE augmentation.
816 R Indicates a non-default pointer encoding for
818 P Indicates the presence of an encoding + language
819 personality routine in the CIE augmentation. */
821 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
822 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
823 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
825 p
= augmentation
+ 1;
829 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
830 assemble_external_libcall (personality
);
835 augmentation_size
+= 1;
837 if (fde_encoding
!= DW_EH_PE_absptr
)
840 augmentation_size
+= 1;
842 if (p
> augmentation
+ 1)
844 augmentation
[0] = 'z';
848 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
849 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
851 int offset
= ( 4 /* Length */
853 + 1 /* CIE version */
854 + strlen (augmentation
) + 1 /* Augmentation */
855 + size_of_uleb128 (1) /* Code alignment */
856 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
858 + 1 /* Augmentation size */
859 + 1 /* Personality encoding */ );
860 int pad
= -offset
& (PTR_SIZE
- 1);
862 augmentation_size
+= pad
;
864 /* Augmentations should be small, so there's scarce need to
865 iterate for a solution. Die if we exceed one uleb128 byte. */
866 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
870 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
871 if (dw_cie_version
>= 4)
873 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
874 dw2_asm_output_data (1, 0, "CIE Segment Size");
876 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
877 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
878 "CIE Data Alignment Factor");
880 if (dw_cie_version
== 1)
881 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
883 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
887 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
890 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
891 eh_data_format_name (per_encoding
));
892 dw2_asm_output_encoded_addr_rtx (per_encoding
,
898 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
899 eh_data_format_name (lsda_encoding
));
901 if (fde_encoding
!= DW_EH_PE_absptr
)
902 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
903 eh_data_format_name (fde_encoding
));
906 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
907 output_cfi (cfi
, NULL
, for_eh
);
909 /* Pad the CIE out to an address sized boundary. */
910 ASM_OUTPUT_ALIGN (asm_out_file
,
911 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
912 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
914 /* Loop through all of the FDE's. */
915 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
919 /* Don't emit EH unwind info for leaf functions that don't need it. */
920 if (for_eh
&& !fde_needed_for_eh_p (fde
))
923 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
924 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
925 augmentation
, any_lsda_needed
, lsda_encoding
);
928 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
929 dw2_asm_output_data (4, 0, "End of Table");
931 /* Turn off app to make assembly quicker. */
936 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
939 dwarf2out_do_cfi_startproc (bool second
)
943 rtx personality
= get_personality_function (current_function_decl
);
945 fprintf (asm_out_file
, "\t.cfi_startproc\n");
949 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
952 /* ??? The GAS support isn't entirely consistent. We have to
953 handle indirect support ourselves, but PC-relative is done
954 in the assembler. Further, the assembler can't handle any
955 of the weirder relocation types. */
956 if (enc
& DW_EH_PE_indirect
)
957 ref
= dw2_force_const_mem (ref
, true);
959 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
960 output_addr_const (asm_out_file
, ref
);
961 fputc ('\n', asm_out_file
);
964 if (crtl
->uses_eh_lsda
)
968 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
969 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
970 current_function_funcdef_no
);
971 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
972 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
974 if (enc
& DW_EH_PE_indirect
)
975 ref
= dw2_force_const_mem (ref
, true);
977 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
978 output_addr_const (asm_out_file
, ref
);
979 fputc ('\n', asm_out_file
);
983 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
984 this allocation may be done before pass_final. */
987 dwarf2out_alloc_current_fde (void)
991 fde
= ggc_alloc_cleared_dw_fde_node ();
992 fde
->decl
= current_function_decl
;
993 fde
->funcdef_number
= current_function_funcdef_no
;
994 fde
->fde_index
= vec_safe_length (fde_vec
);
995 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
996 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
997 fde
->nothrow
= crtl
->nothrow
;
998 fde
->drap_reg
= INVALID_REGNUM
;
999 fde
->vdrap_reg
= INVALID_REGNUM
;
1001 /* Record the FDE associated with this function. */
1003 vec_safe_push (fde_vec
, fde
);
1008 /* Output a marker (i.e. a label) for the beginning of a function, before
1012 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1013 const char *file ATTRIBUTE_UNUSED
)
1015 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1021 current_function_func_begin_label
= NULL
;
1023 do_frame
= dwarf2out_do_frame ();
1025 /* ??? current_function_func_begin_label is also used by except.c for
1026 call-site information. We must emit this label if it might be used. */
1028 && (!flag_exceptions
1029 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1032 fnsec
= function_section (current_function_decl
);
1033 switch_to_section (fnsec
);
1034 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1035 current_function_funcdef_no
);
1036 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1037 current_function_funcdef_no
);
1038 dup_label
= xstrdup (label
);
1039 current_function_func_begin_label
= dup_label
;
1041 /* We can elide the fde allocation if we're not emitting debug info. */
1045 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1046 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1047 would include pass_dwarf2_frame. If we've not created the FDE yet,
1051 fde
= dwarf2out_alloc_current_fde ();
1053 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1054 fde
->dw_fde_begin
= dup_label
;
1055 fde
->dw_fde_current_label
= dup_label
;
1056 fde
->in_std_section
= (fnsec
== text_section
1057 || (cold_text_section
&& fnsec
== cold_text_section
));
1059 /* We only want to output line number information for the genuine dwarf2
1060 prologue case, not the eh frame case. */
1061 #ifdef DWARF2_DEBUGGING_INFO
1063 dwarf2out_source_line (line
, file
, 0, true);
1066 if (dwarf2out_do_cfi_asm ())
1067 dwarf2out_do_cfi_startproc (false);
1070 rtx personality
= get_personality_function (current_function_decl
);
1071 if (!current_unit_personality
)
1072 current_unit_personality
= personality
;
1074 /* We cannot keep a current personality per function as without CFI
1075 asm, at the point where we emit the CFI data, there is no current
1076 function anymore. */
1077 if (personality
&& current_unit_personality
!= personality
)
1078 sorry ("multiple EH personalities are supported only with assemblers "
1079 "supporting .cfi_personality directive");
1083 /* Output a marker (i.e. a label) for the end of the generated code
1084 for a function prologue. This gets called *after* the prologue code has
1088 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1089 const char *file ATTRIBUTE_UNUSED
)
1091 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1093 /* Output a label to mark the endpoint of the code generated for this
1095 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1096 current_function_funcdef_no
);
1097 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1098 current_function_funcdef_no
);
1099 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1102 /* Output a marker (i.e. a label) for the beginning of the generated code
1103 for a function epilogue. This gets called *before* the prologue code has
1107 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1108 const char *file ATTRIBUTE_UNUSED
)
1110 dw_fde_ref fde
= cfun
->fde
;
1111 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1113 if (fde
->dw_fde_vms_begin_epilogue
)
1116 /* Output a label to mark the endpoint of the code generated for this
1118 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1119 current_function_funcdef_no
);
1120 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1121 current_function_funcdef_no
);
1122 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1125 /* Output a marker (i.e. a label) for the absolute end of the generated code
1126 for a function definition. This gets called *after* the epilogue code has
1130 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1131 const char *file ATTRIBUTE_UNUSED
)
1134 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1136 last_var_location_insn
= NULL_RTX
;
1137 cached_next_real_insn
= NULL_RTX
;
1139 if (dwarf2out_do_cfi_asm ())
1140 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1142 /* Output a label to mark the endpoint of the code generated for this
1144 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1145 current_function_funcdef_no
);
1146 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1148 gcc_assert (fde
!= NULL
);
1149 if (fde
->dw_fde_second_begin
== NULL
)
1150 fde
->dw_fde_end
= xstrdup (label
);
1154 dwarf2out_frame_finish (void)
1156 /* Output call frame information. */
1157 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1158 output_call_frame_info (0);
1160 /* Output another copy for the unwinder. */
1161 if ((flag_unwind_tables
|| flag_exceptions
)
1162 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1163 output_call_frame_info (1);
1166 /* Note that the current function section is being used for code. */
1169 dwarf2out_note_section_used (void)
1171 section
*sec
= current_function_section ();
1172 if (sec
== text_section
)
1173 text_section_used
= true;
1174 else if (sec
== cold_text_section
)
1175 cold_text_section_used
= true;
1178 static void var_location_switch_text_section (void);
1179 static void set_cur_line_info_table (section
*);
1182 dwarf2out_switch_text_section (void)
1185 dw_fde_ref fde
= cfun
->fde
;
1187 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1189 if (!in_cold_section_p
)
1191 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1192 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1193 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1197 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1198 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1199 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1201 have_multiple_function_sections
= true;
1203 /* There is no need to mark used sections when not debugging. */
1204 if (cold_text_section
!= NULL
)
1205 dwarf2out_note_section_used ();
1207 if (dwarf2out_do_cfi_asm ())
1208 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1210 /* Now do the real section switch. */
1211 sect
= current_function_section ();
1212 switch_to_section (sect
);
1214 fde
->second_in_std_section
1215 = (sect
== text_section
1216 || (cold_text_section
&& sect
== cold_text_section
));
1218 if (dwarf2out_do_cfi_asm ())
1219 dwarf2out_do_cfi_startproc (true);
1221 var_location_switch_text_section ();
1223 if (cold_text_section
!= NULL
)
1224 set_cur_line_info_table (sect
);
1227 /* And now, the subset of the debugging information support code necessary
1228 for emitting location expressions. */
1230 /* Data about a single source file. */
1231 struct GTY(()) dwarf_file_data
{
1232 const char * filename
;
1236 typedef struct GTY(()) deferred_locations_struct
1240 } deferred_locations
;
1243 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1246 /* Describe an entry into the .debug_addr section. */
1250 ate_kind_rtx_dtprel
,
1254 typedef struct GTY(()) addr_table_entry_struct
{
1256 unsigned int refcount
;
1258 union addr_table_entry_struct_union
1260 rtx
GTY ((tag ("0"))) rtl
;
1261 char * GTY ((tag ("1"))) label
;
1263 GTY ((desc ("%1.kind"))) addr
;
1267 /* Location lists are ranges + location descriptions for that range,
1268 so you can track variables that are in different places over
1269 their entire life. */
1270 typedef struct GTY(()) dw_loc_list_struct
{
1271 dw_loc_list_ref dw_loc_next
;
1272 const char *begin
; /* Label and addr_entry for start of range */
1273 addr_table_entry
*begin_entry
;
1274 const char *end
; /* Label for end of range */
1275 char *ll_symbol
; /* Label for beginning of location list.
1276 Only on head of list */
1277 const char *section
; /* Section this loclist is relative to */
1278 dw_loc_descr_ref expr
;
1280 /* True if all addresses in this and subsequent lists are known to be
1283 /* True if this list has been replaced by dw_loc_next. */
1286 /* True if the range should be emitted even if begin and end
1291 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1293 /* Convert a DWARF stack opcode into its string name. */
1296 dwarf_stack_op_name (unsigned int op
)
1298 const char *name
= get_DW_OP_name (op
);
1303 return "OP_<unknown>";
1306 /* Return a pointer to a newly allocated location description. Location
1307 descriptions are simple expression terms that can be strung
1308 together to form more complicated location (address) descriptions. */
1310 static inline dw_loc_descr_ref
1311 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1312 unsigned HOST_WIDE_INT oprnd2
)
1314 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1316 descr
->dw_loc_opc
= op
;
1317 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1318 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1319 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1320 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1321 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1322 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1327 /* Return a pointer to a newly allocated location description for
1330 static inline dw_loc_descr_ref
1331 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1334 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1337 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1340 /* Add a location description term to a location description expression. */
1343 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1345 dw_loc_descr_ref
*d
;
1347 /* Find the end of the chain. */
1348 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1354 /* Compare two location operands for exact equality. */
1357 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1359 if (a
->val_class
!= b
->val_class
)
1361 switch (a
->val_class
)
1363 case dw_val_class_none
:
1365 case dw_val_class_addr
:
1366 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1368 case dw_val_class_offset
:
1369 case dw_val_class_unsigned_const
:
1370 case dw_val_class_const
:
1371 case dw_val_class_range_list
:
1372 case dw_val_class_lineptr
:
1373 case dw_val_class_macptr
:
1374 /* These are all HOST_WIDE_INT, signed or unsigned. */
1375 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1377 case dw_val_class_loc
:
1378 return a
->v
.val_loc
== b
->v
.val_loc
;
1379 case dw_val_class_loc_list
:
1380 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1381 case dw_val_class_die_ref
:
1382 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1383 case dw_val_class_fde_ref
:
1384 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1385 case dw_val_class_lbl_id
:
1386 case dw_val_class_high_pc
:
1387 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1388 case dw_val_class_str
:
1389 return a
->v
.val_str
== b
->v
.val_str
;
1390 case dw_val_class_flag
:
1391 return a
->v
.val_flag
== b
->v
.val_flag
;
1392 case dw_val_class_file
:
1393 return a
->v
.val_file
== b
->v
.val_file
;
1394 case dw_val_class_decl_ref
:
1395 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1397 case dw_val_class_const_double
:
1398 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1399 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1401 case dw_val_class_wide_int
:
1402 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1404 case dw_val_class_vec
:
1406 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1407 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1409 return (a_len
== b_len
1410 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1413 case dw_val_class_data8
:
1414 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1416 case dw_val_class_vms_delta
:
1417 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1418 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1423 /* Compare two location atoms for exact equality. */
1426 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1428 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1431 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1432 address size, but since we always allocate cleared storage it
1433 should be zero for other types of locations. */
1434 if (a
->dtprel
!= b
->dtprel
)
1437 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1438 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1441 /* Compare two complete location expressions for exact equality. */
1444 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1450 if (a
== NULL
|| b
== NULL
)
1452 if (!loc_descr_equal_p_1 (a
, b
))
1461 /* Add a constant OFFSET to a location expression. */
1464 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1466 dw_loc_descr_ref loc
;
1469 gcc_assert (*list_head
!= NULL
);
1474 /* Find the end of the chain. */
1475 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1479 if (loc
->dw_loc_opc
== DW_OP_fbreg
1480 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1481 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1482 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1483 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1485 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1486 offset. Don't optimize if an signed integer overflow would happen. */
1488 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1489 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1492 else if (offset
> 0)
1493 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1497 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1498 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1502 /* Add a constant OFFSET to a location list. */
1505 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1508 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1509 loc_descr_plus_const (&d
->expr
, offset
);
1512 #define DWARF_REF_SIZE \
1513 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1515 static unsigned long int get_base_type_offset (dw_die_ref
);
1517 /* Return the size of a location descriptor. */
1519 static unsigned long
1520 size_of_loc_descr (dw_loc_descr_ref loc
)
1522 unsigned long size
= 1;
1524 switch (loc
->dw_loc_opc
)
1527 size
+= DWARF2_ADDR_SIZE
;
1529 case DW_OP_GNU_addr_index
:
1530 case DW_OP_GNU_const_index
:
1531 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1532 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1551 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1554 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1559 case DW_OP_plus_uconst
:
1560 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1598 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1601 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1604 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1607 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1608 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1611 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1613 case DW_OP_bit_piece
:
1614 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1615 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1617 case DW_OP_deref_size
:
1618 case DW_OP_xderef_size
:
1627 case DW_OP_call_ref
:
1628 size
+= DWARF_REF_SIZE
;
1630 case DW_OP_implicit_value
:
1631 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1632 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1634 case DW_OP_GNU_implicit_pointer
:
1635 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1637 case DW_OP_GNU_entry_value
:
1639 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1640 size
+= size_of_uleb128 (op_size
) + op_size
;
1643 case DW_OP_GNU_const_type
:
1646 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1647 size
+= size_of_uleb128 (o
) + 1;
1648 switch (loc
->dw_loc_oprnd2
.val_class
)
1650 case dw_val_class_vec
:
1651 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1652 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1654 case dw_val_class_const
:
1655 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1657 case dw_val_class_const_double
:
1658 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1660 case dw_val_class_wide_int
:
1661 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1662 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1669 case DW_OP_GNU_regval_type
:
1672 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1673 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1674 + size_of_uleb128 (o
);
1677 case DW_OP_GNU_deref_type
:
1680 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1681 size
+= 1 + size_of_uleb128 (o
);
1684 case DW_OP_GNU_convert
:
1685 case DW_OP_GNU_reinterpret
:
1686 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1687 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1691 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1692 size
+= size_of_uleb128 (o
);
1695 case DW_OP_GNU_parameter_ref
:
1705 /* Return the size of a series of location descriptors. */
1708 size_of_locs (dw_loc_descr_ref loc
)
1713 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1714 field, to avoid writing to a PCH file. */
1715 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1717 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1719 size
+= size_of_loc_descr (l
);
1724 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1726 l
->dw_loc_addr
= size
;
1727 size
+= size_of_loc_descr (l
);
1733 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1734 static void get_ref_die_offset_label (char *, dw_die_ref
);
1735 static unsigned long int get_ref_die_offset (dw_die_ref
);
1737 /* Output location description stack opcode's operands (if any).
1738 The for_eh_or_skip parameter controls whether register numbers are
1739 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1740 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1741 info). This should be suppressed for the cases that have not been converted
1742 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1745 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1747 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1748 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1750 switch (loc
->dw_loc_opc
)
1752 #ifdef DWARF2_DEBUGGING_INFO
1755 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1760 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1761 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1763 fputc ('\n', asm_out_file
);
1768 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1773 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1774 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1776 fputc ('\n', asm_out_file
);
1781 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1782 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1789 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1790 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1792 dw2_asm_output_data (2, offset
, NULL
);
1795 case DW_OP_implicit_value
:
1796 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1797 switch (val2
->val_class
)
1799 case dw_val_class_const
:
1800 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1802 case dw_val_class_vec
:
1804 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1805 unsigned int len
= val2
->v
.val_vec
.length
;
1809 if (elt_size
> sizeof (HOST_WIDE_INT
))
1814 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1817 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1818 "fp or vector constant word %u", i
);
1821 case dw_val_class_const_double
:
1823 unsigned HOST_WIDE_INT first
, second
;
1825 if (WORDS_BIG_ENDIAN
)
1827 first
= val2
->v
.val_double
.high
;
1828 second
= val2
->v
.val_double
.low
;
1832 first
= val2
->v
.val_double
.low
;
1833 second
= val2
->v
.val_double
.high
;
1835 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1837 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1841 case dw_val_class_wide_int
:
1844 int len
= get_full_len (*val2
->v
.val_wide
);
1845 if (WORDS_BIG_ENDIAN
)
1846 for (i
= len
; i
>= 0; --i
)
1847 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1848 val2
->v
.val_wide
->elt (i
), NULL
);
1850 for (i
= 0; i
< len
; ++i
)
1851 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1852 val2
->v
.val_wide
->elt (i
), NULL
);
1855 case dw_val_class_addr
:
1856 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1857 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1872 case DW_OP_implicit_value
:
1873 /* We currently don't make any attempt to make sure these are
1874 aligned properly like we do for the main unwind info, so
1875 don't support emitting things larger than a byte if we're
1876 only doing unwinding. */
1881 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1884 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1887 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1890 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1892 case DW_OP_plus_uconst
:
1893 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1927 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1931 unsigned r
= val1
->v
.val_unsigned
;
1932 if (for_eh_or_skip
>= 0)
1933 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1934 gcc_assert (size_of_uleb128 (r
)
1935 == size_of_uleb128 (val1
->v
.val_unsigned
));
1936 dw2_asm_output_data_uleb128 (r
, NULL
);
1940 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1944 unsigned r
= val1
->v
.val_unsigned
;
1945 if (for_eh_or_skip
>= 0)
1946 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1947 gcc_assert (size_of_uleb128 (r
)
1948 == size_of_uleb128 (val1
->v
.val_unsigned
));
1949 dw2_asm_output_data_uleb128 (r
, NULL
);
1950 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1954 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1956 case DW_OP_bit_piece
:
1957 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1958 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1960 case DW_OP_deref_size
:
1961 case DW_OP_xderef_size
:
1962 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1968 if (targetm
.asm_out
.output_dwarf_dtprel
)
1970 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1973 fputc ('\n', asm_out_file
);
1980 #ifdef DWARF2_DEBUGGING_INFO
1981 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1988 case DW_OP_GNU_addr_index
:
1989 case DW_OP_GNU_const_index
:
1990 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1991 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1992 "(index into .debug_addr)");
1995 case DW_OP_GNU_implicit_pointer
:
1997 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1998 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1999 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2000 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2001 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2002 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2006 case DW_OP_GNU_entry_value
:
2007 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2008 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2011 case DW_OP_GNU_const_type
:
2013 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2015 dw2_asm_output_data_uleb128 (o
, NULL
);
2016 switch (val2
->val_class
)
2018 case dw_val_class_const
:
2019 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2020 dw2_asm_output_data (1, l
, NULL
);
2021 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2023 case dw_val_class_vec
:
2025 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2026 unsigned int len
= val2
->v
.val_vec
.length
;
2031 dw2_asm_output_data (1, l
, NULL
);
2032 if (elt_size
> sizeof (HOST_WIDE_INT
))
2037 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2040 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2041 "fp or vector constant word %u", i
);
2044 case dw_val_class_const_double
:
2046 unsigned HOST_WIDE_INT first
, second
;
2047 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2049 dw2_asm_output_data (1, 2 * l
, NULL
);
2050 if (WORDS_BIG_ENDIAN
)
2052 first
= val2
->v
.val_double
.high
;
2053 second
= val2
->v
.val_double
.low
;
2057 first
= val2
->v
.val_double
.low
;
2058 second
= val2
->v
.val_double
.high
;
2060 dw2_asm_output_data (l
, first
, NULL
);
2061 dw2_asm_output_data (l
, second
, NULL
);
2064 case dw_val_class_wide_int
:
2067 int len
= get_full_len (*val2
->v
.val_wide
);
2068 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2070 dw2_asm_output_data (1, len
* l
, NULL
);
2071 if (WORDS_BIG_ENDIAN
)
2072 for (i
= len
; i
>= 0; --i
)
2073 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2075 for (i
= 0; i
< len
; ++i
)
2076 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2084 case DW_OP_GNU_regval_type
:
2086 unsigned r
= val1
->v
.val_unsigned
;
2087 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2089 if (for_eh_or_skip
>= 0)
2091 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2092 gcc_assert (size_of_uleb128 (r
)
2093 == size_of_uleb128 (val1
->v
.val_unsigned
));
2095 dw2_asm_output_data_uleb128 (r
, NULL
);
2096 dw2_asm_output_data_uleb128 (o
, NULL
);
2099 case DW_OP_GNU_deref_type
:
2101 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2103 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2104 dw2_asm_output_data_uleb128 (o
, NULL
);
2107 case DW_OP_GNU_convert
:
2108 case DW_OP_GNU_reinterpret
:
2109 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2110 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2113 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2115 dw2_asm_output_data_uleb128 (o
, NULL
);
2119 case DW_OP_GNU_parameter_ref
:
2122 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2123 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2124 dw2_asm_output_data (4, o
, NULL
);
2129 /* Other codes have no operands. */
2134 /* Output a sequence of location operations.
2135 The for_eh_or_skip parameter controls whether register numbers are
2136 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2137 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2138 info). This should be suppressed for the cases that have not been converted
2139 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2142 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2144 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2146 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2147 /* Output the opcode. */
2148 if (for_eh_or_skip
>= 0
2149 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2151 unsigned r
= (opc
- DW_OP_breg0
);
2152 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2153 gcc_assert (r
<= 31);
2154 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2156 else if (for_eh_or_skip
>= 0
2157 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2159 unsigned r
= (opc
- DW_OP_reg0
);
2160 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2161 gcc_assert (r
<= 31);
2162 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2165 dw2_asm_output_data (1, opc
,
2166 "%s", dwarf_stack_op_name (opc
));
2168 /* Output the operand(s) (if any). */
2169 output_loc_operands (loc
, for_eh_or_skip
);
2173 /* Output location description stack opcode's operands (if any).
2174 The output is single bytes on a line, suitable for .cfi_escape. */
2177 output_loc_operands_raw (dw_loc_descr_ref loc
)
2179 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2180 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2182 switch (loc
->dw_loc_opc
)
2185 case DW_OP_GNU_addr_index
:
2186 case DW_OP_GNU_const_index
:
2187 case DW_OP_implicit_value
:
2188 /* We cannot output addresses in .cfi_escape, only bytes. */
2194 case DW_OP_deref_size
:
2195 case DW_OP_xderef_size
:
2196 fputc (',', asm_out_file
);
2197 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2202 fputc (',', asm_out_file
);
2203 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2208 fputc (',', asm_out_file
);
2209 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2214 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2215 fputc (',', asm_out_file
);
2216 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2224 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2225 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2227 fputc (',', asm_out_file
);
2228 dw2_asm_output_data_raw (2, offset
);
2234 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2235 gcc_assert (size_of_uleb128 (r
)
2236 == size_of_uleb128 (val1
->v
.val_unsigned
));
2237 fputc (',', asm_out_file
);
2238 dw2_asm_output_data_uleb128_raw (r
);
2243 case DW_OP_plus_uconst
:
2245 fputc (',', asm_out_file
);
2246 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2249 case DW_OP_bit_piece
:
2250 fputc (',', asm_out_file
);
2251 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2252 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2289 fputc (',', asm_out_file
);
2290 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2295 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2296 gcc_assert (size_of_uleb128 (r
)
2297 == size_of_uleb128 (val1
->v
.val_unsigned
));
2298 fputc (',', asm_out_file
);
2299 dw2_asm_output_data_uleb128_raw (r
);
2300 fputc (',', asm_out_file
);
2301 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2305 case DW_OP_GNU_implicit_pointer
:
2306 case DW_OP_GNU_entry_value
:
2307 case DW_OP_GNU_const_type
:
2308 case DW_OP_GNU_regval_type
:
2309 case DW_OP_GNU_deref_type
:
2310 case DW_OP_GNU_convert
:
2311 case DW_OP_GNU_reinterpret
:
2312 case DW_OP_GNU_parameter_ref
:
2317 /* Other codes have no operands. */
2323 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2327 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2328 /* Output the opcode. */
2329 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2331 unsigned r
= (opc
- DW_OP_breg0
);
2332 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2333 gcc_assert (r
<= 31);
2334 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2336 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2338 unsigned r
= (opc
- DW_OP_reg0
);
2339 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2340 gcc_assert (r
<= 31);
2341 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2343 /* Output the opcode. */
2344 fprintf (asm_out_file
, "%#x", opc
);
2345 output_loc_operands_raw (loc
);
2347 if (!loc
->dw_loc_next
)
2349 loc
= loc
->dw_loc_next
;
2351 fputc (',', asm_out_file
);
2355 /* This function builds a dwarf location descriptor sequence from a
2356 dw_cfa_location, adding the given OFFSET to the result of the
2359 struct dw_loc_descr_struct
*
2360 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2362 struct dw_loc_descr_struct
*head
, *tmp
;
2364 offset
+= cfa
->offset
;
2368 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2369 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2370 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2371 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2372 add_loc_descr (&head
, tmp
);
2375 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2376 add_loc_descr (&head
, tmp
);
2380 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2385 /* This function builds a dwarf location descriptor sequence for
2386 the address at OFFSET from the CFA when stack is aligned to
2389 struct dw_loc_descr_struct
*
2390 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2391 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2393 struct dw_loc_descr_struct
*head
;
2394 unsigned int dwarf_fp
2395 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2397 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2398 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2400 head
= new_reg_loc_descr (dwarf_fp
, 0);
2401 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2402 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2403 loc_descr_plus_const (&head
, offset
);
2406 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2410 /* And now, the support for symbolic debugging information. */
2412 /* .debug_str support. */
2413 static int output_indirect_string (void **, void *);
2415 static void dwarf2out_init (const char *);
2416 static void dwarf2out_finish (const char *);
2417 static void dwarf2out_assembly_start (void);
2418 static void dwarf2out_define (unsigned int, const char *);
2419 static void dwarf2out_undef (unsigned int, const char *);
2420 static void dwarf2out_start_source_file (unsigned, const char *);
2421 static void dwarf2out_end_source_file (unsigned);
2422 static void dwarf2out_function_decl (tree
);
2423 static void dwarf2out_begin_block (unsigned, unsigned);
2424 static void dwarf2out_end_block (unsigned, unsigned);
2425 static bool dwarf2out_ignore_block (const_tree
);
2426 static void dwarf2out_global_decl (tree
);
2427 static void dwarf2out_type_decl (tree
, int);
2428 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2429 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2431 static void dwarf2out_abstract_function (tree
);
2432 static void dwarf2out_var_location (rtx
);
2433 static void dwarf2out_begin_function (tree
);
2434 static void dwarf2out_end_function (unsigned int);
2435 static void dwarf2out_set_name (tree
, tree
);
2437 /* The debug hooks structure. */
2439 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2443 dwarf2out_assembly_start
,
2446 dwarf2out_start_source_file
,
2447 dwarf2out_end_source_file
,
2448 dwarf2out_begin_block
,
2449 dwarf2out_end_block
,
2450 dwarf2out_ignore_block
,
2451 dwarf2out_source_line
,
2452 dwarf2out_begin_prologue
,
2453 #if VMS_DEBUGGING_INFO
2454 dwarf2out_vms_end_prologue
,
2455 dwarf2out_vms_begin_epilogue
,
2457 debug_nothing_int_charstar
,
2458 debug_nothing_int_charstar
,
2460 dwarf2out_end_epilogue
,
2461 dwarf2out_begin_function
,
2462 dwarf2out_end_function
, /* end_function */
2463 dwarf2out_function_decl
, /* function_decl */
2464 dwarf2out_global_decl
,
2465 dwarf2out_type_decl
, /* type_decl */
2466 dwarf2out_imported_module_or_decl
,
2467 debug_nothing_tree
, /* deferred_inline_function */
2468 /* The DWARF 2 backend tries to reduce debugging bloat by not
2469 emitting the abstract description of inline functions until
2470 something tries to reference them. */
2471 dwarf2out_abstract_function
, /* outlining_inline_function */
2472 debug_nothing_rtx
, /* label */
2473 debug_nothing_int
, /* handle_pch */
2474 dwarf2out_var_location
,
2475 dwarf2out_switch_text_section
,
2477 1, /* start_end_main_source_file */
2478 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2481 /* NOTE: In the comments in this file, many references are made to
2482 "Debugging Information Entries". This term is abbreviated as `DIE'
2483 throughout the remainder of this file. */
2485 /* An internal representation of the DWARF output is built, and then
2486 walked to generate the DWARF debugging info. The walk of the internal
2487 representation is done after the entire program has been compiled.
2488 The types below are used to describe the internal representation. */
2490 /* Whether to put type DIEs into their own section .debug_types instead
2491 of making them part of the .debug_info section. Only supported for
2492 Dwarf V4 or higher and the user didn't disable them through
2493 -fno-debug-types-section. It is more efficient to put them in a
2494 separate comdat sections since the linker will then be able to
2495 remove duplicates. But not all tools support .debug_types sections
2498 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2500 /* Various DIE's use offsets relative to the beginning of the
2501 .debug_info section to refer to each other. */
2503 typedef long int dw_offset
;
2505 /* Define typedefs here to avoid circular dependencies. */
2507 typedef struct dw_attr_struct
*dw_attr_ref
;
2508 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2509 typedef struct pubname_struct
*pubname_ref
;
2510 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2511 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2512 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2514 /* The entries in the line_info table more-or-less mirror the opcodes
2515 that are used in the real dwarf line table. Arrays of these entries
2516 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2519 enum dw_line_info_opcode
{
2520 /* Emit DW_LNE_set_address; the operand is the label index. */
2523 /* Emit a row to the matrix with the given line. This may be done
2524 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2528 /* Emit a DW_LNS_set_file. */
2531 /* Emit a DW_LNS_set_column. */
2534 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2537 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2538 LI_set_prologue_end
,
2539 LI_set_epilogue_begin
,
2541 /* Emit a DW_LNE_set_discriminator. */
2542 LI_set_discriminator
2545 typedef struct GTY(()) dw_line_info_struct
{
2546 enum dw_line_info_opcode opcode
;
2548 } dw_line_info_entry
;
2551 typedef struct GTY(()) dw_line_info_table_struct
{
2552 /* The label that marks the end of this section. */
2553 const char *end_label
;
2555 /* The values for the last row of the matrix, as collected in the table.
2556 These are used to minimize the changes to the next row. */
2557 unsigned int file_num
;
2558 unsigned int line_num
;
2559 unsigned int column_num
;
2564 vec
<dw_line_info_entry
, va_gc
> *entries
;
2565 } dw_line_info_table
;
2567 typedef dw_line_info_table
*dw_line_info_table_p
;
2570 /* Each DIE attribute has a field specifying the attribute kind,
2571 a link to the next attribute in the chain, and an attribute value.
2572 Attributes are typically linked below the DIE they modify. */
2574 typedef struct GTY(()) dw_attr_struct
{
2575 enum dwarf_attribute dw_attr
;
2576 dw_val_node dw_attr_val
;
2581 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2582 The children of each node form a circular list linked by
2583 die_sib. die_child points to the node *before* the "first" child node. */
2585 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2586 union die_symbol_or_type_node
2588 const char * GTY ((tag ("0"))) die_symbol
;
2589 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2591 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2592 vec
<dw_attr_node
, va_gc
> *die_attr
;
2593 dw_die_ref die_parent
;
2594 dw_die_ref die_child
;
2596 dw_die_ref die_definition
; /* ref from a specification to its definition */
2597 dw_offset die_offset
;
2598 unsigned long die_abbrev
;
2600 unsigned int decl_id
;
2601 enum dwarf_tag die_tag
;
2602 /* Die is used and must not be pruned as unused. */
2603 BOOL_BITFIELD die_perennial_p
: 1;
2604 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2605 /* Lots of spare bits. */
2609 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2610 #define FOR_EACH_CHILD(die, c, expr) do { \
2611 c = die->die_child; \
2615 } while (c != die->die_child); \
2618 /* The pubname structure */
2620 typedef struct GTY(()) pubname_struct
{
2627 struct GTY(()) dw_ranges_struct
{
2628 /* If this is positive, it's a block number, otherwise it's a
2629 bitwise-negated index into dw_ranges_by_label. */
2633 /* A structure to hold a macinfo entry. */
2635 typedef struct GTY(()) macinfo_struct
{
2637 unsigned HOST_WIDE_INT lineno
;
2643 struct GTY(()) dw_ranges_by_label_struct
{
2648 /* The comdat type node structure. */
2649 typedef struct GTY(()) comdat_type_struct
2651 dw_die_ref root_die
;
2652 dw_die_ref type_die
;
2653 dw_die_ref skeleton_die
;
2654 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2655 struct comdat_type_struct
*next
;
2659 /* The limbo die list structure. */
2660 typedef struct GTY(()) limbo_die_struct
{
2663 struct limbo_die_struct
*next
;
2667 typedef struct skeleton_chain_struct
2671 struct skeleton_chain_struct
*parent
;
2673 skeleton_chain_node
;
2675 /* Define a macro which returns nonzero for a TYPE_DECL which was
2676 implicitly generated for a type.
2678 Note that, unlike the C front-end (which generates a NULL named
2679 TYPE_DECL node for each complete tagged type, each array type,
2680 and each function type node created) the C++ front-end generates
2681 a _named_ TYPE_DECL node for each tagged type node created.
2682 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2683 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2684 front-end, but for each type, tagged or not. */
2686 #define TYPE_DECL_IS_STUB(decl) \
2687 (DECL_NAME (decl) == NULL_TREE \
2688 || (DECL_ARTIFICIAL (decl) \
2689 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2690 /* This is necessary for stub decls that \
2691 appear in nested inline functions. */ \
2692 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2693 && (decl_ultimate_origin (decl) \
2694 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2696 /* Information concerning the compilation unit's programming
2697 language, and compiler version. */
2699 /* Fixed size portion of the DWARF compilation unit header. */
2700 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2701 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2703 /* Fixed size portion of the DWARF comdat type unit header. */
2704 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2705 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2706 + DWARF_OFFSET_SIZE)
2708 /* Fixed size portion of public names info. */
2709 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2711 /* Fixed size portion of the address range info. */
2712 #define DWARF_ARANGES_HEADER_SIZE \
2713 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2714 DWARF2_ADDR_SIZE * 2) \
2715 - DWARF_INITIAL_LENGTH_SIZE)
2717 /* Size of padding portion in the address range info. It must be
2718 aligned to twice the pointer size. */
2719 #define DWARF_ARANGES_PAD_SIZE \
2720 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2721 DWARF2_ADDR_SIZE * 2) \
2722 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2724 /* Use assembler line directives if available. */
2725 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2726 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2727 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2729 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2733 /* Minimum line offset in a special line info. opcode.
2734 This value was chosen to give a reasonable range of values. */
2735 #define DWARF_LINE_BASE -10
2737 /* First special line opcode - leave room for the standard opcodes. */
2738 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2740 /* Range of line offsets in a special line info. opcode. */
2741 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2743 /* Flag that indicates the initial value of the is_stmt_start flag.
2744 In the present implementation, we do not mark any lines as
2745 the beginning of a source statement, because that information
2746 is not made available by the GCC front-end. */
2747 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2749 /* Maximum number of operations per instruction bundle. */
2750 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2751 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2754 /* This location is used by calc_die_sizes() to keep track
2755 the offset of each DIE within the .debug_info section. */
2756 static unsigned long next_die_offset
;
2758 /* Record the root of the DIE's built for the current compilation unit. */
2759 static GTY(()) dw_die_ref single_comp_unit_die
;
2761 /* A list of type DIEs that have been separated into comdat sections. */
2762 static GTY(()) comdat_type_node
*comdat_type_list
;
2764 /* A list of DIEs with a NULL parent waiting to be relocated. */
2765 static GTY(()) limbo_die_node
*limbo_die_list
;
2767 /* A list of DIEs for which we may have to generate
2768 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2769 static GTY(()) limbo_die_node
*deferred_asm_name
;
2771 /* Filenames referenced by this compilation unit. */
2772 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2774 /* A hash table of references to DIE's that describe declarations.
2775 The key is a DECL_UID() which is a unique number identifying each decl. */
2776 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2778 /* A hash table of references to DIE's that describe COMMON blocks.
2779 The key is DECL_UID() ^ die_parent. */
2780 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2782 typedef struct GTY(()) die_arg_entry_struct
{
2788 /* Node of the variable location list. */
2789 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2790 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2791 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2792 in mode of the EXPR_LIST node and first EXPR_LIST operand
2793 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2794 location or NULL for padding. For larger bitsizes,
2795 mode is 0 and first operand is a CONCAT with bitsize
2796 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2797 NULL as second operand. */
2799 const char * GTY (()) label
;
2800 struct var_loc_node
* GTY (()) next
;
2803 /* Variable location list. */
2804 struct GTY (()) var_loc_list_def
{
2805 struct var_loc_node
* GTY (()) first
;
2807 /* Pointer to the last but one or last element of the
2808 chained list. If the list is empty, both first and
2809 last are NULL, if the list contains just one node
2810 or the last node certainly is not redundant, it points
2811 to the last node, otherwise points to the last but one.
2812 Do not mark it for GC because it is marked through the chain. */
2813 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2815 /* Pointer to the last element before section switch,
2816 if NULL, either sections weren't switched or first
2817 is after section switch. */
2818 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2820 /* DECL_UID of the variable decl. */
2821 unsigned int decl_id
;
2823 typedef struct var_loc_list_def var_loc_list
;
2825 /* Call argument location list. */
2826 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2827 rtx
GTY (()) call_arg_loc_note
;
2828 const char * GTY (()) label
;
2829 tree
GTY (()) block
;
2831 rtx
GTY (()) symbol_ref
;
2832 struct call_arg_loc_node
* GTY (()) next
;
2836 /* Table of decl location linked lists. */
2837 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2839 /* Head and tail of call_arg_loc chain. */
2840 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2841 static struct call_arg_loc_node
*call_arg_loc_last
;
2843 /* Number of call sites in the current function. */
2844 static int call_site_count
= -1;
2845 /* Number of tail call sites in the current function. */
2846 static int tail_call_site_count
= -1;
2848 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2850 static vec
<dw_die_ref
> block_map
;
2852 /* A cached location list. */
2853 struct GTY (()) cached_dw_loc_list_def
{
2854 /* The DECL_UID of the decl that this entry describes. */
2855 unsigned int decl_id
;
2857 /* The cached location list. */
2858 dw_loc_list_ref loc_list
;
2860 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2862 /* Table of cached location lists. */
2863 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2865 /* A pointer to the base of a list of references to DIE's that
2866 are uniquely identified by their tag, presence/absence of
2867 children DIE's, and list of attribute/value pairs. */
2868 static GTY((length ("abbrev_die_table_allocated")))
2869 dw_die_ref
*abbrev_die_table
;
2871 /* Number of elements currently allocated for abbrev_die_table. */
2872 static GTY(()) unsigned abbrev_die_table_allocated
;
2874 /* Number of elements in type_die_table currently in use. */
2875 static GTY(()) unsigned abbrev_die_table_in_use
;
2877 /* Size (in elements) of increments by which we may expand the
2878 abbrev_die_table. */
2879 #define ABBREV_DIE_TABLE_INCREMENT 256
2881 /* A global counter for generating labels for line number data. */
2882 static unsigned int line_info_label_num
;
2884 /* The current table to which we should emit line number information
2885 for the current function. This will be set up at the beginning of
2886 assembly for the function. */
2887 static dw_line_info_table
*cur_line_info_table
;
2889 /* The two default tables of line number info. */
2890 static GTY(()) dw_line_info_table
*text_section_line_info
;
2891 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2893 /* The set of all non-default tables of line number info. */
2894 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2896 /* A flag to tell pubnames/types export if there is an info section to
2898 static bool info_section_emitted
;
2900 /* A pointer to the base of a table that contains a list of publicly
2901 accessible names. */
2902 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2904 /* A pointer to the base of a table that contains a list of publicly
2905 accessible types. */
2906 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2908 /* A pointer to the base of a table that contains a list of macro
2909 defines/undefines (and file start/end markers). */
2910 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2912 /* True if .debug_macinfo or .debug_macros section is going to be
2914 #define have_macinfo \
2915 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2916 && !macinfo_table->is_empty ())
2918 /* Array of dies for which we should generate .debug_ranges info. */
2919 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2921 /* Number of elements currently allocated for ranges_table. */
2922 static GTY(()) unsigned ranges_table_allocated
;
2924 /* Number of elements in ranges_table currently in use. */
2925 static GTY(()) unsigned ranges_table_in_use
;
2927 /* Array of pairs of labels referenced in ranges_table. */
2928 static GTY ((length ("ranges_by_label_allocated")))
2929 dw_ranges_by_label_ref ranges_by_label
;
2931 /* Number of elements currently allocated for ranges_by_label. */
2932 static GTY(()) unsigned ranges_by_label_allocated
;
2934 /* Number of elements in ranges_by_label currently in use. */
2935 static GTY(()) unsigned ranges_by_label_in_use
;
2937 /* Size (in elements) of increments by which we may expand the
2939 #define RANGES_TABLE_INCREMENT 64
2941 /* Whether we have location lists that need outputting */
2942 static GTY(()) bool have_location_lists
;
2944 /* Unique label counter. */
2945 static GTY(()) unsigned int loclabel_num
;
2947 /* Unique label counter for point-of-call tables. */
2948 static GTY(()) unsigned int poc_label_num
;
2950 /* Record whether the function being analyzed contains inlined functions. */
2951 static int current_function_has_inlines
;
2953 /* The last file entry emitted by maybe_emit_file(). */
2954 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2956 /* Number of internal labels generated by gen_internal_sym(). */
2957 static GTY(()) int label_num
;
2959 /* Cached result of previous call to lookup_filename. */
2960 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2962 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2964 /* Instances of generic types for which we need to generate debug
2965 info that describe their generic parameters and arguments. That
2966 generation needs to happen once all types are properly laid out so
2967 we do it at the end of compilation. */
2968 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2970 /* Offset from the "steady-state frame pointer" to the frame base,
2971 within the current function. */
2972 static HOST_WIDE_INT frame_pointer_fb_offset
;
2973 static bool frame_pointer_fb_offset_valid
;
2975 static vec
<dw_die_ref
> base_types
;
2977 /* Forward declarations for functions defined in this file. */
2979 static int is_pseudo_reg (const_rtx
);
2980 static tree
type_main_variant (tree
);
2981 static int is_tagged_type (const_tree
);
2982 static const char *dwarf_tag_name (unsigned);
2983 static const char *dwarf_attr_name (unsigned);
2984 static const char *dwarf_form_name (unsigned);
2985 static tree
decl_ultimate_origin (const_tree
);
2986 static tree
decl_class_context (tree
);
2987 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2988 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2989 static inline unsigned int AT_index (dw_attr_ref
);
2990 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2991 static inline unsigned AT_flag (dw_attr_ref
);
2992 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2993 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2994 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2995 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2996 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2997 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2998 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2999 unsigned int, unsigned char *);
3000 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3001 static hashval_t
debug_str_do_hash (const void *);
3002 static int debug_str_eq (const void *, const void *);
3003 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3004 static inline const char *AT_string (dw_attr_ref
);
3005 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3006 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3007 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3008 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3009 static inline int AT_ref_external (dw_attr_ref
);
3010 static inline void set_AT_ref_external (dw_attr_ref
, int);
3011 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3012 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3013 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3014 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3016 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3017 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3018 static void remove_addr_table_entry (addr_table_entry
*);
3019 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3020 static inline rtx
AT_addr (dw_attr_ref
);
3021 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3022 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3023 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3024 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3025 unsigned HOST_WIDE_INT
);
3026 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3027 unsigned long, bool);
3028 static inline const char *AT_lbl (dw_attr_ref
);
3029 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3030 static const char *get_AT_low_pc (dw_die_ref
);
3031 static const char *get_AT_hi_pc (dw_die_ref
);
3032 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3033 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3034 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3035 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3036 static bool is_cxx (void);
3037 static bool is_fortran (void);
3038 static bool is_ada (void);
3039 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3040 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3041 static void add_child_die (dw_die_ref
, dw_die_ref
);
3042 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3043 static dw_die_ref
lookup_type_die (tree
);
3044 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3045 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3046 static void equate_type_number_to_die (tree
, dw_die_ref
);
3047 static hashval_t
decl_die_table_hash (const void *);
3048 static int decl_die_table_eq (const void *, const void *);
3049 static dw_die_ref
lookup_decl_die (tree
);
3050 static hashval_t
common_block_die_table_hash (const void *);
3051 static int common_block_die_table_eq (const void *, const void *);
3052 static hashval_t
decl_loc_table_hash (const void *);
3053 static int decl_loc_table_eq (const void *, const void *);
3054 static var_loc_list
*lookup_decl_loc (const_tree
);
3055 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3056 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3057 static void print_spaces (FILE *);
3058 static void print_die (dw_die_ref
, FILE *);
3059 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3060 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3061 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3062 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3063 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3064 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3065 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3066 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3067 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3068 struct md5_ctx
*, int *);
3069 struct checksum_attributes
;
3070 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3071 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3072 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3073 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3074 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3075 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3076 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3077 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3078 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3079 static void compute_section_prefix (dw_die_ref
);
3080 static int is_type_die (dw_die_ref
);
3081 static int is_comdat_die (dw_die_ref
);
3082 static int is_symbol_die (dw_die_ref
);
3083 static inline bool is_template_instantiation (dw_die_ref
);
3084 static void assign_symbol_names (dw_die_ref
);
3085 static void break_out_includes (dw_die_ref
);
3086 static int is_declaration_die (dw_die_ref
);
3087 static int should_move_die_to_comdat (dw_die_ref
);
3088 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3089 static dw_die_ref
clone_die (dw_die_ref
);
3090 static dw_die_ref
clone_tree (dw_die_ref
);
3091 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3092 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3093 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3094 static dw_die_ref
generate_skeleton (dw_die_ref
);
3095 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3098 static void break_out_comdat_types (dw_die_ref
);
3099 static void copy_decls_for_unworthy_types (dw_die_ref
);
3101 static void add_sibling_attributes (dw_die_ref
);
3102 static void output_location_lists (dw_die_ref
);
3103 static int constant_size (unsigned HOST_WIDE_INT
);
3104 static unsigned long size_of_die (dw_die_ref
);
3105 static void calc_die_sizes (dw_die_ref
);
3106 static void calc_base_type_die_sizes (void);
3107 static void mark_dies (dw_die_ref
);
3108 static void unmark_dies (dw_die_ref
);
3109 static void unmark_all_dies (dw_die_ref
);
3110 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3111 static unsigned long size_of_aranges (void);
3112 static enum dwarf_form
value_format (dw_attr_ref
);
3113 static void output_value_format (dw_attr_ref
);
3114 static void output_abbrev_section (void);
3115 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3116 static void output_die_symbol (dw_die_ref
);
3117 static void output_die (dw_die_ref
);
3118 static void output_compilation_unit_header (void);
3119 static void output_comp_unit (dw_die_ref
, int);
3120 static void output_comdat_type_unit (comdat_type_node
*);
3121 static const char *dwarf2_name (tree
, int);
3122 static void add_pubname (tree
, dw_die_ref
);
3123 static void add_enumerator_pubname (const char *, dw_die_ref
);
3124 static void add_pubname_string (const char *, dw_die_ref
);
3125 static void add_pubtype (tree
, dw_die_ref
);
3126 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3127 static void output_aranges (unsigned long);
3128 static unsigned int add_ranges_num (int);
3129 static unsigned int add_ranges (const_tree
);
3130 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3132 static void output_ranges (void);
3133 static dw_line_info_table
*new_line_info_table (void);
3134 static void output_line_info (bool);
3135 static void output_file_names (void);
3136 static dw_die_ref
base_type_die (tree
);
3137 static int is_base_type (tree
);
3138 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3139 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3140 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3141 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3142 static int type_is_enum (const_tree
);
3143 static unsigned int dbx_reg_number (const_rtx
);
3144 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3145 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3146 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3147 enum var_init_status
);
3148 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3149 enum var_init_status
);
3150 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3151 enum var_init_status
);
3152 static int is_based_loc (const_rtx
);
3153 static int resolve_one_addr (rtx
*, void *);
3154 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3155 enum var_init_status
);
3156 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3157 enum var_init_status
);
3158 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3159 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3160 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3161 static tree
field_type (const_tree
);
3162 static unsigned int simple_type_align_in_bits (const_tree
);
3163 static unsigned int simple_decl_align_in_bits (const_tree
);
3164 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3165 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3166 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3168 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3169 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3170 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3171 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3172 static void insert_float (const_rtx
, unsigned char *);
3173 static rtx
rtl_for_decl_location (tree
);
3174 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3175 enum dwarf_attribute
);
3176 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3177 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3178 static void add_name_attribute (dw_die_ref
, const char *);
3179 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3180 static void add_comp_dir_attribute (dw_die_ref
);
3181 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3182 static void add_subscript_info (dw_die_ref
, tree
, bool);
3183 static void add_byte_size_attribute (dw_die_ref
, tree
);
3184 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3185 static void add_bit_size_attribute (dw_die_ref
, tree
);
3186 static void add_prototyped_attribute (dw_die_ref
, tree
);
3187 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3188 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3189 static void add_src_coords_attributes (dw_die_ref
, tree
);
3190 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3191 static void push_decl_scope (tree
);
3192 static void pop_decl_scope (void);
3193 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3194 static inline int local_scope_p (dw_die_ref
);
3195 static inline int class_scope_p (dw_die_ref
);
3196 static inline int class_or_namespace_scope_p (dw_die_ref
);
3197 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3198 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3199 static const char *type_tag (const_tree
);
3200 static tree
member_declared_type (const_tree
);
3202 static const char *decl_start_label (tree
);
3204 static void gen_array_type_die (tree
, dw_die_ref
);
3205 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3207 static void gen_entry_point_die (tree
, dw_die_ref
);
3209 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3210 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3211 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3212 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3213 static void gen_formal_types_die (tree
, dw_die_ref
);
3214 static void gen_subprogram_die (tree
, dw_die_ref
);
3215 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3216 static void gen_const_die (tree
, dw_die_ref
);
3217 static void gen_label_die (tree
, dw_die_ref
);
3218 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3219 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3220 static void gen_field_die (tree
, dw_die_ref
);
3221 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3222 static dw_die_ref
gen_compile_unit_die (const char *);
3223 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3224 static void gen_member_die (tree
, dw_die_ref
);
3225 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3226 enum debug_info_usage
);
3227 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3228 static void gen_typedef_die (tree
, dw_die_ref
);
3229 static void gen_type_die (tree
, dw_die_ref
);
3230 static void gen_block_die (tree
, dw_die_ref
, int);
3231 static void decls_for_scope (tree
, dw_die_ref
, int);
3232 static inline int is_redundant_typedef (const_tree
);
3233 static bool is_naming_typedef_decl (const_tree
);
3234 static inline dw_die_ref
get_context_die (tree
);
3235 static void gen_namespace_die (tree
, dw_die_ref
);
3236 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3237 static dw_die_ref
force_decl_die (tree
);
3238 static dw_die_ref
force_type_die (tree
);
3239 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3240 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3241 static struct dwarf_file_data
* lookup_filename (const char *);
3242 static void retry_incomplete_types (void);
3243 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3244 static void gen_generic_params_dies (tree
);
3245 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3246 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3247 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3248 static int file_info_cmp (const void *, const void *);
3249 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3250 const char *, const char *);
3251 static void output_loc_list (dw_loc_list_ref
);
3252 static char *gen_internal_sym (const char *);
3253 static bool want_pubnames (void);
3255 static void prune_unmark_dies (dw_die_ref
);
3256 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3257 static void prune_unused_types_mark (dw_die_ref
, int);
3258 static void prune_unused_types_walk (dw_die_ref
);
3259 static void prune_unused_types_walk_attribs (dw_die_ref
);
3260 static void prune_unused_types_prune (dw_die_ref
);
3261 static void prune_unused_types (void);
3262 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3263 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3264 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3265 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3266 const char *, const char *);
3267 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3268 static void gen_remaining_tmpl_value_param_die_attribute (void);
3269 static bool generic_type_p (tree
);
3270 static void schedule_generic_params_dies_gen (tree t
);
3271 static void gen_scheduled_generic_parms_dies (void);
3273 static const char *comp_dir_string (void);
3275 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3277 /* enum for tracking thread-local variables whose address is really an offset
3278 relative to the TLS pointer, which will need link-time relocation, but will
3279 not need relocation by the DWARF consumer. */
3287 /* Return the operator to use for an address of a variable. For dtprel_true, we
3288 use DW_OP_const*. For regular variables, which need both link-time
3289 relocation and consumer-level relocation (e.g., to account for shared objects
3290 loaded at a random address), we use DW_OP_addr*. */
3292 static inline enum dwarf_location_atom
3293 dw_addr_op (enum dtprel_bool dtprel
)
3295 if (dtprel
== dtprel_true
)
3296 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3297 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3299 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3302 /* Return a pointer to a newly allocated address location description. If
3303 dwarf_split_debug_info is true, then record the address with the appropriate
3305 static inline dw_loc_descr_ref
3306 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3308 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3310 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3311 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3312 ref
->dtprel
= dtprel
;
3313 if (dwarf_split_debug_info
)
3314 ref
->dw_loc_oprnd1
.val_entry
3315 = add_addr_table_entry (addr
,
3316 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3318 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3323 /* Section names used to hold DWARF debugging information. */
3325 #ifndef DEBUG_INFO_SECTION
3326 #define DEBUG_INFO_SECTION ".debug_info"
3328 #ifndef DEBUG_DWO_INFO_SECTION
3329 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3331 #ifndef DEBUG_ABBREV_SECTION
3332 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3334 #ifndef DEBUG_DWO_ABBREV_SECTION
3335 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3337 #ifndef DEBUG_ARANGES_SECTION
3338 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3340 #ifndef DEBUG_ADDR_SECTION
3341 #define DEBUG_ADDR_SECTION ".debug_addr"
3343 #ifndef DEBUG_NORM_MACINFO_SECTION
3344 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3346 #ifndef DEBUG_DWO_MACINFO_SECTION
3347 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3349 #ifndef DEBUG_MACINFO_SECTION
3350 #define DEBUG_MACINFO_SECTION \
3351 (!dwarf_split_debug_info \
3352 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3354 #ifndef DEBUG_NORM_MACRO_SECTION
3355 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3357 #ifndef DEBUG_DWO_MACRO_SECTION
3358 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3360 #ifndef DEBUG_MACRO_SECTION
3361 #define DEBUG_MACRO_SECTION \
3362 (!dwarf_split_debug_info \
3363 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3365 #ifndef DEBUG_LINE_SECTION
3366 #define DEBUG_LINE_SECTION ".debug_line"
3368 #ifndef DEBUG_DWO_LINE_SECTION
3369 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3371 #ifndef DEBUG_LOC_SECTION
3372 #define DEBUG_LOC_SECTION ".debug_loc"
3374 #ifndef DEBUG_DWO_LOC_SECTION
3375 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3377 #ifndef DEBUG_PUBNAMES_SECTION
3378 #define DEBUG_PUBNAMES_SECTION \
3379 ((debug_generate_pub_sections == 2) \
3380 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3382 #ifndef DEBUG_PUBTYPES_SECTION
3383 #define DEBUG_PUBTYPES_SECTION \
3384 ((debug_generate_pub_sections == 2) \
3385 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3387 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3388 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3389 #ifndef DEBUG_STR_OFFSETS_SECTION
3390 #define DEBUG_STR_OFFSETS_SECTION \
3391 (!dwarf_split_debug_info \
3392 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3394 #ifndef DEBUG_STR_DWO_SECTION
3395 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3397 #ifndef DEBUG_STR_SECTION
3398 #define DEBUG_STR_SECTION ".debug_str"
3400 #ifndef DEBUG_RANGES_SECTION
3401 #define DEBUG_RANGES_SECTION ".debug_ranges"
3404 /* Standard ELF section names for compiled code and data. */
3405 #ifndef TEXT_SECTION_NAME
3406 #define TEXT_SECTION_NAME ".text"
3409 /* Section flags for .debug_macinfo/.debug_macro section. */
3410 #define DEBUG_MACRO_SECTION_FLAGS \
3411 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3413 /* Section flags for .debug_str section. */
3414 #define DEBUG_STR_SECTION_FLAGS \
3415 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3416 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3419 /* Section flags for .debug_str.dwo section. */
3420 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3422 /* Labels we insert at beginning sections we can reference instead of
3423 the section names themselves. */
3425 #ifndef TEXT_SECTION_LABEL
3426 #define TEXT_SECTION_LABEL "Ltext"
3428 #ifndef COLD_TEXT_SECTION_LABEL
3429 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3431 #ifndef DEBUG_LINE_SECTION_LABEL
3432 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3434 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3435 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3437 #ifndef DEBUG_INFO_SECTION_LABEL
3438 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3440 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3441 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3443 #ifndef DEBUG_ABBREV_SECTION_LABEL
3444 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3446 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3447 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3449 #ifndef DEBUG_ADDR_SECTION_LABEL
3450 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3452 #ifndef DEBUG_LOC_SECTION_LABEL
3453 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3455 #ifndef DEBUG_RANGES_SECTION_LABEL
3456 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3458 #ifndef DEBUG_MACINFO_SECTION_LABEL
3459 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3461 #ifndef DEBUG_MACRO_SECTION_LABEL
3462 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3464 #define SKELETON_COMP_DIE_ABBREV 1
3465 #define SKELETON_TYPE_DIE_ABBREV 2
3467 /* Definitions of defaults for formats and names of various special
3468 (artificial) labels which may be generated within this file (when the -g
3469 options is used and DWARF2_DEBUGGING_INFO is in effect.
3470 If necessary, these may be overridden from within the tm.h file, but
3471 typically, overriding these defaults is unnecessary. */
3473 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3474 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3475 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3476 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3477 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3478 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3479 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3480 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3481 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3482 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3483 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3484 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3485 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3486 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3488 #ifndef TEXT_END_LABEL
3489 #define TEXT_END_LABEL "Letext"
3491 #ifndef COLD_END_LABEL
3492 #define COLD_END_LABEL "Letext_cold"
3494 #ifndef BLOCK_BEGIN_LABEL
3495 #define BLOCK_BEGIN_LABEL "LBB"
3497 #ifndef BLOCK_END_LABEL
3498 #define BLOCK_END_LABEL "LBE"
3500 #ifndef LINE_CODE_LABEL
3501 #define LINE_CODE_LABEL "LM"
3505 /* Return the root of the DIE's built for the current compilation unit. */
3507 comp_unit_die (void)
3509 if (!single_comp_unit_die
)
3510 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3511 return single_comp_unit_die
;
3514 /* We allow a language front-end to designate a function that is to be
3515 called to "demangle" any name before it is put into a DIE. */
3517 static const char *(*demangle_name_func
) (const char *);
3520 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3522 demangle_name_func
= func
;
3525 /* Test if rtl node points to a pseudo register. */
3528 is_pseudo_reg (const_rtx rtl
)
3530 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3531 || (GET_CODE (rtl
) == SUBREG
3532 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3535 /* Return a reference to a type, with its const and volatile qualifiers
3539 type_main_variant (tree type
)
3541 type
= TYPE_MAIN_VARIANT (type
);
3543 /* ??? There really should be only one main variant among any group of
3544 variants of a given type (and all of the MAIN_VARIANT values for all
3545 members of the group should point to that one type) but sometimes the C
3546 front-end messes this up for array types, so we work around that bug
3548 if (TREE_CODE (type
) == ARRAY_TYPE
)
3549 while (type
!= TYPE_MAIN_VARIANT (type
))
3550 type
= TYPE_MAIN_VARIANT (type
);
3555 /* Return nonzero if the given type node represents a tagged type. */
3558 is_tagged_type (const_tree type
)
3560 enum tree_code code
= TREE_CODE (type
);
3562 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3563 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3566 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3569 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3571 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3574 /* Return die_offset of a DIE reference to a base type. */
3576 static unsigned long int
3577 get_base_type_offset (dw_die_ref ref
)
3579 if (ref
->die_offset
)
3580 return ref
->die_offset
;
3581 if (comp_unit_die ()->die_abbrev
)
3583 calc_base_type_die_sizes ();
3584 gcc_assert (ref
->die_offset
);
3586 return ref
->die_offset
;
3589 /* Return die_offset of a DIE reference other than base type. */
3591 static unsigned long int
3592 get_ref_die_offset (dw_die_ref ref
)
3594 gcc_assert (ref
->die_offset
);
3595 return ref
->die_offset
;
3598 /* Convert a DIE tag into its string name. */
3601 dwarf_tag_name (unsigned int tag
)
3603 const char *name
= get_DW_TAG_name (tag
);
3608 return "DW_TAG_<unknown>";
3611 /* Convert a DWARF attribute code into its string name. */
3614 dwarf_attr_name (unsigned int attr
)
3620 #if VMS_DEBUGGING_INFO
3621 case DW_AT_HP_prologue
:
3622 return "DW_AT_HP_prologue";
3624 case DW_AT_MIPS_loop_unroll_factor
:
3625 return "DW_AT_MIPS_loop_unroll_factor";
3628 #if VMS_DEBUGGING_INFO
3629 case DW_AT_HP_epilogue
:
3630 return "DW_AT_HP_epilogue";
3632 case DW_AT_MIPS_stride
:
3633 return "DW_AT_MIPS_stride";
3637 name
= get_DW_AT_name (attr
);
3642 return "DW_AT_<unknown>";
3645 /* Convert a DWARF value form code into its string name. */
3648 dwarf_form_name (unsigned int form
)
3650 const char *name
= get_DW_FORM_name (form
);
3655 return "DW_FORM_<unknown>";
3658 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3659 instance of an inlined instance of a decl which is local to an inline
3660 function, so we have to trace all of the way back through the origin chain
3661 to find out what sort of node actually served as the original seed for the
3665 decl_ultimate_origin (const_tree decl
)
3667 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3670 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3671 nodes in the function to point to themselves; ignore that if
3672 we're trying to output the abstract instance of this function. */
3673 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3676 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3677 most distant ancestor, this should never happen. */
3678 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3680 return DECL_ABSTRACT_ORIGIN (decl
);
3683 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3684 of a virtual function may refer to a base class, so we check the 'this'
3688 decl_class_context (tree decl
)
3690 tree context
= NULL_TREE
;
3692 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3693 context
= DECL_CONTEXT (decl
);
3695 context
= TYPE_MAIN_VARIANT
3696 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3698 if (context
&& !TYPE_P (context
))
3699 context
= NULL_TREE
;
3704 /* Add an attribute/value pair to a DIE. */
3707 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3709 /* Maybe this should be an assert? */
3713 vec_safe_reserve (die
->die_attr
, 1);
3714 vec_safe_push (die
->die_attr
, *attr
);
3717 static inline enum dw_val_class
3718 AT_class (dw_attr_ref a
)
3720 return a
->dw_attr_val
.val_class
;
3723 /* Return the index for any attribute that will be referenced with a
3724 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3725 are stored in dw_attr_val.v.val_str for reference counting
3728 static inline unsigned int
3729 AT_index (dw_attr_ref a
)
3731 if (AT_class (a
) == dw_val_class_str
)
3732 return a
->dw_attr_val
.v
.val_str
->index
;
3733 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3734 return a
->dw_attr_val
.val_entry
->index
;
3738 /* Add a flag value attribute to a DIE. */
3741 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3745 attr
.dw_attr
= attr_kind
;
3746 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3747 attr
.dw_attr_val
.val_entry
= NULL
;
3748 attr
.dw_attr_val
.v
.val_flag
= flag
;
3749 add_dwarf_attr (die
, &attr
);
3752 static inline unsigned
3753 AT_flag (dw_attr_ref a
)
3755 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3756 return a
->dw_attr_val
.v
.val_flag
;
3759 /* Add a signed integer attribute value to a DIE. */
3762 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3766 attr
.dw_attr
= attr_kind
;
3767 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3768 attr
.dw_attr_val
.val_entry
= NULL
;
3769 attr
.dw_attr_val
.v
.val_int
= int_val
;
3770 add_dwarf_attr (die
, &attr
);
3773 static inline HOST_WIDE_INT
3774 AT_int (dw_attr_ref a
)
3776 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3777 return a
->dw_attr_val
.v
.val_int
;
3780 /* Add an unsigned integer attribute value to a DIE. */
3783 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3784 unsigned HOST_WIDE_INT unsigned_val
)
3788 attr
.dw_attr
= attr_kind
;
3789 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3790 attr
.dw_attr_val
.val_entry
= NULL
;
3791 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3792 add_dwarf_attr (die
, &attr
);
3795 static inline unsigned HOST_WIDE_INT
3796 AT_unsigned (dw_attr_ref a
)
3798 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3799 return a
->dw_attr_val
.v
.val_unsigned
;
3802 /* Add an unsigned wide integer attribute value to a DIE. */
3805 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3810 attr
.dw_attr
= attr_kind
;
3811 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3812 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc_cleared_wide_int ();
3813 *attr
.dw_attr_val
.v
.val_wide
= w
;
3814 add_dwarf_attr (die
, &attr
);
3817 /* Add an unsigned double integer attribute value to a DIE. */
3820 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3821 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3825 attr
.dw_attr
= attr_kind
;
3826 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3827 attr
.dw_attr_val
.val_entry
= NULL
;
3828 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3829 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3830 add_dwarf_attr (die
, &attr
);
3833 /* Add a floating point attribute value to a DIE and return it. */
3836 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3837 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3841 attr
.dw_attr
= attr_kind
;
3842 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3843 attr
.dw_attr_val
.val_entry
= NULL
;
3844 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3845 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3846 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3847 add_dwarf_attr (die
, &attr
);
3850 /* Add an 8-byte data attribute value to a DIE. */
3853 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3854 unsigned char data8
[8])
3858 attr
.dw_attr
= attr_kind
;
3859 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3860 attr
.dw_attr_val
.val_entry
= NULL
;
3861 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3862 add_dwarf_attr (die
, &attr
);
3865 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3866 dwarf_split_debug_info, address attributes in dies destined for the
3867 final executable have force_direct set to avoid using indexed
3871 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3877 lbl_id
= xstrdup (lbl_low
);
3878 attr
.dw_attr
= DW_AT_low_pc
;
3879 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3880 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3881 if (dwarf_split_debug_info
&& !force_direct
)
3882 attr
.dw_attr_val
.val_entry
3883 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3885 attr
.dw_attr_val
.val_entry
= NULL
;
3886 add_dwarf_attr (die
, &attr
);
3888 attr
.dw_attr
= DW_AT_high_pc
;
3889 if (dwarf_version
< 4)
3890 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3892 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3893 lbl_id
= xstrdup (lbl_high
);
3894 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3895 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3896 && dwarf_split_debug_info
&& !force_direct
)
3897 attr
.dw_attr_val
.val_entry
3898 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3900 attr
.dw_attr_val
.val_entry
= NULL
;
3901 add_dwarf_attr (die
, &attr
);
3904 /* Hash and equality functions for debug_str_hash. */
3907 debug_str_do_hash (const void *x
)
3909 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3913 debug_str_eq (const void *x1
, const void *x2
)
3915 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3916 (const char *)x2
) == 0;
3919 /* Add STR to the given string hash table. */
3921 static struct indirect_string_node
*
3922 find_AT_string_in_table (const char *str
, htab_t table
)
3924 struct indirect_string_node
*node
;
3927 slot
= htab_find_slot_with_hash (table
, str
,
3928 htab_hash_string (str
), INSERT
);
3931 node
= ggc_alloc_cleared_indirect_string_node ();
3932 node
->str
= ggc_strdup (str
);
3936 node
= (struct indirect_string_node
*) *slot
;
3942 /* Add STR to the indirect string hash table. */
3944 static struct indirect_string_node
*
3945 find_AT_string (const char *str
)
3947 if (! debug_str_hash
)
3948 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3949 debug_str_eq
, NULL
);
3951 return find_AT_string_in_table (str
, debug_str_hash
);
3954 /* Add a string attribute value to a DIE. */
3957 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3960 struct indirect_string_node
*node
;
3962 node
= find_AT_string (str
);
3964 attr
.dw_attr
= attr_kind
;
3965 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3966 attr
.dw_attr_val
.val_entry
= NULL
;
3967 attr
.dw_attr_val
.v
.val_str
= node
;
3968 add_dwarf_attr (die
, &attr
);
3971 static inline const char *
3972 AT_string (dw_attr_ref a
)
3974 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3975 return a
->dw_attr_val
.v
.val_str
->str
;
3978 /* Call this function directly to bypass AT_string_form's logic to put
3979 the string inline in the die. */
3982 set_indirect_string (struct indirect_string_node
*node
)
3985 /* Already indirect is a no op. */
3986 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3988 gcc_assert (node
->label
);
3991 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3992 ++dw2_string_counter
;
3993 node
->label
= xstrdup (label
);
3995 if (!dwarf_split_debug_info
)
3997 node
->form
= DW_FORM_strp
;
3998 node
->index
= NOT_INDEXED
;
4002 node
->form
= DW_FORM_GNU_str_index
;
4003 node
->index
= NO_INDEX_ASSIGNED
;
4007 /* Find out whether a string should be output inline in DIE
4008 or out-of-line in .debug_str section. */
4010 static enum dwarf_form
4011 find_string_form (struct indirect_string_node
*node
)
4018 len
= strlen (node
->str
) + 1;
4020 /* If the string is shorter or equal to the size of the reference, it is
4021 always better to put it inline. */
4022 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4023 return node
->form
= DW_FORM_string
;
4025 /* If we cannot expect the linker to merge strings in .debug_str
4026 section, only put it into .debug_str if it is worth even in this
4028 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4029 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4030 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4031 return node
->form
= DW_FORM_string
;
4033 set_indirect_string (node
);
4038 /* Find out whether the string referenced from the attribute should be
4039 output inline in DIE or out-of-line in .debug_str section. */
4041 static enum dwarf_form
4042 AT_string_form (dw_attr_ref a
)
4044 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4045 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4048 /* Add a DIE reference attribute value to a DIE. */
4051 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4055 #ifdef ENABLE_CHECKING
4056 gcc_assert (targ_die
!= NULL
);
4058 /* With LTO we can end up trying to reference something we didn't create
4059 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4060 if (targ_die
== NULL
)
4064 attr
.dw_attr
= attr_kind
;
4065 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4066 attr
.dw_attr_val
.val_entry
= NULL
;
4067 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4068 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4069 add_dwarf_attr (die
, &attr
);
4072 /* Change DIE reference REF to point to NEW_DIE instead. */
4075 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4077 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4078 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4079 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4082 /* Add an AT_specification attribute to a DIE, and also make the back
4083 pointer from the specification to the definition. */
4086 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4088 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4089 gcc_assert (!targ_die
->die_definition
);
4090 targ_die
->die_definition
= die
;
4093 static inline dw_die_ref
4094 AT_ref (dw_attr_ref a
)
4096 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4097 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4101 AT_ref_external (dw_attr_ref a
)
4103 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4104 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4110 set_AT_ref_external (dw_attr_ref a
, int i
)
4112 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4113 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4116 /* Add an FDE reference attribute value to a DIE. */
4119 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4123 attr
.dw_attr
= attr_kind
;
4124 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4125 attr
.dw_attr_val
.val_entry
= NULL
;
4126 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4127 add_dwarf_attr (die
, &attr
);
4130 /* Add a location description attribute value to a DIE. */
4133 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4137 attr
.dw_attr
= attr_kind
;
4138 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4139 attr
.dw_attr_val
.val_entry
= NULL
;
4140 attr
.dw_attr_val
.v
.val_loc
= loc
;
4141 add_dwarf_attr (die
, &attr
);
4144 static inline dw_loc_descr_ref
4145 AT_loc (dw_attr_ref a
)
4147 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4148 return a
->dw_attr_val
.v
.val_loc
;
4152 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4156 attr
.dw_attr
= attr_kind
;
4157 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4158 attr
.dw_attr_val
.val_entry
= NULL
;
4159 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4160 add_dwarf_attr (die
, &attr
);
4161 have_location_lists
= true;
4164 static inline dw_loc_list_ref
4165 AT_loc_list (dw_attr_ref a
)
4167 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4168 return a
->dw_attr_val
.v
.val_loc_list
;
4171 static inline dw_loc_list_ref
*
4172 AT_loc_list_ptr (dw_attr_ref a
)
4174 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4175 return &a
->dw_attr_val
.v
.val_loc_list
;
4178 /* Table of entries into the .debug_addr section. */
4180 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4182 /* Hash an address_table_entry. */
4185 addr_table_entry_do_hash (const void *x
)
4187 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4191 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4192 case ate_kind_rtx_dtprel
:
4193 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4194 case ate_kind_label
:
4195 return htab_hash_string (a
->addr
.label
);
4201 /* Determine equality for two address_table_entries. */
4204 addr_table_entry_eq (const void *x1
, const void *x2
)
4206 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4207 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4209 if (a1
->kind
!= a2
->kind
)
4214 case ate_kind_rtx_dtprel
:
4215 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4216 case ate_kind_label
:
4217 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4223 /* Initialize an addr_table_entry. */
4226 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4232 case ate_kind_rtx_dtprel
:
4233 e
->addr
.rtl
= (rtx
) addr
;
4235 case ate_kind_label
:
4236 e
->addr
.label
= (char *) addr
;
4240 e
->index
= NO_INDEX_ASSIGNED
;
4243 /* Add attr to the address table entry to the table. Defer setting an
4244 index until output time. */
4246 static addr_table_entry
*
4247 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4249 addr_table_entry
*node
;
4250 addr_table_entry finder
;
4253 gcc_assert (dwarf_split_debug_info
);
4254 if (! addr_index_table
)
4255 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4256 addr_table_entry_eq
, NULL
);
4257 init_addr_table_entry (&finder
, kind
, addr
);
4258 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4260 if (*slot
== HTAB_EMPTY_ENTRY
)
4262 node
= ggc_alloc_cleared_addr_table_entry ();
4263 init_addr_table_entry (node
, kind
, addr
);
4267 node
= (addr_table_entry
*) *slot
;
4273 /* Remove an entry from the addr table by decrementing its refcount.
4274 Strictly, decrementing the refcount would be enough, but the
4275 assertion that the entry is actually in the table has found
4279 remove_addr_table_entry (addr_table_entry
*entry
)
4281 addr_table_entry
*node
;
4283 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4284 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4285 /* After an index is assigned, the table is frozen. */
4286 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4290 /* Given a location list, remove all addresses it refers to from the
4294 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4296 for (; descr
; descr
= descr
->dw_loc_next
)
4297 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4299 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4300 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4304 /* A helper function for dwarf2out_finish called through
4305 htab_traverse. Assign an addr_table_entry its index. All entries
4306 must be collected into the table when this function is called,
4307 because the indexing code relies on htab_traverse to traverse nodes
4308 in the same order for each run. */
4311 index_addr_table_entry (void **h
, void *v
)
4313 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4314 unsigned int *index
= (unsigned int *) v
;
4316 /* Don't index unreferenced nodes. */
4317 if (node
->refcount
== 0)
4320 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4321 node
->index
= *index
;
4327 /* Add an address constant attribute value to a DIE. When using
4328 dwarf_split_debug_info, address attributes in dies destined for the
4329 final executable should be direct references--setting the parameter
4330 force_direct ensures this behavior. */
4333 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4338 attr
.dw_attr
= attr_kind
;
4339 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4340 attr
.dw_attr_val
.v
.val_addr
= addr
;
4341 if (dwarf_split_debug_info
&& !force_direct
)
4342 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4344 attr
.dw_attr_val
.val_entry
= NULL
;
4345 add_dwarf_attr (die
, &attr
);
4348 /* Get the RTX from to an address DIE attribute. */
4351 AT_addr (dw_attr_ref a
)
4353 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4354 return a
->dw_attr_val
.v
.val_addr
;
4357 /* Add a file attribute value to a DIE. */
4360 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4361 struct dwarf_file_data
*fd
)
4365 attr
.dw_attr
= attr_kind
;
4366 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4367 attr
.dw_attr_val
.val_entry
= NULL
;
4368 attr
.dw_attr_val
.v
.val_file
= fd
;
4369 add_dwarf_attr (die
, &attr
);
4372 /* Get the dwarf_file_data from a file DIE attribute. */
4374 static inline struct dwarf_file_data
*
4375 AT_file (dw_attr_ref a
)
4377 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4378 return a
->dw_attr_val
.v
.val_file
;
4381 /* Add a vms delta attribute value to a DIE. */
4384 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4385 const char *lbl1
, const char *lbl2
)
4389 attr
.dw_attr
= attr_kind
;
4390 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4391 attr
.dw_attr_val
.val_entry
= NULL
;
4392 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4393 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4394 add_dwarf_attr (die
, &attr
);
4397 /* Add a label identifier attribute value to a DIE. */
4400 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4405 attr
.dw_attr
= attr_kind
;
4406 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4407 attr
.dw_attr_val
.val_entry
= NULL
;
4408 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4409 if (dwarf_split_debug_info
)
4410 attr
.dw_attr_val
.val_entry
4411 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4413 add_dwarf_attr (die
, &attr
);
4416 /* Add a section offset attribute value to a DIE, an offset into the
4417 debug_line section. */
4420 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4425 attr
.dw_attr
= attr_kind
;
4426 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4427 attr
.dw_attr_val
.val_entry
= NULL
;
4428 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4429 add_dwarf_attr (die
, &attr
);
4432 /* Add a section offset attribute value to a DIE, an offset into the
4433 debug_macinfo section. */
4436 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4441 attr
.dw_attr
= attr_kind
;
4442 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4443 attr
.dw_attr_val
.val_entry
= NULL
;
4444 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4445 add_dwarf_attr (die
, &attr
);
4448 /* Add an offset attribute value to a DIE. */
4451 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4452 unsigned HOST_WIDE_INT offset
)
4456 attr
.dw_attr
= attr_kind
;
4457 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4458 attr
.dw_attr_val
.val_entry
= NULL
;
4459 attr
.dw_attr_val
.v
.val_offset
= offset
;
4460 add_dwarf_attr (die
, &attr
);
4463 /* Add a range_list attribute value to a DIE. When using
4464 dwarf_split_debug_info, address attributes in dies destined for the
4465 final executable should be direct references--setting the parameter
4466 force_direct ensures this behavior. */
4468 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4469 #define RELOCATED_OFFSET (NULL)
4472 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4473 long unsigned int offset
, bool force_direct
)
4477 attr
.dw_attr
= attr_kind
;
4478 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4479 /* For the range_list attribute, use val_entry to store whether the
4480 offset should follow split-debug-info or normal semantics. This
4481 value is read in output_range_list_offset. */
4482 if (dwarf_split_debug_info
&& !force_direct
)
4483 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4485 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4486 attr
.dw_attr_val
.v
.val_offset
= offset
;
4487 add_dwarf_attr (die
, &attr
);
4490 /* Return the start label of a delta attribute. */
4492 static inline const char *
4493 AT_vms_delta1 (dw_attr_ref a
)
4495 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4496 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4499 /* Return the end label of a delta attribute. */
4501 static inline const char *
4502 AT_vms_delta2 (dw_attr_ref a
)
4504 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4505 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4508 static inline const char *
4509 AT_lbl (dw_attr_ref a
)
4511 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4512 || AT_class (a
) == dw_val_class_lineptr
4513 || AT_class (a
) == dw_val_class_macptr
4514 || AT_class (a
) == dw_val_class_high_pc
));
4515 return a
->dw_attr_val
.v
.val_lbl_id
;
4518 /* Get the attribute of type attr_kind. */
4521 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4525 dw_die_ref spec
= NULL
;
4530 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4531 if (a
->dw_attr
== attr_kind
)
4533 else if (a
->dw_attr
== DW_AT_specification
4534 || a
->dw_attr
== DW_AT_abstract_origin
)
4538 return get_AT (spec
, attr_kind
);
4543 /* Returns the parent of the declaration of DIE. */
4546 get_die_parent (dw_die_ref die
)
4553 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4554 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4557 return die
->die_parent
;
4560 /* Return the "low pc" attribute value, typically associated with a subprogram
4561 DIE. Return null if the "low pc" attribute is either not present, or if it
4562 cannot be represented as an assembler label identifier. */
4564 static inline const char *
4565 get_AT_low_pc (dw_die_ref die
)
4567 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4569 return a
? AT_lbl (a
) : NULL
;
4572 /* Return the "high pc" attribute value, typically associated with a subprogram
4573 DIE. Return null if the "high pc" attribute is either not present, or if it
4574 cannot be represented as an assembler label identifier. */
4576 static inline const char *
4577 get_AT_hi_pc (dw_die_ref die
)
4579 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4581 return a
? AT_lbl (a
) : NULL
;
4584 /* Return the value of the string attribute designated by ATTR_KIND, or
4585 NULL if it is not present. */
4587 static inline const char *
4588 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4590 dw_attr_ref a
= get_AT (die
, attr_kind
);
4592 return a
? AT_string (a
) : NULL
;
4595 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4596 if it is not present. */
4599 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4601 dw_attr_ref a
= get_AT (die
, attr_kind
);
4603 return a
? AT_flag (a
) : 0;
4606 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4607 if it is not present. */
4609 static inline unsigned
4610 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4612 dw_attr_ref a
= get_AT (die
, attr_kind
);
4614 return a
? AT_unsigned (a
) : 0;
4617 static inline dw_die_ref
4618 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4620 dw_attr_ref a
= get_AT (die
, attr_kind
);
4622 return a
? AT_ref (a
) : NULL
;
4625 static inline struct dwarf_file_data
*
4626 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4628 dw_attr_ref a
= get_AT (die
, attr_kind
);
4630 return a
? AT_file (a
) : NULL
;
4633 /* Return TRUE if the language is C++. */
4638 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4640 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4643 /* Return TRUE if the language is Java. */
4648 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4650 return lang
== DW_LANG_Java
;
4653 /* Return TRUE if the language is Fortran. */
4658 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4660 return (lang
== DW_LANG_Fortran77
4661 || lang
== DW_LANG_Fortran90
4662 || lang
== DW_LANG_Fortran95
);
4665 /* Return TRUE if the language is Ada. */
4670 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4672 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4675 /* Remove the specified attribute if present. */
4678 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4686 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4687 if (a
->dw_attr
== attr_kind
)
4689 if (AT_class (a
) == dw_val_class_str
)
4690 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4691 a
->dw_attr_val
.v
.val_str
->refcount
--;
4693 /* vec::ordered_remove should help reduce the number of abbrevs
4695 die
->die_attr
->ordered_remove (ix
);
4700 /* Remove CHILD from its parent. PREV must have the property that
4701 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4704 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4706 gcc_assert (child
->die_parent
== prev
->die_parent
);
4707 gcc_assert (prev
->die_sib
== child
);
4710 gcc_assert (child
->die_parent
->die_child
== child
);
4714 prev
->die_sib
= child
->die_sib
;
4715 if (child
->die_parent
->die_child
== child
)
4716 child
->die_parent
->die_child
= prev
;
4719 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4720 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4723 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4725 dw_die_ref parent
= old_child
->die_parent
;
4727 gcc_assert (parent
== prev
->die_parent
);
4728 gcc_assert (prev
->die_sib
== old_child
);
4730 new_child
->die_parent
= parent
;
4731 if (prev
== old_child
)
4733 gcc_assert (parent
->die_child
== old_child
);
4734 new_child
->die_sib
= new_child
;
4738 prev
->die_sib
= new_child
;
4739 new_child
->die_sib
= old_child
->die_sib
;
4741 if (old_child
->die_parent
->die_child
== old_child
)
4742 old_child
->die_parent
->die_child
= new_child
;
4745 /* Move all children from OLD_PARENT to NEW_PARENT. */
4748 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4751 new_parent
->die_child
= old_parent
->die_child
;
4752 old_parent
->die_child
= NULL
;
4753 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4756 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4760 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4766 dw_die_ref prev
= c
;
4768 while (c
->die_tag
== tag
)
4770 remove_child_with_prev (c
, prev
);
4771 /* Might have removed every child. */
4772 if (c
== c
->die_sib
)
4776 } while (c
!= die
->die_child
);
4779 /* Add a CHILD_DIE as the last child of DIE. */
4782 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4784 /* FIXME this should probably be an assert. */
4785 if (! die
|| ! child_die
)
4787 gcc_assert (die
!= child_die
);
4789 child_die
->die_parent
= die
;
4792 child_die
->die_sib
= die
->die_child
->die_sib
;
4793 die
->die_child
->die_sib
= child_die
;
4796 child_die
->die_sib
= child_die
;
4797 die
->die_child
= child_die
;
4800 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4801 is the specification, to the end of PARENT's list of children.
4802 This is done by removing and re-adding it. */
4805 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4809 /* We want the declaration DIE from inside the class, not the
4810 specification DIE at toplevel. */
4811 if (child
->die_parent
!= parent
)
4813 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4819 gcc_assert (child
->die_parent
== parent
4820 || (child
->die_parent
4821 == get_AT_ref (parent
, DW_AT_specification
)));
4823 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4824 if (p
->die_sib
== child
)
4826 remove_child_with_prev (child
, p
);
4830 add_child_die (parent
, child
);
4833 /* Return a pointer to a newly created DIE node. */
4835 static inline dw_die_ref
4836 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4838 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4840 die
->die_tag
= tag_value
;
4842 if (parent_die
!= NULL
)
4843 add_child_die (parent_die
, die
);
4846 limbo_die_node
*limbo_node
;
4848 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4849 limbo_node
->die
= die
;
4850 limbo_node
->created_for
= t
;
4851 limbo_node
->next
= limbo_die_list
;
4852 limbo_die_list
= limbo_node
;
4858 /* Return the DIE associated with the given type specifier. */
4860 static inline dw_die_ref
4861 lookup_type_die (tree type
)
4863 return TYPE_SYMTAB_DIE (type
);
4866 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4867 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4868 anonymous type instead the one of the naming typedef. */
4870 static inline dw_die_ref
4871 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4874 && TREE_CODE (type
) == RECORD_TYPE
4876 && type_die
->die_tag
== DW_TAG_typedef
4877 && is_naming_typedef_decl (TYPE_NAME (type
)))
4878 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4882 /* Like lookup_type_die, but if type is an anonymous type named by a
4883 typedef[1], return the DIE of the anonymous type instead the one of
4884 the naming typedef. This is because in gen_typedef_die, we did
4885 equate the anonymous struct named by the typedef with the DIE of
4886 the naming typedef. So by default, lookup_type_die on an anonymous
4887 struct yields the DIE of the naming typedef.
4889 [1]: Read the comment of is_naming_typedef_decl to learn about what
4890 a naming typedef is. */
4892 static inline dw_die_ref
4893 lookup_type_die_strip_naming_typedef (tree type
)
4895 dw_die_ref die
= lookup_type_die (type
);
4896 return strip_naming_typedef (type
, die
);
4899 /* Equate a DIE to a given type specifier. */
4902 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4904 TYPE_SYMTAB_DIE (type
) = type_die
;
4907 /* Returns a hash value for X (which really is a die_struct). */
4910 decl_die_table_hash (const void *x
)
4912 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4915 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4918 decl_die_table_eq (const void *x
, const void *y
)
4920 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4923 /* Return the DIE associated with a given declaration. */
4925 static inline dw_die_ref
4926 lookup_decl_die (tree decl
)
4928 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4931 /* Returns a hash value for X (which really is a var_loc_list). */
4934 decl_loc_table_hash (const void *x
)
4936 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4939 /* Return nonzero if decl_id of var_loc_list X is the same as
4943 decl_loc_table_eq (const void *x
, const void *y
)
4945 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4948 /* Return the var_loc list associated with a given declaration. */
4950 static inline var_loc_list
*
4951 lookup_decl_loc (const_tree decl
)
4953 if (!decl_loc_table
)
4955 return (var_loc_list
*)
4956 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4959 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4962 cached_dw_loc_list_table_hash (const void *x
)
4964 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4967 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4971 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4973 return (((const cached_dw_loc_list
*) x
)->decl_id
4974 == DECL_UID ((const_tree
) y
));
4977 /* Equate a DIE to a particular declaration. */
4980 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4982 unsigned int decl_id
= DECL_UID (decl
);
4985 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4987 decl_die
->decl_id
= decl_id
;
4990 /* Return how many bits covers PIECE EXPR_LIST. */
4993 decl_piece_bitsize (rtx piece
)
4995 int ret
= (int) GET_MODE (piece
);
4998 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4999 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5000 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5003 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5006 decl_piece_varloc_ptr (rtx piece
)
5008 if ((int) GET_MODE (piece
))
5009 return &XEXP (piece
, 0);
5011 return &XEXP (XEXP (piece
, 0), 1);
5014 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5015 Next is the chain of following piece nodes. */
5018 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5020 if (bitsize
<= (int) MAX_MACHINE_MODE
)
5021 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5023 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5028 /* Return rtx that should be stored into loc field for
5029 LOC_NOTE and BITPOS/BITSIZE. */
5032 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5033 HOST_WIDE_INT bitsize
)
5037 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5039 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5044 /* This function either modifies location piece list *DEST in
5045 place (if SRC and INNER is NULL), or copies location piece list
5046 *SRC to *DEST while modifying it. Location BITPOS is modified
5047 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5048 not copied and if needed some padding around it is added.
5049 When modifying in place, DEST should point to EXPR_LIST where
5050 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5051 to the start of the whole list and INNER points to the EXPR_LIST
5052 where earlier pieces cover PIECE_BITPOS bits. */
5055 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5056 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5057 HOST_WIDE_INT bitsize
, rtx loc_note
)
5060 bool copy
= inner
!= NULL
;
5064 /* First copy all nodes preceding the current bitpos. */
5065 while (src
!= inner
)
5067 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5068 decl_piece_bitsize (*src
), NULL_RTX
);
5069 dest
= &XEXP (*dest
, 1);
5070 src
= &XEXP (*src
, 1);
5073 /* Add padding if needed. */
5074 if (bitpos
!= piece_bitpos
)
5076 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5077 copy
? NULL_RTX
: *dest
);
5078 dest
= &XEXP (*dest
, 1);
5080 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5083 /* A piece with correct bitpos and bitsize already exist,
5084 just update the location for it and return. */
5085 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5088 /* Add the piece that changed. */
5089 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5090 dest
= &XEXP (*dest
, 1);
5091 /* Skip over pieces that overlap it. */
5092 diff
= bitpos
- piece_bitpos
+ bitsize
;
5095 while (diff
> 0 && *src
)
5098 diff
-= decl_piece_bitsize (piece
);
5100 src
= &XEXP (piece
, 1);
5103 *src
= XEXP (piece
, 1);
5104 free_EXPR_LIST_node (piece
);
5107 /* Add padding if needed. */
5108 if (diff
< 0 && *src
)
5112 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5113 dest
= &XEXP (*dest
, 1);
5117 /* Finally copy all nodes following it. */
5120 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5121 decl_piece_bitsize (*src
), NULL_RTX
);
5122 dest
= &XEXP (*dest
, 1);
5123 src
= &XEXP (*src
, 1);
5127 /* Add a variable location node to the linked list for DECL. */
5129 static struct var_loc_node
*
5130 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5132 unsigned int decl_id
;
5135 struct var_loc_node
*loc
= NULL
;
5136 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5138 if (TREE_CODE (decl
) == VAR_DECL
5139 && DECL_HAS_DEBUG_EXPR_P (decl
))
5141 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5142 if (handled_component_p (realdecl
)
5143 || (TREE_CODE (realdecl
) == MEM_REF
5144 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5146 HOST_WIDE_INT maxsize
;
5149 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5150 if (!DECL_P (innerdecl
)
5151 || DECL_IGNORED_P (innerdecl
)
5152 || TREE_STATIC (innerdecl
)
5154 || bitpos
+ bitsize
> 256
5155 || bitsize
!= maxsize
)
5161 decl_id
= DECL_UID (decl
);
5162 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5165 temp
= ggc_alloc_cleared_var_loc_list ();
5166 temp
->decl_id
= decl_id
;
5170 temp
= (var_loc_list
*) *slot
;
5172 /* For PARM_DECLs try to keep around the original incoming value,
5173 even if that means we'll emit a zero-range .debug_loc entry. */
5175 && temp
->first
== temp
->last
5176 && TREE_CODE (decl
) == PARM_DECL
5177 && NOTE_P (temp
->first
->loc
)
5178 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5179 && DECL_INCOMING_RTL (decl
)
5180 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5181 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5182 == GET_CODE (DECL_INCOMING_RTL (decl
))
5183 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5185 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5186 NOTE_VAR_LOCATION_LOC (loc_note
))
5187 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5188 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5190 loc
= ggc_alloc_cleared_var_loc_node ();
5191 temp
->first
->next
= loc
;
5193 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5195 else if (temp
->last
)
5197 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5198 rtx
*piece_loc
= NULL
, last_loc_note
;
5199 int piece_bitpos
= 0;
5203 gcc_assert (last
->next
== NULL
);
5205 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5207 piece_loc
= &last
->loc
;
5210 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5211 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5213 piece_bitpos
+= cur_bitsize
;
5214 piece_loc
= &XEXP (*piece_loc
, 1);
5218 /* TEMP->LAST here is either pointer to the last but one or
5219 last element in the chained list, LAST is pointer to the
5221 if (label
&& strcmp (last
->label
, label
) == 0)
5223 /* For SRA optimized variables if there weren't any real
5224 insns since last note, just modify the last node. */
5225 if (piece_loc
!= NULL
)
5227 adjust_piece_list (piece_loc
, NULL
, NULL
,
5228 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5231 /* If the last note doesn't cover any instructions, remove it. */
5232 if (temp
->last
!= last
)
5234 temp
->last
->next
= NULL
;
5237 gcc_assert (strcmp (last
->label
, label
) != 0);
5241 gcc_assert (temp
->first
== temp
->last
5242 || (temp
->first
->next
== temp
->last
5243 && TREE_CODE (decl
) == PARM_DECL
));
5244 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5245 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5249 if (bitsize
== -1 && NOTE_P (last
->loc
))
5250 last_loc_note
= last
->loc
;
5251 else if (piece_loc
!= NULL
5252 && *piece_loc
!= NULL_RTX
5253 && piece_bitpos
== bitpos
5254 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5255 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5257 last_loc_note
= NULL_RTX
;
5258 /* If the current location is the same as the end of the list,
5259 and either both or neither of the locations is uninitialized,
5260 we have nothing to do. */
5261 if (last_loc_note
== NULL_RTX
5262 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5263 NOTE_VAR_LOCATION_LOC (loc_note
)))
5264 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5265 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5266 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5267 == VAR_INIT_STATUS_UNINITIALIZED
)
5268 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5269 == VAR_INIT_STATUS_UNINITIALIZED
))))
5271 /* Add LOC to the end of list and update LAST. If the last
5272 element of the list has been removed above, reuse its
5273 memory for the new node, otherwise allocate a new one. */
5277 memset (loc
, '\0', sizeof (*loc
));
5280 loc
= ggc_alloc_cleared_var_loc_node ();
5281 if (bitsize
== -1 || piece_loc
== NULL
)
5282 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5284 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5285 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5287 /* Ensure TEMP->LAST will point either to the new last but one
5288 element of the chain, or to the last element in it. */
5289 if (last
!= temp
->last
)
5297 loc
= ggc_alloc_cleared_var_loc_node ();
5300 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5305 /* Keep track of the number of spaces used to indent the
5306 output of the debugging routines that print the structure of
5307 the DIE internal representation. */
5308 static int print_indent
;
5310 /* Indent the line the number of spaces given by print_indent. */
5313 print_spaces (FILE *outfile
)
5315 fprintf (outfile
, "%*s", print_indent
, "");
5318 /* Print a type signature in hex. */
5321 print_signature (FILE *outfile
, char *sig
)
5325 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5326 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5329 /* Print the information associated with a given DIE, and its children.
5330 This routine is a debugging aid only. */
5333 print_die (dw_die_ref die
, FILE *outfile
)
5339 print_spaces (outfile
);
5340 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5341 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5343 print_spaces (outfile
);
5344 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5345 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5346 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5348 if (die
->comdat_type_p
)
5350 print_spaces (outfile
);
5351 fprintf (outfile
, " signature: ");
5352 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5353 fprintf (outfile
, "\n");
5356 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5358 print_spaces (outfile
);
5359 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5361 switch (AT_class (a
))
5363 case dw_val_class_addr
:
5364 fprintf (outfile
, "address");
5366 case dw_val_class_offset
:
5367 fprintf (outfile
, "offset");
5369 case dw_val_class_loc
:
5370 fprintf (outfile
, "location descriptor");
5372 case dw_val_class_loc_list
:
5373 fprintf (outfile
, "location list -> label:%s",
5374 AT_loc_list (a
)->ll_symbol
);
5376 case dw_val_class_range_list
:
5377 fprintf (outfile
, "range list");
5379 case dw_val_class_const
:
5380 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5382 case dw_val_class_unsigned_const
:
5383 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5385 case dw_val_class_const_double
:
5386 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5387 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5388 a
->dw_attr_val
.v
.val_double
.high
,
5389 a
->dw_attr_val
.v
.val_double
.low
);
5391 case dw_val_class_wide_int
:
5393 int i
= a
->dw_attr_val
.v
.val_wide
->get_len ();
5394 fprintf (outfile
, "constant (");
5396 if (a
->dw_attr_val
.v
.val_wide
->elt (i
) == 0)
5397 fprintf (outfile
, "0x");
5398 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5399 a
->dw_attr_val
.v
.val_wide
->elt (--i
));
5401 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5402 a
->dw_attr_val
.v
.val_wide
->elt (i
));
5403 fprintf (outfile
, ")");
5406 case dw_val_class_vec
:
5407 fprintf (outfile
, "floating-point or vector constant");
5409 case dw_val_class_flag
:
5410 fprintf (outfile
, "%u", AT_flag (a
));
5412 case dw_val_class_die_ref
:
5413 if (AT_ref (a
) != NULL
)
5415 if (AT_ref (a
)->comdat_type_p
)
5417 fprintf (outfile
, "die -> signature: ");
5418 print_signature (outfile
,
5419 AT_ref (a
)->die_id
.die_type_node
->signature
);
5421 else if (AT_ref (a
)->die_id
.die_symbol
)
5422 fprintf (outfile
, "die -> label: %s",
5423 AT_ref (a
)->die_id
.die_symbol
);
5425 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5426 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5429 fprintf (outfile
, "die -> <null>");
5431 case dw_val_class_vms_delta
:
5432 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5433 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5435 case dw_val_class_lbl_id
:
5436 case dw_val_class_lineptr
:
5437 case dw_val_class_macptr
:
5438 case dw_val_class_high_pc
:
5439 fprintf (outfile
, "label: %s", AT_lbl (a
));
5441 case dw_val_class_str
:
5442 if (AT_string (a
) != NULL
)
5443 fprintf (outfile
, "\"%s\"", AT_string (a
));
5445 fprintf (outfile
, "<null>");
5447 case dw_val_class_file
:
5448 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5449 AT_file (a
)->emitted_number
);
5451 case dw_val_class_data8
:
5455 for (i
= 0; i
< 8; i
++)
5456 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5463 fprintf (outfile
, "\n");
5466 if (die
->die_child
!= NULL
)
5469 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5472 if (print_indent
== 0)
5473 fprintf (outfile
, "\n");
5476 /* Print the information collected for a given DIE. */
5479 debug_dwarf_die (dw_die_ref die
)
5481 print_die (die
, stderr
);
5485 debug (die_struct
&ref
)
5487 print_die (&ref
, stderr
);
5491 debug (die_struct
*ptr
)
5496 fprintf (stderr
, "<nil>\n");
5500 /* Print all DWARF information collected for the compilation unit.
5501 This routine is a debugging aid only. */
5507 print_die (comp_unit_die (), stderr
);
5510 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5511 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5512 DIE that marks the start of the DIEs for this include file. */
5515 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5517 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5518 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5520 new_unit
->die_sib
= old_unit
;
5524 /* Close an include-file CU and reopen the enclosing one. */
5527 pop_compile_unit (dw_die_ref old_unit
)
5529 dw_die_ref new_unit
= old_unit
->die_sib
;
5531 old_unit
->die_sib
= NULL
;
5535 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5536 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5537 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5539 /* Calculate the checksum of a location expression. */
5542 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5547 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5549 hash
= hash_loc_operands (loc
, hash
);
5553 /* Calculate the checksum of an attribute. */
5556 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5558 dw_loc_descr_ref loc
;
5561 CHECKSUM (at
->dw_attr
);
5563 /* We don't care that this was compiled with a different compiler
5564 snapshot; if the output is the same, that's what matters. */
5565 if (at
->dw_attr
== DW_AT_producer
)
5568 switch (AT_class (at
))
5570 case dw_val_class_const
:
5571 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5573 case dw_val_class_unsigned_const
:
5574 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5576 case dw_val_class_const_double
:
5577 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5579 case dw_val_class_wide_int
:
5580 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5582 case dw_val_class_vec
:
5583 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5584 (at
->dw_attr_val
.v
.val_vec
.length
5585 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5587 case dw_val_class_flag
:
5588 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5590 case dw_val_class_str
:
5591 CHECKSUM_STRING (AT_string (at
));
5594 case dw_val_class_addr
:
5596 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5597 CHECKSUM_STRING (XSTR (r
, 0));
5600 case dw_val_class_offset
:
5601 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5604 case dw_val_class_loc
:
5605 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5606 loc_checksum (loc
, ctx
);
5609 case dw_val_class_die_ref
:
5610 die_checksum (AT_ref (at
), ctx
, mark
);
5613 case dw_val_class_fde_ref
:
5614 case dw_val_class_vms_delta
:
5615 case dw_val_class_lbl_id
:
5616 case dw_val_class_lineptr
:
5617 case dw_val_class_macptr
:
5618 case dw_val_class_high_pc
:
5621 case dw_val_class_file
:
5622 CHECKSUM_STRING (AT_file (at
)->filename
);
5625 case dw_val_class_data8
:
5626 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5634 /* Calculate the checksum of a DIE. */
5637 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5643 /* To avoid infinite recursion. */
5646 CHECKSUM (die
->die_mark
);
5649 die
->die_mark
= ++(*mark
);
5651 CHECKSUM (die
->die_tag
);
5653 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5654 attr_checksum (a
, ctx
, mark
);
5656 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5660 #undef CHECKSUM_BLOCK
5661 #undef CHECKSUM_STRING
5663 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5664 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5665 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5666 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5667 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5668 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5669 #define CHECKSUM_ATTR(FOO) \
5670 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5672 /* Calculate the checksum of a number in signed LEB128 format. */
5675 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5682 byte
= (value
& 0x7f);
5684 more
= !((value
== 0 && (byte
& 0x40) == 0)
5685 || (value
== -1 && (byte
& 0x40) != 0));
5694 /* Calculate the checksum of a number in unsigned LEB128 format. */
5697 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5701 unsigned char byte
= (value
& 0x7f);
5704 /* More bytes to follow. */
5712 /* Checksum the context of the DIE. This adds the names of any
5713 surrounding namespaces or structures to the checksum. */
5716 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5720 int tag
= die
->die_tag
;
5722 if (tag
!= DW_TAG_namespace
5723 && tag
!= DW_TAG_structure_type
5724 && tag
!= DW_TAG_class_type
)
5727 name
= get_AT_string (die
, DW_AT_name
);
5729 spec
= get_AT_ref (die
, DW_AT_specification
);
5733 if (die
->die_parent
!= NULL
)
5734 checksum_die_context (die
->die_parent
, ctx
);
5736 CHECKSUM_ULEB128 ('C');
5737 CHECKSUM_ULEB128 (tag
);
5739 CHECKSUM_STRING (name
);
5742 /* Calculate the checksum of a location expression. */
5745 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5747 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5748 were emitted as a DW_FORM_sdata instead of a location expression. */
5749 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5751 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5752 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5756 /* Otherwise, just checksum the raw location expression. */
5761 CHECKSUM_ULEB128 (loc
->dtprel
);
5762 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5763 hash
= hash_loc_operands (loc
, hash
);
5765 loc
= loc
->dw_loc_next
;
5769 /* Calculate the checksum of an attribute. */
5772 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5773 struct md5_ctx
*ctx
, int *mark
)
5775 dw_loc_descr_ref loc
;
5778 if (AT_class (at
) == dw_val_class_die_ref
)
5780 dw_die_ref target_die
= AT_ref (at
);
5782 /* For pointer and reference types, we checksum only the (qualified)
5783 name of the target type (if there is a name). For friend entries,
5784 we checksum only the (qualified) name of the target type or function.
5785 This allows the checksum to remain the same whether the target type
5786 is complete or not. */
5787 if ((at
->dw_attr
== DW_AT_type
5788 && (tag
== DW_TAG_pointer_type
5789 || tag
== DW_TAG_reference_type
5790 || tag
== DW_TAG_rvalue_reference_type
5791 || tag
== DW_TAG_ptr_to_member_type
))
5792 || (at
->dw_attr
== DW_AT_friend
5793 && tag
== DW_TAG_friend
))
5795 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5797 if (name_attr
!= NULL
)
5799 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5803 CHECKSUM_ULEB128 ('N');
5804 CHECKSUM_ULEB128 (at
->dw_attr
);
5805 if (decl
->die_parent
!= NULL
)
5806 checksum_die_context (decl
->die_parent
, ctx
);
5807 CHECKSUM_ULEB128 ('E');
5808 CHECKSUM_STRING (AT_string (name_attr
));
5813 /* For all other references to another DIE, we check to see if the
5814 target DIE has already been visited. If it has, we emit a
5815 backward reference; if not, we descend recursively. */
5816 if (target_die
->die_mark
> 0)
5818 CHECKSUM_ULEB128 ('R');
5819 CHECKSUM_ULEB128 (at
->dw_attr
);
5820 CHECKSUM_ULEB128 (target_die
->die_mark
);
5824 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5828 target_die
->die_mark
= ++(*mark
);
5829 CHECKSUM_ULEB128 ('T');
5830 CHECKSUM_ULEB128 (at
->dw_attr
);
5831 if (decl
->die_parent
!= NULL
)
5832 checksum_die_context (decl
->die_parent
, ctx
);
5833 die_checksum_ordered (target_die
, ctx
, mark
);
5838 CHECKSUM_ULEB128 ('A');
5839 CHECKSUM_ULEB128 (at
->dw_attr
);
5841 switch (AT_class (at
))
5843 case dw_val_class_const
:
5844 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5845 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5848 case dw_val_class_unsigned_const
:
5849 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5850 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5853 case dw_val_class_const_double
:
5854 CHECKSUM_ULEB128 (DW_FORM_block
);
5855 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5856 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5859 case dw_val_class_wide_int
:
5860 CHECKSUM_ULEB128 (DW_FORM_block
);
5861 CHECKSUM_ULEB128 (sizeof (*at
->dw_attr_val
.v
.val_wide
));
5862 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5865 case dw_val_class_vec
:
5866 CHECKSUM_ULEB128 (DW_FORM_block
);
5867 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5868 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5869 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5870 (at
->dw_attr_val
.v
.val_vec
.length
5871 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5874 case dw_val_class_flag
:
5875 CHECKSUM_ULEB128 (DW_FORM_flag
);
5876 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5879 case dw_val_class_str
:
5880 CHECKSUM_ULEB128 (DW_FORM_string
);
5881 CHECKSUM_STRING (AT_string (at
));
5884 case dw_val_class_addr
:
5886 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5887 CHECKSUM_ULEB128 (DW_FORM_string
);
5888 CHECKSUM_STRING (XSTR (r
, 0));
5891 case dw_val_class_offset
:
5892 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5893 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5896 case dw_val_class_loc
:
5897 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5898 loc_checksum_ordered (loc
, ctx
);
5901 case dw_val_class_fde_ref
:
5902 case dw_val_class_lbl_id
:
5903 case dw_val_class_lineptr
:
5904 case dw_val_class_macptr
:
5905 case dw_val_class_high_pc
:
5908 case dw_val_class_file
:
5909 CHECKSUM_ULEB128 (DW_FORM_string
);
5910 CHECKSUM_STRING (AT_file (at
)->filename
);
5913 case dw_val_class_data8
:
5914 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5922 struct checksum_attributes
5924 dw_attr_ref at_name
;
5925 dw_attr_ref at_type
;
5926 dw_attr_ref at_friend
;
5927 dw_attr_ref at_accessibility
;
5928 dw_attr_ref at_address_class
;
5929 dw_attr_ref at_allocated
;
5930 dw_attr_ref at_artificial
;
5931 dw_attr_ref at_associated
;
5932 dw_attr_ref at_binary_scale
;
5933 dw_attr_ref at_bit_offset
;
5934 dw_attr_ref at_bit_size
;
5935 dw_attr_ref at_bit_stride
;
5936 dw_attr_ref at_byte_size
;
5937 dw_attr_ref at_byte_stride
;
5938 dw_attr_ref at_const_value
;
5939 dw_attr_ref at_containing_type
;
5940 dw_attr_ref at_count
;
5941 dw_attr_ref at_data_location
;
5942 dw_attr_ref at_data_member_location
;
5943 dw_attr_ref at_decimal_scale
;
5944 dw_attr_ref at_decimal_sign
;
5945 dw_attr_ref at_default_value
;
5946 dw_attr_ref at_digit_count
;
5947 dw_attr_ref at_discr
;
5948 dw_attr_ref at_discr_list
;
5949 dw_attr_ref at_discr_value
;
5950 dw_attr_ref at_encoding
;
5951 dw_attr_ref at_endianity
;
5952 dw_attr_ref at_explicit
;
5953 dw_attr_ref at_is_optional
;
5954 dw_attr_ref at_location
;
5955 dw_attr_ref at_lower_bound
;
5956 dw_attr_ref at_mutable
;
5957 dw_attr_ref at_ordering
;
5958 dw_attr_ref at_picture_string
;
5959 dw_attr_ref at_prototyped
;
5960 dw_attr_ref at_small
;
5961 dw_attr_ref at_segment
;
5962 dw_attr_ref at_string_length
;
5963 dw_attr_ref at_threads_scaled
;
5964 dw_attr_ref at_upper_bound
;
5965 dw_attr_ref at_use_location
;
5966 dw_attr_ref at_use_UTF8
;
5967 dw_attr_ref at_variable_parameter
;
5968 dw_attr_ref at_virtuality
;
5969 dw_attr_ref at_visibility
;
5970 dw_attr_ref at_vtable_elem_location
;
5973 /* Collect the attributes that we will want to use for the checksum. */
5976 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5981 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5992 attrs
->at_friend
= a
;
5994 case DW_AT_accessibility
:
5995 attrs
->at_accessibility
= a
;
5997 case DW_AT_address_class
:
5998 attrs
->at_address_class
= a
;
6000 case DW_AT_allocated
:
6001 attrs
->at_allocated
= a
;
6003 case DW_AT_artificial
:
6004 attrs
->at_artificial
= a
;
6006 case DW_AT_associated
:
6007 attrs
->at_associated
= a
;
6009 case DW_AT_binary_scale
:
6010 attrs
->at_binary_scale
= a
;
6012 case DW_AT_bit_offset
:
6013 attrs
->at_bit_offset
= a
;
6015 case DW_AT_bit_size
:
6016 attrs
->at_bit_size
= a
;
6018 case DW_AT_bit_stride
:
6019 attrs
->at_bit_stride
= a
;
6021 case DW_AT_byte_size
:
6022 attrs
->at_byte_size
= a
;
6024 case DW_AT_byte_stride
:
6025 attrs
->at_byte_stride
= a
;
6027 case DW_AT_const_value
:
6028 attrs
->at_const_value
= a
;
6030 case DW_AT_containing_type
:
6031 attrs
->at_containing_type
= a
;
6034 attrs
->at_count
= a
;
6036 case DW_AT_data_location
:
6037 attrs
->at_data_location
= a
;
6039 case DW_AT_data_member_location
:
6040 attrs
->at_data_member_location
= a
;
6042 case DW_AT_decimal_scale
:
6043 attrs
->at_decimal_scale
= a
;
6045 case DW_AT_decimal_sign
:
6046 attrs
->at_decimal_sign
= a
;
6048 case DW_AT_default_value
:
6049 attrs
->at_default_value
= a
;
6051 case DW_AT_digit_count
:
6052 attrs
->at_digit_count
= a
;
6055 attrs
->at_discr
= a
;
6057 case DW_AT_discr_list
:
6058 attrs
->at_discr_list
= a
;
6060 case DW_AT_discr_value
:
6061 attrs
->at_discr_value
= a
;
6063 case DW_AT_encoding
:
6064 attrs
->at_encoding
= a
;
6066 case DW_AT_endianity
:
6067 attrs
->at_endianity
= a
;
6069 case DW_AT_explicit
:
6070 attrs
->at_explicit
= a
;
6072 case DW_AT_is_optional
:
6073 attrs
->at_is_optional
= a
;
6075 case DW_AT_location
:
6076 attrs
->at_location
= a
;
6078 case DW_AT_lower_bound
:
6079 attrs
->at_lower_bound
= a
;
6082 attrs
->at_mutable
= a
;
6084 case DW_AT_ordering
:
6085 attrs
->at_ordering
= a
;
6087 case DW_AT_picture_string
:
6088 attrs
->at_picture_string
= a
;
6090 case DW_AT_prototyped
:
6091 attrs
->at_prototyped
= a
;
6094 attrs
->at_small
= a
;
6097 attrs
->at_segment
= a
;
6099 case DW_AT_string_length
:
6100 attrs
->at_string_length
= a
;
6102 case DW_AT_threads_scaled
:
6103 attrs
->at_threads_scaled
= a
;
6105 case DW_AT_upper_bound
:
6106 attrs
->at_upper_bound
= a
;
6108 case DW_AT_use_location
:
6109 attrs
->at_use_location
= a
;
6111 case DW_AT_use_UTF8
:
6112 attrs
->at_use_UTF8
= a
;
6114 case DW_AT_variable_parameter
:
6115 attrs
->at_variable_parameter
= a
;
6117 case DW_AT_virtuality
:
6118 attrs
->at_virtuality
= a
;
6120 case DW_AT_visibility
:
6121 attrs
->at_visibility
= a
;
6123 case DW_AT_vtable_elem_location
:
6124 attrs
->at_vtable_elem_location
= a
;
6132 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6135 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6139 struct checksum_attributes attrs
;
6141 CHECKSUM_ULEB128 ('D');
6142 CHECKSUM_ULEB128 (die
->die_tag
);
6144 memset (&attrs
, 0, sizeof (attrs
));
6146 decl
= get_AT_ref (die
, DW_AT_specification
);
6148 collect_checksum_attributes (&attrs
, decl
);
6149 collect_checksum_attributes (&attrs
, die
);
6151 CHECKSUM_ATTR (attrs
.at_name
);
6152 CHECKSUM_ATTR (attrs
.at_accessibility
);
6153 CHECKSUM_ATTR (attrs
.at_address_class
);
6154 CHECKSUM_ATTR (attrs
.at_allocated
);
6155 CHECKSUM_ATTR (attrs
.at_artificial
);
6156 CHECKSUM_ATTR (attrs
.at_associated
);
6157 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6158 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6159 CHECKSUM_ATTR (attrs
.at_bit_size
);
6160 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6161 CHECKSUM_ATTR (attrs
.at_byte_size
);
6162 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6163 CHECKSUM_ATTR (attrs
.at_const_value
);
6164 CHECKSUM_ATTR (attrs
.at_containing_type
);
6165 CHECKSUM_ATTR (attrs
.at_count
);
6166 CHECKSUM_ATTR (attrs
.at_data_location
);
6167 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6168 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6169 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6170 CHECKSUM_ATTR (attrs
.at_default_value
);
6171 CHECKSUM_ATTR (attrs
.at_digit_count
);
6172 CHECKSUM_ATTR (attrs
.at_discr
);
6173 CHECKSUM_ATTR (attrs
.at_discr_list
);
6174 CHECKSUM_ATTR (attrs
.at_discr_value
);
6175 CHECKSUM_ATTR (attrs
.at_encoding
);
6176 CHECKSUM_ATTR (attrs
.at_endianity
);
6177 CHECKSUM_ATTR (attrs
.at_explicit
);
6178 CHECKSUM_ATTR (attrs
.at_is_optional
);
6179 CHECKSUM_ATTR (attrs
.at_location
);
6180 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6181 CHECKSUM_ATTR (attrs
.at_mutable
);
6182 CHECKSUM_ATTR (attrs
.at_ordering
);
6183 CHECKSUM_ATTR (attrs
.at_picture_string
);
6184 CHECKSUM_ATTR (attrs
.at_prototyped
);
6185 CHECKSUM_ATTR (attrs
.at_small
);
6186 CHECKSUM_ATTR (attrs
.at_segment
);
6187 CHECKSUM_ATTR (attrs
.at_string_length
);
6188 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6189 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6190 CHECKSUM_ATTR (attrs
.at_use_location
);
6191 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6192 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6193 CHECKSUM_ATTR (attrs
.at_virtuality
);
6194 CHECKSUM_ATTR (attrs
.at_visibility
);
6195 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6196 CHECKSUM_ATTR (attrs
.at_type
);
6197 CHECKSUM_ATTR (attrs
.at_friend
);
6199 /* Checksum the child DIEs. */
6202 dw_attr_ref name_attr
;
6205 name_attr
= get_AT (c
, DW_AT_name
);
6206 if (is_template_instantiation (c
))
6208 /* Ignore instantiations of member type and function templates. */
6210 else if (name_attr
!= NULL
6211 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6213 /* Use a shallow checksum for named nested types and member
6215 CHECKSUM_ULEB128 ('S');
6216 CHECKSUM_ULEB128 (c
->die_tag
);
6217 CHECKSUM_STRING (AT_string (name_attr
));
6221 /* Use a deep checksum for other children. */
6222 /* Mark this DIE so it gets processed when unmarking. */
6223 if (c
->die_mark
== 0)
6225 die_checksum_ordered (c
, ctx
, mark
);
6227 } while (c
!= die
->die_child
);
6229 CHECKSUM_ULEB128 (0);
6232 /* Add a type name and tag to a hash. */
6234 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6236 CHECKSUM_ULEB128 (tag
);
6237 CHECKSUM_STRING (name
);
6241 #undef CHECKSUM_STRING
6242 #undef CHECKSUM_ATTR
6243 #undef CHECKSUM_LEB128
6244 #undef CHECKSUM_ULEB128
6246 /* Generate the type signature for DIE. This is computed by generating an
6247 MD5 checksum over the DIE's tag, its relevant attributes, and its
6248 children. Attributes that are references to other DIEs are processed
6249 by recursion, using the MARK field to prevent infinite recursion.
6250 If the DIE is nested inside a namespace or another type, we also
6251 need to include that context in the signature. The lower 64 bits
6252 of the resulting MD5 checksum comprise the signature. */
6255 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6259 unsigned char checksum
[16];
6264 name
= get_AT_string (die
, DW_AT_name
);
6265 decl
= get_AT_ref (die
, DW_AT_specification
);
6266 parent
= get_die_parent (die
);
6268 /* First, compute a signature for just the type name (and its surrounding
6269 context, if any. This is stored in the type unit DIE for link-time
6270 ODR (one-definition rule) checking. */
6272 if (is_cxx () && name
!= NULL
)
6274 md5_init_ctx (&ctx
);
6276 /* Checksum the names of surrounding namespaces and structures. */
6278 checksum_die_context (parent
, &ctx
);
6280 /* Checksum the current DIE. */
6281 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6282 md5_finish_ctx (&ctx
, checksum
);
6284 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6287 /* Next, compute the complete type signature. */
6289 md5_init_ctx (&ctx
);
6291 die
->die_mark
= mark
;
6293 /* Checksum the names of surrounding namespaces and structures. */
6295 checksum_die_context (parent
, &ctx
);
6297 /* Checksum the DIE and its children. */
6298 die_checksum_ordered (die
, &ctx
, &mark
);
6299 unmark_all_dies (die
);
6300 md5_finish_ctx (&ctx
, checksum
);
6302 /* Store the signature in the type node and link the type DIE and the
6303 type node together. */
6304 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6305 DWARF_TYPE_SIGNATURE_SIZE
);
6306 die
->comdat_type_p
= true;
6307 die
->die_id
.die_type_node
= type_node
;
6308 type_node
->type_die
= die
;
6310 /* If the DIE is a specification, link its declaration to the type node
6314 decl
->comdat_type_p
= true;
6315 decl
->die_id
.die_type_node
= type_node
;
6319 /* Do the location expressions look same? */
6321 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6323 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6324 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6325 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6328 /* Do the values look the same? */
6330 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6332 dw_loc_descr_ref loc1
, loc2
;
6335 if (v1
->val_class
!= v2
->val_class
)
6338 switch (v1
->val_class
)
6340 case dw_val_class_const
:
6341 return v1
->v
.val_int
== v2
->v
.val_int
;
6342 case dw_val_class_unsigned_const
:
6343 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6344 case dw_val_class_const_double
:
6345 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6346 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6347 case dw_val_class_wide_int
:
6348 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6349 case dw_val_class_vec
:
6350 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6351 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6353 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6354 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6357 case dw_val_class_flag
:
6358 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6359 case dw_val_class_str
:
6360 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6362 case dw_val_class_addr
:
6363 r1
= v1
->v
.val_addr
;
6364 r2
= v2
->v
.val_addr
;
6365 if (GET_CODE (r1
) != GET_CODE (r2
))
6367 return !rtx_equal_p (r1
, r2
);
6369 case dw_val_class_offset
:
6370 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6372 case dw_val_class_loc
:
6373 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6375 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6376 if (!same_loc_p (loc1
, loc2
, mark
))
6378 return !loc1
&& !loc2
;
6380 case dw_val_class_die_ref
:
6381 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6383 case dw_val_class_fde_ref
:
6384 case dw_val_class_vms_delta
:
6385 case dw_val_class_lbl_id
:
6386 case dw_val_class_lineptr
:
6387 case dw_val_class_macptr
:
6388 case dw_val_class_high_pc
:
6391 case dw_val_class_file
:
6392 return v1
->v
.val_file
== v2
->v
.val_file
;
6394 case dw_val_class_data8
:
6395 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6402 /* Do the attributes look the same? */
6405 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6407 if (at1
->dw_attr
!= at2
->dw_attr
)
6410 /* We don't care that this was compiled with a different compiler
6411 snapshot; if the output is the same, that's what matters. */
6412 if (at1
->dw_attr
== DW_AT_producer
)
6415 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6418 /* Do the dies look the same? */
6421 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6427 /* To avoid infinite recursion. */
6429 return die1
->die_mark
== die2
->die_mark
;
6430 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6432 if (die1
->die_tag
!= die2
->die_tag
)
6435 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6438 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6439 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6442 c1
= die1
->die_child
;
6443 c2
= die2
->die_child
;
6452 if (!same_die_p (c1
, c2
, mark
))
6456 if (c1
== die1
->die_child
)
6458 if (c2
== die2
->die_child
)
6468 /* Do the dies look the same? Wrapper around same_die_p. */
6471 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6474 int ret
= same_die_p (die1
, die2
, &mark
);
6476 unmark_all_dies (die1
);
6477 unmark_all_dies (die2
);
6482 /* The prefix to attach to symbols on DIEs in the current comdat debug
6484 static const char *comdat_symbol_id
;
6486 /* The index of the current symbol within the current comdat CU. */
6487 static unsigned int comdat_symbol_number
;
6489 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6490 children, and set comdat_symbol_id accordingly. */
6493 compute_section_prefix (dw_die_ref unit_die
)
6495 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6496 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6497 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6500 unsigned char checksum
[16];
6503 /* Compute the checksum of the DIE, then append part of it as hex digits to
6504 the name filename of the unit. */
6506 md5_init_ctx (&ctx
);
6508 die_checksum (unit_die
, &ctx
, &mark
);
6509 unmark_all_dies (unit_die
);
6510 md5_finish_ctx (&ctx
, checksum
);
6512 sprintf (name
, "%s.", base
);
6513 clean_symbol_name (name
);
6515 p
= name
+ strlen (name
);
6516 for (i
= 0; i
< 4; i
++)
6518 sprintf (p
, "%.2x", checksum
[i
]);
6522 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6523 comdat_symbol_number
= 0;
6526 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6529 is_type_die (dw_die_ref die
)
6531 switch (die
->die_tag
)
6533 case DW_TAG_array_type
:
6534 case DW_TAG_class_type
:
6535 case DW_TAG_interface_type
:
6536 case DW_TAG_enumeration_type
:
6537 case DW_TAG_pointer_type
:
6538 case DW_TAG_reference_type
:
6539 case DW_TAG_rvalue_reference_type
:
6540 case DW_TAG_string_type
:
6541 case DW_TAG_structure_type
:
6542 case DW_TAG_subroutine_type
:
6543 case DW_TAG_union_type
:
6544 case DW_TAG_ptr_to_member_type
:
6545 case DW_TAG_set_type
:
6546 case DW_TAG_subrange_type
:
6547 case DW_TAG_base_type
:
6548 case DW_TAG_const_type
:
6549 case DW_TAG_file_type
:
6550 case DW_TAG_packed_type
:
6551 case DW_TAG_volatile_type
:
6552 case DW_TAG_typedef
:
6559 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6560 Basically, we want to choose the bits that are likely to be shared between
6561 compilations (types) and leave out the bits that are specific to individual
6562 compilations (functions). */
6565 is_comdat_die (dw_die_ref c
)
6567 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6568 we do for stabs. The advantage is a greater likelihood of sharing between
6569 objects that don't include headers in the same order (and therefore would
6570 put the base types in a different comdat). jason 8/28/00 */
6572 if (c
->die_tag
== DW_TAG_base_type
)
6575 if (c
->die_tag
== DW_TAG_pointer_type
6576 || c
->die_tag
== DW_TAG_reference_type
6577 || c
->die_tag
== DW_TAG_rvalue_reference_type
6578 || c
->die_tag
== DW_TAG_const_type
6579 || c
->die_tag
== DW_TAG_volatile_type
)
6581 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6583 return t
? is_comdat_die (t
) : 0;
6586 return is_type_die (c
);
6589 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6590 compilation unit. */
6593 is_symbol_die (dw_die_ref c
)
6595 return (is_type_die (c
)
6596 || is_declaration_die (c
)
6597 || c
->die_tag
== DW_TAG_namespace
6598 || c
->die_tag
== DW_TAG_module
);
6601 /* Returns true iff C is a compile-unit DIE. */
6604 is_cu_die (dw_die_ref c
)
6606 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6609 /* Returns true iff C is a unit DIE of some sort. */
6612 is_unit_die (dw_die_ref c
)
6614 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6615 || c
->die_tag
== DW_TAG_partial_unit
6616 || c
->die_tag
== DW_TAG_type_unit
);
6619 /* Returns true iff C is a namespace DIE. */
6622 is_namespace_die (dw_die_ref c
)
6624 return c
&& c
->die_tag
== DW_TAG_namespace
;
6627 /* Returns true iff C is a class or structure DIE. */
6630 is_class_die (dw_die_ref c
)
6632 return c
&& (c
->die_tag
== DW_TAG_class_type
6633 || c
->die_tag
== DW_TAG_structure_type
);
6636 /* Return non-zero if this DIE is a template parameter. */
6639 is_template_parameter (dw_die_ref die
)
6641 switch (die
->die_tag
)
6643 case DW_TAG_template_type_param
:
6644 case DW_TAG_template_value_param
:
6645 case DW_TAG_GNU_template_template_param
:
6646 case DW_TAG_GNU_template_parameter_pack
:
6653 /* Return non-zero if this DIE represents a template instantiation. */
6656 is_template_instantiation (dw_die_ref die
)
6660 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6662 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6667 gen_internal_sym (const char *prefix
)
6671 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6672 return xstrdup (buf
);
6675 /* Assign symbols to all worthy DIEs under DIE. */
6678 assign_symbol_names (dw_die_ref die
)
6682 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6684 if (comdat_symbol_id
)
6686 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6688 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6689 comdat_symbol_id
, comdat_symbol_number
++);
6690 die
->die_id
.die_symbol
= xstrdup (p
);
6693 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6696 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6699 struct cu_hash_table_entry
6702 unsigned min_comdat_num
, max_comdat_num
;
6703 struct cu_hash_table_entry
*next
;
6706 /* Helpers to manipulate hash table of CUs. */
6708 struct cu_hash_table_entry_hasher
6710 typedef cu_hash_table_entry value_type
;
6711 typedef die_struct compare_type
;
6712 static inline hashval_t
hash (const value_type
*);
6713 static inline bool equal (const value_type
*, const compare_type
*);
6714 static inline void remove (value_type
*);
6718 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6720 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6724 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6725 const compare_type
*entry2
)
6727 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6731 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6733 struct cu_hash_table_entry
*next
;
6743 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6745 /* Check whether we have already seen this CU and set up SYM_NUM
6748 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6750 struct cu_hash_table_entry dummy
;
6751 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6753 dummy
.max_comdat_num
= 0;
6755 slot
= htable
.find_slot_with_hash (cu
,
6756 htab_hash_string (cu
->die_id
.die_symbol
),
6760 for (; entry
; last
= entry
, entry
= entry
->next
)
6762 if (same_die_p_wrap (cu
, entry
->cu
))
6768 *sym_num
= entry
->min_comdat_num
;
6772 entry
= XCNEW (struct cu_hash_table_entry
);
6774 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6775 entry
->next
= *slot
;
6781 /* Record SYM_NUM to record of CU in HTABLE. */
6783 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6784 unsigned int sym_num
)
6786 struct cu_hash_table_entry
**slot
, *entry
;
6788 slot
= htable
.find_slot_with_hash (cu
,
6789 htab_hash_string (cu
->die_id
.die_symbol
),
6793 entry
->max_comdat_num
= sym_num
;
6796 /* Traverse the DIE (which is always comp_unit_die), and set up
6797 additional compilation units for each of the include files we see
6798 bracketed by BINCL/EINCL. */
6801 break_out_includes (dw_die_ref die
)
6804 dw_die_ref unit
= NULL
;
6805 limbo_die_node
*node
, **pnode
;
6806 cu_hash_type cu_hash_table
;
6810 dw_die_ref prev
= c
;
6812 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6813 || (unit
&& is_comdat_die (c
)))
6815 dw_die_ref next
= c
->die_sib
;
6817 /* This DIE is for a secondary CU; remove it from the main one. */
6818 remove_child_with_prev (c
, prev
);
6820 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6821 unit
= push_new_compile_unit (unit
, c
);
6822 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6823 unit
= pop_compile_unit (unit
);
6825 add_child_die (unit
, c
);
6827 if (c
== die
->die_child
)
6830 } while (c
!= die
->die_child
);
6833 /* We can only use this in debugging, since the frontend doesn't check
6834 to make sure that we leave every include file we enter. */
6838 assign_symbol_names (die
);
6839 cu_hash_table
.create (10);
6840 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6846 compute_section_prefix (node
->die
);
6847 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6848 &comdat_symbol_number
);
6849 assign_symbol_names (node
->die
);
6851 *pnode
= node
->next
;
6854 pnode
= &node
->next
;
6855 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6856 comdat_symbol_number
);
6859 cu_hash_table
.dispose ();
6862 /* Return non-zero if this DIE is a declaration. */
6865 is_declaration_die (dw_die_ref die
)
6870 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6871 if (a
->dw_attr
== DW_AT_declaration
)
6877 /* Return non-zero if this DIE is nested inside a subprogram. */
6880 is_nested_in_subprogram (dw_die_ref die
)
6882 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6886 return local_scope_p (decl
);
6889 /* Return non-zero if this DIE contains a defining declaration of a
6893 contains_subprogram_definition (dw_die_ref die
)
6897 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6899 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6903 /* Return non-zero if this is a type DIE that should be moved to a
6904 COMDAT .debug_types section. */
6907 should_move_die_to_comdat (dw_die_ref die
)
6909 switch (die
->die_tag
)
6911 case DW_TAG_class_type
:
6912 case DW_TAG_structure_type
:
6913 case DW_TAG_enumeration_type
:
6914 case DW_TAG_union_type
:
6915 /* Don't move declarations, inlined instances, or types nested in a
6917 if (is_declaration_die (die
)
6918 || get_AT (die
, DW_AT_abstract_origin
)
6919 || is_nested_in_subprogram (die
))
6921 /* A type definition should never contain a subprogram definition. */
6922 gcc_assert (!contains_subprogram_definition (die
));
6924 case DW_TAG_array_type
:
6925 case DW_TAG_interface_type
:
6926 case DW_TAG_pointer_type
:
6927 case DW_TAG_reference_type
:
6928 case DW_TAG_rvalue_reference_type
:
6929 case DW_TAG_string_type
:
6930 case DW_TAG_subroutine_type
:
6931 case DW_TAG_ptr_to_member_type
:
6932 case DW_TAG_set_type
:
6933 case DW_TAG_subrange_type
:
6934 case DW_TAG_base_type
:
6935 case DW_TAG_const_type
:
6936 case DW_TAG_file_type
:
6937 case DW_TAG_packed_type
:
6938 case DW_TAG_volatile_type
:
6939 case DW_TAG_typedef
:
6945 /* Make a clone of DIE. */
6948 clone_die (dw_die_ref die
)
6954 clone
= ggc_alloc_cleared_die_node ();
6955 clone
->die_tag
= die
->die_tag
;
6957 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6958 add_dwarf_attr (clone
, a
);
6963 /* Make a clone of the tree rooted at DIE. */
6966 clone_tree (dw_die_ref die
)
6969 dw_die_ref clone
= clone_die (die
);
6971 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6976 /* Make a clone of DIE as a declaration. */
6979 clone_as_declaration (dw_die_ref die
)
6986 /* If the DIE is already a declaration, just clone it. */
6987 if (is_declaration_die (die
))
6988 return clone_die (die
);
6990 /* If the DIE is a specification, just clone its declaration DIE. */
6991 decl
= get_AT_ref (die
, DW_AT_specification
);
6994 clone
= clone_die (decl
);
6995 if (die
->comdat_type_p
)
6996 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7000 clone
= ggc_alloc_cleared_die_node ();
7001 clone
->die_tag
= die
->die_tag
;
7003 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7005 /* We don't want to copy over all attributes.
7006 For example we don't want DW_AT_byte_size because otherwise we will no
7007 longer have a declaration and GDB will treat it as a definition. */
7011 case DW_AT_artificial
:
7012 case DW_AT_containing_type
:
7013 case DW_AT_external
:
7016 case DW_AT_virtuality
:
7017 case DW_AT_linkage_name
:
7018 case DW_AT_MIPS_linkage_name
:
7019 add_dwarf_attr (clone
, a
);
7021 case DW_AT_byte_size
:
7027 if (die
->comdat_type_p
)
7028 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7030 add_AT_flag (clone
, DW_AT_declaration
, 1);
7035 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7037 struct decl_table_entry
7043 /* Helpers to manipulate hash table of copied declarations. */
7045 /* Hashtable helpers. */
7047 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
7049 typedef decl_table_entry value_type
;
7050 typedef die_struct compare_type
;
7051 static inline hashval_t
hash (const value_type
*);
7052 static inline bool equal (const value_type
*, const compare_type
*);
7056 decl_table_entry_hasher::hash (const value_type
*entry
)
7058 return htab_hash_pointer (entry
->orig
);
7062 decl_table_entry_hasher::equal (const value_type
*entry1
,
7063 const compare_type
*entry2
)
7065 return entry1
->orig
== entry2
;
7068 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7070 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7071 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7072 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7073 to check if the ancestor has already been copied into UNIT. */
7076 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7078 dw_die_ref parent
= die
->die_parent
;
7079 dw_die_ref new_parent
= unit
;
7081 decl_table_entry
**slot
= NULL
;
7082 struct decl_table_entry
*entry
= NULL
;
7084 if (decl_table
.is_created ())
7086 /* Check if the entry has already been copied to UNIT. */
7087 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
7089 if (*slot
!= HTAB_EMPTY_ENTRY
)
7095 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7096 entry
= XCNEW (struct decl_table_entry
);
7104 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7107 if (!is_unit_die (parent
))
7108 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7111 copy
= clone_as_declaration (die
);
7112 add_child_die (new_parent
, copy
);
7114 if (decl_table
.is_created ())
7116 /* Record the pointer to the copy. */
7122 /* Copy the declaration context to the new type unit DIE. This includes
7123 any surrounding namespace or type declarations. If the DIE has an
7124 AT_specification attribute, it also includes attributes and children
7125 attached to the specification, and returns a pointer to the original
7126 parent of the declaration DIE. Returns NULL otherwise. */
7129 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7132 dw_die_ref new_decl
;
7133 dw_die_ref orig_parent
= NULL
;
7135 decl
= get_AT_ref (die
, DW_AT_specification
);
7144 /* The original DIE will be changed to a declaration, and must
7145 be moved to be a child of the original declaration DIE. */
7146 orig_parent
= decl
->die_parent
;
7148 /* Copy the type node pointer from the new DIE to the original
7149 declaration DIE so we can forward references later. */
7150 decl
->comdat_type_p
= true;
7151 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7153 remove_AT (die
, DW_AT_specification
);
7155 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7157 if (a
->dw_attr
!= DW_AT_name
7158 && a
->dw_attr
!= DW_AT_declaration
7159 && a
->dw_attr
!= DW_AT_external
)
7160 add_dwarf_attr (die
, a
);
7163 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7166 if (decl
->die_parent
!= NULL
7167 && !is_unit_die (decl
->die_parent
))
7169 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7170 if (new_decl
!= NULL
)
7172 remove_AT (new_decl
, DW_AT_signature
);
7173 add_AT_specification (die
, new_decl
);
7180 /* Generate the skeleton ancestor tree for the given NODE, then clone
7181 the DIE and add the clone into the tree. */
7184 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7186 if (node
->new_die
!= NULL
)
7189 node
->new_die
= clone_as_declaration (node
->old_die
);
7191 if (node
->parent
!= NULL
)
7193 generate_skeleton_ancestor_tree (node
->parent
);
7194 add_child_die (node
->parent
->new_die
, node
->new_die
);
7198 /* Generate a skeleton tree of DIEs containing any declarations that are
7199 found in the original tree. We traverse the tree looking for declaration
7200 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7203 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7205 skeleton_chain_node node
;
7208 dw_die_ref prev
= NULL
;
7209 dw_die_ref next
= NULL
;
7211 node
.parent
= parent
;
7213 first
= c
= parent
->old_die
->die_child
;
7217 if (prev
== NULL
|| prev
->die_sib
== c
)
7220 next
= (c
== first
? NULL
: c
->die_sib
);
7222 node
.new_die
= NULL
;
7223 if (is_declaration_die (c
))
7225 if (is_template_instantiation (c
))
7227 /* Instantiated templates do not need to be cloned into the
7228 type unit. Just move the DIE and its children back to
7229 the skeleton tree (in the main CU). */
7230 remove_child_with_prev (c
, prev
);
7231 add_child_die (parent
->new_die
, c
);
7236 /* Clone the existing DIE, move the original to the skeleton
7237 tree (which is in the main CU), and put the clone, with
7238 all the original's children, where the original came from
7239 (which is about to be moved to the type unit). */
7240 dw_die_ref clone
= clone_die (c
);
7241 move_all_children (c
, clone
);
7243 replace_child (c
, clone
, prev
);
7244 generate_skeleton_ancestor_tree (parent
);
7245 add_child_die (parent
->new_die
, c
);
7250 generate_skeleton_bottom_up (&node
);
7251 } while (next
!= NULL
);
7254 /* Wrapper function for generate_skeleton_bottom_up. */
7257 generate_skeleton (dw_die_ref die
)
7259 skeleton_chain_node node
;
7262 node
.new_die
= NULL
;
7265 /* If this type definition is nested inside another type,
7266 and is not an instantiation of a template, always leave
7267 at least a declaration in its place. */
7268 if (die
->die_parent
!= NULL
7269 && is_type_die (die
->die_parent
)
7270 && !is_template_instantiation (die
))
7271 node
.new_die
= clone_as_declaration (die
);
7273 generate_skeleton_bottom_up (&node
);
7274 return node
.new_die
;
7277 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7278 declaration. The original DIE is moved to a new compile unit so that
7279 existing references to it follow it to the new location. If any of the
7280 original DIE's descendants is a declaration, we need to replace the
7281 original DIE with a skeleton tree and move the declarations back into the
7285 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7288 dw_die_ref skeleton
, orig_parent
;
7290 /* Copy the declaration context to the type unit DIE. If the returned
7291 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7293 orig_parent
= copy_declaration_context (unit
, child
);
7295 skeleton
= generate_skeleton (child
);
7296 if (skeleton
== NULL
)
7297 remove_child_with_prev (child
, prev
);
7300 skeleton
->comdat_type_p
= true;
7301 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7303 /* If the original DIE was a specification, we need to put
7304 the skeleton under the parent DIE of the declaration.
7305 This leaves the original declaration in the tree, but
7306 it will be pruned later since there are no longer any
7307 references to it. */
7308 if (orig_parent
!= NULL
)
7310 remove_child_with_prev (child
, prev
);
7311 add_child_die (orig_parent
, skeleton
);
7314 replace_child (child
, skeleton
, prev
);
7320 /* Traverse the DIE and set up additional .debug_types sections for each
7321 type worthy of being placed in a COMDAT section. */
7324 break_out_comdat_types (dw_die_ref die
)
7328 dw_die_ref prev
= NULL
;
7329 dw_die_ref next
= NULL
;
7330 dw_die_ref unit
= NULL
;
7332 first
= c
= die
->die_child
;
7336 if (prev
== NULL
|| prev
->die_sib
== c
)
7339 next
= (c
== first
? NULL
: c
->die_sib
);
7340 if (should_move_die_to_comdat (c
))
7342 dw_die_ref replacement
;
7343 comdat_type_node_ref type_node
;
7345 /* Break out nested types into their own type units. */
7346 break_out_comdat_types (c
);
7348 /* Create a new type unit DIE as the root for the new tree, and
7349 add it to the list of comdat types. */
7350 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7351 add_AT_unsigned (unit
, DW_AT_language
,
7352 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7353 type_node
= ggc_alloc_cleared_comdat_type_node ();
7354 type_node
->root_die
= unit
;
7355 type_node
->next
= comdat_type_list
;
7356 comdat_type_list
= type_node
;
7358 /* Generate the type signature. */
7359 generate_type_signature (c
, type_node
);
7361 /* Copy the declaration context, attributes, and children of the
7362 declaration into the new type unit DIE, then remove this DIE
7363 from the main CU (or replace it with a skeleton if necessary). */
7364 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7365 type_node
->skeleton_die
= replacement
;
7367 /* Add the DIE to the new compunit. */
7368 add_child_die (unit
, c
);
7370 if (replacement
!= NULL
)
7373 else if (c
->die_tag
== DW_TAG_namespace
7374 || c
->die_tag
== DW_TAG_class_type
7375 || c
->die_tag
== DW_TAG_structure_type
7376 || c
->die_tag
== DW_TAG_union_type
)
7378 /* Look for nested types that can be broken out. */
7379 break_out_comdat_types (c
);
7381 } while (next
!= NULL
);
7384 /* Like clone_tree, but additionally enter all the children into
7385 the hash table decl_table. */
7388 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7391 dw_die_ref clone
= clone_die (die
);
7392 struct decl_table_entry
*entry
;
7393 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7394 htab_hash_pointer (die
), INSERT
);
7395 /* Assert that DIE isn't in the hash table yet. If it would be there
7396 before, the ancestors would be necessarily there as well, therefore
7397 clone_tree_hash wouldn't be called. */
7398 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7399 entry
= XCNEW (struct decl_table_entry
);
7401 entry
->copy
= clone
;
7404 FOR_EACH_CHILD (die
, c
,
7405 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7410 /* Walk the DIE and its children, looking for references to incomplete
7411 or trivial types that are unmarked (i.e., that are not in the current
7415 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7421 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7423 if (AT_class (a
) == dw_val_class_die_ref
)
7425 dw_die_ref targ
= AT_ref (a
);
7426 decl_table_entry
**slot
;
7427 struct decl_table_entry
*entry
;
7429 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7432 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7435 if (*slot
!= HTAB_EMPTY_ENTRY
)
7437 /* TARG has already been copied, so we just need to
7438 modify the reference to point to the copy. */
7440 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7444 dw_die_ref parent
= unit
;
7445 dw_die_ref copy
= clone_die (targ
);
7447 /* Record in DECL_TABLE that TARG has been copied.
7448 Need to do this now, before the recursive call,
7449 because DECL_TABLE may be expanded and SLOT
7450 would no longer be a valid pointer. */
7451 entry
= XCNEW (struct decl_table_entry
);
7456 FOR_EACH_CHILD (targ
, c
,
7457 add_child_die (copy
,
7458 clone_tree_hash (c
, decl_table
)));
7460 /* Make sure the cloned tree is marked as part of the
7464 /* If TARG has surrounding context, copy its ancestor tree
7465 into the new type unit. */
7466 if (targ
->die_parent
!= NULL
7467 && !is_unit_die (targ
->die_parent
))
7468 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7471 add_child_die (parent
, copy
);
7472 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7474 /* Make sure the newly-copied DIE is walked. If it was
7475 installed in a previously-added context, it won't
7476 get visited otherwise. */
7479 /* Find the highest point of the newly-added tree,
7480 mark each node along the way, and walk from there. */
7481 parent
->die_mark
= 1;
7482 while (parent
->die_parent
7483 && parent
->die_parent
->die_mark
== 0)
7485 parent
= parent
->die_parent
;
7486 parent
->die_mark
= 1;
7488 copy_decls_walk (unit
, parent
, decl_table
);
7494 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7497 /* Copy declarations for "unworthy" types into the new comdat section.
7498 Incomplete types, modified types, and certain other types aren't broken
7499 out into comdat sections of their own, so they don't have a signature,
7500 and we need to copy the declaration into the same section so that we
7501 don't have an external reference. */
7504 copy_decls_for_unworthy_types (dw_die_ref unit
)
7506 decl_hash_type decl_table
;
7509 decl_table
.create (10);
7510 copy_decls_walk (unit
, unit
, decl_table
);
7511 decl_table
.dispose ();
7515 /* Traverse the DIE and add a sibling attribute if it may have the
7516 effect of speeding up access to siblings. To save some space,
7517 avoid generating sibling attributes for DIE's without children. */
7520 add_sibling_attributes (dw_die_ref die
)
7524 if (! die
->die_child
)
7527 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7528 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7530 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7533 /* Output all location lists for the DIE and its children. */
7536 output_location_lists (dw_die_ref die
)
7542 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7543 if (AT_class (a
) == dw_val_class_loc_list
)
7544 output_loc_list (AT_loc_list (a
));
7546 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7549 /* We want to limit the number of external references, because they are
7550 larger than local references: a relocation takes multiple words, and
7551 even a sig8 reference is always eight bytes, whereas a local reference
7552 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7553 So if we encounter multiple external references to the same type DIE, we
7554 make a local typedef stub for it and redirect all references there.
7556 This is the element of the hash table for keeping track of these
7566 /* Hashtable helpers. */
7568 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7570 typedef external_ref value_type
;
7571 typedef external_ref compare_type
;
7572 static inline hashval_t
hash (const value_type
*);
7573 static inline bool equal (const value_type
*, const compare_type
*);
7577 external_ref_hasher::hash (const value_type
*r
)
7579 dw_die_ref die
= r
->type
;
7582 /* We can't use the address of the DIE for hashing, because
7583 that will make the order of the stub DIEs non-deterministic. */
7584 if (! die
->comdat_type_p
)
7585 /* We have a symbol; use it to compute a hash. */
7586 h
= htab_hash_string (die
->die_id
.die_symbol
);
7589 /* We have a type signature; use a subset of the bits as the hash.
7590 The 8-byte signature is at least as large as hashval_t. */
7591 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7592 memcpy (&h
, type_node
->signature
, sizeof (h
));
7598 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7600 return r1
->type
== r2
->type
;
7603 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7605 /* Return a pointer to the external_ref for references to DIE. */
7607 static struct external_ref
*
7608 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7610 struct external_ref ref
, *ref_p
;
7611 external_ref
**slot
;
7614 slot
= map
.find_slot (&ref
, INSERT
);
7615 if (*slot
!= HTAB_EMPTY_ENTRY
)
7618 ref_p
= XCNEW (struct external_ref
);
7624 /* Subroutine of optimize_external_refs, below.
7626 If we see a type skeleton, record it as our stub. If we see external
7627 references, remember how many we've seen. */
7630 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7635 struct external_ref
*ref_p
;
7637 if (is_type_die (die
)
7638 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7640 /* This is a local skeleton; use it for local references. */
7641 ref_p
= lookup_external_ref (map
, c
);
7645 /* Scan the DIE references, and remember any that refer to DIEs from
7646 other CUs (i.e. those which are not marked). */
7647 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7648 if (AT_class (a
) == dw_val_class_die_ref
7649 && (c
= AT_ref (a
))->die_mark
== 0
7652 ref_p
= lookup_external_ref (map
, c
);
7656 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7659 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7660 points to an external_ref, DATA is the CU we're processing. If we don't
7661 already have a local stub, and we have multiple refs, build a stub. */
7664 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7666 struct external_ref
*ref_p
= *slot
;
7668 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7670 /* We have multiple references to this type, so build a small stub.
7671 Both of these forms are a bit dodgy from the perspective of the
7672 DWARF standard, since technically they should have names. */
7673 dw_die_ref cu
= data
;
7674 dw_die_ref type
= ref_p
->type
;
7675 dw_die_ref stub
= NULL
;
7677 if (type
->comdat_type_p
)
7679 /* If we refer to this type via sig8, use AT_signature. */
7680 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7681 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7685 /* Otherwise, use a typedef with no name. */
7686 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7687 add_AT_die_ref (stub
, DW_AT_type
, type
);
7696 /* DIE is a unit; look through all the DIE references to see if there are
7697 any external references to types, and if so, create local stubs for
7698 them which will be applied in build_abbrev_table. This is useful because
7699 references to local DIEs are smaller. */
7701 static external_ref_hash_type
7702 optimize_external_refs (dw_die_ref die
)
7704 external_ref_hash_type map
;
7706 optimize_external_refs_1 (die
, map
);
7707 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7711 /* The format of each DIE (and its attribute value pairs) is encoded in an
7712 abbreviation table. This routine builds the abbreviation table and assigns
7713 a unique abbreviation id for each abbreviation entry. The children of each
7714 die are visited recursively. */
7717 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7719 unsigned long abbrev_id
;
7720 unsigned int n_alloc
;
7725 /* Scan the DIE references, and replace any that refer to
7726 DIEs from other CUs (i.e. those which are not marked) with
7727 the local stubs we built in optimize_external_refs. */
7728 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7729 if (AT_class (a
) == dw_val_class_die_ref
7730 && (c
= AT_ref (a
))->die_mark
== 0)
7732 struct external_ref
*ref_p
;
7733 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7735 ref_p
= lookup_external_ref (extern_map
, c
);
7736 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7737 change_AT_die_ref (a
, ref_p
->stub
);
7739 /* We aren't changing this reference, so mark it external. */
7740 set_AT_ref_external (a
, 1);
7743 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7745 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7746 dw_attr_ref die_a
, abbrev_a
;
7750 if (abbrev
->die_tag
!= die
->die_tag
)
7752 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7755 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7758 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7760 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7761 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7762 || (value_format (abbrev_a
) != value_format (die_a
)))
7772 if (abbrev_id
>= abbrev_die_table_in_use
)
7774 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7776 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7777 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7780 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7781 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7782 abbrev_die_table_allocated
= n_alloc
;
7785 ++abbrev_die_table_in_use
;
7786 abbrev_die_table
[abbrev_id
] = die
;
7789 die
->die_abbrev
= abbrev_id
;
7790 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7793 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7796 constant_size (unsigned HOST_WIDE_INT value
)
7803 log
= floor_log2 (value
);
7806 log
= 1 << (floor_log2 (log
) + 1);
7811 /* Return the size of a DIE as it is represented in the
7812 .debug_info section. */
7814 static unsigned long
7815 size_of_die (dw_die_ref die
)
7817 unsigned long size
= 0;
7820 enum dwarf_form form
;
7822 size
+= size_of_uleb128 (die
->die_abbrev
);
7823 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7825 switch (AT_class (a
))
7827 case dw_val_class_addr
:
7828 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7830 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7831 size
+= size_of_uleb128 (AT_index (a
));
7834 size
+= DWARF2_ADDR_SIZE
;
7836 case dw_val_class_offset
:
7837 size
+= DWARF_OFFSET_SIZE
;
7839 case dw_val_class_loc
:
7841 unsigned long lsize
= size_of_locs (AT_loc (a
));
7844 if (dwarf_version
>= 4)
7845 size
+= size_of_uleb128 (lsize
);
7847 size
+= constant_size (lsize
);
7851 case dw_val_class_loc_list
:
7852 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7854 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7855 size
+= size_of_uleb128 (AT_index (a
));
7858 size
+= DWARF_OFFSET_SIZE
;
7860 case dw_val_class_range_list
:
7861 size
+= DWARF_OFFSET_SIZE
;
7863 case dw_val_class_const
:
7864 size
+= size_of_sleb128 (AT_int (a
));
7866 case dw_val_class_unsigned_const
:
7868 int csize
= constant_size (AT_unsigned (a
));
7869 if (dwarf_version
== 3
7870 && a
->dw_attr
== DW_AT_data_member_location
7872 size
+= size_of_uleb128 (AT_unsigned (a
));
7877 case dw_val_class_const_double
:
7878 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7879 if (HOST_BITS_PER_WIDE_INT
>= 64)
7882 case dw_val_class_wide_int
:
7883 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
7884 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7885 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
7889 case dw_val_class_vec
:
7890 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7891 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7892 + a
->dw_attr_val
.v
.val_vec
.length
7893 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7895 case dw_val_class_flag
:
7896 if (dwarf_version
>= 4)
7897 /* Currently all add_AT_flag calls pass in 1 as last argument,
7898 so DW_FORM_flag_present can be used. If that ever changes,
7899 we'll need to use DW_FORM_flag and have some optimization
7900 in build_abbrev_table that will change those to
7901 DW_FORM_flag_present if it is set to 1 in all DIEs using
7902 the same abbrev entry. */
7903 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7907 case dw_val_class_die_ref
:
7908 if (AT_ref_external (a
))
7910 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7911 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7912 is sized by target address length, whereas in DWARF3
7913 it's always sized as an offset. */
7914 if (use_debug_types
)
7915 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7916 else if (dwarf_version
== 2)
7917 size
+= DWARF2_ADDR_SIZE
;
7919 size
+= DWARF_OFFSET_SIZE
;
7922 size
+= DWARF_OFFSET_SIZE
;
7924 case dw_val_class_fde_ref
:
7925 size
+= DWARF_OFFSET_SIZE
;
7927 case dw_val_class_lbl_id
:
7928 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7930 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7931 size
+= size_of_uleb128 (AT_index (a
));
7934 size
+= DWARF2_ADDR_SIZE
;
7936 case dw_val_class_lineptr
:
7937 case dw_val_class_macptr
:
7938 size
+= DWARF_OFFSET_SIZE
;
7940 case dw_val_class_str
:
7941 form
= AT_string_form (a
);
7942 if (form
== DW_FORM_strp
)
7943 size
+= DWARF_OFFSET_SIZE
;
7944 else if (form
== DW_FORM_GNU_str_index
)
7945 size
+= size_of_uleb128 (AT_index (a
));
7947 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7949 case dw_val_class_file
:
7950 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7952 case dw_val_class_data8
:
7955 case dw_val_class_vms_delta
:
7956 size
+= DWARF_OFFSET_SIZE
;
7958 case dw_val_class_high_pc
:
7959 size
+= DWARF2_ADDR_SIZE
;
7969 /* Size the debugging information associated with a given DIE. Visits the
7970 DIE's children recursively. Updates the global variable next_die_offset, on
7971 each time through. Uses the current value of next_die_offset to update the
7972 die_offset field in each DIE. */
7975 calc_die_sizes (dw_die_ref die
)
7979 gcc_assert (die
->die_offset
== 0
7980 || (unsigned long int) die
->die_offset
== next_die_offset
);
7981 die
->die_offset
= next_die_offset
;
7982 next_die_offset
+= size_of_die (die
);
7984 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7986 if (die
->die_child
!= NULL
)
7987 /* Count the null byte used to terminate sibling lists. */
7988 next_die_offset
+= 1;
7991 /* Size just the base type children at the start of the CU.
7992 This is needed because build_abbrev needs to size locs
7993 and sizing of type based stack ops needs to know die_offset
7994 values for the base types. */
7997 calc_base_type_die_sizes (void)
7999 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8001 dw_die_ref base_type
;
8002 #if ENABLE_ASSERT_CHECKING
8003 dw_die_ref prev
= comp_unit_die ()->die_child
;
8006 die_offset
+= size_of_die (comp_unit_die ());
8007 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8009 #if ENABLE_ASSERT_CHECKING
8010 gcc_assert (base_type
->die_offset
== 0
8011 && prev
->die_sib
== base_type
8012 && base_type
->die_child
== NULL
8013 && base_type
->die_abbrev
);
8016 base_type
->die_offset
= die_offset
;
8017 die_offset
+= size_of_die (base_type
);
8021 /* Set the marks for a die and its children. We do this so
8022 that we know whether or not a reference needs to use FORM_ref_addr; only
8023 DIEs in the same CU will be marked. We used to clear out the offset
8024 and use that as the flag, but ran into ordering problems. */
8027 mark_dies (dw_die_ref die
)
8031 gcc_assert (!die
->die_mark
);
8034 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8037 /* Clear the marks for a die and its children. */
8040 unmark_dies (dw_die_ref die
)
8044 if (! use_debug_types
)
8045 gcc_assert (die
->die_mark
);
8048 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8051 /* Clear the marks for a die, its children and referred dies. */
8054 unmark_all_dies (dw_die_ref die
)
8064 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8066 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8067 if (AT_class (a
) == dw_val_class_die_ref
)
8068 unmark_all_dies (AT_ref (a
));
8071 /* Calculate if the entry should appear in the final output file. It may be
8072 from a pruned a type. */
8075 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8077 /* By limiting gnu pubnames to definitions only, gold can generate a
8078 gdb index without entries for declarations, which don't include
8079 enough information to be useful. */
8080 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8083 if (table
== pubname_table
)
8085 /* Enumerator names are part of the pubname table, but the
8086 parent DW_TAG_enumeration_type die may have been pruned.
8087 Don't output them if that is the case. */
8088 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8089 (p
->die
->die_parent
== NULL
8090 || !p
->die
->die_parent
->die_perennial_p
))
8093 /* Everything else in the pubname table is included. */
8097 /* The pubtypes table shouldn't include types that have been
8099 return (p
->die
->die_offset
!= 0
8100 || !flag_eliminate_unused_debug_types
);
8103 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8104 generated for the compilation unit. */
8106 static unsigned long
8107 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8112 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8114 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8115 FOR_EACH_VEC_ELT (*names
, i
, p
)
8116 if (include_pubname_in_output (names
, p
))
8117 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8119 size
+= DWARF_OFFSET_SIZE
;
8123 /* Return the size of the information in the .debug_aranges section. */
8125 static unsigned long
8126 size_of_aranges (void)
8130 size
= DWARF_ARANGES_HEADER_SIZE
;
8132 /* Count the address/length pair for this compilation unit. */
8133 if (text_section_used
)
8134 size
+= 2 * DWARF2_ADDR_SIZE
;
8135 if (cold_text_section_used
)
8136 size
+= 2 * DWARF2_ADDR_SIZE
;
8137 if (have_multiple_function_sections
)
8142 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8144 if (DECL_IGNORED_P (fde
->decl
))
8146 if (!fde
->in_std_section
)
8147 size
+= 2 * DWARF2_ADDR_SIZE
;
8148 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8149 size
+= 2 * DWARF2_ADDR_SIZE
;
8153 /* Count the two zero words used to terminated the address range table. */
8154 size
+= 2 * DWARF2_ADDR_SIZE
;
8158 /* Select the encoding of an attribute value. */
8160 static enum dwarf_form
8161 value_format (dw_attr_ref a
)
8163 switch (AT_class (a
))
8165 case dw_val_class_addr
:
8166 /* Only very few attributes allow DW_FORM_addr. */
8171 case DW_AT_entry_pc
:
8172 case DW_AT_trampoline
:
8173 return (AT_index (a
) == NOT_INDEXED
8174 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8178 switch (DWARF2_ADDR_SIZE
)
8181 return DW_FORM_data1
;
8183 return DW_FORM_data2
;
8185 return DW_FORM_data4
;
8187 return DW_FORM_data8
;
8191 case dw_val_class_range_list
:
8192 case dw_val_class_loc_list
:
8193 if (dwarf_version
>= 4)
8194 return DW_FORM_sec_offset
;
8196 case dw_val_class_vms_delta
:
8197 case dw_val_class_offset
:
8198 switch (DWARF_OFFSET_SIZE
)
8201 return DW_FORM_data4
;
8203 return DW_FORM_data8
;
8207 case dw_val_class_loc
:
8208 if (dwarf_version
>= 4)
8209 return DW_FORM_exprloc
;
8210 switch (constant_size (size_of_locs (AT_loc (a
))))
8213 return DW_FORM_block1
;
8215 return DW_FORM_block2
;
8217 return DW_FORM_block4
;
8221 case dw_val_class_const
:
8222 return DW_FORM_sdata
;
8223 case dw_val_class_unsigned_const
:
8224 switch (constant_size (AT_unsigned (a
)))
8227 return DW_FORM_data1
;
8229 return DW_FORM_data2
;
8231 /* In DWARF3 DW_AT_data_member_location with
8232 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8233 constant, so we need to use DW_FORM_udata if we need
8234 a large constant. */
8235 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8236 return DW_FORM_udata
;
8237 return DW_FORM_data4
;
8239 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8240 return DW_FORM_udata
;
8241 return DW_FORM_data8
;
8245 case dw_val_class_const_double
:
8246 switch (HOST_BITS_PER_WIDE_INT
)
8249 return DW_FORM_data2
;
8251 return DW_FORM_data4
;
8253 return DW_FORM_data8
;
8256 return DW_FORM_block1
;
8258 case dw_val_class_wide_int
:
8259 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8262 return DW_FORM_data1
;
8264 return DW_FORM_data2
;
8266 return DW_FORM_data4
;
8268 return DW_FORM_data8
;
8270 return DW_FORM_block1
;
8272 case dw_val_class_vec
:
8273 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8274 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8277 return DW_FORM_block1
;
8279 return DW_FORM_block2
;
8281 return DW_FORM_block4
;
8285 case dw_val_class_flag
:
8286 if (dwarf_version
>= 4)
8288 /* Currently all add_AT_flag calls pass in 1 as last argument,
8289 so DW_FORM_flag_present can be used. If that ever changes,
8290 we'll need to use DW_FORM_flag and have some optimization
8291 in build_abbrev_table that will change those to
8292 DW_FORM_flag_present if it is set to 1 in all DIEs using
8293 the same abbrev entry. */
8294 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8295 return DW_FORM_flag_present
;
8297 return DW_FORM_flag
;
8298 case dw_val_class_die_ref
:
8299 if (AT_ref_external (a
))
8300 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8303 case dw_val_class_fde_ref
:
8304 return DW_FORM_data
;
8305 case dw_val_class_lbl_id
:
8306 return (AT_index (a
) == NOT_INDEXED
8307 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8308 case dw_val_class_lineptr
:
8309 case dw_val_class_macptr
:
8310 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8311 case dw_val_class_str
:
8312 return AT_string_form (a
);
8313 case dw_val_class_file
:
8314 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8317 return DW_FORM_data1
;
8319 return DW_FORM_data2
;
8321 return DW_FORM_data4
;
8326 case dw_val_class_data8
:
8327 return DW_FORM_data8
;
8329 case dw_val_class_high_pc
:
8330 switch (DWARF2_ADDR_SIZE
)
8333 return DW_FORM_data1
;
8335 return DW_FORM_data2
;
8337 return DW_FORM_data4
;
8339 return DW_FORM_data8
;
8349 /* Output the encoding of an attribute value. */
8352 output_value_format (dw_attr_ref a
)
8354 enum dwarf_form form
= value_format (a
);
8356 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8359 /* Given a die and id, produce the appropriate abbreviations. */
8362 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8367 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8368 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8369 dwarf_tag_name (abbrev
->die_tag
));
8371 if (abbrev
->die_child
!= NULL
)
8372 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8374 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8376 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8378 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8379 dwarf_attr_name (a_attr
->dw_attr
));
8380 output_value_format (a_attr
);
8383 dw2_asm_output_data (1, 0, NULL
);
8384 dw2_asm_output_data (1, 0, NULL
);
8388 /* Output the .debug_abbrev section which defines the DIE abbreviation
8392 output_abbrev_section (void)
8394 unsigned long abbrev_id
;
8396 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8397 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8399 /* Terminate the table. */
8400 dw2_asm_output_data (1, 0, NULL
);
8403 /* Output a symbol we can use to refer to this DIE from another CU. */
8406 output_die_symbol (dw_die_ref die
)
8408 const char *sym
= die
->die_id
.die_symbol
;
8410 gcc_assert (!die
->comdat_type_p
);
8415 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8416 /* We make these global, not weak; if the target doesn't support
8417 .linkonce, it doesn't support combining the sections, so debugging
8419 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8421 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8424 /* Return a new location list, given the begin and end range, and the
8427 static inline dw_loc_list_ref
8428 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8429 const char *section
)
8431 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8433 retlist
->begin
= begin
;
8434 retlist
->begin_entry
= NULL
;
8436 retlist
->expr
= expr
;
8437 retlist
->section
= section
;
8442 /* Generate a new internal symbol for this location list node, if it
8443 hasn't got one yet. */
8446 gen_llsym (dw_loc_list_ref list
)
8448 gcc_assert (!list
->ll_symbol
);
8449 list
->ll_symbol
= gen_internal_sym ("LLST");
8452 /* Output the location list given to us. */
8455 output_loc_list (dw_loc_list_ref list_head
)
8457 dw_loc_list_ref curr
= list_head
;
8459 if (list_head
->emitted
)
8461 list_head
->emitted
= true;
8463 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8465 /* Walk the location list, and output each range + expression. */
8466 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8469 /* Don't output an entry that starts and ends at the same address. */
8470 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8472 size
= size_of_locs (curr
->expr
);
8473 /* If the expression is too large, drop it on the floor. We could
8474 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8475 in the expression, but >= 64KB expressions for a single value
8476 in a single range are unlikely very useful. */
8479 if (dwarf_split_debug_info
)
8481 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8482 "Location list start/length entry (%s)",
8483 list_head
->ll_symbol
);
8484 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8485 "Location list range start index (%s)",
8487 /* The length field is 4 bytes. If we ever need to support
8488 an 8-byte length, we can add a new DW_LLE code or fall back
8489 to DW_LLE_GNU_start_end_entry. */
8490 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8491 "Location list range length (%s)",
8492 list_head
->ll_symbol
);
8494 else if (!have_multiple_function_sections
)
8496 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8497 "Location list begin address (%s)",
8498 list_head
->ll_symbol
);
8499 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8500 "Location list end address (%s)",
8501 list_head
->ll_symbol
);
8505 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8506 "Location list begin address (%s)",
8507 list_head
->ll_symbol
);
8508 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8509 "Location list end address (%s)",
8510 list_head
->ll_symbol
);
8513 /* Output the block length for this list of location operations. */
8514 gcc_assert (size
<= 0xffff);
8515 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8517 output_loc_sequence (curr
->expr
, -1);
8520 if (dwarf_split_debug_info
)
8521 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8522 "Location list terminator (%s)",
8523 list_head
->ll_symbol
);
8526 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8527 "Location list terminator begin (%s)",
8528 list_head
->ll_symbol
);
8529 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8530 "Location list terminator end (%s)",
8531 list_head
->ll_symbol
);
8535 /* Output a range_list offset into the debug_range section. Emit a
8536 relocated reference if val_entry is NULL, otherwise, emit an
8537 indirect reference. */
8540 output_range_list_offset (dw_attr_ref a
)
8542 const char *name
= dwarf_attr_name (a
->dw_attr
);
8544 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8546 char *p
= strchr (ranges_section_label
, '\0');
8547 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8548 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8549 debug_ranges_section
, "%s", name
);
8553 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8554 "%s (offset from %s)", name
, ranges_section_label
);
8557 /* Output the offset into the debug_loc section. */
8560 output_loc_list_offset (dw_attr_ref a
)
8562 char *sym
= AT_loc_list (a
)->ll_symbol
;
8565 if (dwarf_split_debug_info
)
8566 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8567 "%s", dwarf_attr_name (a
->dw_attr
));
8569 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8570 "%s", dwarf_attr_name (a
->dw_attr
));
8573 /* Output an attribute's index or value appropriately. */
8576 output_attr_index_or_value (dw_attr_ref a
)
8578 const char *name
= dwarf_attr_name (a
->dw_attr
);
8580 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8582 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8585 switch (AT_class (a
))
8587 case dw_val_class_addr
:
8588 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8590 case dw_val_class_high_pc
:
8591 case dw_val_class_lbl_id
:
8592 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8594 case dw_val_class_loc_list
:
8595 output_loc_list_offset (a
);
8602 /* Output a type signature. */
8605 output_signature (const char *sig
, const char *name
)
8609 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8610 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8613 /* Output the DIE and its attributes. Called recursively to generate
8614 the definitions of each child DIE. */
8617 output_die (dw_die_ref die
)
8624 /* If someone in another CU might refer to us, set up a symbol for
8625 them to point to. */
8626 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8627 output_die_symbol (die
);
8629 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8630 (unsigned long)die
->die_offset
,
8631 dwarf_tag_name (die
->die_tag
));
8633 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8635 const char *name
= dwarf_attr_name (a
->dw_attr
);
8637 switch (AT_class (a
))
8639 case dw_val_class_addr
:
8640 output_attr_index_or_value (a
);
8643 case dw_val_class_offset
:
8644 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8648 case dw_val_class_range_list
:
8649 output_range_list_offset (a
);
8652 case dw_val_class_loc
:
8653 size
= size_of_locs (AT_loc (a
));
8655 /* Output the block length for this list of location operations. */
8656 if (dwarf_version
>= 4)
8657 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8659 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8661 output_loc_sequence (AT_loc (a
), -1);
8664 case dw_val_class_const
:
8665 /* ??? It would be slightly more efficient to use a scheme like is
8666 used for unsigned constants below, but gdb 4.x does not sign
8667 extend. Gdb 5.x does sign extend. */
8668 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8671 case dw_val_class_unsigned_const
:
8673 int csize
= constant_size (AT_unsigned (a
));
8674 if (dwarf_version
== 3
8675 && a
->dw_attr
== DW_AT_data_member_location
8677 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8679 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8683 case dw_val_class_const_double
:
8685 unsigned HOST_WIDE_INT first
, second
;
8687 if (HOST_BITS_PER_WIDE_INT
>= 64)
8688 dw2_asm_output_data (1,
8689 HOST_BITS_PER_DOUBLE_INT
8690 / HOST_BITS_PER_CHAR
,
8693 if (WORDS_BIG_ENDIAN
)
8695 first
= a
->dw_attr_val
.v
.val_double
.high
;
8696 second
= a
->dw_attr_val
.v
.val_double
.low
;
8700 first
= a
->dw_attr_val
.v
.val_double
.low
;
8701 second
= a
->dw_attr_val
.v
.val_double
.high
;
8704 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8706 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8711 case dw_val_class_wide_int
:
8714 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8715 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8716 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8717 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8720 if (WORDS_BIG_ENDIAN
)
8721 for (i
= len
; i
>= 0; --i
)
8723 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8728 for (i
= 0; i
< len
; ++i
)
8730 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8737 case dw_val_class_vec
:
8739 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8740 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8744 dw2_asm_output_data (constant_size (len
* elt_size
),
8745 len
* elt_size
, "%s", name
);
8746 if (elt_size
> sizeof (HOST_WIDE_INT
))
8751 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8754 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8755 "fp or vector constant word %u", i
);
8759 case dw_val_class_flag
:
8760 if (dwarf_version
>= 4)
8762 /* Currently all add_AT_flag calls pass in 1 as last argument,
8763 so DW_FORM_flag_present can be used. If that ever changes,
8764 we'll need to use DW_FORM_flag and have some optimization
8765 in build_abbrev_table that will change those to
8766 DW_FORM_flag_present if it is set to 1 in all DIEs using
8767 the same abbrev entry. */
8768 gcc_assert (AT_flag (a
) == 1);
8770 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8771 ASM_COMMENT_START
, name
);
8774 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8777 case dw_val_class_loc_list
:
8778 output_attr_index_or_value (a
);
8781 case dw_val_class_die_ref
:
8782 if (AT_ref_external (a
))
8784 if (AT_ref (a
)->comdat_type_p
)
8786 comdat_type_node_ref type_node
=
8787 AT_ref (a
)->die_id
.die_type_node
;
8789 gcc_assert (type_node
);
8790 output_signature (type_node
->signature
, name
);
8794 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8798 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8799 length, whereas in DWARF3 it's always sized as an
8801 if (dwarf_version
== 2)
8802 size
= DWARF2_ADDR_SIZE
;
8804 size
= DWARF_OFFSET_SIZE
;
8805 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8811 gcc_assert (AT_ref (a
)->die_offset
);
8812 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8817 case dw_val_class_fde_ref
:
8821 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8822 a
->dw_attr_val
.v
.val_fde_index
* 2);
8823 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8828 case dw_val_class_vms_delta
:
8829 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8830 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8834 case dw_val_class_lbl_id
:
8835 output_attr_index_or_value (a
);
8838 case dw_val_class_lineptr
:
8839 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8840 debug_line_section
, "%s", name
);
8843 case dw_val_class_macptr
:
8844 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8845 debug_macinfo_section
, "%s", name
);
8848 case dw_val_class_str
:
8849 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8850 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8851 a
->dw_attr_val
.v
.val_str
->label
,
8853 "%s: \"%s\"", name
, AT_string (a
));
8854 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8855 dw2_asm_output_data_uleb128 (AT_index (a
),
8856 "%s: \"%s\"", name
, AT_string (a
));
8858 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8861 case dw_val_class_file
:
8863 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8865 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8866 a
->dw_attr_val
.v
.val_file
->filename
);
8870 case dw_val_class_data8
:
8874 for (i
= 0; i
< 8; i
++)
8875 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8876 i
== 0 ? "%s" : NULL
, name
);
8880 case dw_val_class_high_pc
:
8881 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8882 get_AT_low_pc (die
), "DW_AT_high_pc");
8890 FOR_EACH_CHILD (die
, c
, output_die (c
));
8892 /* Add null byte to terminate sibling list. */
8893 if (die
->die_child
!= NULL
)
8894 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8895 (unsigned long) die
->die_offset
);
8898 /* Output the compilation unit that appears at the beginning of the
8899 .debug_info section, and precedes the DIE descriptions. */
8902 output_compilation_unit_header (void)
8904 int ver
= dwarf_version
;
8906 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8907 dw2_asm_output_data (4, 0xffffffff,
8908 "Initial length escape value indicating 64-bit DWARF extension");
8909 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8910 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8911 "Length of Compilation Unit Info");
8912 dw2_asm_output_data (2, ver
, "DWARF version number");
8913 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8914 debug_abbrev_section
,
8915 "Offset Into Abbrev. Section");
8916 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8919 /* Output the compilation unit DIE and its children. */
8922 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8924 const char *secname
, *oldsym
;
8926 external_ref_hash_type extern_map
;
8928 /* Unless we are outputting main CU, we may throw away empty ones. */
8929 if (!output_if_empty
&& die
->die_child
== NULL
)
8932 /* Even if there are no children of this DIE, we must output the information
8933 about the compilation unit. Otherwise, on an empty translation unit, we
8934 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8935 will then complain when examining the file. First mark all the DIEs in
8936 this CU so we know which get local refs. */
8939 extern_map
= optimize_external_refs (die
);
8941 build_abbrev_table (die
, extern_map
);
8943 extern_map
.dispose ();
8945 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8946 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8947 calc_die_sizes (die
);
8949 oldsym
= die
->die_id
.die_symbol
;
8952 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8954 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8956 die
->die_id
.die_symbol
= NULL
;
8957 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8961 switch_to_section (debug_info_section
);
8962 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8963 info_section_emitted
= true;
8966 /* Output debugging information. */
8967 output_compilation_unit_header ();
8970 /* Leave the marks on the main CU, so we can check them in
8975 die
->die_id
.die_symbol
= oldsym
;
8979 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8980 and .debug_pubtypes. This is configured per-target, but can be
8981 overridden by the -gpubnames or -gno-pubnames options. */
8984 want_pubnames (void)
8986 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8988 if (debug_generate_pub_sections
!= -1)
8989 return debug_generate_pub_sections
;
8990 return targetm
.want_debug_pub_sections
;
8993 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8996 add_AT_pubnames (dw_die_ref die
)
8998 if (want_pubnames ())
8999 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9002 /* Add a string attribute value to a skeleton DIE. */
9005 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9009 struct indirect_string_node
*node
;
9011 if (! skeleton_debug_str_hash
)
9012 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
9013 debug_str_eq
, NULL
);
9015 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9016 find_string_form (node
);
9017 if (node
->form
== DW_FORM_GNU_str_index
)
9018 node
->form
= DW_FORM_strp
;
9020 attr
.dw_attr
= attr_kind
;
9021 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9022 attr
.dw_attr_val
.val_entry
= NULL
;
9023 attr
.dw_attr_val
.v
.val_str
= node
;
9024 add_dwarf_attr (die
, &attr
);
9027 /* Helper function to generate top-level dies for skeleton debug_info and
9031 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9033 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9034 const char *comp_dir
= comp_dir_string ();
9036 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9037 if (comp_dir
!= NULL
)
9038 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9039 add_AT_pubnames (die
);
9040 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9043 /* Return the single type-unit die for skeleton type units. */
9046 get_skeleton_type_unit (void)
9048 /* For dwarf_split_debug_sections with use_type info, all type units in the
9049 skeleton sections have identical dies (but different headers). This
9050 single die will be output many times. */
9052 static dw_die_ref skeleton_type_unit
= NULL
;
9054 if (skeleton_type_unit
== NULL
)
9056 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
9057 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
9058 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
9060 return skeleton_type_unit
;
9063 /* Output skeleton debug sections that point to the dwo file. */
9066 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9068 /* These attributes will be found in the full debug_info section. */
9069 remove_AT (comp_unit
, DW_AT_producer
);
9070 remove_AT (comp_unit
, DW_AT_language
);
9072 switch_to_section (debug_skeleton_info_section
);
9073 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9075 /* Produce the skeleton compilation-unit header. This one differs enough from
9076 a normal CU header that it's better not to call output_compilation_unit
9078 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9079 dw2_asm_output_data (4, 0xffffffff,
9080 "Initial length escape value indicating 64-bit DWARF extension");
9082 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9083 DWARF_COMPILE_UNIT_HEADER_SIZE
9084 - DWARF_INITIAL_LENGTH_SIZE
9085 + size_of_die (comp_unit
),
9086 "Length of Compilation Unit Info");
9087 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9088 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9089 debug_abbrev_section
,
9090 "Offset Into Abbrev. Section");
9091 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9093 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9094 output_die (comp_unit
);
9096 /* Build the skeleton debug_abbrev section. */
9097 switch_to_section (debug_skeleton_abbrev_section
);
9098 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9100 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9101 if (use_debug_types
)
9102 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
9104 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9107 /* Output a comdat type unit DIE and its children. */
9110 output_comdat_type_unit (comdat_type_node
*node
)
9112 const char *secname
;
9115 #if defined (OBJECT_FORMAT_ELF)
9118 external_ref_hash_type extern_map
;
9120 /* First mark all the DIEs in this CU so we know which get local refs. */
9121 mark_dies (node
->root_die
);
9123 extern_map
= optimize_external_refs (node
->root_die
);
9125 build_abbrev_table (node
->root_die
, extern_map
);
9127 extern_map
.dispose ();
9129 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9130 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9131 calc_die_sizes (node
->root_die
);
9133 #if defined (OBJECT_FORMAT_ELF)
9134 if (!dwarf_split_debug_info
)
9135 secname
= ".debug_types";
9137 secname
= ".debug_types.dwo";
9139 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9140 sprintf (tmp
, "wt.");
9141 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9142 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9143 comdat_key
= get_identifier (tmp
);
9144 targetm
.asm_out
.named_section (secname
,
9145 SECTION_DEBUG
| SECTION_LINKONCE
,
9148 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9149 sprintf (tmp
, ".gnu.linkonce.wt.");
9150 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9151 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9153 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9156 /* Output debugging information. */
9157 output_compilation_unit_header ();
9158 output_signature (node
->signature
, "Type Signature");
9159 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9160 "Offset to Type DIE");
9161 output_die (node
->root_die
);
9163 unmark_dies (node
->root_die
);
9165 #if defined (OBJECT_FORMAT_ELF)
9166 if (dwarf_split_debug_info
)
9168 /* Produce the skeleton type-unit header. */
9169 const char *secname
= ".debug_types";
9171 targetm
.asm_out
.named_section (secname
,
9172 SECTION_DEBUG
| SECTION_LINKONCE
,
9174 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9175 dw2_asm_output_data (4, 0xffffffff,
9176 "Initial length escape value indicating 64-bit DWARF extension");
9178 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9179 DWARF_COMPILE_UNIT_HEADER_SIZE
9180 - DWARF_INITIAL_LENGTH_SIZE
9181 + size_of_die (get_skeleton_type_unit ())
9182 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9183 "Length of Type Unit Info");
9184 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9185 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9186 debug_skeleton_abbrev_section_label
,
9187 debug_abbrev_section
,
9188 "Offset Into Abbrev. Section");
9189 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9190 output_signature (node
->signature
, "Type Signature");
9191 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9193 output_die (get_skeleton_type_unit ());
9198 /* Return the DWARF2/3 pubname associated with a decl. */
9201 dwarf2_name (tree decl
, int scope
)
9203 if (DECL_NAMELESS (decl
))
9205 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9208 /* Add a new entry to .debug_pubnames if appropriate. */
9211 add_pubname_string (const char *str
, dw_die_ref die
)
9216 e
.name
= xstrdup (str
);
9217 vec_safe_push (pubname_table
, e
);
9221 add_pubname (tree decl
, dw_die_ref die
)
9223 if (!want_pubnames ())
9226 /* Don't add items to the table when we expect that the consumer will have
9227 just read the enclosing die. For example, if the consumer is looking at a
9228 class_member, it will either be inside the class already, or will have just
9229 looked up the class to find the member. Either way, searching the class is
9230 faster than searching the index. */
9231 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9232 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9234 const char *name
= dwarf2_name (decl
, 1);
9237 add_pubname_string (name
, die
);
9241 /* Add an enumerator to the pubnames section. */
9244 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9248 gcc_assert (scope_name
);
9249 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9251 vec_safe_push (pubname_table
, e
);
9254 /* Add a new entry to .debug_pubtypes if appropriate. */
9257 add_pubtype (tree decl
, dw_die_ref die
)
9261 if (!want_pubnames ())
9264 if ((TREE_PUBLIC (decl
)
9265 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9266 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9269 const char *scope_name
= "";
9270 const char *sep
= is_cxx () ? "::" : ".";
9273 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9274 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9276 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9277 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9278 scope_name
= concat (scope_name
, sep
, NULL
);
9284 name
= type_tag (decl
);
9286 name
= lang_hooks
.dwarf_name (decl
, 1);
9288 /* If we don't have a name for the type, there's no point in adding
9290 if (name
!= NULL
&& name
[0] != '\0')
9293 e
.name
= concat (scope_name
, name
, NULL
);
9294 vec_safe_push (pubtype_table
, e
);
9297 /* Although it might be more consistent to add the pubinfo for the
9298 enumerators as their dies are created, they should only be added if the
9299 enum type meets the criteria above. So rather than re-check the parent
9300 enum type whenever an enumerator die is created, just output them all
9301 here. This isn't protected by the name conditional because anonymous
9302 enums don't have names. */
9303 if (die
->die_tag
== DW_TAG_enumeration_type
)
9307 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9312 /* Output a single entry in the pubnames table. */
9315 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9317 dw_die_ref die
= entry
->die
;
9318 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9320 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9322 if (debug_generate_pub_sections
== 2)
9324 /* This logic follows gdb's method for determining the value of the flag
9326 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9327 switch (die
->die_tag
)
9329 case DW_TAG_typedef
:
9330 case DW_TAG_base_type
:
9331 case DW_TAG_subrange_type
:
9332 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9333 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9335 case DW_TAG_enumerator
:
9336 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9337 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9338 if (!is_cxx () && !is_java ())
9339 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9341 case DW_TAG_subprogram
:
9342 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9343 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9345 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9347 case DW_TAG_constant
:
9348 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9349 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9350 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9352 case DW_TAG_variable
:
9353 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9354 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9355 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9357 case DW_TAG_namespace
:
9358 case DW_TAG_imported_declaration
:
9359 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9361 case DW_TAG_class_type
:
9362 case DW_TAG_interface_type
:
9363 case DW_TAG_structure_type
:
9364 case DW_TAG_union_type
:
9365 case DW_TAG_enumeration_type
:
9366 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9367 if (!is_cxx () && !is_java ())
9368 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9371 /* An unusual tag. Leave the flag-byte empty. */
9374 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9378 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9382 /* Output the public names table used to speed up access to externally
9383 visible names; or the public types table used to find type definitions. */
9386 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9389 unsigned long pubnames_length
= size_of_pubnames (names
);
9392 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9393 dw2_asm_output_data (4, 0xffffffff,
9394 "Initial length escape value indicating 64-bit DWARF extension");
9395 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9397 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9398 dw2_asm_output_data (2, 2, "DWARF Version");
9400 if (dwarf_split_debug_info
)
9401 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9402 debug_skeleton_info_section
,
9403 "Offset of Compilation Unit Info");
9405 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9407 "Offset of Compilation Unit Info");
9408 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9409 "Compilation Unit Length");
9411 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9413 if (include_pubname_in_output (names
, pub
))
9415 dw_offset die_offset
= pub
->die
->die_offset
;
9417 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9418 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9419 gcc_assert (pub
->die
->die_mark
);
9421 /* If we're putting types in their own .debug_types sections,
9422 the .debug_pubtypes table will still point to the compile
9423 unit (not the type unit), so we want to use the offset of
9424 the skeleton DIE (if there is one). */
9425 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9427 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9429 if (type_node
!= NULL
)
9430 die_offset
= (type_node
->skeleton_die
!= NULL
9431 ? type_node
->skeleton_die
->die_offset
9435 output_pubname (die_offset
, pub
);
9439 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9442 /* Output public names and types tables if necessary. */
9445 output_pubtables (void)
9447 if (!want_pubnames () || !info_section_emitted
)
9450 switch_to_section (debug_pubnames_section
);
9451 output_pubnames (pubname_table
);
9452 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9453 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9454 simply won't look for the section. */
9455 switch_to_section (debug_pubtypes_section
);
9456 output_pubnames (pubtype_table
);
9460 /* Output the information that goes into the .debug_aranges table.
9461 Namely, define the beginning and ending address range of the
9462 text section generated for this compilation unit. */
9465 output_aranges (unsigned long aranges_length
)
9469 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9470 dw2_asm_output_data (4, 0xffffffff,
9471 "Initial length escape value indicating 64-bit DWARF extension");
9472 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9473 "Length of Address Ranges Info");
9474 /* Version number for aranges is still 2, even in DWARF3. */
9475 dw2_asm_output_data (2, 2, "DWARF Version");
9476 if (dwarf_split_debug_info
)
9477 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9478 debug_skeleton_info_section
,
9479 "Offset of Compilation Unit Info");
9481 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9483 "Offset of Compilation Unit Info");
9484 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9485 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9487 /* We need to align to twice the pointer size here. */
9488 if (DWARF_ARANGES_PAD_SIZE
)
9490 /* Pad using a 2 byte words so that padding is correct for any
9492 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9493 2 * DWARF2_ADDR_SIZE
);
9494 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9495 dw2_asm_output_data (2, 0, NULL
);
9498 /* It is necessary not to output these entries if the sections were
9499 not used; if the sections were not used, the length will be 0 and
9500 the address may end up as 0 if the section is discarded by ld
9501 --gc-sections, leaving an invalid (0, 0) entry that can be
9502 confused with the terminator. */
9503 if (text_section_used
)
9505 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9506 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9507 text_section_label
, "Length");
9509 if (cold_text_section_used
)
9511 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9513 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9514 cold_text_section_label
, "Length");
9517 if (have_multiple_function_sections
)
9522 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9524 if (DECL_IGNORED_P (fde
->decl
))
9526 if (!fde
->in_std_section
)
9528 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9530 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9531 fde
->dw_fde_begin
, "Length");
9533 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9535 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9537 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9538 fde
->dw_fde_second_begin
, "Length");
9543 /* Output the terminator words. */
9544 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9545 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9548 /* Add a new entry to .debug_ranges. Return the offset at which it
9552 add_ranges_num (int num
)
9554 unsigned int in_use
= ranges_table_in_use
;
9556 if (in_use
== ranges_table_allocated
)
9558 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9559 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9560 ranges_table_allocated
);
9561 memset (ranges_table
+ ranges_table_in_use
, 0,
9562 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9565 ranges_table
[in_use
].num
= num
;
9566 ranges_table_in_use
= in_use
+ 1;
9568 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9571 /* Add a new entry to .debug_ranges corresponding to a block, or a
9572 range terminator if BLOCK is NULL. */
9575 add_ranges (const_tree block
)
9577 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9580 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9581 When using dwarf_split_debug_info, address attributes in dies destined
9582 for the final executable should be direct references--setting the
9583 parameter force_direct ensures this behavior. */
9586 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9587 bool *added
, bool force_direct
)
9589 unsigned int in_use
= ranges_by_label_in_use
;
9590 unsigned int offset
;
9592 if (in_use
== ranges_by_label_allocated
)
9594 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9595 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9597 ranges_by_label_allocated
);
9598 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9599 RANGES_TABLE_INCREMENT
9600 * sizeof (struct dw_ranges_by_label_struct
));
9603 ranges_by_label
[in_use
].begin
= begin
;
9604 ranges_by_label
[in_use
].end
= end
;
9605 ranges_by_label_in_use
= in_use
+ 1;
9607 offset
= add_ranges_num (-(int)in_use
- 1);
9610 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9616 output_ranges (void)
9619 static const char *const start_fmt
= "Offset %#x";
9620 const char *fmt
= start_fmt
;
9622 for (i
= 0; i
< ranges_table_in_use
; i
++)
9624 int block_num
= ranges_table
[i
].num
;
9628 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9629 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9631 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9632 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9634 /* If all code is in the text section, then the compilation
9635 unit base address defaults to DW_AT_low_pc, which is the
9636 base of the text section. */
9637 if (!have_multiple_function_sections
)
9639 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9641 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9642 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9643 text_section_label
, NULL
);
9646 /* Otherwise, the compilation unit base address is zero,
9647 which allows us to use absolute addresses, and not worry
9648 about whether the target supports cross-section
9652 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9653 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9654 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9660 /* Negative block_num stands for an index into ranges_by_label. */
9661 else if (block_num
< 0)
9663 int lab_idx
= - block_num
- 1;
9665 if (!have_multiple_function_sections
)
9669 /* If we ever use add_ranges_by_labels () for a single
9670 function section, all we have to do is to take out
9672 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9673 ranges_by_label
[lab_idx
].begin
,
9675 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9676 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9677 ranges_by_label
[lab_idx
].end
,
9678 text_section_label
, NULL
);
9683 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9684 ranges_by_label
[lab_idx
].begin
,
9685 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9686 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9687 ranges_by_label
[lab_idx
].end
,
9693 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9694 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9700 /* Data structure containing information about input files. */
9703 const char *path
; /* Complete file name. */
9704 const char *fname
; /* File name part. */
9705 int length
; /* Length of entire string. */
9706 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9707 int dir_idx
; /* Index in directory table. */
9710 /* Data structure containing information about directories with source
9714 const char *path
; /* Path including directory name. */
9715 int length
; /* Path length. */
9716 int prefix
; /* Index of directory entry which is a prefix. */
9717 int count
; /* Number of files in this directory. */
9718 int dir_idx
; /* Index of directory used as base. */
9721 /* Callback function for file_info comparison. We sort by looking at
9722 the directories in the path. */
9725 file_info_cmp (const void *p1
, const void *p2
)
9727 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9728 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9729 const unsigned char *cp1
;
9730 const unsigned char *cp2
;
9732 /* Take care of file names without directories. We need to make sure that
9733 we return consistent values to qsort since some will get confused if
9734 we return the same value when identical operands are passed in opposite
9735 orders. So if neither has a directory, return 0 and otherwise return
9736 1 or -1 depending on which one has the directory. */
9737 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9738 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9740 cp1
= (const unsigned char *) s1
->path
;
9741 cp2
= (const unsigned char *) s2
->path
;
9747 /* Reached the end of the first path? If so, handle like above. */
9748 if ((cp1
== (const unsigned char *) s1
->fname
)
9749 || (cp2
== (const unsigned char *) s2
->fname
))
9750 return ((cp2
== (const unsigned char *) s2
->fname
)
9751 - (cp1
== (const unsigned char *) s1
->fname
));
9753 /* Character of current path component the same? */
9754 else if (*cp1
!= *cp2
)
9759 struct file_name_acquire_data
9761 struct file_info
*files
;
9766 /* Traversal function for the hash table. */
9769 file_name_acquire (void ** slot
, void *data
)
9771 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9772 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9773 struct file_info
*fi
;
9776 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9778 if (! d
->emitted_number
)
9781 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9783 fi
= fnad
->files
+ fnad
->used_files
++;
9785 /* Skip all leading "./". */
9787 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9790 /* Create a new array entry. */
9792 fi
->length
= strlen (f
);
9795 /* Search for the file name part. */
9796 f
= strrchr (f
, DIR_SEPARATOR
);
9797 #if defined (DIR_SEPARATOR_2)
9799 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9803 if (f
== NULL
|| f
< g
)
9809 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9813 /* Output the directory table and the file name table. We try to minimize
9814 the total amount of memory needed. A heuristic is used to avoid large
9815 slowdowns with many input files. */
9818 output_file_names (void)
9820 struct file_name_acquire_data fnad
;
9822 struct file_info
*files
;
9823 struct dir_info
*dirs
;
9831 if (!last_emitted_file
)
9833 dw2_asm_output_data (1, 0, "End directory table");
9834 dw2_asm_output_data (1, 0, "End file name table");
9838 numfiles
= last_emitted_file
->emitted_number
;
9840 /* Allocate the various arrays we need. */
9841 files
= XALLOCAVEC (struct file_info
, numfiles
);
9842 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9845 fnad
.used_files
= 0;
9846 fnad
.max_files
= numfiles
;
9847 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9848 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9850 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9852 /* Find all the different directories used. */
9853 dirs
[0].path
= files
[0].path
;
9854 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9855 dirs
[0].prefix
= -1;
9857 dirs
[0].dir_idx
= 0;
9858 files
[0].dir_idx
= 0;
9861 for (i
= 1; i
< numfiles
; i
++)
9862 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9863 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9864 dirs
[ndirs
- 1].length
) == 0)
9866 /* Same directory as last entry. */
9867 files
[i
].dir_idx
= ndirs
- 1;
9868 ++dirs
[ndirs
- 1].count
;
9874 /* This is a new directory. */
9875 dirs
[ndirs
].path
= files
[i
].path
;
9876 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9877 dirs
[ndirs
].count
= 1;
9878 dirs
[ndirs
].dir_idx
= ndirs
;
9879 files
[i
].dir_idx
= ndirs
;
9881 /* Search for a prefix. */
9882 dirs
[ndirs
].prefix
= -1;
9883 for (j
= 0; j
< ndirs
; j
++)
9884 if (dirs
[j
].length
< dirs
[ndirs
].length
9885 && dirs
[j
].length
> 1
9886 && (dirs
[ndirs
].prefix
== -1
9887 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9888 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9889 dirs
[ndirs
].prefix
= j
;
9894 /* Now to the actual work. We have to find a subset of the directories which
9895 allow expressing the file name using references to the directory table
9896 with the least amount of characters. We do not do an exhaustive search
9897 where we would have to check out every combination of every single
9898 possible prefix. Instead we use a heuristic which provides nearly optimal
9899 results in most cases and never is much off. */
9900 saved
= XALLOCAVEC (int, ndirs
);
9901 savehere
= XALLOCAVEC (int, ndirs
);
9903 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9904 for (i
= 0; i
< ndirs
; i
++)
9909 /* We can always save some space for the current directory. But this
9910 does not mean it will be enough to justify adding the directory. */
9911 savehere
[i
] = dirs
[i
].length
;
9912 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9914 for (j
= i
+ 1; j
< ndirs
; j
++)
9917 if (saved
[j
] < dirs
[i
].length
)
9919 /* Determine whether the dirs[i] path is a prefix of the
9924 while (k
!= -1 && k
!= (int) i
)
9929 /* Yes it is. We can possibly save some memory by
9930 writing the filenames in dirs[j] relative to
9932 savehere
[j
] = dirs
[i
].length
;
9933 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9938 /* Check whether we can save enough to justify adding the dirs[i]
9940 if (total
> dirs
[i
].length
+ 1)
9942 /* It's worthwhile adding. */
9943 for (j
= i
; j
< ndirs
; j
++)
9944 if (savehere
[j
] > 0)
9946 /* Remember how much we saved for this directory so far. */
9947 saved
[j
] = savehere
[j
];
9949 /* Remember the prefix directory. */
9950 dirs
[j
].dir_idx
= i
;
9955 /* Emit the directory name table. */
9956 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9957 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9958 dw2_asm_output_nstring (dirs
[i
].path
,
9960 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9961 "Directory Entry: %#x", i
+ idx_offset
);
9963 dw2_asm_output_data (1, 0, "End directory table");
9965 /* We have to emit them in the order of emitted_number since that's
9966 used in the debug info generation. To do this efficiently we
9967 generate a back-mapping of the indices first. */
9968 backmap
= XALLOCAVEC (int, numfiles
);
9969 for (i
= 0; i
< numfiles
; i
++)
9970 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9972 /* Now write all the file names. */
9973 for (i
= 0; i
< numfiles
; i
++)
9975 int file_idx
= backmap
[i
];
9976 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9978 #ifdef VMS_DEBUGGING_INFO
9979 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9981 /* Setting these fields can lead to debugger miscomparisons,
9982 but VMS Debug requires them to be set correctly. */
9987 int maxfilelen
= strlen (files
[file_idx
].path
)
9988 + dirs
[dir_idx
].length
9989 + MAX_VMS_VERSION_LEN
+ 1;
9990 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9992 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9993 snprintf (filebuf
, maxfilelen
, "%s;%d",
9994 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9996 dw2_asm_output_nstring
9997 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9999 /* Include directory index. */
10000 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10002 /* Modification time. */
10003 dw2_asm_output_data_uleb128
10004 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10008 /* File length in bytes. */
10009 dw2_asm_output_data_uleb128
10010 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10014 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10015 "File Entry: %#x", (unsigned) i
+ 1);
10017 /* Include directory index. */
10018 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10020 /* Modification time. */
10021 dw2_asm_output_data_uleb128 (0, NULL
);
10023 /* File length in bytes. */
10024 dw2_asm_output_data_uleb128 (0, NULL
);
10025 #endif /* VMS_DEBUGGING_INFO */
10028 dw2_asm_output_data (1, 0, "End file name table");
10032 /* Output one line number table into the .debug_line section. */
10035 output_one_line_info_table (dw_line_info_table
*table
)
10037 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10038 unsigned int current_line
= 1;
10039 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10040 dw_line_info_entry
*ent
;
10043 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10045 switch (ent
->opcode
)
10047 case LI_set_address
:
10048 /* ??? Unfortunately, we have little choice here currently, and
10049 must always use the most general form. GCC does not know the
10050 address delta itself, so we can't use DW_LNS_advance_pc. Many
10051 ports do have length attributes which will give an upper bound
10052 on the address range. We could perhaps use length attributes
10053 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10054 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10056 /* This can handle any delta. This takes
10057 4+DWARF2_ADDR_SIZE bytes. */
10058 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10059 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10060 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10061 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10065 if (ent
->val
== current_line
)
10067 /* We still need to start a new row, so output a copy insn. */
10068 dw2_asm_output_data (1, DW_LNS_copy
,
10069 "copy line %u", current_line
);
10073 int line_offset
= ent
->val
- current_line
;
10074 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10076 current_line
= ent
->val
;
10077 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10079 /* This can handle deltas from -10 to 234, using the current
10080 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10081 This takes 1 byte. */
10082 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10083 "line %u", current_line
);
10087 /* This can handle any delta. This takes at least 4 bytes,
10088 depending on the value being encoded. */
10089 dw2_asm_output_data (1, DW_LNS_advance_line
,
10090 "advance to line %u", current_line
);
10091 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10092 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10098 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10099 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10102 case LI_set_column
:
10103 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10104 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10107 case LI_negate_stmt
:
10108 current_is_stmt
= !current_is_stmt
;
10109 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10110 "is_stmt %d", current_is_stmt
);
10113 case LI_set_prologue_end
:
10114 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10115 "set prologue end");
10118 case LI_set_epilogue_begin
:
10119 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10120 "set epilogue begin");
10123 case LI_set_discriminator
:
10124 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10125 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10126 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10127 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10132 /* Emit debug info for the address of the end of the table. */
10133 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10134 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10135 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10136 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10138 dw2_asm_output_data (1, 0, "end sequence");
10139 dw2_asm_output_data_uleb128 (1, NULL
);
10140 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10143 /* Output the source line number correspondence information. This
10144 information goes into the .debug_line section. */
10147 output_line_info (bool prologue_only
)
10149 char l1
[20], l2
[20], p1
[20], p2
[20];
10150 int ver
= dwarf_version
;
10151 bool saw_one
= false;
10154 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10155 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10156 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10157 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10159 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10160 dw2_asm_output_data (4, 0xffffffff,
10161 "Initial length escape value indicating 64-bit DWARF extension");
10162 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10163 "Length of Source Line Info");
10164 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10166 dw2_asm_output_data (2, ver
, "DWARF Version");
10167 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10168 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10170 /* Define the architecture-dependent minimum instruction length (in bytes).
10171 In this implementation of DWARF, this field is used for information
10172 purposes only. Since GCC generates assembly language, we have no
10173 a priori knowledge of how many instruction bytes are generated for each
10174 source line, and therefore can use only the DW_LNE_set_address and
10175 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10176 this as '1', which is "correct enough" for all architectures,
10177 and don't let the target override. */
10178 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10181 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10182 "Maximum Operations Per Instruction");
10183 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10184 "Default is_stmt_start flag");
10185 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10186 "Line Base Value (Special Opcodes)");
10187 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10188 "Line Range Value (Special Opcodes)");
10189 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10190 "Special Opcode Base");
10192 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10197 case DW_LNS_advance_pc
:
10198 case DW_LNS_advance_line
:
10199 case DW_LNS_set_file
:
10200 case DW_LNS_set_column
:
10201 case DW_LNS_fixed_advance_pc
:
10202 case DW_LNS_set_isa
:
10210 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10214 /* Write out the information about the files we use. */
10215 output_file_names ();
10216 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10219 /* Output the marker for the end of the line number info. */
10220 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10224 if (separate_line_info
)
10226 dw_line_info_table
*table
;
10229 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10232 output_one_line_info_table (table
);
10236 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10238 output_one_line_info_table (cold_text_section_line_info
);
10242 /* ??? Some Darwin linkers crash on a .debug_line section with no
10243 sequences. Further, merely a DW_LNE_end_sequence entry is not
10244 sufficient -- the address column must also be initialized.
10245 Make sure to output at least one set_address/end_sequence pair,
10246 choosing .text since that section is always present. */
10247 if (text_section_line_info
->in_use
|| !saw_one
)
10248 output_one_line_info_table (text_section_line_info
);
10250 /* Output the marker for the end of the line number info. */
10251 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10254 /* Given a pointer to a tree node for some base type, return a pointer to
10255 a DIE that describes the given type.
10257 This routine must only be called for GCC type nodes that correspond to
10258 Dwarf base (fundamental) types. */
10261 base_type_die (tree type
)
10263 dw_die_ref base_type_result
;
10264 enum dwarf_type encoding
;
10266 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10269 /* If this is a subtype that should not be emitted as a subrange type,
10270 use the base type. See subrange_type_for_debug_p. */
10271 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10272 type
= TREE_TYPE (type
);
10274 switch (TREE_CODE (type
))
10277 if ((dwarf_version
>= 4 || !dwarf_strict
)
10278 && TYPE_NAME (type
)
10279 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10280 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10281 && DECL_NAME (TYPE_NAME (type
)))
10283 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10284 if (strcmp (name
, "char16_t") == 0
10285 || strcmp (name
, "char32_t") == 0)
10287 encoding
= DW_ATE_UTF
;
10291 if (TYPE_STRING_FLAG (type
))
10293 if (TYPE_UNSIGNED (type
))
10294 encoding
= DW_ATE_unsigned_char
;
10296 encoding
= DW_ATE_signed_char
;
10298 else if (TYPE_UNSIGNED (type
))
10299 encoding
= DW_ATE_unsigned
;
10301 encoding
= DW_ATE_signed
;
10305 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10307 if (dwarf_version
>= 3 || !dwarf_strict
)
10308 encoding
= DW_ATE_decimal_float
;
10310 encoding
= DW_ATE_lo_user
;
10313 encoding
= DW_ATE_float
;
10316 case FIXED_POINT_TYPE
:
10317 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10318 encoding
= DW_ATE_lo_user
;
10319 else if (TYPE_UNSIGNED (type
))
10320 encoding
= DW_ATE_unsigned_fixed
;
10322 encoding
= DW_ATE_signed_fixed
;
10325 /* Dwarf2 doesn't know anything about complex ints, so use
10326 a user defined type for it. */
10328 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10329 encoding
= DW_ATE_complex_float
;
10331 encoding
= DW_ATE_lo_user
;
10335 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10336 encoding
= DW_ATE_boolean
;
10340 /* No other TREE_CODEs are Dwarf fundamental types. */
10341 gcc_unreachable ();
10344 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10346 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10347 int_size_in_bytes (type
));
10348 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10349 add_pubtype (type
, base_type_result
);
10351 return base_type_result
;
10354 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10355 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10358 is_base_type (tree type
)
10360 switch (TREE_CODE (type
))
10366 case FIXED_POINT_TYPE
:
10374 case QUAL_UNION_TYPE
:
10375 case ENUMERAL_TYPE
:
10376 case FUNCTION_TYPE
:
10379 case REFERENCE_TYPE
:
10387 gcc_unreachable ();
10393 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10394 node, return the size in bits for the type if it is a constant, or else
10395 return the alignment for the type if the type's size is not constant, or
10396 else return BITS_PER_WORD if the type actually turns out to be an
10397 ERROR_MARK node. */
10399 static inline unsigned HOST_WIDE_INT
10400 simple_type_size_in_bits (const_tree type
)
10402 if (TREE_CODE (type
) == ERROR_MARK
)
10403 return BITS_PER_WORD
;
10404 else if (TYPE_SIZE (type
) == NULL_TREE
)
10406 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10407 return tree_to_uhwi (TYPE_SIZE (type
));
10409 return TYPE_ALIGN (type
);
10412 /* Similarly, but return an offset_int instead of UHWI. */
10414 static inline offset_int
10415 offset_int_type_size_in_bits (const_tree type
)
10417 if (TREE_CODE (type
) == ERROR_MARK
)
10418 return BITS_PER_WORD
;
10419 else if (TYPE_SIZE (type
) == NULL_TREE
)
10421 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10422 return wi::to_offset (TYPE_SIZE (type
));
10424 return TYPE_ALIGN (type
);
10427 /* Given a pointer to a tree node for a subrange type, return a pointer
10428 to a DIE that describes the given type. */
10431 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10433 dw_die_ref subrange_die
;
10434 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10436 if (context_die
== NULL
)
10437 context_die
= comp_unit_die ();
10439 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10441 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10443 /* The size of the subrange type and its base type do not match,
10444 so we need to generate a size attribute for the subrange type. */
10445 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10449 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10451 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10453 return subrange_die
;
10456 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10457 entry that chains various modifiers in front of the given type. */
10460 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10461 dw_die_ref context_die
)
10463 enum tree_code code
= TREE_CODE (type
);
10464 dw_die_ref mod_type_die
;
10465 dw_die_ref sub_die
= NULL
;
10466 tree item_type
= NULL
;
10467 tree qualified_type
;
10468 tree name
, low
, high
;
10469 dw_die_ref mod_scope
;
10471 if (code
== ERROR_MARK
)
10474 /* See if we already have the appropriately qualified variant of
10477 = get_qualified_type (type
,
10478 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10479 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10481 if (qualified_type
== sizetype
10482 && TYPE_NAME (qualified_type
)
10483 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10485 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10487 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10488 && TYPE_PRECISION (t
)
10489 == TYPE_PRECISION (qualified_type
)
10490 && TYPE_UNSIGNED (t
)
10491 == TYPE_UNSIGNED (qualified_type
));
10492 qualified_type
= t
;
10495 /* If we do, then we can just use its DIE, if it exists. */
10496 if (qualified_type
)
10498 mod_type_die
= lookup_type_die (qualified_type
);
10500 return mod_type_die
;
10503 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10505 /* Handle C typedef types. */
10506 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10507 && !DECL_ARTIFICIAL (name
))
10509 tree dtype
= TREE_TYPE (name
);
10511 if (qualified_type
== dtype
)
10513 /* For a named type, use the typedef. */
10514 gen_type_die (qualified_type
, context_die
);
10515 return lookup_type_die (qualified_type
);
10517 else if (is_const_type
< TYPE_READONLY (dtype
)
10518 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10519 || (is_const_type
<= TYPE_READONLY (dtype
)
10520 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10521 && DECL_ORIGINAL_TYPE (name
) != type
))
10522 /* cv-unqualified version of named type. Just use the unnamed
10523 type to which it refers. */
10524 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10525 is_const_type
, is_volatile_type
,
10527 /* Else cv-qualified version of named type; fall through. */
10530 mod_scope
= scope_die_for (type
, context_die
);
10533 /* If both is_const_type and is_volatile_type, prefer the path
10534 which leads to a qualified type. */
10535 && (!is_volatile_type
10536 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10537 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10539 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10540 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10542 else if (is_volatile_type
)
10544 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10545 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10547 else if (code
== POINTER_TYPE
)
10549 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10550 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10551 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10552 item_type
= TREE_TYPE (type
);
10553 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10554 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10555 TYPE_ADDR_SPACE (item_type
));
10557 else if (code
== REFERENCE_TYPE
)
10559 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10560 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10563 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10564 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10565 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10566 item_type
= TREE_TYPE (type
);
10567 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10568 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10569 TYPE_ADDR_SPACE (item_type
));
10571 else if (code
== INTEGER_TYPE
10572 && TREE_TYPE (type
) != NULL_TREE
10573 && subrange_type_for_debug_p (type
, &low
, &high
))
10575 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10576 item_type
= TREE_TYPE (type
);
10578 else if (is_base_type (type
))
10579 mod_type_die
= base_type_die (type
);
10582 gen_type_die (type
, context_die
);
10584 /* We have to get the type_main_variant here (and pass that to the
10585 `lookup_type_die' routine) because the ..._TYPE node we have
10586 might simply be a *copy* of some original type node (where the
10587 copy was created to help us keep track of typedef names) and
10588 that copy might have a different TYPE_UID from the original
10590 if (TREE_CODE (type
) != VECTOR_TYPE
)
10591 return lookup_type_die (type_main_variant (type
));
10593 /* Vectors have the debugging information in the type,
10594 not the main variant. */
10595 return lookup_type_die (type
);
10598 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10599 don't output a DW_TAG_typedef, since there isn't one in the
10600 user's program; just attach a DW_AT_name to the type.
10601 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10602 if the base type already has the same name. */
10604 && ((TREE_CODE (name
) != TYPE_DECL
10605 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10606 || (!is_const_type
&& !is_volatile_type
)))
10607 || (TREE_CODE (name
) == TYPE_DECL
10608 && TREE_TYPE (name
) == qualified_type
10609 && DECL_NAME (name
))))
10611 if (TREE_CODE (name
) == TYPE_DECL
)
10612 /* Could just call add_name_and_src_coords_attributes here,
10613 but since this is a builtin type it doesn't have any
10614 useful source coordinates anyway. */
10615 name
= DECL_NAME (name
);
10616 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10618 /* This probably indicates a bug. */
10619 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10621 name
= TYPE_NAME (type
);
10623 && TREE_CODE (name
) == TYPE_DECL
)
10624 name
= DECL_NAME (name
);
10625 add_name_attribute (mod_type_die
,
10626 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10629 if (qualified_type
)
10630 equate_type_number_to_die (qualified_type
, mod_type_die
);
10633 /* We must do this after the equate_type_number_to_die call, in case
10634 this is a recursive type. This ensures that the modified_type_die
10635 recursion will terminate even if the type is recursive. Recursive
10636 types are possible in Ada. */
10637 sub_die
= modified_type_die (item_type
,
10638 TYPE_READONLY (item_type
),
10639 TYPE_VOLATILE (item_type
),
10642 if (sub_die
!= NULL
)
10643 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10645 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10646 if (TYPE_ARTIFICIAL (type
))
10647 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10649 return mod_type_die
;
10652 /* Generate DIEs for the generic parameters of T.
10653 T must be either a generic type or a generic function.
10654 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10657 gen_generic_params_dies (tree t
)
10661 dw_die_ref die
= NULL
;
10664 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10668 die
= lookup_type_die (t
);
10669 else if (DECL_P (t
))
10670 die
= lookup_decl_die (t
);
10674 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10676 /* T has no generic parameter. It means T is neither a generic type
10677 or function. End of story. */
10680 parms_num
= TREE_VEC_LENGTH (parms
);
10681 args
= lang_hooks
.get_innermost_generic_args (t
);
10682 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10683 non_default
= int_cst_value (TREE_CHAIN (args
));
10685 non_default
= TREE_VEC_LENGTH (args
);
10686 for (i
= 0; i
< parms_num
; i
++)
10688 tree parm
, arg
, arg_pack_elems
;
10689 dw_die_ref parm_die
;
10691 parm
= TREE_VEC_ELT (parms
, i
);
10692 arg
= TREE_VEC_ELT (args
, i
);
10693 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10694 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10696 if (parm
&& TREE_VALUE (parm
) && arg
)
10698 /* If PARM represents a template parameter pack,
10699 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10700 by DW_TAG_template_*_parameter DIEs for the argument
10701 pack elements of ARG. Note that ARG would then be
10702 an argument pack. */
10703 if (arg_pack_elems
)
10704 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10708 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10709 true /* emit name */, die
);
10710 if (i
>= non_default
)
10711 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10716 /* Create and return a DIE for PARM which should be
10717 the representation of a generic type parameter.
10718 For instance, in the C++ front end, PARM would be a template parameter.
10719 ARG is the argument to PARM.
10720 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10722 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10723 as a child node. */
10726 generic_parameter_die (tree parm
, tree arg
,
10728 dw_die_ref parent_die
)
10730 dw_die_ref tmpl_die
= NULL
;
10731 const char *name
= NULL
;
10733 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10736 /* We support non-type generic parameters and arguments,
10737 type generic parameters and arguments, as well as
10738 generic generic parameters (a.k.a. template template parameters in C++)
10740 if (TREE_CODE (parm
) == PARM_DECL
)
10741 /* PARM is a nontype generic parameter */
10742 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10743 else if (TREE_CODE (parm
) == TYPE_DECL
)
10744 /* PARM is a type generic parameter. */
10745 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10746 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10747 /* PARM is a generic generic parameter.
10748 Its DIE is a GNU extension. It shall have a
10749 DW_AT_name attribute to represent the name of the template template
10750 parameter, and a DW_AT_GNU_template_name attribute to represent the
10751 name of the template template argument. */
10752 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10755 gcc_unreachable ();
10761 /* If PARM is a generic parameter pack, it means we are
10762 emitting debug info for a template argument pack element.
10763 In other terms, ARG is a template argument pack element.
10764 In that case, we don't emit any DW_AT_name attribute for
10768 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10770 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10773 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10775 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10776 TMPL_DIE should have a child DW_AT_type attribute that is set
10777 to the type of the argument to PARM, which is ARG.
10778 If PARM is a type generic parameter, TMPL_DIE should have a
10779 child DW_AT_type that is set to ARG. */
10780 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10781 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10782 TREE_THIS_VOLATILE (tmpl_type
),
10787 /* So TMPL_DIE is a DIE representing a
10788 a generic generic template parameter, a.k.a template template
10789 parameter in C++ and arg is a template. */
10791 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10792 to the name of the argument. */
10793 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10795 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10798 if (TREE_CODE (parm
) == PARM_DECL
)
10799 /* So PARM is a non-type generic parameter.
10800 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10801 attribute of TMPL_DIE which value represents the value
10803 We must be careful here:
10804 The value of ARG might reference some function decls.
10805 We might currently be emitting debug info for a generic
10806 type and types are emitted before function decls, we don't
10807 know if the function decls referenced by ARG will actually be
10808 emitted after cgraph computations.
10809 So must defer the generation of the DW_AT_const_value to
10810 after cgraph is ready. */
10811 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10817 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10818 PARM_PACK must be a template parameter pack. The returned DIE
10819 will be child DIE of PARENT_DIE. */
10822 template_parameter_pack_die (tree parm_pack
,
10823 tree parm_pack_args
,
10824 dw_die_ref parent_die
)
10829 gcc_assert (parent_die
&& parm_pack
);
10831 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10832 add_name_and_src_coords_attributes (die
, parm_pack
);
10833 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10834 generic_parameter_die (parm_pack
,
10835 TREE_VEC_ELT (parm_pack_args
, j
),
10836 false /* Don't emit DW_AT_name */,
10841 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10842 an enumerated type. */
10845 type_is_enum (const_tree type
)
10847 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10850 /* Return the DBX register number described by a given RTL node. */
10852 static unsigned int
10853 dbx_reg_number (const_rtx rtl
)
10855 unsigned regno
= REGNO (rtl
);
10857 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10859 #ifdef LEAF_REG_REMAP
10860 if (crtl
->uses_only_leaf_regs
)
10862 int leaf_reg
= LEAF_REG_REMAP (regno
);
10863 if (leaf_reg
!= -1)
10864 regno
= (unsigned) leaf_reg
;
10868 regno
= DBX_REGISTER_NUMBER (regno
);
10869 gcc_assert (regno
!= INVALID_REGNUM
);
10873 /* Optionally add a DW_OP_piece term to a location description expression.
10874 DW_OP_piece is only added if the location description expression already
10875 doesn't end with DW_OP_piece. */
10878 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10880 dw_loc_descr_ref loc
;
10882 if (*list_head
!= NULL
)
10884 /* Find the end of the chain. */
10885 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10888 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10889 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10893 /* Return a location descriptor that designates a machine register or
10894 zero if there is none. */
10896 static dw_loc_descr_ref
10897 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10901 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10904 /* We only use "frame base" when we're sure we're talking about the
10905 post-prologue local stack frame. We do this by *not* running
10906 register elimination until this point, and recognizing the special
10907 argument pointer and soft frame pointer rtx's.
10908 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10909 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10910 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10912 dw_loc_descr_ref result
= NULL
;
10914 if (dwarf_version
>= 4 || !dwarf_strict
)
10916 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10919 add_loc_descr (&result
,
10920 new_loc_descr (DW_OP_stack_value
, 0, 0));
10925 regs
= targetm
.dwarf_register_span (rtl
);
10927 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10928 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10931 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10932 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10934 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10938 /* Return a location descriptor that designates a machine register for
10939 a given hard register number. */
10941 static dw_loc_descr_ref
10942 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10944 dw_loc_descr_ref reg_loc_descr
;
10948 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10950 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10952 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10953 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10955 return reg_loc_descr
;
10958 /* Given an RTL of a register, return a location descriptor that
10959 designates a value that spans more than one register. */
10961 static dw_loc_descr_ref
10962 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10963 enum var_init_status initialized
)
10966 dw_loc_descr_ref loc_result
= NULL
;
10968 /* Simple, contiguous registers. */
10969 if (regs
== NULL_RTX
)
10971 unsigned reg
= REGNO (rtl
);
10974 #ifdef LEAF_REG_REMAP
10975 if (crtl
->uses_only_leaf_regs
)
10977 int leaf_reg
= LEAF_REG_REMAP (reg
);
10978 if (leaf_reg
!= -1)
10979 reg
= (unsigned) leaf_reg
;
10983 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10984 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10986 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10991 dw_loc_descr_ref t
;
10993 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10994 VAR_INIT_STATUS_INITIALIZED
);
10995 add_loc_descr (&loc_result
, t
);
10996 add_loc_descr_op_piece (&loc_result
, size
);
11002 /* Now onto stupid register sets in non contiguous locations. */
11004 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11006 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11009 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11011 dw_loc_descr_ref t
;
11013 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11014 VAR_INIT_STATUS_INITIALIZED
);
11015 add_loc_descr (&loc_result
, t
);
11016 add_loc_descr_op_piece (&loc_result
, size
);
11019 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11020 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11024 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11026 /* Return a location descriptor that designates a constant i,
11027 as a compound operation from constant (i >> shift), constant shift
11030 static dw_loc_descr_ref
11031 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11033 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11034 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11035 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11039 /* Return a location descriptor that designates a constant. */
11041 static dw_loc_descr_ref
11042 int_loc_descriptor (HOST_WIDE_INT i
)
11044 enum dwarf_location_atom op
;
11046 /* Pick the smallest representation of a constant, rather than just
11047 defaulting to the LEB encoding. */
11050 int clz
= clz_hwi (i
);
11051 int ctz
= ctz_hwi (i
);
11053 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11054 else if (i
<= 0xff)
11055 op
= DW_OP_const1u
;
11056 else if (i
<= 0xffff)
11057 op
= DW_OP_const2u
;
11058 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11059 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11060 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11061 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11062 while DW_OP_const4u is 5 bytes. */
11063 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11064 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11065 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11066 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11067 while DW_OP_const4u is 5 bytes. */
11068 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11069 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11070 op
= DW_OP_const4u
;
11071 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11072 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11073 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11074 while DW_OP_constu of constant >= 0x100000000 takes at least
11076 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11077 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11078 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11079 >= HOST_BITS_PER_WIDE_INT
)
11080 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11081 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11082 while DW_OP_constu takes in this case at least 6 bytes. */
11083 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11084 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11085 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11086 && size_of_uleb128 (i
) > 6)
11087 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11088 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11095 op
= DW_OP_const1s
;
11096 else if (i
>= -0x8000)
11097 op
= DW_OP_const2s
;
11098 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11100 if (size_of_int_loc_descriptor (i
) < 5)
11102 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11103 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11106 op
= DW_OP_const4s
;
11110 if (size_of_int_loc_descriptor (i
)
11111 < (unsigned long) 1 + size_of_sleb128 (i
))
11113 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11114 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11121 return new_loc_descr (op
, i
, 0);
11124 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11125 without actually allocating it. */
11127 static unsigned long
11128 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11130 return size_of_int_loc_descriptor (i
>> shift
)
11131 + size_of_int_loc_descriptor (shift
)
11135 /* Return size_of_locs (int_loc_descriptor (i)) without
11136 actually allocating it. */
11138 static unsigned long
11139 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11148 else if (i
<= 0xff)
11150 else if (i
<= 0xffff)
11154 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11155 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11156 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11158 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11159 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11160 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11162 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11164 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11165 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11166 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11167 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11169 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11170 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11171 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11173 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11174 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11176 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11185 else if (i
>= -0x8000)
11187 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11189 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11191 s
= size_of_int_loc_descriptor (-i
) + 1;
11199 unsigned long r
= 1 + size_of_sleb128 (i
);
11200 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11202 s
= size_of_int_loc_descriptor (-i
) + 1;
11211 /* Return loc description representing "address" of integer value.
11212 This can appear only as toplevel expression. */
11214 static dw_loc_descr_ref
11215 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11218 dw_loc_descr_ref loc_result
= NULL
;
11220 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11223 litsize
= size_of_int_loc_descriptor (i
);
11224 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11225 is more compact. For DW_OP_stack_value we need:
11226 litsize + 1 (DW_OP_stack_value)
11227 and for DW_OP_implicit_value:
11228 1 (DW_OP_implicit_value) + 1 (length) + size. */
11229 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11231 loc_result
= int_loc_descriptor (i
);
11232 add_loc_descr (&loc_result
,
11233 new_loc_descr (DW_OP_stack_value
, 0, 0));
11237 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11239 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11240 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11244 /* Return a location descriptor that designates a base+offset location. */
11246 static dw_loc_descr_ref
11247 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11248 enum var_init_status initialized
)
11250 unsigned int regno
;
11251 dw_loc_descr_ref result
;
11252 dw_fde_ref fde
= cfun
->fde
;
11254 /* We only use "frame base" when we're sure we're talking about the
11255 post-prologue local stack frame. We do this by *not* running
11256 register elimination until this point, and recognizing the special
11257 argument pointer and soft frame pointer rtx's. */
11258 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11260 rtx elim
= (ira_use_lra_p
11261 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11262 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11266 if (GET_CODE (elim
) == PLUS
)
11268 offset
+= INTVAL (XEXP (elim
, 1));
11269 elim
= XEXP (elim
, 0);
11271 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11272 && (elim
== hard_frame_pointer_rtx
11273 || elim
== stack_pointer_rtx
))
11274 || elim
== (frame_pointer_needed
11275 ? hard_frame_pointer_rtx
11276 : stack_pointer_rtx
));
11278 /* If drap register is used to align stack, use frame
11279 pointer + offset to access stack variables. If stack
11280 is aligned without drap, use stack pointer + offset to
11281 access stack variables. */
11282 if (crtl
->stack_realign_tried
11283 && reg
== frame_pointer_rtx
)
11286 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11287 ? HARD_FRAME_POINTER_REGNUM
11289 return new_reg_loc_descr (base_reg
, offset
);
11292 gcc_assert (frame_pointer_fb_offset_valid
);
11293 offset
+= frame_pointer_fb_offset
;
11294 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11298 regno
= REGNO (reg
);
11299 #ifdef LEAF_REG_REMAP
11300 if (crtl
->uses_only_leaf_regs
)
11302 int leaf_reg
= LEAF_REG_REMAP (regno
);
11303 if (leaf_reg
!= -1)
11304 regno
= (unsigned) leaf_reg
;
11307 regno
= DWARF_FRAME_REGNUM (regno
);
11309 if (!optimize
&& fde
11310 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11312 /* Use cfa+offset to represent the location of arguments passed
11313 on the stack when drap is used to align stack.
11314 Only do this when not optimizing, for optimized code var-tracking
11315 is supposed to track where the arguments live and the register
11316 used as vdrap or drap in some spot might be used for something
11317 else in other part of the routine. */
11318 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11322 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11325 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11327 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11328 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11333 /* Return true if this RTL expression describes a base+offset calculation. */
11336 is_based_loc (const_rtx rtl
)
11338 return (GET_CODE (rtl
) == PLUS
11339 && ((REG_P (XEXP (rtl
, 0))
11340 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11341 && CONST_INT_P (XEXP (rtl
, 1)))));
11344 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11347 static dw_loc_descr_ref
11348 tls_mem_loc_descriptor (rtx mem
)
11351 dw_loc_descr_ref loc_result
;
11353 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11356 base
= get_base_address (MEM_EXPR (mem
));
11358 || TREE_CODE (base
) != VAR_DECL
11359 || !DECL_THREAD_LOCAL_P (base
))
11362 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11363 if (loc_result
== NULL
)
11366 if (MEM_OFFSET (mem
))
11367 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11372 /* Output debug info about reason why we failed to expand expression as dwarf
11376 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11378 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11380 fprintf (dump_file
, "Failed to expand as dwarf: ");
11382 print_generic_expr (dump_file
, expr
, dump_flags
);
11385 fprintf (dump_file
, "\n");
11386 print_rtl (dump_file
, rtl
);
11388 fprintf (dump_file
, "\nReason: %s\n", reason
);
11392 /* Helper function for const_ok_for_output, called either directly
11393 or via for_each_rtx. */
11396 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11400 if (GET_CODE (rtl
) == UNSPEC
)
11402 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11403 we can't express it in the debug info. */
11404 #ifdef ENABLE_CHECKING
11405 /* Don't complain about TLS UNSPECs, those are just too hard to
11406 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11407 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11408 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11409 if (XVECLEN (rtl
, 0) == 0
11410 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11411 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11412 inform (current_function_decl
11413 ? DECL_SOURCE_LOCATION (current_function_decl
)
11414 : UNKNOWN_LOCATION
,
11415 #if NUM_UNSPEC_VALUES > 0
11416 "non-delegitimized UNSPEC %s (%d) found in variable location",
11417 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11418 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11421 "non-delegitimized UNSPEC %d found in variable location",
11425 expansion_failed (NULL_TREE
, rtl
,
11426 "UNSPEC hasn't been delegitimized.\n");
11430 if (targetm
.const_not_ok_for_debug_p (rtl
))
11432 expansion_failed (NULL_TREE
, rtl
,
11433 "Expression rejected for debug by the backend.\n");
11437 if (GET_CODE (rtl
) != SYMBOL_REF
)
11440 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11443 get_pool_constant_mark (rtl
, &marked
);
11444 /* If all references to this pool constant were optimized away,
11445 it was not output and thus we can't represent it. */
11448 expansion_failed (NULL_TREE
, rtl
,
11449 "Constant was removed from constant pool.\n");
11454 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11457 /* Avoid references to external symbols in debug info, on several targets
11458 the linker might even refuse to link when linking a shared library,
11459 and in many other cases the relocations for .debug_info/.debug_loc are
11460 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11461 to be defined within the same shared library or executable are fine. */
11462 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11464 tree decl
= SYMBOL_REF_DECL (rtl
);
11466 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11468 expansion_failed (NULL_TREE
, rtl
,
11469 "Symbol not defined in current TU.\n");
11477 /* Return true if constant RTL can be emitted in DW_OP_addr or
11478 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11479 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11482 const_ok_for_output (rtx rtl
)
11484 if (GET_CODE (rtl
) == SYMBOL_REF
)
11485 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11487 if (GET_CODE (rtl
) == CONST
)
11488 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11493 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11494 if possible, NULL otherwise. */
11497 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11499 dw_die_ref type_die
;
11500 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11504 switch (TREE_CODE (type
))
11512 type_die
= lookup_type_die (type
);
11514 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11515 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11520 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11521 type matching MODE, or, if MODE is narrower than or as wide as
11522 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11525 static dw_loc_descr_ref
11526 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11528 enum machine_mode outer_mode
= mode
;
11529 dw_die_ref type_die
;
11530 dw_loc_descr_ref cvt
;
11532 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11534 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11537 type_die
= base_type_for_mode (outer_mode
, 1);
11538 if (type_die
== NULL
)
11540 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11541 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11542 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11543 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11544 add_loc_descr (&op
, cvt
);
11548 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11550 static dw_loc_descr_ref
11551 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11552 dw_loc_descr_ref op1
)
11554 dw_loc_descr_ref ret
= op0
;
11555 add_loc_descr (&ret
, op1
);
11556 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11557 if (STORE_FLAG_VALUE
!= 1)
11559 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11560 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11565 /* Return location descriptor for signed comparison OP RTL. */
11567 static dw_loc_descr_ref
11568 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11569 enum machine_mode mem_mode
)
11571 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11572 dw_loc_descr_ref op0
, op1
;
11575 if (op_mode
== VOIDmode
)
11576 op_mode
= GET_MODE (XEXP (rtl
, 1));
11577 if (op_mode
== VOIDmode
)
11581 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11582 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11585 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11586 VAR_INIT_STATUS_INITIALIZED
);
11587 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11588 VAR_INIT_STATUS_INITIALIZED
);
11590 if (op0
== NULL
|| op1
== NULL
)
11593 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11594 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11595 return compare_loc_descriptor (op
, op0
, op1
);
11597 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11599 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11600 dw_loc_descr_ref cvt
;
11602 if (type_die
== NULL
)
11604 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11605 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11606 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11607 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11608 add_loc_descr (&op0
, cvt
);
11609 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11610 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11611 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11612 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11613 add_loc_descr (&op1
, cvt
);
11614 return compare_loc_descriptor (op
, op0
, op1
);
11617 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11618 /* For eq/ne, if the operands are known to be zero-extended,
11619 there is no need to do the fancy shifting up. */
11620 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11622 dw_loc_descr_ref last0
, last1
;
11623 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11625 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11627 /* deref_size zero extends, and for constants we can check
11628 whether they are zero extended or not. */
11629 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11630 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11631 || (CONST_INT_P (XEXP (rtl
, 0))
11632 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11633 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11634 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11635 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11636 || (CONST_INT_P (XEXP (rtl
, 1))
11637 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11638 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11639 return compare_loc_descriptor (op
, op0
, op1
);
11641 /* EQ/NE comparison against constant in narrower type than
11642 DWARF2_ADDR_SIZE can be performed either as
11643 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11646 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11647 DW_OP_{eq,ne}. Pick whatever is shorter. */
11648 if (CONST_INT_P (XEXP (rtl
, 1))
11649 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11650 && (size_of_int_loc_descriptor (shift
) + 1
11651 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11652 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11653 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11654 & GET_MODE_MASK (op_mode
))))
11656 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11657 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11658 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11659 & GET_MODE_MASK (op_mode
));
11660 return compare_loc_descriptor (op
, op0
, op1
);
11663 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11664 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11665 if (CONST_INT_P (XEXP (rtl
, 1)))
11666 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11669 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11670 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11672 return compare_loc_descriptor (op
, op0
, op1
);
11675 /* Return location descriptor for unsigned comparison OP RTL. */
11677 static dw_loc_descr_ref
11678 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11679 enum machine_mode mem_mode
)
11681 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11682 dw_loc_descr_ref op0
, op1
;
11684 if (op_mode
== VOIDmode
)
11685 op_mode
= GET_MODE (XEXP (rtl
, 1));
11686 if (op_mode
== VOIDmode
)
11688 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11691 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11694 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11695 VAR_INIT_STATUS_INITIALIZED
);
11696 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11697 VAR_INIT_STATUS_INITIALIZED
);
11699 if (op0
== NULL
|| op1
== NULL
)
11702 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11704 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11705 dw_loc_descr_ref last0
, last1
;
11706 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11708 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11710 if (CONST_INT_P (XEXP (rtl
, 0)))
11711 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11712 /* deref_size zero extends, so no need to mask it again. */
11713 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11714 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11716 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11717 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11719 if (CONST_INT_P (XEXP (rtl
, 1)))
11720 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11721 /* deref_size zero extends, so no need to mask it again. */
11722 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11723 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11725 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11726 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11729 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11731 HOST_WIDE_INT bias
= 1;
11732 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11733 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11734 if (CONST_INT_P (XEXP (rtl
, 1)))
11735 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11736 + INTVAL (XEXP (rtl
, 1)));
11738 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11741 return compare_loc_descriptor (op
, op0
, op1
);
11744 /* Return location descriptor for {U,S}{MIN,MAX}. */
11746 static dw_loc_descr_ref
11747 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11748 enum machine_mode mem_mode
)
11750 enum dwarf_location_atom op
;
11751 dw_loc_descr_ref op0
, op1
, ret
;
11752 dw_loc_descr_ref bra_node
, drop_node
;
11755 && (GET_MODE_CLASS (mode
) != MODE_INT
11756 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11759 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11760 VAR_INIT_STATUS_INITIALIZED
);
11761 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11762 VAR_INIT_STATUS_INITIALIZED
);
11764 if (op0
== NULL
|| op1
== NULL
)
11767 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11768 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11769 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11770 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11772 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11774 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11775 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11776 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11777 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11778 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11780 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11782 HOST_WIDE_INT bias
= 1;
11783 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11784 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11785 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11788 else if (GET_MODE_CLASS (mode
) == MODE_INT
11789 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11791 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11792 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11793 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11794 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11795 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11797 else if (GET_MODE_CLASS (mode
) == MODE_INT
11798 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11800 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11801 dw_loc_descr_ref cvt
;
11802 if (type_die
== NULL
)
11804 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11805 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11806 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11807 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11808 add_loc_descr (&op0
, cvt
);
11809 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11810 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11811 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11812 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11813 add_loc_descr (&op1
, cvt
);
11816 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11821 add_loc_descr (&ret
, op1
);
11822 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11823 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11824 add_loc_descr (&ret
, bra_node
);
11825 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11826 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11827 add_loc_descr (&ret
, drop_node
);
11828 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11829 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11830 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11831 && GET_MODE_CLASS (mode
) == MODE_INT
11832 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11833 ret
= convert_descriptor_to_mode (mode
, ret
);
11837 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11838 but after converting arguments to type_die, afterwards
11839 convert back to unsigned. */
11841 static dw_loc_descr_ref
11842 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11843 enum machine_mode mode
, enum machine_mode mem_mode
)
11845 dw_loc_descr_ref cvt
, op0
, op1
;
11847 if (type_die
== NULL
)
11849 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11850 VAR_INIT_STATUS_INITIALIZED
);
11851 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11852 VAR_INIT_STATUS_INITIALIZED
);
11853 if (op0
== NULL
|| op1
== NULL
)
11855 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11856 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11857 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11858 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11859 add_loc_descr (&op0
, cvt
);
11860 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11861 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11862 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11863 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11864 add_loc_descr (&op1
, cvt
);
11865 add_loc_descr (&op0
, op1
);
11866 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11867 return convert_descriptor_to_mode (mode
, op0
);
11870 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11871 const0 is DW_OP_lit0 or corresponding typed constant,
11872 const1 is DW_OP_lit1 or corresponding typed constant
11873 and constMSB is constant with just the MSB bit set
11875 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11876 L1: const0 DW_OP_swap
11877 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11878 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11883 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11884 L1: const0 DW_OP_swap
11885 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11886 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11891 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11892 L1: const1 DW_OP_swap
11893 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11894 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11898 static dw_loc_descr_ref
11899 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11900 enum machine_mode mem_mode
)
11902 dw_loc_descr_ref op0
, ret
, tmp
;
11903 HOST_WIDE_INT valv
;
11904 dw_loc_descr_ref l1jump
, l1label
;
11905 dw_loc_descr_ref l2jump
, l2label
;
11906 dw_loc_descr_ref l3jump
, l3label
;
11907 dw_loc_descr_ref l4jump
, l4label
;
11910 if (GET_MODE_CLASS (mode
) != MODE_INT
11911 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11914 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11915 VAR_INIT_STATUS_INITIALIZED
);
11919 if (GET_CODE (rtl
) == CLZ
)
11921 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11922 valv
= GET_MODE_BITSIZE (mode
);
11924 else if (GET_CODE (rtl
) == FFS
)
11926 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11927 valv
= GET_MODE_BITSIZE (mode
);
11928 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11929 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11930 add_loc_descr (&ret
, l1jump
);
11931 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11932 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11933 VAR_INIT_STATUS_INITIALIZED
);
11936 add_loc_descr (&ret
, tmp
);
11937 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11938 add_loc_descr (&ret
, l4jump
);
11939 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11940 ? const1_rtx
: const0_rtx
,
11942 VAR_INIT_STATUS_INITIALIZED
);
11943 if (l1label
== NULL
)
11945 add_loc_descr (&ret
, l1label
);
11946 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11947 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11948 add_loc_descr (&ret
, l2label
);
11949 if (GET_CODE (rtl
) != CLZ
)
11951 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11952 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11953 << (GET_MODE_BITSIZE (mode
) - 1));
11955 msb
= immed_wide_int_const
11956 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
11957 GET_MODE_PRECISION (mode
)), mode
);
11958 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11959 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11960 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11961 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11963 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11964 VAR_INIT_STATUS_INITIALIZED
);
11967 add_loc_descr (&ret
, tmp
);
11968 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11969 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11970 add_loc_descr (&ret
, l3jump
);
11971 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11972 VAR_INIT_STATUS_INITIALIZED
);
11975 add_loc_descr (&ret
, tmp
);
11976 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11977 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11978 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11979 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11980 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11981 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11982 add_loc_descr (&ret
, l2jump
);
11983 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11984 add_loc_descr (&ret
, l3label
);
11985 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11986 add_loc_descr (&ret
, l4label
);
11987 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11988 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11989 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11990 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11991 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11992 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11993 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11994 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11998 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11999 const1 is DW_OP_lit1 or corresponding typed constant):
12001 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12002 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12006 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12007 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12010 static dw_loc_descr_ref
12011 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12012 enum machine_mode mem_mode
)
12014 dw_loc_descr_ref op0
, ret
, tmp
;
12015 dw_loc_descr_ref l1jump
, l1label
;
12016 dw_loc_descr_ref l2jump
, l2label
;
12018 if (GET_MODE_CLASS (mode
) != MODE_INT
12019 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12022 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12023 VAR_INIT_STATUS_INITIALIZED
);
12027 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12028 VAR_INIT_STATUS_INITIALIZED
);
12031 add_loc_descr (&ret
, tmp
);
12032 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12033 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12034 add_loc_descr (&ret
, l1label
);
12035 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12036 add_loc_descr (&ret
, l2jump
);
12037 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12038 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12039 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12040 VAR_INIT_STATUS_INITIALIZED
);
12043 add_loc_descr (&ret
, tmp
);
12044 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12045 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12046 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12047 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12048 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12049 VAR_INIT_STATUS_INITIALIZED
);
12050 add_loc_descr (&ret
, tmp
);
12051 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12052 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12053 add_loc_descr (&ret
, l1jump
);
12054 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12055 add_loc_descr (&ret
, l2label
);
12056 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12057 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12058 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12059 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12063 /* BSWAP (constS is initial shift count, either 56 or 24):
12065 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12066 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12067 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12068 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12069 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12071 static dw_loc_descr_ref
12072 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12073 enum machine_mode mem_mode
)
12075 dw_loc_descr_ref op0
, ret
, tmp
;
12076 dw_loc_descr_ref l1jump
, l1label
;
12077 dw_loc_descr_ref l2jump
, l2label
;
12079 if (GET_MODE_CLASS (mode
) != MODE_INT
12080 || BITS_PER_UNIT
!= 8
12081 || (GET_MODE_BITSIZE (mode
) != 32
12082 && GET_MODE_BITSIZE (mode
) != 64))
12085 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12086 VAR_INIT_STATUS_INITIALIZED
);
12091 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12093 VAR_INIT_STATUS_INITIALIZED
);
12096 add_loc_descr (&ret
, tmp
);
12097 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12098 VAR_INIT_STATUS_INITIALIZED
);
12101 add_loc_descr (&ret
, tmp
);
12102 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12103 add_loc_descr (&ret
, l1label
);
12104 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12106 VAR_INIT_STATUS_INITIALIZED
);
12107 add_loc_descr (&ret
, tmp
);
12108 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12109 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12110 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12111 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12112 VAR_INIT_STATUS_INITIALIZED
);
12115 add_loc_descr (&ret
, tmp
);
12116 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12117 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12118 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12119 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12120 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12121 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12122 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12123 VAR_INIT_STATUS_INITIALIZED
);
12124 add_loc_descr (&ret
, tmp
);
12125 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12126 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12127 add_loc_descr (&ret
, l2jump
);
12128 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12129 VAR_INIT_STATUS_INITIALIZED
);
12130 add_loc_descr (&ret
, tmp
);
12131 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12132 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12133 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12134 add_loc_descr (&ret
, l1jump
);
12135 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12136 add_loc_descr (&ret
, l2label
);
12137 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12138 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12139 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12140 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12141 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12142 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12146 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12147 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12148 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12149 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12151 ROTATERT is similar:
12152 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12153 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12154 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12156 static dw_loc_descr_ref
12157 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12158 enum machine_mode mem_mode
)
12160 rtx rtlop1
= XEXP (rtl
, 1);
12161 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12164 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12167 if (GET_MODE (rtlop1
) != VOIDmode
12168 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12169 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12170 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12171 VAR_INIT_STATUS_INITIALIZED
);
12172 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12173 VAR_INIT_STATUS_INITIALIZED
);
12174 if (op0
== NULL
|| op1
== NULL
)
12176 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12177 for (i
= 0; i
< 2; i
++)
12179 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12180 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12182 VAR_INIT_STATUS_INITIALIZED
);
12183 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12184 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12186 : HOST_BITS_PER_WIDE_INT
== 64
12187 ? DW_OP_const8u
: DW_OP_constu
,
12188 GET_MODE_MASK (mode
), 0);
12191 if (mask
[i
] == NULL
)
12193 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12196 add_loc_descr (&ret
, op1
);
12197 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12198 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12199 if (GET_CODE (rtl
) == ROTATERT
)
12201 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12202 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12203 GET_MODE_BITSIZE (mode
), 0));
12205 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12206 if (mask
[0] != NULL
)
12207 add_loc_descr (&ret
, mask
[0]);
12208 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12209 if (mask
[1] != NULL
)
12211 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12212 add_loc_descr (&ret
, mask
[1]);
12213 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12215 if (GET_CODE (rtl
) == ROTATE
)
12217 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12218 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12219 GET_MODE_BITSIZE (mode
), 0));
12221 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12222 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12226 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12227 for DEBUG_PARAMETER_REF RTL. */
12229 static dw_loc_descr_ref
12230 parameter_ref_descriptor (rtx rtl
)
12232 dw_loc_descr_ref ret
;
12237 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12238 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12239 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12242 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12243 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12244 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12248 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12249 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12254 /* The following routine converts the RTL for a variable or parameter
12255 (resident in memory) into an equivalent Dwarf representation of a
12256 mechanism for getting the address of that same variable onto the top of a
12257 hypothetical "address evaluation" stack.
12259 When creating memory location descriptors, we are effectively transforming
12260 the RTL for a memory-resident object into its Dwarf postfix expression
12261 equivalent. This routine recursively descends an RTL tree, turning
12262 it into Dwarf postfix code as it goes.
12264 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12266 MEM_MODE is the mode of the memory reference, needed to handle some
12267 autoincrement addressing modes.
12269 Return 0 if we can't represent the location. */
12272 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12273 enum machine_mode mem_mode
,
12274 enum var_init_status initialized
)
12276 dw_loc_descr_ref mem_loc_result
= NULL
;
12277 enum dwarf_location_atom op
;
12278 dw_loc_descr_ref op0
, op1
;
12279 rtx inner
= NULL_RTX
;
12281 if (mode
== VOIDmode
)
12282 mode
= GET_MODE (rtl
);
12284 /* Note that for a dynamically sized array, the location we will generate a
12285 description of here will be the lowest numbered location which is
12286 actually within the array. That's *not* necessarily the same as the
12287 zeroth element of the array. */
12289 rtl
= targetm
.delegitimize_address (rtl
);
12291 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12294 switch (GET_CODE (rtl
))
12299 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12302 /* The case of a subreg may arise when we have a local (register)
12303 variable or a formal (register) parameter which doesn't quite fill
12304 up an entire register. For now, just assume that it is
12305 legitimate to make the Dwarf info refer to the whole register which
12306 contains the given subreg. */
12307 if (!subreg_lowpart_p (rtl
))
12309 inner
= SUBREG_REG (rtl
);
12311 if (inner
== NULL_RTX
)
12312 inner
= XEXP (rtl
, 0);
12313 if (GET_MODE_CLASS (mode
) == MODE_INT
12314 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12315 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12316 #ifdef POINTERS_EXTEND_UNSIGNED
12317 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12320 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12322 mem_loc_result
= mem_loc_descriptor (inner
,
12324 mem_mode
, initialized
);
12329 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12331 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12332 && (GET_MODE_CLASS (mode
) != MODE_INT
12333 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12337 dw_die_ref type_die
;
12338 dw_loc_descr_ref cvt
;
12340 mem_loc_result
= mem_loc_descriptor (inner
,
12342 mem_mode
, initialized
);
12343 if (mem_loc_result
== NULL
)
12345 type_die
= base_type_for_mode (mode
,
12346 GET_MODE_CLASS (mode
) == MODE_INT
);
12347 if (type_die
== NULL
)
12349 mem_loc_result
= NULL
;
12352 if (GET_MODE_SIZE (mode
)
12353 != GET_MODE_SIZE (GET_MODE (inner
)))
12354 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12356 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12357 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12358 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12359 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12360 add_loc_descr (&mem_loc_result
, cvt
);
12365 if (GET_MODE_CLASS (mode
) != MODE_INT
12366 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12367 && rtl
!= arg_pointer_rtx
12368 && rtl
!= frame_pointer_rtx
12369 #ifdef POINTERS_EXTEND_UNSIGNED
12370 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12374 dw_die_ref type_die
;
12375 unsigned int dbx_regnum
;
12379 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12381 type_die
= base_type_for_mode (mode
,
12382 GET_MODE_CLASS (mode
) == MODE_INT
);
12383 if (type_die
== NULL
)
12386 dbx_regnum
= dbx_reg_number (rtl
);
12387 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12389 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12391 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12392 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12393 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12396 /* Whenever a register number forms a part of the description of the
12397 method for calculating the (dynamic) address of a memory resident
12398 object, DWARF rules require the register number be referred to as
12399 a "base register". This distinction is not based in any way upon
12400 what category of register the hardware believes the given register
12401 belongs to. This is strictly DWARF terminology we're dealing with
12402 here. Note that in cases where the location of a memory-resident
12403 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12404 OP_CONST (0)) the actual DWARF location descriptor that we generate
12405 may just be OP_BASEREG (basereg). This may look deceptively like
12406 the object in question was allocated to a register (rather than in
12407 memory) so DWARF consumers need to be aware of the subtle
12408 distinction between OP_REG and OP_BASEREG. */
12409 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12410 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12411 else if (stack_realign_drap
12413 && crtl
->args
.internal_arg_pointer
== rtl
12414 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12416 /* If RTL is internal_arg_pointer, which has been optimized
12417 out, use DRAP instead. */
12418 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12419 VAR_INIT_STATUS_INITIALIZED
);
12425 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12427 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12428 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12431 else if (GET_CODE (rtl
) == ZERO_EXTEND
12432 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12433 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12434 < HOST_BITS_PER_WIDE_INT
12435 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12436 to expand zero extend as two shifts instead of
12438 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12440 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12441 mem_loc_result
= op0
;
12442 add_loc_descr (&mem_loc_result
,
12443 int_loc_descriptor (GET_MODE_MASK (imode
)));
12444 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12446 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12448 int shift
= DWARF2_ADDR_SIZE
12449 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12450 shift
*= BITS_PER_UNIT
;
12451 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12455 mem_loc_result
= op0
;
12456 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12457 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12458 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12459 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12461 else if (!dwarf_strict
)
12463 dw_die_ref type_die1
, type_die2
;
12464 dw_loc_descr_ref cvt
;
12466 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12467 GET_CODE (rtl
) == ZERO_EXTEND
);
12468 if (type_die1
== NULL
)
12470 type_die2
= base_type_for_mode (mode
, 1);
12471 if (type_die2
== NULL
)
12473 mem_loc_result
= op0
;
12474 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12475 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12476 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12477 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12478 add_loc_descr (&mem_loc_result
, cvt
);
12479 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12480 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12481 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12482 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12483 add_loc_descr (&mem_loc_result
, cvt
);
12489 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12490 if (new_rtl
!= rtl
)
12492 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12494 if (mem_loc_result
!= NULL
)
12495 return mem_loc_result
;
12498 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12499 get_address_mode (rtl
), mode
,
12500 VAR_INIT_STATUS_INITIALIZED
);
12501 if (mem_loc_result
== NULL
)
12502 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12503 if (mem_loc_result
!= NULL
)
12505 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12506 || GET_MODE_CLASS (mode
) != MODE_INT
)
12508 dw_die_ref type_die
;
12509 dw_loc_descr_ref deref
;
12514 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12515 if (type_die
== NULL
)
12517 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12518 GET_MODE_SIZE (mode
), 0);
12519 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12520 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12521 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12522 add_loc_descr (&mem_loc_result
, deref
);
12524 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12525 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12527 add_loc_descr (&mem_loc_result
,
12528 new_loc_descr (DW_OP_deref_size
,
12529 GET_MODE_SIZE (mode
), 0));
12534 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12537 /* Some ports can transform a symbol ref into a label ref, because
12538 the symbol ref is too far away and has to be dumped into a constant
12542 if (GET_MODE_CLASS (mode
) != MODE_INT
12543 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12544 #ifdef POINTERS_EXTEND_UNSIGNED
12545 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12549 if (GET_CODE (rtl
) == SYMBOL_REF
12550 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12552 dw_loc_descr_ref temp
;
12554 /* If this is not defined, we have no way to emit the data. */
12555 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12558 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12560 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12561 add_loc_descr (&mem_loc_result
, temp
);
12566 if (!const_ok_for_output (rtl
))
12570 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12571 vec_safe_push (used_rtx_array
, rtl
);
12577 case DEBUG_IMPLICIT_PTR
:
12578 expansion_failed (NULL_TREE
, rtl
,
12579 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12585 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12587 if (GET_MODE_CLASS (mode
) != MODE_INT
12588 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12589 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12590 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12593 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12594 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12596 op0
= one_reg_loc_descriptor (dbx_regnum
,
12597 VAR_INIT_STATUS_INITIALIZED
);
12600 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12601 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12603 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12604 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12605 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12609 gcc_unreachable ();
12612 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12613 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12614 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12617 case DEBUG_PARAMETER_REF
:
12618 mem_loc_result
= parameter_ref_descriptor (rtl
);
12622 /* Extract the PLUS expression nested inside and fall into
12623 PLUS code below. */
12624 rtl
= XEXP (rtl
, 1);
12629 /* Turn these into a PLUS expression and fall into the PLUS code
12631 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12632 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12633 ? GET_MODE_UNIT_SIZE (mem_mode
)
12634 : -GET_MODE_UNIT_SIZE (mem_mode
),
12637 /* ... fall through ... */
12641 if (is_based_loc (rtl
)
12642 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12643 || XEXP (rtl
, 0) == arg_pointer_rtx
12644 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12645 && GET_MODE_CLASS (mode
) == MODE_INT
)
12646 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12647 INTVAL (XEXP (rtl
, 1)),
12648 VAR_INIT_STATUS_INITIALIZED
);
12651 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12652 VAR_INIT_STATUS_INITIALIZED
);
12653 if (mem_loc_result
== 0)
12656 if (CONST_INT_P (XEXP (rtl
, 1))
12657 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12658 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12661 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12662 VAR_INIT_STATUS_INITIALIZED
);
12665 add_loc_descr (&mem_loc_result
, op1
);
12666 add_loc_descr (&mem_loc_result
,
12667 new_loc_descr (DW_OP_plus
, 0, 0));
12672 /* If a pseudo-reg is optimized away, it is possible for it to
12673 be replaced with a MEM containing a multiply or shift. */
12684 && GET_MODE_CLASS (mode
) == MODE_INT
12685 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12687 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12688 base_type_for_mode (mode
, 0),
12712 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12714 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12715 VAR_INIT_STATUS_INITIALIZED
);
12717 rtx rtlop1
= XEXP (rtl
, 1);
12718 if (GET_MODE (rtlop1
) != VOIDmode
12719 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12720 < GET_MODE_BITSIZE (mode
))
12721 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12722 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12723 VAR_INIT_STATUS_INITIALIZED
);
12726 if (op0
== 0 || op1
== 0)
12729 mem_loc_result
= op0
;
12730 add_loc_descr (&mem_loc_result
, op1
);
12731 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12747 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12748 VAR_INIT_STATUS_INITIALIZED
);
12749 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12750 VAR_INIT_STATUS_INITIALIZED
);
12752 if (op0
== 0 || op1
== 0)
12755 mem_loc_result
= op0
;
12756 add_loc_descr (&mem_loc_result
, op1
);
12757 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12761 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12763 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12764 base_type_for_mode (mode
, 0),
12769 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12770 VAR_INIT_STATUS_INITIALIZED
);
12771 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12772 VAR_INIT_STATUS_INITIALIZED
);
12774 if (op0
== 0 || op1
== 0)
12777 mem_loc_result
= op0
;
12778 add_loc_descr (&mem_loc_result
, op1
);
12779 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12780 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12781 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12782 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12783 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12787 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12789 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12794 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12795 base_type_for_mode (mode
, 1),
12813 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12814 VAR_INIT_STATUS_INITIALIZED
);
12819 mem_loc_result
= op0
;
12820 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12824 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12825 #ifdef POINTERS_EXTEND_UNSIGNED
12827 && mem_mode
!= VOIDmode
12828 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12832 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12836 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12837 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12839 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12840 enum machine_mode amode
;
12841 if (type_die
== NULL
)
12843 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12845 if (INTVAL (rtl
) >= 0
12846 && amode
!= BLKmode
12847 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12848 /* const DW_OP_GNU_convert <XXX> vs.
12849 DW_OP_GNU_const_type <XXX, 1, const>. */
12850 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12851 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12853 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12854 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12855 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12856 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12857 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12858 add_loc_descr (&mem_loc_result
, op0
);
12859 return mem_loc_result
;
12861 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12863 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12864 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12865 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12866 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12867 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12870 mem_loc_result
->dw_loc_oprnd2
.val_class
12871 = dw_val_class_const_double
;
12872 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12873 = double_int::from_shwi (INTVAL (rtl
));
12881 dw_die_ref type_die
;
12883 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
12884 CONST_DOUBLE rtx could represent either an large integer
12885 or a floating-point constant. If
12886 TARGET_SUPPORTS_WIDE_INT != 0, the value is always a
12887 floating point constant.
12889 When it is an integer, a CONST_DOUBLE is used whenever
12890 the constant requires 2 HWIs to be adequately
12891 represented. We output CONST_DOUBLEs as blocks. */
12892 if (mode
== VOIDmode
12893 || (GET_MODE (rtl
) == VOIDmode
12894 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12896 type_die
= base_type_for_mode (mode
,
12897 GET_MODE_CLASS (mode
) == MODE_INT
);
12898 if (type_die
== NULL
)
12900 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12901 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12902 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12903 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12904 #if TARGET_SUPPORTS_WIDE_INT == 0
12905 if (!SCALAR_FLOAT_MODE_P (mode
))
12907 mem_loc_result
->dw_loc_oprnd2
.val_class
12908 = dw_val_class_const_double
;
12909 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12910 = rtx_to_double_int (rtl
);
12915 unsigned int length
= GET_MODE_SIZE (mode
);
12916 unsigned char *array
12917 = (unsigned char*) ggc_alloc_atomic (length
);
12919 insert_float (rtl
, array
);
12920 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12921 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12922 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12923 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12928 case CONST_WIDE_INT
:
12931 dw_die_ref type_die
;
12933 type_die
= base_type_for_mode (mode
,
12934 GET_MODE_CLASS (mode
) == MODE_INT
);
12935 if (type_die
== NULL
)
12937 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12938 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12939 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12940 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12941 mem_loc_result
->dw_loc_oprnd2
.val_class
12942 = dw_val_class_wide_int
;
12943 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc_cleared_wide_int ();
12944 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
12949 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12953 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12957 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12961 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12965 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12969 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12973 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12977 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12981 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12985 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12990 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12995 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13000 if (CONST_INT_P (XEXP (rtl
, 1))
13001 && CONST_INT_P (XEXP (rtl
, 2))
13002 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13003 + (unsigned) INTVAL (XEXP (rtl
, 2))
13004 <= GET_MODE_BITSIZE (mode
))
13005 && GET_MODE_CLASS (mode
) == MODE_INT
13006 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13007 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13010 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13011 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13014 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13018 mem_loc_result
= op0
;
13019 size
= INTVAL (XEXP (rtl
, 1));
13020 shift
= INTVAL (XEXP (rtl
, 2));
13021 if (BITS_BIG_ENDIAN
)
13022 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13024 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13026 add_loc_descr (&mem_loc_result
,
13027 int_loc_descriptor (DWARF2_ADDR_SIZE
13029 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13031 if (size
!= (int) DWARF2_ADDR_SIZE
)
13033 add_loc_descr (&mem_loc_result
,
13034 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13035 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13042 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13043 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13044 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13045 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13046 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13047 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13048 VAR_INIT_STATUS_INITIALIZED
);
13049 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13050 VAR_INIT_STATUS_INITIALIZED
);
13051 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13054 mem_loc_result
= op1
;
13055 add_loc_descr (&mem_loc_result
, op2
);
13056 add_loc_descr (&mem_loc_result
, op0
);
13057 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13058 add_loc_descr (&mem_loc_result
, bra_node
);
13059 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13060 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13061 add_loc_descr (&mem_loc_result
, drop_node
);
13062 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13063 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13068 case FLOAT_TRUNCATE
:
13070 case UNSIGNED_FLOAT
:
13075 dw_die_ref type_die
;
13076 dw_loc_descr_ref cvt
;
13078 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13079 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13082 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13083 && (GET_CODE (rtl
) == FLOAT
13084 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13085 <= DWARF2_ADDR_SIZE
))
13087 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13088 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13089 if (type_die
== NULL
)
13091 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13092 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13093 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13094 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13095 add_loc_descr (&op0
, cvt
);
13097 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13098 if (type_die
== NULL
)
13100 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13101 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13102 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13103 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13104 add_loc_descr (&op0
, cvt
);
13105 if (GET_MODE_CLASS (mode
) == MODE_INT
13106 && (GET_CODE (rtl
) == FIX
13107 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13109 op0
= convert_descriptor_to_mode (mode
, op0
);
13113 mem_loc_result
= op0
;
13120 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13125 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13129 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13134 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13138 /* In theory, we could implement the above. */
13139 /* DWARF cannot represent the unsigned compare operations
13164 case FRACT_CONVERT
:
13165 case UNSIGNED_FRACT_CONVERT
:
13167 case UNSIGNED_SAT_FRACT
:
13173 case VEC_DUPLICATE
:
13177 case STRICT_LOW_PART
:
13182 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13183 can't express it in the debug info. This can happen e.g. with some
13188 resolve_one_addr (&rtl
, NULL
);
13192 #ifdef ENABLE_CHECKING
13193 print_rtl (stderr
, rtl
);
13194 gcc_unreachable ();
13200 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13201 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13203 return mem_loc_result
;
13206 /* Return a descriptor that describes the concatenation of two locations.
13207 This is typically a complex variable. */
13209 static dw_loc_descr_ref
13210 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13212 dw_loc_descr_ref cc_loc_result
= NULL
;
13213 dw_loc_descr_ref x0_ref
13214 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13215 dw_loc_descr_ref x1_ref
13216 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13218 if (x0_ref
== 0 || x1_ref
== 0)
13221 cc_loc_result
= x0_ref
;
13222 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13224 add_loc_descr (&cc_loc_result
, x1_ref
);
13225 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13227 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13228 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13230 return cc_loc_result
;
13233 /* Return a descriptor that describes the concatenation of N
13236 static dw_loc_descr_ref
13237 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13240 dw_loc_descr_ref cc_loc_result
= NULL
;
13241 unsigned int n
= XVECLEN (concatn
, 0);
13243 for (i
= 0; i
< n
; ++i
)
13245 dw_loc_descr_ref ref
;
13246 rtx x
= XVECEXP (concatn
, 0, i
);
13248 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13252 add_loc_descr (&cc_loc_result
, ref
);
13253 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13256 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13257 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13259 return cc_loc_result
;
13262 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13263 for DEBUG_IMPLICIT_PTR RTL. */
13265 static dw_loc_descr_ref
13266 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13268 dw_loc_descr_ref ret
;
13273 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13274 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13275 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13276 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13277 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13278 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13281 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13282 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13283 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13287 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13288 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13293 /* Output a proper Dwarf location descriptor for a variable or parameter
13294 which is either allocated in a register or in a memory location. For a
13295 register, we just generate an OP_REG and the register number. For a
13296 memory location we provide a Dwarf postfix expression describing how to
13297 generate the (dynamic) address of the object onto the address stack.
13299 MODE is mode of the decl if this loc_descriptor is going to be used in
13300 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13301 allowed, VOIDmode otherwise.
13303 If we don't know how to describe it, return 0. */
13305 static dw_loc_descr_ref
13306 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13307 enum var_init_status initialized
)
13309 dw_loc_descr_ref loc_result
= NULL
;
13311 switch (GET_CODE (rtl
))
13314 /* The case of a subreg may arise when we have a local (register)
13315 variable or a formal (register) parameter which doesn't quite fill
13316 up an entire register. For now, just assume that it is
13317 legitimate to make the Dwarf info refer to the whole register which
13318 contains the given subreg. */
13319 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13320 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13321 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13327 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13331 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13332 GET_MODE (rtl
), initialized
);
13333 if (loc_result
== NULL
)
13334 loc_result
= tls_mem_loc_descriptor (rtl
);
13335 if (loc_result
== NULL
)
13337 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13338 if (new_rtl
!= rtl
)
13339 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13344 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13349 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13354 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13356 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13357 if (GET_CODE (loc
) == EXPR_LIST
)
13358 loc
= XEXP (loc
, 0);
13359 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13363 rtl
= XEXP (rtl
, 1);
13368 rtvec par_elems
= XVEC (rtl
, 0);
13369 int num_elem
= GET_NUM_ELEM (par_elems
);
13370 enum machine_mode mode
;
13373 /* Create the first one, so we have something to add to. */
13374 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13375 VOIDmode
, initialized
);
13376 if (loc_result
== NULL
)
13378 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13379 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13380 for (i
= 1; i
< num_elem
; i
++)
13382 dw_loc_descr_ref temp
;
13384 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13385 VOIDmode
, initialized
);
13388 add_loc_descr (&loc_result
, temp
);
13389 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13390 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13396 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13397 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13402 if (mode
== VOIDmode
)
13403 mode
= GET_MODE (rtl
);
13405 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13407 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13409 /* Note that a CONST_DOUBLE rtx could represent either an integer
13410 or a floating-point constant. A CONST_DOUBLE is used whenever
13411 the constant requires more than one word in order to be
13412 adequately represented. We output CONST_DOUBLEs as blocks. */
13413 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13414 GET_MODE_SIZE (mode
), 0);
13415 #if TARGET_SUPPORTS_WIDE_INT == 0
13416 if (!SCALAR_FLOAT_MODE_P (mode
))
13418 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13419 loc_result
->dw_loc_oprnd2
.v
.val_double
13420 = rtx_to_double_int (rtl
);
13425 unsigned int length
= GET_MODE_SIZE (mode
);
13426 unsigned char *array
13427 = (unsigned char*) ggc_alloc_atomic (length
);
13429 insert_float (rtl
, array
);
13430 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13431 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13432 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13433 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13438 case CONST_WIDE_INT
:
13439 if (mode
== VOIDmode
)
13440 mode
= GET_MODE (rtl
);
13442 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13444 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13445 GET_MODE_SIZE (mode
), 0);
13446 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13447 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc_cleared_wide_int ();
13448 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13453 if (mode
== VOIDmode
)
13454 mode
= GET_MODE (rtl
);
13456 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13458 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13459 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13460 unsigned char *array
= (unsigned char *)
13461 ggc_alloc_atomic (length
* elt_size
);
13464 enum machine_mode imode
= GET_MODE_INNER (mode
);
13466 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13467 switch (GET_MODE_CLASS (mode
))
13469 case MODE_VECTOR_INT
:
13470 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13472 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13473 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13477 case MODE_VECTOR_FLOAT
:
13478 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13480 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13481 insert_float (elt
, p
);
13486 gcc_unreachable ();
13489 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13490 length
* elt_size
, 0);
13491 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13492 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13493 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13494 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13499 if (mode
== VOIDmode
13500 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13501 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13502 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13504 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13509 if (!const_ok_for_output (rtl
))
13512 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13513 && (dwarf_version
>= 4 || !dwarf_strict
))
13515 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13516 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13517 vec_safe_push (used_rtx_array
, rtl
);
13521 case DEBUG_IMPLICIT_PTR
:
13522 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13526 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13527 && CONST_INT_P (XEXP (rtl
, 1)))
13530 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13536 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13537 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13538 && dwarf_version
>= 4)
13539 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13541 /* Value expression. */
13542 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13544 add_loc_descr (&loc_result
,
13545 new_loc_descr (DW_OP_stack_value
, 0, 0));
13553 /* We need to figure out what section we should use as the base for the
13554 address ranges where a given location is valid.
13555 1. If this particular DECL has a section associated with it, use that.
13556 2. If this function has a section associated with it, use that.
13557 3. Otherwise, use the text section.
13558 XXX: If you split a variable across multiple sections, we won't notice. */
13560 static const char *
13561 secname_for_decl (const_tree decl
)
13563 const char *secname
;
13565 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13567 tree sectree
= DECL_SECTION_NAME (decl
);
13568 secname
= TREE_STRING_POINTER (sectree
);
13570 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13572 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13573 secname
= TREE_STRING_POINTER (sectree
);
13575 else if (cfun
&& in_cold_section_p
)
13576 secname
= crtl
->subsections
.cold_section_label
;
13578 secname
= text_section_label
;
13583 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13586 decl_by_reference_p (tree decl
)
13588 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13589 || TREE_CODE (decl
) == VAR_DECL
)
13590 && DECL_BY_REFERENCE (decl
));
13593 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13596 static dw_loc_descr_ref
13597 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13598 enum var_init_status initialized
)
13600 int have_address
= 0;
13601 dw_loc_descr_ref descr
;
13602 enum machine_mode mode
;
13604 if (want_address
!= 2)
13606 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13608 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13610 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13611 if (GET_CODE (varloc
) == EXPR_LIST
)
13612 varloc
= XEXP (varloc
, 0);
13613 mode
= GET_MODE (varloc
);
13614 if (MEM_P (varloc
))
13616 rtx addr
= XEXP (varloc
, 0);
13617 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13618 mode
, initialized
);
13623 rtx x
= avoid_constant_pool_reference (varloc
);
13625 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13630 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13637 if (GET_CODE (varloc
) == VAR_LOCATION
)
13638 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13640 mode
= DECL_MODE (loc
);
13641 descr
= loc_descriptor (varloc
, mode
, initialized
);
13648 if (want_address
== 2 && !have_address
13649 && (dwarf_version
>= 4 || !dwarf_strict
))
13651 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13653 expansion_failed (loc
, NULL_RTX
,
13654 "DWARF address size mismatch");
13657 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13660 /* Show if we can't fill the request for an address. */
13661 if (want_address
&& !have_address
)
13663 expansion_failed (loc
, NULL_RTX
,
13664 "Want address and only have value");
13668 /* If we've got an address and don't want one, dereference. */
13669 if (!want_address
&& have_address
)
13671 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13672 enum dwarf_location_atom op
;
13674 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13676 expansion_failed (loc
, NULL_RTX
,
13677 "DWARF address size mismatch");
13680 else if (size
== DWARF2_ADDR_SIZE
)
13683 op
= DW_OP_deref_size
;
13685 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13691 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13692 if it is not possible. */
13694 static dw_loc_descr_ref
13695 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13697 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13698 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13699 else if (dwarf_version
>= 3 || !dwarf_strict
)
13700 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13705 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13706 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13708 static dw_loc_descr_ref
13709 dw_sra_loc_expr (tree decl
, rtx loc
)
13712 unsigned int padsize
= 0;
13713 dw_loc_descr_ref descr
, *descr_tail
;
13714 unsigned HOST_WIDE_INT decl_size
;
13716 enum var_init_status initialized
;
13718 if (DECL_SIZE (decl
) == NULL
13719 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
13722 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
13724 descr_tail
= &descr
;
13726 for (p
= loc
; p
; p
= XEXP (p
, 1))
13728 unsigned int bitsize
= decl_piece_bitsize (p
);
13729 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13730 dw_loc_descr_ref cur_descr
;
13731 dw_loc_descr_ref
*tail
, last
= NULL
;
13732 unsigned int opsize
= 0;
13734 if (loc_note
== NULL_RTX
13735 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13737 padsize
+= bitsize
;
13740 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13741 varloc
= NOTE_VAR_LOCATION (loc_note
);
13742 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13743 if (cur_descr
== NULL
)
13745 padsize
+= bitsize
;
13749 /* Check that cur_descr either doesn't use
13750 DW_OP_*piece operations, or their sum is equal
13751 to bitsize. Otherwise we can't embed it. */
13752 for (tail
= &cur_descr
; *tail
!= NULL
;
13753 tail
= &(*tail
)->dw_loc_next
)
13754 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13756 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13760 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13762 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13766 if (last
!= NULL
&& opsize
!= bitsize
)
13768 padsize
+= bitsize
;
13769 /* Discard the current piece of the descriptor and release any
13770 addr_table entries it uses. */
13771 remove_loc_list_addr_table_entries (cur_descr
);
13775 /* If there is a hole, add DW_OP_*piece after empty DWARF
13776 expression, which means that those bits are optimized out. */
13779 if (padsize
> decl_size
)
13781 remove_loc_list_addr_table_entries (cur_descr
);
13782 goto discard_descr
;
13784 decl_size
-= padsize
;
13785 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13786 if (*descr_tail
== NULL
)
13788 remove_loc_list_addr_table_entries (cur_descr
);
13789 goto discard_descr
;
13791 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13794 *descr_tail
= cur_descr
;
13796 if (bitsize
> decl_size
)
13797 goto discard_descr
;
13798 decl_size
-= bitsize
;
13801 HOST_WIDE_INT offset
= 0;
13802 if (GET_CODE (varloc
) == VAR_LOCATION
13803 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13805 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13806 if (GET_CODE (varloc
) == EXPR_LIST
)
13807 varloc
= XEXP (varloc
, 0);
13811 if (GET_CODE (varloc
) == CONST
13812 || GET_CODE (varloc
) == SIGN_EXTEND
13813 || GET_CODE (varloc
) == ZERO_EXTEND
)
13814 varloc
= XEXP (varloc
, 0);
13815 else if (GET_CODE (varloc
) == SUBREG
)
13816 varloc
= SUBREG_REG (varloc
);
13821 /* DW_OP_bit_size offset should be zero for register
13822 or implicit location descriptions and empty location
13823 descriptions, but for memory addresses needs big endian
13825 if (MEM_P (varloc
))
13827 unsigned HOST_WIDE_INT memsize
13828 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13829 if (memsize
!= bitsize
)
13831 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13832 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13833 goto discard_descr
;
13834 if (memsize
< bitsize
)
13835 goto discard_descr
;
13836 if (BITS_BIG_ENDIAN
)
13837 offset
= memsize
- bitsize
;
13841 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13842 if (*descr_tail
== NULL
)
13843 goto discard_descr
;
13844 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13848 /* If there were any non-empty expressions, add padding till the end of
13850 if (descr
!= NULL
&& decl_size
!= 0)
13852 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13853 if (*descr_tail
== NULL
)
13854 goto discard_descr
;
13859 /* Discard the descriptor and release any addr_table entries it uses. */
13860 remove_loc_list_addr_table_entries (descr
);
13864 /* Return the dwarf representation of the location list LOC_LIST of
13865 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13868 static dw_loc_list_ref
13869 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13871 const char *endname
, *secname
;
13873 enum var_init_status initialized
;
13874 struct var_loc_node
*node
;
13875 dw_loc_descr_ref descr
;
13876 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13877 dw_loc_list_ref list
= NULL
;
13878 dw_loc_list_ref
*listp
= &list
;
13880 /* Now that we know what section we are using for a base,
13881 actually construct the list of locations.
13882 The first location information is what is passed to the
13883 function that creates the location list, and the remaining
13884 locations just get added on to that list.
13885 Note that we only know the start address for a location
13886 (IE location changes), so to build the range, we use
13887 the range [current location start, next location start].
13888 This means we have to special case the last node, and generate
13889 a range of [last location start, end of function label]. */
13891 secname
= secname_for_decl (decl
);
13893 for (node
= loc_list
->first
; node
; node
= node
->next
)
13894 if (GET_CODE (node
->loc
) == EXPR_LIST
13895 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13897 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13899 /* This requires DW_OP_{,bit_}piece, which is not usable
13900 inside DWARF expressions. */
13901 if (want_address
!= 2)
13903 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13909 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13910 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13911 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13915 bool range_across_switch
= false;
13916 /* If section switch happens in between node->label
13917 and node->next->label (or end of function) and
13918 we can't emit it as a single entry list,
13919 emit two ranges, first one ending at the end
13920 of first partition and second one starting at the
13921 beginning of second partition. */
13922 if (node
== loc_list
->last_before_switch
13923 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13924 && current_function_decl
)
13926 endname
= cfun
->fde
->dw_fde_end
;
13927 range_across_switch
= true;
13929 /* The variable has a location between NODE->LABEL and
13930 NODE->NEXT->LABEL. */
13931 else if (node
->next
)
13932 endname
= node
->next
->label
;
13933 /* If the variable has a location at the last label
13934 it keeps its location until the end of function. */
13935 else if (!current_function_decl
)
13936 endname
= text_end_label
;
13939 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13940 current_function_funcdef_no
);
13941 endname
= ggc_strdup (label_id
);
13944 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13945 if (TREE_CODE (decl
) == PARM_DECL
13946 && node
== loc_list
->first
13947 && NOTE_P (node
->loc
)
13948 && strcmp (node
->label
, endname
) == 0)
13949 (*listp
)->force
= true;
13950 listp
= &(*listp
)->dw_loc_next
;
13952 if (range_across_switch
)
13954 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13955 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13958 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13959 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13960 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13963 gcc_assert (descr
);
13964 /* The variable has a location between NODE->LABEL and
13965 NODE->NEXT->LABEL. */
13967 endname
= node
->next
->label
;
13969 endname
= cfun
->fde
->dw_fde_second_end
;
13970 *listp
= new_loc_list (descr
,
13971 cfun
->fde
->dw_fde_second_begin
,
13973 listp
= &(*listp
)->dw_loc_next
;
13978 /* Try to avoid the overhead of a location list emitting a location
13979 expression instead, but only if we didn't have more than one
13980 location entry in the first place. If some entries were not
13981 representable, we don't want to pretend a single entry that was
13982 applies to the entire scope in which the variable is
13984 if (list
&& loc_list
->first
->next
)
13990 /* Return if the loc_list has only single element and thus can be represented
13991 as location description. */
13994 single_element_loc_list_p (dw_loc_list_ref list
)
13996 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13997 return !list
->ll_symbol
;
14000 /* To each location in list LIST add loc descr REF. */
14003 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14005 dw_loc_descr_ref copy
;
14006 add_loc_descr (&list
->expr
, ref
);
14007 list
= list
->dw_loc_next
;
14010 copy
= ggc_alloc_dw_loc_descr_node ();
14011 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14012 add_loc_descr (&list
->expr
, copy
);
14013 while (copy
->dw_loc_next
)
14015 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
14016 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14017 copy
->dw_loc_next
= new_copy
;
14020 list
= list
->dw_loc_next
;
14024 /* Given two lists RET and LIST
14025 produce location list that is result of adding expression in LIST
14026 to expression in RET on each position in program.
14027 Might be destructive on both RET and LIST.
14029 TODO: We handle only simple cases of RET or LIST having at most one
14030 element. General case would inolve sorting the lists in program order
14031 and merging them that will need some additional work.
14032 Adding that will improve quality of debug info especially for SRA-ed
14036 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14045 if (!list
->dw_loc_next
)
14047 add_loc_descr_to_each (*ret
, list
->expr
);
14050 if (!(*ret
)->dw_loc_next
)
14052 add_loc_descr_to_each (list
, (*ret
)->expr
);
14056 expansion_failed (NULL_TREE
, NULL_RTX
,
14057 "Don't know how to merge two non-trivial"
14058 " location lists.\n");
14063 /* LOC is constant expression. Try a luck, look it up in constant
14064 pool and return its loc_descr of its address. */
14066 static dw_loc_descr_ref
14067 cst_pool_loc_descr (tree loc
)
14069 /* Get an RTL for this, if something has been emitted. */
14070 rtx rtl
= lookup_constant_def (loc
);
14072 if (!rtl
|| !MEM_P (rtl
))
14077 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14079 /* TODO: We might get more coverage if we was actually delaying expansion
14080 of all expressions till end of compilation when constant pools are fully
14082 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14084 expansion_failed (loc
, NULL_RTX
,
14085 "CST value in contant pool but not marked.");
14088 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14089 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14092 /* Return dw_loc_list representing address of addr_expr LOC
14093 by looking for inner INDIRECT_REF expression and turning
14094 it into simple arithmetics. */
14096 static dw_loc_list_ref
14097 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
14100 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14101 enum machine_mode mode
;
14102 int unsignedp
, volatilep
= 0;
14103 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14105 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14106 &bitsize
, &bitpos
, &offset
, &mode
,
14107 &unsignedp
, &volatilep
, false);
14109 if (bitpos
% BITS_PER_UNIT
)
14111 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14114 if (!INDIRECT_REF_P (obj
))
14116 expansion_failed (obj
,
14117 NULL_RTX
, "no indirect ref in inner refrence");
14120 if (!offset
&& !bitpos
)
14121 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
14123 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14124 && (dwarf_version
>= 4 || !dwarf_strict
))
14126 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
14131 /* Variable offset. */
14132 list_ret1
= loc_list_from_tree (offset
, 0);
14133 if (list_ret1
== 0)
14135 add_loc_list (&list_ret
, list_ret1
);
14138 add_loc_descr_to_each (list_ret
,
14139 new_loc_descr (DW_OP_plus
, 0, 0));
14141 bytepos
= bitpos
/ BITS_PER_UNIT
;
14143 add_loc_descr_to_each (list_ret
,
14144 new_loc_descr (DW_OP_plus_uconst
,
14146 else if (bytepos
< 0)
14147 loc_list_plus_const (list_ret
, bytepos
);
14148 add_loc_descr_to_each (list_ret
,
14149 new_loc_descr (DW_OP_stack_value
, 0, 0));
14155 /* Generate Dwarf location list representing LOC.
14156 If WANT_ADDRESS is false, expression computing LOC will be computed
14157 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14158 if WANT_ADDRESS is 2, expression computing address useable in location
14159 will be returned (i.e. DW_OP_reg can be used
14160 to refer to register values). */
14162 static dw_loc_list_ref
14163 loc_list_from_tree (tree loc
, int want_address
)
14165 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14166 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14167 int have_address
= 0;
14168 enum dwarf_location_atom op
;
14170 /* ??? Most of the time we do not take proper care for sign/zero
14171 extending the values properly. Hopefully this won't be a real
14174 switch (TREE_CODE (loc
))
14177 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14180 case PLACEHOLDER_EXPR
:
14181 /* This case involves extracting fields from an object to determine the
14182 position of other fields. We don't try to encode this here. The
14183 only user of this is Ada, which encodes the needed information using
14184 the names of types. */
14185 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14189 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14190 /* There are no opcodes for these operations. */
14193 case PREINCREMENT_EXPR
:
14194 case PREDECREMENT_EXPR
:
14195 case POSTINCREMENT_EXPR
:
14196 case POSTDECREMENT_EXPR
:
14197 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14198 /* There are no opcodes for these operations. */
14202 /* If we already want an address, see if there is INDIRECT_REF inside
14203 e.g. for &this->field. */
14206 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14207 (loc
, want_address
== 2);
14210 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14211 && (ret
= cst_pool_loc_descr (loc
)))
14214 /* Otherwise, process the argument and look for the address. */
14215 if (!list_ret
&& !ret
)
14216 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14220 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14226 if (DECL_THREAD_LOCAL_P (loc
))
14229 enum dwarf_location_atom tls_op
;
14230 enum dtprel_bool dtprel
= dtprel_false
;
14232 if (targetm
.have_tls
)
14234 /* If this is not defined, we have no way to emit the
14236 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14239 /* The way DW_OP_GNU_push_tls_address is specified, we
14240 can only look up addresses of objects in the current
14241 module. We used DW_OP_addr as first op, but that's
14242 wrong, because DW_OP_addr is relocated by the debug
14243 info consumer, while DW_OP_GNU_push_tls_address
14244 operand shouldn't be. */
14245 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14247 dtprel
= dtprel_true
;
14248 tls_op
= DW_OP_GNU_push_tls_address
;
14252 if (!targetm
.emutls
.debug_form_tls_address
14253 || !(dwarf_version
>= 3 || !dwarf_strict
))
14255 /* We stuffed the control variable into the DECL_VALUE_EXPR
14256 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14257 no longer appear in gimple code. We used the control
14258 variable in specific so that we could pick it up here. */
14259 loc
= DECL_VALUE_EXPR (loc
);
14260 tls_op
= DW_OP_form_tls_address
;
14263 rtl
= rtl_for_decl_location (loc
);
14264 if (rtl
== NULL_RTX
)
14269 rtl
= XEXP (rtl
, 0);
14270 if (! CONSTANT_P (rtl
))
14273 ret
= new_addr_loc_descr (rtl
, dtprel
);
14274 ret1
= new_loc_descr (tls_op
, 0, 0);
14275 add_loc_descr (&ret
, ret1
);
14284 if (DECL_HAS_VALUE_EXPR_P (loc
))
14285 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14289 case FUNCTION_DECL
:
14292 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14294 if (loc_list
&& loc_list
->first
)
14296 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14297 have_address
= want_address
!= 0;
14300 rtl
= rtl_for_decl_location (loc
);
14301 if (rtl
== NULL_RTX
)
14303 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14306 else if (CONST_INT_P (rtl
))
14308 HOST_WIDE_INT val
= INTVAL (rtl
);
14309 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14310 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14311 ret
= int_loc_descriptor (val
);
14313 else if (GET_CODE (rtl
) == CONST_STRING
)
14315 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14318 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14319 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14322 enum machine_mode mode
, mem_mode
;
14324 /* Certain constructs can only be represented at top-level. */
14325 if (want_address
== 2)
14327 ret
= loc_descriptor (rtl
, VOIDmode
,
14328 VAR_INIT_STATUS_INITIALIZED
);
14333 mode
= GET_MODE (rtl
);
14334 mem_mode
= VOIDmode
;
14338 mode
= get_address_mode (rtl
);
14339 rtl
= XEXP (rtl
, 0);
14342 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14343 VAR_INIT_STATUS_INITIALIZED
);
14346 expansion_failed (loc
, rtl
,
14347 "failed to produce loc descriptor for rtl");
14354 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14358 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14362 case COMPOUND_EXPR
:
14363 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14366 case VIEW_CONVERT_EXPR
:
14369 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14371 case COMPONENT_REF
:
14372 case BIT_FIELD_REF
:
14374 case ARRAY_RANGE_REF
:
14375 case REALPART_EXPR
:
14376 case IMAGPART_EXPR
:
14379 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14380 enum machine_mode mode
;
14381 int unsignedp
, volatilep
= 0;
14383 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14384 &unsignedp
, &volatilep
, false);
14386 gcc_assert (obj
!= loc
);
14388 list_ret
= loc_list_from_tree (obj
,
14390 && !bitpos
&& !offset
? 2 : 1);
14391 /* TODO: We can extract value of the small expression via shifting even
14392 for nonzero bitpos. */
14395 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14397 expansion_failed (loc
, NULL_RTX
,
14398 "bitfield access");
14402 if (offset
!= NULL_TREE
)
14404 /* Variable offset. */
14405 list_ret1
= loc_list_from_tree (offset
, 0);
14406 if (list_ret1
== 0)
14408 add_loc_list (&list_ret
, list_ret1
);
14411 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14414 bytepos
= bitpos
/ BITS_PER_UNIT
;
14416 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14417 else if (bytepos
< 0)
14418 loc_list_plus_const (list_ret
, bytepos
);
14425 if ((want_address
|| !tree_fits_shwi_p (loc
))
14426 && (ret
= cst_pool_loc_descr (loc
)))
14428 else if (want_address
== 2
14429 && tree_fits_shwi_p (loc
)
14430 && (ret
= address_of_int_loc_descriptor
14431 (int_size_in_bytes (TREE_TYPE (loc
)),
14432 tree_to_shwi (loc
))))
14434 else if (tree_fits_shwi_p (loc
))
14435 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14438 expansion_failed (loc
, NULL_RTX
,
14439 "Integer operand is not host integer");
14448 if ((ret
= cst_pool_loc_descr (loc
)))
14451 /* We can construct small constants here using int_loc_descriptor. */
14452 expansion_failed (loc
, NULL_RTX
,
14453 "constructor or constant not in constant pool");
14456 case TRUTH_AND_EXPR
:
14457 case TRUTH_ANDIF_EXPR
:
14462 case TRUTH_XOR_EXPR
:
14467 case TRUTH_OR_EXPR
:
14468 case TRUTH_ORIF_EXPR
:
14473 case FLOOR_DIV_EXPR
:
14474 case CEIL_DIV_EXPR
:
14475 case ROUND_DIV_EXPR
:
14476 case TRUNC_DIV_EXPR
:
14477 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14486 case FLOOR_MOD_EXPR
:
14487 case CEIL_MOD_EXPR
:
14488 case ROUND_MOD_EXPR
:
14489 case TRUNC_MOD_EXPR
:
14490 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14495 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14496 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14497 if (list_ret
== 0 || list_ret1
== 0)
14500 add_loc_list (&list_ret
, list_ret1
);
14503 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14504 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14505 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14506 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14507 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14519 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14522 case POINTER_PLUS_EXPR
:
14524 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14526 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14530 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14538 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14545 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14552 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14559 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14574 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14575 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14576 if (list_ret
== 0 || list_ret1
== 0)
14579 add_loc_list (&list_ret
, list_ret1
);
14582 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14585 case TRUTH_NOT_EXPR
:
14599 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14603 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14609 const enum tree_code code
=
14610 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14612 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14613 build2 (code
, integer_type_node
,
14614 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14615 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14618 /* ... fall through ... */
14622 dw_loc_descr_ref lhs
14623 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14624 dw_loc_list_ref rhs
14625 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14626 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14628 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14629 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14632 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14633 add_loc_descr_to_each (list_ret
, bra_node
);
14635 add_loc_list (&list_ret
, rhs
);
14636 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14637 add_loc_descr_to_each (list_ret
, jump_node
);
14639 add_loc_descr_to_each (list_ret
, lhs
);
14640 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14641 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14643 /* ??? Need a node to point the skip at. Use a nop. */
14644 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14645 add_loc_descr_to_each (list_ret
, tmp
);
14646 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14647 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14651 case FIX_TRUNC_EXPR
:
14655 /* Leave front-end specific codes as simply unknown. This comes
14656 up, for instance, with the C STMT_EXPR. */
14657 if ((unsigned int) TREE_CODE (loc
)
14658 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14660 expansion_failed (loc
, NULL_RTX
,
14661 "language specific tree node");
14665 #ifdef ENABLE_CHECKING
14666 /* Otherwise this is a generic code; we should just lists all of
14667 these explicitly. We forgot one. */
14668 gcc_unreachable ();
14670 /* In a release build, we want to degrade gracefully: better to
14671 generate incomplete debugging information than to crash. */
14676 if (!ret
&& !list_ret
)
14679 if (want_address
== 2 && !have_address
14680 && (dwarf_version
>= 4 || !dwarf_strict
))
14682 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14684 expansion_failed (loc
, NULL_RTX
,
14685 "DWARF address size mismatch");
14689 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14691 add_loc_descr_to_each (list_ret
,
14692 new_loc_descr (DW_OP_stack_value
, 0, 0));
14695 /* Show if we can't fill the request for an address. */
14696 if (want_address
&& !have_address
)
14698 expansion_failed (loc
, NULL_RTX
,
14699 "Want address and only have value");
14703 gcc_assert (!ret
|| !list_ret
);
14705 /* If we've got an address and don't want one, dereference. */
14706 if (!want_address
&& have_address
)
14708 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14710 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14712 expansion_failed (loc
, NULL_RTX
,
14713 "DWARF address size mismatch");
14716 else if (size
== DWARF2_ADDR_SIZE
)
14719 op
= DW_OP_deref_size
;
14722 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14724 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14727 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14732 /* Same as above but return only single location expression. */
14733 static dw_loc_descr_ref
14734 loc_descriptor_from_tree (tree loc
, int want_address
)
14736 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14739 if (ret
->dw_loc_next
)
14741 expansion_failed (loc
, NULL_RTX
,
14742 "Location list where only loc descriptor needed");
14748 /* Given a value, round it up to the lowest multiple of `boundary'
14749 which is not less than the value itself. */
14751 static inline HOST_WIDE_INT
14752 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14754 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14757 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14758 pointer to the declared type for the relevant field variable, or return
14759 `integer_type_node' if the given node turns out to be an
14760 ERROR_MARK node. */
14763 field_type (const_tree decl
)
14767 if (TREE_CODE (decl
) == ERROR_MARK
)
14768 return integer_type_node
;
14770 type
= DECL_BIT_FIELD_TYPE (decl
);
14771 if (type
== NULL_TREE
)
14772 type
= TREE_TYPE (decl
);
14777 /* Given a pointer to a tree node, return the alignment in bits for
14778 it, or else return BITS_PER_WORD if the node actually turns out to
14779 be an ERROR_MARK node. */
14781 static inline unsigned
14782 simple_type_align_in_bits (const_tree type
)
14784 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14787 static inline unsigned
14788 simple_decl_align_in_bits (const_tree decl
)
14790 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14793 /* Return the result of rounding T up to ALIGN. */
14795 static inline offset_int
14796 round_up_to_align (const offset_int
&t
, unsigned int align
)
14798 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
14801 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14802 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14803 or return 0 if we are unable to determine what that offset is, either
14804 because the argument turns out to be a pointer to an ERROR_MARK node, or
14805 because the offset is actually variable. (We can't handle the latter case
14808 static HOST_WIDE_INT
14809 field_byte_offset (const_tree decl
)
14811 offset_int object_offset_in_bits
;
14812 offset_int object_offset_in_bytes
;
14813 offset_int bitpos_int
;
14815 if (TREE_CODE (decl
) == ERROR_MARK
)
14818 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14820 /* We cannot yet cope with fields whose positions are variable, so
14821 for now, when we see such things, we simply return 0. Someday, we may
14822 be able to handle such cases, but it will be damn difficult. */
14823 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14826 bitpos_int
= wi::to_offset (bit_position (decl
));
14828 #ifdef PCC_BITFIELD_TYPE_MATTERS
14829 if (PCC_BITFIELD_TYPE_MATTERS
)
14832 tree field_size_tree
;
14833 offset_int deepest_bitpos
;
14834 offset_int field_size_in_bits
;
14835 unsigned int type_align_in_bits
;
14836 unsigned int decl_align_in_bits
;
14837 offset_int type_size_in_bits
;
14839 type
= field_type (decl
);
14840 type_size_in_bits
= offset_int_type_size_in_bits (type
);
14841 type_align_in_bits
= simple_type_align_in_bits (type
);
14843 field_size_tree
= DECL_SIZE (decl
);
14845 /* The size could be unspecified if there was an error, or for
14846 a flexible array member. */
14847 if (!field_size_tree
)
14848 field_size_tree
= bitsize_zero_node
;
14850 /* If the size of the field is not constant, use the type size. */
14851 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14852 field_size_in_bits
= wi::to_offset (field_size_tree
);
14854 field_size_in_bits
= type_size_in_bits
;
14856 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14858 /* The GCC front-end doesn't make any attempt to keep track of the
14859 starting bit offset (relative to the start of the containing
14860 structure type) of the hypothetical "containing object" for a
14861 bit-field. Thus, when computing the byte offset value for the
14862 start of the "containing object" of a bit-field, we must deduce
14863 this information on our own. This can be rather tricky to do in
14864 some cases. For example, handling the following structure type
14865 definition when compiling for an i386/i486 target (which only
14866 aligns long long's to 32-bit boundaries) can be very tricky:
14868 struct S { int field1; long long field2:31; };
14870 Fortunately, there is a simple rule-of-thumb which can be used
14871 in such cases. When compiling for an i386/i486, GCC will
14872 allocate 8 bytes for the structure shown above. It decides to
14873 do this based upon one simple rule for bit-field allocation.
14874 GCC allocates each "containing object" for each bit-field at
14875 the first (i.e. lowest addressed) legitimate alignment boundary
14876 (based upon the required minimum alignment for the declared
14877 type of the field) which it can possibly use, subject to the
14878 condition that there is still enough available space remaining
14879 in the containing object (when allocated at the selected point)
14880 to fully accommodate all of the bits of the bit-field itself.
14882 This simple rule makes it obvious why GCC allocates 8 bytes for
14883 each object of the structure type shown above. When looking
14884 for a place to allocate the "containing object" for `field2',
14885 the compiler simply tries to allocate a 64-bit "containing
14886 object" at each successive 32-bit boundary (starting at zero)
14887 until it finds a place to allocate that 64- bit field such that
14888 at least 31 contiguous (and previously unallocated) bits remain
14889 within that selected 64 bit field. (As it turns out, for the
14890 example above, the compiler finds it is OK to allocate the
14891 "containing object" 64-bit field at bit-offset zero within the
14894 Here we attempt to work backwards from the limited set of facts
14895 we're given, and we try to deduce from those facts, where GCC
14896 must have believed that the containing object started (within
14897 the structure type). The value we deduce is then used (by the
14898 callers of this routine) to generate DW_AT_location and
14899 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14900 the case of DW_AT_location, regular fields as well). */
14902 /* Figure out the bit-distance from the start of the structure to
14903 the "deepest" bit of the bit-field. */
14904 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14906 /* This is the tricky part. Use some fancy footwork to deduce
14907 where the lowest addressed bit of the containing object must
14909 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14911 /* Round up to type_align by default. This works best for
14913 object_offset_in_bits
14914 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14916 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
14918 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14920 /* Round up to decl_align instead. */
14921 object_offset_in_bits
14922 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14926 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14927 object_offset_in_bits
= bitpos_int
;
14929 object_offset_in_bytes
14930 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
14931 return object_offset_in_bytes
.to_shwi ();
14934 /* The following routines define various Dwarf attributes and any data
14935 associated with them. */
14937 /* Add a location description attribute value to a DIE.
14939 This emits location attributes suitable for whole variables and
14940 whole parameters. Note that the location attributes for struct fields are
14941 generated by the routine `data_member_location_attribute' below. */
14944 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14945 dw_loc_list_ref descr
)
14949 if (single_element_loc_list_p (descr
))
14950 add_AT_loc (die
, attr_kind
, descr
->expr
);
14952 add_AT_loc_list (die
, attr_kind
, descr
);
14955 /* Add DW_AT_accessibility attribute to DIE if needed. */
14958 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14960 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14961 children, otherwise the default is DW_ACCESS_public. In DWARF2
14962 the default has always been DW_ACCESS_public. */
14963 if (TREE_PROTECTED (decl
))
14964 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14965 else if (TREE_PRIVATE (decl
))
14967 if (dwarf_version
== 2
14968 || die
->die_parent
== NULL
14969 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14970 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14972 else if (dwarf_version
> 2
14974 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14975 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14978 /* Attach the specialized form of location attribute used for data members of
14979 struct and union types. In the special case of a FIELD_DECL node which
14980 represents a bit-field, the "offset" part of this special location
14981 descriptor must indicate the distance in bytes from the lowest-addressed
14982 byte of the containing struct or union type to the lowest-addressed byte of
14983 the "containing object" for the bit-field. (See the `field_byte_offset'
14986 For any given bit-field, the "containing object" is a hypothetical object
14987 (of some integral or enum type) within which the given bit-field lives. The
14988 type of this hypothetical "containing object" is always the same as the
14989 declared type of the individual bit-field itself (for GCC anyway... the
14990 DWARF spec doesn't actually mandate this). Note that it is the size (in
14991 bytes) of the hypothetical "containing object" which will be given in the
14992 DW_AT_byte_size attribute for this bit-field. (See the
14993 `byte_size_attribute' function below.) It is also used when calculating the
14994 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14995 function below.) */
14998 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15000 HOST_WIDE_INT offset
;
15001 dw_loc_descr_ref loc_descr
= 0;
15003 if (TREE_CODE (decl
) == TREE_BINFO
)
15005 /* We're working on the TAG_inheritance for a base class. */
15006 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15008 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15009 aren't at a fixed offset from all (sub)objects of the same
15010 type. We need to extract the appropriate offset from our
15011 vtable. The following dwarf expression means
15013 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15015 This is specific to the V3 ABI, of course. */
15017 dw_loc_descr_ref tmp
;
15019 /* Make a copy of the object address. */
15020 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15021 add_loc_descr (&loc_descr
, tmp
);
15023 /* Extract the vtable address. */
15024 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15025 add_loc_descr (&loc_descr
, tmp
);
15027 /* Calculate the address of the offset. */
15028 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15029 gcc_assert (offset
< 0);
15031 tmp
= int_loc_descriptor (-offset
);
15032 add_loc_descr (&loc_descr
, tmp
);
15033 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15034 add_loc_descr (&loc_descr
, tmp
);
15036 /* Extract the offset. */
15037 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15038 add_loc_descr (&loc_descr
, tmp
);
15040 /* Add it to the object address. */
15041 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15042 add_loc_descr (&loc_descr
, tmp
);
15045 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15048 offset
= field_byte_offset (decl
);
15052 if (dwarf_version
> 2)
15054 /* Don't need to output a location expression, just the constant. */
15056 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15058 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15063 enum dwarf_location_atom op
;
15065 /* The DWARF2 standard says that we should assume that the structure
15066 address is already on the stack, so we can specify a structure
15067 field address by using DW_OP_plus_uconst. */
15068 op
= DW_OP_plus_uconst
;
15069 loc_descr
= new_loc_descr (op
, offset
, 0);
15073 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15076 /* Writes integer values to dw_vec_const array. */
15079 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15083 *dest
++ = val
& 0xff;
15089 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15091 static HOST_WIDE_INT
15092 extract_int (const unsigned char *src
, unsigned int size
)
15094 HOST_WIDE_INT val
= 0;
15100 val
|= *--src
& 0xff;
15106 /* Writes wide_int values to dw_vec_const array. */
15109 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15113 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15115 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15119 /* We'd have to extend this code to support odd sizes. */
15120 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
) == 0);
15122 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
);
15124 if (WORDS_BIG_ENDIAN
)
15125 for (i
= n
- 1; i
>= 0; i
--)
15127 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15128 dest
+= sizeof (HOST_WIDE_INT
);
15131 for (i
= 0; i
< n
; i
++)
15133 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15134 dest
+= sizeof (HOST_WIDE_INT
);
15138 /* Writes floating point values to dw_vec_const array. */
15141 insert_float (const_rtx rtl
, unsigned char *array
)
15143 REAL_VALUE_TYPE rv
;
15147 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15148 real_to_target (val
, &rv
, GET_MODE (rtl
));
15150 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15151 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15153 insert_int (val
[i
], 4, array
);
15158 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15159 does not have a "location" either in memory or in a register. These
15160 things can arise in GNU C when a constant is passed as an actual parameter
15161 to an inlined function. They can also arise in C++ where declared
15162 constants do not necessarily get memory "homes". */
15165 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15167 switch (GET_CODE (rtl
))
15171 HOST_WIDE_INT val
= INTVAL (rtl
);
15174 add_AT_int (die
, DW_AT_const_value
, val
);
15176 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15180 case CONST_WIDE_INT
:
15181 add_AT_wide (die
, DW_AT_const_value
,
15182 std::make_pair (rtl
, GET_MODE (rtl
)));
15186 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15187 floating-point constant. A CONST_DOUBLE is used whenever the
15188 constant requires more than one word in order to be adequately
15191 enum machine_mode mode
= GET_MODE (rtl
);
15193 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15194 add_AT_double (die
, DW_AT_const_value
,
15195 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15198 unsigned int length
= GET_MODE_SIZE (mode
);
15199 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15201 insert_float (rtl
, array
);
15202 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15209 enum machine_mode mode
= GET_MODE (rtl
);
15210 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15211 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15212 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15213 (length
* elt_size
);
15216 enum machine_mode imode
= GET_MODE_INNER (mode
);
15218 switch (GET_MODE_CLASS (mode
))
15220 case MODE_VECTOR_INT
:
15221 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15223 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15224 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15228 case MODE_VECTOR_FLOAT
:
15229 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15231 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15232 insert_float (elt
, p
);
15237 gcc_unreachable ();
15240 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15245 if (dwarf_version
>= 4 || !dwarf_strict
)
15247 dw_loc_descr_ref loc_result
;
15248 resolve_one_addr (&rtl
, NULL
);
15250 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15251 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15252 add_AT_loc (die
, DW_AT_location
, loc_result
);
15253 vec_safe_push (used_rtx_array
, rtl
);
15259 if (CONSTANT_P (XEXP (rtl
, 0)))
15260 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15263 if (!const_ok_for_output (rtl
))
15266 if (dwarf_version
>= 4 || !dwarf_strict
)
15271 /* In cases where an inlined instance of an inline function is passed
15272 the address of an `auto' variable (which is local to the caller) we
15273 can get a situation where the DECL_RTL of the artificial local
15274 variable (for the inlining) which acts as a stand-in for the
15275 corresponding formal parameter (of the inline function) will look
15276 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15277 exactly a compile-time constant expression, but it isn't the address
15278 of the (artificial) local variable either. Rather, it represents the
15279 *value* which the artificial local variable always has during its
15280 lifetime. We currently have no way to represent such quasi-constant
15281 values in Dwarf, so for now we just punt and generate nothing. */
15289 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15290 && MEM_READONLY_P (rtl
)
15291 && GET_MODE (rtl
) == BLKmode
)
15293 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15299 /* No other kinds of rtx should be possible here. */
15300 gcc_unreachable ();
15305 /* Determine whether the evaluation of EXPR references any variables
15306 or functions which aren't otherwise used (and therefore may not be
15309 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15310 void * data ATTRIBUTE_UNUSED
)
15312 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15313 *walk_subtrees
= 0;
15315 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15316 && ! TREE_ASM_WRITTEN (*tp
))
15318 /* ??? The C++ FE emits debug information for using decls, so
15319 putting gcc_unreachable here falls over. See PR31899. For now
15320 be conservative. */
15321 else if (!cgraph_global_info_ready
15322 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15324 else if (TREE_CODE (*tp
) == VAR_DECL
)
15326 struct varpool_node
*node
= varpool_get_node (*tp
);
15327 if (!node
|| !node
->definition
)
15330 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15331 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15333 /* The call graph machinery must have finished analyzing,
15334 optimizing and gimplifying the CU by now.
15335 So if *TP has no call graph node associated
15336 to it, it means *TP will not be emitted. */
15337 if (!cgraph_get_node (*tp
))
15340 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15346 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15347 for use in a later add_const_value_attribute call. */
15350 rtl_for_decl_init (tree init
, tree type
)
15352 rtx rtl
= NULL_RTX
;
15356 /* If a variable is initialized with a string constant without embedded
15357 zeros, build CONST_STRING. */
15358 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15360 tree enttype
= TREE_TYPE (type
);
15361 tree domain
= TYPE_DOMAIN (type
);
15362 enum machine_mode mode
= TYPE_MODE (enttype
);
15364 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15366 && integer_zerop (TYPE_MIN_VALUE (domain
))
15367 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15368 TREE_STRING_LENGTH (init
) - 1) == 0
15369 && ((size_t) TREE_STRING_LENGTH (init
)
15370 == strlen (TREE_STRING_POINTER (init
)) + 1))
15372 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15373 ggc_strdup (TREE_STRING_POINTER (init
)));
15374 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15375 MEM_READONLY_P (rtl
) = 1;
15378 /* Other aggregates, and complex values, could be represented using
15380 else if (AGGREGATE_TYPE_P (type
)
15381 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15382 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15383 || TREE_CODE (type
) == COMPLEX_TYPE
)
15385 /* Vectors only work if their mode is supported by the target.
15386 FIXME: generic vectors ought to work too. */
15387 else if (TREE_CODE (type
) == VECTOR_TYPE
15388 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15390 /* If the initializer is something that we know will expand into an
15391 immediate RTL constant, expand it now. We must be careful not to
15392 reference variables which won't be output. */
15393 else if (initializer_constant_valid_p (init
, type
)
15394 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15396 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15398 if (TREE_CODE (type
) == VECTOR_TYPE
)
15399 switch (TREE_CODE (init
))
15404 if (TREE_CONSTANT (init
))
15406 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15407 bool constant_p
= true;
15409 unsigned HOST_WIDE_INT ix
;
15411 /* Even when ctor is constant, it might contain non-*_CST
15412 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15413 belong into VECTOR_CST nodes. */
15414 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15415 if (!CONSTANT_CLASS_P (value
))
15417 constant_p
= false;
15423 init
= build_vector_from_ctor (type
, elts
);
15433 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15435 /* If expand_expr returns a MEM, it wasn't immediate. */
15436 gcc_assert (!rtl
|| !MEM_P (rtl
));
15442 /* Generate RTL for the variable DECL to represent its location. */
15445 rtl_for_decl_location (tree decl
)
15449 /* Here we have to decide where we are going to say the parameter "lives"
15450 (as far as the debugger is concerned). We only have a couple of
15451 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15453 DECL_RTL normally indicates where the parameter lives during most of the
15454 activation of the function. If optimization is enabled however, this
15455 could be either NULL or else a pseudo-reg. Both of those cases indicate
15456 that the parameter doesn't really live anywhere (as far as the code
15457 generation parts of GCC are concerned) during most of the function's
15458 activation. That will happen (for example) if the parameter is never
15459 referenced within the function.
15461 We could just generate a location descriptor here for all non-NULL
15462 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15463 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15464 where DECL_RTL is NULL or is a pseudo-reg.
15466 Note however that we can only get away with using DECL_INCOMING_RTL as
15467 a backup substitute for DECL_RTL in certain limited cases. In cases
15468 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15469 we can be sure that the parameter was passed using the same type as it is
15470 declared to have within the function, and that its DECL_INCOMING_RTL
15471 points us to a place where a value of that type is passed.
15473 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15474 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15475 because in these cases DECL_INCOMING_RTL points us to a value of some
15476 type which is *different* from the type of the parameter itself. Thus,
15477 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15478 such cases, the debugger would end up (for example) trying to fetch a
15479 `float' from a place which actually contains the first part of a
15480 `double'. That would lead to really incorrect and confusing
15481 output at debug-time.
15483 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15484 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15485 are a couple of exceptions however. On little-endian machines we can
15486 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15487 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15488 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15489 when (on a little-endian machine) a non-prototyped function has a
15490 parameter declared to be of type `short' or `char'. In such cases,
15491 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15492 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15493 passed `int' value. If the debugger then uses that address to fetch
15494 a `short' or a `char' (on a little-endian machine) the result will be
15495 the correct data, so we allow for such exceptional cases below.
15497 Note that our goal here is to describe the place where the given formal
15498 parameter lives during most of the function's activation (i.e. between the
15499 end of the prologue and the start of the epilogue). We'll do that as best
15500 as we can. Note however that if the given formal parameter is modified
15501 sometime during the execution of the function, then a stack backtrace (at
15502 debug-time) will show the function as having been called with the *new*
15503 value rather than the value which was originally passed in. This happens
15504 rarely enough that it is not a major problem, but it *is* a problem, and
15505 I'd like to fix it.
15507 A future version of dwarf2out.c may generate two additional attributes for
15508 any given DW_TAG_formal_parameter DIE which will describe the "passed
15509 type" and the "passed location" for the given formal parameter in addition
15510 to the attributes we now generate to indicate the "declared type" and the
15511 "active location" for each parameter. This additional set of attributes
15512 could be used by debuggers for stack backtraces. Separately, note that
15513 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15514 This happens (for example) for inlined-instances of inline function formal
15515 parameters which are never referenced. This really shouldn't be
15516 happening. All PARM_DECL nodes should get valid non-NULL
15517 DECL_INCOMING_RTL values. FIXME. */
15519 /* Use DECL_RTL as the "location" unless we find something better. */
15520 rtl
= DECL_RTL_IF_SET (decl
);
15522 /* When generating abstract instances, ignore everything except
15523 constants, symbols living in memory, and symbols living in
15524 fixed registers. */
15525 if (! reload_completed
)
15528 && (CONSTANT_P (rtl
)
15530 && CONSTANT_P (XEXP (rtl
, 0)))
15532 && TREE_CODE (decl
) == VAR_DECL
15533 && TREE_STATIC (decl
))))
15535 rtl
= targetm
.delegitimize_address (rtl
);
15540 else if (TREE_CODE (decl
) == PARM_DECL
)
15542 if (rtl
== NULL_RTX
15543 || is_pseudo_reg (rtl
)
15545 && is_pseudo_reg (XEXP (rtl
, 0))
15546 && DECL_INCOMING_RTL (decl
)
15547 && MEM_P (DECL_INCOMING_RTL (decl
))
15548 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15550 tree declared_type
= TREE_TYPE (decl
);
15551 tree passed_type
= DECL_ARG_TYPE (decl
);
15552 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15553 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15555 /* This decl represents a formal parameter which was optimized out.
15556 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15557 all cases where (rtl == NULL_RTX) just below. */
15558 if (dmode
== pmode
)
15559 rtl
= DECL_INCOMING_RTL (decl
);
15560 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15561 && SCALAR_INT_MODE_P (dmode
)
15562 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15563 && DECL_INCOMING_RTL (decl
))
15565 rtx inc
= DECL_INCOMING_RTL (decl
);
15568 else if (MEM_P (inc
))
15570 if (BYTES_BIG_ENDIAN
)
15571 rtl
= adjust_address_nv (inc
, dmode
,
15572 GET_MODE_SIZE (pmode
)
15573 - GET_MODE_SIZE (dmode
));
15580 /* If the parm was passed in registers, but lives on the stack, then
15581 make a big endian correction if the mode of the type of the
15582 parameter is not the same as the mode of the rtl. */
15583 /* ??? This is the same series of checks that are made in dbxout.c before
15584 we reach the big endian correction code there. It isn't clear if all
15585 of these checks are necessary here, but keeping them all is the safe
15587 else if (MEM_P (rtl
)
15588 && XEXP (rtl
, 0) != const0_rtx
15589 && ! CONSTANT_P (XEXP (rtl
, 0))
15590 /* Not passed in memory. */
15591 && !MEM_P (DECL_INCOMING_RTL (decl
))
15592 /* Not passed by invisible reference. */
15593 && (!REG_P (XEXP (rtl
, 0))
15594 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15595 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15596 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15597 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15600 /* Big endian correction check. */
15601 && BYTES_BIG_ENDIAN
15602 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15603 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15606 enum machine_mode addr_mode
= get_address_mode (rtl
);
15607 int offset
= (UNITS_PER_WORD
15608 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15610 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15611 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15614 else if (TREE_CODE (decl
) == VAR_DECL
15617 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15618 && BYTES_BIG_ENDIAN
)
15620 enum machine_mode addr_mode
= get_address_mode (rtl
);
15621 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15622 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15624 /* If a variable is declared "register" yet is smaller than
15625 a register, then if we store the variable to memory, it
15626 looks like we're storing a register-sized value, when in
15627 fact we are not. We need to adjust the offset of the
15628 storage location to reflect the actual value's bytes,
15629 else gdb will not be able to display it. */
15631 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15632 plus_constant (addr_mode
, XEXP (rtl
, 0),
15636 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15637 and will have been substituted directly into all expressions that use it.
15638 C does not have such a concept, but C++ and other languages do. */
15639 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15640 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15643 rtl
= targetm
.delegitimize_address (rtl
);
15645 /* If we don't look past the constant pool, we risk emitting a
15646 reference to a constant pool entry that isn't referenced from
15647 code, and thus is not emitted. */
15649 rtl
= avoid_constant_pool_reference (rtl
);
15651 /* Try harder to get a rtl. If this symbol ends up not being emitted
15652 in the current CU, resolve_addr will remove the expression referencing
15654 if (rtl
== NULL_RTX
15655 && TREE_CODE (decl
) == VAR_DECL
15656 && !DECL_EXTERNAL (decl
)
15657 && TREE_STATIC (decl
)
15658 && DECL_NAME (decl
)
15659 && !DECL_HARD_REGISTER (decl
)
15660 && DECL_MODE (decl
) != VOIDmode
)
15662 rtl
= make_decl_rtl_for_debug (decl
);
15664 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15665 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15672 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15673 returned. If so, the decl for the COMMON block is returned, and the
15674 value is the offset into the common block for the symbol. */
15677 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15679 tree val_expr
, cvar
;
15680 enum machine_mode mode
;
15681 HOST_WIDE_INT bitsize
, bitpos
;
15683 int unsignedp
, volatilep
= 0;
15685 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15686 it does not have a value (the offset into the common area), or if it
15687 is thread local (as opposed to global) then it isn't common, and shouldn't
15688 be handled as such. */
15689 if (TREE_CODE (decl
) != VAR_DECL
15690 || !TREE_STATIC (decl
)
15691 || !DECL_HAS_VALUE_EXPR_P (decl
)
15695 val_expr
= DECL_VALUE_EXPR (decl
);
15696 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15699 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15700 &mode
, &unsignedp
, &volatilep
, true);
15702 if (cvar
== NULL_TREE
15703 || TREE_CODE (cvar
) != VAR_DECL
15704 || DECL_ARTIFICIAL (cvar
)
15705 || !TREE_PUBLIC (cvar
))
15709 if (offset
!= NULL
)
15711 if (!tree_fits_shwi_p (offset
))
15713 *value
= tree_to_shwi (offset
);
15716 *value
+= bitpos
/ BITS_PER_UNIT
;
15721 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15722 data attribute for a variable or a parameter. We generate the
15723 DW_AT_const_value attribute only in those cases where the given variable
15724 or parameter does not have a true "location" either in memory or in a
15725 register. This can happen (for example) when a constant is passed as an
15726 actual argument in a call to an inline function. (It's possible that
15727 these things can crop up in other ways also.) Note that one type of
15728 constant value which can be passed into an inlined function is a constant
15729 pointer. This can happen for example if an actual argument in an inlined
15730 function call evaluates to a compile-time constant address.
15732 CACHE_P is true if it is worth caching the location list for DECL,
15733 so that future calls can reuse it rather than regenerate it from scratch.
15734 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15735 since we will need to refer to them each time the function is inlined. */
15738 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15739 enum dwarf_attribute attr
)
15742 dw_loc_list_ref list
;
15743 var_loc_list
*loc_list
;
15744 cached_dw_loc_list
*cache
;
15747 if (TREE_CODE (decl
) == ERROR_MARK
)
15750 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15751 || TREE_CODE (decl
) == RESULT_DECL
);
15753 /* Try to get some constant RTL for this decl, and use that as the value of
15756 rtl
= rtl_for_decl_location (decl
);
15757 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15758 && add_const_value_attribute (die
, rtl
))
15761 /* See if we have single element location list that is equivalent to
15762 a constant value. That way we are better to use add_const_value_attribute
15763 rather than expanding constant value equivalent. */
15764 loc_list
= lookup_decl_loc (decl
);
15767 && loc_list
->first
->next
== NULL
15768 && NOTE_P (loc_list
->first
->loc
)
15769 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15770 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15772 struct var_loc_node
*node
;
15774 node
= loc_list
->first
;
15775 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15776 if (GET_CODE (rtl
) == EXPR_LIST
)
15777 rtl
= XEXP (rtl
, 0);
15778 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15779 && add_const_value_attribute (die
, rtl
))
15782 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15783 list several times. See if we've already cached the contents. */
15785 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15789 cache
= (cached_dw_loc_list
*)
15790 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15792 list
= cache
->loc_list
;
15796 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15797 /* It is usually worth caching this result if the decl is from
15798 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15799 if (cache_p
&& list
&& list
->dw_loc_next
)
15801 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15802 DECL_UID (decl
), INSERT
);
15803 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15804 cache
->decl_id
= DECL_UID (decl
);
15805 cache
->loc_list
= list
;
15811 add_AT_location_description (die
, attr
, list
);
15814 /* None of that worked, so it must not really have a location;
15815 try adding a constant value attribute from the DECL_INITIAL. */
15816 return tree_add_const_value_attribute_for_decl (die
, decl
);
15819 /* Add VARIABLE and DIE into deferred locations list. */
15822 defer_location (tree variable
, dw_die_ref die
)
15824 deferred_locations entry
;
15825 entry
.variable
= variable
;
15827 vec_safe_push (deferred_locations_list
, entry
);
15830 /* Helper function for tree_add_const_value_attribute. Natively encode
15831 initializer INIT into an array. Return true if successful. */
15834 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15838 if (init
== NULL_TREE
)
15842 switch (TREE_CODE (init
))
15845 type
= TREE_TYPE (init
);
15846 if (TREE_CODE (type
) == ARRAY_TYPE
)
15848 tree enttype
= TREE_TYPE (type
);
15849 enum machine_mode mode
= TYPE_MODE (enttype
);
15851 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15853 if (int_size_in_bytes (type
) != size
)
15855 if (size
> TREE_STRING_LENGTH (init
))
15857 memcpy (array
, TREE_STRING_POINTER (init
),
15858 TREE_STRING_LENGTH (init
));
15859 memset (array
+ TREE_STRING_LENGTH (init
),
15860 '\0', size
- TREE_STRING_LENGTH (init
));
15863 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15868 type
= TREE_TYPE (init
);
15869 if (int_size_in_bytes (type
) != size
)
15871 if (TREE_CODE (type
) == ARRAY_TYPE
)
15873 HOST_WIDE_INT min_index
;
15874 unsigned HOST_WIDE_INT cnt
;
15875 int curpos
= 0, fieldsize
;
15876 constructor_elt
*ce
;
15878 if (TYPE_DOMAIN (type
) == NULL_TREE
15879 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
15882 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15883 if (fieldsize
<= 0)
15886 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
15887 memset (array
, '\0', size
);
15888 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15890 tree val
= ce
->value
;
15891 tree index
= ce
->index
;
15893 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15894 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
15897 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
15902 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15905 curpos
= pos
+ fieldsize
;
15906 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15908 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
15909 - tree_to_shwi (TREE_OPERAND (index
, 0));
15910 while (count
-- > 0)
15913 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15914 curpos
+= fieldsize
;
15917 gcc_assert (curpos
<= size
);
15921 else if (TREE_CODE (type
) == RECORD_TYPE
15922 || TREE_CODE (type
) == UNION_TYPE
)
15924 tree field
= NULL_TREE
;
15925 unsigned HOST_WIDE_INT cnt
;
15926 constructor_elt
*ce
;
15928 if (int_size_in_bytes (type
) != size
)
15931 if (TREE_CODE (type
) == RECORD_TYPE
)
15932 field
= TYPE_FIELDS (type
);
15934 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15936 tree val
= ce
->value
;
15937 int pos
, fieldsize
;
15939 if (ce
->index
!= 0)
15945 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15948 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15949 && TYPE_DOMAIN (TREE_TYPE (field
))
15950 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15952 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15953 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
15955 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
15956 pos
= int_byte_position (field
);
15957 gcc_assert (pos
+ fieldsize
<= size
);
15959 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15965 case VIEW_CONVERT_EXPR
:
15966 case NON_LVALUE_EXPR
:
15967 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15969 return native_encode_expr (init
, array
, size
) == size
;
15973 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15974 attribute is the const value T. */
15977 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15980 tree type
= TREE_TYPE (t
);
15983 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15987 gcc_assert (!DECL_P (init
));
15989 rtl
= rtl_for_decl_init (init
, type
);
15991 return add_const_value_attribute (die
, rtl
);
15992 /* If the host and target are sane, try harder. */
15993 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15994 && initializer_constant_valid_p (init
, type
))
15996 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15997 if (size
> 0 && (int) size
== size
)
15999 unsigned char *array
= (unsigned char *)
16000 ggc_alloc_cleared_atomic (size
);
16002 if (native_encode_initializer (init
, array
, size
))
16004 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16013 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16014 attribute is the const value of T, where T is an integral constant
16015 variable with static storage duration
16016 (so it can't be a PARM_DECL or a RESULT_DECL). */
16019 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16023 || (TREE_CODE (decl
) != VAR_DECL
16024 && TREE_CODE (decl
) != CONST_DECL
)
16025 || (TREE_CODE (decl
) == VAR_DECL
16026 && !TREE_STATIC (decl
)))
16029 if (TREE_READONLY (decl
)
16030 && ! TREE_THIS_VOLATILE (decl
)
16031 && DECL_INITIAL (decl
))
16036 /* Don't add DW_AT_const_value if abstract origin already has one. */
16037 if (get_AT (var_die
, DW_AT_const_value
))
16040 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16043 /* Convert the CFI instructions for the current function into a
16044 location list. This is used for DW_AT_frame_base when we targeting
16045 a dwarf2 consumer that does not support the dwarf3
16046 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16049 static dw_loc_list_ref
16050 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16054 dw_loc_list_ref list
, *list_tail
;
16056 dw_cfa_location last_cfa
, next_cfa
;
16057 const char *start_label
, *last_label
, *section
;
16058 dw_cfa_location remember
;
16061 gcc_assert (fde
!= NULL
);
16063 section
= secname_for_decl (current_function_decl
);
16067 memset (&next_cfa
, 0, sizeof (next_cfa
));
16068 next_cfa
.reg
= INVALID_REGNUM
;
16069 remember
= next_cfa
;
16071 start_label
= fde
->dw_fde_begin
;
16073 /* ??? Bald assumption that the CIE opcode list does not contain
16074 advance opcodes. */
16075 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16076 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16078 last_cfa
= next_cfa
;
16079 last_label
= start_label
;
16081 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16083 /* If the first partition contained no CFI adjustments, the
16084 CIE opcodes apply to the whole first partition. */
16085 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16086 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16087 list_tail
=&(*list_tail
)->dw_loc_next
;
16088 start_label
= last_label
= fde
->dw_fde_second_begin
;
16091 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16093 switch (cfi
->dw_cfi_opc
)
16095 case DW_CFA_set_loc
:
16096 case DW_CFA_advance_loc1
:
16097 case DW_CFA_advance_loc2
:
16098 case DW_CFA_advance_loc4
:
16099 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16101 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16102 start_label
, last_label
, section
);
16104 list_tail
= &(*list_tail
)->dw_loc_next
;
16105 last_cfa
= next_cfa
;
16106 start_label
= last_label
;
16108 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16111 case DW_CFA_advance_loc
:
16112 /* The encoding is complex enough that we should never emit this. */
16113 gcc_unreachable ();
16116 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16119 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16121 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16123 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16124 start_label
, last_label
, section
);
16126 list_tail
= &(*list_tail
)->dw_loc_next
;
16127 last_cfa
= next_cfa
;
16128 start_label
= last_label
;
16130 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16131 start_label
, fde
->dw_fde_end
, section
);
16132 list_tail
= &(*list_tail
)->dw_loc_next
;
16133 start_label
= last_label
= fde
->dw_fde_second_begin
;
16137 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16139 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16140 start_label
, last_label
, section
);
16141 list_tail
= &(*list_tail
)->dw_loc_next
;
16142 start_label
= last_label
;
16145 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16147 fde
->dw_fde_second_begin
16148 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16151 if (list
&& list
->dw_loc_next
)
16157 /* Compute a displacement from the "steady-state frame pointer" to the
16158 frame base (often the same as the CFA), and store it in
16159 frame_pointer_fb_offset. OFFSET is added to the displacement
16160 before the latter is negated. */
16163 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16167 #ifdef FRAME_POINTER_CFA_OFFSET
16168 reg
= frame_pointer_rtx
;
16169 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16171 reg
= arg_pointer_rtx
;
16172 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16175 elim
= (ira_use_lra_p
16176 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16177 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16178 if (GET_CODE (elim
) == PLUS
)
16180 offset
+= INTVAL (XEXP (elim
, 1));
16181 elim
= XEXP (elim
, 0);
16184 frame_pointer_fb_offset
= -offset
;
16186 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16187 in which to eliminate. This is because it's stack pointer isn't
16188 directly accessible as a register within the ISA. To work around
16189 this, assume that while we cannot provide a proper value for
16190 frame_pointer_fb_offset, we won't need one either. */
16191 frame_pointer_fb_offset_valid
16192 = ((SUPPORTS_STACK_ALIGNMENT
16193 && (elim
== hard_frame_pointer_rtx
16194 || elim
== stack_pointer_rtx
))
16195 || elim
== (frame_pointer_needed
16196 ? hard_frame_pointer_rtx
16197 : stack_pointer_rtx
));
16200 /* Generate a DW_AT_name attribute given some string value to be included as
16201 the value of the attribute. */
16204 add_name_attribute (dw_die_ref die
, const char *name_string
)
16206 if (name_string
!= NULL
&& *name_string
!= 0)
16208 if (demangle_name_func
)
16209 name_string
= (*demangle_name_func
) (name_string
);
16211 add_AT_string (die
, DW_AT_name
, name_string
);
16215 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16216 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16217 of TYPE accordingly.
16219 ??? This is a temporary measure until after we're able to generate
16220 regular DWARF for the complex Ada type system. */
16223 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16224 dw_die_ref context_die
)
16227 dw_die_ref dtype_die
;
16229 if (!lang_hooks
.types
.descriptive_type
)
16232 dtype
= lang_hooks
.types
.descriptive_type (type
);
16236 dtype_die
= lookup_type_die (dtype
);
16239 gen_type_die (dtype
, context_die
);
16240 dtype_die
= lookup_type_die (dtype
);
16241 gcc_assert (dtype_die
);
16244 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16247 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16249 static const char *
16250 comp_dir_string (void)
16254 static const char *cached_wd
= NULL
;
16256 if (cached_wd
!= NULL
)
16259 wd
= get_src_pwd ();
16263 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16267 wdlen
= strlen (wd
);
16268 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16270 wd1
[wdlen
] = DIR_SEPARATOR
;
16271 wd1
[wdlen
+ 1] = 0;
16275 cached_wd
= remap_debug_filename (wd
);
16279 /* Generate a DW_AT_comp_dir attribute for DIE. */
16282 add_comp_dir_attribute (dw_die_ref die
)
16284 const char * wd
= comp_dir_string ();
16286 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16289 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16293 lower_bound_default (void)
16295 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16300 case DW_LANG_C_plus_plus
:
16302 case DW_LANG_ObjC_plus_plus
:
16305 case DW_LANG_Fortran77
:
16306 case DW_LANG_Fortran90
:
16307 case DW_LANG_Fortran95
:
16311 case DW_LANG_Python
:
16312 return dwarf_version
>= 4 ? 0 : -1;
16313 case DW_LANG_Ada95
:
16314 case DW_LANG_Ada83
:
16315 case DW_LANG_Cobol74
:
16316 case DW_LANG_Cobol85
:
16317 case DW_LANG_Pascal83
:
16318 case DW_LANG_Modula2
:
16320 return dwarf_version
>= 4 ? 1 : -1;
16326 /* Given a tree node describing an array bound (either lower or upper) output
16327 a representation for that bound. */
16330 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16332 switch (TREE_CODE (bound
))
16337 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16340 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16343 /* Use the default if possible. */
16344 if (bound_attr
== DW_AT_lower_bound
16345 && tree_fits_shwi_p (bound
)
16346 && (dflt
= lower_bound_default ()) != -1
16347 && tree_to_shwi (bound
) == dflt
)
16350 /* Otherwise represent the bound as an unsigned value with the
16351 precision of its type. The precision and signedness of the
16352 type will be necessary to re-interpret it unambiguously. */
16353 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16355 unsigned HOST_WIDE_INT mask
16356 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16357 add_AT_unsigned (subrange_die
, bound_attr
,
16358 TREE_INT_CST_LOW (bound
) & mask
);
16360 else if (prec
== HOST_BITS_PER_WIDE_INT
|| tree_fits_uhwi_p (bound
))
16361 add_AT_unsigned (subrange_die
, bound_attr
,
16362 TREE_INT_CST_LOW (bound
));
16364 add_AT_wide (subrange_die
, bound_attr
, bound
);
16369 case VIEW_CONVERT_EXPR
:
16370 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16380 dw_die_ref decl_die
= lookup_decl_die (bound
);
16382 /* ??? Can this happen, or should the variable have been bound
16383 first? Probably it can, since I imagine that we try to create
16384 the types of parameters in the order in which they exist in
16385 the list, and won't have created a forward reference to a
16386 later parameter. */
16387 if (decl_die
!= NULL
)
16389 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16397 /* Otherwise try to create a stack operation procedure to
16398 evaluate the value of the array bound. */
16400 dw_die_ref ctx
, decl_die
;
16401 dw_loc_list_ref list
;
16403 list
= loc_list_from_tree (bound
, 2);
16404 if (list
== NULL
|| single_element_loc_list_p (list
))
16406 /* If DW_AT_*bound is not a reference nor constant, it is
16407 a DWARF expression rather than location description.
16408 For that loc_list_from_tree (bound, 0) is needed.
16409 If that fails to give a single element list,
16410 fall back to outputting this as a reference anyway. */
16411 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16412 if (list2
&& single_element_loc_list_p (list2
))
16414 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16421 if (current_function_decl
== 0)
16422 ctx
= comp_unit_die ();
16424 ctx
= lookup_decl_die (current_function_decl
);
16426 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16427 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16428 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16429 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16430 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16436 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16437 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16438 Note that the block of subscript information for an array type also
16439 includes information about the element type of the given array type. */
16442 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16444 unsigned dimension_number
;
16446 dw_die_ref subrange_die
;
16448 for (dimension_number
= 0;
16449 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16450 type
= TREE_TYPE (type
), dimension_number
++)
16452 tree domain
= TYPE_DOMAIN (type
);
16454 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16457 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16458 and (in GNU C only) variable bounds. Handle all three forms
16460 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16463 /* We have an array type with specified bounds. */
16464 lower
= TYPE_MIN_VALUE (domain
);
16465 upper
= TYPE_MAX_VALUE (domain
);
16467 /* Define the index type. */
16468 if (TREE_TYPE (domain
))
16470 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16471 TREE_TYPE field. We can't emit debug info for this
16472 because it is an unnamed integral type. */
16473 if (TREE_CODE (domain
) == INTEGER_TYPE
16474 && TYPE_NAME (domain
) == NULL_TREE
16475 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16476 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16479 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16483 /* ??? If upper is NULL, the array has unspecified length,
16484 but it does have a lower bound. This happens with Fortran
16486 Since the debugger is definitely going to need to know N
16487 to produce useful results, go ahead and output the lower
16488 bound solo, and hope the debugger can cope. */
16490 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16492 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16495 /* Otherwise we have an array type with an unspecified length. The
16496 DWARF-2 spec does not say how to handle this; let's just leave out the
16501 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16504 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16506 dw_die_ref decl_die
;
16507 HOST_WIDE_INT size
;
16509 switch (TREE_CODE (tree_node
))
16514 case ENUMERAL_TYPE
:
16517 case QUAL_UNION_TYPE
:
16518 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16519 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16521 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16524 size
= int_size_in_bytes (tree_node
);
16527 /* For a data member of a struct or union, the DW_AT_byte_size is
16528 generally given as the number of bytes normally allocated for an
16529 object of the *declared* type of the member itself. This is true
16530 even for bit-fields. */
16531 size
= int_size_in_bytes (field_type (tree_node
));
16534 gcc_unreachable ();
16537 /* Note that `size' might be -1 when we get to this point. If it is, that
16538 indicates that the byte size of the entity in question is variable. We
16539 have no good way of expressing this fact in Dwarf at the present time,
16540 when location description was not used by the caller code instead. */
16542 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16545 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16546 which specifies the distance in bits from the highest order bit of the
16547 "containing object" for the bit-field to the highest order bit of the
16550 For any given bit-field, the "containing object" is a hypothetical object
16551 (of some integral or enum type) within which the given bit-field lives. The
16552 type of this hypothetical "containing object" is always the same as the
16553 declared type of the individual bit-field itself. The determination of the
16554 exact location of the "containing object" for a bit-field is rather
16555 complicated. It's handled by the `field_byte_offset' function (above).
16557 Note that it is the size (in bytes) of the hypothetical "containing object"
16558 which will be given in the DW_AT_byte_size attribute for this bit-field.
16559 (See `byte_size_attribute' above). */
16562 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16564 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16565 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16566 HOST_WIDE_INT bitpos_int
;
16567 HOST_WIDE_INT highest_order_object_bit_offset
;
16568 HOST_WIDE_INT highest_order_field_bit_offset
;
16569 HOST_WIDE_INT bit_offset
;
16571 /* Must be a field and a bit field. */
16572 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16574 /* We can't yet handle bit-fields whose offsets are variable, so if we
16575 encounter such things, just return without generating any attribute
16576 whatsoever. Likewise for variable or too large size. */
16577 if (! tree_fits_shwi_p (bit_position (decl
))
16578 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
16581 bitpos_int
= int_bit_position (decl
);
16583 /* Note that the bit offset is always the distance (in bits) from the
16584 highest-order bit of the "containing object" to the highest-order bit of
16585 the bit-field itself. Since the "high-order end" of any object or field
16586 is different on big-endian and little-endian machines, the computation
16587 below must take account of these differences. */
16588 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16589 highest_order_field_bit_offset
= bitpos_int
;
16591 if (! BYTES_BIG_ENDIAN
)
16593 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
16594 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16598 = (! BYTES_BIG_ENDIAN
16599 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16600 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16602 if (bit_offset
< 0)
16603 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16605 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16608 /* For a FIELD_DECL node which represents a bit field, output an attribute
16609 which specifies the length in bits of the given field. */
16612 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16614 /* Must be a field and a bit field. */
16615 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16616 && DECL_BIT_FIELD_TYPE (decl
));
16618 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
16619 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
16622 /* If the compiled language is ANSI C, then add a 'prototyped'
16623 attribute, if arg types are given for the parameters of a function. */
16626 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16628 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16629 && prototype_p (func_type
))
16630 add_AT_flag (die
, DW_AT_prototyped
, 1);
16633 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16634 by looking in either the type declaration or object declaration
16637 static inline dw_die_ref
16638 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16640 dw_die_ref origin_die
= NULL
;
16642 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16644 /* We may have gotten separated from the block for the inlined
16645 function, if we're in an exception handler or some such; make
16646 sure that the abstract function has been written out.
16648 Doing this for nested functions is wrong, however; functions are
16649 distinct units, and our context might not even be inline. */
16653 fn
= TYPE_STUB_DECL (fn
);
16655 fn
= decl_function_context (fn
);
16657 dwarf2out_abstract_function (fn
);
16660 if (DECL_P (origin
))
16661 origin_die
= lookup_decl_die (origin
);
16662 else if (TYPE_P (origin
))
16663 origin_die
= lookup_type_die (origin
);
16665 /* XXX: Functions that are never lowered don't always have correct block
16666 trees (in the case of java, they simply have no block tree, in some other
16667 languages). For these functions, there is nothing we can really do to
16668 output correct debug info for inlined functions in all cases. Rather
16669 than die, we'll just produce deficient debug info now, in that we will
16670 have variables without a proper abstract origin. In the future, when all
16671 functions are lowered, we should re-add a gcc_assert (origin_die)
16675 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16679 /* We do not currently support the pure_virtual attribute. */
16682 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16684 if (DECL_VINDEX (func_decl
))
16686 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16688 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
16689 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16690 new_loc_descr (DW_OP_constu
,
16691 tree_to_shwi (DECL_VINDEX (func_decl
)),
16694 /* GNU extension: Record what type this method came from originally. */
16695 if (debug_info_level
> DINFO_LEVEL_TERSE
16696 && DECL_CONTEXT (func_decl
))
16697 add_AT_die_ref (die
, DW_AT_containing_type
,
16698 lookup_type_die (DECL_CONTEXT (func_decl
)));
16702 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16703 given decl. This used to be a vendor extension until after DWARF 4
16704 standardized it. */
16707 add_linkage_attr (dw_die_ref die
, tree decl
)
16709 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16711 /* Mimic what assemble_name_raw does with a leading '*'. */
16712 if (name
[0] == '*')
16715 if (dwarf_version
>= 4)
16716 add_AT_string (die
, DW_AT_linkage_name
, name
);
16718 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16721 /* Add source coordinate attributes for the given decl. */
16724 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16726 expanded_location s
;
16728 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16730 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16731 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16732 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16735 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16738 add_linkage_name (dw_die_ref die
, tree decl
)
16740 if (debug_info_level
> DINFO_LEVEL_TERSE
16741 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16742 && TREE_PUBLIC (decl
)
16743 && !DECL_ABSTRACT (decl
)
16744 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16745 && die
->die_tag
!= DW_TAG_member
)
16747 /* Defer until we have an assembler name set. */
16748 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16750 limbo_die_node
*asm_name
;
16752 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16753 asm_name
->die
= die
;
16754 asm_name
->created_for
= decl
;
16755 asm_name
->next
= deferred_asm_name
;
16756 deferred_asm_name
= asm_name
;
16758 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16759 add_linkage_attr (die
, decl
);
16763 /* Add a DW_AT_name attribute and source coordinate attribute for the
16764 given decl, but only if it actually has a name. */
16767 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16771 decl_name
= DECL_NAME (decl
);
16772 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16774 const char *name
= dwarf2_name (decl
, 0);
16776 add_name_attribute (die
, name
);
16777 if (! DECL_ARTIFICIAL (decl
))
16778 add_src_coords_attributes (die
, decl
);
16780 add_linkage_name (die
, decl
);
16783 #ifdef VMS_DEBUGGING_INFO
16784 /* Get the function's name, as described by its RTL. This may be different
16785 from the DECL_NAME name used in the source file. */
16786 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16788 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16789 XEXP (DECL_RTL (decl
), 0), false);
16790 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16792 #endif /* VMS_DEBUGGING_INFO */
16795 #ifdef VMS_DEBUGGING_INFO
16796 /* Output the debug main pointer die for VMS */
16799 dwarf2out_vms_debug_main_pointer (void)
16801 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16804 /* Allocate the VMS debug main subprogram die. */
16805 die
= ggc_alloc_cleared_die_node ();
16806 die
->die_tag
= DW_TAG_subprogram
;
16807 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16808 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16809 current_function_funcdef_no
);
16810 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16812 /* Make it the first child of comp_unit_die (). */
16813 die
->die_parent
= comp_unit_die ();
16814 if (comp_unit_die ()->die_child
)
16816 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16817 comp_unit_die ()->die_child
->die_sib
= die
;
16821 die
->die_sib
= die
;
16822 comp_unit_die ()->die_child
= die
;
16825 #endif /* VMS_DEBUGGING_INFO */
16827 /* Push a new declaration scope. */
16830 push_decl_scope (tree scope
)
16832 vec_safe_push (decl_scope_table
, scope
);
16835 /* Pop a declaration scope. */
16838 pop_decl_scope (void)
16840 decl_scope_table
->pop ();
16843 /* walk_tree helper function for uses_local_type, below. */
16846 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16849 *walk_subtrees
= 0;
16852 tree name
= TYPE_NAME (*tp
);
16853 if (name
&& DECL_P (name
) && decl_function_context (name
))
16859 /* If TYPE involves a function-local type (including a local typedef to a
16860 non-local type), returns that type; otherwise returns NULL_TREE. */
16863 uses_local_type (tree type
)
16865 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16869 /* Return the DIE for the scope that immediately contains this type.
16870 Non-named types that do not involve a function-local type get global
16871 scope. Named types nested in namespaces or other types get their
16872 containing scope. All other types (i.e. function-local named types) get
16873 the current active scope. */
16876 scope_die_for (tree t
, dw_die_ref context_die
)
16878 dw_die_ref scope_die
= NULL
;
16879 tree containing_scope
;
16881 /* Non-types always go in the current scope. */
16882 gcc_assert (TYPE_P (t
));
16884 /* Use the scope of the typedef, rather than the scope of the type
16886 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16887 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16889 containing_scope
= TYPE_CONTEXT (t
);
16891 /* Use the containing namespace if there is one. */
16892 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16894 if (context_die
== lookup_decl_die (containing_scope
))
16896 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16897 context_die
= get_context_die (containing_scope
);
16899 containing_scope
= NULL_TREE
;
16902 /* Ignore function type "scopes" from the C frontend. They mean that
16903 a tagged type is local to a parmlist of a function declarator, but
16904 that isn't useful to DWARF. */
16905 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16906 containing_scope
= NULL_TREE
;
16908 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16910 /* If T uses a local type keep it local as well, to avoid references
16911 to function-local DIEs from outside the function. */
16912 if (current_function_decl
&& uses_local_type (t
))
16913 scope_die
= context_die
;
16915 scope_die
= comp_unit_die ();
16917 else if (TYPE_P (containing_scope
))
16919 /* For types, we can just look up the appropriate DIE. */
16920 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16921 scope_die
= get_context_die (containing_scope
);
16924 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16925 if (scope_die
== NULL
)
16926 scope_die
= comp_unit_die ();
16930 scope_die
= context_die
;
16935 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16938 local_scope_p (dw_die_ref context_die
)
16940 for (; context_die
; context_die
= context_die
->die_parent
)
16941 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16942 || context_die
->die_tag
== DW_TAG_subprogram
)
16948 /* Returns nonzero if CONTEXT_DIE is a class. */
16951 class_scope_p (dw_die_ref context_die
)
16953 return (context_die
16954 && (context_die
->die_tag
== DW_TAG_structure_type
16955 || context_die
->die_tag
== DW_TAG_class_type
16956 || context_die
->die_tag
== DW_TAG_interface_type
16957 || context_die
->die_tag
== DW_TAG_union_type
));
16960 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16961 whether or not to treat a DIE in this context as a declaration. */
16964 class_or_namespace_scope_p (dw_die_ref context_die
)
16966 return (class_scope_p (context_die
)
16967 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16970 /* Many forms of DIEs require a "type description" attribute. This
16971 routine locates the proper "type descriptor" die for the type given
16972 by 'type', and adds a DW_AT_type attribute below the given die. */
16975 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16976 int decl_volatile
, dw_die_ref context_die
)
16978 enum tree_code code
= TREE_CODE (type
);
16979 dw_die_ref type_die
= NULL
;
16981 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16982 or fixed-point type, use the inner type. This is because we have no
16983 support for unnamed types in base_type_die. This can happen if this is
16984 an Ada subrange type. Correct solution is emit a subrange type die. */
16985 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16986 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16987 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16989 if (code
== ERROR_MARK
16990 /* Handle a special case. For functions whose return type is void, we
16991 generate *no* type attribute. (Note that no object may have type
16992 `void', so this only applies to function return types). */
16993 || code
== VOID_TYPE
)
16996 type_die
= modified_type_die (type
,
16997 decl_const
|| TYPE_READONLY (type
),
16998 decl_volatile
|| TYPE_VOLATILE (type
),
17001 if (type_die
!= NULL
)
17002 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17005 /* Given an object die, add the calling convention attribute for the
17006 function call type. */
17008 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17010 enum dwarf_calling_convention value
= DW_CC_normal
;
17012 value
= ((enum dwarf_calling_convention
)
17013 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17016 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17018 /* DWARF 2 doesn't provide a way to identify a program's source-level
17019 entry point. DW_AT_calling_convention attributes are only meant
17020 to describe functions' calling conventions. However, lacking a
17021 better way to signal the Fortran main program, we used this for
17022 a long time, following existing custom. Now, DWARF 4 has
17023 DW_AT_main_subprogram, which we add below, but some tools still
17024 rely on the old way, which we thus keep. */
17025 value
= DW_CC_program
;
17027 if (dwarf_version
>= 4 || !dwarf_strict
)
17028 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17031 /* Only add the attribute if the backend requests it, and
17032 is not DW_CC_normal. */
17033 if (value
&& (value
!= DW_CC_normal
))
17034 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17037 /* Given a tree pointer to a struct, class, union, or enum type node, return
17038 a pointer to the (string) tag name for the given type, or zero if the type
17039 was declared without a tag. */
17041 static const char *
17042 type_tag (const_tree type
)
17044 const char *name
= 0;
17046 if (TYPE_NAME (type
) != 0)
17050 /* Find the IDENTIFIER_NODE for the type name. */
17051 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17052 && !TYPE_NAMELESS (type
))
17053 t
= TYPE_NAME (type
);
17055 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17056 a TYPE_DECL node, regardless of whether or not a `typedef' was
17058 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17059 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17061 /* We want to be extra verbose. Don't call dwarf_name if
17062 DECL_NAME isn't set. The default hook for decl_printable_name
17063 doesn't like that, and in this context it's correct to return
17064 0, instead of "<anonymous>" or the like. */
17065 if (DECL_NAME (TYPE_NAME (type
))
17066 && !DECL_NAMELESS (TYPE_NAME (type
)))
17067 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17070 /* Now get the name as a string, or invent one. */
17071 if (!name
&& t
!= 0)
17072 name
= IDENTIFIER_POINTER (t
);
17075 return (name
== 0 || *name
== '\0') ? 0 : name
;
17078 /* Return the type associated with a data member, make a special check
17079 for bit field types. */
17082 member_declared_type (const_tree member
)
17084 return (DECL_BIT_FIELD_TYPE (member
)
17085 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17088 /* Get the decl's label, as described by its RTL. This may be different
17089 from the DECL_NAME name used in the source file. */
17092 static const char *
17093 decl_start_label (tree decl
)
17096 const char *fnname
;
17098 x
= DECL_RTL (decl
);
17099 gcc_assert (MEM_P (x
));
17102 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17104 fnname
= XSTR (x
, 0);
17109 /* These routines generate the internal representation of the DIE's for
17110 the compilation unit. Debugging information is collected by walking
17111 the declaration trees passed in from dwarf2out_decl(). */
17114 gen_array_type_die (tree type
, dw_die_ref context_die
)
17116 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17117 dw_die_ref array_die
;
17119 /* GNU compilers represent multidimensional array types as sequences of one
17120 dimensional array types whose element types are themselves array types.
17121 We sometimes squish that down to a single array_type DIE with multiple
17122 subscripts in the Dwarf debugging info. The draft Dwarf specification
17123 say that we are allowed to do this kind of compression in C, because
17124 there is no difference between an array of arrays and a multidimensional
17125 array. We don't do this for Ada to remain as close as possible to the
17126 actual representation, which is especially important against the language
17127 flexibilty wrt arrays of variable size. */
17129 bool collapse_nested_arrays
= !is_ada ();
17132 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17133 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17134 if (TYPE_STRING_FLAG (type
)
17135 && TREE_CODE (type
) == ARRAY_TYPE
17137 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17139 HOST_WIDE_INT size
;
17141 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17142 add_name_attribute (array_die
, type_tag (type
));
17143 equate_type_number_to_die (type
, array_die
);
17144 size
= int_size_in_bytes (type
);
17146 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17147 else if (TYPE_DOMAIN (type
) != NULL_TREE
17148 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17149 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17151 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17152 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
17154 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17155 if (loc
&& size
> 0)
17157 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17158 if (size
!= DWARF2_ADDR_SIZE
)
17159 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17165 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17166 add_name_attribute (array_die
, type_tag (type
));
17167 equate_type_number_to_die (type
, array_die
);
17169 if (TREE_CODE (type
) == VECTOR_TYPE
)
17170 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17172 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17174 && TREE_CODE (type
) == ARRAY_TYPE
17175 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17176 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17177 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17180 /* We default the array ordering. SDB will probably do
17181 the right things even if DW_AT_ordering is not present. It's not even
17182 an issue until we start to get into multidimensional arrays anyway. If
17183 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17184 then we'll have to put the DW_AT_ordering attribute back in. (But if
17185 and when we find out that we need to put these in, we will only do so
17186 for multidimensional arrays. */
17187 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17190 if (TREE_CODE (type
) == VECTOR_TYPE
)
17192 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17193 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17194 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17195 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17196 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17199 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17201 /* Add representation of the type of the elements of this array type and
17202 emit the corresponding DIE if we haven't done it already. */
17203 element_type
= TREE_TYPE (type
);
17204 if (collapse_nested_arrays
)
17205 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17207 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17209 element_type
= TREE_TYPE (element_type
);
17212 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17214 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17215 if (TYPE_ARTIFICIAL (type
))
17216 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17218 if (get_AT (array_die
, DW_AT_name
))
17219 add_pubtype (type
, array_die
);
17222 static dw_loc_descr_ref
17223 descr_info_loc (tree val
, tree base_decl
)
17225 HOST_WIDE_INT size
;
17226 dw_loc_descr_ref loc
, loc2
;
17227 enum dwarf_location_atom op
;
17229 if (val
== base_decl
)
17230 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17232 switch (TREE_CODE (val
))
17235 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17237 return loc_descriptor_from_tree (val
, 0);
17239 if (tree_fits_shwi_p (val
))
17240 return int_loc_descriptor (tree_to_shwi (val
));
17243 size
= int_size_in_bytes (TREE_TYPE (val
));
17246 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17249 if (size
== DWARF2_ADDR_SIZE
)
17250 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17252 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17254 case POINTER_PLUS_EXPR
:
17256 if (tree_fits_uhwi_p (TREE_OPERAND (val
, 1))
17257 && tree_to_uhwi (TREE_OPERAND (val
, 1)) < 16384)
17259 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17262 loc_descr_plus_const (&loc
, tree_to_shwi (TREE_OPERAND (val
, 1)));
17268 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17271 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17274 add_loc_descr (&loc
, loc2
);
17275 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17297 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17298 tree val
, tree base_decl
)
17300 dw_loc_descr_ref loc
;
17302 if (tree_fits_shwi_p (val
))
17304 add_AT_unsigned (die
, attr
, tree_to_shwi (val
));
17308 loc
= descr_info_loc (val
, base_decl
);
17312 add_AT_loc (die
, attr
, loc
);
17315 /* This routine generates DIE for array with hidden descriptor, details
17316 are filled into *info by a langhook. */
17319 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17320 dw_die_ref context_die
)
17322 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17323 dw_die_ref array_die
;
17326 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17327 add_name_attribute (array_die
, type_tag (type
));
17328 equate_type_number_to_die (type
, array_die
);
17330 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17332 && info
->ndimensions
>= 2)
17333 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17335 if (info
->data_location
)
17336 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17338 if (info
->associated
)
17339 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17341 if (info
->allocated
)
17342 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17345 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17347 dw_die_ref subrange_die
17348 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17350 if (info
->dimen
[dim
].lower_bound
)
17352 /* If it is the default value, omit it. */
17355 if (tree_fits_shwi_p (info
->dimen
[dim
].lower_bound
)
17356 && (dflt
= lower_bound_default ()) != -1
17357 && tree_to_shwi (info
->dimen
[dim
].lower_bound
) == dflt
)
17360 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17361 info
->dimen
[dim
].lower_bound
,
17364 if (info
->dimen
[dim
].upper_bound
)
17365 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17366 info
->dimen
[dim
].upper_bound
,
17368 if (info
->dimen
[dim
].stride
)
17369 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17370 info
->dimen
[dim
].stride
,
17374 gen_type_die (info
->element_type
, context_die
);
17375 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17377 if (get_AT (array_die
, DW_AT_name
))
17378 add_pubtype (type
, array_die
);
17383 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17385 tree origin
= decl_ultimate_origin (decl
);
17386 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17388 if (origin
!= NULL
)
17389 add_abstract_origin_attribute (decl_die
, origin
);
17392 add_name_and_src_coords_attributes (decl_die
, decl
);
17393 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17394 0, 0, context_die
);
17397 if (DECL_ABSTRACT (decl
))
17398 equate_decl_number_to_die (decl
, decl_die
);
17400 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17404 /* Walk through the list of incomplete types again, trying once more to
17405 emit full debugging info for them. */
17408 retry_incomplete_types (void)
17412 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17413 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17414 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17417 /* Determine what tag to use for a record type. */
17419 static enum dwarf_tag
17420 record_type_tag (tree type
)
17422 if (! lang_hooks
.types
.classify_record
)
17423 return DW_TAG_structure_type
;
17425 switch (lang_hooks
.types
.classify_record (type
))
17427 case RECORD_IS_STRUCT
:
17428 return DW_TAG_structure_type
;
17430 case RECORD_IS_CLASS
:
17431 return DW_TAG_class_type
;
17433 case RECORD_IS_INTERFACE
:
17434 if (dwarf_version
>= 3 || !dwarf_strict
)
17435 return DW_TAG_interface_type
;
17436 return DW_TAG_structure_type
;
17439 gcc_unreachable ();
17443 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17444 include all of the information about the enumeration values also. Each
17445 enumerated type name/value is listed as a child of the enumerated type
17449 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17451 dw_die_ref type_die
= lookup_type_die (type
);
17453 if (type_die
== NULL
)
17455 type_die
= new_die (DW_TAG_enumeration_type
,
17456 scope_die_for (type
, context_die
), type
);
17457 equate_type_number_to_die (type
, type_die
);
17458 add_name_attribute (type_die
, type_tag (type
));
17459 if (dwarf_version
>= 4 || !dwarf_strict
)
17461 if (ENUM_IS_SCOPED (type
))
17462 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17463 if (ENUM_IS_OPAQUE (type
))
17464 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17467 else if (! TYPE_SIZE (type
))
17470 remove_AT (type_die
, DW_AT_declaration
);
17472 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17473 given enum type is incomplete, do not generate the DW_AT_byte_size
17474 attribute or the DW_AT_element_list attribute. */
17475 if (TYPE_SIZE (type
))
17479 TREE_ASM_WRITTEN (type
) = 1;
17480 add_byte_size_attribute (type_die
, type
);
17481 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17483 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17484 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17487 /* If the first reference to this type was as the return type of an
17488 inline function, then it may not have a parent. Fix this now. */
17489 if (type_die
->die_parent
== NULL
)
17490 add_child_die (scope_die_for (type
, context_die
), type_die
);
17492 for (link
= TYPE_VALUES (type
);
17493 link
!= NULL
; link
= TREE_CHAIN (link
))
17495 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17496 tree value
= TREE_VALUE (link
);
17498 add_name_attribute (enum_die
,
17499 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17501 if (TREE_CODE (value
) == CONST_DECL
)
17502 value
= DECL_INITIAL (value
);
17504 if (simple_type_size_in_bits (TREE_TYPE (value
))
17505 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17506 /* DWARF2 does not provide a way of indicating whether or
17507 not enumeration constants are signed or unsigned. GDB
17508 always assumes the values are signed, so we output all
17509 values as if they were signed. That means that
17510 enumeration constants with very large unsigned values
17511 will appear to have negative values in the debugger.
17513 TODO: the above comment is wrong, DWARF2 does provide
17514 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17515 This should be re-worked to use correct signed/unsigned
17516 int/double tags for all cases, instead of always treating as
17518 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17520 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17522 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17525 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17526 if (TYPE_ARTIFICIAL (type
))
17527 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17530 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17532 add_pubtype (type
, type_die
);
17537 /* Generate a DIE to represent either a real live formal parameter decl or to
17538 represent just the type of some formal parameter position in some function
17541 Note that this routine is a bit unusual because its argument may be a
17542 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17543 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17544 node. If it's the former then this function is being called to output a
17545 DIE to represent a formal parameter object (or some inlining thereof). If
17546 it's the latter, then this function is only being called to output a
17547 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17548 argument type of some subprogram type.
17549 If EMIT_NAME_P is true, name and source coordinate attributes
17553 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17554 dw_die_ref context_die
)
17556 tree node_or_origin
= node
? node
: origin
;
17557 tree ultimate_origin
;
17558 dw_die_ref parm_die
17559 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17561 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17563 case tcc_declaration
:
17564 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17565 if (node
|| ultimate_origin
)
17566 origin
= ultimate_origin
;
17567 if (origin
!= NULL
)
17568 add_abstract_origin_attribute (parm_die
, origin
);
17569 else if (emit_name_p
)
17570 add_name_and_src_coords_attributes (parm_die
, node
);
17572 || (! DECL_ABSTRACT (node_or_origin
)
17573 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17574 decl_function_context
17575 (node_or_origin
))))
17577 tree type
= TREE_TYPE (node_or_origin
);
17578 if (decl_by_reference_p (node_or_origin
))
17579 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17582 add_type_attribute (parm_die
, type
,
17583 TREE_READONLY (node_or_origin
),
17584 TREE_THIS_VOLATILE (node_or_origin
),
17587 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17588 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17590 if (node
&& node
!= origin
)
17591 equate_decl_number_to_die (node
, parm_die
);
17592 if (! DECL_ABSTRACT (node_or_origin
))
17593 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17594 node
== NULL
, DW_AT_location
);
17599 /* We were called with some kind of a ..._TYPE node. */
17600 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17604 gcc_unreachable ();
17610 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17611 children DW_TAG_formal_parameter DIEs representing the arguments of the
17614 PARM_PACK must be a function parameter pack.
17615 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17616 must point to the subsequent arguments of the function PACK_ARG belongs to.
17617 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17618 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17619 following the last one for which a DIE was generated. */
17622 gen_formal_parameter_pack_die (tree parm_pack
,
17624 dw_die_ref subr_die
,
17628 dw_die_ref parm_pack_die
;
17630 gcc_assert (parm_pack
17631 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17634 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17635 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17637 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17639 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17642 gen_formal_parameter_die (arg
, NULL
,
17643 false /* Don't emit name attribute. */,
17648 return parm_pack_die
;
17651 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17652 at the end of an (ANSI prototyped) formal parameters list. */
17655 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17657 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17660 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17661 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17662 parameters as specified in some function type specification (except for
17663 those which appear as part of a function *definition*). */
17666 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17669 tree formal_type
= NULL
;
17670 tree first_parm_type
;
17673 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17675 arg
= DECL_ARGUMENTS (function_or_method_type
);
17676 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17681 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17683 /* Make our first pass over the list of formal parameter types and output a
17684 DW_TAG_formal_parameter DIE for each one. */
17685 for (link
= first_parm_type
; link
; )
17687 dw_die_ref parm_die
;
17689 formal_type
= TREE_VALUE (link
);
17690 if (formal_type
== void_type_node
)
17693 /* Output a (nameless) DIE to represent the formal parameter itself. */
17694 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17695 true /* Emit name attribute. */,
17697 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17698 && link
== first_parm_type
)
17700 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17701 if (dwarf_version
>= 3 || !dwarf_strict
)
17702 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17704 else if (arg
&& DECL_ARTIFICIAL (arg
))
17705 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17707 link
= TREE_CHAIN (link
);
17709 arg
= DECL_CHAIN (arg
);
17712 /* If this function type has an ellipsis, add a
17713 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17714 if (formal_type
!= void_type_node
)
17715 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17717 /* Make our second (and final) pass over the list of formal parameter types
17718 and output DIEs to represent those types (as necessary). */
17719 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17720 link
&& TREE_VALUE (link
);
17721 link
= TREE_CHAIN (link
))
17722 gen_type_die (TREE_VALUE (link
), context_die
);
17725 /* We want to generate the DIE for TYPE so that we can generate the
17726 die for MEMBER, which has been defined; we will need to refer back
17727 to the member declaration nested within TYPE. If we're trying to
17728 generate minimal debug info for TYPE, processing TYPE won't do the
17729 trick; we need to attach the member declaration by hand. */
17732 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17734 gen_type_die (type
, context_die
);
17736 /* If we're trying to avoid duplicate debug info, we may not have
17737 emitted the member decl for this function. Emit it now. */
17738 if (TYPE_STUB_DECL (type
)
17739 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17740 && ! lookup_decl_die (member
))
17742 dw_die_ref type_die
;
17743 gcc_assert (!decl_ultimate_origin (member
));
17745 push_decl_scope (type
);
17746 type_die
= lookup_type_die_strip_naming_typedef (type
);
17747 if (TREE_CODE (member
) == FUNCTION_DECL
)
17748 gen_subprogram_die (member
, type_die
);
17749 else if (TREE_CODE (member
) == FIELD_DECL
)
17751 /* Ignore the nameless fields that are used to skip bits but handle
17752 C++ anonymous unions and structs. */
17753 if (DECL_NAME (member
) != NULL_TREE
17754 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17755 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17757 gen_type_die (member_declared_type (member
), type_die
);
17758 gen_field_die (member
, type_die
);
17762 gen_variable_die (member
, NULL_TREE
, type_die
);
17768 /* Forward declare these functions, because they are mutually recursive
17769 with their set_block_* pairing functions. */
17770 static void set_decl_origin_self (tree
);
17771 static void set_decl_abstract_flags (tree
, int);
17773 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17774 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17775 that it points to the node itself, thus indicating that the node is its
17776 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17777 the given node is NULL, recursively descend the decl/block tree which
17778 it is the root of, and for each other ..._DECL or BLOCK node contained
17779 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17780 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17781 values to point to themselves. */
17784 set_block_origin_self (tree stmt
)
17786 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17788 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17793 for (local_decl
= BLOCK_VARS (stmt
);
17794 local_decl
!= NULL_TREE
;
17795 local_decl
= DECL_CHAIN (local_decl
))
17796 if (! DECL_EXTERNAL (local_decl
))
17797 set_decl_origin_self (local_decl
); /* Potential recursion. */
17803 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17804 subblock
!= NULL_TREE
;
17805 subblock
= BLOCK_CHAIN (subblock
))
17806 set_block_origin_self (subblock
); /* Recurse. */
17811 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17812 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17813 node to so that it points to the node itself, thus indicating that the
17814 node represents its own (abstract) origin. Additionally, if the
17815 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17816 the decl/block tree of which the given node is the root of, and for
17817 each other ..._DECL or BLOCK node contained therein whose
17818 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17819 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17820 point to themselves. */
17823 set_decl_origin_self (tree decl
)
17825 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17827 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17828 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17832 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17833 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17834 if (DECL_INITIAL (decl
) != NULL_TREE
17835 && DECL_INITIAL (decl
) != error_mark_node
)
17836 set_block_origin_self (DECL_INITIAL (decl
));
17841 /* Given a pointer to some BLOCK node, and a boolean value to set the
17842 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17843 the given block, and for all local decls and all local sub-blocks
17844 (recursively) which are contained therein. */
17847 set_block_abstract_flags (tree stmt
, int setting
)
17853 BLOCK_ABSTRACT (stmt
) = setting
;
17855 for (local_decl
= BLOCK_VARS (stmt
);
17856 local_decl
!= NULL_TREE
;
17857 local_decl
= DECL_CHAIN (local_decl
))
17858 if (! DECL_EXTERNAL (local_decl
))
17859 set_decl_abstract_flags (local_decl
, setting
);
17861 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17863 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17864 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17865 || TREE_CODE (local_decl
) == PARM_DECL
)
17866 set_decl_abstract_flags (local_decl
, setting
);
17869 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17870 subblock
!= NULL_TREE
;
17871 subblock
= BLOCK_CHAIN (subblock
))
17872 set_block_abstract_flags (subblock
, setting
);
17875 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17876 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17877 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17878 set the abstract flags for all of the parameters, local vars, local
17879 blocks and sub-blocks (recursively) to the same setting. */
17882 set_decl_abstract_flags (tree decl
, int setting
)
17884 DECL_ABSTRACT (decl
) = setting
;
17885 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17889 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17890 DECL_ABSTRACT (arg
) = setting
;
17891 if (DECL_INITIAL (decl
) != NULL_TREE
17892 && DECL_INITIAL (decl
) != error_mark_node
)
17893 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17897 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17898 may later generate inlined and/or out-of-line instances of. */
17901 dwarf2out_abstract_function (tree decl
)
17903 dw_die_ref old_die
;
17907 htab_t old_decl_loc_table
;
17908 htab_t old_cached_dw_loc_list_table
;
17909 int old_call_site_count
, old_tail_call_site_count
;
17910 struct call_arg_loc_node
*old_call_arg_locations
;
17912 /* Make sure we have the actual abstract inline, not a clone. */
17913 decl
= DECL_ORIGIN (decl
);
17915 old_die
= lookup_decl_die (decl
);
17916 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17917 /* We've already generated the abstract instance. */
17920 /* We can be called while recursively when seeing block defining inlined subroutine
17921 DIE. Be sure to not clobber the outer location table nor use it or we would
17922 get locations in abstract instantces. */
17923 old_decl_loc_table
= decl_loc_table
;
17924 decl_loc_table
= NULL
;
17925 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17926 cached_dw_loc_list_table
= NULL
;
17927 old_call_arg_locations
= call_arg_locations
;
17928 call_arg_locations
= NULL
;
17929 old_call_site_count
= call_site_count
;
17930 call_site_count
= -1;
17931 old_tail_call_site_count
= tail_call_site_count
;
17932 tail_call_site_count
= -1;
17934 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17935 we don't get confused by DECL_ABSTRACT. */
17936 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17938 context
= decl_class_context (decl
);
17940 gen_type_die_for_member
17941 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17944 /* Pretend we've just finished compiling this function. */
17945 save_fn
= current_function_decl
;
17946 current_function_decl
= decl
;
17948 was_abstract
= DECL_ABSTRACT (decl
);
17949 set_decl_abstract_flags (decl
, 1);
17950 dwarf2out_decl (decl
);
17951 if (! was_abstract
)
17952 set_decl_abstract_flags (decl
, 0);
17954 current_function_decl
= save_fn
;
17955 decl_loc_table
= old_decl_loc_table
;
17956 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17957 call_arg_locations
= old_call_arg_locations
;
17958 call_site_count
= old_call_site_count
;
17959 tail_call_site_count
= old_tail_call_site_count
;
17962 /* Helper function of premark_used_types() which gets called through
17965 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17966 marked as unused by prune_unused_types. */
17969 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17974 type
= (tree
) *slot
;
17975 die
= lookup_type_die (type
);
17977 die
->die_perennial_p
= 1;
17981 /* Helper function of premark_types_used_by_global_vars which gets called
17982 through htab_traverse.
17984 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17985 marked as unused by prune_unused_types. The DIE of the type is marked
17986 only if the global variable using the type will actually be emitted. */
17989 premark_types_used_by_global_vars_helper (void **slot
,
17990 void *data ATTRIBUTE_UNUSED
)
17992 struct types_used_by_vars_entry
*entry
;
17995 entry
= (struct types_used_by_vars_entry
*) *slot
;
17996 gcc_assert (entry
->type
!= NULL
17997 && entry
->var_decl
!= NULL
);
17998 die
= lookup_type_die (entry
->type
);
18001 /* Ask cgraph if the global variable really is to be emitted.
18002 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18003 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
18004 if (node
&& node
->definition
)
18006 die
->die_perennial_p
= 1;
18007 /* Keep the parent DIEs as well. */
18008 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18009 die
->die_perennial_p
= 1;
18015 /* Mark all members of used_types_hash as perennial. */
18018 premark_used_types (struct function
*fun
)
18020 if (fun
&& fun
->used_types_hash
)
18021 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
18024 /* Mark all members of types_used_by_vars_entry as perennial. */
18027 premark_types_used_by_global_vars (void)
18029 if (types_used_by_vars_hash
)
18030 htab_traverse (types_used_by_vars_hash
,
18031 premark_types_used_by_global_vars_helper
, NULL
);
18034 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18035 for CA_LOC call arg loc node. */
18038 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18039 struct call_arg_loc_node
*ca_loc
)
18041 dw_die_ref stmt_die
= NULL
, die
;
18042 tree block
= ca_loc
->block
;
18045 && block
!= DECL_INITIAL (decl
)
18046 && TREE_CODE (block
) == BLOCK
)
18048 if (block_map
.length () > BLOCK_NUMBER (block
))
18049 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
18052 block
= BLOCK_SUPERCONTEXT (block
);
18054 if (stmt_die
== NULL
)
18055 stmt_die
= subr_die
;
18056 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18057 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18058 if (ca_loc
->tail_call_p
)
18059 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18060 if (ca_loc
->symbol_ref
)
18062 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18064 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18066 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18071 /* Generate a DIE to represent a declared function (either file-scope or
18075 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18077 tree origin
= decl_ultimate_origin (decl
);
18078 dw_die_ref subr_die
;
18080 dw_die_ref old_die
= lookup_decl_die (decl
);
18081 int declaration
= (current_function_decl
!= decl
18082 || class_or_namespace_scope_p (context_die
));
18084 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18086 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18087 started to generate the abstract instance of an inline, decided to output
18088 its containing class, and proceeded to emit the declaration of the inline
18089 from the member list for the class. If so, DECLARATION takes priority;
18090 we'll get back to the abstract instance when done with the class. */
18092 /* The class-scope declaration DIE must be the primary DIE. */
18093 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
18096 gcc_assert (!old_die
);
18099 /* Now that the C++ front end lazily declares artificial member fns, we
18100 might need to retrofit the declaration into its class. */
18101 if (!declaration
&& !origin
&& !old_die
18102 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18103 && !class_or_namespace_scope_p (context_die
)
18104 && debug_info_level
> DINFO_LEVEL_TERSE
)
18105 old_die
= force_decl_die (decl
);
18107 if (origin
!= NULL
)
18109 gcc_assert (!declaration
|| local_scope_p (context_die
));
18111 /* Fixup die_parent for the abstract instance of a nested
18112 inline function. */
18113 if (old_die
&& old_die
->die_parent
== NULL
)
18114 add_child_die (context_die
, old_die
);
18116 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18117 add_abstract_origin_attribute (subr_die
, origin
);
18118 /* This is where the actual code for a cloned function is.
18119 Let's emit linkage name attribute for it. This helps
18120 debuggers to e.g, set breakpoints into
18121 constructors/destructors when the user asks "break
18123 add_linkage_name (subr_die
, decl
);
18127 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18128 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18130 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18131 /* We can have a normal definition following an inline one in the
18132 case of redefinition of GNU C extern inlines.
18133 It seems reasonable to use AT_specification in this case. */
18134 && !get_AT (old_die
, DW_AT_inline
))
18136 /* Detect and ignore this case, where we are trying to output
18137 something we have already output. */
18141 /* If the definition comes from the same place as the declaration,
18142 maybe use the old DIE. We always want the DIE for this function
18143 that has the *_pc attributes to be under comp_unit_die so the
18144 debugger can find it. We also need to do this for abstract
18145 instances of inlines, since the spec requires the out-of-line copy
18146 to have the same parent. For local class methods, this doesn't
18147 apply; we just use the old DIE. */
18148 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
18149 && (DECL_ARTIFICIAL (decl
)
18150 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18151 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18152 == (unsigned) s
.line
))))
18154 subr_die
= old_die
;
18156 /* Clear out the declaration attribute and the formal parameters.
18157 Do not remove all children, because it is possible that this
18158 declaration die was forced using force_decl_die(). In such
18159 cases die that forced declaration die (e.g. TAG_imported_module)
18160 is one of the children that we do not want to remove. */
18161 remove_AT (subr_die
, DW_AT_declaration
);
18162 remove_AT (subr_die
, DW_AT_object_pointer
);
18163 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18167 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18168 add_AT_specification (subr_die
, old_die
);
18169 add_pubname (decl
, subr_die
);
18170 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18171 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18172 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18173 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18178 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18180 if (TREE_PUBLIC (decl
))
18181 add_AT_flag (subr_die
, DW_AT_external
, 1);
18183 add_name_and_src_coords_attributes (subr_die
, decl
);
18184 add_pubname (decl
, subr_die
);
18185 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18187 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18188 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18189 0, 0, context_die
);
18192 add_pure_or_virtual_attribute (subr_die
, decl
);
18193 if (DECL_ARTIFICIAL (decl
))
18194 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18196 add_accessibility_attribute (subr_die
, decl
);
18201 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18203 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18205 /* If this is an explicit function declaration then generate
18206 a DW_AT_explicit attribute. */
18207 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18208 && (dwarf_version
>= 3 || !dwarf_strict
))
18209 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18211 /* The first time we see a member function, it is in the context of
18212 the class to which it belongs. We make sure of this by emitting
18213 the class first. The next time is the definition, which is
18214 handled above. The two may come from the same source text.
18216 Note that force_decl_die() forces function declaration die. It is
18217 later reused to represent definition. */
18218 equate_decl_number_to_die (decl
, subr_die
);
18221 else if (DECL_ABSTRACT (decl
))
18223 if (DECL_DECLARED_INLINE_P (decl
))
18225 if (cgraph_function_possibly_inlined_p (decl
))
18226 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18228 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18232 if (cgraph_function_possibly_inlined_p (decl
))
18233 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18235 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18238 if (DECL_DECLARED_INLINE_P (decl
)
18239 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18240 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18242 equate_decl_number_to_die (decl
, subr_die
);
18244 else if (!DECL_EXTERNAL (decl
))
18246 HOST_WIDE_INT cfa_fb_offset
;
18247 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18249 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18250 equate_decl_number_to_die (decl
, subr_die
);
18252 gcc_checking_assert (fun
);
18253 if (!flag_reorder_blocks_and_partition
)
18255 dw_fde_ref fde
= fun
->fde
;
18256 if (fde
->dw_fde_begin
)
18258 /* We have already generated the labels. */
18259 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18260 fde
->dw_fde_end
, false);
18264 /* Create start/end labels and add the range. */
18265 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18266 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18267 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18268 current_function_funcdef_no
);
18269 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18270 current_function_funcdef_no
);
18271 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18275 #if VMS_DEBUGGING_INFO
18276 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18277 Section 2.3 Prologue and Epilogue Attributes:
18278 When a breakpoint is set on entry to a function, it is generally
18279 desirable for execution to be suspended, not on the very first
18280 instruction of the function, but rather at a point after the
18281 function's frame has been set up, after any language defined local
18282 declaration processing has been completed, and before execution of
18283 the first statement of the function begins. Debuggers generally
18284 cannot properly determine where this point is. Similarly for a
18285 breakpoint set on exit from a function. The prologue and epilogue
18286 attributes allow a compiler to communicate the location(s) to use. */
18289 if (fde
->dw_fde_vms_end_prologue
)
18290 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18291 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18293 if (fde
->dw_fde_vms_begin_epilogue
)
18294 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18295 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18302 /* Generate pubnames entries for the split function code ranges. */
18303 dw_fde_ref fde
= fun
->fde
;
18305 if (fde
->dw_fde_second_begin
)
18307 if (dwarf_version
>= 3 || !dwarf_strict
)
18309 /* We should use ranges for non-contiguous code section
18310 addresses. Use the actual code range for the initial
18311 section, since the HOT/COLD labels might precede an
18312 alignment offset. */
18313 bool range_list_added
= false;
18314 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18315 fde
->dw_fde_end
, &range_list_added
,
18317 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18318 fde
->dw_fde_second_end
,
18319 &range_list_added
, false);
18320 if (range_list_added
)
18325 /* There is no real support in DW2 for this .. so we make
18326 a work-around. First, emit the pub name for the segment
18327 containing the function label. Then make and emit a
18328 simplified subprogram DIE for the second segment with the
18329 name pre-fixed by __hot/cold_sect_of_. We use the same
18330 linkage name for the second die so that gdb will find both
18331 sections when given "b foo". */
18332 const char *name
= NULL
;
18333 tree decl_name
= DECL_NAME (decl
);
18334 dw_die_ref seg_die
;
18336 /* Do the 'primary' section. */
18337 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18338 fde
->dw_fde_end
, false);
18340 /* Build a minimal DIE for the secondary section. */
18341 seg_die
= new_die (DW_TAG_subprogram
,
18342 subr_die
->die_parent
, decl
);
18344 if (TREE_PUBLIC (decl
))
18345 add_AT_flag (seg_die
, DW_AT_external
, 1);
18347 if (decl_name
!= NULL
18348 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18350 name
= dwarf2_name (decl
, 1);
18351 if (! DECL_ARTIFICIAL (decl
))
18352 add_src_coords_attributes (seg_die
, decl
);
18354 add_linkage_name (seg_die
, decl
);
18356 gcc_assert (name
!= NULL
);
18357 add_pure_or_virtual_attribute (seg_die
, decl
);
18358 if (DECL_ARTIFICIAL (decl
))
18359 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18361 name
= concat ("__second_sect_of_", name
, NULL
);
18362 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18363 fde
->dw_fde_second_end
, false);
18364 add_name_attribute (seg_die
, name
);
18365 if (want_pubnames ())
18366 add_pubname_string (name
, seg_die
);
18370 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18374 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18376 /* We define the "frame base" as the function's CFA. This is more
18377 convenient for several reasons: (1) It's stable across the prologue
18378 and epilogue, which makes it better than just a frame pointer,
18379 (2) With dwarf3, there exists a one-byte encoding that allows us
18380 to reference the .debug_frame data by proxy, but failing that,
18381 (3) We can at least reuse the code inspection and interpretation
18382 code that determines the CFA position at various points in the
18384 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18386 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18387 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18391 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18392 if (list
->dw_loc_next
)
18393 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18395 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18398 /* Compute a displacement from the "steady-state frame pointer" to
18399 the CFA. The former is what all stack slots and argument slots
18400 will reference in the rtl; the latter is what we've told the
18401 debugger about. We'll need to adjust all frame_base references
18402 by this displacement. */
18403 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18405 if (fun
->static_chain_decl
)
18406 add_AT_location_description (subr_die
, DW_AT_static_link
,
18407 loc_list_from_tree (fun
->static_chain_decl
, 2));
18410 /* Generate child dies for template paramaters. */
18411 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18412 gen_generic_params_dies (decl
);
18414 /* Now output descriptions of the arguments for this function. This gets
18415 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18416 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18417 `...' at the end of the formal parameter list. In order to find out if
18418 there was a trailing ellipsis or not, we must instead look at the type
18419 associated with the FUNCTION_DECL. This will be a node of type
18420 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18421 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18422 an ellipsis at the end. */
18424 /* In the case where we are describing a mere function declaration, all we
18425 need to do here (and all we *can* do here) is to describe the *types* of
18426 its formal parameters. */
18427 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18429 else if (declaration
)
18430 gen_formal_types_die (decl
, subr_die
);
18433 /* Generate DIEs to represent all known formal parameters. */
18434 tree parm
= DECL_ARGUMENTS (decl
);
18435 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18436 tree generic_decl_parm
= generic_decl
18437 ? DECL_ARGUMENTS (generic_decl
)
18440 /* Now we want to walk the list of parameters of the function and
18441 emit their relevant DIEs.
18443 We consider the case of DECL being an instance of a generic function
18444 as well as it being a normal function.
18446 If DECL is an instance of a generic function we walk the
18447 parameters of the generic function declaration _and_ the parameters of
18448 DECL itself. This is useful because we want to emit specific DIEs for
18449 function parameter packs and those are declared as part of the
18450 generic function declaration. In that particular case,
18451 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18452 That DIE has children DIEs representing the set of arguments
18453 of the pack. Note that the set of pack arguments can be empty.
18454 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18457 Otherwise, we just consider the parameters of DECL. */
18458 while (generic_decl_parm
|| parm
)
18460 if (generic_decl_parm
18461 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18462 gen_formal_parameter_pack_die (generic_decl_parm
,
18465 else if (parm
&& !POINTER_BOUNDS_P (parm
))
18467 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18469 if (parm
== DECL_ARGUMENTS (decl
)
18470 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18472 && (dwarf_version
>= 3 || !dwarf_strict
))
18473 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18475 parm
= DECL_CHAIN (parm
);
18478 parm
= DECL_CHAIN (parm
);
18480 if (generic_decl_parm
)
18481 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18484 /* Decide whether we need an unspecified_parameters DIE at the end.
18485 There are 2 more cases to do this for: 1) the ansi ... declaration -
18486 this is detectable when the end of the arg list is not a
18487 void_type_node 2) an unprototyped function declaration (not a
18488 definition). This just means that we have no info about the
18489 parameters at all. */
18490 if (prototype_p (TREE_TYPE (decl
)))
18492 /* This is the prototyped case, check for.... */
18493 if (stdarg_p (TREE_TYPE (decl
)))
18494 gen_unspecified_parameters_die (decl
, subr_die
);
18496 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18497 gen_unspecified_parameters_die (decl
, subr_die
);
18500 /* Output Dwarf info for all of the stuff within the body of the function
18501 (if it has one - it may be just a declaration). */
18502 outer_scope
= DECL_INITIAL (decl
);
18504 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18505 a function. This BLOCK actually represents the outermost binding contour
18506 for the function, i.e. the contour in which the function's formal
18507 parameters and labels get declared. Curiously, it appears that the front
18508 end doesn't actually put the PARM_DECL nodes for the current function onto
18509 the BLOCK_VARS list for this outer scope, but are strung off of the
18510 DECL_ARGUMENTS list for the function instead.
18512 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18513 the LABEL_DECL nodes for the function however, and we output DWARF info
18514 for those in decls_for_scope. Just within the `outer_scope' there will be
18515 a BLOCK node representing the function's outermost pair of curly braces,
18516 and any blocks used for the base and member initializers of a C++
18517 constructor function. */
18518 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18520 int call_site_note_count
= 0;
18521 int tail_call_site_note_count
= 0;
18523 /* Emit a DW_TAG_variable DIE for a named return value. */
18524 if (DECL_NAME (DECL_RESULT (decl
)))
18525 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18527 current_function_has_inlines
= 0;
18528 decls_for_scope (outer_scope
, subr_die
, 0);
18530 if (call_arg_locations
&& !dwarf_strict
)
18532 struct call_arg_loc_node
*ca_loc
;
18533 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18535 dw_die_ref die
= NULL
;
18536 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18539 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18540 arg
; arg
= next_arg
)
18542 dw_loc_descr_ref reg
, val
;
18543 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18544 dw_die_ref cdie
, tdie
= NULL
;
18546 next_arg
= XEXP (arg
, 1);
18547 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18549 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18550 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18551 && REGNO (XEXP (XEXP (arg
, 0), 0))
18552 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18553 next_arg
= XEXP (next_arg
, 1);
18554 if (mode
== VOIDmode
)
18556 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18557 if (mode
== VOIDmode
)
18558 mode
= GET_MODE (XEXP (arg
, 0));
18560 if (mode
== VOIDmode
|| mode
== BLKmode
)
18562 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18564 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18565 tloc
= XEXP (XEXP (arg
, 0), 1);
18568 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18569 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18571 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18572 tlocc
= XEXP (XEXP (arg
, 0), 1);
18576 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18577 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18578 VAR_INIT_STATUS_INITIALIZED
);
18579 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18581 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18582 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18583 get_address_mode (mem
),
18585 VAR_INIT_STATUS_INITIALIZED
);
18587 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18588 == DEBUG_PARAMETER_REF
)
18591 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18592 tdie
= lookup_decl_die (tdecl
);
18599 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18600 != DEBUG_PARAMETER_REF
)
18602 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18604 VAR_INIT_STATUS_INITIALIZED
);
18608 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18609 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18612 add_AT_loc (cdie
, DW_AT_location
, reg
);
18613 else if (tdie
!= NULL
)
18614 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18615 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18616 if (next_arg
!= XEXP (arg
, 1))
18618 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18619 if (mode
== VOIDmode
)
18620 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18621 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18624 VAR_INIT_STATUS_INITIALIZED
);
18626 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18630 && (ca_loc
->symbol_ref
|| tloc
))
18631 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18632 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18634 dw_loc_descr_ref tval
= NULL
;
18636 if (tloc
!= NULL_RTX
)
18637 tval
= mem_loc_descriptor (tloc
,
18638 GET_MODE (tloc
) == VOIDmode
18639 ? Pmode
: GET_MODE (tloc
),
18641 VAR_INIT_STATUS_INITIALIZED
);
18643 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18644 else if (tlocc
!= NULL_RTX
)
18646 tval
= mem_loc_descriptor (tlocc
,
18647 GET_MODE (tlocc
) == VOIDmode
18648 ? Pmode
: GET_MODE (tlocc
),
18650 VAR_INIT_STATUS_INITIALIZED
);
18652 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18658 call_site_note_count
++;
18659 if (ca_loc
->tail_call_p
)
18660 tail_call_site_note_count
++;
18664 call_arg_locations
= NULL
;
18665 call_arg_loc_last
= NULL
;
18666 if (tail_call_site_count
>= 0
18667 && tail_call_site_count
== tail_call_site_note_count
18670 if (call_site_count
>= 0
18671 && call_site_count
== call_site_note_count
)
18672 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18674 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18676 call_site_count
= -1;
18677 tail_call_site_count
= -1;
18679 /* Add the calling convention attribute if requested. */
18680 add_calling_convention_attribute (subr_die
, decl
);
18684 /* Returns a hash value for X (which really is a die_struct). */
18687 common_block_die_table_hash (const void *x
)
18689 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18690 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18693 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18694 as decl_id and die_parent of die_struct Y. */
18697 common_block_die_table_eq (const void *x
, const void *y
)
18699 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18700 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18701 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18704 /* Generate a DIE to represent a declared data object.
18705 Either DECL or ORIGIN must be non-null. */
18708 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18710 HOST_WIDE_INT off
= 0;
18712 tree decl_or_origin
= decl
? decl
: origin
;
18713 tree ultimate_origin
;
18714 dw_die_ref var_die
;
18715 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18716 dw_die_ref origin_die
;
18717 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18718 || class_or_namespace_scope_p (context_die
));
18719 bool specialization_p
= false;
18721 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18722 if (decl
|| ultimate_origin
)
18723 origin
= ultimate_origin
;
18724 com_decl
= fortran_common (decl_or_origin
, &off
);
18726 /* Symbol in common gets emitted as a child of the common block, in the form
18727 of a data member. */
18730 dw_die_ref com_die
;
18731 dw_loc_list_ref loc
;
18732 die_node com_die_arg
;
18734 var_die
= lookup_decl_die (decl_or_origin
);
18737 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18739 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18744 /* Optimize the common case. */
18745 if (single_element_loc_list_p (loc
)
18746 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18747 && loc
->expr
->dw_loc_next
== NULL
18748 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18751 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18752 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18753 = plus_constant (GET_MODE (x
), x
, off
);
18756 loc_list_plus_const (loc
, off
);
18758 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18759 remove_AT (var_die
, DW_AT_declaration
);
18765 if (common_block_die_table
== NULL
)
18766 common_block_die_table
18767 = htab_create_ggc (10, common_block_die_table_hash
,
18768 common_block_die_table_eq
, NULL
);
18770 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18771 com_die_arg
.die_parent
= context_die
;
18772 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18773 loc
= loc_list_from_tree (com_decl
, 2);
18774 if (com_die
== NULL
)
18777 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18780 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18781 add_name_and_src_coords_attributes (com_die
, com_decl
);
18784 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18785 /* Avoid sharing the same loc descriptor between
18786 DW_TAG_common_block and DW_TAG_variable. */
18787 loc
= loc_list_from_tree (com_decl
, 2);
18789 else if (DECL_EXTERNAL (decl
))
18790 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18791 if (want_pubnames ())
18792 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18793 com_die
->decl_id
= DECL_UID (com_decl
);
18794 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18795 *slot
= (void *) com_die
;
18797 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18799 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18800 loc
= loc_list_from_tree (com_decl
, 2);
18801 remove_AT (com_die
, DW_AT_declaration
);
18803 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18804 add_name_and_src_coords_attributes (var_die
, decl
);
18805 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18806 TREE_THIS_VOLATILE (decl
), context_die
);
18807 add_AT_flag (var_die
, DW_AT_external
, 1);
18812 /* Optimize the common case. */
18813 if (single_element_loc_list_p (loc
)
18814 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18815 && loc
->expr
->dw_loc_next
== NULL
18816 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18818 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18819 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18820 = plus_constant (GET_MODE (x
), x
, off
);
18823 loc_list_plus_const (loc
, off
);
18825 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18827 else if (DECL_EXTERNAL (decl
))
18828 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18829 equate_decl_number_to_die (decl
, var_die
);
18833 /* If the compiler emitted a definition for the DECL declaration
18834 and if we already emitted a DIE for it, don't emit a second
18835 DIE for it again. Allow re-declarations of DECLs that are
18836 inside functions, though. */
18837 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18840 /* For static data members, the declaration in the class is supposed
18841 to have DW_TAG_member tag; the specification should still be
18842 DW_TAG_variable referencing the DW_TAG_member DIE. */
18843 if (declaration
&& class_scope_p (context_die
))
18844 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18846 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18849 if (origin
!= NULL
)
18850 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18852 /* Loop unrolling can create multiple blocks that refer to the same
18853 static variable, so we must test for the DW_AT_declaration flag.
18855 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18856 copy decls and set the DECL_ABSTRACT flag on them instead of
18859 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18861 ??? The declare_in_namespace support causes us to get two DIEs for one
18862 variable, both of which are declarations. We want to avoid considering
18863 one to be a specification, so we must test that this DIE is not a
18865 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18866 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18868 /* This is a definition of a C++ class level static. */
18869 add_AT_specification (var_die
, old_die
);
18870 specialization_p
= true;
18871 if (DECL_NAME (decl
))
18873 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18874 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18876 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18877 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18879 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18880 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18882 if (old_die
->die_tag
== DW_TAG_member
)
18883 add_linkage_name (var_die
, decl
);
18887 add_name_and_src_coords_attributes (var_die
, decl
);
18889 if ((origin
== NULL
&& !specialization_p
)
18891 && !DECL_ABSTRACT (decl_or_origin
)
18892 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18893 decl_function_context
18894 (decl_or_origin
))))
18896 tree type
= TREE_TYPE (decl_or_origin
);
18898 if (decl_by_reference_p (decl_or_origin
))
18899 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18901 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18902 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18905 if (origin
== NULL
&& !specialization_p
)
18907 if (TREE_PUBLIC (decl
))
18908 add_AT_flag (var_die
, DW_AT_external
, 1);
18910 if (DECL_ARTIFICIAL (decl
))
18911 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18913 add_accessibility_attribute (var_die
, decl
);
18917 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18919 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18920 equate_decl_number_to_die (decl
, var_die
);
18923 && (! DECL_ABSTRACT (decl_or_origin
)
18924 /* Local static vars are shared between all clones/inlines,
18925 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18927 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18928 && TREE_STATIC (decl_or_origin
)
18929 && DECL_RTL_SET_P (decl_or_origin
)))
18930 /* When abstract origin already has DW_AT_location attribute, no need
18931 to add it again. */
18932 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18934 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18935 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18936 defer_location (decl_or_origin
, var_die
);
18938 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18939 decl
== NULL
, DW_AT_location
);
18940 add_pubname (decl_or_origin
, var_die
);
18943 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18946 /* Generate a DIE to represent a named constant. */
18949 gen_const_die (tree decl
, dw_die_ref context_die
)
18951 dw_die_ref const_die
;
18952 tree type
= TREE_TYPE (decl
);
18954 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18955 add_name_and_src_coords_attributes (const_die
, decl
);
18956 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18957 if (TREE_PUBLIC (decl
))
18958 add_AT_flag (const_die
, DW_AT_external
, 1);
18959 if (DECL_ARTIFICIAL (decl
))
18960 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18961 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18964 /* Generate a DIE to represent a label identifier. */
18967 gen_label_die (tree decl
, dw_die_ref context_die
)
18969 tree origin
= decl_ultimate_origin (decl
);
18970 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18972 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18974 if (origin
!= NULL
)
18975 add_abstract_origin_attribute (lbl_die
, origin
);
18977 add_name_and_src_coords_attributes (lbl_die
, decl
);
18979 if (DECL_ABSTRACT (decl
))
18980 equate_decl_number_to_die (decl
, lbl_die
);
18983 insn
= DECL_RTL_IF_SET (decl
);
18985 /* Deleted labels are programmer specified labels which have been
18986 eliminated because of various optimizations. We still emit them
18987 here so that it is possible to put breakpoints on them. */
18991 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18993 /* When optimization is enabled (via -O) some parts of the compiler
18994 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18995 represent source-level labels which were explicitly declared by
18996 the user. This really shouldn't be happening though, so catch
18997 it if it ever does happen. */
18998 gcc_assert (!INSN_DELETED_P (insn
));
19000 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19001 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19005 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19006 && CODE_LABEL_NUMBER (insn
) != -1)
19008 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19009 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19014 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19015 attributes to the DIE for a block STMT, to describe where the inlined
19016 function was called from. This is similar to add_src_coords_attributes. */
19019 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19021 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19023 if (dwarf_version
>= 3 || !dwarf_strict
)
19025 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19026 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19031 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19032 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19035 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19037 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19039 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19040 && (dwarf_version
>= 3 || !dwarf_strict
))
19042 tree chain
, superblock
= NULL_TREE
;
19044 dw_attr_ref attr
= NULL
;
19046 if (inlined_function_outer_scope_p (stmt
))
19048 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19049 BLOCK_NUMBER (stmt
));
19050 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19053 /* Optimize duplicate .debug_ranges lists or even tails of
19054 lists. If this BLOCK has same ranges as its supercontext,
19055 lookup DW_AT_ranges attribute in the supercontext (and
19056 recursively so), verify that the ranges_table contains the
19057 right values and use it instead of adding a new .debug_range. */
19058 for (chain
= stmt
, pdie
= die
;
19059 BLOCK_SAME_RANGE (chain
);
19060 chain
= BLOCK_SUPERCONTEXT (chain
))
19062 dw_attr_ref new_attr
;
19064 pdie
= pdie
->die_parent
;
19067 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19069 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19070 if (new_attr
== NULL
19071 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19074 superblock
= BLOCK_SUPERCONTEXT (chain
);
19077 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19078 / 2 / DWARF2_ADDR_SIZE
].num
19079 == BLOCK_NUMBER (superblock
))
19080 && BLOCK_FRAGMENT_CHAIN (superblock
))
19082 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19083 / 2 / DWARF2_ADDR_SIZE
;
19084 unsigned long supercnt
= 0, thiscnt
= 0;
19085 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19086 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19089 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19090 == BLOCK_NUMBER (chain
));
19092 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19093 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19094 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19096 gcc_assert (supercnt
>= thiscnt
);
19097 add_AT_range_list (die
, DW_AT_ranges
,
19098 ((off
+ supercnt
- thiscnt
)
19099 * 2 * DWARF2_ADDR_SIZE
),
19104 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19106 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19109 add_ranges (chain
);
19110 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19117 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19118 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19119 BLOCK_NUMBER (stmt
));
19120 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19121 BLOCK_NUMBER (stmt
));
19122 add_AT_low_high_pc (die
, label
, label_high
, false);
19126 /* Generate a DIE for a lexical block. */
19129 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19131 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19133 if (call_arg_locations
)
19135 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19136 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19137 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
19140 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19141 add_high_low_attributes (stmt
, stmt_die
);
19143 decls_for_scope (stmt
, stmt_die
, depth
);
19146 /* Generate a DIE for an inlined subprogram. */
19149 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
19153 /* The instance of function that is effectively being inlined shall not
19155 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19157 decl
= block_ultimate_origin (stmt
);
19159 /* Emit info for the abstract instance first, if we haven't yet. We
19160 must emit this even if the block is abstract, otherwise when we
19161 emit the block below (or elsewhere), we may end up trying to emit
19162 a die whose origin die hasn't been emitted, and crashing. */
19163 dwarf2out_abstract_function (decl
);
19165 if (! BLOCK_ABSTRACT (stmt
))
19167 dw_die_ref subr_die
19168 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19170 if (call_arg_locations
)
19172 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19173 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19174 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
19176 add_abstract_origin_attribute (subr_die
, decl
);
19177 if (TREE_ASM_WRITTEN (stmt
))
19178 add_high_low_attributes (stmt
, subr_die
);
19179 add_call_src_coords_attributes (stmt
, subr_die
);
19181 decls_for_scope (stmt
, subr_die
, depth
);
19182 current_function_has_inlines
= 1;
19186 /* Generate a DIE for a field in a record, or structure. */
19189 gen_field_die (tree decl
, dw_die_ref context_die
)
19191 dw_die_ref decl_die
;
19193 if (TREE_TYPE (decl
) == error_mark_node
)
19196 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19197 add_name_and_src_coords_attributes (decl_die
, decl
);
19198 add_type_attribute (decl_die
, member_declared_type (decl
),
19199 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19202 if (DECL_BIT_FIELD_TYPE (decl
))
19204 add_byte_size_attribute (decl_die
, decl
);
19205 add_bit_size_attribute (decl_die
, decl
);
19206 add_bit_offset_attribute (decl_die
, decl
);
19209 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19210 add_data_member_location_attribute (decl_die
, decl
);
19212 if (DECL_ARTIFICIAL (decl
))
19213 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19215 add_accessibility_attribute (decl_die
, decl
);
19217 /* Equate decl number to die, so that we can look up this decl later on. */
19218 equate_decl_number_to_die (decl
, decl_die
);
19222 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19223 Use modified_type_die instead.
19224 We keep this code here just in case these types of DIEs may be needed to
19225 represent certain things in other languages (e.g. Pascal) someday. */
19228 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19231 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19233 equate_type_number_to_die (type
, ptr_die
);
19234 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19235 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19238 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19239 Use modified_type_die instead.
19240 We keep this code here just in case these types of DIEs may be needed to
19241 represent certain things in other languages (e.g. Pascal) someday. */
19244 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19246 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19248 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19249 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19251 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19253 equate_type_number_to_die (type
, ref_die
);
19254 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19255 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19259 /* Generate a DIE for a pointer to a member type. */
19262 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19265 = new_die (DW_TAG_ptr_to_member_type
,
19266 scope_die_for (type
, context_die
), type
);
19268 equate_type_number_to_die (type
, ptr_die
);
19269 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19270 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19271 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19274 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19276 static char *producer_string
;
19278 /* Return a heap allocated producer string including command line options
19279 if -grecord-gcc-switches. */
19282 gen_producer_string (void)
19285 auto_vec
<dchar_p
> switches
;
19286 const char *language_string
= lang_hooks
.name
;
19287 char *producer
, *tail
;
19289 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19290 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19292 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19293 switch (save_decoded_options
[j
].opt_index
)
19300 case OPT_auxbase_strip
:
19309 case OPT_SPECIAL_unknown
:
19310 case OPT_SPECIAL_ignore
:
19311 case OPT_SPECIAL_program_name
:
19312 case OPT_SPECIAL_input_file
:
19313 case OPT_grecord_gcc_switches
:
19314 case OPT_gno_record_gcc_switches
:
19315 case OPT__output_pch_
:
19316 case OPT_fdiagnostics_show_location_
:
19317 case OPT_fdiagnostics_show_option
:
19318 case OPT_fdiagnostics_show_caret
:
19319 case OPT_fdiagnostics_color_
:
19320 case OPT_fverbose_asm
:
19322 case OPT__sysroot_
:
19324 case OPT_nostdinc__
:
19325 /* Ignore these. */
19328 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19329 & CL_NO_DWARF_RECORD
)
19331 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19333 switch (save_decoded_options
[j
].canonical_option
[0][1])
19340 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19347 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19348 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19352 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19354 sprintf (tail
, "%s %s", language_string
, version_string
);
19357 FOR_EACH_VEC_ELT (switches
, j
, p
)
19361 memcpy (tail
+ 1, p
, len
);
19369 /* Generate the DIE for the compilation unit. */
19372 gen_compile_unit_die (const char *filename
)
19375 const char *language_string
= lang_hooks
.name
;
19378 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19382 add_name_attribute (die
, filename
);
19383 /* Don't add cwd for <built-in>. */
19384 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19385 add_comp_dir_attribute (die
);
19388 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19390 /* If our producer is LTO try to figure out a common language to use
19391 from the global list of translation units. */
19392 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19396 const char *common_lang
= NULL
;
19398 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19400 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19403 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19404 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19406 else if (strncmp (common_lang
, "GNU C", 5) == 0
19407 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19408 /* Mixing C and C++ is ok, use C++ in that case. */
19409 common_lang
= "GNU C++";
19412 /* Fall back to C. */
19413 common_lang
= NULL
;
19419 language_string
= common_lang
;
19422 language
= DW_LANG_C89
;
19423 if (strcmp (language_string
, "GNU C++") == 0)
19424 language
= DW_LANG_C_plus_plus
;
19425 else if (strcmp (language_string
, "GNU F77") == 0)
19426 language
= DW_LANG_Fortran77
;
19427 else if (strcmp (language_string
, "GNU Pascal") == 0)
19428 language
= DW_LANG_Pascal83
;
19429 else if (dwarf_version
>= 3 || !dwarf_strict
)
19431 if (strcmp (language_string
, "GNU Ada") == 0)
19432 language
= DW_LANG_Ada95
;
19433 else if (strcmp (language_string
, "GNU Fortran") == 0)
19434 language
= DW_LANG_Fortran95
;
19435 else if (strcmp (language_string
, "GNU Java") == 0)
19436 language
= DW_LANG_Java
;
19437 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19438 language
= DW_LANG_ObjC
;
19439 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19440 language
= DW_LANG_ObjC_plus_plus
;
19441 else if (dwarf_version
>= 5 || !dwarf_strict
)
19443 if (strcmp (language_string
, "GNU Go") == 0)
19444 language
= DW_LANG_Go
;
19447 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19448 else if (strcmp (language_string
, "GNU Fortran") == 0)
19449 language
= DW_LANG_Fortran90
;
19451 add_AT_unsigned (die
, DW_AT_language
, language
);
19455 case DW_LANG_Fortran77
:
19456 case DW_LANG_Fortran90
:
19457 case DW_LANG_Fortran95
:
19458 /* Fortran has case insensitive identifiers and the front-end
19459 lowercases everything. */
19460 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19463 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19469 /* Generate the DIE for a base class. */
19472 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19474 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19476 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19477 add_data_member_location_attribute (die
, binfo
);
19479 if (BINFO_VIRTUAL_P (binfo
))
19480 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19482 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19483 children, otherwise the default is DW_ACCESS_public. In DWARF2
19484 the default has always been DW_ACCESS_private. */
19485 if (access
== access_public_node
)
19487 if (dwarf_version
== 2
19488 || context_die
->die_tag
== DW_TAG_class_type
)
19489 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19491 else if (access
== access_protected_node
)
19492 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19493 else if (dwarf_version
> 2
19494 && context_die
->die_tag
!= DW_TAG_class_type
)
19495 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19498 /* Generate a DIE for a class member. */
19501 gen_member_die (tree type
, dw_die_ref context_die
)
19504 tree binfo
= TYPE_BINFO (type
);
19507 /* If this is not an incomplete type, output descriptions of each of its
19508 members. Note that as we output the DIEs necessary to represent the
19509 members of this record or union type, we will also be trying to output
19510 DIEs to represent the *types* of those members. However the `type'
19511 function (above) will specifically avoid generating type DIEs for member
19512 types *within* the list of member DIEs for this (containing) type except
19513 for those types (of members) which are explicitly marked as also being
19514 members of this (containing) type themselves. The g++ front- end can
19515 force any given type to be treated as a member of some other (containing)
19516 type by setting the TYPE_CONTEXT of the given (member) type to point to
19517 the TREE node representing the appropriate (containing) type. */
19519 /* First output info about the base classes. */
19522 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19526 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19527 gen_inheritance_die (base
,
19528 (accesses
? (*accesses
)[i
] : access_public_node
),
19532 /* Now output info about the data members and type members. */
19533 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19535 /* If we thought we were generating minimal debug info for TYPE
19536 and then changed our minds, some of the member declarations
19537 may have already been defined. Don't define them again, but
19538 do put them in the right order. */
19540 child
= lookup_decl_die (member
);
19542 splice_child_die (context_die
, child
);
19544 gen_decl_die (member
, NULL
, context_die
);
19547 /* Now output info about the function members (if any). */
19548 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19550 /* Don't include clones in the member list. */
19551 if (DECL_ABSTRACT_ORIGIN (member
))
19554 child
= lookup_decl_die (member
);
19556 splice_child_die (context_die
, child
);
19558 gen_decl_die (member
, NULL
, context_die
);
19562 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19563 is set, we pretend that the type was never defined, so we only get the
19564 member DIEs needed by later specification DIEs. */
19567 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19568 enum debug_info_usage usage
)
19570 dw_die_ref type_die
= lookup_type_die (type
);
19571 dw_die_ref scope_die
= 0;
19573 int complete
= (TYPE_SIZE (type
)
19574 && (! TYPE_STUB_DECL (type
)
19575 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19576 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19577 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19579 if (type_die
&& ! complete
)
19582 if (TYPE_CONTEXT (type
) != NULL_TREE
19583 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19584 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19587 scope_die
= scope_die_for (type
, context_die
);
19589 /* Generate child dies for template paramaters. */
19590 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19591 schedule_generic_params_dies_gen (type
);
19593 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19594 /* First occurrence of type or toplevel definition of nested class. */
19596 dw_die_ref old_die
= type_die
;
19598 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19599 ? record_type_tag (type
) : DW_TAG_union_type
,
19601 equate_type_number_to_die (type
, type_die
);
19603 add_AT_specification (type_die
, old_die
);
19605 add_name_attribute (type_die
, type_tag (type
));
19608 remove_AT (type_die
, DW_AT_declaration
);
19610 /* If this type has been completed, then give it a byte_size attribute and
19611 then give a list of members. */
19612 if (complete
&& !ns_decl
)
19614 /* Prevent infinite recursion in cases where the type of some member of
19615 this type is expressed in terms of this type itself. */
19616 TREE_ASM_WRITTEN (type
) = 1;
19617 add_byte_size_attribute (type_die
, type
);
19618 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19620 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19621 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19624 /* If the first reference to this type was as the return type of an
19625 inline function, then it may not have a parent. Fix this now. */
19626 if (type_die
->die_parent
== NULL
)
19627 add_child_die (scope_die
, type_die
);
19629 push_decl_scope (type
);
19630 gen_member_die (type
, type_die
);
19633 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19634 if (TYPE_ARTIFICIAL (type
))
19635 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19637 /* GNU extension: Record what type our vtable lives in. */
19638 if (TYPE_VFIELD (type
))
19640 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19642 gen_type_die (vtype
, context_die
);
19643 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19644 lookup_type_die (vtype
));
19649 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19651 /* We don't need to do this for function-local types. */
19652 if (TYPE_STUB_DECL (type
)
19653 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19654 vec_safe_push (incomplete_types
, type
);
19657 if (get_AT (type_die
, DW_AT_name
))
19658 add_pubtype (type
, type_die
);
19661 /* Generate a DIE for a subroutine _type_. */
19664 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19666 tree return_type
= TREE_TYPE (type
);
19667 dw_die_ref subr_die
19668 = new_die (DW_TAG_subroutine_type
,
19669 scope_die_for (type
, context_die
), type
);
19671 equate_type_number_to_die (type
, subr_die
);
19672 add_prototyped_attribute (subr_die
, type
);
19673 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19674 gen_formal_types_die (type
, subr_die
);
19676 if (get_AT (subr_die
, DW_AT_name
))
19677 add_pubtype (type
, subr_die
);
19680 /* Generate a DIE for a type definition. */
19683 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19685 dw_die_ref type_die
;
19688 if (TREE_ASM_WRITTEN (decl
))
19691 TREE_ASM_WRITTEN (decl
) = 1;
19692 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19693 origin
= decl_ultimate_origin (decl
);
19694 if (origin
!= NULL
)
19695 add_abstract_origin_attribute (type_die
, origin
);
19700 add_name_and_src_coords_attributes (type_die
, decl
);
19701 if (DECL_ORIGINAL_TYPE (decl
))
19703 type
= DECL_ORIGINAL_TYPE (decl
);
19705 gcc_assert (type
!= TREE_TYPE (decl
));
19706 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19710 type
= TREE_TYPE (decl
);
19712 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19714 /* Here, we are in the case of decl being a typedef naming
19715 an anonymous type, e.g:
19716 typedef struct {...} foo;
19717 In that case TREE_TYPE (decl) is not a typedef variant
19718 type and TYPE_NAME of the anonymous type is set to the
19719 TYPE_DECL of the typedef. This construct is emitted by
19722 TYPE is the anonymous struct named by the typedef
19723 DECL. As we need the DW_AT_type attribute of the
19724 DW_TAG_typedef to point to the DIE of TYPE, let's
19725 generate that DIE right away. add_type_attribute
19726 called below will then pick (via lookup_type_die) that
19727 anonymous struct DIE. */
19728 if (!TREE_ASM_WRITTEN (type
))
19729 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19731 /* This is a GNU Extension. We are adding a
19732 DW_AT_linkage_name attribute to the DIE of the
19733 anonymous struct TYPE. The value of that attribute
19734 is the name of the typedef decl naming the anonymous
19735 struct. This greatly eases the work of consumers of
19736 this debug info. */
19737 add_linkage_attr (lookup_type_die (type
), decl
);
19741 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19742 TREE_THIS_VOLATILE (decl
), context_die
);
19744 if (is_naming_typedef_decl (decl
))
19745 /* We want that all subsequent calls to lookup_type_die with
19746 TYPE in argument yield the DW_TAG_typedef we have just
19748 equate_type_number_to_die (type
, type_die
);
19750 add_accessibility_attribute (type_die
, decl
);
19753 if (DECL_ABSTRACT (decl
))
19754 equate_decl_number_to_die (decl
, type_die
);
19756 if (get_AT (type_die
, DW_AT_name
))
19757 add_pubtype (decl
, type_die
);
19760 /* Generate a DIE for a struct, class, enum or union type. */
19763 gen_tagged_type_die (tree type
,
19764 dw_die_ref context_die
,
19765 enum debug_info_usage usage
)
19769 if (type
== NULL_TREE
19770 || !is_tagged_type (type
))
19773 /* If this is a nested type whose containing class hasn't been written
19774 out yet, writing it out will cover this one, too. This does not apply
19775 to instantiations of member class templates; they need to be added to
19776 the containing class as they are generated. FIXME: This hurts the
19777 idea of combining type decls from multiple TUs, since we can't predict
19778 what set of template instantiations we'll get. */
19779 if (TYPE_CONTEXT (type
)
19780 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19781 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19783 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19785 if (TREE_ASM_WRITTEN (type
))
19788 /* If that failed, attach ourselves to the stub. */
19789 push_decl_scope (TYPE_CONTEXT (type
));
19790 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19793 else if (TYPE_CONTEXT (type
) != NULL_TREE
19794 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19796 /* If this type is local to a function that hasn't been written
19797 out yet, use a NULL context for now; it will be fixed up in
19798 decls_for_scope. */
19799 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19800 /* A declaration DIE doesn't count; nested types need to go in the
19802 if (context_die
&& is_declaration_die (context_die
))
19803 context_die
= NULL
;
19808 context_die
= declare_in_namespace (type
, context_die
);
19812 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19814 /* This might have been written out by the call to
19815 declare_in_namespace. */
19816 if (!TREE_ASM_WRITTEN (type
))
19817 gen_enumeration_type_die (type
, context_die
);
19820 gen_struct_or_union_type_die (type
, context_die
, usage
);
19825 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19826 it up if it is ever completed. gen_*_type_die will set it for us
19827 when appropriate. */
19830 /* Generate a type description DIE. */
19833 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19834 enum debug_info_usage usage
)
19836 struct array_descr_info info
;
19838 if (type
== NULL_TREE
|| type
== error_mark_node
)
19841 if (TYPE_NAME (type
) != NULL_TREE
19842 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19843 && is_redundant_typedef (TYPE_NAME (type
))
19844 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19845 /* The DECL of this type is a typedef we don't want to emit debug
19846 info for but we want debug info for its underlying typedef.
19847 This can happen for e.g, the injected-class-name of a C++
19849 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19851 /* If TYPE is a typedef type variant, let's generate debug info
19852 for the parent typedef which TYPE is a type of. */
19853 if (typedef_variant_p (type
))
19855 if (TREE_ASM_WRITTEN (type
))
19858 /* Prevent broken recursion; we can't hand off to the same type. */
19859 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19861 /* Give typedefs the right scope. */
19862 context_die
= scope_die_for (type
, context_die
);
19864 TREE_ASM_WRITTEN (type
) = 1;
19866 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19870 /* If type is an anonymous tagged type named by a typedef, let's
19871 generate debug info for the typedef. */
19872 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19874 /* Use the DIE of the containing namespace as the parent DIE of
19875 the type description DIE we want to generate. */
19876 if (DECL_CONTEXT (TYPE_NAME (type
))
19877 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19878 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19880 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19884 /* If this is an array type with hidden descriptor, handle it first. */
19885 if (!TREE_ASM_WRITTEN (type
)
19886 && lang_hooks
.types
.get_array_descr_info
19887 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19888 && (dwarf_version
>= 3 || !dwarf_strict
))
19890 gen_descr_array_type_die (type
, &info
, context_die
);
19891 TREE_ASM_WRITTEN (type
) = 1;
19895 /* We are going to output a DIE to represent the unqualified version
19896 of this type (i.e. without any const or volatile qualifiers) so
19897 get the main variant (i.e. the unqualified version) of this type
19898 now. (Vectors are special because the debugging info is in the
19899 cloned type itself). */
19900 if (TREE_CODE (type
) != VECTOR_TYPE
)
19901 type
= type_main_variant (type
);
19903 if (TREE_ASM_WRITTEN (type
))
19906 switch (TREE_CODE (type
))
19912 case REFERENCE_TYPE
:
19913 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19914 ensures that the gen_type_die recursion will terminate even if the
19915 type is recursive. Recursive types are possible in Ada. */
19916 /* ??? We could perhaps do this for all types before the switch
19918 TREE_ASM_WRITTEN (type
) = 1;
19920 /* For these types, all that is required is that we output a DIE (or a
19921 set of DIEs) to represent the "basis" type. */
19922 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19923 DINFO_USAGE_IND_USE
);
19927 /* This code is used for C++ pointer-to-data-member types.
19928 Output a description of the relevant class type. */
19929 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19930 DINFO_USAGE_IND_USE
);
19932 /* Output a description of the type of the object pointed to. */
19933 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19934 DINFO_USAGE_IND_USE
);
19936 /* Now output a DIE to represent this pointer-to-data-member type
19938 gen_ptr_to_mbr_type_die (type
, context_die
);
19941 case FUNCTION_TYPE
:
19942 /* Force out return type (in case it wasn't forced out already). */
19943 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19944 DINFO_USAGE_DIR_USE
);
19945 gen_subroutine_type_die (type
, context_die
);
19949 /* Force out return type (in case it wasn't forced out already). */
19950 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19951 DINFO_USAGE_DIR_USE
);
19952 gen_subroutine_type_die (type
, context_die
);
19956 gen_array_type_die (type
, context_die
);
19960 gen_array_type_die (type
, context_die
);
19963 case ENUMERAL_TYPE
:
19966 case QUAL_UNION_TYPE
:
19967 gen_tagged_type_die (type
, context_die
, usage
);
19973 case FIXED_POINT_TYPE
:
19976 case POINTER_BOUNDS_TYPE
:
19977 /* No DIEs needed for fundamental types. */
19982 /* Just use DW_TAG_unspecified_type. */
19984 dw_die_ref type_die
= lookup_type_die (type
);
19985 if (type_die
== NULL
)
19987 tree name
= TYPE_NAME (type
);
19988 if (TREE_CODE (name
) == TYPE_DECL
)
19989 name
= DECL_NAME (name
);
19990 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19991 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19992 equate_type_number_to_die (type
, type_die
);
19998 gcc_unreachable ();
20001 TREE_ASM_WRITTEN (type
) = 1;
20005 gen_type_die (tree type
, dw_die_ref context_die
)
20007 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20010 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20011 things which are local to the given block. */
20014 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
20016 int must_output_die
= 0;
20019 /* Ignore blocks that are NULL. */
20020 if (stmt
== NULL_TREE
)
20023 inlined_func
= inlined_function_outer_scope_p (stmt
);
20025 /* If the block is one fragment of a non-contiguous block, do not
20026 process the variables, since they will have been done by the
20027 origin block. Do process subblocks. */
20028 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20032 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20033 gen_block_die (sub
, context_die
, depth
+ 1);
20038 /* Determine if we need to output any Dwarf DIEs at all to represent this
20041 /* The outer scopes for inlinings *must* always be represented. We
20042 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20043 must_output_die
= 1;
20046 /* Determine if this block directly contains any "significant"
20047 local declarations which we will need to output DIEs for. */
20048 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20049 /* We are not in terse mode so *any* local declaration counts
20050 as being a "significant" one. */
20051 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20052 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20053 && (TREE_USED (stmt
)
20054 || TREE_ASM_WRITTEN (stmt
)
20055 || BLOCK_ABSTRACT (stmt
)));
20056 else if ((TREE_USED (stmt
)
20057 || TREE_ASM_WRITTEN (stmt
)
20058 || BLOCK_ABSTRACT (stmt
))
20059 && !dwarf2out_ignore_block (stmt
))
20060 must_output_die
= 1;
20063 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20064 DIE for any block which contains no significant local declarations at
20065 all. Rather, in such cases we just call `decls_for_scope' so that any
20066 needed Dwarf info for any sub-blocks will get properly generated. Note
20067 that in terse mode, our definition of what constitutes a "significant"
20068 local declaration gets restricted to include only inlined function
20069 instances and local (nested) function definitions. */
20070 if (must_output_die
)
20074 /* If STMT block is abstract, that means we have been called
20075 indirectly from dwarf2out_abstract_function.
20076 That function rightfully marks the descendent blocks (of
20077 the abstract function it is dealing with) as being abstract,
20078 precisely to prevent us from emitting any
20079 DW_TAG_inlined_subroutine DIE as a descendent
20080 of an abstract function instance. So in that case, we should
20081 not call gen_inlined_subroutine_die.
20083 Later though, when cgraph asks dwarf2out to emit info
20084 for the concrete instance of the function decl into which
20085 the concrete instance of STMT got inlined, the later will lead
20086 to the generation of a DW_TAG_inlined_subroutine DIE. */
20087 if (! BLOCK_ABSTRACT (stmt
))
20088 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20091 gen_lexical_block_die (stmt
, context_die
, depth
);
20094 decls_for_scope (stmt
, context_die
, depth
);
20097 /* Process variable DECL (or variable with origin ORIGIN) within
20098 block STMT and add it to CONTEXT_DIE. */
20100 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20103 tree decl_or_origin
= decl
? decl
: origin
;
20105 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20106 die
= lookup_decl_die (decl_or_origin
);
20107 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20108 && TYPE_DECL_IS_STUB (decl_or_origin
))
20109 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20113 if (die
!= NULL
&& die
->die_parent
== NULL
)
20114 add_child_die (context_die
, die
);
20115 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20116 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20117 stmt
, context_die
);
20119 gen_decl_die (decl
, origin
, context_die
);
20122 /* Generate all of the decls declared within a given scope and (recursively)
20123 all of its sub-blocks. */
20126 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20132 /* Ignore NULL blocks. */
20133 if (stmt
== NULL_TREE
)
20136 /* Output the DIEs to represent all of the data objects and typedefs
20137 declared directly within this block but not within any nested
20138 sub-blocks. Also, nested function and tag DIEs have been
20139 generated with a parent of NULL; fix that up now. We don't
20140 have to do this if we're at -g1. */
20141 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20143 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20144 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20145 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20146 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20150 /* Even if we're at -g1, we need to process the subblocks in order to get
20151 inlined call information. */
20153 /* Output the DIEs to represent all sub-blocks (and the items declared
20154 therein) of this block. */
20155 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20157 subblocks
= BLOCK_CHAIN (subblocks
))
20158 gen_block_die (subblocks
, context_die
, depth
+ 1);
20161 /* Is this a typedef we can avoid emitting? */
20164 is_redundant_typedef (const_tree decl
)
20166 if (TYPE_DECL_IS_STUB (decl
))
20169 if (DECL_ARTIFICIAL (decl
)
20170 && DECL_CONTEXT (decl
)
20171 && is_tagged_type (DECL_CONTEXT (decl
))
20172 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20173 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20174 /* Also ignore the artificial member typedef for the class name. */
20180 /* Return TRUE if TYPE is a typedef that names a type for linkage
20181 purposes. This kind of typedefs is produced by the C++ FE for
20184 typedef struct {...} foo;
20186 In that case, there is no typedef variant type produced for foo.
20187 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20191 is_naming_typedef_decl (const_tree decl
)
20193 if (decl
== NULL_TREE
20194 || TREE_CODE (decl
) != TYPE_DECL
20195 || !is_tagged_type (TREE_TYPE (decl
))
20196 || DECL_IS_BUILTIN (decl
)
20197 || is_redundant_typedef (decl
)
20198 /* It looks like Ada produces TYPE_DECLs that are very similar
20199 to C++ naming typedefs but that have different
20200 semantics. Let's be specific to c++ for now. */
20204 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20205 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20206 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20207 != TYPE_NAME (TREE_TYPE (decl
))));
20210 /* Returns the DIE for a context. */
20212 static inline dw_die_ref
20213 get_context_die (tree context
)
20217 /* Find die that represents this context. */
20218 if (TYPE_P (context
))
20220 context
= TYPE_MAIN_VARIANT (context
);
20221 return strip_naming_typedef (context
, force_type_die (context
));
20224 return force_decl_die (context
);
20226 return comp_unit_die ();
20229 /* Returns the DIE for decl. A DIE will always be returned. */
20232 force_decl_die (tree decl
)
20234 dw_die_ref decl_die
;
20235 unsigned saved_external_flag
;
20236 tree save_fn
= NULL_TREE
;
20237 decl_die
= lookup_decl_die (decl
);
20240 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20242 decl_die
= lookup_decl_die (decl
);
20246 switch (TREE_CODE (decl
))
20248 case FUNCTION_DECL
:
20249 /* Clear current_function_decl, so that gen_subprogram_die thinks
20250 that this is a declaration. At this point, we just want to force
20251 declaration die. */
20252 save_fn
= current_function_decl
;
20253 current_function_decl
= NULL_TREE
;
20254 gen_subprogram_die (decl
, context_die
);
20255 current_function_decl
= save_fn
;
20259 /* Set external flag to force declaration die. Restore it after
20260 gen_decl_die() call. */
20261 saved_external_flag
= DECL_EXTERNAL (decl
);
20262 DECL_EXTERNAL (decl
) = 1;
20263 gen_decl_die (decl
, NULL
, context_die
);
20264 DECL_EXTERNAL (decl
) = saved_external_flag
;
20267 case NAMESPACE_DECL
:
20268 if (dwarf_version
>= 3 || !dwarf_strict
)
20269 dwarf2out_decl (decl
);
20271 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20272 decl_die
= comp_unit_die ();
20275 case TRANSLATION_UNIT_DECL
:
20276 decl_die
= comp_unit_die ();
20280 gcc_unreachable ();
20283 /* We should be able to find the DIE now. */
20285 decl_die
= lookup_decl_die (decl
);
20286 gcc_assert (decl_die
);
20292 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20293 always returned. */
20296 force_type_die (tree type
)
20298 dw_die_ref type_die
;
20300 type_die
= lookup_type_die (type
);
20303 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20305 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20306 TYPE_VOLATILE (type
), context_die
);
20307 gcc_assert (type_die
);
20312 /* Force out any required namespaces to be able to output DECL,
20313 and return the new context_die for it, if it's changed. */
20316 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20318 tree context
= (DECL_P (thing
)
20319 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20320 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20321 /* Force out the namespace. */
20322 context_die
= force_decl_die (context
);
20324 return context_die
;
20327 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20328 type) within its namespace, if appropriate.
20330 For compatibility with older debuggers, namespace DIEs only contain
20331 declarations; all definitions are emitted at CU scope. */
20334 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20336 dw_die_ref ns_context
;
20338 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20339 return context_die
;
20341 /* If this decl is from an inlined function, then don't try to emit it in its
20342 namespace, as we will get confused. It would have already been emitted
20343 when the abstract instance of the inline function was emitted anyways. */
20344 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20345 return context_die
;
20347 ns_context
= setup_namespace_context (thing
, context_die
);
20349 if (ns_context
!= context_die
)
20353 if (DECL_P (thing
))
20354 gen_decl_die (thing
, NULL
, ns_context
);
20356 gen_type_die (thing
, ns_context
);
20358 return context_die
;
20361 /* Generate a DIE for a namespace or namespace alias. */
20364 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20366 dw_die_ref namespace_die
;
20368 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20369 they are an alias of. */
20370 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20372 /* Output a real namespace or module. */
20373 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20374 namespace_die
= new_die (is_fortran ()
20375 ? DW_TAG_module
: DW_TAG_namespace
,
20376 context_die
, decl
);
20377 /* For Fortran modules defined in different CU don't add src coords. */
20378 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20380 const char *name
= dwarf2_name (decl
, 0);
20382 add_name_attribute (namespace_die
, name
);
20385 add_name_and_src_coords_attributes (namespace_die
, decl
);
20386 if (DECL_EXTERNAL (decl
))
20387 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20388 equate_decl_number_to_die (decl
, namespace_die
);
20392 /* Output a namespace alias. */
20394 /* Force out the namespace we are an alias of, if necessary. */
20395 dw_die_ref origin_die
20396 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20398 if (DECL_FILE_SCOPE_P (decl
)
20399 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20400 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20401 /* Now create the namespace alias DIE. */
20402 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20403 add_name_and_src_coords_attributes (namespace_die
, decl
);
20404 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20405 equate_decl_number_to_die (decl
, namespace_die
);
20407 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20408 if (want_pubnames ())
20409 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20412 /* Generate Dwarf debug information for a decl described by DECL.
20413 The return value is currently only meaningful for PARM_DECLs,
20414 for all other decls it returns NULL. */
20417 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20419 tree decl_or_origin
= decl
? decl
: origin
;
20420 tree class_origin
= NULL
, ultimate_origin
;
20422 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20425 switch (TREE_CODE (decl_or_origin
))
20431 if (!is_fortran () && !is_ada ())
20433 /* The individual enumerators of an enum type get output when we output
20434 the Dwarf representation of the relevant enum type itself. */
20438 /* Emit its type. */
20439 gen_type_die (TREE_TYPE (decl
), context_die
);
20441 /* And its containing namespace. */
20442 context_die
= declare_in_namespace (decl
, context_die
);
20444 gen_const_die (decl
, context_die
);
20447 case FUNCTION_DECL
:
20448 /* Don't output any DIEs to represent mere function declarations,
20449 unless they are class members or explicit block externs. */
20450 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20451 && DECL_FILE_SCOPE_P (decl_or_origin
)
20452 && (current_function_decl
== NULL_TREE
20453 || DECL_ARTIFICIAL (decl_or_origin
)))
20458 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20459 on local redeclarations of global functions. That seems broken. */
20460 if (current_function_decl
!= decl
)
20461 /* This is only a declaration. */;
20464 /* If we're emitting a clone, emit info for the abstract instance. */
20465 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20466 dwarf2out_abstract_function (origin
20467 ? DECL_ORIGIN (origin
)
20468 : DECL_ABSTRACT_ORIGIN (decl
));
20470 /* If we're emitting an out-of-line copy of an inline function,
20471 emit info for the abstract instance and set up to refer to it. */
20472 else if (cgraph_function_possibly_inlined_p (decl
)
20473 && ! DECL_ABSTRACT (decl
)
20474 && ! class_or_namespace_scope_p (context_die
)
20475 /* dwarf2out_abstract_function won't emit a die if this is just
20476 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20477 that case, because that works only if we have a die. */
20478 && DECL_INITIAL (decl
) != NULL_TREE
)
20480 dwarf2out_abstract_function (decl
);
20481 set_decl_origin_self (decl
);
20484 /* Otherwise we're emitting the primary DIE for this decl. */
20485 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20487 /* Before we describe the FUNCTION_DECL itself, make sure that we
20488 have its containing type. */
20490 origin
= decl_class_context (decl
);
20491 if (origin
!= NULL_TREE
)
20492 gen_type_die (origin
, context_die
);
20494 /* And its return type. */
20495 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20497 /* And its virtual context. */
20498 if (DECL_VINDEX (decl
) != NULL_TREE
)
20499 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20501 /* Make sure we have a member DIE for decl. */
20502 if (origin
!= NULL_TREE
)
20503 gen_type_die_for_member (origin
, decl
, context_die
);
20505 /* And its containing namespace. */
20506 context_die
= declare_in_namespace (decl
, context_die
);
20509 /* Now output a DIE to represent the function itself. */
20511 gen_subprogram_die (decl
, context_die
);
20515 /* If we are in terse mode, don't generate any DIEs to represent any
20516 actual typedefs. */
20517 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20520 /* In the special case of a TYPE_DECL node representing the declaration
20521 of some type tag, if the given TYPE_DECL is marked as having been
20522 instantiated from some other (original) TYPE_DECL node (e.g. one which
20523 was generated within the original definition of an inline function) we
20524 used to generate a special (abbreviated) DW_TAG_structure_type,
20525 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20526 should be actually referencing those DIEs, as variable DIEs with that
20527 type would be emitted already in the abstract origin, so it was always
20528 removed during unused type prunning. Don't add anything in this
20530 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20533 if (is_redundant_typedef (decl
))
20534 gen_type_die (TREE_TYPE (decl
), context_die
);
20536 /* Output a DIE to represent the typedef itself. */
20537 gen_typedef_die (decl
, context_die
);
20541 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20542 gen_label_die (decl
, context_die
);
20547 /* If we are in terse mode, don't generate any DIEs to represent any
20548 variable declarations or definitions. */
20549 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20552 /* Output any DIEs that are needed to specify the type of this data
20554 if (decl_by_reference_p (decl_or_origin
))
20555 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20557 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20559 /* And its containing type. */
20560 class_origin
= decl_class_context (decl_or_origin
);
20561 if (class_origin
!= NULL_TREE
)
20562 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20564 /* And its containing namespace. */
20565 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20567 /* Now output the DIE to represent the data object itself. This gets
20568 complicated because of the possibility that the VAR_DECL really
20569 represents an inlined instance of a formal parameter for an inline
20571 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20572 if (ultimate_origin
!= NULL_TREE
20573 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20574 gen_formal_parameter_die (decl
, origin
,
20575 true /* Emit name attribute. */,
20578 gen_variable_die (decl
, origin
, context_die
);
20582 /* Ignore the nameless fields that are used to skip bits but handle C++
20583 anonymous unions and structs. */
20584 if (DECL_NAME (decl
) != NULL_TREE
20585 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20586 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20588 gen_type_die (member_declared_type (decl
), context_die
);
20589 gen_field_die (decl
, context_die
);
20594 if (DECL_BY_REFERENCE (decl_or_origin
))
20595 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20597 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20598 return gen_formal_parameter_die (decl
, origin
,
20599 true /* Emit name attribute. */,
20602 case NAMESPACE_DECL
:
20603 case IMPORTED_DECL
:
20604 if (dwarf_version
>= 3 || !dwarf_strict
)
20605 gen_namespace_die (decl
, context_die
);
20609 /* Probably some frontend-internal decl. Assume we don't care. */
20610 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20617 /* Output debug information for global decl DECL. Called from toplev.c after
20618 compilation proper has finished. */
20621 dwarf2out_global_decl (tree decl
)
20623 /* Output DWARF2 information for file-scope tentative data object
20624 declarations, file-scope (extern) function declarations (which
20625 had no corresponding body) and file-scope tagged type declarations
20626 and definitions which have not yet been forced out. */
20627 if ((TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20628 && !POINTER_BOUNDS_P (decl
))
20629 dwarf2out_decl (decl
);
20632 /* Output debug information for type decl DECL. Called from toplev.c
20633 and from language front ends (to record built-in types). */
20635 dwarf2out_type_decl (tree decl
, int local
)
20638 dwarf2out_decl (decl
);
20641 /* Output debug information for imported module or decl DECL.
20642 NAME is non-NULL name in the lexical block if the decl has been renamed.
20643 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20644 that DECL belongs to.
20645 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20647 dwarf2out_imported_module_or_decl_1 (tree decl
,
20649 tree lexical_block
,
20650 dw_die_ref lexical_block_die
)
20652 expanded_location xloc
;
20653 dw_die_ref imported_die
= NULL
;
20654 dw_die_ref at_import_die
;
20656 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20658 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20659 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20663 xloc
= expand_location (input_location
);
20665 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20667 at_import_die
= force_type_die (TREE_TYPE (decl
));
20668 /* For namespace N { typedef void T; } using N::T; base_type_die
20669 returns NULL, but DW_TAG_imported_declaration requires
20670 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20671 if (!at_import_die
)
20673 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20674 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20675 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20676 gcc_assert (at_import_die
);
20681 at_import_die
= lookup_decl_die (decl
);
20682 if (!at_import_die
)
20684 /* If we're trying to avoid duplicate debug info, we may not have
20685 emitted the member decl for this field. Emit it now. */
20686 if (TREE_CODE (decl
) == FIELD_DECL
)
20688 tree type
= DECL_CONTEXT (decl
);
20690 if (TYPE_CONTEXT (type
)
20691 && TYPE_P (TYPE_CONTEXT (type
))
20692 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20693 DINFO_USAGE_DIR_USE
))
20695 gen_type_die_for_member (type
, decl
,
20696 get_context_die (TYPE_CONTEXT (type
)));
20698 at_import_die
= force_decl_die (decl
);
20702 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20704 if (dwarf_version
>= 3 || !dwarf_strict
)
20705 imported_die
= new_die (DW_TAG_imported_module
,
20712 imported_die
= new_die (DW_TAG_imported_declaration
,
20716 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20717 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20719 add_AT_string (imported_die
, DW_AT_name
,
20720 IDENTIFIER_POINTER (name
));
20721 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20724 /* Output debug information for imported module or decl DECL.
20725 NAME is non-NULL name in context if the decl has been renamed.
20726 CHILD is true if decl is one of the renamed decls as part of
20727 importing whole module. */
20730 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20733 /* dw_die_ref at_import_die; */
20734 dw_die_ref scope_die
;
20736 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20741 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20742 We need decl DIE for reference and scope die. First, get DIE for the decl
20745 /* Get the scope die for decl context. Use comp_unit_die for global module
20746 or decl. If die is not found for non globals, force new die. */
20748 && TYPE_P (context
)
20749 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20752 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20755 scope_die
= get_context_die (context
);
20759 gcc_assert (scope_die
->die_child
);
20760 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20761 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20762 scope_die
= scope_die
->die_child
;
20765 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20766 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20770 /* Write the debugging output for DECL. */
20773 dwarf2out_decl (tree decl
)
20775 dw_die_ref context_die
= comp_unit_die ();
20777 switch (TREE_CODE (decl
))
20782 case FUNCTION_DECL
:
20783 /* What we would really like to do here is to filter out all mere
20784 file-scope declarations of file-scope functions which are never
20785 referenced later within this translation unit (and keep all of ones
20786 that *are* referenced later on) but we aren't clairvoyant, so we have
20787 no idea which functions will be referenced in the future (i.e. later
20788 on within the current translation unit). So here we just ignore all
20789 file-scope function declarations which are not also definitions. If
20790 and when the debugger needs to know something about these functions,
20791 it will have to hunt around and find the DWARF information associated
20792 with the definition of the function.
20794 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20795 nodes represent definitions and which ones represent mere
20796 declarations. We have to check DECL_INITIAL instead. That's because
20797 the C front-end supports some weird semantics for "extern inline"
20798 function definitions. These can get inlined within the current
20799 translation unit (and thus, we need to generate Dwarf info for their
20800 abstract instances so that the Dwarf info for the concrete inlined
20801 instances can have something to refer to) but the compiler never
20802 generates any out-of-lines instances of such things (despite the fact
20803 that they *are* definitions).
20805 The important point is that the C front-end marks these "extern
20806 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20807 them anyway. Note that the C++ front-end also plays some similar games
20808 for inline function definitions appearing within include files which
20809 also contain `#pragma interface' pragmas.
20811 If we are called from dwarf2out_abstract_function output a DIE
20812 anyway. We can end up here this way with early inlining and LTO
20813 where the inlined function is output in a different LTRANS unit
20815 if (DECL_INITIAL (decl
) == NULL_TREE
20816 && ! DECL_ABSTRACT (decl
))
20819 /* If we're a nested function, initially use a parent of NULL; if we're
20820 a plain function, this will be fixed up in decls_for_scope. If
20821 we're a method, it will be ignored, since we already have a DIE. */
20822 if (decl_function_context (decl
)
20823 /* But if we're in terse mode, we don't care about scope. */
20824 && debug_info_level
> DINFO_LEVEL_TERSE
)
20825 context_die
= NULL
;
20829 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20830 declaration and if the declaration was never even referenced from
20831 within this entire compilation unit. We suppress these DIEs in
20832 order to save space in the .debug section (by eliminating entries
20833 which are probably useless). Note that we must not suppress
20834 block-local extern declarations (whether used or not) because that
20835 would screw-up the debugger's name lookup mechanism and cause it to
20836 miss things which really ought to be in scope at a given point. */
20837 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20840 /* For local statics lookup proper context die. */
20841 if (TREE_STATIC (decl
)
20842 && DECL_CONTEXT (decl
)
20843 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20844 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20846 /* If we are in terse mode, don't generate any DIEs to represent any
20847 variable declarations or definitions. */
20848 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20853 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20855 if (!is_fortran () && !is_ada ())
20857 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20858 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20861 case NAMESPACE_DECL
:
20862 case IMPORTED_DECL
:
20863 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20865 if (lookup_decl_die (decl
) != NULL
)
20870 /* Don't emit stubs for types unless they are needed by other DIEs. */
20871 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20874 /* Don't bother trying to generate any DIEs to represent any of the
20875 normal built-in types for the language we are compiling. */
20876 if (DECL_IS_BUILTIN (decl
))
20879 /* If we are in terse mode, don't generate any DIEs for types. */
20880 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20883 /* If we're a function-scope tag, initially use a parent of NULL;
20884 this will be fixed up in decls_for_scope. */
20885 if (decl_function_context (decl
))
20886 context_die
= NULL
;
20894 gen_decl_die (decl
, NULL
, context_die
);
20897 /* Write the debugging output for DECL. */
20900 dwarf2out_function_decl (tree decl
)
20902 dwarf2out_decl (decl
);
20903 call_arg_locations
= NULL
;
20904 call_arg_loc_last
= NULL
;
20905 call_site_count
= -1;
20906 tail_call_site_count
= -1;
20907 block_map
.release ();
20908 htab_empty (decl_loc_table
);
20909 htab_empty (cached_dw_loc_list_table
);
20912 /* Output a marker (i.e. a label) for the beginning of the generated code for
20913 a lexical block. */
20916 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20917 unsigned int blocknum
)
20919 switch_to_section (current_function_section ());
20920 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20923 /* Output a marker (i.e. a label) for the end of the generated code for a
20927 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20929 switch_to_section (current_function_section ());
20930 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20933 /* Returns nonzero if it is appropriate not to emit any debugging
20934 information for BLOCK, because it doesn't contain any instructions.
20936 Don't allow this for blocks with nested functions or local classes
20937 as we would end up with orphans, and in the presence of scheduling
20938 we may end up calling them anyway. */
20941 dwarf2out_ignore_block (const_tree block
)
20946 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20947 if (TREE_CODE (decl
) == FUNCTION_DECL
20948 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20950 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20952 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20953 if (TREE_CODE (decl
) == FUNCTION_DECL
20954 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20961 /* Hash table routines for file_hash. */
20964 file_table_eq (const void *p1_p
, const void *p2_p
)
20966 const struct dwarf_file_data
*const p1
=
20967 (const struct dwarf_file_data
*) p1_p
;
20968 const char *const p2
= (const char *) p2_p
;
20969 return filename_cmp (p1
->filename
, p2
) == 0;
20973 file_table_hash (const void *p_p
)
20975 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20976 return htab_hash_string (p
->filename
);
20979 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20980 dwarf2out.c) and return its "index". The index of each (known) filename is
20981 just a unique number which is associated with only that one filename. We
20982 need such numbers for the sake of generating labels (in the .debug_sfnames
20983 section) and references to those files numbers (in the .debug_srcinfo
20984 and.debug_macinfo sections). If the filename given as an argument is not
20985 found in our current list, add it to the list and assign it the next
20986 available unique index number. In order to speed up searches, we remember
20987 the index of the filename was looked up last. This handles the majority of
20990 static struct dwarf_file_data
*
20991 lookup_filename (const char *file_name
)
20994 struct dwarf_file_data
* created
;
20996 /* Check to see if the file name that was searched on the previous
20997 call matches this file name. If so, return the index. */
20998 if (file_table_last_lookup
20999 && (file_name
== file_table_last_lookup
->filename
21000 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
21001 return file_table_last_lookup
;
21003 /* Didn't match the previous lookup, search the table. */
21004 slot
= htab_find_slot_with_hash (file_table
, file_name
,
21005 htab_hash_string (file_name
), INSERT
);
21007 return (struct dwarf_file_data
*) *slot
;
21009 created
= ggc_alloc_dwarf_file_data ();
21010 created
->filename
= file_name
;
21011 created
->emitted_number
= 0;
21016 /* If the assembler will construct the file table, then translate the compiler
21017 internal file table number into the assembler file table number, and emit
21018 a .file directive if we haven't already emitted one yet. The file table
21019 numbers are different because we prune debug info for unused variables and
21020 types, which may include filenames. */
21023 maybe_emit_file (struct dwarf_file_data
* fd
)
21025 if (! fd
->emitted_number
)
21027 if (last_emitted_file
)
21028 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
21030 fd
->emitted_number
= 1;
21031 last_emitted_file
= fd
;
21033 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21035 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
21036 output_quoted_string (asm_out_file
,
21037 remap_debug_filename (fd
->filename
));
21038 fputc ('\n', asm_out_file
);
21042 return fd
->emitted_number
;
21045 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21046 That generation should happen after function debug info has been
21047 generated. The value of the attribute is the constant value of ARG. */
21050 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21052 die_arg_entry entry
;
21057 if (!tmpl_value_parm_die_table
)
21058 vec_alloc (tmpl_value_parm_die_table
, 32);
21062 vec_safe_push (tmpl_value_parm_die_table
, entry
);
21065 /* Return TRUE if T is an instance of generic type, FALSE
21069 generic_type_p (tree t
)
21071 if (t
== NULL_TREE
|| !TYPE_P (t
))
21073 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
21076 /* Schedule the generation of the generic parameter dies for the
21077 instance of generic type T. The proper generation itself is later
21078 done by gen_scheduled_generic_parms_dies. */
21081 schedule_generic_params_dies_gen (tree t
)
21083 if (!generic_type_p (t
))
21086 if (!generic_type_instances
)
21087 vec_alloc (generic_type_instances
, 256);
21089 vec_safe_push (generic_type_instances
, t
);
21092 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21093 by append_entry_to_tmpl_value_parm_die_table. This function must
21094 be called after function DIEs have been generated. */
21097 gen_remaining_tmpl_value_param_die_attribute (void)
21099 if (tmpl_value_parm_die_table
)
21104 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
21105 tree_add_const_value_attribute (e
->die
, e
->arg
);
21109 /* Generate generic parameters DIEs for instances of generic types
21110 that have been previously scheduled by
21111 schedule_generic_params_dies_gen. This function must be called
21112 after all the types of the CU have been laid out. */
21115 gen_scheduled_generic_parms_dies (void)
21120 if (!generic_type_instances
)
21123 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
21124 if (COMPLETE_TYPE_P (t
))
21125 gen_generic_params_dies (t
);
21129 /* Replace DW_AT_name for the decl with name. */
21132 dwarf2out_set_name (tree decl
, tree name
)
21138 die
= TYPE_SYMTAB_DIE (decl
);
21142 dname
= dwarf2_name (name
, 0);
21146 attr
= get_AT (die
, DW_AT_name
);
21149 struct indirect_string_node
*node
;
21151 node
= find_AT_string (dname
);
21152 /* replace the string. */
21153 attr
->dw_attr_val
.v
.val_str
= node
;
21157 add_name_attribute (die
, dname
);
21160 /* True if before or during processing of the first function being emitted. */
21161 static bool in_first_function_p
= true;
21162 /* True if loc_note during dwarf2out_var_location call might still be
21163 before first real instruction at address equal to .Ltext0. */
21164 static bool maybe_at_text_label_p
= true;
21165 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
21166 static unsigned int first_loclabel_num_not_at_text_label
;
21168 /* Called by the final INSN scan whenever we see a var location. We
21169 use it to drop labels in the right places, and throw the location in
21170 our lookup table. */
21173 dwarf2out_var_location (rtx loc_note
)
21175 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21176 struct var_loc_node
*newloc
;
21177 rtx next_real
, next_note
;
21178 static const char *last_label
;
21179 static const char *last_postcall_label
;
21180 static bool last_in_cold_section_p
;
21181 static rtx expected_next_loc_note
;
21185 if (!NOTE_P (loc_note
))
21187 if (CALL_P (loc_note
))
21190 if (SIBLING_CALL_P (loc_note
))
21191 tail_call_site_count
++;
21196 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21197 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21200 /* Optimize processing a large consecutive sequence of location
21201 notes so we don't spend too much time in next_real_insn. If the
21202 next insn is another location note, remember the next_real_insn
21203 calculation for next time. */
21204 next_real
= cached_next_real_insn
;
21207 if (expected_next_loc_note
!= loc_note
)
21208 next_real
= NULL_RTX
;
21211 next_note
= NEXT_INSN (loc_note
);
21213 || INSN_DELETED_P (next_note
)
21214 || ! NOTE_P (next_note
)
21215 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21216 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21217 next_note
= NULL_RTX
;
21220 next_real
= next_real_insn (loc_note
);
21224 expected_next_loc_note
= next_note
;
21225 cached_next_real_insn
= next_real
;
21228 cached_next_real_insn
= NULL_RTX
;
21230 /* If there are no instructions which would be affected by this note,
21231 don't do anything. */
21233 && next_real
== NULL_RTX
21234 && !NOTE_DURING_CALL_P (loc_note
))
21237 if (next_real
== NULL_RTX
)
21238 next_real
= get_last_insn ();
21240 /* If there were any real insns between note we processed last time
21241 and this note (or if it is the first note), clear
21242 last_{,postcall_}label so that they are not reused this time. */
21243 if (last_var_location_insn
== NULL_RTX
21244 || last_var_location_insn
!= next_real
21245 || last_in_cold_section_p
!= in_cold_section_p
)
21248 last_postcall_label
= NULL
;
21253 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21254 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21255 NOTE_DURING_CALL_P (loc_note
)
21256 ? last_postcall_label
: last_label
);
21257 if (newloc
== NULL
)
21266 /* If there were no real insns between note we processed last time
21267 and this note, use the label we emitted last time. Otherwise
21268 create a new label and emit it. */
21269 if (last_label
== NULL
)
21271 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21272 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21274 last_label
= ggc_strdup (loclabel
);
21275 /* See if loclabel might be equal to .Ltext0. If yes,
21276 bump first_loclabel_num_not_at_text_label. */
21277 if (!have_multiple_function_sections
21278 && in_first_function_p
21279 && maybe_at_text_label_p
)
21281 static rtx last_start
;
21283 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21284 if (insn
== last_start
)
21286 else if (!NONDEBUG_INSN_P (insn
))
21290 rtx body
= PATTERN (insn
);
21291 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21293 /* Inline asm could occupy zero bytes. */
21294 else if (GET_CODE (body
) == ASM_INPUT
21295 || asm_noperands (body
) >= 0)
21297 #ifdef HAVE_attr_length
21298 else if (get_attr_min_length (insn
) == 0)
21303 /* Assume insn has non-zero length. */
21304 maybe_at_text_label_p
= false;
21308 if (maybe_at_text_label_p
)
21310 last_start
= loc_note
;
21311 first_loclabel_num_not_at_text_label
= loclabel_num
;
21318 struct call_arg_loc_node
*ca_loc
21319 = ggc_alloc_cleared_call_arg_loc_node ();
21320 rtx prev
= prev_real_insn (loc_note
), x
;
21321 ca_loc
->call_arg_loc_note
= loc_note
;
21322 ca_loc
->next
= NULL
;
21323 ca_loc
->label
= last_label
;
21326 || (NONJUMP_INSN_P (prev
)
21327 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21328 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21329 if (!CALL_P (prev
))
21330 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21331 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21332 x
= get_call_rtx_from (PATTERN (prev
));
21335 x
= XEXP (XEXP (x
, 0), 0);
21336 if (GET_CODE (x
) == SYMBOL_REF
21337 && SYMBOL_REF_DECL (x
)
21338 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21339 ca_loc
->symbol_ref
= x
;
21341 ca_loc
->block
= insn_scope (prev
);
21342 if (call_arg_locations
)
21343 call_arg_loc_last
->next
= ca_loc
;
21345 call_arg_locations
= ca_loc
;
21346 call_arg_loc_last
= ca_loc
;
21348 else if (!NOTE_DURING_CALL_P (loc_note
))
21349 newloc
->label
= last_label
;
21352 if (!last_postcall_label
)
21354 sprintf (loclabel
, "%s-1", last_label
);
21355 last_postcall_label
= ggc_strdup (loclabel
);
21357 newloc
->label
= last_postcall_label
;
21360 last_var_location_insn
= next_real
;
21361 last_in_cold_section_p
= in_cold_section_p
;
21364 /* Note in one location list that text section has changed. */
21367 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21369 var_loc_list
*list
= (var_loc_list
*) *slot
;
21371 list
->last_before_switch
21372 = list
->last
->next
? list
->last
->next
: list
->last
;
21376 /* Note in all location lists that text section has changed. */
21379 var_location_switch_text_section (void)
21381 if (decl_loc_table
== NULL
)
21384 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21387 /* Create a new line number table. */
21389 static dw_line_info_table
*
21390 new_line_info_table (void)
21392 dw_line_info_table
*table
;
21394 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21395 table
->file_num
= 1;
21396 table
->line_num
= 1;
21397 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21402 /* Lookup the "current" table into which we emit line info, so
21403 that we don't have to do it for every source line. */
21406 set_cur_line_info_table (section
*sec
)
21408 dw_line_info_table
*table
;
21410 if (sec
== text_section
)
21411 table
= text_section_line_info
;
21412 else if (sec
== cold_text_section
)
21414 table
= cold_text_section_line_info
;
21417 cold_text_section_line_info
= table
= new_line_info_table ();
21418 table
->end_label
= cold_end_label
;
21423 const char *end_label
;
21425 if (flag_reorder_blocks_and_partition
)
21427 if (in_cold_section_p
)
21428 end_label
= crtl
->subsections
.cold_section_end_label
;
21430 end_label
= crtl
->subsections
.hot_section_end_label
;
21434 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21435 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21436 current_function_funcdef_no
);
21437 end_label
= ggc_strdup (label
);
21440 table
= new_line_info_table ();
21441 table
->end_label
= end_label
;
21443 vec_safe_push (separate_line_info
, table
);
21446 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21447 table
->is_stmt
= (cur_line_info_table
21448 ? cur_line_info_table
->is_stmt
21449 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21450 cur_line_info_table
= table
;
21454 /* We need to reset the locations at the beginning of each
21455 function. We can't do this in the end_function hook, because the
21456 declarations that use the locations won't have been output when
21457 that hook is called. Also compute have_multiple_function_sections here. */
21460 dwarf2out_begin_function (tree fun
)
21462 section
*sec
= function_section (fun
);
21464 if (sec
!= text_section
)
21465 have_multiple_function_sections
= true;
21467 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21469 gcc_assert (current_function_decl
== fun
);
21470 cold_text_section
= unlikely_text_section ();
21471 switch_to_section (cold_text_section
);
21472 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21473 switch_to_section (sec
);
21476 dwarf2out_note_section_used ();
21477 call_site_count
= 0;
21478 tail_call_site_count
= 0;
21480 set_cur_line_info_table (sec
);
21483 /* Helper function of dwarf2out_end_function, called only after emitting
21484 the very first function into assembly. Check if some .debug_loc range
21485 might end with a .LVL* label that could be equal to .Ltext0.
21486 In that case we must force using absolute addresses in .debug_loc ranges,
21487 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21488 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21490 Set have_multiple_function_sections to true in that case and
21491 terminate htab traversal. */
21494 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21496 var_loc_list
*entry
;
21497 struct var_loc_node
*node
;
21499 entry
= (var_loc_list
*) *slot
;
21500 node
= entry
->first
;
21501 if (node
&& node
->next
&& node
->next
->label
)
21504 const char *label
= node
->next
->label
;
21505 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21507 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21509 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21510 if (strcmp (label
, loclabel
) == 0)
21512 have_multiple_function_sections
= true;
21520 /* Hook called after emitting a function into assembly.
21521 This does something only for the very first function emitted. */
21524 dwarf2out_end_function (unsigned int)
21526 if (in_first_function_p
21527 && !have_multiple_function_sections
21528 && first_loclabel_num_not_at_text_label
21530 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21532 in_first_function_p
= false;
21533 maybe_at_text_label_p
= false;
21536 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21539 push_dw_line_info_entry (dw_line_info_table
*table
,
21540 enum dw_line_info_opcode opcode
, unsigned int val
)
21542 dw_line_info_entry e
;
21545 vec_safe_push (table
->entries
, e
);
21548 /* Output a label to mark the beginning of a source code line entry
21549 and record information relating to this source line, in
21550 'line_info_table' for later output of the .debug_line section. */
21551 /* ??? The discriminator parameter ought to be unsigned. */
21554 dwarf2out_source_line (unsigned int line
, const char *filename
,
21555 int discriminator
, bool is_stmt
)
21557 unsigned int file_num
;
21558 dw_line_info_table
*table
;
21560 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21563 /* The discriminator column was added in dwarf4. Simplify the below
21564 by simply removing it if we're not supposed to output it. */
21565 if (dwarf_version
< 4 && dwarf_strict
)
21568 table
= cur_line_info_table
;
21569 file_num
= maybe_emit_file (lookup_filename (filename
));
21571 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21572 the debugger has used the second (possibly duplicate) line number
21573 at the beginning of the function to mark the end of the prologue.
21574 We could eliminate any other duplicates within the function. For
21575 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21576 that second line number entry. */
21577 /* Recall that this end-of-prologue indication is *not* the same thing
21578 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21579 to which the hook corresponds, follows the last insn that was
21580 emitted by gen_prologue. What we need is to precede the first insn
21581 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21582 insn that corresponds to something the user wrote. These may be
21583 very different locations once scheduling is enabled. */
21585 if (0 && file_num
== table
->file_num
21586 && line
== table
->line_num
21587 && discriminator
== table
->discrim_num
21588 && is_stmt
== table
->is_stmt
)
21591 switch_to_section (current_function_section ());
21593 /* If requested, emit something human-readable. */
21594 if (flag_debug_asm
)
21595 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21597 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21599 /* Emit the .loc directive understood by GNU as. */
21600 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21601 file_num, line, is_stmt, discriminator */
21602 fputs ("\t.loc ", asm_out_file
);
21603 fprint_ul (asm_out_file
, file_num
);
21604 putc (' ', asm_out_file
);
21605 fprint_ul (asm_out_file
, line
);
21606 putc (' ', asm_out_file
);
21607 putc ('0', asm_out_file
);
21609 if (is_stmt
!= table
->is_stmt
)
21611 fputs (" is_stmt ", asm_out_file
);
21612 putc (is_stmt
? '1' : '0', asm_out_file
);
21614 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21616 gcc_assert (discriminator
> 0);
21617 fputs (" discriminator ", asm_out_file
);
21618 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21620 putc ('\n', asm_out_file
);
21624 unsigned int label_num
= ++line_info_label_num
;
21626 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21628 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21629 if (file_num
!= table
->file_num
)
21630 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21631 if (discriminator
!= table
->discrim_num
)
21632 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21633 if (is_stmt
!= table
->is_stmt
)
21634 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21635 push_dw_line_info_entry (table
, LI_set_line
, line
);
21638 table
->file_num
= file_num
;
21639 table
->line_num
= line
;
21640 table
->discrim_num
= discriminator
;
21641 table
->is_stmt
= is_stmt
;
21642 table
->in_use
= true;
21645 /* Record the beginning of a new source file. */
21648 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21650 if (flag_eliminate_dwarf2_dups
)
21652 /* Record the beginning of the file for break_out_includes. */
21653 dw_die_ref bincl_die
;
21655 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21656 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21659 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21662 e
.code
= DW_MACINFO_start_file
;
21664 e
.info
= ggc_strdup (filename
);
21665 vec_safe_push (macinfo_table
, e
);
21669 /* Record the end of a source file. */
21672 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21674 if (flag_eliminate_dwarf2_dups
)
21675 /* Record the end of the file for break_out_includes. */
21676 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21678 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21681 e
.code
= DW_MACINFO_end_file
;
21684 vec_safe_push (macinfo_table
, e
);
21688 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21689 the tail part of the directive line, i.e. the part which is past the
21690 initial whitespace, #, whitespace, directive-name, whitespace part. */
21693 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21694 const char *buffer ATTRIBUTE_UNUSED
)
21696 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21699 /* Insert a dummy first entry to be able to optimize the whole
21700 predefined macro block using DW_MACRO_GNU_transparent_include. */
21701 if (macinfo_table
->is_empty () && lineno
<= 1)
21706 vec_safe_push (macinfo_table
, e
);
21708 e
.code
= DW_MACINFO_define
;
21710 e
.info
= ggc_strdup (buffer
);
21711 vec_safe_push (macinfo_table
, e
);
21715 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21716 the tail part of the directive line, i.e. the part which is past the
21717 initial whitespace, #, whitespace, directive-name, whitespace part. */
21720 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21721 const char *buffer ATTRIBUTE_UNUSED
)
21723 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21726 /* Insert a dummy first entry to be able to optimize the whole
21727 predefined macro block using DW_MACRO_GNU_transparent_include. */
21728 if (macinfo_table
->is_empty () && lineno
<= 1)
21733 vec_safe_push (macinfo_table
, e
);
21735 e
.code
= DW_MACINFO_undef
;
21737 e
.info
= ggc_strdup (buffer
);
21738 vec_safe_push (macinfo_table
, e
);
21742 /* Helpers to manipulate hash table of CUs. */
21744 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21746 typedef macinfo_entry value_type
;
21747 typedef macinfo_entry compare_type
;
21748 static inline hashval_t
hash (const value_type
*);
21749 static inline bool equal (const value_type
*, const compare_type
*);
21753 macinfo_entry_hasher::hash (const value_type
*entry
)
21755 return htab_hash_string (entry
->info
);
21759 macinfo_entry_hasher::equal (const value_type
*entry1
,
21760 const compare_type
*entry2
)
21762 return !strcmp (entry1
->info
, entry2
->info
);
21765 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21767 /* Output a single .debug_macinfo entry. */
21770 output_macinfo_op (macinfo_entry
*ref
)
21774 struct indirect_string_node
*node
;
21775 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21776 struct dwarf_file_data
*fd
;
21780 case DW_MACINFO_start_file
:
21781 fd
= lookup_filename (ref
->info
);
21782 file_num
= maybe_emit_file (fd
);
21783 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21784 dw2_asm_output_data_uleb128 (ref
->lineno
,
21785 "Included from line number %lu",
21786 (unsigned long) ref
->lineno
);
21787 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21789 case DW_MACINFO_end_file
:
21790 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21792 case DW_MACINFO_define
:
21793 case DW_MACINFO_undef
:
21794 len
= strlen (ref
->info
) + 1;
21796 && len
> DWARF_OFFSET_SIZE
21797 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21798 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21800 ref
->code
= ref
->code
== DW_MACINFO_define
21801 ? DW_MACRO_GNU_define_indirect
21802 : DW_MACRO_GNU_undef_indirect
;
21803 output_macinfo_op (ref
);
21806 dw2_asm_output_data (1, ref
->code
,
21807 ref
->code
== DW_MACINFO_define
21808 ? "Define macro" : "Undefine macro");
21809 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21810 (unsigned long) ref
->lineno
);
21811 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21813 case DW_MACRO_GNU_define_indirect
:
21814 case DW_MACRO_GNU_undef_indirect
:
21815 node
= find_AT_string (ref
->info
);
21817 && ((node
->form
== DW_FORM_strp
)
21818 || (node
->form
== DW_FORM_GNU_str_index
)));
21819 dw2_asm_output_data (1, ref
->code
,
21820 ref
->code
== DW_MACRO_GNU_define_indirect
21821 ? "Define macro indirect"
21822 : "Undefine macro indirect");
21823 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21824 (unsigned long) ref
->lineno
);
21825 if (node
->form
== DW_FORM_strp
)
21826 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21827 debug_str_section
, "The macro: \"%s\"",
21830 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21833 case DW_MACRO_GNU_transparent_include
:
21834 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21835 ASM_GENERATE_INTERNAL_LABEL (label
,
21836 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21837 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21840 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21841 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21846 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21847 other compilation unit .debug_macinfo sections. IDX is the first
21848 index of a define/undef, return the number of ops that should be
21849 emitted in a comdat .debug_macinfo section and emit
21850 a DW_MACRO_GNU_transparent_include entry referencing it.
21851 If the define/undef entry should be emitted normally, return 0. */
21854 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21855 macinfo_hash_type
*macinfo_htab
)
21857 macinfo_entry
*first
, *second
, *cur
, *inc
;
21858 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21859 unsigned char checksum
[16];
21860 struct md5_ctx ctx
;
21861 char *grp_name
, *tail
;
21863 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21864 macinfo_entry
**slot
;
21866 first
= &(*macinfo_table
)[idx
];
21867 second
= &(*macinfo_table
)[idx
+ 1];
21869 /* Optimize only if there are at least two consecutive define/undef ops,
21870 and either all of them are before first DW_MACINFO_start_file
21871 with lineno {0,1} (i.e. predefined macro block), or all of them are
21872 in some included header file. */
21873 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21875 if (vec_safe_is_empty (files
))
21877 if (first
->lineno
> 1 || second
->lineno
> 1)
21880 else if (first
->lineno
== 0)
21883 /* Find the last define/undef entry that can be grouped together
21884 with first and at the same time compute md5 checksum of their
21885 codes, linenumbers and strings. */
21886 md5_init_ctx (&ctx
);
21887 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21888 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21890 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21894 unsigned char code
= cur
->code
;
21895 md5_process_bytes (&code
, 1, &ctx
);
21896 checksum_uleb128 (cur
->lineno
, &ctx
);
21897 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21899 md5_finish_ctx (&ctx
, checksum
);
21902 /* From the containing include filename (if any) pick up just
21903 usable characters from its basename. */
21904 if (vec_safe_is_empty (files
))
21907 base
= lbasename (files
->last ().info
);
21908 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21909 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21910 encoded_filename_len
++;
21911 /* Count . at the end. */
21912 if (encoded_filename_len
)
21913 encoded_filename_len
++;
21915 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21916 linebuf_len
= strlen (linebuf
);
21918 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21919 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21921 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21922 tail
= grp_name
+ 4;
21923 if (encoded_filename_len
)
21925 for (i
= 0; base
[i
]; i
++)
21926 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21930 memcpy (tail
, linebuf
, linebuf_len
);
21931 tail
+= linebuf_len
;
21933 for (i
= 0; i
< 16; i
++)
21934 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21936 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21937 in the empty vector entry before the first define/undef. */
21938 inc
= &(*macinfo_table
)[idx
- 1];
21939 inc
->code
= DW_MACRO_GNU_transparent_include
;
21941 inc
->info
= ggc_strdup (grp_name
);
21942 if (!macinfo_htab
->is_created ())
21943 macinfo_htab
->create (10);
21944 /* Avoid emitting duplicates. */
21945 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21950 /* If such an entry has been used before, just emit
21951 a DW_MACRO_GNU_transparent_include op. */
21953 output_macinfo_op (inc
);
21954 /* And clear all macinfo_entry in the range to avoid emitting them
21955 in the second pass. */
21956 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21965 inc
->lineno
= macinfo_htab
->elements ();
21966 output_macinfo_op (inc
);
21971 /* Save any strings needed by the macinfo table in the debug str
21972 table. All strings must be collected into the table by the time
21973 index_string is called. */
21976 save_macinfo_strings (void)
21980 macinfo_entry
*ref
;
21982 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21986 /* Match the logic in output_macinfo_op to decide on
21987 indirect strings. */
21988 case DW_MACINFO_define
:
21989 case DW_MACINFO_undef
:
21990 len
= strlen (ref
->info
) + 1;
21992 && len
> DWARF_OFFSET_SIZE
21993 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21994 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21995 set_indirect_string (find_AT_string (ref
->info
));
21997 case DW_MACRO_GNU_define_indirect
:
21998 case DW_MACRO_GNU_undef_indirect
:
21999 set_indirect_string (find_AT_string (ref
->info
));
22007 /* Output macinfo section(s). */
22010 output_macinfo (void)
22013 unsigned long length
= vec_safe_length (macinfo_table
);
22014 macinfo_entry
*ref
;
22015 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
22016 macinfo_hash_type macinfo_htab
;
22021 /* output_macinfo* uses these interchangeably. */
22022 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
22023 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
22024 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
22025 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
22027 /* For .debug_macro emit the section header. */
22030 dw2_asm_output_data (2, 4, "DWARF macro version number");
22031 if (DWARF_OFFSET_SIZE
== 8)
22032 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
22034 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
22035 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
22036 (!dwarf_split_debug_info
? debug_line_section_label
22037 : debug_skeleton_line_section_label
),
22038 debug_line_section
, NULL
);
22041 /* In the first loop, it emits the primary .debug_macinfo section
22042 and after each emitted op the macinfo_entry is cleared.
22043 If a longer range of define/undef ops can be optimized using
22044 DW_MACRO_GNU_transparent_include, the
22045 DW_MACRO_GNU_transparent_include op is emitted and kept in
22046 the vector before the first define/undef in the range and the
22047 whole range of define/undef ops is not emitted and kept. */
22048 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22052 case DW_MACINFO_start_file
:
22053 vec_safe_push (files
, *ref
);
22055 case DW_MACINFO_end_file
:
22056 if (!vec_safe_is_empty (files
))
22059 case DW_MACINFO_define
:
22060 case DW_MACINFO_undef
:
22062 && HAVE_COMDAT_GROUP
22063 && vec_safe_length (files
) != 1
22066 && (*macinfo_table
)[i
- 1].code
== 0)
22068 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
22077 /* A dummy entry may be inserted at the beginning to be able
22078 to optimize the whole block of predefined macros. */
22084 output_macinfo_op (ref
);
22089 if (!macinfo_htab
.is_created ())
22092 macinfo_htab
.dispose ();
22094 /* If any DW_MACRO_GNU_transparent_include were used, on those
22095 DW_MACRO_GNU_transparent_include entries terminate the
22096 current chain and switch to a new comdat .debug_macinfo
22097 section and emit the define/undef entries within it. */
22098 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22103 case DW_MACRO_GNU_transparent_include
:
22105 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22106 tree comdat_key
= get_identifier (ref
->info
);
22107 /* Terminate the previous .debug_macinfo section. */
22108 dw2_asm_output_data (1, 0, "End compilation unit");
22109 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
22111 | SECTION_LINKONCE
,
22113 ASM_GENERATE_INTERNAL_LABEL (label
,
22114 DEBUG_MACRO_SECTION_LABEL
,
22116 ASM_OUTPUT_LABEL (asm_out_file
, label
);
22119 dw2_asm_output_data (2, 4, "DWARF macro version number");
22120 if (DWARF_OFFSET_SIZE
== 8)
22121 dw2_asm_output_data (1, 1, "Flags: 64-bit");
22123 dw2_asm_output_data (1, 0, "Flags: 32-bit");
22126 case DW_MACINFO_define
:
22127 case DW_MACINFO_undef
:
22128 output_macinfo_op (ref
);
22133 gcc_unreachable ();
22137 /* Set up for Dwarf output at the start of compilation. */
22140 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
22142 /* Allocate the file_table. */
22143 file_table
= htab_create_ggc (50, file_table_hash
,
22144 file_table_eq
, NULL
);
22146 /* Allocate the decl_die_table. */
22147 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
22148 decl_die_table_eq
, NULL
);
22150 /* Allocate the decl_loc_table. */
22151 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
22152 decl_loc_table_eq
, NULL
);
22154 /* Allocate the cached_dw_loc_list_table. */
22155 cached_dw_loc_list_table
22156 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
22157 cached_dw_loc_list_table_eq
, NULL
);
22159 /* Allocate the initial hunk of the decl_scope_table. */
22160 vec_alloc (decl_scope_table
, 256);
22162 /* Allocate the initial hunk of the abbrev_die_table. */
22163 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
22164 (ABBREV_DIE_TABLE_INCREMENT
);
22165 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22166 /* Zero-th entry is allocated, but unused. */
22167 abbrev_die_table_in_use
= 1;
22169 /* Allocate the pubtypes and pubnames vectors. */
22170 vec_alloc (pubname_table
, 32);
22171 vec_alloc (pubtype_table
, 32);
22173 vec_alloc (incomplete_types
, 64);
22175 vec_alloc (used_rtx_array
, 32);
22177 if (!dwarf_split_debug_info
)
22179 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22180 SECTION_DEBUG
, NULL
);
22181 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22182 SECTION_DEBUG
, NULL
);
22183 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22184 SECTION_DEBUG
, NULL
);
22188 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22189 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22190 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22191 SECTION_DEBUG
| SECTION_EXCLUDE
,
22193 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22194 SECTION_DEBUG
, NULL
);
22195 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22196 SECTION_DEBUG
, NULL
);
22197 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22198 SECTION_DEBUG
, NULL
);
22199 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22200 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22202 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22203 the main .o, but the skeleton_line goes into the split off dwo. */
22204 debug_skeleton_line_section
22205 = get_section (DEBUG_DWO_LINE_SECTION
,
22206 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22207 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22208 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22209 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22210 SECTION_DEBUG
| SECTION_EXCLUDE
,
22212 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22213 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22214 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22215 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22216 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22217 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22219 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22220 SECTION_DEBUG
, NULL
);
22221 debug_macinfo_section
= get_section (dwarf_strict
22222 ? DEBUG_MACINFO_SECTION
22223 : DEBUG_MACRO_SECTION
,
22224 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22225 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22226 SECTION_DEBUG
, NULL
);
22227 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22228 SECTION_DEBUG
, NULL
);
22229 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22230 SECTION_DEBUG
, NULL
);
22231 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22232 DEBUG_STR_SECTION_FLAGS
, NULL
);
22233 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22234 SECTION_DEBUG
, NULL
);
22235 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22236 SECTION_DEBUG
, NULL
);
22238 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22239 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22240 DEBUG_ABBREV_SECTION_LABEL
, 0);
22241 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22242 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22243 COLD_TEXT_SECTION_LABEL
, 0);
22244 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22246 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22247 DEBUG_INFO_SECTION_LABEL
, 0);
22248 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22249 DEBUG_LINE_SECTION_LABEL
, 0);
22250 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22251 DEBUG_RANGES_SECTION_LABEL
, 0);
22252 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22253 DEBUG_ADDR_SECTION_LABEL
, 0);
22254 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22256 ? DEBUG_MACINFO_SECTION_LABEL
22257 : DEBUG_MACRO_SECTION_LABEL
, 0);
22258 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22260 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22261 vec_alloc (macinfo_table
, 64);
22263 switch_to_section (text_section
);
22264 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22266 /* Make sure the line number table for .text always exists. */
22267 text_section_line_info
= new_line_info_table ();
22268 text_section_line_info
->end_label
= text_end_label
;
22271 /* Called before compile () starts outputtting functions, variables
22272 and toplevel asms into assembly. */
22275 dwarf2out_assembly_start (void)
22277 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22278 && dwarf2out_do_cfi_asm ()
22279 && (!(flag_unwind_tables
|| flag_exceptions
)
22280 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22281 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22284 /* A helper function for dwarf2out_finish called through
22285 htab_traverse. Assign a string its index. All strings must be
22286 collected into the table by the time index_string is called,
22287 because the indexing code relies on htab_traverse to traverse nodes
22288 in the same order for each run. */
22291 index_string (void **h
, void *v
)
22293 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22294 unsigned int *index
= (unsigned int *) v
;
22296 find_string_form (node
);
22297 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22299 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22300 node
->index
= *index
;
22306 /* A helper function for output_indirect_strings called through
22307 htab_traverse. Output the offset to a string and update the
22311 output_index_string_offset (void **h
, void *v
)
22313 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22314 unsigned int *offset
= (unsigned int *) v
;
22316 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22318 /* Assert that this node has been assigned an index. */
22319 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22320 && node
->index
!= NOT_INDEXED
);
22321 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22322 "indexed string 0x%x: %s", node
->index
, node
->str
);
22323 *offset
+= strlen (node
->str
) + 1;
22328 /* A helper function for dwarf2out_finish called through
22329 htab_traverse. Output the indexed string. */
22332 output_index_string (void **h
, void *v
)
22334 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22335 unsigned int *cur_idx
= (unsigned int *) v
;
22337 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22339 /* Assert that the strings are output in the same order as their
22340 indexes were assigned. */
22341 gcc_assert (*cur_idx
== node
->index
);
22342 assemble_string (node
->str
, strlen (node
->str
) + 1);
22348 /* A helper function for dwarf2out_finish called through
22349 htab_traverse. Emit one queued .debug_str string. */
22352 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22354 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22356 node
->form
= find_string_form (node
);
22357 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22359 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22360 assemble_string (node
->str
, strlen (node
->str
) + 1);
22366 /* Output the indexed string table. */
22369 output_indirect_strings (void)
22371 switch_to_section (debug_str_section
);
22372 if (!dwarf_split_debug_info
)
22373 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22376 unsigned int offset
= 0;
22377 unsigned int cur_idx
= 0;
22379 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22381 switch_to_section (debug_str_offsets_section
);
22382 htab_traverse_noresize (debug_str_hash
,
22383 output_index_string_offset
,
22385 switch_to_section (debug_str_dwo_section
);
22386 htab_traverse_noresize (debug_str_hash
,
22387 output_index_string
,
22392 /* Callback for htab_traverse to assign an index to an entry in the
22393 table, and to write that entry to the .debug_addr section. */
22396 output_addr_table_entry (void **slot
, void *data
)
22398 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22399 unsigned int *cur_index
= (unsigned int *)data
;
22401 if (entry
->refcount
== 0)
22403 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22404 || entry
->index
== NOT_INDEXED
);
22408 gcc_assert (entry
->index
== *cur_index
);
22411 switch (entry
->kind
)
22414 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22415 "0x%x", entry
->index
);
22417 case ate_kind_rtx_dtprel
:
22418 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22419 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22422 fputc ('\n', asm_out_file
);
22424 case ate_kind_label
:
22425 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22426 "0x%x", entry
->index
);
22429 gcc_unreachable ();
22434 /* Produce the .debug_addr section. */
22437 output_addr_table (void)
22439 unsigned int index
= 0;
22440 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22443 switch_to_section (debug_addr_section
);
22444 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22447 #if ENABLE_ASSERT_CHECKING
22448 /* Verify that all marks are clear. */
22451 verify_marks_clear (dw_die_ref die
)
22455 gcc_assert (! die
->die_mark
);
22456 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22458 #endif /* ENABLE_ASSERT_CHECKING */
22460 /* Clear the marks for a die and its children.
22461 Be cool if the mark isn't set. */
22464 prune_unmark_dies (dw_die_ref die
)
22470 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22473 /* Given DIE that we're marking as used, find any other dies
22474 it references as attributes and mark them as used. */
22477 prune_unused_types_walk_attribs (dw_die_ref die
)
22482 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22484 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22486 /* A reference to another DIE.
22487 Make sure that it will get emitted.
22488 If it was broken out into a comdat group, don't follow it. */
22489 if (! AT_ref (a
)->comdat_type_p
22490 || a
->dw_attr
== DW_AT_specification
)
22491 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22493 /* Set the string's refcount to 0 so that prune_unused_types_mark
22494 accounts properly for it. */
22495 if (AT_class (a
) == dw_val_class_str
)
22496 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22500 /* Mark the generic parameters and arguments children DIEs of DIE. */
22503 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22507 if (die
== NULL
|| die
->die_child
== NULL
)
22509 c
= die
->die_child
;
22512 if (is_template_parameter (c
))
22513 prune_unused_types_mark (c
, 1);
22515 } while (c
&& c
!= die
->die_child
);
22518 /* Mark DIE as being used. If DOKIDS is true, then walk down
22519 to DIE's children. */
22522 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22526 if (die
->die_mark
== 0)
22528 /* We haven't done this node yet. Mark it as used. */
22530 /* If this is the DIE of a generic type instantiation,
22531 mark the children DIEs that describe its generic parms and
22533 prune_unused_types_mark_generic_parms_dies (die
);
22535 /* We also have to mark its parents as used.
22536 (But we don't want to mark our parent's kids due to this,
22537 unless it is a class.) */
22538 if (die
->die_parent
)
22539 prune_unused_types_mark (die
->die_parent
,
22540 class_scope_p (die
->die_parent
));
22542 /* Mark any referenced nodes. */
22543 prune_unused_types_walk_attribs (die
);
22545 /* If this node is a specification,
22546 also mark the definition, if it exists. */
22547 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22548 prune_unused_types_mark (die
->die_definition
, 1);
22551 if (dokids
&& die
->die_mark
!= 2)
22553 /* We need to walk the children, but haven't done so yet.
22554 Remember that we've walked the kids. */
22557 /* If this is an array type, we need to make sure our
22558 kids get marked, even if they're types. If we're
22559 breaking out types into comdat sections, do this
22560 for all type definitions. */
22561 if (die
->die_tag
== DW_TAG_array_type
22562 || (use_debug_types
22563 && is_type_die (die
) && ! is_declaration_die (die
)))
22564 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22566 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22570 /* For local classes, look if any static member functions were emitted
22571 and if so, mark them. */
22574 prune_unused_types_walk_local_classes (dw_die_ref die
)
22578 if (die
->die_mark
== 2)
22581 switch (die
->die_tag
)
22583 case DW_TAG_structure_type
:
22584 case DW_TAG_union_type
:
22585 case DW_TAG_class_type
:
22588 case DW_TAG_subprogram
:
22589 if (!get_AT_flag (die
, DW_AT_declaration
)
22590 || die
->die_definition
!= NULL
)
22591 prune_unused_types_mark (die
, 1);
22598 /* Mark children. */
22599 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22602 /* Walk the tree DIE and mark types that we actually use. */
22605 prune_unused_types_walk (dw_die_ref die
)
22609 /* Don't do anything if this node is already marked and
22610 children have been marked as well. */
22611 if (die
->die_mark
== 2)
22614 switch (die
->die_tag
)
22616 case DW_TAG_structure_type
:
22617 case DW_TAG_union_type
:
22618 case DW_TAG_class_type
:
22619 if (die
->die_perennial_p
)
22622 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22623 if (c
->die_tag
== DW_TAG_subprogram
)
22626 /* Finding used static member functions inside of classes
22627 is needed just for local classes, because for other classes
22628 static member function DIEs with DW_AT_specification
22629 are emitted outside of the DW_TAG_*_type. If we ever change
22630 it, we'd need to call this even for non-local classes. */
22632 prune_unused_types_walk_local_classes (die
);
22634 /* It's a type node --- don't mark it. */
22637 case DW_TAG_const_type
:
22638 case DW_TAG_packed_type
:
22639 case DW_TAG_pointer_type
:
22640 case DW_TAG_reference_type
:
22641 case DW_TAG_rvalue_reference_type
:
22642 case DW_TAG_volatile_type
:
22643 case DW_TAG_typedef
:
22644 case DW_TAG_array_type
:
22645 case DW_TAG_interface_type
:
22646 case DW_TAG_friend
:
22647 case DW_TAG_variant_part
:
22648 case DW_TAG_enumeration_type
:
22649 case DW_TAG_subroutine_type
:
22650 case DW_TAG_string_type
:
22651 case DW_TAG_set_type
:
22652 case DW_TAG_subrange_type
:
22653 case DW_TAG_ptr_to_member_type
:
22654 case DW_TAG_file_type
:
22655 if (die
->die_perennial_p
)
22658 /* It's a type node --- don't mark it. */
22662 /* Mark everything else. */
22666 if (die
->die_mark
== 0)
22670 /* Now, mark any dies referenced from here. */
22671 prune_unused_types_walk_attribs (die
);
22676 /* Mark children. */
22677 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22680 /* Increment the string counts on strings referred to from DIE's
22684 prune_unused_types_update_strings (dw_die_ref die
)
22689 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22690 if (AT_class (a
) == dw_val_class_str
)
22692 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22694 /* Avoid unnecessarily putting strings that are used less than
22695 twice in the hash table. */
22697 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22700 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22701 htab_hash_string (s
->str
),
22703 gcc_assert (*slot
== NULL
);
22709 /* Remove from the tree DIE any dies that aren't marked. */
22712 prune_unused_types_prune (dw_die_ref die
)
22716 gcc_assert (die
->die_mark
);
22717 prune_unused_types_update_strings (die
);
22719 if (! die
->die_child
)
22722 c
= die
->die_child
;
22724 dw_die_ref prev
= c
;
22725 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22726 if (c
== die
->die_child
)
22728 /* No marked children between 'prev' and the end of the list. */
22730 /* No marked children at all. */
22731 die
->die_child
= NULL
;
22734 prev
->die_sib
= c
->die_sib
;
22735 die
->die_child
= prev
;
22740 if (c
!= prev
->die_sib
)
22742 prune_unused_types_prune (c
);
22743 } while (c
!= die
->die_child
);
22746 /* Remove dies representing declarations that we never use. */
22749 prune_unused_types (void)
22752 limbo_die_node
*node
;
22753 comdat_type_node
*ctnode
;
22755 dw_die_ref base_type
;
22757 #if ENABLE_ASSERT_CHECKING
22758 /* All the marks should already be clear. */
22759 verify_marks_clear (comp_unit_die ());
22760 for (node
= limbo_die_list
; node
; node
= node
->next
)
22761 verify_marks_clear (node
->die
);
22762 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22763 verify_marks_clear (ctnode
->root_die
);
22764 #endif /* ENABLE_ASSERT_CHECKING */
22766 /* Mark types that are used in global variables. */
22767 premark_types_used_by_global_vars ();
22769 /* Set the mark on nodes that are actually used. */
22770 prune_unused_types_walk (comp_unit_die ());
22771 for (node
= limbo_die_list
; node
; node
= node
->next
)
22772 prune_unused_types_walk (node
->die
);
22773 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22775 prune_unused_types_walk (ctnode
->root_die
);
22776 prune_unused_types_mark (ctnode
->type_die
, 1);
22779 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22780 are unusual in that they are pubnames that are the children of pubtypes.
22781 They should only be marked via their parent DW_TAG_enumeration_type die,
22782 not as roots in themselves. */
22783 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22784 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22785 prune_unused_types_mark (pub
->die
, 1);
22786 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22787 prune_unused_types_mark (base_type
, 1);
22789 if (debug_str_hash
)
22790 htab_empty (debug_str_hash
);
22791 if (skeleton_debug_str_hash
)
22792 htab_empty (skeleton_debug_str_hash
);
22793 prune_unused_types_prune (comp_unit_die ());
22794 for (node
= limbo_die_list
; node
; node
= node
->next
)
22795 prune_unused_types_prune (node
->die
);
22796 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22797 prune_unused_types_prune (ctnode
->root_die
);
22799 /* Leave the marks clear. */
22800 prune_unmark_dies (comp_unit_die ());
22801 for (node
= limbo_die_list
; node
; node
= node
->next
)
22802 prune_unmark_dies (node
->die
);
22803 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22804 prune_unmark_dies (ctnode
->root_die
);
22807 /* Set the parameter to true if there are any relative pathnames in
22810 file_table_relative_p (void ** slot
, void *param
)
22812 bool *p
= (bool *) param
;
22813 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22814 if (!IS_ABSOLUTE_PATH (d
->filename
))
22822 /* Helpers to manipulate hash table of comdat type units. */
22824 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22826 typedef comdat_type_node value_type
;
22827 typedef comdat_type_node compare_type
;
22828 static inline hashval_t
hash (const value_type
*);
22829 static inline bool equal (const value_type
*, const compare_type
*);
22833 comdat_type_hasher::hash (const value_type
*type_node
)
22836 memcpy (&h
, type_node
->signature
, sizeof (h
));
22841 comdat_type_hasher::equal (const value_type
*type_node_1
,
22842 const compare_type
*type_node_2
)
22844 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22845 DWARF_TYPE_SIGNATURE_SIZE
));
22848 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22849 to the location it would have been added, should we know its
22850 DECL_ASSEMBLER_NAME when we added other attributes. This will
22851 probably improve compactness of debug info, removing equivalent
22852 abbrevs, and hide any differences caused by deferring the
22853 computation of the assembler name, triggered by e.g. PCH. */
22856 move_linkage_attr (dw_die_ref die
)
22858 unsigned ix
= vec_safe_length (die
->die_attr
);
22859 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22861 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22862 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22866 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22868 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22872 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22874 die
->die_attr
->pop ();
22875 die
->die_attr
->quick_insert (ix
, linkage
);
22879 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22880 referenced from typed stack ops and count how often they are used. */
22883 mark_base_types (dw_loc_descr_ref loc
)
22885 dw_die_ref base_type
= NULL
;
22887 for (; loc
; loc
= loc
->dw_loc_next
)
22889 switch (loc
->dw_loc_opc
)
22891 case DW_OP_GNU_regval_type
:
22892 case DW_OP_GNU_deref_type
:
22893 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22895 case DW_OP_GNU_convert
:
22896 case DW_OP_GNU_reinterpret
:
22897 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22900 case DW_OP_GNU_const_type
:
22901 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22903 case DW_OP_GNU_entry_value
:
22904 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22909 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22910 if (base_type
->die_mark
)
22911 base_type
->die_mark
++;
22914 base_types
.safe_push (base_type
);
22915 base_type
->die_mark
= 1;
22920 /* Comparison function for sorting marked base types. */
22923 base_type_cmp (const void *x
, const void *y
)
22925 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22926 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22927 unsigned int byte_size1
, byte_size2
;
22928 unsigned int encoding1
, encoding2
;
22929 if (dx
->die_mark
> dy
->die_mark
)
22931 if (dx
->die_mark
< dy
->die_mark
)
22933 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22934 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22935 if (byte_size1
< byte_size2
)
22937 if (byte_size1
> byte_size2
)
22939 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22940 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22941 if (encoding1
< encoding2
)
22943 if (encoding1
> encoding2
)
22948 /* Move base types marked by mark_base_types as early as possible
22949 in the CU, sorted by decreasing usage count both to make the
22950 uleb128 references as small as possible and to make sure they
22951 will have die_offset already computed by calc_die_sizes when
22952 sizes of typed stack loc ops is computed. */
22955 move_marked_base_types (void)
22958 dw_die_ref base_type
, die
, c
;
22960 if (base_types
.is_empty ())
22963 /* Sort by decreasing usage count, they will be added again in that
22965 base_types
.qsort (base_type_cmp
);
22966 die
= comp_unit_die ();
22967 c
= die
->die_child
;
22970 dw_die_ref prev
= c
;
22972 while (c
->die_mark
)
22974 remove_child_with_prev (c
, prev
);
22975 /* As base types got marked, there must be at least
22976 one node other than DW_TAG_base_type. */
22977 gcc_assert (c
!= c
->die_sib
);
22981 while (c
!= die
->die_child
);
22982 gcc_assert (die
->die_child
);
22983 c
= die
->die_child
;
22984 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22986 base_type
->die_mark
= 0;
22987 base_type
->die_sib
= c
->die_sib
;
22988 c
->die_sib
= base_type
;
22993 /* Helper function for resolve_addr, attempt to resolve
22994 one CONST_STRING, return non-zero if not successful. Similarly verify that
22995 SYMBOL_REFs refer to variables emitted in the current CU. */
22998 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
23002 if (GET_CODE (rtl
) == CONST_STRING
)
23004 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23005 tree t
= build_string (len
, XSTR (rtl
, 0));
23006 tree tlen
= size_int (len
- 1);
23008 = build_array_type (char_type_node
, build_index_type (tlen
));
23009 rtl
= lookup_constant_def (t
);
23010 if (!rtl
|| !MEM_P (rtl
))
23012 rtl
= XEXP (rtl
, 0);
23013 if (GET_CODE (rtl
) == SYMBOL_REF
23014 && SYMBOL_REF_DECL (rtl
)
23015 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23017 vec_safe_push (used_rtx_array
, rtl
);
23022 if (GET_CODE (rtl
) == SYMBOL_REF
23023 && SYMBOL_REF_DECL (rtl
))
23025 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
23027 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
23030 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23034 if (GET_CODE (rtl
) == CONST
23035 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
23041 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
23042 if possible, and create DW_TAG_dwarf_procedure that can be referenced
23043 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
23046 string_cst_pool_decl (tree t
)
23048 rtx rtl
= output_constant_def (t
, 1);
23049 unsigned char *array
;
23050 dw_loc_descr_ref l
;
23055 if (!rtl
|| !MEM_P (rtl
))
23057 rtl
= XEXP (rtl
, 0);
23058 if (GET_CODE (rtl
) != SYMBOL_REF
23059 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
23062 decl
= SYMBOL_REF_DECL (rtl
);
23063 if (!lookup_decl_die (decl
))
23065 len
= TREE_STRING_LENGTH (t
);
23066 vec_safe_push (used_rtx_array
, rtl
);
23067 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
23068 array
= (unsigned char *) ggc_alloc_atomic (len
);
23069 memcpy (array
, TREE_STRING_POINTER (t
), len
);
23070 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
23071 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
23072 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
23073 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
23074 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
23075 add_AT_loc (ref
, DW_AT_location
, l
);
23076 equate_decl_number_to_die (decl
, ref
);
23081 /* Helper function of resolve_addr_in_expr. LOC is
23082 a DW_OP_addr followed by DW_OP_stack_value, either at the start
23083 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
23084 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
23085 with DW_OP_GNU_implicit_pointer if possible
23086 and return true, if unsuccessful, return false. */
23089 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
23091 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
23092 HOST_WIDE_INT offset
= 0;
23093 dw_die_ref ref
= NULL
;
23096 if (GET_CODE (rtl
) == CONST
23097 && GET_CODE (XEXP (rtl
, 0)) == PLUS
23098 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
23100 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
23101 rtl
= XEXP (XEXP (rtl
, 0), 0);
23103 if (GET_CODE (rtl
) == CONST_STRING
)
23105 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23106 tree t
= build_string (len
, XSTR (rtl
, 0));
23107 tree tlen
= size_int (len
- 1);
23110 = build_array_type (char_type_node
, build_index_type (tlen
));
23111 rtl
= string_cst_pool_decl (t
);
23115 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
23117 decl
= SYMBOL_REF_DECL (rtl
);
23118 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
23120 ref
= lookup_decl_die (decl
);
23121 if (ref
&& (get_AT (ref
, DW_AT_location
)
23122 || get_AT (ref
, DW_AT_const_value
)))
23124 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
23125 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23126 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
23127 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23128 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23129 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23130 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
23138 /* Helper function for resolve_addr, handle one location
23139 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23140 the location list couldn't be resolved. */
23143 resolve_addr_in_expr (dw_loc_descr_ref loc
)
23145 dw_loc_descr_ref keep
= NULL
;
23146 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
23147 switch (loc
->dw_loc_opc
)
23150 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23153 || prev
->dw_loc_opc
== DW_OP_piece
23154 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
23155 && loc
->dw_loc_next
23156 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
23158 && optimize_one_addr_into_implicit_ptr (loc
))
23163 case DW_OP_GNU_addr_index
:
23164 case DW_OP_GNU_const_index
:
23165 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
23166 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
23167 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
23171 case DW_OP_const4u
:
23172 case DW_OP_const8u
:
23174 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23177 case DW_OP_plus_uconst
:
23178 if (size_of_loc_descr (loc
)
23179 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
23181 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
23183 dw_loc_descr_ref repl
23184 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
23185 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23186 add_loc_descr (&repl
, loc
->dw_loc_next
);
23190 case DW_OP_implicit_value
:
23191 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23192 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
23195 case DW_OP_GNU_implicit_pointer
:
23196 case DW_OP_GNU_parameter_ref
:
23197 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23200 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23203 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23204 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23205 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23208 case DW_OP_GNU_const_type
:
23209 case DW_OP_GNU_regval_type
:
23210 case DW_OP_GNU_deref_type
:
23211 case DW_OP_GNU_convert
:
23212 case DW_OP_GNU_reinterpret
:
23213 while (loc
->dw_loc_next
23214 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23216 dw_die_ref base1
, base2
;
23217 unsigned enc1
, enc2
, size1
, size2
;
23218 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23219 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23220 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23221 else if (loc
->dw_loc_oprnd1
.val_class
23222 == dw_val_class_unsigned_const
)
23225 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23226 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23227 == dw_val_class_unsigned_const
)
23229 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23230 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23231 && base2
->die_tag
== DW_TAG_base_type
);
23232 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23233 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23234 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23235 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23237 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23238 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23242 /* Optimize away next DW_OP_GNU_convert after
23243 adjusting LOC's base type die reference. */
23244 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23245 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23246 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23248 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23249 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23252 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23253 point typed stack entry. */
23254 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23255 keep
= loc
->dw_loc_next
;
23265 /* Helper function of resolve_addr. DIE had DW_AT_location of
23266 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23267 and DW_OP_addr couldn't be resolved. resolve_addr has already
23268 removed the DW_AT_location attribute. This function attempts to
23269 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23270 to it or DW_AT_const_value attribute, if possible. */
23273 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23275 if (TREE_CODE (decl
) != VAR_DECL
23276 || lookup_decl_die (decl
) != die
23277 || DECL_EXTERNAL (decl
)
23278 || !TREE_STATIC (decl
)
23279 || DECL_INITIAL (decl
) == NULL_TREE
23280 || DECL_P (DECL_INITIAL (decl
))
23281 || get_AT (die
, DW_AT_const_value
))
23284 tree init
= DECL_INITIAL (decl
);
23285 HOST_WIDE_INT offset
= 0;
23286 /* For variables that have been optimized away and thus
23287 don't have a memory location, see if we can emit
23288 DW_AT_const_value instead. */
23289 if (tree_add_const_value_attribute (die
, init
))
23293 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23294 and ADDR_EXPR refers to a decl that has DW_AT_location or
23295 DW_AT_const_value (but isn't addressable, otherwise
23296 resolving the original DW_OP_addr wouldn't fail), see if
23297 we can add DW_OP_GNU_implicit_pointer. */
23299 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23300 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
23302 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
23303 init
= TREE_OPERAND (init
, 0);
23306 if (TREE_CODE (init
) != ADDR_EXPR
)
23308 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23309 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23310 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23311 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23312 && TREE_OPERAND (init
, 0) != decl
))
23315 dw_loc_descr_ref l
;
23317 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23319 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23322 decl
= SYMBOL_REF_DECL (rtl
);
23325 decl
= TREE_OPERAND (init
, 0);
23326 ref
= lookup_decl_die (decl
);
23328 || (!get_AT (ref
, DW_AT_location
)
23329 && !get_AT (ref
, DW_AT_const_value
)))
23331 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23332 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23333 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23334 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23335 add_AT_loc (die
, DW_AT_location
, l
);
23339 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23340 an address in .rodata section if the string literal is emitted there,
23341 or remove the containing location list or replace DW_AT_const_value
23342 with DW_AT_location and empty location expression, if it isn't found
23343 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23344 to something that has been emitted in the current CU. */
23347 resolve_addr (dw_die_ref die
)
23351 dw_loc_list_ref
*curr
, *start
, loc
;
23354 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23355 switch (AT_class (a
))
23357 case dw_val_class_loc_list
:
23358 start
= curr
= AT_loc_list_ptr (a
);
23361 /* The same list can be referenced more than once. See if we have
23362 already recorded the result from a previous pass. */
23364 *curr
= loc
->dw_loc_next
;
23365 else if (!loc
->resolved_addr
)
23367 /* As things stand, we do not expect or allow one die to
23368 reference a suffix of another die's location list chain.
23369 References must be identical or completely separate.
23370 There is therefore no need to cache the result of this
23371 pass on any list other than the first; doing so
23372 would lead to unnecessary writes. */
23375 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23376 if (!resolve_addr_in_expr ((*curr
)->expr
))
23378 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23379 dw_loc_descr_ref l
= (*curr
)->expr
;
23381 if (next
&& (*curr
)->ll_symbol
)
23383 gcc_assert (!next
->ll_symbol
);
23384 next
->ll_symbol
= (*curr
)->ll_symbol
;
23386 if (dwarf_split_debug_info
)
23387 remove_loc_list_addr_table_entries (l
);
23392 mark_base_types ((*curr
)->expr
);
23393 curr
= &(*curr
)->dw_loc_next
;
23397 loc
->resolved_addr
= 1;
23401 loc
->dw_loc_next
= *start
;
23406 remove_AT (die
, a
->dw_attr
);
23410 case dw_val_class_loc
:
23412 dw_loc_descr_ref l
= AT_loc (a
);
23413 /* For -gdwarf-2 don't attempt to optimize
23414 DW_AT_data_member_location containing
23415 DW_OP_plus_uconst - older consumers might
23416 rely on it being that op instead of a more complex,
23417 but shorter, location description. */
23418 if ((dwarf_version
> 2
23419 || a
->dw_attr
!= DW_AT_data_member_location
23421 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23422 || l
->dw_loc_next
!= NULL
)
23423 && !resolve_addr_in_expr (l
))
23425 if (dwarf_split_debug_info
)
23426 remove_loc_list_addr_table_entries (l
);
23428 && l
->dw_loc_next
== NULL
23429 && l
->dw_loc_opc
== DW_OP_addr
23430 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23431 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23432 && a
->dw_attr
== DW_AT_location
)
23434 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23435 remove_AT (die
, a
->dw_attr
);
23437 optimize_location_into_implicit_ptr (die
, decl
);
23440 remove_AT (die
, a
->dw_attr
);
23444 mark_base_types (l
);
23447 case dw_val_class_addr
:
23448 if (a
->dw_attr
== DW_AT_const_value
23449 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23451 if (AT_index (a
) != NOT_INDEXED
)
23452 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23453 remove_AT (die
, a
->dw_attr
);
23456 if (die
->die_tag
== DW_TAG_GNU_call_site
23457 && a
->dw_attr
== DW_AT_abstract_origin
)
23459 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23460 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23462 && DECL_EXTERNAL (tdecl
)
23463 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23465 force_decl_die (tdecl
);
23466 tdie
= lookup_decl_die (tdecl
);
23470 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23471 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23472 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23476 if (AT_index (a
) != NOT_INDEXED
)
23477 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23478 remove_AT (die
, a
->dw_attr
);
23487 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23490 /* Helper routines for optimize_location_lists.
23491 This pass tries to share identical local lists in .debug_loc
23494 /* Iteratively hash operands of LOC opcode. */
23497 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23499 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23500 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23502 switch (loc
->dw_loc_opc
)
23504 case DW_OP_const4u
:
23505 case DW_OP_const8u
:
23509 case DW_OP_const1u
:
23510 case DW_OP_const1s
:
23511 case DW_OP_const2u
:
23512 case DW_OP_const2s
:
23513 case DW_OP_const4s
:
23514 case DW_OP_const8s
:
23518 case DW_OP_plus_uconst
:
23554 case DW_OP_deref_size
:
23555 case DW_OP_xderef_size
:
23556 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23563 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23564 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23565 hash
= iterative_hash_object (offset
, hash
);
23568 case DW_OP_implicit_value
:
23569 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23570 switch (val2
->val_class
)
23572 case dw_val_class_const
:
23573 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23575 case dw_val_class_vec
:
23577 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23578 unsigned int len
= val2
->v
.val_vec
.length
;
23580 hash
= iterative_hash_object (elt_size
, hash
);
23581 hash
= iterative_hash_object (len
, hash
);
23582 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23583 len
* elt_size
, hash
);
23586 case dw_val_class_const_double
:
23587 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23588 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23590 case dw_val_class_wide_int
:
23591 hash
= iterative_hash_object (*val2
->v
.val_wide
, hash
);
23593 case dw_val_class_addr
:
23594 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23597 gcc_unreachable ();
23601 case DW_OP_bit_piece
:
23602 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23603 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23609 unsigned char dtprel
= 0xd1;
23610 hash
= iterative_hash_object (dtprel
, hash
);
23612 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23614 case DW_OP_GNU_addr_index
:
23615 case DW_OP_GNU_const_index
:
23619 unsigned char dtprel
= 0xd1;
23620 hash
= iterative_hash_object (dtprel
, hash
);
23622 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23625 case DW_OP_GNU_implicit_pointer
:
23626 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23628 case DW_OP_GNU_entry_value
:
23629 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23631 case DW_OP_GNU_regval_type
:
23632 case DW_OP_GNU_deref_type
:
23634 unsigned int byte_size
23635 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23636 unsigned int encoding
23637 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23638 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23639 hash
= iterative_hash_object (byte_size
, hash
);
23640 hash
= iterative_hash_object (encoding
, hash
);
23643 case DW_OP_GNU_convert
:
23644 case DW_OP_GNU_reinterpret
:
23645 if (val1
->val_class
== dw_val_class_unsigned_const
)
23647 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23651 case DW_OP_GNU_const_type
:
23653 unsigned int byte_size
23654 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23655 unsigned int encoding
23656 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23657 hash
= iterative_hash_object (byte_size
, hash
);
23658 hash
= iterative_hash_object (encoding
, hash
);
23659 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23661 hash
= iterative_hash_object (val2
->val_class
, hash
);
23662 switch (val2
->val_class
)
23664 case dw_val_class_const
:
23665 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23667 case dw_val_class_vec
:
23669 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23670 unsigned int len
= val2
->v
.val_vec
.length
;
23672 hash
= iterative_hash_object (elt_size
, hash
);
23673 hash
= iterative_hash_object (len
, hash
);
23674 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23675 len
* elt_size
, hash
);
23678 case dw_val_class_const_double
:
23679 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23680 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23682 case dw_val_class_wide_int
:
23683 hash
= iterative_hash_object (*val2
->v
.val_wide
, hash
);
23686 gcc_unreachable ();
23692 /* Other codes have no operands. */
23698 /* Iteratively hash the whole DWARF location expression LOC. */
23700 static inline hashval_t
23701 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23703 dw_loc_descr_ref l
;
23704 bool sizes_computed
= false;
23705 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23706 size_of_locs (loc
);
23708 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23710 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23711 hash
= iterative_hash_object (opc
, hash
);
23712 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23714 size_of_locs (loc
);
23715 sizes_computed
= true;
23717 hash
= hash_loc_operands (l
, hash
);
23722 /* Compute hash of the whole location list LIST_HEAD. */
23725 hash_loc_list (dw_loc_list_ref list_head
)
23727 dw_loc_list_ref curr
= list_head
;
23728 hashval_t hash
= 0;
23730 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23732 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23733 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23735 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23737 hash
= hash_locs (curr
->expr
, hash
);
23739 list_head
->hash
= hash
;
23742 /* Return true if X and Y opcodes have the same operands. */
23745 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23747 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23748 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23749 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23750 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23752 switch (x
->dw_loc_opc
)
23754 case DW_OP_const4u
:
23755 case DW_OP_const8u
:
23759 case DW_OP_const1u
:
23760 case DW_OP_const1s
:
23761 case DW_OP_const2u
:
23762 case DW_OP_const2s
:
23763 case DW_OP_const4s
:
23764 case DW_OP_const8s
:
23768 case DW_OP_plus_uconst
:
23804 case DW_OP_deref_size
:
23805 case DW_OP_xderef_size
:
23806 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23809 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23810 can cause irrelevant differences in dw_loc_addr. */
23811 gcc_assert (valx1
->val_class
== dw_val_class_loc
23812 && valy1
->val_class
== dw_val_class_loc
23813 && (dwarf_split_debug_info
23814 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23815 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23816 case DW_OP_implicit_value
:
23817 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23818 || valx2
->val_class
!= valy2
->val_class
)
23820 switch (valx2
->val_class
)
23822 case dw_val_class_const
:
23823 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23824 case dw_val_class_vec
:
23825 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23826 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23827 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23828 valx2
->v
.val_vec
.elt_size
23829 * valx2
->v
.val_vec
.length
) == 0;
23830 case dw_val_class_const_double
:
23831 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23832 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23833 case dw_val_class_wide_int
:
23834 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
23835 case dw_val_class_addr
:
23836 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23838 gcc_unreachable ();
23841 case DW_OP_bit_piece
:
23842 return valx1
->v
.val_int
== valy1
->v
.val_int
23843 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23846 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23847 case DW_OP_GNU_addr_index
:
23848 case DW_OP_GNU_const_index
:
23850 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23851 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23852 return rtx_equal_p (ax1
, ay1
);
23854 case DW_OP_GNU_implicit_pointer
:
23855 return valx1
->val_class
== dw_val_class_die_ref
23856 && valx1
->val_class
== valy1
->val_class
23857 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23858 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23859 case DW_OP_GNU_entry_value
:
23860 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23861 case DW_OP_GNU_const_type
:
23862 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23863 || valx2
->val_class
!= valy2
->val_class
)
23865 switch (valx2
->val_class
)
23867 case dw_val_class_const
:
23868 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23869 case dw_val_class_vec
:
23870 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23871 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23872 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23873 valx2
->v
.val_vec
.elt_size
23874 * valx2
->v
.val_vec
.length
) == 0;
23875 case dw_val_class_const_double
:
23876 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23877 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23878 case dw_val_class_wide_int
:
23879 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
23881 gcc_unreachable ();
23883 case DW_OP_GNU_regval_type
:
23884 case DW_OP_GNU_deref_type
:
23885 return valx1
->v
.val_int
== valy1
->v
.val_int
23886 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23887 case DW_OP_GNU_convert
:
23888 case DW_OP_GNU_reinterpret
:
23889 if (valx1
->val_class
!= valy1
->val_class
)
23891 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23892 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23893 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23894 case DW_OP_GNU_parameter_ref
:
23895 return valx1
->val_class
== dw_val_class_die_ref
23896 && valx1
->val_class
== valy1
->val_class
23897 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23899 /* Other codes have no operands. */
23904 /* Return true if DWARF location expressions X and Y are the same. */
23907 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23909 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23910 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23911 || x
->dtprel
!= y
->dtprel
23912 || !compare_loc_operands (x
, y
))
23914 return x
== NULL
&& y
== NULL
;
23917 /* Hashtable helpers. */
23919 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23921 typedef dw_loc_list_struct value_type
;
23922 typedef dw_loc_list_struct compare_type
;
23923 static inline hashval_t
hash (const value_type
*);
23924 static inline bool equal (const value_type
*, const compare_type
*);
23927 /* Return precomputed hash of location list X. */
23930 loc_list_hasher::hash (const value_type
*x
)
23935 /* Return true if location lists A and B are the same. */
23938 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23942 if (a
->hash
!= b
->hash
)
23944 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23945 if (strcmp (a
->begin
, b
->begin
) != 0
23946 || strcmp (a
->end
, b
->end
) != 0
23947 || (a
->section
== NULL
) != (b
->section
== NULL
)
23948 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23949 || !compare_locs (a
->expr
, b
->expr
))
23951 return a
== NULL
&& b
== NULL
;
23954 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23957 /* Recursively optimize location lists referenced from DIE
23958 children and share them whenever possible. */
23961 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23966 dw_loc_list_struct
**slot
;
23968 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23969 if (AT_class (a
) == dw_val_class_loc_list
)
23971 dw_loc_list_ref list
= AT_loc_list (a
);
23972 /* TODO: perform some optimizations here, before hashing
23973 it and storing into the hash table. */
23974 hash_loc_list (list
);
23975 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23979 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23982 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23986 /* Recursively assign each location list a unique index into the debug_addr
23990 index_location_lists (dw_die_ref die
)
23996 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23997 if (AT_class (a
) == dw_val_class_loc_list
)
23999 dw_loc_list_ref list
= AT_loc_list (a
);
24000 dw_loc_list_ref curr
;
24001 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24003 /* Don't index an entry that has already been indexed
24004 or won't be output. */
24005 if (curr
->begin_entry
!= NULL
24006 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
24010 = add_addr_table_entry (xstrdup (curr
->begin
),
24015 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
24018 /* Optimize location lists referenced from DIE
24019 children and share them whenever possible. */
24022 optimize_location_lists (dw_die_ref die
)
24024 loc_list_hash_type htab
;
24026 optimize_location_lists_1 (die
, htab
);
24030 /* Output stuff that dwarf requires at the end of every file,
24031 and generate the DWARF-2 debugging info. */
24034 dwarf2out_finish (const char *filename
)
24036 limbo_die_node
*node
, *next_node
;
24037 comdat_type_node
*ctnode
;
24038 hash_table
<comdat_type_hasher
> comdat_type_table
;
24040 dw_die_ref main_comp_unit_die
;
24042 /* PCH might result in DW_AT_producer string being restored from the
24043 header compilation, so always fill it with empty string initially
24044 and overwrite only here. */
24045 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
24046 producer_string
= gen_producer_string ();
24047 producer
->dw_attr_val
.v
.val_str
->refcount
--;
24048 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
24050 gen_scheduled_generic_parms_dies ();
24051 gen_remaining_tmpl_value_param_die_attribute ();
24053 /* Add the name for the main input file now. We delayed this from
24054 dwarf2out_init to avoid complications with PCH. */
24055 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
24056 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
24057 add_comp_dir_attribute (comp_unit_die ());
24058 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
24061 htab_traverse (file_table
, file_table_relative_p
, &p
);
24063 add_comp_dir_attribute (comp_unit_die ());
24066 if (deferred_locations_list
)
24067 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
24069 add_location_or_const_value_attribute (
24070 (*deferred_locations_list
)[i
].die
,
24071 (*deferred_locations_list
)[i
].variable
,
24076 /* Traverse the limbo die list, and add parent/child links. The only
24077 dies without parents that should be here are concrete instances of
24078 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
24079 For concrete instances, we can get the parent die from the abstract
24081 for (node
= limbo_die_list
; node
; node
= next_node
)
24083 dw_die_ref die
= node
->die
;
24084 next_node
= node
->next
;
24086 if (die
->die_parent
== NULL
)
24088 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
24090 if (origin
&& origin
->die_parent
)
24091 add_child_die (origin
->die_parent
, die
);
24092 else if (is_cu_die (die
))
24094 else if (seen_error ())
24095 /* It's OK to be confused by errors in the input. */
24096 add_child_die (comp_unit_die (), die
);
24099 /* In certain situations, the lexical block containing a
24100 nested function can be optimized away, which results
24101 in the nested function die being orphaned. Likewise
24102 with the return type of that nested function. Force
24103 this to be a child of the containing function.
24105 It may happen that even the containing function got fully
24106 inlined and optimized out. In that case we are lost and
24107 assign the empty child. This should not be big issue as
24108 the function is likely unreachable too. */
24109 gcc_assert (node
->created_for
);
24111 if (DECL_P (node
->created_for
))
24112 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
24113 else if (TYPE_P (node
->created_for
))
24114 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
24116 origin
= comp_unit_die ();
24118 add_child_die (origin
, die
);
24123 limbo_die_list
= NULL
;
24125 #if ENABLE_ASSERT_CHECKING
24127 dw_die_ref die
= comp_unit_die (), c
;
24128 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
24131 resolve_addr (comp_unit_die ());
24132 move_marked_base_types ();
24134 for (node
= deferred_asm_name
; node
; node
= node
->next
)
24136 tree decl
= node
->created_for
;
24137 /* When generating LTO bytecode we can not generate new assembler
24138 names at this point and all important decls got theirs via
24140 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
24141 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
24143 add_linkage_attr (node
->die
, decl
);
24144 move_linkage_attr (node
->die
);
24148 deferred_asm_name
= NULL
;
24150 /* Walk through the list of incomplete types again, trying once more to
24151 emit full debugging info for them. */
24152 retry_incomplete_types ();
24154 if (flag_eliminate_unused_debug_types
)
24155 prune_unused_types ();
24157 /* Generate separate COMDAT sections for type DIEs. */
24158 if (use_debug_types
)
24160 break_out_comdat_types (comp_unit_die ());
24162 /* Each new type_unit DIE was added to the limbo die list when created.
24163 Since these have all been added to comdat_type_list, clear the
24165 limbo_die_list
= NULL
;
24167 /* For each new comdat type unit, copy declarations for incomplete
24168 types to make the new unit self-contained (i.e., no direct
24169 references to the main compile unit). */
24170 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24171 copy_decls_for_unworthy_types (ctnode
->root_die
);
24172 copy_decls_for_unworthy_types (comp_unit_die ());
24174 /* In the process of copying declarations from one unit to another,
24175 we may have left some declarations behind that are no longer
24176 referenced. Prune them. */
24177 prune_unused_types ();
24180 /* Generate separate CUs for each of the include files we've seen.
24181 They will go into limbo_die_list. */
24182 if (flag_eliminate_dwarf2_dups
)
24183 break_out_includes (comp_unit_die ());
24185 /* Traverse the DIE's and add add sibling attributes to those DIE's
24186 that have children. */
24187 add_sibling_attributes (comp_unit_die ());
24188 for (node
= limbo_die_list
; node
; node
= node
->next
)
24189 add_sibling_attributes (node
->die
);
24190 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24191 add_sibling_attributes (ctnode
->root_die
);
24193 /* When splitting DWARF info, we put some attributes in the
24194 skeleton compile_unit DIE that remains in the .o, while
24195 most attributes go in the DWO compile_unit_die. */
24196 if (dwarf_split_debug_info
)
24197 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24199 main_comp_unit_die
= comp_unit_die ();
24201 /* Output a terminator label for the .text section. */
24202 switch_to_section (text_section
);
24203 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24204 if (cold_text_section
)
24206 switch_to_section (cold_text_section
);
24207 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24210 /* We can only use the low/high_pc attributes if all of the code was
24212 if (!have_multiple_function_sections
24213 || (dwarf_version
< 3 && dwarf_strict
))
24215 /* Don't add if the CU has no associated code. */
24216 if (text_section_used
)
24217 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24218 text_end_label
, true);
24224 bool range_list_added
= false;
24226 if (text_section_used
)
24227 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24228 text_end_label
, &range_list_added
, true);
24229 if (cold_text_section_used
)
24230 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24231 cold_end_label
, &range_list_added
, true);
24233 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24235 if (DECL_IGNORED_P (fde
->decl
))
24237 if (!fde
->in_std_section
)
24238 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24239 fde
->dw_fde_end
, &range_list_added
,
24241 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24242 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24243 fde
->dw_fde_second_end
, &range_list_added
,
24247 if (range_list_added
)
24249 /* We need to give .debug_loc and .debug_ranges an appropriate
24250 "base address". Use zero so that these addresses become
24251 absolute. Historically, we've emitted the unexpected
24252 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24253 Emit both to give time for other tools to adapt. */
24254 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24255 if (! dwarf_strict
&& dwarf_version
< 4)
24256 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24262 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24263 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24264 debug_line_section_label
);
24267 add_AT_macptr (comp_unit_die (),
24268 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24269 macinfo_section_label
);
24271 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
24273 /* optimize_location_lists calculates the size of the lists,
24274 so index them first, and assign indices to the entries.
24275 Although optimize_location_lists will remove entries from
24276 the table, it only does so for duplicates, and therefore
24277 only reduces ref_counts to 1. */
24278 unsigned int index
= 0;
24279 index_location_lists (comp_unit_die ());
24280 htab_traverse_noresize (addr_index_table
,
24281 index_addr_table_entry
, &index
);
24283 if (have_location_lists
)
24284 optimize_location_lists (comp_unit_die ());
24286 save_macinfo_strings ();
24288 if (dwarf_split_debug_info
)
24290 unsigned int index
= 0;
24292 /* Add attributes common to skeleton compile_units and
24293 type_units. Because these attributes include strings, it
24294 must be done before freezing the string table. Top-level
24295 skeleton die attrs are added when the skeleton type unit is
24296 created, so ensure it is created by this point. */
24297 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24298 (void) get_skeleton_type_unit ();
24299 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24302 /* Output all of the compilation units. We put the main one last so that
24303 the offsets are available to output_pubnames. */
24304 for (node
= limbo_die_list
; node
; node
= node
->next
)
24305 output_comp_unit (node
->die
, 0);
24307 comdat_type_table
.create (100);
24308 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24310 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24312 /* Don't output duplicate types. */
24313 if (*slot
!= HTAB_EMPTY_ENTRY
)
24316 /* Add a pointer to the line table for the main compilation unit
24317 so that the debugger can make sense of DW_AT_decl_file
24319 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24320 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24321 (!dwarf_split_debug_info
24322 ? debug_line_section_label
24323 : debug_skeleton_line_section_label
));
24325 output_comdat_type_unit (ctnode
);
24328 comdat_type_table
.dispose ();
24330 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24331 both the main_cu and all skeleton TUs. Making this call unconditional
24332 would end up either adding a second copy of the AT_pubnames attribute, or
24333 requiring a special case in add_top_level_skeleton_die_attrs. */
24334 if (!dwarf_split_debug_info
)
24335 add_AT_pubnames (comp_unit_die ());
24337 if (dwarf_split_debug_info
)
24340 unsigned char checksum
[16];
24341 struct md5_ctx ctx
;
24343 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24344 md5_init_ctx (&ctx
);
24346 die_checksum (comp_unit_die (), &ctx
, &mark
);
24347 unmark_all_dies (comp_unit_die ());
24348 md5_finish_ctx (&ctx
, checksum
);
24350 /* Use the first 8 bytes of the checksum as the dwo_id,
24351 and add it to both comp-unit DIEs. */
24352 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24353 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24355 /* Add the base offset of the ranges table to the skeleton
24357 if (ranges_table_in_use
)
24358 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24359 ranges_section_label
);
24361 switch_to_section (debug_addr_section
);
24362 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24363 output_addr_table ();
24366 /* Output the main compilation unit if non-empty or if .debug_macinfo
24367 or .debug_macro will be emitted. */
24368 output_comp_unit (comp_unit_die (), have_macinfo
);
24370 if (dwarf_split_debug_info
&& info_section_emitted
)
24371 output_skeleton_debug_sections (main_comp_unit_die
);
24373 /* Output the abbreviation table. */
24374 if (abbrev_die_table_in_use
!= 1)
24376 switch_to_section (debug_abbrev_section
);
24377 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24378 output_abbrev_section ();
24381 /* Output location list section if necessary. */
24382 if (have_location_lists
)
24384 /* Output the location lists info. */
24385 switch_to_section (debug_loc_section
);
24386 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24387 output_location_lists (comp_unit_die ());
24390 output_pubtables ();
24392 /* Output the address range information if a CU (.debug_info section)
24393 was emitted. We output an empty table even if we had no functions
24394 to put in it. This because the consumer has no way to tell the
24395 difference between an empty table that we omitted and failure to
24396 generate a table that would have contained data. */
24397 if (info_section_emitted
)
24399 unsigned long aranges_length
= size_of_aranges ();
24401 switch_to_section (debug_aranges_section
);
24402 output_aranges (aranges_length
);
24405 /* Output ranges section if necessary. */
24406 if (ranges_table_in_use
)
24408 switch_to_section (debug_ranges_section
);
24409 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24413 /* Have to end the macro section. */
24416 switch_to_section (debug_macinfo_section
);
24417 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24419 dw2_asm_output_data (1, 0, "End compilation unit");
24422 /* Output the source line correspondence table. We must do this
24423 even if there is no line information. Otherwise, on an empty
24424 translation unit, we will generate a present, but empty,
24425 .debug_info section. IRIX 6.5 `nm' will then complain when
24426 examining the file. This is done late so that any filenames
24427 used by the debug_info section are marked as 'used'. */
24428 switch_to_section (debug_line_section
);
24429 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24430 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24431 output_line_info (false);
24433 if (dwarf_split_debug_info
&& info_section_emitted
)
24435 switch_to_section (debug_skeleton_line_section
);
24436 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24437 output_line_info (true);
24440 /* If we emitted any indirect strings, output the string table too. */
24441 if (debug_str_hash
|| skeleton_debug_str_hash
)
24442 output_indirect_strings ();
24445 #include "gt-dwarf2out.h"