1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2015 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
66 #include "stringpool.h"
68 #include "insn-config.h"
72 #include "diagnostic.h"
74 #include "fold-const.h"
75 #include "stor-layout.h"
89 #include "dwarf2out.h"
90 #include "dwarf2asm.h"
93 #include "tree-pretty-print.h"
95 #include "common/common-target.h"
96 #include "langhooks.h"
100 #include "tree-dfa.h"
101 #include "gdb/gdb-index.h"
102 #include "rtl-iter.h"
104 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
105 static rtx_insn
*last_var_location_insn
;
106 static rtx_insn
*cached_next_real_insn
;
107 static void dwarf2out_decl (tree
);
109 #ifndef XCOFF_DEBUGGING_INFO
110 #define XCOFF_DEBUGGING_INFO 0
113 #ifndef HAVE_XCOFF_DWARF_EXTRAS
114 #define HAVE_XCOFF_DWARF_EXTRAS 0
117 #ifdef VMS_DEBUGGING_INFO
118 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
120 /* Define this macro to be a nonzero value if the directory specifications
121 which are output in the debug info should end with a separator. */
122 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
123 /* Define this macro to evaluate to a nonzero value if GCC should refrain
124 from generating indirect strings in DWARF2 debug information, for instance
125 if your target is stuck with an old version of GDB that is unable to
126 process them properly or uses VMS Debug. */
127 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
129 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
130 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
133 /* ??? Poison these here until it can be done generically. They've been
134 totally replaced in this file; make sure it stays that way. */
135 #undef DWARF2_UNWIND_INFO
136 #undef DWARF2_FRAME_INFO
137 #if (GCC_VERSION >= 3000)
138 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
141 /* The size of the target's pointer type. */
143 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
146 /* Array of RTXes referenced by the debugging information, which therefore
147 must be kept around forever. */
148 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
150 /* A pointer to the base of a list of incomplete types which might be
151 completed at some later time. incomplete_types_list needs to be a
152 vec<tree, va_gc> *because we want to tell the garbage collector about
154 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
156 /* A pointer to the base of a table of references to declaration
157 scopes. This table is a display which tracks the nesting
158 of declaration scopes at the current scope and containing
159 scopes. This table is used to find the proper place to
160 define type declaration DIE's. */
161 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
163 /* Pointers to various DWARF2 sections. */
164 static GTY(()) section
*debug_info_section
;
165 static GTY(()) section
*debug_skeleton_info_section
;
166 static GTY(()) section
*debug_abbrev_section
;
167 static GTY(()) section
*debug_skeleton_abbrev_section
;
168 static GTY(()) section
*debug_aranges_section
;
169 static GTY(()) section
*debug_addr_section
;
170 static GTY(()) section
*debug_macinfo_section
;
171 static GTY(()) section
*debug_line_section
;
172 static GTY(()) section
*debug_skeleton_line_section
;
173 static GTY(()) section
*debug_loc_section
;
174 static GTY(()) section
*debug_pubnames_section
;
175 static GTY(()) section
*debug_pubtypes_section
;
176 static GTY(()) section
*debug_str_section
;
177 static GTY(()) section
*debug_str_dwo_section
;
178 static GTY(()) section
*debug_str_offsets_section
;
179 static GTY(()) section
*debug_ranges_section
;
180 static GTY(()) section
*debug_frame_section
;
182 /* Maximum size (in bytes) of an artificially generated label. */
183 #define MAX_ARTIFICIAL_LABEL_BYTES 30
185 /* According to the (draft) DWARF 3 specification, the initial length
186 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
187 bytes are 0xffffffff, followed by the length stored in the next 8
190 However, the SGI/MIPS ABI uses an initial length which is equal to
191 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
193 #ifndef DWARF_INITIAL_LENGTH_SIZE
194 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
197 /* Round SIZE up to the nearest BOUNDARY. */
198 #define DWARF_ROUND(SIZE,BOUNDARY) \
199 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 /* CIE identifier. */
202 #if HOST_BITS_PER_WIDE_INT >= 64
203 #define DWARF_CIE_ID \
204 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
206 #define DWARF_CIE_ID DW_CIE_ID
210 /* A vector for a table that contains frame description
211 information for each routine. */
212 #define NOT_INDEXED (-1U)
213 #define NO_INDEX_ASSIGNED (-2U)
215 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
217 struct GTY((for_user
)) indirect_string_node
{
219 unsigned int refcount
;
220 enum dwarf_form form
;
225 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
227 typedef const char *compare_type
;
229 static hashval_t
hash (indirect_string_node
*);
230 static bool equal (indirect_string_node
*, const char *);
233 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
235 /* With split_debug_info, both the comp_dir and dwo_name go in the
236 main object file, rather than the dwo, similar to the force_direct
237 parameter elsewhere but with additional complications:
239 1) The string is needed in both the main object file and the dwo.
240 That is, the comp_dir and dwo_name will appear in both places.
242 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
243 DW_FORM_GNU_str_index.
245 3) GCC chooses the form to use late, depending on the size and
248 Rather than forcing the all debug string handling functions and
249 callers to deal with these complications, simply use a separate,
250 special-cased string table for any attribute that should go in the
251 main object file. This limits the complexity to just the places
254 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
256 static GTY(()) int dw2_string_counter
;
258 /* True if the compilation unit places functions in more than one section. */
259 static GTY(()) bool have_multiple_function_sections
= false;
261 /* Whether the default text and cold text sections have been used at all. */
263 static GTY(()) bool text_section_used
= false;
264 static GTY(()) bool cold_text_section_used
= false;
266 /* The default cold text section. */
267 static GTY(()) section
*cold_text_section
;
269 /* The DIE for C++14 'auto' in a function return type. */
270 static GTY(()) dw_die_ref auto_die
;
272 /* The DIE for C++14 'decltype(auto)' in a function return type. */
273 static GTY(()) dw_die_ref decltype_auto_die
;
275 /* Forward declarations for functions defined in this file. */
277 static char *stripattributes (const char *);
278 static void output_call_frame_info (int);
279 static void dwarf2out_note_section_used (void);
281 /* Personality decl of current unit. Used only when assembler does not support
283 static GTY(()) rtx current_unit_personality
;
285 /* Data and reference forms for relocatable data. */
286 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
287 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
289 #ifndef DEBUG_FRAME_SECTION
290 #define DEBUG_FRAME_SECTION ".debug_frame"
293 #ifndef FUNC_BEGIN_LABEL
294 #define FUNC_BEGIN_LABEL "LFB"
297 #ifndef FUNC_END_LABEL
298 #define FUNC_END_LABEL "LFE"
301 #ifndef PROLOGUE_END_LABEL
302 #define PROLOGUE_END_LABEL "LPE"
305 #ifndef EPILOGUE_BEGIN_LABEL
306 #define EPILOGUE_BEGIN_LABEL "LEB"
309 #ifndef FRAME_BEGIN_LABEL
310 #define FRAME_BEGIN_LABEL "Lframe"
312 #define CIE_AFTER_SIZE_LABEL "LSCIE"
313 #define CIE_END_LABEL "LECIE"
314 #define FDE_LABEL "LSFDE"
315 #define FDE_AFTER_SIZE_LABEL "LASFDE"
316 #define FDE_END_LABEL "LEFDE"
317 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
318 #define LINE_NUMBER_END_LABEL "LELT"
319 #define LN_PROLOG_AS_LABEL "LASLTP"
320 #define LN_PROLOG_END_LABEL "LELTP"
321 #define DIE_LABEL_PREFIX "DW"
323 /* Match the base name of a file to the base name of a compilation unit. */
326 matches_main_base (const char *path
)
328 /* Cache the last query. */
329 static const char *last_path
= NULL
;
330 static int last_match
= 0;
331 if (path
!= last_path
)
334 int length
= base_of_path (path
, &base
);
336 last_match
= (length
== main_input_baselength
337 && memcmp (base
, main_input_basename
, length
) == 0);
342 #ifdef DEBUG_DEBUG_STRUCT
345 dump_struct_debug (tree type
, enum debug_info_usage usage
,
346 enum debug_struct_file criterion
, int generic
,
347 int matches
, int result
)
349 /* Find the type name. */
350 tree type_decl
= TYPE_STUB_DECL (type
);
352 const char *name
= 0;
353 if (TREE_CODE (t
) == TYPE_DECL
)
356 name
= IDENTIFIER_POINTER (t
);
358 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
360 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
361 matches
? "bas" : "hdr",
362 generic
? "gen" : "ord",
363 usage
== DINFO_USAGE_DFN
? ";" :
364 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
366 (void*) type_decl
, name
);
369 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
370 dump_struct_debug (type, usage, criterion, generic, matches, result)
374 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
379 /* Get the number of HOST_WIDE_INTs needed to represent the precision
383 get_full_len (const wide_int
&op
)
385 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
386 / HOST_BITS_PER_WIDE_INT
);
390 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
392 enum debug_struct_file criterion
;
394 bool generic
= lang_hooks
.types
.generic_p (type
);
397 criterion
= debug_struct_generic
[usage
];
399 criterion
= debug_struct_ordinary
[usage
];
401 if (criterion
== DINFO_STRUCT_FILE_NONE
)
402 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
403 if (criterion
== DINFO_STRUCT_FILE_ANY
)
404 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
406 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
408 if (type_decl
!= NULL
)
410 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
411 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
413 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
414 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
417 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
420 /* Return a pointer to a copy of the section string name S with all
421 attributes stripped off, and an asterisk prepended (for assemble_name). */
424 stripattributes (const char *s
)
426 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
431 while (*s
&& *s
!= ',')
438 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
439 switch to the data section instead, and write out a synthetic start label
440 for collect2 the first time around. */
443 switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED
)
445 if (eh_frame_section
== 0)
449 if (EH_TABLES_CAN_BE_READ_ONLY
)
455 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
457 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
459 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
462 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
463 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
464 && (per_encoding
& 0x70) != DW_EH_PE_absptr
465 && (per_encoding
& 0x70) != DW_EH_PE_aligned
466 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
467 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
468 ? 0 : SECTION_WRITE
);
471 flags
= SECTION_WRITE
;
473 #ifdef EH_FRAME_SECTION_NAME
474 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
476 eh_frame_section
= ((flags
== SECTION_WRITE
)
477 ? data_section
: readonly_data_section
);
478 #endif /* EH_FRAME_SECTION_NAME */
481 switch_to_section (eh_frame_section
);
483 #ifdef EH_FRAME_THROUGH_COLLECT2
484 /* We have no special eh_frame section. Emit special labels to guide
488 tree label
= get_file_function_name ("F");
489 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
490 targetm
.asm_out
.globalize_label (asm_out_file
,
491 IDENTIFIER_POINTER (label
));
492 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
497 /* Switch [BACK] to the eh or debug frame table section, depending on
501 switch_to_frame_table_section (int for_eh
, bool back
)
504 switch_to_eh_frame_section (back
);
507 if (!debug_frame_section
)
508 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
509 SECTION_DEBUG
, NULL
);
510 switch_to_section (debug_frame_section
);
514 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
516 enum dw_cfi_oprnd_type
517 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
522 case DW_CFA_GNU_window_save
:
523 case DW_CFA_remember_state
:
524 case DW_CFA_restore_state
:
525 return dw_cfi_oprnd_unused
;
528 case DW_CFA_advance_loc1
:
529 case DW_CFA_advance_loc2
:
530 case DW_CFA_advance_loc4
:
531 case DW_CFA_MIPS_advance_loc8
:
532 return dw_cfi_oprnd_addr
;
535 case DW_CFA_offset_extended
:
537 case DW_CFA_offset_extended_sf
:
538 case DW_CFA_def_cfa_sf
:
540 case DW_CFA_restore_extended
:
541 case DW_CFA_undefined
:
542 case DW_CFA_same_value
:
543 case DW_CFA_def_cfa_register
:
544 case DW_CFA_register
:
545 case DW_CFA_expression
:
546 return dw_cfi_oprnd_reg_num
;
548 case DW_CFA_def_cfa_offset
:
549 case DW_CFA_GNU_args_size
:
550 case DW_CFA_def_cfa_offset_sf
:
551 return dw_cfi_oprnd_offset
;
553 case DW_CFA_def_cfa_expression
:
554 return dw_cfi_oprnd_loc
;
561 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
563 enum dw_cfi_oprnd_type
564 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
569 case DW_CFA_def_cfa_sf
:
571 case DW_CFA_offset_extended_sf
:
572 case DW_CFA_offset_extended
:
573 return dw_cfi_oprnd_offset
;
575 case DW_CFA_register
:
576 return dw_cfi_oprnd_reg_num
;
578 case DW_CFA_expression
:
579 return dw_cfi_oprnd_loc
;
582 return dw_cfi_oprnd_unused
;
586 /* Output one FDE. */
589 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
590 char *section_start_label
, int fde_encoding
, char *augmentation
,
591 bool any_lsda_needed
, int lsda_encoding
)
593 const char *begin
, *end
;
594 static unsigned int j
;
597 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
599 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
601 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
602 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
603 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
605 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
606 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
607 " indicating 64-bit DWARF extension");
608 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
611 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
614 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
616 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
617 debug_frame_section
, "FDE CIE offset");
619 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
620 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
624 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
625 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
626 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
627 "FDE initial location");
628 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
629 end
, begin
, "FDE address range");
633 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
634 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
641 int size
= size_of_encoded_value (lsda_encoding
);
643 if (lsda_encoding
== DW_EH_PE_aligned
)
645 int offset
= ( 4 /* Length */
647 + 2 * size_of_encoded_value (fde_encoding
)
648 + 1 /* Augmentation size */ );
649 int pad
= -offset
& (PTR_SIZE
- 1);
652 gcc_assert (size_of_uleb128 (size
) == 1);
655 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
657 if (fde
->uses_eh_lsda
)
659 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
660 fde
->funcdef_number
);
661 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
662 gen_rtx_SYMBOL_REF (Pmode
, l1
),
664 "Language Specific Data Area");
668 if (lsda_encoding
== DW_EH_PE_aligned
)
669 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
670 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
671 "Language Specific Data Area (none)");
675 dw2_asm_output_data_uleb128 (0, "Augmentation size");
678 /* Loop through the Call Frame Instructions associated with this FDE. */
679 fde
->dw_fde_current_label
= begin
;
681 size_t from
, until
, i
;
684 until
= vec_safe_length (fde
->dw_fde_cfi
);
686 if (fde
->dw_fde_second_begin
== NULL
)
689 until
= fde
->dw_fde_switch_cfi_index
;
691 from
= fde
->dw_fde_switch_cfi_index
;
693 for (i
= from
; i
< until
; i
++)
694 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
697 /* If we are to emit a ref/link from function bodies to their frame tables,
698 do it now. This is typically performed to make sure that tables
699 associated with functions are dragged with them and not discarded in
700 garbage collecting links. We need to do this on a per function basis to
701 cope with -ffunction-sections. */
703 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
704 /* Switch to the function section, emit the ref to the tables, and
705 switch *back* into the table section. */
706 switch_to_section (function_section (fde
->decl
));
707 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
708 switch_to_frame_table_section (for_eh
, true);
711 /* Pad the FDE out to an address sized boundary. */
712 ASM_OUTPUT_ALIGN (asm_out_file
,
713 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
714 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
719 /* Return true if frame description entry FDE is needed for EH. */
722 fde_needed_for_eh_p (dw_fde_ref fde
)
724 if (flag_asynchronous_unwind_tables
)
727 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
730 if (fde
->uses_eh_lsda
)
733 /* If exceptions are enabled, we have collected nothrow info. */
734 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
740 /* Output the call frame information used to record information
741 that relates to calculating the frame pointer, and records the
742 location of saved registers. */
745 output_call_frame_info (int for_eh
)
750 char l1
[20], l2
[20], section_start_label
[20];
751 bool any_lsda_needed
= false;
752 char augmentation
[6];
753 int augmentation_size
;
754 int fde_encoding
= DW_EH_PE_absptr
;
755 int per_encoding
= DW_EH_PE_absptr
;
756 int lsda_encoding
= DW_EH_PE_absptr
;
758 rtx personality
= NULL
;
761 /* Don't emit a CIE if there won't be any FDEs. */
765 /* Nothing to do if the assembler's doing it all. */
766 if (dwarf2out_do_cfi_asm ())
769 /* If we don't have any functions we'll want to unwind out of, don't emit
770 any EH unwind information. If we make FDEs linkonce, we may have to
771 emit an empty label for an FDE that wouldn't otherwise be emitted. We
772 want to avoid having an FDE kept around when the function it refers to
773 is discarded. Example where this matters: a primary function template
774 in C++ requires EH information, an explicit specialization doesn't. */
777 bool any_eh_needed
= false;
779 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
781 if (fde
->uses_eh_lsda
)
782 any_eh_needed
= any_lsda_needed
= true;
783 else if (fde_needed_for_eh_p (fde
))
784 any_eh_needed
= true;
785 else if (TARGET_USES_WEAK_UNWIND_INFO
)
786 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
793 /* We're going to be generating comments, so turn on app. */
797 /* Switch to the proper frame section, first time. */
798 switch_to_frame_table_section (for_eh
, false);
800 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
801 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
803 /* Output the CIE. */
804 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
805 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
806 if (!XCOFF_DEBUGGING_INFO
|| for_eh
)
808 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
809 dw2_asm_output_data (4, 0xffffffff,
810 "Initial length escape value indicating 64-bit DWARF extension");
811 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
812 "Length of Common Information Entry");
814 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
816 /* Now that the CIE pointer is PC-relative for EH,
817 use 0 to identify the CIE. */
818 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
819 (for_eh
? 0 : DWARF_CIE_ID
),
820 "CIE Identifier Tag");
822 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
823 use CIE version 1, unless that would produce incorrect results
824 due to overflowing the return register column. */
825 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
827 if (return_reg
>= 256 || dwarf_version
> 2)
829 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
832 augmentation_size
= 0;
834 personality
= current_unit_personality
;
840 z Indicates that a uleb128 is present to size the
841 augmentation section.
842 L Indicates the encoding (and thus presence) of
843 an LSDA pointer in the FDE augmentation.
844 R Indicates a non-default pointer encoding for
846 P Indicates the presence of an encoding + language
847 personality routine in the CIE augmentation. */
849 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
850 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
851 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
853 p
= augmentation
+ 1;
857 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
858 assemble_external_libcall (personality
);
863 augmentation_size
+= 1;
865 if (fde_encoding
!= DW_EH_PE_absptr
)
868 augmentation_size
+= 1;
870 if (p
> augmentation
+ 1)
872 augmentation
[0] = 'z';
876 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
877 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
879 int offset
= ( 4 /* Length */
881 + 1 /* CIE version */
882 + strlen (augmentation
) + 1 /* Augmentation */
883 + size_of_uleb128 (1) /* Code alignment */
884 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
886 + 1 /* Augmentation size */
887 + 1 /* Personality encoding */ );
888 int pad
= -offset
& (PTR_SIZE
- 1);
890 augmentation_size
+= pad
;
892 /* Augmentations should be small, so there's scarce need to
893 iterate for a solution. Die if we exceed one uleb128 byte. */
894 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
898 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
899 if (dw_cie_version
>= 4)
901 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
902 dw2_asm_output_data (1, 0, "CIE Segment Size");
904 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
905 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
906 "CIE Data Alignment Factor");
908 if (dw_cie_version
== 1)
909 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
911 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
915 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
918 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
919 eh_data_format_name (per_encoding
));
920 dw2_asm_output_encoded_addr_rtx (per_encoding
,
926 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
927 eh_data_format_name (lsda_encoding
));
929 if (fde_encoding
!= DW_EH_PE_absptr
)
930 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
931 eh_data_format_name (fde_encoding
));
934 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
935 output_cfi (cfi
, NULL
, for_eh
);
937 /* Pad the CIE out to an address sized boundary. */
938 ASM_OUTPUT_ALIGN (asm_out_file
,
939 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
940 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
942 /* Loop through all of the FDE's. */
943 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
947 /* Don't emit EH unwind info for leaf functions that don't need it. */
948 if (for_eh
&& !fde_needed_for_eh_p (fde
))
951 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
952 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
953 augmentation
, any_lsda_needed
, lsda_encoding
);
956 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
957 dw2_asm_output_data (4, 0, "End of Table");
959 /* Turn off app to make assembly quicker. */
964 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
967 dwarf2out_do_cfi_startproc (bool second
)
971 rtx personality
= get_personality_function (current_function_decl
);
973 fprintf (asm_out_file
, "\t.cfi_startproc\n");
977 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
980 /* ??? The GAS support isn't entirely consistent. We have to
981 handle indirect support ourselves, but PC-relative is done
982 in the assembler. Further, the assembler can't handle any
983 of the weirder relocation types. */
984 if (enc
& DW_EH_PE_indirect
)
985 ref
= dw2_force_const_mem (ref
, true);
987 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
988 output_addr_const (asm_out_file
, ref
);
989 fputc ('\n', asm_out_file
);
992 if (crtl
->uses_eh_lsda
)
996 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
997 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
998 current_function_funcdef_no
);
999 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
1000 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
1002 if (enc
& DW_EH_PE_indirect
)
1003 ref
= dw2_force_const_mem (ref
, true);
1005 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
1006 output_addr_const (asm_out_file
, ref
);
1007 fputc ('\n', asm_out_file
);
1011 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1012 this allocation may be done before pass_final. */
1015 dwarf2out_alloc_current_fde (void)
1019 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1020 fde
->decl
= current_function_decl
;
1021 fde
->funcdef_number
= current_function_funcdef_no
;
1022 fde
->fde_index
= vec_safe_length (fde_vec
);
1023 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1024 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1025 fde
->nothrow
= crtl
->nothrow
;
1026 fde
->drap_reg
= INVALID_REGNUM
;
1027 fde
->vdrap_reg
= INVALID_REGNUM
;
1029 /* Record the FDE associated with this function. */
1031 vec_safe_push (fde_vec
, fde
);
1036 /* Output a marker (i.e. a label) for the beginning of a function, before
1040 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1041 const char *file ATTRIBUTE_UNUSED
)
1043 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1049 current_function_func_begin_label
= NULL
;
1051 do_frame
= dwarf2out_do_frame ();
1053 /* ??? current_function_func_begin_label is also used by except.c for
1054 call-site information. We must emit this label if it might be used. */
1056 && (!flag_exceptions
1057 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1060 fnsec
= function_section (current_function_decl
);
1061 switch_to_section (fnsec
);
1062 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1063 current_function_funcdef_no
);
1064 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1065 current_function_funcdef_no
);
1066 dup_label
= xstrdup (label
);
1067 current_function_func_begin_label
= dup_label
;
1069 /* We can elide the fde allocation if we're not emitting debug info. */
1073 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1074 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1075 would include pass_dwarf2_frame. If we've not created the FDE yet,
1079 fde
= dwarf2out_alloc_current_fde ();
1081 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1082 fde
->dw_fde_begin
= dup_label
;
1083 fde
->dw_fde_current_label
= dup_label
;
1084 fde
->in_std_section
= (fnsec
== text_section
1085 || (cold_text_section
&& fnsec
== cold_text_section
));
1087 /* We only want to output line number information for the genuine dwarf2
1088 prologue case, not the eh frame case. */
1089 #ifdef DWARF2_DEBUGGING_INFO
1091 dwarf2out_source_line (line
, file
, 0, true);
1094 if (dwarf2out_do_cfi_asm ())
1095 dwarf2out_do_cfi_startproc (false);
1098 rtx personality
= get_personality_function (current_function_decl
);
1099 if (!current_unit_personality
)
1100 current_unit_personality
= personality
;
1102 /* We cannot keep a current personality per function as without CFI
1103 asm, at the point where we emit the CFI data, there is no current
1104 function anymore. */
1105 if (personality
&& current_unit_personality
!= personality
)
1106 sorry ("multiple EH personalities are supported only with assemblers "
1107 "supporting .cfi_personality directive");
1111 /* Output a marker (i.e. a label) for the end of the generated code
1112 for a function prologue. This gets called *after* the prologue code has
1116 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1117 const char *file ATTRIBUTE_UNUSED
)
1119 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1121 /* Output a label to mark the endpoint of the code generated for this
1123 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1124 current_function_funcdef_no
);
1125 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1126 current_function_funcdef_no
);
1127 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1130 /* Output a marker (i.e. a label) for the beginning of the generated code
1131 for a function epilogue. This gets called *before* the prologue code has
1135 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1136 const char *file ATTRIBUTE_UNUSED
)
1138 dw_fde_ref fde
= cfun
->fde
;
1139 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1141 if (fde
->dw_fde_vms_begin_epilogue
)
1144 /* Output a label to mark the endpoint of the code generated for this
1146 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1147 current_function_funcdef_no
);
1148 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1149 current_function_funcdef_no
);
1150 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1153 /* Output a marker (i.e. a label) for the absolute end of the generated code
1154 for a function definition. This gets called *after* the epilogue code has
1158 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1159 const char *file ATTRIBUTE_UNUSED
)
1162 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1164 last_var_location_insn
= NULL
;
1165 cached_next_real_insn
= NULL
;
1167 if (dwarf2out_do_cfi_asm ())
1168 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1170 /* Output a label to mark the endpoint of the code generated for this
1172 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1173 current_function_funcdef_no
);
1174 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1176 gcc_assert (fde
!= NULL
);
1177 if (fde
->dw_fde_second_begin
== NULL
)
1178 fde
->dw_fde_end
= xstrdup (label
);
1182 dwarf2out_frame_finish (void)
1184 /* Output call frame information. */
1185 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1186 output_call_frame_info (0);
1188 /* Output another copy for the unwinder. */
1189 if ((flag_unwind_tables
|| flag_exceptions
)
1190 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1191 output_call_frame_info (1);
1194 /* Note that the current function section is being used for code. */
1197 dwarf2out_note_section_used (void)
1199 section
*sec
= current_function_section ();
1200 if (sec
== text_section
)
1201 text_section_used
= true;
1202 else if (sec
== cold_text_section
)
1203 cold_text_section_used
= true;
1206 static void var_location_switch_text_section (void);
1207 static void set_cur_line_info_table (section
*);
1210 dwarf2out_switch_text_section (void)
1213 dw_fde_ref fde
= cfun
->fde
;
1215 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1217 if (!in_cold_section_p
)
1219 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1220 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1221 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1225 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1226 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1227 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1229 have_multiple_function_sections
= true;
1231 /* There is no need to mark used sections when not debugging. */
1232 if (cold_text_section
!= NULL
)
1233 dwarf2out_note_section_used ();
1235 if (dwarf2out_do_cfi_asm ())
1236 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1238 /* Now do the real section switch. */
1239 sect
= current_function_section ();
1240 switch_to_section (sect
);
1242 fde
->second_in_std_section
1243 = (sect
== text_section
1244 || (cold_text_section
&& sect
== cold_text_section
));
1246 if (dwarf2out_do_cfi_asm ())
1247 dwarf2out_do_cfi_startproc (true);
1249 var_location_switch_text_section ();
1251 if (cold_text_section
!= NULL
)
1252 set_cur_line_info_table (sect
);
1255 /* And now, the subset of the debugging information support code necessary
1256 for emitting location expressions. */
1258 /* Data about a single source file. */
1259 struct GTY((for_user
)) dwarf_file_data
{
1260 const char * filename
;
1264 /* Describe an entry into the .debug_addr section. */
1268 ate_kind_rtx_dtprel
,
1272 struct GTY((for_user
)) addr_table_entry
{
1274 unsigned int refcount
;
1276 union addr_table_entry_struct_union
1278 rtx
GTY ((tag ("0"))) rtl
;
1279 char * GTY ((tag ("1"))) label
;
1281 GTY ((desc ("%1.kind"))) addr
;
1284 /* Location lists are ranges + location descriptions for that range,
1285 so you can track variables that are in different places over
1286 their entire life. */
1287 typedef struct GTY(()) dw_loc_list_struct
{
1288 dw_loc_list_ref dw_loc_next
;
1289 const char *begin
; /* Label and addr_entry for start of range */
1290 addr_table_entry
*begin_entry
;
1291 const char *end
; /* Label for end of range */
1292 char *ll_symbol
; /* Label for beginning of location list.
1293 Only on head of list */
1294 const char *section
; /* Section this loclist is relative to */
1295 dw_loc_descr_ref expr
;
1297 /* True if all addresses in this and subsequent lists are known to be
1300 /* True if this list has been replaced by dw_loc_next. */
1303 /* True if the range should be emitted even if begin and end
1308 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1310 /* Convert a DWARF stack opcode into its string name. */
1313 dwarf_stack_op_name (unsigned int op
)
1315 const char *name
= get_DW_OP_name (op
);
1320 return "OP_<unknown>";
1323 /* Return a pointer to a newly allocated location description. Location
1324 descriptions are simple expression terms that can be strung
1325 together to form more complicated location (address) descriptions. */
1327 static inline dw_loc_descr_ref
1328 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1329 unsigned HOST_WIDE_INT oprnd2
)
1331 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1333 descr
->dw_loc_opc
= op
;
1334 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1335 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1336 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1337 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1338 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1339 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1344 /* Return a pointer to a newly allocated location description for
1347 static inline dw_loc_descr_ref
1348 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1351 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1354 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1357 /* Add a location description term to a location description expression. */
1360 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1362 dw_loc_descr_ref
*d
;
1364 /* Find the end of the chain. */
1365 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1371 /* Compare two location operands for exact equality. */
1374 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1376 if (a
->val_class
!= b
->val_class
)
1378 switch (a
->val_class
)
1380 case dw_val_class_none
:
1382 case dw_val_class_addr
:
1383 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1385 case dw_val_class_offset
:
1386 case dw_val_class_unsigned_const
:
1387 case dw_val_class_const
:
1388 case dw_val_class_range_list
:
1389 case dw_val_class_lineptr
:
1390 case dw_val_class_macptr
:
1391 /* These are all HOST_WIDE_INT, signed or unsigned. */
1392 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1394 case dw_val_class_loc
:
1395 return a
->v
.val_loc
== b
->v
.val_loc
;
1396 case dw_val_class_loc_list
:
1397 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1398 case dw_val_class_die_ref
:
1399 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1400 case dw_val_class_fde_ref
:
1401 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1402 case dw_val_class_lbl_id
:
1403 case dw_val_class_high_pc
:
1404 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1405 case dw_val_class_str
:
1406 return a
->v
.val_str
== b
->v
.val_str
;
1407 case dw_val_class_flag
:
1408 return a
->v
.val_flag
== b
->v
.val_flag
;
1409 case dw_val_class_file
:
1410 return a
->v
.val_file
== b
->v
.val_file
;
1411 case dw_val_class_decl_ref
:
1412 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1414 case dw_val_class_const_double
:
1415 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1416 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1418 case dw_val_class_wide_int
:
1419 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1421 case dw_val_class_vec
:
1423 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1424 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1426 return (a_len
== b_len
1427 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1430 case dw_val_class_data8
:
1431 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1433 case dw_val_class_vms_delta
:
1434 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1435 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1440 /* Compare two location atoms for exact equality. */
1443 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1445 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1448 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1449 address size, but since we always allocate cleared storage it
1450 should be zero for other types of locations. */
1451 if (a
->dtprel
!= b
->dtprel
)
1454 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1455 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1458 /* Compare two complete location expressions for exact equality. */
1461 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1467 if (a
== NULL
|| b
== NULL
)
1469 if (!loc_descr_equal_p_1 (a
, b
))
1478 /* Add a constant OFFSET to a location expression. */
1481 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1483 dw_loc_descr_ref loc
;
1486 gcc_assert (*list_head
!= NULL
);
1491 /* Find the end of the chain. */
1492 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1496 if (loc
->dw_loc_opc
== DW_OP_fbreg
1497 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1498 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1499 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1500 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1502 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1503 offset. Don't optimize if an signed integer overflow would happen. */
1505 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1506 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1509 else if (offset
> 0)
1510 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1514 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1515 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1519 /* Add a constant OFFSET to a location list. */
1522 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1525 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1526 loc_descr_plus_const (&d
->expr
, offset
);
1529 #define DWARF_REF_SIZE \
1530 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1532 static unsigned long int get_base_type_offset (dw_die_ref
);
1534 /* Return the size of a location descriptor. */
1536 static unsigned long
1537 size_of_loc_descr (dw_loc_descr_ref loc
)
1539 unsigned long size
= 1;
1541 switch (loc
->dw_loc_opc
)
1544 size
+= DWARF2_ADDR_SIZE
;
1546 case DW_OP_GNU_addr_index
:
1547 case DW_OP_GNU_const_index
:
1548 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1549 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1568 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1571 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1576 case DW_OP_plus_uconst
:
1577 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1615 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1618 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1621 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1624 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1625 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1628 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1630 case DW_OP_bit_piece
:
1631 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1632 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1634 case DW_OP_deref_size
:
1635 case DW_OP_xderef_size
:
1644 case DW_OP_call_ref
:
1645 size
+= DWARF_REF_SIZE
;
1647 case DW_OP_implicit_value
:
1648 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1649 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1651 case DW_OP_GNU_implicit_pointer
:
1652 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1654 case DW_OP_GNU_entry_value
:
1656 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1657 size
+= size_of_uleb128 (op_size
) + op_size
;
1660 case DW_OP_GNU_const_type
:
1663 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1664 size
+= size_of_uleb128 (o
) + 1;
1665 switch (loc
->dw_loc_oprnd2
.val_class
)
1667 case dw_val_class_vec
:
1668 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1669 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1671 case dw_val_class_const
:
1672 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1674 case dw_val_class_const_double
:
1675 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1677 case dw_val_class_wide_int
:
1678 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1679 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1686 case DW_OP_GNU_regval_type
:
1689 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1690 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1691 + size_of_uleb128 (o
);
1694 case DW_OP_GNU_deref_type
:
1697 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1698 size
+= 1 + size_of_uleb128 (o
);
1701 case DW_OP_GNU_convert
:
1702 case DW_OP_GNU_reinterpret
:
1703 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1704 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1708 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1709 size
+= size_of_uleb128 (o
);
1712 case DW_OP_GNU_parameter_ref
:
1722 /* Return the size of a series of location descriptors. */
1725 size_of_locs (dw_loc_descr_ref loc
)
1730 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1731 field, to avoid writing to a PCH file. */
1732 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1734 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1736 size
+= size_of_loc_descr (l
);
1741 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1743 l
->dw_loc_addr
= size
;
1744 size
+= size_of_loc_descr (l
);
1750 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1751 static void get_ref_die_offset_label (char *, dw_die_ref
);
1752 static unsigned long int get_ref_die_offset (dw_die_ref
);
1754 /* Output location description stack opcode's operands (if any).
1755 The for_eh_or_skip parameter controls whether register numbers are
1756 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1757 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1758 info). This should be suppressed for the cases that have not been converted
1759 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1762 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1764 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1765 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1767 switch (loc
->dw_loc_opc
)
1769 #ifdef DWARF2_DEBUGGING_INFO
1772 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1777 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1778 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1780 fputc ('\n', asm_out_file
);
1785 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1790 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1791 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1793 fputc ('\n', asm_out_file
);
1798 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1799 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1806 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1807 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1809 dw2_asm_output_data (2, offset
, NULL
);
1812 case DW_OP_implicit_value
:
1813 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1814 switch (val2
->val_class
)
1816 case dw_val_class_const
:
1817 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1819 case dw_val_class_vec
:
1821 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1822 unsigned int len
= val2
->v
.val_vec
.length
;
1826 if (elt_size
> sizeof (HOST_WIDE_INT
))
1831 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1834 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1835 "fp or vector constant word %u", i
);
1838 case dw_val_class_const_double
:
1840 unsigned HOST_WIDE_INT first
, second
;
1842 if (WORDS_BIG_ENDIAN
)
1844 first
= val2
->v
.val_double
.high
;
1845 second
= val2
->v
.val_double
.low
;
1849 first
= val2
->v
.val_double
.low
;
1850 second
= val2
->v
.val_double
.high
;
1852 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1854 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1858 case dw_val_class_wide_int
:
1861 int len
= get_full_len (*val2
->v
.val_wide
);
1862 if (WORDS_BIG_ENDIAN
)
1863 for (i
= len
- 1; i
>= 0; --i
)
1864 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1865 val2
->v
.val_wide
->elt (i
), NULL
);
1867 for (i
= 0; i
< len
; ++i
)
1868 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1869 val2
->v
.val_wide
->elt (i
), NULL
);
1872 case dw_val_class_addr
:
1873 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1874 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1889 case DW_OP_implicit_value
:
1890 /* We currently don't make any attempt to make sure these are
1891 aligned properly like we do for the main unwind info, so
1892 don't support emitting things larger than a byte if we're
1893 only doing unwinding. */
1898 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1901 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1904 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1907 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1909 case DW_OP_plus_uconst
:
1910 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1944 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1948 unsigned r
= val1
->v
.val_unsigned
;
1949 if (for_eh_or_skip
>= 0)
1950 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1951 gcc_assert (size_of_uleb128 (r
)
1952 == size_of_uleb128 (val1
->v
.val_unsigned
));
1953 dw2_asm_output_data_uleb128 (r
, NULL
);
1957 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1961 unsigned r
= val1
->v
.val_unsigned
;
1962 if (for_eh_or_skip
>= 0)
1963 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1964 gcc_assert (size_of_uleb128 (r
)
1965 == size_of_uleb128 (val1
->v
.val_unsigned
));
1966 dw2_asm_output_data_uleb128 (r
, NULL
);
1967 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1971 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1973 case DW_OP_bit_piece
:
1974 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1975 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1977 case DW_OP_deref_size
:
1978 case DW_OP_xderef_size
:
1979 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1985 if (targetm
.asm_out
.output_dwarf_dtprel
)
1987 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1990 fputc ('\n', asm_out_file
);
1997 #ifdef DWARF2_DEBUGGING_INFO
1998 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2005 case DW_OP_GNU_addr_index
:
2006 case DW_OP_GNU_const_index
:
2007 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2008 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2009 "(index into .debug_addr)");
2012 case DW_OP_GNU_implicit_pointer
:
2014 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2015 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2016 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2017 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2018 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2019 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2023 case DW_OP_GNU_entry_value
:
2024 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2025 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2028 case DW_OP_GNU_const_type
:
2030 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2032 dw2_asm_output_data_uleb128 (o
, NULL
);
2033 switch (val2
->val_class
)
2035 case dw_val_class_const
:
2036 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2037 dw2_asm_output_data (1, l
, NULL
);
2038 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2040 case dw_val_class_vec
:
2042 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2043 unsigned int len
= val2
->v
.val_vec
.length
;
2048 dw2_asm_output_data (1, l
, NULL
);
2049 if (elt_size
> sizeof (HOST_WIDE_INT
))
2054 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2057 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2058 "fp or vector constant word %u", i
);
2061 case dw_val_class_const_double
:
2063 unsigned HOST_WIDE_INT first
, second
;
2064 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2066 dw2_asm_output_data (1, 2 * l
, NULL
);
2067 if (WORDS_BIG_ENDIAN
)
2069 first
= val2
->v
.val_double
.high
;
2070 second
= val2
->v
.val_double
.low
;
2074 first
= val2
->v
.val_double
.low
;
2075 second
= val2
->v
.val_double
.high
;
2077 dw2_asm_output_data (l
, first
, NULL
);
2078 dw2_asm_output_data (l
, second
, NULL
);
2081 case dw_val_class_wide_int
:
2084 int len
= get_full_len (*val2
->v
.val_wide
);
2085 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2087 dw2_asm_output_data (1, len
* l
, NULL
);
2088 if (WORDS_BIG_ENDIAN
)
2089 for (i
= len
- 1; i
>= 0; --i
)
2090 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2092 for (i
= 0; i
< len
; ++i
)
2093 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2101 case DW_OP_GNU_regval_type
:
2103 unsigned r
= val1
->v
.val_unsigned
;
2104 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2106 if (for_eh_or_skip
>= 0)
2108 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2109 gcc_assert (size_of_uleb128 (r
)
2110 == size_of_uleb128 (val1
->v
.val_unsigned
));
2112 dw2_asm_output_data_uleb128 (r
, NULL
);
2113 dw2_asm_output_data_uleb128 (o
, NULL
);
2116 case DW_OP_GNU_deref_type
:
2118 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2120 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2121 dw2_asm_output_data_uleb128 (o
, NULL
);
2124 case DW_OP_GNU_convert
:
2125 case DW_OP_GNU_reinterpret
:
2126 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2127 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2130 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2132 dw2_asm_output_data_uleb128 (o
, NULL
);
2136 case DW_OP_GNU_parameter_ref
:
2139 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2140 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2141 dw2_asm_output_data (4, o
, NULL
);
2146 /* Other codes have no operands. */
2151 /* Output a sequence of location operations.
2152 The for_eh_or_skip parameter controls whether register numbers are
2153 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2154 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2155 info). This should be suppressed for the cases that have not been converted
2156 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2159 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2161 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2163 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2164 /* Output the opcode. */
2165 if (for_eh_or_skip
>= 0
2166 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2168 unsigned r
= (opc
- DW_OP_breg0
);
2169 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2170 gcc_assert (r
<= 31);
2171 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2173 else if (for_eh_or_skip
>= 0
2174 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2176 unsigned r
= (opc
- DW_OP_reg0
);
2177 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2178 gcc_assert (r
<= 31);
2179 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2182 dw2_asm_output_data (1, opc
,
2183 "%s", dwarf_stack_op_name (opc
));
2185 /* Output the operand(s) (if any). */
2186 output_loc_operands (loc
, for_eh_or_skip
);
2190 /* Output location description stack opcode's operands (if any).
2191 The output is single bytes on a line, suitable for .cfi_escape. */
2194 output_loc_operands_raw (dw_loc_descr_ref loc
)
2196 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2197 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2199 switch (loc
->dw_loc_opc
)
2202 case DW_OP_GNU_addr_index
:
2203 case DW_OP_GNU_const_index
:
2204 case DW_OP_implicit_value
:
2205 /* We cannot output addresses in .cfi_escape, only bytes. */
2211 case DW_OP_deref_size
:
2212 case DW_OP_xderef_size
:
2213 fputc (',', asm_out_file
);
2214 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2219 fputc (',', asm_out_file
);
2220 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2225 fputc (',', asm_out_file
);
2226 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2231 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2232 fputc (',', asm_out_file
);
2233 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2241 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2242 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2244 fputc (',', asm_out_file
);
2245 dw2_asm_output_data_raw (2, offset
);
2251 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2252 gcc_assert (size_of_uleb128 (r
)
2253 == size_of_uleb128 (val1
->v
.val_unsigned
));
2254 fputc (',', asm_out_file
);
2255 dw2_asm_output_data_uleb128_raw (r
);
2260 case DW_OP_plus_uconst
:
2262 fputc (',', asm_out_file
);
2263 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2266 case DW_OP_bit_piece
:
2267 fputc (',', asm_out_file
);
2268 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2269 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2306 fputc (',', asm_out_file
);
2307 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2312 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2313 gcc_assert (size_of_uleb128 (r
)
2314 == size_of_uleb128 (val1
->v
.val_unsigned
));
2315 fputc (',', asm_out_file
);
2316 dw2_asm_output_data_uleb128_raw (r
);
2317 fputc (',', asm_out_file
);
2318 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2322 case DW_OP_GNU_implicit_pointer
:
2323 case DW_OP_GNU_entry_value
:
2324 case DW_OP_GNU_const_type
:
2325 case DW_OP_GNU_regval_type
:
2326 case DW_OP_GNU_deref_type
:
2327 case DW_OP_GNU_convert
:
2328 case DW_OP_GNU_reinterpret
:
2329 case DW_OP_GNU_parameter_ref
:
2334 /* Other codes have no operands. */
2340 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2344 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2345 /* Output the opcode. */
2346 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2348 unsigned r
= (opc
- DW_OP_breg0
);
2349 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2350 gcc_assert (r
<= 31);
2351 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2353 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2355 unsigned r
= (opc
- DW_OP_reg0
);
2356 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2357 gcc_assert (r
<= 31);
2358 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2360 /* Output the opcode. */
2361 fprintf (asm_out_file
, "%#x", opc
);
2362 output_loc_operands_raw (loc
);
2364 if (!loc
->dw_loc_next
)
2366 loc
= loc
->dw_loc_next
;
2368 fputc (',', asm_out_file
);
2372 /* This function builds a dwarf location descriptor sequence from a
2373 dw_cfa_location, adding the given OFFSET to the result of the
2376 struct dw_loc_descr_node
*
2377 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2379 struct dw_loc_descr_node
*head
, *tmp
;
2381 offset
+= cfa
->offset
;
2385 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2386 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2387 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2388 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2389 add_loc_descr (&head
, tmp
);
2392 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2393 add_loc_descr (&head
, tmp
);
2397 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2402 /* This function builds a dwarf location descriptor sequence for
2403 the address at OFFSET from the CFA when stack is aligned to
2406 struct dw_loc_descr_node
*
2407 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2408 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2410 struct dw_loc_descr_node
*head
;
2411 unsigned int dwarf_fp
2412 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2414 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2415 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2417 head
= new_reg_loc_descr (dwarf_fp
, 0);
2418 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2419 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2420 loc_descr_plus_const (&head
, offset
);
2423 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2427 /* And now, the support for symbolic debugging information. */
2429 /* .debug_str support. */
2431 static void dwarf2out_init (const char *);
2432 static void dwarf2out_finish (const char *);
2433 static void dwarf2out_early_finish (void);
2434 static void dwarf2out_assembly_start (void);
2435 static void dwarf2out_define (unsigned int, const char *);
2436 static void dwarf2out_undef (unsigned int, const char *);
2437 static void dwarf2out_start_source_file (unsigned, const char *);
2438 static void dwarf2out_end_source_file (unsigned);
2439 static void dwarf2out_function_decl (tree
);
2440 static void dwarf2out_begin_block (unsigned, unsigned);
2441 static void dwarf2out_end_block (unsigned, unsigned);
2442 static bool dwarf2out_ignore_block (const_tree
);
2443 static void dwarf2out_early_global_decl (tree
);
2444 static void dwarf2out_late_global_decl (tree
);
2445 static void dwarf2out_type_decl (tree
, int);
2446 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2447 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2449 static void dwarf2out_abstract_function (tree
);
2450 static void dwarf2out_var_location (rtx_insn
*);
2451 static void dwarf2out_begin_function (tree
);
2452 static void dwarf2out_end_function (unsigned int);
2453 static void dwarf2out_register_main_translation_unit (tree unit
);
2454 static void dwarf2out_set_name (tree
, tree
);
2456 /* The debug hooks structure. */
2458 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2462 dwarf2out_early_finish
,
2463 dwarf2out_assembly_start
,
2466 dwarf2out_start_source_file
,
2467 dwarf2out_end_source_file
,
2468 dwarf2out_begin_block
,
2469 dwarf2out_end_block
,
2470 dwarf2out_ignore_block
,
2471 dwarf2out_source_line
,
2472 dwarf2out_begin_prologue
,
2473 #if VMS_DEBUGGING_INFO
2474 dwarf2out_vms_end_prologue
,
2475 dwarf2out_vms_begin_epilogue
,
2477 debug_nothing_int_charstar
,
2478 debug_nothing_int_charstar
,
2480 dwarf2out_end_epilogue
,
2481 dwarf2out_begin_function
,
2482 dwarf2out_end_function
, /* end_function */
2483 dwarf2out_register_main_translation_unit
,
2484 dwarf2out_function_decl
, /* function_decl */
2485 dwarf2out_early_global_decl
,
2486 dwarf2out_late_global_decl
,
2487 dwarf2out_type_decl
, /* type_decl */
2488 dwarf2out_imported_module_or_decl
,
2489 debug_nothing_tree
, /* deferred_inline_function */
2490 /* The DWARF 2 backend tries to reduce debugging bloat by not
2491 emitting the abstract description of inline functions until
2492 something tries to reference them. */
2493 dwarf2out_abstract_function
, /* outlining_inline_function */
2494 debug_nothing_rtx_code_label
, /* label */
2495 debug_nothing_int
, /* handle_pch */
2496 dwarf2out_var_location
,
2497 dwarf2out_switch_text_section
,
2499 1, /* start_end_main_source_file */
2500 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2503 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2506 debug_nothing_charstar
,
2509 debug_nothing_int_charstar
,
2510 debug_nothing_int_charstar
,
2511 debug_nothing_int_charstar
,
2513 debug_nothing_int_int
, /* begin_block */
2514 debug_nothing_int_int
, /* end_block */
2515 debug_true_const_tree
, /* ignore_block */
2516 dwarf2out_source_line
, /* source_line */
2517 debug_nothing_int_charstar
, /* begin_prologue */
2518 debug_nothing_int_charstar
, /* end_prologue */
2519 debug_nothing_int_charstar
, /* begin_epilogue */
2520 debug_nothing_int_charstar
, /* end_epilogue */
2521 debug_nothing_tree
, /* begin_function */
2522 debug_nothing_int
, /* end_function */
2523 debug_nothing_tree
, /* register_main_translation_unit */
2524 debug_nothing_tree
, /* function_decl */
2525 debug_nothing_tree
, /* early_global_decl */
2526 debug_nothing_tree
, /* late_global_decl */
2527 debug_nothing_tree_int
, /* type_decl */
2528 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2529 debug_nothing_tree
, /* deferred_inline_function */
2530 debug_nothing_tree
, /* outlining_inline_function */
2531 debug_nothing_rtx_code_label
, /* label */
2532 debug_nothing_int
, /* handle_pch */
2533 debug_nothing_rtx_insn
, /* var_location */
2534 debug_nothing_void
, /* switch_text_section */
2535 debug_nothing_tree_tree
, /* set_name */
2536 0, /* start_end_main_source_file */
2537 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2540 /* NOTE: In the comments in this file, many references are made to
2541 "Debugging Information Entries". This term is abbreviated as `DIE'
2542 throughout the remainder of this file. */
2544 /* An internal representation of the DWARF output is built, and then
2545 walked to generate the DWARF debugging info. The walk of the internal
2546 representation is done after the entire program has been compiled.
2547 The types below are used to describe the internal representation. */
2549 /* Whether to put type DIEs into their own section .debug_types instead
2550 of making them part of the .debug_info section. Only supported for
2551 Dwarf V4 or higher and the user didn't disable them through
2552 -fno-debug-types-section. It is more efficient to put them in a
2553 separate comdat sections since the linker will then be able to
2554 remove duplicates. But not all tools support .debug_types sections
2557 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2559 /* Various DIE's use offsets relative to the beginning of the
2560 .debug_info section to refer to each other. */
2562 typedef long int dw_offset
;
2564 struct comdat_type_node
;
2566 /* The entries in the line_info table more-or-less mirror the opcodes
2567 that are used in the real dwarf line table. Arrays of these entries
2568 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2571 enum dw_line_info_opcode
{
2572 /* Emit DW_LNE_set_address; the operand is the label index. */
2575 /* Emit a row to the matrix with the given line. This may be done
2576 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2580 /* Emit a DW_LNS_set_file. */
2583 /* Emit a DW_LNS_set_column. */
2586 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2589 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2590 LI_set_prologue_end
,
2591 LI_set_epilogue_begin
,
2593 /* Emit a DW_LNE_set_discriminator. */
2594 LI_set_discriminator
2597 typedef struct GTY(()) dw_line_info_struct
{
2598 enum dw_line_info_opcode opcode
;
2600 } dw_line_info_entry
;
2603 struct GTY(()) dw_line_info_table
{
2604 /* The label that marks the end of this section. */
2605 const char *end_label
;
2607 /* The values for the last row of the matrix, as collected in the table.
2608 These are used to minimize the changes to the next row. */
2609 unsigned int file_num
;
2610 unsigned int line_num
;
2611 unsigned int column_num
;
2616 vec
<dw_line_info_entry
, va_gc
> *entries
;
2620 /* Each DIE attribute has a field specifying the attribute kind,
2621 a link to the next attribute in the chain, and an attribute value.
2622 Attributes are typically linked below the DIE they modify. */
2624 typedef struct GTY(()) dw_attr_struct
{
2625 enum dwarf_attribute dw_attr
;
2626 dw_val_node dw_attr_val
;
2631 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2632 The children of each node form a circular list linked by
2633 die_sib. die_child points to the node *before* the "first" child node. */
2635 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2636 union die_symbol_or_type_node
2638 const char * GTY ((tag ("0"))) die_symbol
;
2639 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2641 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2642 vec
<dw_attr_node
, va_gc
> *die_attr
;
2643 dw_die_ref die_parent
;
2644 dw_die_ref die_child
;
2646 dw_die_ref die_definition
; /* ref from a specification to its definition */
2647 dw_offset die_offset
;
2648 unsigned long die_abbrev
;
2650 unsigned int decl_id
;
2651 enum dwarf_tag die_tag
;
2652 /* Die is used and must not be pruned as unused. */
2653 BOOL_BITFIELD die_perennial_p
: 1;
2654 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2655 /* Lots of spare bits. */
2659 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2660 static bool early_dwarf
;
2661 struct set_early_dwarf
{
2663 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2664 ~set_early_dwarf () { early_dwarf
= saved
; }
2667 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2668 #define FOR_EACH_CHILD(die, c, expr) do { \
2669 c = die->die_child; \
2673 } while (c != die->die_child); \
2676 /* The pubname structure */
2678 typedef struct GTY(()) pubname_struct
{
2685 struct GTY(()) dw_ranges
{
2686 /* If this is positive, it's a block number, otherwise it's a
2687 bitwise-negated index into dw_ranges_by_label. */
2691 /* A structure to hold a macinfo entry. */
2693 typedef struct GTY(()) macinfo_struct
{
2695 unsigned HOST_WIDE_INT lineno
;
2701 struct GTY(()) dw_ranges_by_label
{
2706 /* The comdat type node structure. */
2707 struct GTY(()) comdat_type_node
2709 dw_die_ref root_die
;
2710 dw_die_ref type_die
;
2711 dw_die_ref skeleton_die
;
2712 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2713 comdat_type_node
*next
;
2716 /* A list of DIEs for which we can't determine ancestry (parent_die
2717 field) just yet. Later in dwarf2out_finish we will fill in the
2719 typedef struct GTY(()) limbo_die_struct
{
2721 /* The tree for which this DIE was created. We use this to
2722 determine ancestry later. */
2724 struct limbo_die_struct
*next
;
2728 typedef struct skeleton_chain_struct
2732 struct skeleton_chain_struct
*parent
;
2734 skeleton_chain_node
;
2736 /* Define a macro which returns nonzero for a TYPE_DECL which was
2737 implicitly generated for a type.
2739 Note that, unlike the C front-end (which generates a NULL named
2740 TYPE_DECL node for each complete tagged type, each array type,
2741 and each function type node created) the C++ front-end generates
2742 a _named_ TYPE_DECL node for each tagged type node created.
2743 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2744 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2745 front-end, but for each type, tagged or not. */
2747 #define TYPE_DECL_IS_STUB(decl) \
2748 (DECL_NAME (decl) == NULL_TREE \
2749 || (DECL_ARTIFICIAL (decl) \
2750 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2751 /* This is necessary for stub decls that \
2752 appear in nested inline functions. */ \
2753 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2754 && (decl_ultimate_origin (decl) \
2755 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2757 /* Information concerning the compilation unit's programming
2758 language, and compiler version. */
2760 /* Fixed size portion of the DWARF compilation unit header. */
2761 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2762 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2764 /* Fixed size portion of the DWARF comdat type unit header. */
2765 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2766 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2767 + DWARF_OFFSET_SIZE)
2769 /* Fixed size portion of public names info. */
2770 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2772 /* Fixed size portion of the address range info. */
2773 #define DWARF_ARANGES_HEADER_SIZE \
2774 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2775 DWARF2_ADDR_SIZE * 2) \
2776 - DWARF_INITIAL_LENGTH_SIZE)
2778 /* Size of padding portion in the address range info. It must be
2779 aligned to twice the pointer size. */
2780 #define DWARF_ARANGES_PAD_SIZE \
2781 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2782 DWARF2_ADDR_SIZE * 2) \
2783 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2785 /* Use assembler line directives if available. */
2786 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2787 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2788 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2790 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2794 /* Minimum line offset in a special line info. opcode.
2795 This value was chosen to give a reasonable range of values. */
2796 #define DWARF_LINE_BASE -10
2798 /* First special line opcode - leave room for the standard opcodes. */
2799 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2801 /* Range of line offsets in a special line info. opcode. */
2802 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2804 /* Flag that indicates the initial value of the is_stmt_start flag.
2805 In the present implementation, we do not mark any lines as
2806 the beginning of a source statement, because that information
2807 is not made available by the GCC front-end. */
2808 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2810 /* Maximum number of operations per instruction bundle. */
2811 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2812 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2815 /* This location is used by calc_die_sizes() to keep track
2816 the offset of each DIE within the .debug_info section. */
2817 static unsigned long next_die_offset
;
2819 /* Record the root of the DIE's built for the current compilation unit. */
2820 static GTY(()) dw_die_ref single_comp_unit_die
;
2822 /* A list of type DIEs that have been separated into comdat sections. */
2823 static GTY(()) comdat_type_node
*comdat_type_list
;
2825 /* A list of DIEs with a NULL parent waiting to be relocated. */
2826 static GTY(()) limbo_die_node
*limbo_die_list
;
2828 /* A list of DIEs for which we may have to generate
2829 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2830 static GTY(()) limbo_die_node
*deferred_asm_name
;
2832 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
2834 typedef const char *compare_type
;
2836 static hashval_t
hash (dwarf_file_data
*);
2837 static bool equal (dwarf_file_data
*, const char *);
2840 /* Filenames referenced by this compilation unit. */
2841 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2843 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
2845 typedef tree compare_type
;
2847 static hashval_t
hash (die_node
*);
2848 static bool equal (die_node
*, tree
);
2850 /* A hash table of references to DIE's that describe declarations.
2851 The key is a DECL_UID() which is a unique number identifying each decl. */
2852 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2854 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
2856 static hashval_t
hash (die_struct
*);
2857 static bool equal (die_struct
*, die_struct
*);
2860 /* A hash table of references to DIE's that describe COMMON blocks.
2861 The key is DECL_UID() ^ die_parent. */
2862 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2864 typedef struct GTY(()) die_arg_entry_struct
{
2870 /* Node of the variable location list. */
2871 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2872 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2873 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2874 in mode of the EXPR_LIST node and first EXPR_LIST operand
2875 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2876 location or NULL for padding. For larger bitsizes,
2877 mode is 0 and first operand is a CONCAT with bitsize
2878 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2879 NULL as second operand. */
2881 const char * GTY (()) label
;
2882 struct var_loc_node
* GTY (()) next
;
2885 /* Variable location list. */
2886 struct GTY ((for_user
)) var_loc_list_def
{
2887 struct var_loc_node
* GTY (()) first
;
2889 /* Pointer to the last but one or last element of the
2890 chained list. If the list is empty, both first and
2891 last are NULL, if the list contains just one node
2892 or the last node certainly is not redundant, it points
2893 to the last node, otherwise points to the last but one.
2894 Do not mark it for GC because it is marked through the chain. */
2895 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2897 /* Pointer to the last element before section switch,
2898 if NULL, either sections weren't switched or first
2899 is after section switch. */
2900 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2902 /* DECL_UID of the variable decl. */
2903 unsigned int decl_id
;
2905 typedef struct var_loc_list_def var_loc_list
;
2907 /* Call argument location list. */
2908 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2909 rtx
GTY (()) call_arg_loc_note
;
2910 const char * GTY (()) label
;
2911 tree
GTY (()) block
;
2913 rtx
GTY (()) symbol_ref
;
2914 struct call_arg_loc_node
* GTY (()) next
;
2918 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
2920 typedef const_tree compare_type
;
2922 static hashval_t
hash (var_loc_list
*);
2923 static bool equal (var_loc_list
*, const_tree
);
2926 /* Table of decl location linked lists. */
2927 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2929 /* Head and tail of call_arg_loc chain. */
2930 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2931 static struct call_arg_loc_node
*call_arg_loc_last
;
2933 /* Number of call sites in the current function. */
2934 static int call_site_count
= -1;
2935 /* Number of tail call sites in the current function. */
2936 static int tail_call_site_count
= -1;
2938 /* A cached location list. */
2939 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2940 /* The DECL_UID of the decl that this entry describes. */
2941 unsigned int decl_id
;
2943 /* The cached location list. */
2944 dw_loc_list_ref loc_list
;
2946 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2948 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
2951 typedef const_tree compare_type
;
2953 static hashval_t
hash (cached_dw_loc_list
*);
2954 static bool equal (cached_dw_loc_list
*, const_tree
);
2957 /* Table of cached location lists. */
2958 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
2960 /* A pointer to the base of a list of references to DIE's that
2961 are uniquely identified by their tag, presence/absence of
2962 children DIE's, and list of attribute/value pairs. */
2963 static GTY((length ("abbrev_die_table_allocated")))
2964 dw_die_ref
*abbrev_die_table
;
2966 /* Number of elements currently allocated for abbrev_die_table. */
2967 static GTY(()) unsigned abbrev_die_table_allocated
;
2969 /* Number of elements in abbrev_die_table currently in use. */
2970 static GTY(()) unsigned abbrev_die_table_in_use
;
2972 /* Size (in elements) of increments by which we may expand the
2973 abbrev_die_table. */
2974 #define ABBREV_DIE_TABLE_INCREMENT 256
2976 /* A global counter for generating labels for line number data. */
2977 static unsigned int line_info_label_num
;
2979 /* The current table to which we should emit line number information
2980 for the current function. This will be set up at the beginning of
2981 assembly for the function. */
2982 static dw_line_info_table
*cur_line_info_table
;
2984 /* The two default tables of line number info. */
2985 static GTY(()) dw_line_info_table
*text_section_line_info
;
2986 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2988 /* The set of all non-default tables of line number info. */
2989 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
2991 /* A flag to tell pubnames/types export if there is an info section to
2993 static bool info_section_emitted
;
2995 /* A pointer to the base of a table that contains a list of publicly
2996 accessible names. */
2997 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2999 /* A pointer to the base of a table that contains a list of publicly
3000 accessible types. */
3001 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3003 /* A pointer to the base of a table that contains a list of macro
3004 defines/undefines (and file start/end markers). */
3005 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3007 /* True if .debug_macinfo or .debug_macros section is going to be
3009 #define have_macinfo \
3010 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3011 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3012 && !macinfo_table->is_empty ())
3014 /* Array of dies for which we should generate .debug_ranges info. */
3015 static GTY ((length ("ranges_table_allocated"))) dw_ranges
*ranges_table
;
3017 /* Number of elements currently allocated for ranges_table. */
3018 static GTY(()) unsigned ranges_table_allocated
;
3020 /* Number of elements in ranges_table currently in use. */
3021 static GTY(()) unsigned ranges_table_in_use
;
3023 /* Array of pairs of labels referenced in ranges_table. */
3024 static GTY ((length ("ranges_by_label_allocated")))
3025 dw_ranges_by_label
*ranges_by_label
;
3027 /* Number of elements currently allocated for ranges_by_label. */
3028 static GTY(()) unsigned ranges_by_label_allocated
;
3030 /* Number of elements in ranges_by_label currently in use. */
3031 static GTY(()) unsigned ranges_by_label_in_use
;
3033 /* Size (in elements) of increments by which we may expand the
3035 #define RANGES_TABLE_INCREMENT 64
3037 /* Whether we have location lists that need outputting */
3038 static GTY(()) bool have_location_lists
;
3040 /* Unique label counter. */
3041 static GTY(()) unsigned int loclabel_num
;
3043 /* Unique label counter for point-of-call tables. */
3044 static GTY(()) unsigned int poc_label_num
;
3046 /* The last file entry emitted by maybe_emit_file(). */
3047 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3049 /* Number of internal labels generated by gen_internal_sym(). */
3050 static GTY(()) int label_num
;
3052 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3054 /* Instances of generic types for which we need to generate debug
3055 info that describe their generic parameters and arguments. That
3056 generation needs to happen once all types are properly laid out so
3057 we do it at the end of compilation. */
3058 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3060 /* Offset from the "steady-state frame pointer" to the frame base,
3061 within the current function. */
3062 static HOST_WIDE_INT frame_pointer_fb_offset
;
3063 static bool frame_pointer_fb_offset_valid
;
3065 static vec
<dw_die_ref
> base_types
;
3067 /* Flags to represent a set of attribute classes for attributes that represent
3068 a scalar value (bounds, pointers, ...). */
3071 dw_scalar_form_constant
= 0x01,
3072 dw_scalar_form_exprloc
= 0x02,
3073 dw_scalar_form_reference
= 0x04
3076 /* Forward declarations for functions defined in this file. */
3078 static int is_pseudo_reg (const_rtx
);
3079 static tree
type_main_variant (tree
);
3080 static int is_tagged_type (const_tree
);
3081 static const char *dwarf_tag_name (unsigned);
3082 static const char *dwarf_attr_name (unsigned);
3083 static const char *dwarf_form_name (unsigned);
3084 static tree
decl_ultimate_origin (const_tree
);
3085 static tree
decl_class_context (tree
);
3086 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3087 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3088 static inline unsigned int AT_index (dw_attr_node
*);
3089 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3090 static inline unsigned AT_flag (dw_attr_node
*);
3091 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3092 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3093 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3094 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3095 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3096 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3097 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3098 unsigned int, unsigned char *);
3099 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3100 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3101 static inline const char *AT_string (dw_attr_node
*);
3102 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3103 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3104 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3105 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3106 static inline int AT_ref_external (dw_attr_node
*);
3107 static inline void set_AT_ref_external (dw_attr_node
*, int);
3108 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3109 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3110 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3111 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3113 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3114 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3115 static void remove_addr_table_entry (addr_table_entry
*);
3116 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3117 static inline rtx
AT_addr (dw_attr_node
*);
3118 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3119 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3120 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3121 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3122 unsigned HOST_WIDE_INT
);
3123 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3124 unsigned long, bool);
3125 static inline const char *AT_lbl (dw_attr_node
*);
3126 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3127 static const char *get_AT_low_pc (dw_die_ref
);
3128 static const char *get_AT_hi_pc (dw_die_ref
);
3129 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3130 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3131 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3132 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3133 static bool is_cxx (void);
3134 static bool is_fortran (void);
3135 static bool is_ada (void);
3136 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3137 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3138 static void add_child_die (dw_die_ref
, dw_die_ref
);
3139 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3140 static dw_die_ref
lookup_type_die (tree
);
3141 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3142 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3143 static void equate_type_number_to_die (tree
, dw_die_ref
);
3144 static dw_die_ref
lookup_decl_die (tree
);
3145 static var_loc_list
*lookup_decl_loc (const_tree
);
3146 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3147 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3148 static void print_spaces (FILE *);
3149 static void print_die (dw_die_ref
, FILE *);
3150 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3151 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3152 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3153 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3154 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3155 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3156 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3157 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3158 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3159 struct md5_ctx
*, int *);
3160 struct checksum_attributes
;
3161 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3162 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3163 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3164 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3165 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3166 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3167 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3168 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3169 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3170 static void compute_section_prefix (dw_die_ref
);
3171 static int is_type_die (dw_die_ref
);
3172 static int is_comdat_die (dw_die_ref
);
3173 static int is_symbol_die (dw_die_ref
);
3174 static inline bool is_template_instantiation (dw_die_ref
);
3175 static void assign_symbol_names (dw_die_ref
);
3176 static void break_out_includes (dw_die_ref
);
3177 static int is_declaration_die (dw_die_ref
);
3178 static int should_move_die_to_comdat (dw_die_ref
);
3179 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3180 static dw_die_ref
clone_die (dw_die_ref
);
3181 static dw_die_ref
clone_tree (dw_die_ref
);
3182 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3183 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3184 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3185 static dw_die_ref
generate_skeleton (dw_die_ref
);
3186 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3189 static void break_out_comdat_types (dw_die_ref
);
3190 static void copy_decls_for_unworthy_types (dw_die_ref
);
3192 static void add_sibling_attributes (dw_die_ref
);
3193 static void output_location_lists (dw_die_ref
);
3194 static int constant_size (unsigned HOST_WIDE_INT
);
3195 static unsigned long size_of_die (dw_die_ref
);
3196 static void calc_die_sizes (dw_die_ref
);
3197 static void calc_base_type_die_sizes (void);
3198 static void mark_dies (dw_die_ref
);
3199 static void unmark_dies (dw_die_ref
);
3200 static void unmark_all_dies (dw_die_ref
);
3201 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3202 static unsigned long size_of_aranges (void);
3203 static enum dwarf_form
value_format (dw_attr_node
*);
3204 static void output_value_format (dw_attr_node
*);
3205 static void output_abbrev_section (void);
3206 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3207 static void output_die_symbol (dw_die_ref
);
3208 static void output_die (dw_die_ref
);
3209 static void output_compilation_unit_header (void);
3210 static void output_comp_unit (dw_die_ref
, int);
3211 static void output_comdat_type_unit (comdat_type_node
*);
3212 static const char *dwarf2_name (tree
, int);
3213 static void add_pubname (tree
, dw_die_ref
);
3214 static void add_enumerator_pubname (const char *, dw_die_ref
);
3215 static void add_pubname_string (const char *, dw_die_ref
);
3216 static void add_pubtype (tree
, dw_die_ref
);
3217 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3218 static void output_aranges (void);
3219 static unsigned int add_ranges_num (int);
3220 static unsigned int add_ranges (const_tree
);
3221 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3223 static void output_ranges (void);
3224 static dw_line_info_table
*new_line_info_table (void);
3225 static void output_line_info (bool);
3226 static void output_file_names (void);
3227 static dw_die_ref
base_type_die (tree
);
3228 static int is_base_type (tree
);
3229 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3230 static int decl_quals (const_tree
);
3231 static dw_die_ref
modified_type_die (tree
, int, dw_die_ref
);
3232 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3233 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3234 static int type_is_enum (const_tree
);
3235 static unsigned int dbx_reg_number (const_rtx
);
3236 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3237 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3238 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3239 enum var_init_status
);
3240 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3241 enum var_init_status
);
3242 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3243 enum var_init_status
);
3244 static int is_based_loc (const_rtx
);
3245 static bool resolve_one_addr (rtx
*);
3246 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3247 enum var_init_status
);
3248 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3249 enum var_init_status
);
3250 struct loc_descr_context
;
3251 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3252 const struct loc_descr_context
*);
3253 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3254 const struct loc_descr_context
*);
3255 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3256 static tree
field_type (const_tree
);
3257 static unsigned int simple_type_align_in_bits (const_tree
);
3258 static unsigned int simple_decl_align_in_bits (const_tree
);
3259 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3260 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3261 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3263 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3264 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3265 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3266 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3267 static void insert_float (const_rtx
, unsigned char *);
3268 static rtx
rtl_for_decl_location (tree
);
3269 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3270 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3271 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3272 static void add_name_attribute (dw_die_ref
, const char *);
3273 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3274 static void add_comp_dir_attribute (dw_die_ref
);
3275 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3276 const struct loc_descr_context
*);
3277 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3278 const struct loc_descr_context
*);
3279 static void add_subscript_info (dw_die_ref
, tree
, bool);
3280 static void add_byte_size_attribute (dw_die_ref
, tree
);
3281 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3282 static void add_bit_size_attribute (dw_die_ref
, tree
);
3283 static void add_prototyped_attribute (dw_die_ref
, tree
);
3284 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3285 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3286 static void add_src_coords_attributes (dw_die_ref
, tree
);
3287 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3288 static void push_decl_scope (tree
);
3289 static void pop_decl_scope (void);
3290 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3291 static inline int local_scope_p (dw_die_ref
);
3292 static inline int class_scope_p (dw_die_ref
);
3293 static inline int class_or_namespace_scope_p (dw_die_ref
);
3294 static void add_type_attribute (dw_die_ref
, tree
, int, dw_die_ref
);
3295 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3296 static const char *type_tag (const_tree
);
3297 static tree
member_declared_type (const_tree
);
3299 static const char *decl_start_label (tree
);
3301 static void gen_array_type_die (tree
, dw_die_ref
);
3302 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3304 static void gen_entry_point_die (tree
, dw_die_ref
);
3306 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3307 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3308 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3309 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3310 static void gen_formal_types_die (tree
, dw_die_ref
);
3311 static void gen_subprogram_die (tree
, dw_die_ref
);
3312 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3313 static void gen_const_die (tree
, dw_die_ref
);
3314 static void gen_label_die (tree
, dw_die_ref
);
3315 static void gen_lexical_block_die (tree
, dw_die_ref
);
3316 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3317 static void gen_field_die (tree
, dw_die_ref
);
3318 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3319 static dw_die_ref
gen_compile_unit_die (const char *);
3320 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3321 static void gen_member_die (tree
, dw_die_ref
);
3322 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3323 enum debug_info_usage
);
3324 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3325 static void gen_typedef_die (tree
, dw_die_ref
);
3326 static void gen_type_die (tree
, dw_die_ref
);
3327 static void gen_block_die (tree
, dw_die_ref
);
3328 static void decls_for_scope (tree
, dw_die_ref
);
3329 static inline int is_redundant_typedef (const_tree
);
3330 static bool is_naming_typedef_decl (const_tree
);
3331 static inline dw_die_ref
get_context_die (tree
);
3332 static void gen_namespace_die (tree
, dw_die_ref
);
3333 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3334 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3335 static dw_die_ref
force_decl_die (tree
);
3336 static dw_die_ref
force_type_die (tree
);
3337 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3338 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3339 static struct dwarf_file_data
* lookup_filename (const char *);
3340 static void retry_incomplete_types (void);
3341 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3342 static void gen_generic_params_dies (tree
);
3343 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3344 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3345 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3346 static int file_info_cmp (const void *, const void *);
3347 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3348 const char *, const char *);
3349 static void output_loc_list (dw_loc_list_ref
);
3350 static char *gen_internal_sym (const char *);
3351 static bool want_pubnames (void);
3353 static void prune_unmark_dies (dw_die_ref
);
3354 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3355 static void prune_unused_types_mark (dw_die_ref
, int);
3356 static void prune_unused_types_walk (dw_die_ref
);
3357 static void prune_unused_types_walk_attribs (dw_die_ref
);
3358 static void prune_unused_types_prune (dw_die_ref
);
3359 static void prune_unused_types (void);
3360 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3361 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3362 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3363 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3364 const char *, const char *);
3365 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3366 static void gen_remaining_tmpl_value_param_die_attribute (void);
3367 static bool generic_type_p (tree
);
3368 static void schedule_generic_params_dies_gen (tree t
);
3369 static void gen_scheduled_generic_parms_dies (void);
3371 static const char *comp_dir_string (void);
3373 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3375 /* enum for tracking thread-local variables whose address is really an offset
3376 relative to the TLS pointer, which will need link-time relocation, but will
3377 not need relocation by the DWARF consumer. */
3385 /* Return the operator to use for an address of a variable. For dtprel_true, we
3386 use DW_OP_const*. For regular variables, which need both link-time
3387 relocation and consumer-level relocation (e.g., to account for shared objects
3388 loaded at a random address), we use DW_OP_addr*. */
3390 static inline enum dwarf_location_atom
3391 dw_addr_op (enum dtprel_bool dtprel
)
3393 if (dtprel
== dtprel_true
)
3394 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3395 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3397 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3400 /* Return a pointer to a newly allocated address location description. If
3401 dwarf_split_debug_info is true, then record the address with the appropriate
3403 static inline dw_loc_descr_ref
3404 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3406 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3408 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3409 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3410 ref
->dtprel
= dtprel
;
3411 if (dwarf_split_debug_info
)
3412 ref
->dw_loc_oprnd1
.val_entry
3413 = add_addr_table_entry (addr
,
3414 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3416 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3421 /* Section names used to hold DWARF debugging information. */
3423 #ifndef DEBUG_INFO_SECTION
3424 #define DEBUG_INFO_SECTION ".debug_info"
3426 #ifndef DEBUG_DWO_INFO_SECTION
3427 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3429 #ifndef DEBUG_ABBREV_SECTION
3430 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3432 #ifndef DEBUG_DWO_ABBREV_SECTION
3433 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3435 #ifndef DEBUG_ARANGES_SECTION
3436 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3438 #ifndef DEBUG_ADDR_SECTION
3439 #define DEBUG_ADDR_SECTION ".debug_addr"
3441 #ifndef DEBUG_NORM_MACINFO_SECTION
3442 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3444 #ifndef DEBUG_DWO_MACINFO_SECTION
3445 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3447 #ifndef DEBUG_MACINFO_SECTION
3448 #define DEBUG_MACINFO_SECTION \
3449 (!dwarf_split_debug_info \
3450 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3452 #ifndef DEBUG_NORM_MACRO_SECTION
3453 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3455 #ifndef DEBUG_DWO_MACRO_SECTION
3456 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3458 #ifndef DEBUG_MACRO_SECTION
3459 #define DEBUG_MACRO_SECTION \
3460 (!dwarf_split_debug_info \
3461 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3463 #ifndef DEBUG_LINE_SECTION
3464 #define DEBUG_LINE_SECTION ".debug_line"
3466 #ifndef DEBUG_DWO_LINE_SECTION
3467 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3469 #ifndef DEBUG_LOC_SECTION
3470 #define DEBUG_LOC_SECTION ".debug_loc"
3472 #ifndef DEBUG_DWO_LOC_SECTION
3473 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3475 #ifndef DEBUG_PUBNAMES_SECTION
3476 #define DEBUG_PUBNAMES_SECTION \
3477 ((debug_generate_pub_sections == 2) \
3478 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3480 #ifndef DEBUG_PUBTYPES_SECTION
3481 #define DEBUG_PUBTYPES_SECTION \
3482 ((debug_generate_pub_sections == 2) \
3483 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3485 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3486 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3487 #ifndef DEBUG_STR_OFFSETS_SECTION
3488 #define DEBUG_STR_OFFSETS_SECTION \
3489 (!dwarf_split_debug_info \
3490 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3492 #ifndef DEBUG_STR_DWO_SECTION
3493 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3495 #ifndef DEBUG_STR_SECTION
3496 #define DEBUG_STR_SECTION ".debug_str"
3498 #ifndef DEBUG_RANGES_SECTION
3499 #define DEBUG_RANGES_SECTION ".debug_ranges"
3502 /* Standard ELF section names for compiled code and data. */
3503 #ifndef TEXT_SECTION_NAME
3504 #define TEXT_SECTION_NAME ".text"
3507 /* Section flags for .debug_macinfo/.debug_macro section. */
3508 #define DEBUG_MACRO_SECTION_FLAGS \
3509 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3511 /* Section flags for .debug_str section. */
3512 #define DEBUG_STR_SECTION_FLAGS \
3513 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3514 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3517 /* Section flags for .debug_str.dwo section. */
3518 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3520 /* Labels we insert at beginning sections we can reference instead of
3521 the section names themselves. */
3523 #ifndef TEXT_SECTION_LABEL
3524 #define TEXT_SECTION_LABEL "Ltext"
3526 #ifndef COLD_TEXT_SECTION_LABEL
3527 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3529 #ifndef DEBUG_LINE_SECTION_LABEL
3530 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3532 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3533 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3535 #ifndef DEBUG_INFO_SECTION_LABEL
3536 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3538 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3539 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3541 #ifndef DEBUG_ABBREV_SECTION_LABEL
3542 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3544 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3545 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3547 #ifndef DEBUG_ADDR_SECTION_LABEL
3548 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3550 #ifndef DEBUG_LOC_SECTION_LABEL
3551 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3553 #ifndef DEBUG_RANGES_SECTION_LABEL
3554 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3556 #ifndef DEBUG_MACINFO_SECTION_LABEL
3557 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3559 #ifndef DEBUG_MACRO_SECTION_LABEL
3560 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3562 #define SKELETON_COMP_DIE_ABBREV 1
3563 #define SKELETON_TYPE_DIE_ABBREV 2
3565 /* Definitions of defaults for formats and names of various special
3566 (artificial) labels which may be generated within this file (when the -g
3567 options is used and DWARF2_DEBUGGING_INFO is in effect.
3568 If necessary, these may be overridden from within the tm.h file, but
3569 typically, overriding these defaults is unnecessary. */
3571 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3572 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3573 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3574 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3575 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3576 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3577 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3578 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3579 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3580 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3581 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3582 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3583 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3584 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3586 #ifndef TEXT_END_LABEL
3587 #define TEXT_END_LABEL "Letext"
3589 #ifndef COLD_END_LABEL
3590 #define COLD_END_LABEL "Letext_cold"
3592 #ifndef BLOCK_BEGIN_LABEL
3593 #define BLOCK_BEGIN_LABEL "LBB"
3595 #ifndef BLOCK_END_LABEL
3596 #define BLOCK_END_LABEL "LBE"
3598 #ifndef LINE_CODE_LABEL
3599 #define LINE_CODE_LABEL "LM"
3603 /* Return the root of the DIE's built for the current compilation unit. */
3605 comp_unit_die (void)
3607 if (!single_comp_unit_die
)
3608 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3609 return single_comp_unit_die
;
3612 /* We allow a language front-end to designate a function that is to be
3613 called to "demangle" any name before it is put into a DIE. */
3615 static const char *(*demangle_name_func
) (const char *);
3618 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3620 demangle_name_func
= func
;
3623 /* Test if rtl node points to a pseudo register. */
3626 is_pseudo_reg (const_rtx rtl
)
3628 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3629 || (GET_CODE (rtl
) == SUBREG
3630 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3633 /* Return a reference to a type, with its const and volatile qualifiers
3637 type_main_variant (tree type
)
3639 type
= TYPE_MAIN_VARIANT (type
);
3641 /* ??? There really should be only one main variant among any group of
3642 variants of a given type (and all of the MAIN_VARIANT values for all
3643 members of the group should point to that one type) but sometimes the C
3644 front-end messes this up for array types, so we work around that bug
3646 if (TREE_CODE (type
) == ARRAY_TYPE
)
3647 while (type
!= TYPE_MAIN_VARIANT (type
))
3648 type
= TYPE_MAIN_VARIANT (type
);
3653 /* Return nonzero if the given type node represents a tagged type. */
3656 is_tagged_type (const_tree type
)
3658 enum tree_code code
= TREE_CODE (type
);
3660 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3661 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3664 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3667 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3669 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3672 /* Return die_offset of a DIE reference to a base type. */
3674 static unsigned long int
3675 get_base_type_offset (dw_die_ref ref
)
3677 if (ref
->die_offset
)
3678 return ref
->die_offset
;
3679 if (comp_unit_die ()->die_abbrev
)
3681 calc_base_type_die_sizes ();
3682 gcc_assert (ref
->die_offset
);
3684 return ref
->die_offset
;
3687 /* Return die_offset of a DIE reference other than base type. */
3689 static unsigned long int
3690 get_ref_die_offset (dw_die_ref ref
)
3692 gcc_assert (ref
->die_offset
);
3693 return ref
->die_offset
;
3696 /* Convert a DIE tag into its string name. */
3699 dwarf_tag_name (unsigned int tag
)
3701 const char *name
= get_DW_TAG_name (tag
);
3706 return "DW_TAG_<unknown>";
3709 /* Convert a DWARF attribute code into its string name. */
3712 dwarf_attr_name (unsigned int attr
)
3718 #if VMS_DEBUGGING_INFO
3719 case DW_AT_HP_prologue
:
3720 return "DW_AT_HP_prologue";
3722 case DW_AT_MIPS_loop_unroll_factor
:
3723 return "DW_AT_MIPS_loop_unroll_factor";
3726 #if VMS_DEBUGGING_INFO
3727 case DW_AT_HP_epilogue
:
3728 return "DW_AT_HP_epilogue";
3730 case DW_AT_MIPS_stride
:
3731 return "DW_AT_MIPS_stride";
3735 name
= get_DW_AT_name (attr
);
3740 return "DW_AT_<unknown>";
3743 /* Convert a DWARF value form code into its string name. */
3746 dwarf_form_name (unsigned int form
)
3748 const char *name
= get_DW_FORM_name (form
);
3753 return "DW_FORM_<unknown>";
3756 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3757 instance of an inlined instance of a decl which is local to an inline
3758 function, so we have to trace all of the way back through the origin chain
3759 to find out what sort of node actually served as the original seed for the
3763 decl_ultimate_origin (const_tree decl
)
3765 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3768 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3769 we're trying to output the abstract instance of this function. */
3770 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3773 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3774 most distant ancestor, this should never happen. */
3775 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3777 return DECL_ABSTRACT_ORIGIN (decl
);
3780 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3781 of a virtual function may refer to a base class, so we check the 'this'
3785 decl_class_context (tree decl
)
3787 tree context
= NULL_TREE
;
3789 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3790 context
= DECL_CONTEXT (decl
);
3792 context
= TYPE_MAIN_VARIANT
3793 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3795 if (context
&& !TYPE_P (context
))
3796 context
= NULL_TREE
;
3801 /* Add an attribute/value pair to a DIE. */
3804 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
3806 /* Maybe this should be an assert? */
3810 vec_safe_reserve (die
->die_attr
, 1);
3811 vec_safe_push (die
->die_attr
, *attr
);
3814 static inline enum dw_val_class
3815 AT_class (dw_attr_node
*a
)
3817 return a
->dw_attr_val
.val_class
;
3820 /* Return the index for any attribute that will be referenced with a
3821 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3822 are stored in dw_attr_val.v.val_str for reference counting
3825 static inline unsigned int
3826 AT_index (dw_attr_node
*a
)
3828 if (AT_class (a
) == dw_val_class_str
)
3829 return a
->dw_attr_val
.v
.val_str
->index
;
3830 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3831 return a
->dw_attr_val
.val_entry
->index
;
3835 /* Add a flag value attribute to a DIE. */
3838 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3842 attr
.dw_attr
= attr_kind
;
3843 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3844 attr
.dw_attr_val
.val_entry
= NULL
;
3845 attr
.dw_attr_val
.v
.val_flag
= flag
;
3846 add_dwarf_attr (die
, &attr
);
3849 static inline unsigned
3850 AT_flag (dw_attr_node
*a
)
3852 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3853 return a
->dw_attr_val
.v
.val_flag
;
3856 /* Add a signed integer attribute value to a DIE. */
3859 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3863 attr
.dw_attr
= attr_kind
;
3864 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3865 attr
.dw_attr_val
.val_entry
= NULL
;
3866 attr
.dw_attr_val
.v
.val_int
= int_val
;
3867 add_dwarf_attr (die
, &attr
);
3870 static inline HOST_WIDE_INT
3871 AT_int (dw_attr_node
*a
)
3873 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3874 return a
->dw_attr_val
.v
.val_int
;
3877 /* Add an unsigned integer attribute value to a DIE. */
3880 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3881 unsigned HOST_WIDE_INT unsigned_val
)
3885 attr
.dw_attr
= attr_kind
;
3886 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3887 attr
.dw_attr_val
.val_entry
= NULL
;
3888 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3889 add_dwarf_attr (die
, &attr
);
3892 static inline unsigned HOST_WIDE_INT
3893 AT_unsigned (dw_attr_node
*a
)
3895 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3896 return a
->dw_attr_val
.v
.val_unsigned
;
3899 /* Add an unsigned wide integer attribute value to a DIE. */
3902 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3907 attr
.dw_attr
= attr_kind
;
3908 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3909 attr
.dw_attr_val
.val_entry
= NULL
;
3910 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3911 *attr
.dw_attr_val
.v
.val_wide
= w
;
3912 add_dwarf_attr (die
, &attr
);
3915 /* Add an unsigned double integer attribute value to a DIE. */
3918 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3919 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3923 attr
.dw_attr
= attr_kind
;
3924 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3925 attr
.dw_attr_val
.val_entry
= NULL
;
3926 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3927 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3928 add_dwarf_attr (die
, &attr
);
3931 /* Add a floating point attribute value to a DIE and return it. */
3934 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3935 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3939 attr
.dw_attr
= attr_kind
;
3940 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3941 attr
.dw_attr_val
.val_entry
= NULL
;
3942 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3943 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3944 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3945 add_dwarf_attr (die
, &attr
);
3948 /* Add an 8-byte data attribute value to a DIE. */
3951 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3952 unsigned char data8
[8])
3956 attr
.dw_attr
= attr_kind
;
3957 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3958 attr
.dw_attr_val
.val_entry
= NULL
;
3959 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3960 add_dwarf_attr (die
, &attr
);
3963 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3964 dwarf_split_debug_info, address attributes in dies destined for the
3965 final executable have force_direct set to avoid using indexed
3969 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3975 lbl_id
= xstrdup (lbl_low
);
3976 attr
.dw_attr
= DW_AT_low_pc
;
3977 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3978 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3979 if (dwarf_split_debug_info
&& !force_direct
)
3980 attr
.dw_attr_val
.val_entry
3981 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3983 attr
.dw_attr_val
.val_entry
= NULL
;
3984 add_dwarf_attr (die
, &attr
);
3986 attr
.dw_attr
= DW_AT_high_pc
;
3987 if (dwarf_version
< 4)
3988 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3990 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3991 lbl_id
= xstrdup (lbl_high
);
3992 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3993 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3994 && dwarf_split_debug_info
&& !force_direct
)
3995 attr
.dw_attr_val
.val_entry
3996 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3998 attr
.dw_attr_val
.val_entry
= NULL
;
3999 add_dwarf_attr (die
, &attr
);
4002 /* Hash and equality functions for debug_str_hash. */
4005 indirect_string_hasher::hash (indirect_string_node
*x
)
4007 return htab_hash_string (x
->str
);
4011 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4013 return strcmp (x1
->str
, x2
) == 0;
4016 /* Add STR to the given string hash table. */
4018 static struct indirect_string_node
*
4019 find_AT_string_in_table (const char *str
,
4020 hash_table
<indirect_string_hasher
> *table
)
4022 struct indirect_string_node
*node
;
4024 indirect_string_node
**slot
4025 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4028 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4029 node
->str
= ggc_strdup (str
);
4039 /* Add STR to the indirect string hash table. */
4041 static struct indirect_string_node
*
4042 find_AT_string (const char *str
)
4044 if (! debug_str_hash
)
4045 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4047 return find_AT_string_in_table (str
, debug_str_hash
);
4050 /* Add a string attribute value to a DIE. */
4053 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4056 struct indirect_string_node
*node
;
4058 node
= find_AT_string (str
);
4060 attr
.dw_attr
= attr_kind
;
4061 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4062 attr
.dw_attr_val
.val_entry
= NULL
;
4063 attr
.dw_attr_val
.v
.val_str
= node
;
4064 add_dwarf_attr (die
, &attr
);
4067 static inline const char *
4068 AT_string (dw_attr_node
*a
)
4070 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4071 return a
->dw_attr_val
.v
.val_str
->str
;
4074 /* Call this function directly to bypass AT_string_form's logic to put
4075 the string inline in the die. */
4078 set_indirect_string (struct indirect_string_node
*node
)
4081 /* Already indirect is a no op. */
4082 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4084 gcc_assert (node
->label
);
4087 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4088 ++dw2_string_counter
;
4089 node
->label
= xstrdup (label
);
4091 if (!dwarf_split_debug_info
)
4093 node
->form
= DW_FORM_strp
;
4094 node
->index
= NOT_INDEXED
;
4098 node
->form
= DW_FORM_GNU_str_index
;
4099 node
->index
= NO_INDEX_ASSIGNED
;
4103 /* Find out whether a string should be output inline in DIE
4104 or out-of-line in .debug_str section. */
4106 static enum dwarf_form
4107 find_string_form (struct indirect_string_node
*node
)
4114 len
= strlen (node
->str
) + 1;
4116 /* If the string is shorter or equal to the size of the reference, it is
4117 always better to put it inline. */
4118 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4119 return node
->form
= DW_FORM_string
;
4121 /* If we cannot expect the linker to merge strings in .debug_str
4122 section, only put it into .debug_str if it is worth even in this
4124 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4125 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4126 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4127 return node
->form
= DW_FORM_string
;
4129 set_indirect_string (node
);
4134 /* Find out whether the string referenced from the attribute should be
4135 output inline in DIE or out-of-line in .debug_str section. */
4137 static enum dwarf_form
4138 AT_string_form (dw_attr_node
*a
)
4140 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4141 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4144 /* Add a DIE reference attribute value to a DIE. */
4147 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4150 gcc_checking_assert (targ_die
!= NULL
);
4152 /* With LTO we can end up trying to reference something we didn't create
4153 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4154 if (targ_die
== NULL
)
4157 attr
.dw_attr
= attr_kind
;
4158 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4159 attr
.dw_attr_val
.val_entry
= NULL
;
4160 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4161 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4162 add_dwarf_attr (die
, &attr
);
4165 /* Change DIE reference REF to point to NEW_DIE instead. */
4168 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4170 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4171 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4172 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4175 /* Add an AT_specification attribute to a DIE, and also make the back
4176 pointer from the specification to the definition. */
4179 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4181 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4182 gcc_assert (!targ_die
->die_definition
);
4183 targ_die
->die_definition
= die
;
4186 static inline dw_die_ref
4187 AT_ref (dw_attr_node
*a
)
4189 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4190 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4194 AT_ref_external (dw_attr_node
*a
)
4196 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4197 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4203 set_AT_ref_external (dw_attr_node
*a
, int i
)
4205 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4206 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4209 /* Add an FDE reference attribute value to a DIE. */
4212 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4216 attr
.dw_attr
= attr_kind
;
4217 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4218 attr
.dw_attr_val
.val_entry
= NULL
;
4219 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4220 add_dwarf_attr (die
, &attr
);
4223 /* Add a location description attribute value to a DIE. */
4226 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4230 attr
.dw_attr
= attr_kind
;
4231 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4232 attr
.dw_attr_val
.val_entry
= NULL
;
4233 attr
.dw_attr_val
.v
.val_loc
= loc
;
4234 add_dwarf_attr (die
, &attr
);
4237 static inline dw_loc_descr_ref
4238 AT_loc (dw_attr_node
*a
)
4240 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4241 return a
->dw_attr_val
.v
.val_loc
;
4245 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4249 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4252 attr
.dw_attr
= attr_kind
;
4253 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4254 attr
.dw_attr_val
.val_entry
= NULL
;
4255 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4256 add_dwarf_attr (die
, &attr
);
4257 have_location_lists
= true;
4260 static inline dw_loc_list_ref
4261 AT_loc_list (dw_attr_node
*a
)
4263 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4264 return a
->dw_attr_val
.v
.val_loc_list
;
4267 static inline dw_loc_list_ref
*
4268 AT_loc_list_ptr (dw_attr_node
*a
)
4270 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4271 return &a
->dw_attr_val
.v
.val_loc_list
;
4274 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4276 static hashval_t
hash (addr_table_entry
*);
4277 static bool equal (addr_table_entry
*, addr_table_entry
*);
4280 /* Table of entries into the .debug_addr section. */
4282 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4284 /* Hash an address_table_entry. */
4287 addr_hasher::hash (addr_table_entry
*a
)
4289 inchash::hash hstate
;
4295 case ate_kind_rtx_dtprel
:
4298 case ate_kind_label
:
4299 return htab_hash_string (a
->addr
.label
);
4303 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4304 return hstate
.end ();
4307 /* Determine equality for two address_table_entries. */
4310 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4312 if (a1
->kind
!= a2
->kind
)
4317 case ate_kind_rtx_dtprel
:
4318 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4319 case ate_kind_label
:
4320 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4326 /* Initialize an addr_table_entry. */
4329 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4335 case ate_kind_rtx_dtprel
:
4336 e
->addr
.rtl
= (rtx
) addr
;
4338 case ate_kind_label
:
4339 e
->addr
.label
= (char *) addr
;
4343 e
->index
= NO_INDEX_ASSIGNED
;
4346 /* Add attr to the address table entry to the table. Defer setting an
4347 index until output time. */
4349 static addr_table_entry
*
4350 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4352 addr_table_entry
*node
;
4353 addr_table_entry finder
;
4355 gcc_assert (dwarf_split_debug_info
);
4356 if (! addr_index_table
)
4357 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4358 init_addr_table_entry (&finder
, kind
, addr
);
4359 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4361 if (*slot
== HTAB_EMPTY_ENTRY
)
4363 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4364 init_addr_table_entry (node
, kind
, addr
);
4374 /* Remove an entry from the addr table by decrementing its refcount.
4375 Strictly, decrementing the refcount would be enough, but the
4376 assertion that the entry is actually in the table has found
4380 remove_addr_table_entry (addr_table_entry
*entry
)
4382 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4383 /* After an index is assigned, the table is frozen. */
4384 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4388 /* Given a location list, remove all addresses it refers to from the
4392 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4394 for (; descr
; descr
= descr
->dw_loc_next
)
4395 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4397 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4398 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4402 /* A helper function for dwarf2out_finish called through
4403 htab_traverse. Assign an addr_table_entry its index. All entries
4404 must be collected into the table when this function is called,
4405 because the indexing code relies on htab_traverse to traverse nodes
4406 in the same order for each run. */
4409 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4411 addr_table_entry
*node
= *h
;
4413 /* Don't index unreferenced nodes. */
4414 if (node
->refcount
== 0)
4417 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4418 node
->index
= *index
;
4424 /* Add an address constant attribute value to a DIE. When using
4425 dwarf_split_debug_info, address attributes in dies destined for the
4426 final executable should be direct references--setting the parameter
4427 force_direct ensures this behavior. */
4430 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4435 attr
.dw_attr
= attr_kind
;
4436 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4437 attr
.dw_attr_val
.v
.val_addr
= addr
;
4438 if (dwarf_split_debug_info
&& !force_direct
)
4439 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4441 attr
.dw_attr_val
.val_entry
= NULL
;
4442 add_dwarf_attr (die
, &attr
);
4445 /* Get the RTX from to an address DIE attribute. */
4448 AT_addr (dw_attr_node
*a
)
4450 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4451 return a
->dw_attr_val
.v
.val_addr
;
4454 /* Add a file attribute value to a DIE. */
4457 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4458 struct dwarf_file_data
*fd
)
4462 attr
.dw_attr
= attr_kind
;
4463 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4464 attr
.dw_attr_val
.val_entry
= NULL
;
4465 attr
.dw_attr_val
.v
.val_file
= fd
;
4466 add_dwarf_attr (die
, &attr
);
4469 /* Get the dwarf_file_data from a file DIE attribute. */
4471 static inline struct dwarf_file_data
*
4472 AT_file (dw_attr_node
*a
)
4474 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4475 return a
->dw_attr_val
.v
.val_file
;
4478 /* Add a vms delta attribute value to a DIE. */
4481 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4482 const char *lbl1
, const char *lbl2
)
4486 attr
.dw_attr
= attr_kind
;
4487 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4488 attr
.dw_attr_val
.val_entry
= NULL
;
4489 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4490 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4491 add_dwarf_attr (die
, &attr
);
4494 /* Add a label identifier attribute value to a DIE. */
4497 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4502 attr
.dw_attr
= attr_kind
;
4503 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4504 attr
.dw_attr_val
.val_entry
= NULL
;
4505 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4506 if (dwarf_split_debug_info
)
4507 attr
.dw_attr_val
.val_entry
4508 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4510 add_dwarf_attr (die
, &attr
);
4513 /* Add a section offset attribute value to a DIE, an offset into the
4514 debug_line section. */
4517 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4522 attr
.dw_attr
= attr_kind
;
4523 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4524 attr
.dw_attr_val
.val_entry
= NULL
;
4525 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4526 add_dwarf_attr (die
, &attr
);
4529 /* Add a section offset attribute value to a DIE, an offset into the
4530 debug_macinfo section. */
4533 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4538 attr
.dw_attr
= attr_kind
;
4539 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4540 attr
.dw_attr_val
.val_entry
= NULL
;
4541 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4542 add_dwarf_attr (die
, &attr
);
4545 /* Add an offset attribute value to a DIE. */
4548 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4549 unsigned HOST_WIDE_INT offset
)
4553 attr
.dw_attr
= attr_kind
;
4554 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4555 attr
.dw_attr_val
.val_entry
= NULL
;
4556 attr
.dw_attr_val
.v
.val_offset
= offset
;
4557 add_dwarf_attr (die
, &attr
);
4560 /* Add a range_list attribute value to a DIE. When using
4561 dwarf_split_debug_info, address attributes in dies destined for the
4562 final executable should be direct references--setting the parameter
4563 force_direct ensures this behavior. */
4565 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4566 #define RELOCATED_OFFSET (NULL)
4569 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4570 long unsigned int offset
, bool force_direct
)
4574 attr
.dw_attr
= attr_kind
;
4575 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4576 /* For the range_list attribute, use val_entry to store whether the
4577 offset should follow split-debug-info or normal semantics. This
4578 value is read in output_range_list_offset. */
4579 if (dwarf_split_debug_info
&& !force_direct
)
4580 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4582 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4583 attr
.dw_attr_val
.v
.val_offset
= offset
;
4584 add_dwarf_attr (die
, &attr
);
4587 /* Return the start label of a delta attribute. */
4589 static inline const char *
4590 AT_vms_delta1 (dw_attr_node
*a
)
4592 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4593 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4596 /* Return the end label of a delta attribute. */
4598 static inline const char *
4599 AT_vms_delta2 (dw_attr_node
*a
)
4601 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4602 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4605 static inline const char *
4606 AT_lbl (dw_attr_node
*a
)
4608 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4609 || AT_class (a
) == dw_val_class_lineptr
4610 || AT_class (a
) == dw_val_class_macptr
4611 || AT_class (a
) == dw_val_class_high_pc
));
4612 return a
->dw_attr_val
.v
.val_lbl_id
;
4615 /* Get the attribute of type attr_kind. */
4617 static dw_attr_node
*
4618 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4622 dw_die_ref spec
= NULL
;
4627 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4628 if (a
->dw_attr
== attr_kind
)
4630 else if (a
->dw_attr
== DW_AT_specification
4631 || a
->dw_attr
== DW_AT_abstract_origin
)
4635 return get_AT (spec
, attr_kind
);
4640 /* Returns the parent of the declaration of DIE. */
4643 get_die_parent (dw_die_ref die
)
4650 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4651 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4654 return die
->die_parent
;
4657 /* Return the "low pc" attribute value, typically associated with a subprogram
4658 DIE. Return null if the "low pc" attribute is either not present, or if it
4659 cannot be represented as an assembler label identifier. */
4661 static inline const char *
4662 get_AT_low_pc (dw_die_ref die
)
4664 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4666 return a
? AT_lbl (a
) : NULL
;
4669 /* Return the "high pc" attribute value, typically associated with a subprogram
4670 DIE. Return null if the "high pc" attribute is either not present, or if it
4671 cannot be represented as an assembler label identifier. */
4673 static inline const char *
4674 get_AT_hi_pc (dw_die_ref die
)
4676 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4678 return a
? AT_lbl (a
) : NULL
;
4681 /* Return the value of the string attribute designated by ATTR_KIND, or
4682 NULL if it is not present. */
4684 static inline const char *
4685 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4687 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4689 return a
? AT_string (a
) : NULL
;
4692 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4693 if it is not present. */
4696 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4698 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4700 return a
? AT_flag (a
) : 0;
4703 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4704 if it is not present. */
4706 static inline unsigned
4707 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4709 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4711 return a
? AT_unsigned (a
) : 0;
4714 static inline dw_die_ref
4715 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4717 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4719 return a
? AT_ref (a
) : NULL
;
4722 static inline struct dwarf_file_data
*
4723 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4725 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4727 return a
? AT_file (a
) : NULL
;
4730 /* Return TRUE if the language is C++. */
4735 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4737 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4738 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4741 /* Return TRUE if the language is Java. */
4746 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4748 return lang
== DW_LANG_Java
;
4751 /* Return TRUE if the language is Fortran. */
4756 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4758 return (lang
== DW_LANG_Fortran77
4759 || lang
== DW_LANG_Fortran90
4760 || lang
== DW_LANG_Fortran95
4761 || lang
== DW_LANG_Fortran03
4762 || lang
== DW_LANG_Fortran08
);
4765 /* Return TRUE if the language is Ada. */
4770 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4772 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4775 /* Remove the specified attribute if present. Return TRUE if removal
4779 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4787 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4788 if (a
->dw_attr
== attr_kind
)
4790 if (AT_class (a
) == dw_val_class_str
)
4791 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4792 a
->dw_attr_val
.v
.val_str
->refcount
--;
4794 /* vec::ordered_remove should help reduce the number of abbrevs
4796 die
->die_attr
->ordered_remove (ix
);
4802 /* Remove CHILD from its parent. PREV must have the property that
4803 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4806 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4808 gcc_assert (child
->die_parent
== prev
->die_parent
);
4809 gcc_assert (prev
->die_sib
== child
);
4812 gcc_assert (child
->die_parent
->die_child
== child
);
4816 prev
->die_sib
= child
->die_sib
;
4817 if (child
->die_parent
->die_child
== child
)
4818 child
->die_parent
->die_child
= prev
;
4821 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4822 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4825 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4827 dw_die_ref parent
= old_child
->die_parent
;
4829 gcc_assert (parent
== prev
->die_parent
);
4830 gcc_assert (prev
->die_sib
== old_child
);
4832 new_child
->die_parent
= parent
;
4833 if (prev
== old_child
)
4835 gcc_assert (parent
->die_child
== old_child
);
4836 new_child
->die_sib
= new_child
;
4840 prev
->die_sib
= new_child
;
4841 new_child
->die_sib
= old_child
->die_sib
;
4843 if (old_child
->die_parent
->die_child
== old_child
)
4844 old_child
->die_parent
->die_child
= new_child
;
4847 /* Move all children from OLD_PARENT to NEW_PARENT. */
4850 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4853 new_parent
->die_child
= old_parent
->die_child
;
4854 old_parent
->die_child
= NULL
;
4855 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4858 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4862 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4868 dw_die_ref prev
= c
;
4870 while (c
->die_tag
== tag
)
4872 remove_child_with_prev (c
, prev
);
4873 c
->die_parent
= NULL
;
4874 /* Might have removed every child. */
4875 if (c
== c
->die_sib
)
4879 } while (c
!= die
->die_child
);
4882 /* Add a CHILD_DIE as the last child of DIE. */
4885 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4887 /* FIXME this should probably be an assert. */
4888 if (! die
|| ! child_die
)
4890 gcc_assert (die
!= child_die
);
4892 child_die
->die_parent
= die
;
4895 child_die
->die_sib
= die
->die_child
->die_sib
;
4896 die
->die_child
->die_sib
= child_die
;
4899 child_die
->die_sib
= child_die
;
4900 die
->die_child
= child_die
;
4903 /* Unassociate CHILD from its parent, and make its parent be
4907 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
4909 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4910 if (p
->die_sib
== child
)
4912 remove_child_with_prev (child
, p
);
4915 add_child_die (new_parent
, child
);
4918 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4919 is the specification, to the end of PARENT's list of children.
4920 This is done by removing and re-adding it. */
4923 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4925 /* We want the declaration DIE from inside the class, not the
4926 specification DIE at toplevel. */
4927 if (child
->die_parent
!= parent
)
4929 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4935 gcc_assert (child
->die_parent
== parent
4936 || (child
->die_parent
4937 == get_AT_ref (parent
, DW_AT_specification
)));
4939 reparent_child (child
, parent
);
4942 /* Create and return a new die with a parent of PARENT_DIE. If
4943 PARENT_DIE is NULL, the new DIE is placed in limbo and an
4944 associated tree T must be supplied to determine parenthood
4947 static inline dw_die_ref
4948 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4950 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
4952 die
->die_tag
= tag_value
;
4954 if (parent_die
!= NULL
)
4955 add_child_die (parent_die
, die
);
4958 limbo_die_node
*limbo_node
;
4960 /* No DIEs created after early dwarf should end up in limbo,
4961 because the limbo list should not persist past LTO
4963 if (tag_value
!= DW_TAG_compile_unit
4964 /* These are allowed because they're generated while
4965 breaking out COMDAT units late. */
4966 && tag_value
!= DW_TAG_type_unit
4968 /* Allow nested functions to live in limbo because they will
4969 only temporarily live there, as decls_for_scope will fix
4971 && (TREE_CODE (t
) != FUNCTION_DECL
4972 || !decl_function_context (t
))
4973 /* Same as nested functions above but for types. Types that
4974 are local to a function will be fixed in
4976 && (!RECORD_OR_UNION_TYPE_P (t
)
4977 || !TYPE_CONTEXT (t
)
4978 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
4979 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
4980 especially in the ltrans stage, but once we implement LTO
4981 dwarf streaming, we should remove this exception. */
4984 fprintf (stderr
, "symbol ended up in limbo too late:");
4985 debug_generic_stmt (t
);
4989 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
4990 limbo_node
->die
= die
;
4991 limbo_node
->created_for
= t
;
4992 limbo_node
->next
= limbo_die_list
;
4993 limbo_die_list
= limbo_node
;
4999 /* Return the DIE associated with the given type specifier. */
5001 static inline dw_die_ref
5002 lookup_type_die (tree type
)
5004 return TYPE_SYMTAB_DIE (type
);
5007 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5008 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5009 anonymous type instead the one of the naming typedef. */
5011 static inline dw_die_ref
5012 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5015 && TREE_CODE (type
) == RECORD_TYPE
5017 && type_die
->die_tag
== DW_TAG_typedef
5018 && is_naming_typedef_decl (TYPE_NAME (type
)))
5019 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5023 /* Like lookup_type_die, but if type is an anonymous type named by a
5024 typedef[1], return the DIE of the anonymous type instead the one of
5025 the naming typedef. This is because in gen_typedef_die, we did
5026 equate the anonymous struct named by the typedef with the DIE of
5027 the naming typedef. So by default, lookup_type_die on an anonymous
5028 struct yields the DIE of the naming typedef.
5030 [1]: Read the comment of is_naming_typedef_decl to learn about what
5031 a naming typedef is. */
5033 static inline dw_die_ref
5034 lookup_type_die_strip_naming_typedef (tree type
)
5036 dw_die_ref die
= lookup_type_die (type
);
5037 return strip_naming_typedef (type
, die
);
5040 /* Equate a DIE to a given type specifier. */
5043 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5045 TYPE_SYMTAB_DIE (type
) = type_die
;
5048 /* Returns a hash value for X (which really is a die_struct). */
5051 decl_die_hasher::hash (die_node
*x
)
5053 return (hashval_t
) x
->decl_id
;
5056 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5059 decl_die_hasher::equal (die_node
*x
, tree y
)
5061 return (x
->decl_id
== DECL_UID (y
));
5064 /* Return the DIE associated with a given declaration. */
5066 static inline dw_die_ref
5067 lookup_decl_die (tree decl
)
5069 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5072 /* Returns a hash value for X (which really is a var_loc_list). */
5075 decl_loc_hasher::hash (var_loc_list
*x
)
5077 return (hashval_t
) x
->decl_id
;
5080 /* Return nonzero if decl_id of var_loc_list X is the same as
5084 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5086 return (x
->decl_id
== DECL_UID (y
));
5089 /* Return the var_loc list associated with a given declaration. */
5091 static inline var_loc_list
*
5092 lookup_decl_loc (const_tree decl
)
5094 if (!decl_loc_table
)
5096 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5099 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5102 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5104 return (hashval_t
) x
->decl_id
;
5107 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5111 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5113 return (x
->decl_id
== DECL_UID (y
));
5116 /* Equate a DIE to a particular declaration. */
5119 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5121 unsigned int decl_id
= DECL_UID (decl
);
5123 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5124 decl_die
->decl_id
= decl_id
;
5127 /* Return how many bits covers PIECE EXPR_LIST. */
5129 static HOST_WIDE_INT
5130 decl_piece_bitsize (rtx piece
)
5132 int ret
= (int) GET_MODE (piece
);
5135 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5136 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5137 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5140 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5143 decl_piece_varloc_ptr (rtx piece
)
5145 if ((int) GET_MODE (piece
))
5146 return &XEXP (piece
, 0);
5148 return &XEXP (XEXP (piece
, 0), 1);
5151 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5152 Next is the chain of following piece nodes. */
5154 static rtx_expr_list
*
5155 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5157 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5158 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5160 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5165 /* Return rtx that should be stored into loc field for
5166 LOC_NOTE and BITPOS/BITSIZE. */
5169 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5170 HOST_WIDE_INT bitsize
)
5174 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5176 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5181 /* This function either modifies location piece list *DEST in
5182 place (if SRC and INNER is NULL), or copies location piece list
5183 *SRC to *DEST while modifying it. Location BITPOS is modified
5184 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5185 not copied and if needed some padding around it is added.
5186 When modifying in place, DEST should point to EXPR_LIST where
5187 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5188 to the start of the whole list and INNER points to the EXPR_LIST
5189 where earlier pieces cover PIECE_BITPOS bits. */
5192 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5193 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5194 HOST_WIDE_INT bitsize
, rtx loc_note
)
5197 bool copy
= inner
!= NULL
;
5201 /* First copy all nodes preceding the current bitpos. */
5202 while (src
!= inner
)
5204 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5205 decl_piece_bitsize (*src
), NULL_RTX
);
5206 dest
= &XEXP (*dest
, 1);
5207 src
= &XEXP (*src
, 1);
5210 /* Add padding if needed. */
5211 if (bitpos
!= piece_bitpos
)
5213 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5214 copy
? NULL_RTX
: *dest
);
5215 dest
= &XEXP (*dest
, 1);
5217 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5220 /* A piece with correct bitpos and bitsize already exist,
5221 just update the location for it and return. */
5222 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5225 /* Add the piece that changed. */
5226 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5227 dest
= &XEXP (*dest
, 1);
5228 /* Skip over pieces that overlap it. */
5229 diff
= bitpos
- piece_bitpos
+ bitsize
;
5232 while (diff
> 0 && *src
)
5235 diff
-= decl_piece_bitsize (piece
);
5237 src
= &XEXP (piece
, 1);
5240 *src
= XEXP (piece
, 1);
5241 free_EXPR_LIST_node (piece
);
5244 /* Add padding if needed. */
5245 if (diff
< 0 && *src
)
5249 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5250 dest
= &XEXP (*dest
, 1);
5254 /* Finally copy all nodes following it. */
5257 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5258 decl_piece_bitsize (*src
), NULL_RTX
);
5259 dest
= &XEXP (*dest
, 1);
5260 src
= &XEXP (*src
, 1);
5264 /* Add a variable location node to the linked list for DECL. */
5266 static struct var_loc_node
*
5267 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5269 unsigned int decl_id
;
5271 struct var_loc_node
*loc
= NULL
;
5272 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5274 if (TREE_CODE (decl
) == VAR_DECL
5275 && DECL_HAS_DEBUG_EXPR_P (decl
))
5277 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5278 if (handled_component_p (realdecl
)
5279 || (TREE_CODE (realdecl
) == MEM_REF
5280 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5282 HOST_WIDE_INT maxsize
;
5285 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5286 if (!DECL_P (innerdecl
)
5287 || DECL_IGNORED_P (innerdecl
)
5288 || TREE_STATIC (innerdecl
)
5290 || bitpos
+ bitsize
> 256
5291 || bitsize
!= maxsize
)
5297 decl_id
= DECL_UID (decl
);
5299 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5302 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5303 temp
->decl_id
= decl_id
;
5309 /* For PARM_DECLs try to keep around the original incoming value,
5310 even if that means we'll emit a zero-range .debug_loc entry. */
5312 && temp
->first
== temp
->last
5313 && TREE_CODE (decl
) == PARM_DECL
5314 && NOTE_P (temp
->first
->loc
)
5315 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5316 && DECL_INCOMING_RTL (decl
)
5317 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5318 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5319 == GET_CODE (DECL_INCOMING_RTL (decl
))
5320 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5322 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5323 NOTE_VAR_LOCATION_LOC (loc_note
))
5324 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5325 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5327 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5328 temp
->first
->next
= loc
;
5330 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5332 else if (temp
->last
)
5334 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5335 rtx
*piece_loc
= NULL
, last_loc_note
;
5336 HOST_WIDE_INT piece_bitpos
= 0;
5340 gcc_assert (last
->next
== NULL
);
5342 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5344 piece_loc
= &last
->loc
;
5347 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5348 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5350 piece_bitpos
+= cur_bitsize
;
5351 piece_loc
= &XEXP (*piece_loc
, 1);
5355 /* TEMP->LAST here is either pointer to the last but one or
5356 last element in the chained list, LAST is pointer to the
5358 if (label
&& strcmp (last
->label
, label
) == 0)
5360 /* For SRA optimized variables if there weren't any real
5361 insns since last note, just modify the last node. */
5362 if (piece_loc
!= NULL
)
5364 adjust_piece_list (piece_loc
, NULL
, NULL
,
5365 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5368 /* If the last note doesn't cover any instructions, remove it. */
5369 if (temp
->last
!= last
)
5371 temp
->last
->next
= NULL
;
5374 gcc_assert (strcmp (last
->label
, label
) != 0);
5378 gcc_assert (temp
->first
== temp
->last
5379 || (temp
->first
->next
== temp
->last
5380 && TREE_CODE (decl
) == PARM_DECL
));
5381 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5382 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5386 if (bitsize
== -1 && NOTE_P (last
->loc
))
5387 last_loc_note
= last
->loc
;
5388 else if (piece_loc
!= NULL
5389 && *piece_loc
!= NULL_RTX
5390 && piece_bitpos
== bitpos
5391 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5392 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5394 last_loc_note
= NULL_RTX
;
5395 /* If the current location is the same as the end of the list,
5396 and either both or neither of the locations is uninitialized,
5397 we have nothing to do. */
5398 if (last_loc_note
== NULL_RTX
5399 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5400 NOTE_VAR_LOCATION_LOC (loc_note
)))
5401 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5402 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5403 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5404 == VAR_INIT_STATUS_UNINITIALIZED
)
5405 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5406 == VAR_INIT_STATUS_UNINITIALIZED
))))
5408 /* Add LOC to the end of list and update LAST. If the last
5409 element of the list has been removed above, reuse its
5410 memory for the new node, otherwise allocate a new one. */
5414 memset (loc
, '\0', sizeof (*loc
));
5417 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5418 if (bitsize
== -1 || piece_loc
== NULL
)
5419 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5421 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5422 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5424 /* Ensure TEMP->LAST will point either to the new last but one
5425 element of the chain, or to the last element in it. */
5426 if (last
!= temp
->last
)
5434 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5437 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5442 /* Keep track of the number of spaces used to indent the
5443 output of the debugging routines that print the structure of
5444 the DIE internal representation. */
5445 static int print_indent
;
5447 /* Indent the line the number of spaces given by print_indent. */
5450 print_spaces (FILE *outfile
)
5452 fprintf (outfile
, "%*s", print_indent
, "");
5455 /* Print a type signature in hex. */
5458 print_signature (FILE *outfile
, char *sig
)
5462 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5463 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5466 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5468 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5469 RECURSE, output location descriptor operations. */
5472 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5474 switch (val
->val_class
)
5476 case dw_val_class_addr
:
5477 fprintf (outfile
, "address");
5479 case dw_val_class_offset
:
5480 fprintf (outfile
, "offset");
5482 case dw_val_class_loc
:
5483 fprintf (outfile
, "location descriptor");
5484 if (val
->v
.val_loc
== NULL
)
5485 fprintf (outfile
, " -> <null>\n");
5488 fprintf (outfile
, ":\n");
5490 print_loc_descr (val
->v
.val_loc
, outfile
);
5494 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5496 case dw_val_class_loc_list
:
5497 fprintf (outfile
, "location list -> label:%s",
5498 val
->v
.val_loc_list
->ll_symbol
);
5500 case dw_val_class_range_list
:
5501 fprintf (outfile
, "range list");
5503 case dw_val_class_const
:
5504 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5506 case dw_val_class_unsigned_const
:
5507 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5509 case dw_val_class_const_double
:
5510 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5511 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5512 val
->v
.val_double
.high
,
5513 val
->v
.val_double
.low
);
5515 case dw_val_class_wide_int
:
5517 int i
= val
->v
.val_wide
->get_len ();
5518 fprintf (outfile
, "constant (");
5520 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5521 fprintf (outfile
, "0x");
5522 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5523 val
->v
.val_wide
->elt (--i
));
5525 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5526 val
->v
.val_wide
->elt (i
));
5527 fprintf (outfile
, ")");
5530 case dw_val_class_vec
:
5531 fprintf (outfile
, "floating-point or vector constant");
5533 case dw_val_class_flag
:
5534 fprintf (outfile
, "%u", val
->v
.val_flag
);
5536 case dw_val_class_die_ref
:
5537 if (val
->v
.val_die_ref
.die
!= NULL
)
5539 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5541 if (die
->comdat_type_p
)
5543 fprintf (outfile
, "die -> signature: ");
5544 print_signature (outfile
,
5545 die
->die_id
.die_type_node
->signature
);
5547 else if (die
->die_id
.die_symbol
)
5548 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5550 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5551 fprintf (outfile
, " (%p)", (void *) die
);
5554 fprintf (outfile
, "die -> <null>");
5556 case dw_val_class_vms_delta
:
5557 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5558 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5560 case dw_val_class_lbl_id
:
5561 case dw_val_class_lineptr
:
5562 case dw_val_class_macptr
:
5563 case dw_val_class_high_pc
:
5564 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5566 case dw_val_class_str
:
5567 if (val
->v
.val_str
->str
!= NULL
)
5568 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5570 fprintf (outfile
, "<null>");
5572 case dw_val_class_file
:
5573 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5574 val
->v
.val_file
->emitted_number
);
5576 case dw_val_class_data8
:
5580 for (i
= 0; i
< 8; i
++)
5581 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5589 /* Likewise, for a DIE attribute. */
5592 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5594 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5598 /* Print the list of operands in the LOC location description to OUTFILE. This
5599 routine is a debugging aid only. */
5602 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5604 dw_loc_descr_ref l
= loc
;
5608 print_spaces (outfile
);
5609 fprintf (outfile
, "<null>\n");
5613 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5615 print_spaces (outfile
);
5616 fprintf (outfile
, "(%p) %s",
5618 dwarf_stack_op_name (l
->dw_loc_opc
));
5619 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5621 fprintf (outfile
, " ");
5622 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5624 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5626 fprintf (outfile
, ", ");
5627 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5629 fprintf (outfile
, "\n");
5633 /* Print the information associated with a given DIE, and its children.
5634 This routine is a debugging aid only. */
5637 print_die (dw_die_ref die
, FILE *outfile
)
5643 print_spaces (outfile
);
5644 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5645 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5647 print_spaces (outfile
);
5648 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5649 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5650 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5652 if (die
->comdat_type_p
)
5654 print_spaces (outfile
);
5655 fprintf (outfile
, " signature: ");
5656 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5657 fprintf (outfile
, "\n");
5660 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5662 print_spaces (outfile
);
5663 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5665 print_attribute (a
, true, outfile
);
5666 fprintf (outfile
, "\n");
5669 if (die
->die_child
!= NULL
)
5672 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5675 if (print_indent
== 0)
5676 fprintf (outfile
, "\n");
5679 /* Print the list of operations in the LOC location description. */
5682 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5684 print_loc_descr (loc
, stderr
);
5687 /* Print the information collected for a given DIE. */
5690 debug_dwarf_die (dw_die_ref die
)
5692 print_die (die
, stderr
);
5696 debug (die_struct
&ref
)
5698 print_die (&ref
, stderr
);
5702 debug (die_struct
*ptr
)
5707 fprintf (stderr
, "<nil>\n");
5711 /* Print all DWARF information collected for the compilation unit.
5712 This routine is a debugging aid only. */
5718 print_die (comp_unit_die (), stderr
);
5721 /* Sanity checks on DIEs. */
5724 check_die (dw_die_ref die
)
5728 bool inline_found
= false;
5729 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5730 int n_decl_line
= 0, n_decl_file
= 0;
5731 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5736 if (a
->dw_attr_val
.v
.val_unsigned
)
5737 inline_found
= true;
5739 case DW_AT_location
:
5748 case DW_AT_artificial
:
5751 case DW_AT_decl_line
:
5754 case DW_AT_decl_file
:
5761 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5762 || n_decl_line
> 1 || n_decl_file
> 1)
5764 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5765 debug_dwarf_die (die
);
5770 /* A debugging information entry that is a member of an abstract
5771 instance tree [that has DW_AT_inline] should not contain any
5772 attributes which describe aspects of the subroutine which vary
5773 between distinct inlined expansions or distinct out-of-line
5775 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5776 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5777 && a
->dw_attr
!= DW_AT_high_pc
5778 && a
->dw_attr
!= DW_AT_location
5779 && a
->dw_attr
!= DW_AT_frame_base
5780 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5784 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5785 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5786 DIE that marks the start of the DIEs for this include file. */
5789 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5791 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5792 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5794 new_unit
->die_sib
= old_unit
;
5798 /* Close an include-file CU and reopen the enclosing one. */
5801 pop_compile_unit (dw_die_ref old_unit
)
5803 dw_die_ref new_unit
= old_unit
->die_sib
;
5805 old_unit
->die_sib
= NULL
;
5809 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5810 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5811 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5813 /* Calculate the checksum of a location expression. */
5816 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5819 inchash::hash hstate
;
5822 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5824 hash_loc_operands (loc
, hstate
);
5825 hash
= hstate
.end();
5829 /* Calculate the checksum of an attribute. */
5832 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
5834 dw_loc_descr_ref loc
;
5837 CHECKSUM (at
->dw_attr
);
5839 /* We don't care that this was compiled with a different compiler
5840 snapshot; if the output is the same, that's what matters. */
5841 if (at
->dw_attr
== DW_AT_producer
)
5844 switch (AT_class (at
))
5846 case dw_val_class_const
:
5847 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5849 case dw_val_class_unsigned_const
:
5850 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5852 case dw_val_class_const_double
:
5853 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5855 case dw_val_class_wide_int
:
5856 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5857 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5858 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5860 case dw_val_class_vec
:
5861 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5862 (at
->dw_attr_val
.v
.val_vec
.length
5863 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5865 case dw_val_class_flag
:
5866 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5868 case dw_val_class_str
:
5869 CHECKSUM_STRING (AT_string (at
));
5872 case dw_val_class_addr
:
5874 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5875 CHECKSUM_STRING (XSTR (r
, 0));
5878 case dw_val_class_offset
:
5879 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5882 case dw_val_class_loc
:
5883 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5884 loc_checksum (loc
, ctx
);
5887 case dw_val_class_die_ref
:
5888 die_checksum (AT_ref (at
), ctx
, mark
);
5891 case dw_val_class_fde_ref
:
5892 case dw_val_class_vms_delta
:
5893 case dw_val_class_lbl_id
:
5894 case dw_val_class_lineptr
:
5895 case dw_val_class_macptr
:
5896 case dw_val_class_high_pc
:
5899 case dw_val_class_file
:
5900 CHECKSUM_STRING (AT_file (at
)->filename
);
5903 case dw_val_class_data8
:
5904 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5912 /* Calculate the checksum of a DIE. */
5915 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5921 /* To avoid infinite recursion. */
5924 CHECKSUM (die
->die_mark
);
5927 die
->die_mark
= ++(*mark
);
5929 CHECKSUM (die
->die_tag
);
5931 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5932 attr_checksum (a
, ctx
, mark
);
5934 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5938 #undef CHECKSUM_BLOCK
5939 #undef CHECKSUM_STRING
5941 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5942 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5943 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5944 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5945 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5946 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5947 #define CHECKSUM_ATTR(FOO) \
5948 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5950 /* Calculate the checksum of a number in signed LEB128 format. */
5953 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5960 byte
= (value
& 0x7f);
5962 more
= !((value
== 0 && (byte
& 0x40) == 0)
5963 || (value
== -1 && (byte
& 0x40) != 0));
5972 /* Calculate the checksum of a number in unsigned LEB128 format. */
5975 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5979 unsigned char byte
= (value
& 0x7f);
5982 /* More bytes to follow. */
5990 /* Checksum the context of the DIE. This adds the names of any
5991 surrounding namespaces or structures to the checksum. */
5994 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5998 int tag
= die
->die_tag
;
6000 if (tag
!= DW_TAG_namespace
6001 && tag
!= DW_TAG_structure_type
6002 && tag
!= DW_TAG_class_type
)
6005 name
= get_AT_string (die
, DW_AT_name
);
6007 spec
= get_AT_ref (die
, DW_AT_specification
);
6011 if (die
->die_parent
!= NULL
)
6012 checksum_die_context (die
->die_parent
, ctx
);
6014 CHECKSUM_ULEB128 ('C');
6015 CHECKSUM_ULEB128 (tag
);
6017 CHECKSUM_STRING (name
);
6020 /* Calculate the checksum of a location expression. */
6023 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6025 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6026 were emitted as a DW_FORM_sdata instead of a location expression. */
6027 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6029 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6030 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6034 /* Otherwise, just checksum the raw location expression. */
6037 inchash::hash hstate
;
6040 CHECKSUM_ULEB128 (loc
->dtprel
);
6041 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6042 hash_loc_operands (loc
, hstate
);
6043 hash
= hstate
.end ();
6045 loc
= loc
->dw_loc_next
;
6049 /* Calculate the checksum of an attribute. */
6052 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6053 struct md5_ctx
*ctx
, int *mark
)
6055 dw_loc_descr_ref loc
;
6058 if (AT_class (at
) == dw_val_class_die_ref
)
6060 dw_die_ref target_die
= AT_ref (at
);
6062 /* For pointer and reference types, we checksum only the (qualified)
6063 name of the target type (if there is a name). For friend entries,
6064 we checksum only the (qualified) name of the target type or function.
6065 This allows the checksum to remain the same whether the target type
6066 is complete or not. */
6067 if ((at
->dw_attr
== DW_AT_type
6068 && (tag
== DW_TAG_pointer_type
6069 || tag
== DW_TAG_reference_type
6070 || tag
== DW_TAG_rvalue_reference_type
6071 || tag
== DW_TAG_ptr_to_member_type
))
6072 || (at
->dw_attr
== DW_AT_friend
6073 && tag
== DW_TAG_friend
))
6075 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6077 if (name_attr
!= NULL
)
6079 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6083 CHECKSUM_ULEB128 ('N');
6084 CHECKSUM_ULEB128 (at
->dw_attr
);
6085 if (decl
->die_parent
!= NULL
)
6086 checksum_die_context (decl
->die_parent
, ctx
);
6087 CHECKSUM_ULEB128 ('E');
6088 CHECKSUM_STRING (AT_string (name_attr
));
6093 /* For all other references to another DIE, we check to see if the
6094 target DIE has already been visited. If it has, we emit a
6095 backward reference; if not, we descend recursively. */
6096 if (target_die
->die_mark
> 0)
6098 CHECKSUM_ULEB128 ('R');
6099 CHECKSUM_ULEB128 (at
->dw_attr
);
6100 CHECKSUM_ULEB128 (target_die
->die_mark
);
6104 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6108 target_die
->die_mark
= ++(*mark
);
6109 CHECKSUM_ULEB128 ('T');
6110 CHECKSUM_ULEB128 (at
->dw_attr
);
6111 if (decl
->die_parent
!= NULL
)
6112 checksum_die_context (decl
->die_parent
, ctx
);
6113 die_checksum_ordered (target_die
, ctx
, mark
);
6118 CHECKSUM_ULEB128 ('A');
6119 CHECKSUM_ULEB128 (at
->dw_attr
);
6121 switch (AT_class (at
))
6123 case dw_val_class_const
:
6124 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6125 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6128 case dw_val_class_unsigned_const
:
6129 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6130 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6133 case dw_val_class_const_double
:
6134 CHECKSUM_ULEB128 (DW_FORM_block
);
6135 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6136 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6139 case dw_val_class_wide_int
:
6140 CHECKSUM_ULEB128 (DW_FORM_block
);
6141 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6142 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6143 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6144 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6145 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6148 case dw_val_class_vec
:
6149 CHECKSUM_ULEB128 (DW_FORM_block
);
6150 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6151 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6152 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6153 (at
->dw_attr_val
.v
.val_vec
.length
6154 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6157 case dw_val_class_flag
:
6158 CHECKSUM_ULEB128 (DW_FORM_flag
);
6159 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6162 case dw_val_class_str
:
6163 CHECKSUM_ULEB128 (DW_FORM_string
);
6164 CHECKSUM_STRING (AT_string (at
));
6167 case dw_val_class_addr
:
6169 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6170 CHECKSUM_ULEB128 (DW_FORM_string
);
6171 CHECKSUM_STRING (XSTR (r
, 0));
6174 case dw_val_class_offset
:
6175 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6176 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6179 case dw_val_class_loc
:
6180 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6181 loc_checksum_ordered (loc
, ctx
);
6184 case dw_val_class_fde_ref
:
6185 case dw_val_class_lbl_id
:
6186 case dw_val_class_lineptr
:
6187 case dw_val_class_macptr
:
6188 case dw_val_class_high_pc
:
6191 case dw_val_class_file
:
6192 CHECKSUM_ULEB128 (DW_FORM_string
);
6193 CHECKSUM_STRING (AT_file (at
)->filename
);
6196 case dw_val_class_data8
:
6197 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6205 struct checksum_attributes
6207 dw_attr_node
*at_name
;
6208 dw_attr_node
*at_type
;
6209 dw_attr_node
*at_friend
;
6210 dw_attr_node
*at_accessibility
;
6211 dw_attr_node
*at_address_class
;
6212 dw_attr_node
*at_allocated
;
6213 dw_attr_node
*at_artificial
;
6214 dw_attr_node
*at_associated
;
6215 dw_attr_node
*at_binary_scale
;
6216 dw_attr_node
*at_bit_offset
;
6217 dw_attr_node
*at_bit_size
;
6218 dw_attr_node
*at_bit_stride
;
6219 dw_attr_node
*at_byte_size
;
6220 dw_attr_node
*at_byte_stride
;
6221 dw_attr_node
*at_const_value
;
6222 dw_attr_node
*at_containing_type
;
6223 dw_attr_node
*at_count
;
6224 dw_attr_node
*at_data_location
;
6225 dw_attr_node
*at_data_member_location
;
6226 dw_attr_node
*at_decimal_scale
;
6227 dw_attr_node
*at_decimal_sign
;
6228 dw_attr_node
*at_default_value
;
6229 dw_attr_node
*at_digit_count
;
6230 dw_attr_node
*at_discr
;
6231 dw_attr_node
*at_discr_list
;
6232 dw_attr_node
*at_discr_value
;
6233 dw_attr_node
*at_encoding
;
6234 dw_attr_node
*at_endianity
;
6235 dw_attr_node
*at_explicit
;
6236 dw_attr_node
*at_is_optional
;
6237 dw_attr_node
*at_location
;
6238 dw_attr_node
*at_lower_bound
;
6239 dw_attr_node
*at_mutable
;
6240 dw_attr_node
*at_ordering
;
6241 dw_attr_node
*at_picture_string
;
6242 dw_attr_node
*at_prototyped
;
6243 dw_attr_node
*at_small
;
6244 dw_attr_node
*at_segment
;
6245 dw_attr_node
*at_string_length
;
6246 dw_attr_node
*at_threads_scaled
;
6247 dw_attr_node
*at_upper_bound
;
6248 dw_attr_node
*at_use_location
;
6249 dw_attr_node
*at_use_UTF8
;
6250 dw_attr_node
*at_variable_parameter
;
6251 dw_attr_node
*at_virtuality
;
6252 dw_attr_node
*at_visibility
;
6253 dw_attr_node
*at_vtable_elem_location
;
6256 /* Collect the attributes that we will want to use for the checksum. */
6259 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6264 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6275 attrs
->at_friend
= a
;
6277 case DW_AT_accessibility
:
6278 attrs
->at_accessibility
= a
;
6280 case DW_AT_address_class
:
6281 attrs
->at_address_class
= a
;
6283 case DW_AT_allocated
:
6284 attrs
->at_allocated
= a
;
6286 case DW_AT_artificial
:
6287 attrs
->at_artificial
= a
;
6289 case DW_AT_associated
:
6290 attrs
->at_associated
= a
;
6292 case DW_AT_binary_scale
:
6293 attrs
->at_binary_scale
= a
;
6295 case DW_AT_bit_offset
:
6296 attrs
->at_bit_offset
= a
;
6298 case DW_AT_bit_size
:
6299 attrs
->at_bit_size
= a
;
6301 case DW_AT_bit_stride
:
6302 attrs
->at_bit_stride
= a
;
6304 case DW_AT_byte_size
:
6305 attrs
->at_byte_size
= a
;
6307 case DW_AT_byte_stride
:
6308 attrs
->at_byte_stride
= a
;
6310 case DW_AT_const_value
:
6311 attrs
->at_const_value
= a
;
6313 case DW_AT_containing_type
:
6314 attrs
->at_containing_type
= a
;
6317 attrs
->at_count
= a
;
6319 case DW_AT_data_location
:
6320 attrs
->at_data_location
= a
;
6322 case DW_AT_data_member_location
:
6323 attrs
->at_data_member_location
= a
;
6325 case DW_AT_decimal_scale
:
6326 attrs
->at_decimal_scale
= a
;
6328 case DW_AT_decimal_sign
:
6329 attrs
->at_decimal_sign
= a
;
6331 case DW_AT_default_value
:
6332 attrs
->at_default_value
= a
;
6334 case DW_AT_digit_count
:
6335 attrs
->at_digit_count
= a
;
6338 attrs
->at_discr
= a
;
6340 case DW_AT_discr_list
:
6341 attrs
->at_discr_list
= a
;
6343 case DW_AT_discr_value
:
6344 attrs
->at_discr_value
= a
;
6346 case DW_AT_encoding
:
6347 attrs
->at_encoding
= a
;
6349 case DW_AT_endianity
:
6350 attrs
->at_endianity
= a
;
6352 case DW_AT_explicit
:
6353 attrs
->at_explicit
= a
;
6355 case DW_AT_is_optional
:
6356 attrs
->at_is_optional
= a
;
6358 case DW_AT_location
:
6359 attrs
->at_location
= a
;
6361 case DW_AT_lower_bound
:
6362 attrs
->at_lower_bound
= a
;
6365 attrs
->at_mutable
= a
;
6367 case DW_AT_ordering
:
6368 attrs
->at_ordering
= a
;
6370 case DW_AT_picture_string
:
6371 attrs
->at_picture_string
= a
;
6373 case DW_AT_prototyped
:
6374 attrs
->at_prototyped
= a
;
6377 attrs
->at_small
= a
;
6380 attrs
->at_segment
= a
;
6382 case DW_AT_string_length
:
6383 attrs
->at_string_length
= a
;
6385 case DW_AT_threads_scaled
:
6386 attrs
->at_threads_scaled
= a
;
6388 case DW_AT_upper_bound
:
6389 attrs
->at_upper_bound
= a
;
6391 case DW_AT_use_location
:
6392 attrs
->at_use_location
= a
;
6394 case DW_AT_use_UTF8
:
6395 attrs
->at_use_UTF8
= a
;
6397 case DW_AT_variable_parameter
:
6398 attrs
->at_variable_parameter
= a
;
6400 case DW_AT_virtuality
:
6401 attrs
->at_virtuality
= a
;
6403 case DW_AT_visibility
:
6404 attrs
->at_visibility
= a
;
6406 case DW_AT_vtable_elem_location
:
6407 attrs
->at_vtable_elem_location
= a
;
6415 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6418 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6422 struct checksum_attributes attrs
;
6424 CHECKSUM_ULEB128 ('D');
6425 CHECKSUM_ULEB128 (die
->die_tag
);
6427 memset (&attrs
, 0, sizeof (attrs
));
6429 decl
= get_AT_ref (die
, DW_AT_specification
);
6431 collect_checksum_attributes (&attrs
, decl
);
6432 collect_checksum_attributes (&attrs
, die
);
6434 CHECKSUM_ATTR (attrs
.at_name
);
6435 CHECKSUM_ATTR (attrs
.at_accessibility
);
6436 CHECKSUM_ATTR (attrs
.at_address_class
);
6437 CHECKSUM_ATTR (attrs
.at_allocated
);
6438 CHECKSUM_ATTR (attrs
.at_artificial
);
6439 CHECKSUM_ATTR (attrs
.at_associated
);
6440 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6441 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6442 CHECKSUM_ATTR (attrs
.at_bit_size
);
6443 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6444 CHECKSUM_ATTR (attrs
.at_byte_size
);
6445 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6446 CHECKSUM_ATTR (attrs
.at_const_value
);
6447 CHECKSUM_ATTR (attrs
.at_containing_type
);
6448 CHECKSUM_ATTR (attrs
.at_count
);
6449 CHECKSUM_ATTR (attrs
.at_data_location
);
6450 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6451 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6452 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6453 CHECKSUM_ATTR (attrs
.at_default_value
);
6454 CHECKSUM_ATTR (attrs
.at_digit_count
);
6455 CHECKSUM_ATTR (attrs
.at_discr
);
6456 CHECKSUM_ATTR (attrs
.at_discr_list
);
6457 CHECKSUM_ATTR (attrs
.at_discr_value
);
6458 CHECKSUM_ATTR (attrs
.at_encoding
);
6459 CHECKSUM_ATTR (attrs
.at_endianity
);
6460 CHECKSUM_ATTR (attrs
.at_explicit
);
6461 CHECKSUM_ATTR (attrs
.at_is_optional
);
6462 CHECKSUM_ATTR (attrs
.at_location
);
6463 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6464 CHECKSUM_ATTR (attrs
.at_mutable
);
6465 CHECKSUM_ATTR (attrs
.at_ordering
);
6466 CHECKSUM_ATTR (attrs
.at_picture_string
);
6467 CHECKSUM_ATTR (attrs
.at_prototyped
);
6468 CHECKSUM_ATTR (attrs
.at_small
);
6469 CHECKSUM_ATTR (attrs
.at_segment
);
6470 CHECKSUM_ATTR (attrs
.at_string_length
);
6471 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6472 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6473 CHECKSUM_ATTR (attrs
.at_use_location
);
6474 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6475 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6476 CHECKSUM_ATTR (attrs
.at_virtuality
);
6477 CHECKSUM_ATTR (attrs
.at_visibility
);
6478 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6479 CHECKSUM_ATTR (attrs
.at_type
);
6480 CHECKSUM_ATTR (attrs
.at_friend
);
6482 /* Checksum the child DIEs. */
6485 dw_attr_node
*name_attr
;
6488 name_attr
= get_AT (c
, DW_AT_name
);
6489 if (is_template_instantiation (c
))
6491 /* Ignore instantiations of member type and function templates. */
6493 else if (name_attr
!= NULL
6494 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6496 /* Use a shallow checksum for named nested types and member
6498 CHECKSUM_ULEB128 ('S');
6499 CHECKSUM_ULEB128 (c
->die_tag
);
6500 CHECKSUM_STRING (AT_string (name_attr
));
6504 /* Use a deep checksum for other children. */
6505 /* Mark this DIE so it gets processed when unmarking. */
6506 if (c
->die_mark
== 0)
6508 die_checksum_ordered (c
, ctx
, mark
);
6510 } while (c
!= die
->die_child
);
6512 CHECKSUM_ULEB128 (0);
6515 /* Add a type name and tag to a hash. */
6517 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6519 CHECKSUM_ULEB128 (tag
);
6520 CHECKSUM_STRING (name
);
6524 #undef CHECKSUM_STRING
6525 #undef CHECKSUM_ATTR
6526 #undef CHECKSUM_LEB128
6527 #undef CHECKSUM_ULEB128
6529 /* Generate the type signature for DIE. This is computed by generating an
6530 MD5 checksum over the DIE's tag, its relevant attributes, and its
6531 children. Attributes that are references to other DIEs are processed
6532 by recursion, using the MARK field to prevent infinite recursion.
6533 If the DIE is nested inside a namespace or another type, we also
6534 need to include that context in the signature. The lower 64 bits
6535 of the resulting MD5 checksum comprise the signature. */
6538 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6542 unsigned char checksum
[16];
6547 name
= get_AT_string (die
, DW_AT_name
);
6548 decl
= get_AT_ref (die
, DW_AT_specification
);
6549 parent
= get_die_parent (die
);
6551 /* First, compute a signature for just the type name (and its surrounding
6552 context, if any. This is stored in the type unit DIE for link-time
6553 ODR (one-definition rule) checking. */
6555 if (is_cxx () && name
!= NULL
)
6557 md5_init_ctx (&ctx
);
6559 /* Checksum the names of surrounding namespaces and structures. */
6561 checksum_die_context (parent
, &ctx
);
6563 /* Checksum the current DIE. */
6564 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6565 md5_finish_ctx (&ctx
, checksum
);
6567 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6570 /* Next, compute the complete type signature. */
6572 md5_init_ctx (&ctx
);
6574 die
->die_mark
= mark
;
6576 /* Checksum the names of surrounding namespaces and structures. */
6578 checksum_die_context (parent
, &ctx
);
6580 /* Checksum the DIE and its children. */
6581 die_checksum_ordered (die
, &ctx
, &mark
);
6582 unmark_all_dies (die
);
6583 md5_finish_ctx (&ctx
, checksum
);
6585 /* Store the signature in the type node and link the type DIE and the
6586 type node together. */
6587 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6588 DWARF_TYPE_SIGNATURE_SIZE
);
6589 die
->comdat_type_p
= true;
6590 die
->die_id
.die_type_node
= type_node
;
6591 type_node
->type_die
= die
;
6593 /* If the DIE is a specification, link its declaration to the type node
6597 decl
->comdat_type_p
= true;
6598 decl
->die_id
.die_type_node
= type_node
;
6602 /* Do the location expressions look same? */
6604 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6606 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6607 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6608 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6611 /* Do the values look the same? */
6613 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6615 dw_loc_descr_ref loc1
, loc2
;
6618 if (v1
->val_class
!= v2
->val_class
)
6621 switch (v1
->val_class
)
6623 case dw_val_class_const
:
6624 return v1
->v
.val_int
== v2
->v
.val_int
;
6625 case dw_val_class_unsigned_const
:
6626 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6627 case dw_val_class_const_double
:
6628 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6629 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6630 case dw_val_class_wide_int
:
6631 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6632 case dw_val_class_vec
:
6633 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6634 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6636 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6637 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6640 case dw_val_class_flag
:
6641 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6642 case dw_val_class_str
:
6643 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6645 case dw_val_class_addr
:
6646 r1
= v1
->v
.val_addr
;
6647 r2
= v2
->v
.val_addr
;
6648 if (GET_CODE (r1
) != GET_CODE (r2
))
6650 return !rtx_equal_p (r1
, r2
);
6652 case dw_val_class_offset
:
6653 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6655 case dw_val_class_loc
:
6656 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6658 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6659 if (!same_loc_p (loc1
, loc2
, mark
))
6661 return !loc1
&& !loc2
;
6663 case dw_val_class_die_ref
:
6664 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6666 case dw_val_class_fde_ref
:
6667 case dw_val_class_vms_delta
:
6668 case dw_val_class_lbl_id
:
6669 case dw_val_class_lineptr
:
6670 case dw_val_class_macptr
:
6671 case dw_val_class_high_pc
:
6674 case dw_val_class_file
:
6675 return v1
->v
.val_file
== v2
->v
.val_file
;
6677 case dw_val_class_data8
:
6678 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6685 /* Do the attributes look the same? */
6688 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
6690 if (at1
->dw_attr
!= at2
->dw_attr
)
6693 /* We don't care that this was compiled with a different compiler
6694 snapshot; if the output is the same, that's what matters. */
6695 if (at1
->dw_attr
== DW_AT_producer
)
6698 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6701 /* Do the dies look the same? */
6704 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6710 /* To avoid infinite recursion. */
6712 return die1
->die_mark
== die2
->die_mark
;
6713 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6715 if (die1
->die_tag
!= die2
->die_tag
)
6718 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6721 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6722 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6725 c1
= die1
->die_child
;
6726 c2
= die2
->die_child
;
6735 if (!same_die_p (c1
, c2
, mark
))
6739 if (c1
== die1
->die_child
)
6741 if (c2
== die2
->die_child
)
6751 /* Do the dies look the same? Wrapper around same_die_p. */
6754 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6757 int ret
= same_die_p (die1
, die2
, &mark
);
6759 unmark_all_dies (die1
);
6760 unmark_all_dies (die2
);
6765 /* The prefix to attach to symbols on DIEs in the current comdat debug
6767 static const char *comdat_symbol_id
;
6769 /* The index of the current symbol within the current comdat CU. */
6770 static unsigned int comdat_symbol_number
;
6772 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6773 children, and set comdat_symbol_id accordingly. */
6776 compute_section_prefix (dw_die_ref unit_die
)
6778 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6779 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6780 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6783 unsigned char checksum
[16];
6786 /* Compute the checksum of the DIE, then append part of it as hex digits to
6787 the name filename of the unit. */
6789 md5_init_ctx (&ctx
);
6791 die_checksum (unit_die
, &ctx
, &mark
);
6792 unmark_all_dies (unit_die
);
6793 md5_finish_ctx (&ctx
, checksum
);
6795 sprintf (name
, "%s.", base
);
6796 clean_symbol_name (name
);
6798 p
= name
+ strlen (name
);
6799 for (i
= 0; i
< 4; i
++)
6801 sprintf (p
, "%.2x", checksum
[i
]);
6805 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6806 comdat_symbol_number
= 0;
6809 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6812 is_type_die (dw_die_ref die
)
6814 switch (die
->die_tag
)
6816 case DW_TAG_array_type
:
6817 case DW_TAG_class_type
:
6818 case DW_TAG_interface_type
:
6819 case DW_TAG_enumeration_type
:
6820 case DW_TAG_pointer_type
:
6821 case DW_TAG_reference_type
:
6822 case DW_TAG_rvalue_reference_type
:
6823 case DW_TAG_string_type
:
6824 case DW_TAG_structure_type
:
6825 case DW_TAG_subroutine_type
:
6826 case DW_TAG_union_type
:
6827 case DW_TAG_ptr_to_member_type
:
6828 case DW_TAG_set_type
:
6829 case DW_TAG_subrange_type
:
6830 case DW_TAG_base_type
:
6831 case DW_TAG_const_type
:
6832 case DW_TAG_file_type
:
6833 case DW_TAG_packed_type
:
6834 case DW_TAG_volatile_type
:
6835 case DW_TAG_typedef
:
6842 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6843 Basically, we want to choose the bits that are likely to be shared between
6844 compilations (types) and leave out the bits that are specific to individual
6845 compilations (functions). */
6848 is_comdat_die (dw_die_ref c
)
6850 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6851 we do for stabs. The advantage is a greater likelihood of sharing between
6852 objects that don't include headers in the same order (and therefore would
6853 put the base types in a different comdat). jason 8/28/00 */
6855 if (c
->die_tag
== DW_TAG_base_type
)
6858 if (c
->die_tag
== DW_TAG_pointer_type
6859 || c
->die_tag
== DW_TAG_reference_type
6860 || c
->die_tag
== DW_TAG_rvalue_reference_type
6861 || c
->die_tag
== DW_TAG_const_type
6862 || c
->die_tag
== DW_TAG_volatile_type
)
6864 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6866 return t
? is_comdat_die (t
) : 0;
6869 return is_type_die (c
);
6872 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6873 compilation unit. */
6876 is_symbol_die (dw_die_ref c
)
6878 return (is_type_die (c
)
6879 || is_declaration_die (c
)
6880 || c
->die_tag
== DW_TAG_namespace
6881 || c
->die_tag
== DW_TAG_module
);
6884 /* Returns true iff C is a compile-unit DIE. */
6887 is_cu_die (dw_die_ref c
)
6889 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6892 /* Returns true iff C is a unit DIE of some sort. */
6895 is_unit_die (dw_die_ref c
)
6897 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6898 || c
->die_tag
== DW_TAG_partial_unit
6899 || c
->die_tag
== DW_TAG_type_unit
);
6902 /* Returns true iff C is a namespace DIE. */
6905 is_namespace_die (dw_die_ref c
)
6907 return c
&& c
->die_tag
== DW_TAG_namespace
;
6910 /* Returns true iff C is a class or structure DIE. */
6913 is_class_die (dw_die_ref c
)
6915 return c
&& (c
->die_tag
== DW_TAG_class_type
6916 || c
->die_tag
== DW_TAG_structure_type
);
6919 /* Return non-zero if this DIE is a template parameter. */
6922 is_template_parameter (dw_die_ref die
)
6924 switch (die
->die_tag
)
6926 case DW_TAG_template_type_param
:
6927 case DW_TAG_template_value_param
:
6928 case DW_TAG_GNU_template_template_param
:
6929 case DW_TAG_GNU_template_parameter_pack
:
6936 /* Return non-zero if this DIE represents a template instantiation. */
6939 is_template_instantiation (dw_die_ref die
)
6943 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6945 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6950 gen_internal_sym (const char *prefix
)
6954 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6955 return xstrdup (buf
);
6958 /* Assign symbols to all worthy DIEs under DIE. */
6961 assign_symbol_names (dw_die_ref die
)
6965 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6967 if (comdat_symbol_id
)
6969 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6971 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6972 comdat_symbol_id
, comdat_symbol_number
++);
6973 die
->die_id
.die_symbol
= xstrdup (p
);
6976 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6979 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6982 struct cu_hash_table_entry
6985 unsigned min_comdat_num
, max_comdat_num
;
6986 struct cu_hash_table_entry
*next
;
6989 /* Helpers to manipulate hash table of CUs. */
6991 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
6993 typedef die_struct
*compare_type
;
6994 static inline hashval_t
hash (const cu_hash_table_entry
*);
6995 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
6996 static inline void remove (cu_hash_table_entry
*);
7000 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7002 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7006 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7007 const die_struct
*entry2
)
7009 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7013 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7015 struct cu_hash_table_entry
*next
;
7025 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7027 /* Check whether we have already seen this CU and set up SYM_NUM
7030 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7032 struct cu_hash_table_entry dummy
;
7033 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7035 dummy
.max_comdat_num
= 0;
7037 slot
= htable
->find_slot_with_hash (cu
,
7038 htab_hash_string (cu
->die_id
.die_symbol
),
7042 for (; entry
; last
= entry
, entry
= entry
->next
)
7044 if (same_die_p_wrap (cu
, entry
->cu
))
7050 *sym_num
= entry
->min_comdat_num
;
7054 entry
= XCNEW (struct cu_hash_table_entry
);
7056 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7057 entry
->next
= *slot
;
7063 /* Record SYM_NUM to record of CU in HTABLE. */
7065 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7066 unsigned int sym_num
)
7068 struct cu_hash_table_entry
**slot
, *entry
;
7070 slot
= htable
->find_slot_with_hash (cu
,
7071 htab_hash_string (cu
->die_id
.die_symbol
),
7075 entry
->max_comdat_num
= sym_num
;
7078 /* Traverse the DIE (which is always comp_unit_die), and set up
7079 additional compilation units for each of the include files we see
7080 bracketed by BINCL/EINCL. */
7083 break_out_includes (dw_die_ref die
)
7086 dw_die_ref unit
= NULL
;
7087 limbo_die_node
*node
, **pnode
;
7091 dw_die_ref prev
= c
;
7093 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7094 || (unit
&& is_comdat_die (c
)))
7096 dw_die_ref next
= c
->die_sib
;
7098 /* This DIE is for a secondary CU; remove it from the main one. */
7099 remove_child_with_prev (c
, prev
);
7101 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7102 unit
= push_new_compile_unit (unit
, c
);
7103 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7104 unit
= pop_compile_unit (unit
);
7106 add_child_die (unit
, c
);
7108 if (c
== die
->die_child
)
7111 } while (c
!= die
->die_child
);
7114 /* We can only use this in debugging, since the frontend doesn't check
7115 to make sure that we leave every include file we enter. */
7119 assign_symbol_names (die
);
7120 cu_hash_type
cu_hash_table (10);
7121 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7127 compute_section_prefix (node
->die
);
7128 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7129 &comdat_symbol_number
);
7130 assign_symbol_names (node
->die
);
7132 *pnode
= node
->next
;
7135 pnode
= &node
->next
;
7136 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7137 comdat_symbol_number
);
7142 /* Return non-zero if this DIE is a declaration. */
7145 is_declaration_die (dw_die_ref die
)
7150 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7151 if (a
->dw_attr
== DW_AT_declaration
)
7157 /* Return non-zero if this DIE is nested inside a subprogram. */
7160 is_nested_in_subprogram (dw_die_ref die
)
7162 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7166 return local_scope_p (decl
);
7169 /* Return non-zero if this DIE contains a defining declaration of a
7173 contains_subprogram_definition (dw_die_ref die
)
7177 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7179 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7183 /* Return non-zero if this is a type DIE that should be moved to a
7184 COMDAT .debug_types section. */
7187 should_move_die_to_comdat (dw_die_ref die
)
7189 switch (die
->die_tag
)
7191 case DW_TAG_class_type
:
7192 case DW_TAG_structure_type
:
7193 case DW_TAG_enumeration_type
:
7194 case DW_TAG_union_type
:
7195 /* Don't move declarations, inlined instances, types nested in a
7196 subprogram, or types that contain subprogram definitions. */
7197 if (is_declaration_die (die
)
7198 || get_AT (die
, DW_AT_abstract_origin
)
7199 || is_nested_in_subprogram (die
)
7200 || contains_subprogram_definition (die
))
7203 case DW_TAG_array_type
:
7204 case DW_TAG_interface_type
:
7205 case DW_TAG_pointer_type
:
7206 case DW_TAG_reference_type
:
7207 case DW_TAG_rvalue_reference_type
:
7208 case DW_TAG_string_type
:
7209 case DW_TAG_subroutine_type
:
7210 case DW_TAG_ptr_to_member_type
:
7211 case DW_TAG_set_type
:
7212 case DW_TAG_subrange_type
:
7213 case DW_TAG_base_type
:
7214 case DW_TAG_const_type
:
7215 case DW_TAG_file_type
:
7216 case DW_TAG_packed_type
:
7217 case DW_TAG_volatile_type
:
7218 case DW_TAG_typedef
:
7224 /* Make a clone of DIE. */
7227 clone_die (dw_die_ref die
)
7233 clone
= ggc_cleared_alloc
<die_node
> ();
7234 clone
->die_tag
= die
->die_tag
;
7236 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7237 add_dwarf_attr (clone
, a
);
7242 /* Make a clone of the tree rooted at DIE. */
7245 clone_tree (dw_die_ref die
)
7248 dw_die_ref clone
= clone_die (die
);
7250 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7255 /* Make a clone of DIE as a declaration. */
7258 clone_as_declaration (dw_die_ref die
)
7265 /* If the DIE is already a declaration, just clone it. */
7266 if (is_declaration_die (die
))
7267 return clone_die (die
);
7269 /* If the DIE is a specification, just clone its declaration DIE. */
7270 decl
= get_AT_ref (die
, DW_AT_specification
);
7273 clone
= clone_die (decl
);
7274 if (die
->comdat_type_p
)
7275 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7279 clone
= ggc_cleared_alloc
<die_node
> ();
7280 clone
->die_tag
= die
->die_tag
;
7282 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7284 /* We don't want to copy over all attributes.
7285 For example we don't want DW_AT_byte_size because otherwise we will no
7286 longer have a declaration and GDB will treat it as a definition. */
7290 case DW_AT_abstract_origin
:
7291 case DW_AT_artificial
:
7292 case DW_AT_containing_type
:
7293 case DW_AT_external
:
7296 case DW_AT_virtuality
:
7297 case DW_AT_linkage_name
:
7298 case DW_AT_MIPS_linkage_name
:
7299 add_dwarf_attr (clone
, a
);
7301 case DW_AT_byte_size
:
7307 if (die
->comdat_type_p
)
7308 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7310 add_AT_flag (clone
, DW_AT_declaration
, 1);
7315 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7317 struct decl_table_entry
7323 /* Helpers to manipulate hash table of copied declarations. */
7325 /* Hashtable helpers. */
7327 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7329 typedef die_struct
*compare_type
;
7330 static inline hashval_t
hash (const decl_table_entry
*);
7331 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7335 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7337 return htab_hash_pointer (entry
->orig
);
7341 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7342 const die_struct
*entry2
)
7344 return entry1
->orig
== entry2
;
7347 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7349 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7350 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7351 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7352 to check if the ancestor has already been copied into UNIT. */
7355 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7356 decl_hash_type
*decl_table
)
7358 dw_die_ref parent
= die
->die_parent
;
7359 dw_die_ref new_parent
= unit
;
7361 decl_table_entry
**slot
= NULL
;
7362 struct decl_table_entry
*entry
= NULL
;
7366 /* Check if the entry has already been copied to UNIT. */
7367 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7369 if (*slot
!= HTAB_EMPTY_ENTRY
)
7375 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7376 entry
= XCNEW (struct decl_table_entry
);
7384 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7387 if (!is_unit_die (parent
))
7388 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7391 copy
= clone_as_declaration (die
);
7392 add_child_die (new_parent
, copy
);
7396 /* Record the pointer to the copy. */
7402 /* Copy the declaration context to the new type unit DIE. This includes
7403 any surrounding namespace or type declarations. If the DIE has an
7404 AT_specification attribute, it also includes attributes and children
7405 attached to the specification, and returns a pointer to the original
7406 parent of the declaration DIE. Returns NULL otherwise. */
7409 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7412 dw_die_ref new_decl
;
7413 dw_die_ref orig_parent
= NULL
;
7415 decl
= get_AT_ref (die
, DW_AT_specification
);
7424 /* The original DIE will be changed to a declaration, and must
7425 be moved to be a child of the original declaration DIE. */
7426 orig_parent
= decl
->die_parent
;
7428 /* Copy the type node pointer from the new DIE to the original
7429 declaration DIE so we can forward references later. */
7430 decl
->comdat_type_p
= true;
7431 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7433 remove_AT (die
, DW_AT_specification
);
7435 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7437 if (a
->dw_attr
!= DW_AT_name
7438 && a
->dw_attr
!= DW_AT_declaration
7439 && a
->dw_attr
!= DW_AT_external
)
7440 add_dwarf_attr (die
, a
);
7443 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7446 if (decl
->die_parent
!= NULL
7447 && !is_unit_die (decl
->die_parent
))
7449 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7450 if (new_decl
!= NULL
)
7452 remove_AT (new_decl
, DW_AT_signature
);
7453 add_AT_specification (die
, new_decl
);
7460 /* Generate the skeleton ancestor tree for the given NODE, then clone
7461 the DIE and add the clone into the tree. */
7464 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7466 if (node
->new_die
!= NULL
)
7469 node
->new_die
= clone_as_declaration (node
->old_die
);
7471 if (node
->parent
!= NULL
)
7473 generate_skeleton_ancestor_tree (node
->parent
);
7474 add_child_die (node
->parent
->new_die
, node
->new_die
);
7478 /* Generate a skeleton tree of DIEs containing any declarations that are
7479 found in the original tree. We traverse the tree looking for declaration
7480 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7483 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7485 skeleton_chain_node node
;
7488 dw_die_ref prev
= NULL
;
7489 dw_die_ref next
= NULL
;
7491 node
.parent
= parent
;
7493 first
= c
= parent
->old_die
->die_child
;
7497 if (prev
== NULL
|| prev
->die_sib
== c
)
7500 next
= (c
== first
? NULL
: c
->die_sib
);
7502 node
.new_die
= NULL
;
7503 if (is_declaration_die (c
))
7505 if (is_template_instantiation (c
))
7507 /* Instantiated templates do not need to be cloned into the
7508 type unit. Just move the DIE and its children back to
7509 the skeleton tree (in the main CU). */
7510 remove_child_with_prev (c
, prev
);
7511 add_child_die (parent
->new_die
, c
);
7516 /* Clone the existing DIE, move the original to the skeleton
7517 tree (which is in the main CU), and put the clone, with
7518 all the original's children, where the original came from
7519 (which is about to be moved to the type unit). */
7520 dw_die_ref clone
= clone_die (c
);
7521 move_all_children (c
, clone
);
7523 /* If the original has a DW_AT_object_pointer attribute,
7524 it would now point to a child DIE just moved to the
7525 cloned tree, so we need to remove that attribute from
7527 remove_AT (c
, DW_AT_object_pointer
);
7529 replace_child (c
, clone
, prev
);
7530 generate_skeleton_ancestor_tree (parent
);
7531 add_child_die (parent
->new_die
, c
);
7536 generate_skeleton_bottom_up (&node
);
7537 } while (next
!= NULL
);
7540 /* Wrapper function for generate_skeleton_bottom_up. */
7543 generate_skeleton (dw_die_ref die
)
7545 skeleton_chain_node node
;
7548 node
.new_die
= NULL
;
7551 /* If this type definition is nested inside another type,
7552 and is not an instantiation of a template, always leave
7553 at least a declaration in its place. */
7554 if (die
->die_parent
!= NULL
7555 && is_type_die (die
->die_parent
)
7556 && !is_template_instantiation (die
))
7557 node
.new_die
= clone_as_declaration (die
);
7559 generate_skeleton_bottom_up (&node
);
7560 return node
.new_die
;
7563 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7564 declaration. The original DIE is moved to a new compile unit so that
7565 existing references to it follow it to the new location. If any of the
7566 original DIE's descendants is a declaration, we need to replace the
7567 original DIE with a skeleton tree and move the declarations back into the
7571 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7574 dw_die_ref skeleton
, orig_parent
;
7576 /* Copy the declaration context to the type unit DIE. If the returned
7577 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7579 orig_parent
= copy_declaration_context (unit
, child
);
7581 skeleton
= generate_skeleton (child
);
7582 if (skeleton
== NULL
)
7583 remove_child_with_prev (child
, prev
);
7586 skeleton
->comdat_type_p
= true;
7587 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7589 /* If the original DIE was a specification, we need to put
7590 the skeleton under the parent DIE of the declaration.
7591 This leaves the original declaration in the tree, but
7592 it will be pruned later since there are no longer any
7593 references to it. */
7594 if (orig_parent
!= NULL
)
7596 remove_child_with_prev (child
, prev
);
7597 add_child_die (orig_parent
, skeleton
);
7600 replace_child (child
, skeleton
, prev
);
7606 /* Traverse the DIE and set up additional .debug_types sections for each
7607 type worthy of being placed in a COMDAT section. */
7610 break_out_comdat_types (dw_die_ref die
)
7614 dw_die_ref prev
= NULL
;
7615 dw_die_ref next
= NULL
;
7616 dw_die_ref unit
= NULL
;
7618 first
= c
= die
->die_child
;
7622 if (prev
== NULL
|| prev
->die_sib
== c
)
7625 next
= (c
== first
? NULL
: c
->die_sib
);
7626 if (should_move_die_to_comdat (c
))
7628 dw_die_ref replacement
;
7629 comdat_type_node
*type_node
;
7631 /* Break out nested types into their own type units. */
7632 break_out_comdat_types (c
);
7634 /* Create a new type unit DIE as the root for the new tree, and
7635 add it to the list of comdat types. */
7636 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7637 add_AT_unsigned (unit
, DW_AT_language
,
7638 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7639 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7640 type_node
->root_die
= unit
;
7641 type_node
->next
= comdat_type_list
;
7642 comdat_type_list
= type_node
;
7644 /* Generate the type signature. */
7645 generate_type_signature (c
, type_node
);
7647 /* Copy the declaration context, attributes, and children of the
7648 declaration into the new type unit DIE, then remove this DIE
7649 from the main CU (or replace it with a skeleton if necessary). */
7650 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7651 type_node
->skeleton_die
= replacement
;
7653 /* Add the DIE to the new compunit. */
7654 add_child_die (unit
, c
);
7656 if (replacement
!= NULL
)
7659 else if (c
->die_tag
== DW_TAG_namespace
7660 || c
->die_tag
== DW_TAG_class_type
7661 || c
->die_tag
== DW_TAG_structure_type
7662 || c
->die_tag
== DW_TAG_union_type
)
7664 /* Look for nested types that can be broken out. */
7665 break_out_comdat_types (c
);
7667 } while (next
!= NULL
);
7670 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7671 Enter all the cloned children into the hash table decl_table. */
7674 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7678 struct decl_table_entry
*entry
;
7679 decl_table_entry
**slot
;
7681 if (die
->die_tag
== DW_TAG_subprogram
)
7682 clone
= clone_as_declaration (die
);
7684 clone
= clone_die (die
);
7686 slot
= decl_table
->find_slot_with_hash (die
,
7687 htab_hash_pointer (die
), INSERT
);
7689 /* Assert that DIE isn't in the hash table yet. If it would be there
7690 before, the ancestors would be necessarily there as well, therefore
7691 clone_tree_partial wouldn't be called. */
7692 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7694 entry
= XCNEW (struct decl_table_entry
);
7696 entry
->copy
= clone
;
7699 if (die
->die_tag
!= DW_TAG_subprogram
)
7700 FOR_EACH_CHILD (die
, c
,
7701 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7706 /* Walk the DIE and its children, looking for references to incomplete
7707 or trivial types that are unmarked (i.e., that are not in the current
7711 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7717 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7719 if (AT_class (a
) == dw_val_class_die_ref
)
7721 dw_die_ref targ
= AT_ref (a
);
7722 decl_table_entry
**slot
;
7723 struct decl_table_entry
*entry
;
7725 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7728 slot
= decl_table
->find_slot_with_hash (targ
,
7729 htab_hash_pointer (targ
),
7732 if (*slot
!= HTAB_EMPTY_ENTRY
)
7734 /* TARG has already been copied, so we just need to
7735 modify the reference to point to the copy. */
7737 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7741 dw_die_ref parent
= unit
;
7742 dw_die_ref copy
= clone_die (targ
);
7744 /* Record in DECL_TABLE that TARG has been copied.
7745 Need to do this now, before the recursive call,
7746 because DECL_TABLE may be expanded and SLOT
7747 would no longer be a valid pointer. */
7748 entry
= XCNEW (struct decl_table_entry
);
7753 /* If TARG is not a declaration DIE, we need to copy its
7755 if (!is_declaration_die (targ
))
7759 add_child_die (copy
,
7760 clone_tree_partial (c
, decl_table
)));
7763 /* Make sure the cloned tree is marked as part of the
7767 /* If TARG has surrounding context, copy its ancestor tree
7768 into the new type unit. */
7769 if (targ
->die_parent
!= NULL
7770 && !is_unit_die (targ
->die_parent
))
7771 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7774 add_child_die (parent
, copy
);
7775 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7777 /* Make sure the newly-copied DIE is walked. If it was
7778 installed in a previously-added context, it won't
7779 get visited otherwise. */
7782 /* Find the highest point of the newly-added tree,
7783 mark each node along the way, and walk from there. */
7784 parent
->die_mark
= 1;
7785 while (parent
->die_parent
7786 && parent
->die_parent
->die_mark
== 0)
7788 parent
= parent
->die_parent
;
7789 parent
->die_mark
= 1;
7791 copy_decls_walk (unit
, parent
, decl_table
);
7797 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7800 /* Copy declarations for "unworthy" types into the new comdat section.
7801 Incomplete types, modified types, and certain other types aren't broken
7802 out into comdat sections of their own, so they don't have a signature,
7803 and we need to copy the declaration into the same section so that we
7804 don't have an external reference. */
7807 copy_decls_for_unworthy_types (dw_die_ref unit
)
7810 decl_hash_type
decl_table (10);
7811 copy_decls_walk (unit
, unit
, &decl_table
);
7815 /* Traverse the DIE and add a sibling attribute if it may have the
7816 effect of speeding up access to siblings. To save some space,
7817 avoid generating sibling attributes for DIE's without children. */
7820 add_sibling_attributes (dw_die_ref die
)
7824 if (! die
->die_child
)
7827 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7828 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7830 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7833 /* Output all location lists for the DIE and its children. */
7836 output_location_lists (dw_die_ref die
)
7842 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7843 if (AT_class (a
) == dw_val_class_loc_list
)
7844 output_loc_list (AT_loc_list (a
));
7846 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7849 /* We want to limit the number of external references, because they are
7850 larger than local references: a relocation takes multiple words, and
7851 even a sig8 reference is always eight bytes, whereas a local reference
7852 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7853 So if we encounter multiple external references to the same type DIE, we
7854 make a local typedef stub for it and redirect all references there.
7856 This is the element of the hash table for keeping track of these
7866 /* Hashtable helpers. */
7868 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
7870 static inline hashval_t
hash (const external_ref
*);
7871 static inline bool equal (const external_ref
*, const external_ref
*);
7875 external_ref_hasher::hash (const external_ref
*r
)
7877 dw_die_ref die
= r
->type
;
7880 /* We can't use the address of the DIE for hashing, because
7881 that will make the order of the stub DIEs non-deterministic. */
7882 if (! die
->comdat_type_p
)
7883 /* We have a symbol; use it to compute a hash. */
7884 h
= htab_hash_string (die
->die_id
.die_symbol
);
7887 /* We have a type signature; use a subset of the bits as the hash.
7888 The 8-byte signature is at least as large as hashval_t. */
7889 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
7890 memcpy (&h
, type_node
->signature
, sizeof (h
));
7896 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
7898 return r1
->type
== r2
->type
;
7901 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7903 /* Return a pointer to the external_ref for references to DIE. */
7905 static struct external_ref
*
7906 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
7908 struct external_ref ref
, *ref_p
;
7909 external_ref
**slot
;
7912 slot
= map
->find_slot (&ref
, INSERT
);
7913 if (*slot
!= HTAB_EMPTY_ENTRY
)
7916 ref_p
= XCNEW (struct external_ref
);
7922 /* Subroutine of optimize_external_refs, below.
7924 If we see a type skeleton, record it as our stub. If we see external
7925 references, remember how many we've seen. */
7928 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
7933 struct external_ref
*ref_p
;
7935 if (is_type_die (die
)
7936 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7938 /* This is a local skeleton; use it for local references. */
7939 ref_p
= lookup_external_ref (map
, c
);
7943 /* Scan the DIE references, and remember any that refer to DIEs from
7944 other CUs (i.e. those which are not marked). */
7945 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7946 if (AT_class (a
) == dw_val_class_die_ref
7947 && (c
= AT_ref (a
))->die_mark
== 0
7950 ref_p
= lookup_external_ref (map
, c
);
7954 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7957 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7958 points to an external_ref, DATA is the CU we're processing. If we don't
7959 already have a local stub, and we have multiple refs, build a stub. */
7962 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7964 struct external_ref
*ref_p
= *slot
;
7966 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7968 /* We have multiple references to this type, so build a small stub.
7969 Both of these forms are a bit dodgy from the perspective of the
7970 DWARF standard, since technically they should have names. */
7971 dw_die_ref cu
= data
;
7972 dw_die_ref type
= ref_p
->type
;
7973 dw_die_ref stub
= NULL
;
7975 if (type
->comdat_type_p
)
7977 /* If we refer to this type via sig8, use AT_signature. */
7978 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7979 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7983 /* Otherwise, use a typedef with no name. */
7984 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7985 add_AT_die_ref (stub
, DW_AT_type
, type
);
7994 /* DIE is a unit; look through all the DIE references to see if there are
7995 any external references to types, and if so, create local stubs for
7996 them which will be applied in build_abbrev_table. This is useful because
7997 references to local DIEs are smaller. */
7999 static external_ref_hash_type
*
8000 optimize_external_refs (dw_die_ref die
)
8002 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8003 optimize_external_refs_1 (die
, map
);
8004 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8008 /* The format of each DIE (and its attribute value pairs) is encoded in an
8009 abbreviation table. This routine builds the abbreviation table and assigns
8010 a unique abbreviation id for each abbreviation entry. The children of each
8011 die are visited recursively. */
8014 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8016 unsigned long abbrev_id
;
8017 unsigned int n_alloc
;
8022 /* Scan the DIE references, and replace any that refer to
8023 DIEs from other CUs (i.e. those which are not marked) with
8024 the local stubs we built in optimize_external_refs. */
8025 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8026 if (AT_class (a
) == dw_val_class_die_ref
8027 && (c
= AT_ref (a
))->die_mark
== 0)
8029 struct external_ref
*ref_p
;
8030 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8032 ref_p
= lookup_external_ref (extern_map
, c
);
8033 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8034 change_AT_die_ref (a
, ref_p
->stub
);
8036 /* We aren't changing this reference, so mark it external. */
8037 set_AT_ref_external (a
, 1);
8040 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8042 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8043 dw_attr_node
*die_a
, *abbrev_a
;
8047 if (abbrev
->die_tag
!= die
->die_tag
)
8049 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8052 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8055 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8057 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8058 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8059 || (value_format (abbrev_a
) != value_format (die_a
)))
8069 if (abbrev_id
>= abbrev_die_table_in_use
)
8071 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8073 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8074 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8077 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8078 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8079 abbrev_die_table_allocated
= n_alloc
;
8082 ++abbrev_die_table_in_use
;
8083 abbrev_die_table
[abbrev_id
] = die
;
8086 die
->die_abbrev
= abbrev_id
;
8087 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8090 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8093 constant_size (unsigned HOST_WIDE_INT value
)
8100 log
= floor_log2 (value
);
8103 log
= 1 << (floor_log2 (log
) + 1);
8108 /* Return the size of a DIE as it is represented in the
8109 .debug_info section. */
8111 static unsigned long
8112 size_of_die (dw_die_ref die
)
8114 unsigned long size
= 0;
8117 enum dwarf_form form
;
8119 size
+= size_of_uleb128 (die
->die_abbrev
);
8120 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8122 switch (AT_class (a
))
8124 case dw_val_class_addr
:
8125 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8127 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8128 size
+= size_of_uleb128 (AT_index (a
));
8131 size
+= DWARF2_ADDR_SIZE
;
8133 case dw_val_class_offset
:
8134 size
+= DWARF_OFFSET_SIZE
;
8136 case dw_val_class_loc
:
8138 unsigned long lsize
= size_of_locs (AT_loc (a
));
8141 if (dwarf_version
>= 4)
8142 size
+= size_of_uleb128 (lsize
);
8144 size
+= constant_size (lsize
);
8148 case dw_val_class_loc_list
:
8149 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8151 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8152 size
+= size_of_uleb128 (AT_index (a
));
8155 size
+= DWARF_OFFSET_SIZE
;
8157 case dw_val_class_range_list
:
8158 size
+= DWARF_OFFSET_SIZE
;
8160 case dw_val_class_const
:
8161 size
+= size_of_sleb128 (AT_int (a
));
8163 case dw_val_class_unsigned_const
:
8165 int csize
= constant_size (AT_unsigned (a
));
8166 if (dwarf_version
== 3
8167 && a
->dw_attr
== DW_AT_data_member_location
8169 size
+= size_of_uleb128 (AT_unsigned (a
));
8174 case dw_val_class_const_double
:
8175 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8176 if (HOST_BITS_PER_WIDE_INT
>= 64)
8179 case dw_val_class_wide_int
:
8180 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8181 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8182 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8186 case dw_val_class_vec
:
8187 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8188 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8189 + a
->dw_attr_val
.v
.val_vec
.length
8190 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8192 case dw_val_class_flag
:
8193 if (dwarf_version
>= 4)
8194 /* Currently all add_AT_flag calls pass in 1 as last argument,
8195 so DW_FORM_flag_present can be used. If that ever changes,
8196 we'll need to use DW_FORM_flag and have some optimization
8197 in build_abbrev_table that will change those to
8198 DW_FORM_flag_present if it is set to 1 in all DIEs using
8199 the same abbrev entry. */
8200 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8204 case dw_val_class_die_ref
:
8205 if (AT_ref_external (a
))
8207 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8208 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8209 is sized by target address length, whereas in DWARF3
8210 it's always sized as an offset. */
8211 if (use_debug_types
)
8212 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8213 else if (dwarf_version
== 2)
8214 size
+= DWARF2_ADDR_SIZE
;
8216 size
+= DWARF_OFFSET_SIZE
;
8219 size
+= DWARF_OFFSET_SIZE
;
8221 case dw_val_class_fde_ref
:
8222 size
+= DWARF_OFFSET_SIZE
;
8224 case dw_val_class_lbl_id
:
8225 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8227 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8228 size
+= size_of_uleb128 (AT_index (a
));
8231 size
+= DWARF2_ADDR_SIZE
;
8233 case dw_val_class_lineptr
:
8234 case dw_val_class_macptr
:
8235 size
+= DWARF_OFFSET_SIZE
;
8237 case dw_val_class_str
:
8238 form
= AT_string_form (a
);
8239 if (form
== DW_FORM_strp
)
8240 size
+= DWARF_OFFSET_SIZE
;
8241 else if (form
== DW_FORM_GNU_str_index
)
8242 size
+= size_of_uleb128 (AT_index (a
));
8244 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8246 case dw_val_class_file
:
8247 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8249 case dw_val_class_data8
:
8252 case dw_val_class_vms_delta
:
8253 size
+= DWARF_OFFSET_SIZE
;
8255 case dw_val_class_high_pc
:
8256 size
+= DWARF2_ADDR_SIZE
;
8266 /* Size the debugging information associated with a given DIE. Visits the
8267 DIE's children recursively. Updates the global variable next_die_offset, on
8268 each time through. Uses the current value of next_die_offset to update the
8269 die_offset field in each DIE. */
8272 calc_die_sizes (dw_die_ref die
)
8276 gcc_assert (die
->die_offset
== 0
8277 || (unsigned long int) die
->die_offset
== next_die_offset
);
8278 die
->die_offset
= next_die_offset
;
8279 next_die_offset
+= size_of_die (die
);
8281 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8283 if (die
->die_child
!= NULL
)
8284 /* Count the null byte used to terminate sibling lists. */
8285 next_die_offset
+= 1;
8288 /* Size just the base type children at the start of the CU.
8289 This is needed because build_abbrev needs to size locs
8290 and sizing of type based stack ops needs to know die_offset
8291 values for the base types. */
8294 calc_base_type_die_sizes (void)
8296 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8298 dw_die_ref base_type
;
8299 #if ENABLE_ASSERT_CHECKING
8300 dw_die_ref prev
= comp_unit_die ()->die_child
;
8303 die_offset
+= size_of_die (comp_unit_die ());
8304 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8306 #if ENABLE_ASSERT_CHECKING
8307 gcc_assert (base_type
->die_offset
== 0
8308 && prev
->die_sib
== base_type
8309 && base_type
->die_child
== NULL
8310 && base_type
->die_abbrev
);
8313 base_type
->die_offset
= die_offset
;
8314 die_offset
+= size_of_die (base_type
);
8318 /* Set the marks for a die and its children. We do this so
8319 that we know whether or not a reference needs to use FORM_ref_addr; only
8320 DIEs in the same CU will be marked. We used to clear out the offset
8321 and use that as the flag, but ran into ordering problems. */
8324 mark_dies (dw_die_ref die
)
8328 gcc_assert (!die
->die_mark
);
8331 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8334 /* Clear the marks for a die and its children. */
8337 unmark_dies (dw_die_ref die
)
8341 if (! use_debug_types
)
8342 gcc_assert (die
->die_mark
);
8345 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8348 /* Clear the marks for a die, its children and referred dies. */
8351 unmark_all_dies (dw_die_ref die
)
8361 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8363 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8364 if (AT_class (a
) == dw_val_class_die_ref
)
8365 unmark_all_dies (AT_ref (a
));
8368 /* Calculate if the entry should appear in the final output file. It may be
8369 from a pruned a type. */
8372 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8374 /* By limiting gnu pubnames to definitions only, gold can generate a
8375 gdb index without entries for declarations, which don't include
8376 enough information to be useful. */
8377 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8380 if (table
== pubname_table
)
8382 /* Enumerator names are part of the pubname table, but the
8383 parent DW_TAG_enumeration_type die may have been pruned.
8384 Don't output them if that is the case. */
8385 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8386 (p
->die
->die_parent
== NULL
8387 || !p
->die
->die_parent
->die_perennial_p
))
8390 /* Everything else in the pubname table is included. */
8394 /* The pubtypes table shouldn't include types that have been
8396 return (p
->die
->die_offset
!= 0
8397 || !flag_eliminate_unused_debug_types
);
8400 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8401 generated for the compilation unit. */
8403 static unsigned long
8404 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8409 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8411 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8412 FOR_EACH_VEC_ELT (*names
, i
, p
)
8413 if (include_pubname_in_output (names
, p
))
8414 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8416 size
+= DWARF_OFFSET_SIZE
;
8420 /* Return the size of the information in the .debug_aranges section. */
8422 static unsigned long
8423 size_of_aranges (void)
8427 size
= DWARF_ARANGES_HEADER_SIZE
;
8429 /* Count the address/length pair for this compilation unit. */
8430 if (text_section_used
)
8431 size
+= 2 * DWARF2_ADDR_SIZE
;
8432 if (cold_text_section_used
)
8433 size
+= 2 * DWARF2_ADDR_SIZE
;
8434 if (have_multiple_function_sections
)
8439 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8441 if (DECL_IGNORED_P (fde
->decl
))
8443 if (!fde
->in_std_section
)
8444 size
+= 2 * DWARF2_ADDR_SIZE
;
8445 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8446 size
+= 2 * DWARF2_ADDR_SIZE
;
8450 /* Count the two zero words used to terminated the address range table. */
8451 size
+= 2 * DWARF2_ADDR_SIZE
;
8455 /* Select the encoding of an attribute value. */
8457 static enum dwarf_form
8458 value_format (dw_attr_node
*a
)
8460 switch (AT_class (a
))
8462 case dw_val_class_addr
:
8463 /* Only very few attributes allow DW_FORM_addr. */
8468 case DW_AT_entry_pc
:
8469 case DW_AT_trampoline
:
8470 return (AT_index (a
) == NOT_INDEXED
8471 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8475 switch (DWARF2_ADDR_SIZE
)
8478 return DW_FORM_data1
;
8480 return DW_FORM_data2
;
8482 return DW_FORM_data4
;
8484 return DW_FORM_data8
;
8488 case dw_val_class_range_list
:
8489 case dw_val_class_loc_list
:
8490 if (dwarf_version
>= 4)
8491 return DW_FORM_sec_offset
;
8493 case dw_val_class_vms_delta
:
8494 case dw_val_class_offset
:
8495 switch (DWARF_OFFSET_SIZE
)
8498 return DW_FORM_data4
;
8500 return DW_FORM_data8
;
8504 case dw_val_class_loc
:
8505 if (dwarf_version
>= 4)
8506 return DW_FORM_exprloc
;
8507 switch (constant_size (size_of_locs (AT_loc (a
))))
8510 return DW_FORM_block1
;
8512 return DW_FORM_block2
;
8514 return DW_FORM_block4
;
8518 case dw_val_class_const
:
8519 return DW_FORM_sdata
;
8520 case dw_val_class_unsigned_const
:
8521 switch (constant_size (AT_unsigned (a
)))
8524 return DW_FORM_data1
;
8526 return DW_FORM_data2
;
8528 /* In DWARF3 DW_AT_data_member_location with
8529 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8530 constant, so we need to use DW_FORM_udata if we need
8531 a large constant. */
8532 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8533 return DW_FORM_udata
;
8534 return DW_FORM_data4
;
8536 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8537 return DW_FORM_udata
;
8538 return DW_FORM_data8
;
8542 case dw_val_class_const_double
:
8543 switch (HOST_BITS_PER_WIDE_INT
)
8546 return DW_FORM_data2
;
8548 return DW_FORM_data4
;
8550 return DW_FORM_data8
;
8553 return DW_FORM_block1
;
8555 case dw_val_class_wide_int
:
8556 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8559 return DW_FORM_data1
;
8561 return DW_FORM_data2
;
8563 return DW_FORM_data4
;
8565 return DW_FORM_data8
;
8567 return DW_FORM_block1
;
8569 case dw_val_class_vec
:
8570 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8571 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8574 return DW_FORM_block1
;
8576 return DW_FORM_block2
;
8578 return DW_FORM_block4
;
8582 case dw_val_class_flag
:
8583 if (dwarf_version
>= 4)
8585 /* Currently all add_AT_flag calls pass in 1 as last argument,
8586 so DW_FORM_flag_present can be used. If that ever changes,
8587 we'll need to use DW_FORM_flag and have some optimization
8588 in build_abbrev_table that will change those to
8589 DW_FORM_flag_present if it is set to 1 in all DIEs using
8590 the same abbrev entry. */
8591 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8592 return DW_FORM_flag_present
;
8594 return DW_FORM_flag
;
8595 case dw_val_class_die_ref
:
8596 if (AT_ref_external (a
))
8597 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8600 case dw_val_class_fde_ref
:
8601 return DW_FORM_data
;
8602 case dw_val_class_lbl_id
:
8603 return (AT_index (a
) == NOT_INDEXED
8604 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8605 case dw_val_class_lineptr
:
8606 case dw_val_class_macptr
:
8607 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8608 case dw_val_class_str
:
8609 return AT_string_form (a
);
8610 case dw_val_class_file
:
8611 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8614 return DW_FORM_data1
;
8616 return DW_FORM_data2
;
8618 return DW_FORM_data4
;
8623 case dw_val_class_data8
:
8624 return DW_FORM_data8
;
8626 case dw_val_class_high_pc
:
8627 switch (DWARF2_ADDR_SIZE
)
8630 return DW_FORM_data1
;
8632 return DW_FORM_data2
;
8634 return DW_FORM_data4
;
8636 return DW_FORM_data8
;
8646 /* Output the encoding of an attribute value. */
8649 output_value_format (dw_attr_node
*a
)
8651 enum dwarf_form form
= value_format (a
);
8653 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8656 /* Given a die and id, produce the appropriate abbreviations. */
8659 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8662 dw_attr_node
*a_attr
;
8664 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8665 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8666 dwarf_tag_name (abbrev
->die_tag
));
8668 if (abbrev
->die_child
!= NULL
)
8669 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8671 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8673 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8675 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8676 dwarf_attr_name (a_attr
->dw_attr
));
8677 output_value_format (a_attr
);
8680 dw2_asm_output_data (1, 0, NULL
);
8681 dw2_asm_output_data (1, 0, NULL
);
8685 /* Output the .debug_abbrev section which defines the DIE abbreviation
8689 output_abbrev_section (void)
8691 unsigned long abbrev_id
;
8693 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8694 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8696 /* Terminate the table. */
8697 dw2_asm_output_data (1, 0, NULL
);
8700 /* Output a symbol we can use to refer to this DIE from another CU. */
8703 output_die_symbol (dw_die_ref die
)
8705 const char *sym
= die
->die_id
.die_symbol
;
8707 gcc_assert (!die
->comdat_type_p
);
8712 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8713 /* We make these global, not weak; if the target doesn't support
8714 .linkonce, it doesn't support combining the sections, so debugging
8716 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8718 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8721 /* Return a new location list, given the begin and end range, and the
8724 static inline dw_loc_list_ref
8725 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8726 const char *section
)
8728 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8730 retlist
->begin
= begin
;
8731 retlist
->begin_entry
= NULL
;
8733 retlist
->expr
= expr
;
8734 retlist
->section
= section
;
8739 /* Generate a new internal symbol for this location list node, if it
8740 hasn't got one yet. */
8743 gen_llsym (dw_loc_list_ref list
)
8745 gcc_assert (!list
->ll_symbol
);
8746 list
->ll_symbol
= gen_internal_sym ("LLST");
8749 /* Output the location list given to us. */
8752 output_loc_list (dw_loc_list_ref list_head
)
8754 dw_loc_list_ref curr
= list_head
;
8756 if (list_head
->emitted
)
8758 list_head
->emitted
= true;
8760 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8762 /* Walk the location list, and output each range + expression. */
8763 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8766 /* Don't output an entry that starts and ends at the same address. */
8767 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8769 size
= size_of_locs (curr
->expr
);
8770 /* If the expression is too large, drop it on the floor. We could
8771 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8772 in the expression, but >= 64KB expressions for a single value
8773 in a single range are unlikely very useful. */
8776 if (dwarf_split_debug_info
)
8778 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8779 "Location list start/length entry (%s)",
8780 list_head
->ll_symbol
);
8781 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8782 "Location list range start index (%s)",
8784 /* The length field is 4 bytes. If we ever need to support
8785 an 8-byte length, we can add a new DW_LLE code or fall back
8786 to DW_LLE_GNU_start_end_entry. */
8787 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8788 "Location list range length (%s)",
8789 list_head
->ll_symbol
);
8791 else if (!have_multiple_function_sections
)
8793 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8794 "Location list begin address (%s)",
8795 list_head
->ll_symbol
);
8796 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8797 "Location list end address (%s)",
8798 list_head
->ll_symbol
);
8802 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8803 "Location list begin address (%s)",
8804 list_head
->ll_symbol
);
8805 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8806 "Location list end address (%s)",
8807 list_head
->ll_symbol
);
8810 /* Output the block length for this list of location operations. */
8811 gcc_assert (size
<= 0xffff);
8812 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8814 output_loc_sequence (curr
->expr
, -1);
8817 if (dwarf_split_debug_info
)
8818 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8819 "Location list terminator (%s)",
8820 list_head
->ll_symbol
);
8823 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8824 "Location list terminator begin (%s)",
8825 list_head
->ll_symbol
);
8826 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8827 "Location list terminator end (%s)",
8828 list_head
->ll_symbol
);
8832 /* Output a range_list offset into the debug_range section. Emit a
8833 relocated reference if val_entry is NULL, otherwise, emit an
8834 indirect reference. */
8837 output_range_list_offset (dw_attr_node
*a
)
8839 const char *name
= dwarf_attr_name (a
->dw_attr
);
8841 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8843 char *p
= strchr (ranges_section_label
, '\0');
8844 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8845 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8846 debug_ranges_section
, "%s", name
);
8850 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8851 "%s (offset from %s)", name
, ranges_section_label
);
8854 /* Output the offset into the debug_loc section. */
8857 output_loc_list_offset (dw_attr_node
*a
)
8859 char *sym
= AT_loc_list (a
)->ll_symbol
;
8862 if (dwarf_split_debug_info
)
8863 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8864 "%s", dwarf_attr_name (a
->dw_attr
));
8866 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8867 "%s", dwarf_attr_name (a
->dw_attr
));
8870 /* Output an attribute's index or value appropriately. */
8873 output_attr_index_or_value (dw_attr_node
*a
)
8875 const char *name
= dwarf_attr_name (a
->dw_attr
);
8877 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8879 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8882 switch (AT_class (a
))
8884 case dw_val_class_addr
:
8885 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8887 case dw_val_class_high_pc
:
8888 case dw_val_class_lbl_id
:
8889 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8891 case dw_val_class_loc_list
:
8892 output_loc_list_offset (a
);
8899 /* Output a type signature. */
8902 output_signature (const char *sig
, const char *name
)
8906 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8907 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8910 /* Output the DIE and its attributes. Called recursively to generate
8911 the definitions of each child DIE. */
8914 output_die (dw_die_ref die
)
8921 /* If someone in another CU might refer to us, set up a symbol for
8922 them to point to. */
8923 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8924 output_die_symbol (die
);
8926 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8927 (unsigned long)die
->die_offset
,
8928 dwarf_tag_name (die
->die_tag
));
8930 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8932 const char *name
= dwarf_attr_name (a
->dw_attr
);
8934 switch (AT_class (a
))
8936 case dw_val_class_addr
:
8937 output_attr_index_or_value (a
);
8940 case dw_val_class_offset
:
8941 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8945 case dw_val_class_range_list
:
8946 output_range_list_offset (a
);
8949 case dw_val_class_loc
:
8950 size
= size_of_locs (AT_loc (a
));
8952 /* Output the block length for this list of location operations. */
8953 if (dwarf_version
>= 4)
8954 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8956 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8958 output_loc_sequence (AT_loc (a
), -1);
8961 case dw_val_class_const
:
8962 /* ??? It would be slightly more efficient to use a scheme like is
8963 used for unsigned constants below, but gdb 4.x does not sign
8964 extend. Gdb 5.x does sign extend. */
8965 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8968 case dw_val_class_unsigned_const
:
8970 int csize
= constant_size (AT_unsigned (a
));
8971 if (dwarf_version
== 3
8972 && a
->dw_attr
== DW_AT_data_member_location
8974 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8976 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8980 case dw_val_class_const_double
:
8982 unsigned HOST_WIDE_INT first
, second
;
8984 if (HOST_BITS_PER_WIDE_INT
>= 64)
8985 dw2_asm_output_data (1,
8986 HOST_BITS_PER_DOUBLE_INT
8987 / HOST_BITS_PER_CHAR
,
8990 if (WORDS_BIG_ENDIAN
)
8992 first
= a
->dw_attr_val
.v
.val_double
.high
;
8993 second
= a
->dw_attr_val
.v
.val_double
.low
;
8997 first
= a
->dw_attr_val
.v
.val_double
.low
;
8998 second
= a
->dw_attr_val
.v
.val_double
.high
;
9001 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9003 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9008 case dw_val_class_wide_int
:
9011 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
9012 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
9013 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
9014 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
9017 if (WORDS_BIG_ENDIAN
)
9018 for (i
= len
- 1; i
>= 0; --i
)
9020 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9025 for (i
= 0; i
< len
; ++i
)
9027 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9034 case dw_val_class_vec
:
9036 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9037 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9041 dw2_asm_output_data (constant_size (len
* elt_size
),
9042 len
* elt_size
, "%s", name
);
9043 if (elt_size
> sizeof (HOST_WIDE_INT
))
9048 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9051 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9052 "fp or vector constant word %u", i
);
9056 case dw_val_class_flag
:
9057 if (dwarf_version
>= 4)
9059 /* Currently all add_AT_flag calls pass in 1 as last argument,
9060 so DW_FORM_flag_present can be used. If that ever changes,
9061 we'll need to use DW_FORM_flag and have some optimization
9062 in build_abbrev_table that will change those to
9063 DW_FORM_flag_present if it is set to 1 in all DIEs using
9064 the same abbrev entry. */
9065 gcc_assert (AT_flag (a
) == 1);
9067 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9068 ASM_COMMENT_START
, name
);
9071 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9074 case dw_val_class_loc_list
:
9075 output_attr_index_or_value (a
);
9078 case dw_val_class_die_ref
:
9079 if (AT_ref_external (a
))
9081 if (AT_ref (a
)->comdat_type_p
)
9083 comdat_type_node
*type_node
=
9084 AT_ref (a
)->die_id
.die_type_node
;
9086 gcc_assert (type_node
);
9087 output_signature (type_node
->signature
, name
);
9091 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9095 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9096 length, whereas in DWARF3 it's always sized as an
9098 if (dwarf_version
== 2)
9099 size
= DWARF2_ADDR_SIZE
;
9101 size
= DWARF_OFFSET_SIZE
;
9102 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9108 gcc_assert (AT_ref (a
)->die_offset
);
9109 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9114 case dw_val_class_fde_ref
:
9118 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9119 a
->dw_attr_val
.v
.val_fde_index
* 2);
9120 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9125 case dw_val_class_vms_delta
:
9126 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9127 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9128 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9131 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9132 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9137 case dw_val_class_lbl_id
:
9138 output_attr_index_or_value (a
);
9141 case dw_val_class_lineptr
:
9142 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9143 debug_line_section
, "%s", name
);
9146 case dw_val_class_macptr
:
9147 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9148 debug_macinfo_section
, "%s", name
);
9151 case dw_val_class_str
:
9152 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9153 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9154 a
->dw_attr_val
.v
.val_str
->label
,
9156 "%s: \"%s\"", name
, AT_string (a
));
9157 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9158 dw2_asm_output_data_uleb128 (AT_index (a
),
9159 "%s: \"%s\"", name
, AT_string (a
));
9161 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9164 case dw_val_class_file
:
9166 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9168 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9169 a
->dw_attr_val
.v
.val_file
->filename
);
9173 case dw_val_class_data8
:
9177 for (i
= 0; i
< 8; i
++)
9178 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9179 i
== 0 ? "%s" : NULL
, name
);
9183 case dw_val_class_high_pc
:
9184 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9185 get_AT_low_pc (die
), "DW_AT_high_pc");
9193 FOR_EACH_CHILD (die
, c
, output_die (c
));
9195 /* Add null byte to terminate sibling list. */
9196 if (die
->die_child
!= NULL
)
9197 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9198 (unsigned long) die
->die_offset
);
9201 /* Output the compilation unit that appears at the beginning of the
9202 .debug_info section, and precedes the DIE descriptions. */
9205 output_compilation_unit_header (void)
9207 /* We don't support actual DWARFv5 units yet, we just use some
9208 DWARFv5 draft DIE tags in DWARFv4 format. */
9209 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9211 if (!XCOFF_DEBUGGING_INFO
)
9213 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9214 dw2_asm_output_data (4, 0xffffffff,
9215 "Initial length escape value indicating 64-bit DWARF extension");
9216 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9217 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9218 "Length of Compilation Unit Info");
9221 dw2_asm_output_data (2, ver
, "DWARF version number");
9222 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9223 debug_abbrev_section
,
9224 "Offset Into Abbrev. Section");
9225 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9228 /* Output the compilation unit DIE and its children. */
9231 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9233 const char *secname
, *oldsym
;
9236 /* Unless we are outputting main CU, we may throw away empty ones. */
9237 if (!output_if_empty
&& die
->die_child
== NULL
)
9240 /* Even if there are no children of this DIE, we must output the information
9241 about the compilation unit. Otherwise, on an empty translation unit, we
9242 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9243 will then complain when examining the file. First mark all the DIEs in
9244 this CU so we know which get local refs. */
9247 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9249 build_abbrev_table (die
, extern_map
);
9253 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9254 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9255 calc_die_sizes (die
);
9257 oldsym
= die
->die_id
.die_symbol
;
9260 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9262 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9264 die
->die_id
.die_symbol
= NULL
;
9265 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9269 switch_to_section (debug_info_section
);
9270 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9271 info_section_emitted
= true;
9274 /* Output debugging information. */
9275 output_compilation_unit_header ();
9278 /* Leave the marks on the main CU, so we can check them in
9283 die
->die_id
.die_symbol
= oldsym
;
9287 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9288 and .debug_pubtypes. This is configured per-target, but can be
9289 overridden by the -gpubnames or -gno-pubnames options. */
9292 want_pubnames (void)
9294 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9296 if (debug_generate_pub_sections
!= -1)
9297 return debug_generate_pub_sections
;
9298 return targetm
.want_debug_pub_sections
;
9301 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9304 add_AT_pubnames (dw_die_ref die
)
9306 if (want_pubnames ())
9307 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9310 /* Add a string attribute value to a skeleton DIE. */
9313 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9317 struct indirect_string_node
*node
;
9319 if (! skeleton_debug_str_hash
)
9320 skeleton_debug_str_hash
9321 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9323 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9324 find_string_form (node
);
9325 if (node
->form
== DW_FORM_GNU_str_index
)
9326 node
->form
= DW_FORM_strp
;
9328 attr
.dw_attr
= attr_kind
;
9329 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9330 attr
.dw_attr_val
.val_entry
= NULL
;
9331 attr
.dw_attr_val
.v
.val_str
= node
;
9332 add_dwarf_attr (die
, &attr
);
9335 /* Helper function to generate top-level dies for skeleton debug_info and
9339 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9341 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9342 const char *comp_dir
= comp_dir_string ();
9344 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9345 if (comp_dir
!= NULL
)
9346 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9347 add_AT_pubnames (die
);
9348 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9351 /* Output skeleton debug sections that point to the dwo file. */
9354 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9356 /* We don't support actual DWARFv5 units yet, we just use some
9357 DWARFv5 draft DIE tags in DWARFv4 format. */
9358 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9360 /* These attributes will be found in the full debug_info section. */
9361 remove_AT (comp_unit
, DW_AT_producer
);
9362 remove_AT (comp_unit
, DW_AT_language
);
9364 switch_to_section (debug_skeleton_info_section
);
9365 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9367 /* Produce the skeleton compilation-unit header. This one differs enough from
9368 a normal CU header that it's better not to call output_compilation_unit
9370 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9371 dw2_asm_output_data (4, 0xffffffff,
9372 "Initial length escape value indicating 64-bit DWARF extension");
9374 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9375 DWARF_COMPILE_UNIT_HEADER_SIZE
9376 - DWARF_INITIAL_LENGTH_SIZE
9377 + size_of_die (comp_unit
),
9378 "Length of Compilation Unit Info");
9379 dw2_asm_output_data (2, ver
, "DWARF version number");
9380 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9381 debug_abbrev_section
,
9382 "Offset Into Abbrev. Section");
9383 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9385 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9386 output_die (comp_unit
);
9388 /* Build the skeleton debug_abbrev section. */
9389 switch_to_section (debug_skeleton_abbrev_section
);
9390 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9392 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9394 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9397 /* Output a comdat type unit DIE and its children. */
9400 output_comdat_type_unit (comdat_type_node
*node
)
9402 const char *secname
;
9405 #if defined (OBJECT_FORMAT_ELF)
9409 /* First mark all the DIEs in this CU so we know which get local refs. */
9410 mark_dies (node
->root_die
);
9412 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9414 build_abbrev_table (node
->root_die
, extern_map
);
9419 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9420 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9421 calc_die_sizes (node
->root_die
);
9423 #if defined (OBJECT_FORMAT_ELF)
9424 if (!dwarf_split_debug_info
)
9425 secname
= ".debug_types";
9427 secname
= ".debug_types.dwo";
9429 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9430 sprintf (tmp
, "wt.");
9431 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9432 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9433 comdat_key
= get_identifier (tmp
);
9434 targetm
.asm_out
.named_section (secname
,
9435 SECTION_DEBUG
| SECTION_LINKONCE
,
9438 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9439 sprintf (tmp
, ".gnu.linkonce.wt.");
9440 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9441 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9443 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9446 /* Output debugging information. */
9447 output_compilation_unit_header ();
9448 output_signature (node
->signature
, "Type Signature");
9449 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9450 "Offset to Type DIE");
9451 output_die (node
->root_die
);
9453 unmark_dies (node
->root_die
);
9456 /* Return the DWARF2/3 pubname associated with a decl. */
9459 dwarf2_name (tree decl
, int scope
)
9461 if (DECL_NAMELESS (decl
))
9463 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9466 /* Add a new entry to .debug_pubnames if appropriate. */
9469 add_pubname_string (const char *str
, dw_die_ref die
)
9474 e
.name
= xstrdup (str
);
9475 vec_safe_push (pubname_table
, e
);
9479 add_pubname (tree decl
, dw_die_ref die
)
9481 if (!want_pubnames ())
9484 /* Don't add items to the table when we expect that the consumer will have
9485 just read the enclosing die. For example, if the consumer is looking at a
9486 class_member, it will either be inside the class already, or will have just
9487 looked up the class to find the member. Either way, searching the class is
9488 faster than searching the index. */
9489 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9490 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9492 const char *name
= dwarf2_name (decl
, 1);
9495 add_pubname_string (name
, die
);
9499 /* Add an enumerator to the pubnames section. */
9502 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9506 gcc_assert (scope_name
);
9507 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9509 vec_safe_push (pubname_table
, e
);
9512 /* Add a new entry to .debug_pubtypes if appropriate. */
9515 add_pubtype (tree decl
, dw_die_ref die
)
9519 if (!want_pubnames ())
9522 if ((TREE_PUBLIC (decl
)
9523 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9524 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9527 const char *scope_name
= "";
9528 const char *sep
= is_cxx () ? "::" : ".";
9531 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9532 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9534 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9535 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9536 scope_name
= concat (scope_name
, sep
, NULL
);
9542 name
= type_tag (decl
);
9544 name
= lang_hooks
.dwarf_name (decl
, 1);
9546 /* If we don't have a name for the type, there's no point in adding
9548 if (name
!= NULL
&& name
[0] != '\0')
9551 e
.name
= concat (scope_name
, name
, NULL
);
9552 vec_safe_push (pubtype_table
, e
);
9555 /* Although it might be more consistent to add the pubinfo for the
9556 enumerators as their dies are created, they should only be added if the
9557 enum type meets the criteria above. So rather than re-check the parent
9558 enum type whenever an enumerator die is created, just output them all
9559 here. This isn't protected by the name conditional because anonymous
9560 enums don't have names. */
9561 if (die
->die_tag
== DW_TAG_enumeration_type
)
9565 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9570 /* Output a single entry in the pubnames table. */
9573 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9575 dw_die_ref die
= entry
->die
;
9576 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9578 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9580 if (debug_generate_pub_sections
== 2)
9582 /* This logic follows gdb's method for determining the value of the flag
9584 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9585 switch (die
->die_tag
)
9587 case DW_TAG_typedef
:
9588 case DW_TAG_base_type
:
9589 case DW_TAG_subrange_type
:
9590 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9591 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9593 case DW_TAG_enumerator
:
9594 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9595 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9596 if (!is_cxx () && !is_java ())
9597 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9599 case DW_TAG_subprogram
:
9600 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9601 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9603 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9605 case DW_TAG_constant
:
9606 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9607 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9608 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9610 case DW_TAG_variable
:
9611 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9612 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9613 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9615 case DW_TAG_namespace
:
9616 case DW_TAG_imported_declaration
:
9617 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9619 case DW_TAG_class_type
:
9620 case DW_TAG_interface_type
:
9621 case DW_TAG_structure_type
:
9622 case DW_TAG_union_type
:
9623 case DW_TAG_enumeration_type
:
9624 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9625 if (!is_cxx () && !is_java ())
9626 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9629 /* An unusual tag. Leave the flag-byte empty. */
9632 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9636 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9640 /* Output the public names table used to speed up access to externally
9641 visible names; or the public types table used to find type definitions. */
9644 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9647 unsigned long pubnames_length
= size_of_pubnames (names
);
9650 if (!XCOFF_DEBUGGING_INFO
)
9652 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9653 dw2_asm_output_data (4, 0xffffffff,
9654 "Initial length escape value indicating 64-bit DWARF extension");
9655 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9659 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9660 dw2_asm_output_data (2, 2, "DWARF Version");
9662 if (dwarf_split_debug_info
)
9663 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9664 debug_skeleton_info_section
,
9665 "Offset of Compilation Unit Info");
9667 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9669 "Offset of Compilation Unit Info");
9670 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9671 "Compilation Unit Length");
9673 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9675 if (include_pubname_in_output (names
, pub
))
9677 dw_offset die_offset
= pub
->die
->die_offset
;
9679 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9680 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9681 gcc_assert (pub
->die
->die_mark
);
9683 /* If we're putting types in their own .debug_types sections,
9684 the .debug_pubtypes table will still point to the compile
9685 unit (not the type unit), so we want to use the offset of
9686 the skeleton DIE (if there is one). */
9687 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9689 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
9691 if (type_node
!= NULL
)
9692 die_offset
= (type_node
->skeleton_die
!= NULL
9693 ? type_node
->skeleton_die
->die_offset
9694 : comp_unit_die ()->die_offset
);
9697 output_pubname (die_offset
, pub
);
9701 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9704 /* Output public names and types tables if necessary. */
9707 output_pubtables (void)
9709 if (!want_pubnames () || !info_section_emitted
)
9712 switch_to_section (debug_pubnames_section
);
9713 output_pubnames (pubname_table
);
9714 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9715 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9716 simply won't look for the section. */
9717 switch_to_section (debug_pubtypes_section
);
9718 output_pubnames (pubtype_table
);
9722 /* Output the information that goes into the .debug_aranges table.
9723 Namely, define the beginning and ending address range of the
9724 text section generated for this compilation unit. */
9727 output_aranges (void)
9730 unsigned long aranges_length
= size_of_aranges ();
9732 if (!XCOFF_DEBUGGING_INFO
)
9734 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9735 dw2_asm_output_data (4, 0xffffffff,
9736 "Initial length escape value indicating 64-bit DWARF extension");
9737 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9738 "Length of Address Ranges Info");
9741 /* Version number for aranges is still 2, even up to DWARF5. */
9742 dw2_asm_output_data (2, 2, "DWARF Version");
9743 if (dwarf_split_debug_info
)
9744 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9745 debug_skeleton_info_section
,
9746 "Offset of Compilation Unit Info");
9748 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9750 "Offset of Compilation Unit Info");
9751 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9752 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9754 /* We need to align to twice the pointer size here. */
9755 if (DWARF_ARANGES_PAD_SIZE
)
9757 /* Pad using a 2 byte words so that padding is correct for any
9759 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9760 2 * DWARF2_ADDR_SIZE
);
9761 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9762 dw2_asm_output_data (2, 0, NULL
);
9765 /* It is necessary not to output these entries if the sections were
9766 not used; if the sections were not used, the length will be 0 and
9767 the address may end up as 0 if the section is discarded by ld
9768 --gc-sections, leaving an invalid (0, 0) entry that can be
9769 confused with the terminator. */
9770 if (text_section_used
)
9772 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9773 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9774 text_section_label
, "Length");
9776 if (cold_text_section_used
)
9778 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9780 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9781 cold_text_section_label
, "Length");
9784 if (have_multiple_function_sections
)
9789 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9791 if (DECL_IGNORED_P (fde
->decl
))
9793 if (!fde
->in_std_section
)
9795 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9797 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9798 fde
->dw_fde_begin
, "Length");
9800 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9802 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9804 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9805 fde
->dw_fde_second_begin
, "Length");
9810 /* Output the terminator words. */
9811 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9812 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9815 /* Add a new entry to .debug_ranges. Return the offset at which it
9819 add_ranges_num (int num
)
9821 unsigned int in_use
= ranges_table_in_use
;
9823 if (in_use
== ranges_table_allocated
)
9825 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9826 ranges_table
= GGC_RESIZEVEC (dw_ranges
, ranges_table
,
9827 ranges_table_allocated
);
9828 memset (ranges_table
+ ranges_table_in_use
, 0,
9829 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges
));
9832 ranges_table
[in_use
].num
= num
;
9833 ranges_table_in_use
= in_use
+ 1;
9835 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9838 /* Add a new entry to .debug_ranges corresponding to a block, or a
9839 range terminator if BLOCK is NULL. */
9842 add_ranges (const_tree block
)
9844 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9847 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9848 When using dwarf_split_debug_info, address attributes in dies destined
9849 for the final executable should be direct references--setting the
9850 parameter force_direct ensures this behavior. */
9853 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9854 bool *added
, bool force_direct
)
9856 unsigned int in_use
= ranges_by_label_in_use
;
9857 unsigned int offset
;
9859 if (in_use
== ranges_by_label_allocated
)
9861 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9862 ranges_by_label
= GGC_RESIZEVEC (dw_ranges_by_label
, ranges_by_label
,
9863 ranges_by_label_allocated
);
9864 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9865 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges_by_label
));
9868 ranges_by_label
[in_use
].begin
= begin
;
9869 ranges_by_label
[in_use
].end
= end
;
9870 ranges_by_label_in_use
= in_use
+ 1;
9872 offset
= add_ranges_num (-(int)in_use
- 1);
9875 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9881 output_ranges (void)
9884 static const char *const start_fmt
= "Offset %#x";
9885 const char *fmt
= start_fmt
;
9887 for (i
= 0; i
< ranges_table_in_use
; i
++)
9889 int block_num
= ranges_table
[i
].num
;
9893 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9894 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9896 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9897 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9899 /* If all code is in the text section, then the compilation
9900 unit base address defaults to DW_AT_low_pc, which is the
9901 base of the text section. */
9902 if (!have_multiple_function_sections
)
9904 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9906 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9907 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9908 text_section_label
, NULL
);
9911 /* Otherwise, the compilation unit base address is zero,
9912 which allows us to use absolute addresses, and not worry
9913 about whether the target supports cross-section
9917 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9918 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9919 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9925 /* Negative block_num stands for an index into ranges_by_label. */
9926 else if (block_num
< 0)
9928 int lab_idx
= - block_num
- 1;
9930 if (!have_multiple_function_sections
)
9934 /* If we ever use add_ranges_by_labels () for a single
9935 function section, all we have to do is to take out
9937 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9938 ranges_by_label
[lab_idx
].begin
,
9940 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9941 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9942 ranges_by_label
[lab_idx
].end
,
9943 text_section_label
, NULL
);
9948 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9949 ranges_by_label
[lab_idx
].begin
,
9950 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9951 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9952 ranges_by_label
[lab_idx
].end
,
9958 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9959 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9965 /* Data structure containing information about input files. */
9968 const char *path
; /* Complete file name. */
9969 const char *fname
; /* File name part. */
9970 int length
; /* Length of entire string. */
9971 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9972 int dir_idx
; /* Index in directory table. */
9975 /* Data structure containing information about directories with source
9979 const char *path
; /* Path including directory name. */
9980 int length
; /* Path length. */
9981 int prefix
; /* Index of directory entry which is a prefix. */
9982 int count
; /* Number of files in this directory. */
9983 int dir_idx
; /* Index of directory used as base. */
9986 /* Callback function for file_info comparison. We sort by looking at
9987 the directories in the path. */
9990 file_info_cmp (const void *p1
, const void *p2
)
9992 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9993 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9994 const unsigned char *cp1
;
9995 const unsigned char *cp2
;
9997 /* Take care of file names without directories. We need to make sure that
9998 we return consistent values to qsort since some will get confused if
9999 we return the same value when identical operands are passed in opposite
10000 orders. So if neither has a directory, return 0 and otherwise return
10001 1 or -1 depending on which one has the directory. */
10002 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
10003 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
10005 cp1
= (const unsigned char *) s1
->path
;
10006 cp2
= (const unsigned char *) s2
->path
;
10012 /* Reached the end of the first path? If so, handle like above. */
10013 if ((cp1
== (const unsigned char *) s1
->fname
)
10014 || (cp2
== (const unsigned char *) s2
->fname
))
10015 return ((cp2
== (const unsigned char *) s2
->fname
)
10016 - (cp1
== (const unsigned char *) s1
->fname
));
10018 /* Character of current path component the same? */
10019 else if (*cp1
!= *cp2
)
10020 return *cp1
- *cp2
;
10024 struct file_name_acquire_data
10026 struct file_info
*files
;
10031 /* Traversal function for the hash table. */
10034 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
10036 struct dwarf_file_data
*d
= *slot
;
10037 struct file_info
*fi
;
10040 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
10042 if (! d
->emitted_number
)
10045 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10047 fi
= fnad
->files
+ fnad
->used_files
++;
10049 /* Skip all leading "./". */
10051 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10054 /* Create a new array entry. */
10056 fi
->length
= strlen (f
);
10059 /* Search for the file name part. */
10060 f
= strrchr (f
, DIR_SEPARATOR
);
10061 #if defined (DIR_SEPARATOR_2)
10063 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10067 if (f
== NULL
|| f
< g
)
10073 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10077 /* Output the directory table and the file name table. We try to minimize
10078 the total amount of memory needed. A heuristic is used to avoid large
10079 slowdowns with many input files. */
10082 output_file_names (void)
10084 struct file_name_acquire_data fnad
;
10086 struct file_info
*files
;
10087 struct dir_info
*dirs
;
10095 if (!last_emitted_file
)
10097 dw2_asm_output_data (1, 0, "End directory table");
10098 dw2_asm_output_data (1, 0, "End file name table");
10102 numfiles
= last_emitted_file
->emitted_number
;
10104 /* Allocate the various arrays we need. */
10105 files
= XALLOCAVEC (struct file_info
, numfiles
);
10106 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10108 fnad
.files
= files
;
10109 fnad
.used_files
= 0;
10110 fnad
.max_files
= numfiles
;
10111 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10112 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10114 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10116 /* Find all the different directories used. */
10117 dirs
[0].path
= files
[0].path
;
10118 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10119 dirs
[0].prefix
= -1;
10121 dirs
[0].dir_idx
= 0;
10122 files
[0].dir_idx
= 0;
10125 for (i
= 1; i
< numfiles
; i
++)
10126 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10127 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10128 dirs
[ndirs
- 1].length
) == 0)
10130 /* Same directory as last entry. */
10131 files
[i
].dir_idx
= ndirs
- 1;
10132 ++dirs
[ndirs
- 1].count
;
10138 /* This is a new directory. */
10139 dirs
[ndirs
].path
= files
[i
].path
;
10140 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10141 dirs
[ndirs
].count
= 1;
10142 dirs
[ndirs
].dir_idx
= ndirs
;
10143 files
[i
].dir_idx
= ndirs
;
10145 /* Search for a prefix. */
10146 dirs
[ndirs
].prefix
= -1;
10147 for (j
= 0; j
< ndirs
; j
++)
10148 if (dirs
[j
].length
< dirs
[ndirs
].length
10149 && dirs
[j
].length
> 1
10150 && (dirs
[ndirs
].prefix
== -1
10151 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10152 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10153 dirs
[ndirs
].prefix
= j
;
10158 /* Now to the actual work. We have to find a subset of the directories which
10159 allow expressing the file name using references to the directory table
10160 with the least amount of characters. We do not do an exhaustive search
10161 where we would have to check out every combination of every single
10162 possible prefix. Instead we use a heuristic which provides nearly optimal
10163 results in most cases and never is much off. */
10164 saved
= XALLOCAVEC (int, ndirs
);
10165 savehere
= XALLOCAVEC (int, ndirs
);
10167 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10168 for (i
= 0; i
< ndirs
; i
++)
10173 /* We can always save some space for the current directory. But this
10174 does not mean it will be enough to justify adding the directory. */
10175 savehere
[i
] = dirs
[i
].length
;
10176 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10178 for (j
= i
+ 1; j
< ndirs
; j
++)
10181 if (saved
[j
] < dirs
[i
].length
)
10183 /* Determine whether the dirs[i] path is a prefix of the
10187 k
= dirs
[j
].prefix
;
10188 while (k
!= -1 && k
!= (int) i
)
10189 k
= dirs
[k
].prefix
;
10193 /* Yes it is. We can possibly save some memory by
10194 writing the filenames in dirs[j] relative to
10196 savehere
[j
] = dirs
[i
].length
;
10197 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10202 /* Check whether we can save enough to justify adding the dirs[i]
10204 if (total
> dirs
[i
].length
+ 1)
10206 /* It's worthwhile adding. */
10207 for (j
= i
; j
< ndirs
; j
++)
10208 if (savehere
[j
] > 0)
10210 /* Remember how much we saved for this directory so far. */
10211 saved
[j
] = savehere
[j
];
10213 /* Remember the prefix directory. */
10214 dirs
[j
].dir_idx
= i
;
10219 /* Emit the directory name table. */
10220 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10221 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10222 dw2_asm_output_nstring (dirs
[i
].path
,
10224 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10225 "Directory Entry: %#x", i
+ idx_offset
);
10227 dw2_asm_output_data (1, 0, "End directory table");
10229 /* We have to emit them in the order of emitted_number since that's
10230 used in the debug info generation. To do this efficiently we
10231 generate a back-mapping of the indices first. */
10232 backmap
= XALLOCAVEC (int, numfiles
);
10233 for (i
= 0; i
< numfiles
; i
++)
10234 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10236 /* Now write all the file names. */
10237 for (i
= 0; i
< numfiles
; i
++)
10239 int file_idx
= backmap
[i
];
10240 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10242 #ifdef VMS_DEBUGGING_INFO
10243 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10245 /* Setting these fields can lead to debugger miscomparisons,
10246 but VMS Debug requires them to be set correctly. */
10251 int maxfilelen
= strlen (files
[file_idx
].path
)
10252 + dirs
[dir_idx
].length
10253 + MAX_VMS_VERSION_LEN
+ 1;
10254 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10256 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10257 snprintf (filebuf
, maxfilelen
, "%s;%d",
10258 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10260 dw2_asm_output_nstring
10261 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10263 /* Include directory index. */
10264 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10266 /* Modification time. */
10267 dw2_asm_output_data_uleb128
10268 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10272 /* File length in bytes. */
10273 dw2_asm_output_data_uleb128
10274 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10278 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10279 "File Entry: %#x", (unsigned) i
+ 1);
10281 /* Include directory index. */
10282 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10284 /* Modification time. */
10285 dw2_asm_output_data_uleb128 (0, NULL
);
10287 /* File length in bytes. */
10288 dw2_asm_output_data_uleb128 (0, NULL
);
10289 #endif /* VMS_DEBUGGING_INFO */
10292 dw2_asm_output_data (1, 0, "End file name table");
10296 /* Output one line number table into the .debug_line section. */
10299 output_one_line_info_table (dw_line_info_table
*table
)
10301 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10302 unsigned int current_line
= 1;
10303 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10304 dw_line_info_entry
*ent
;
10307 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10309 switch (ent
->opcode
)
10311 case LI_set_address
:
10312 /* ??? Unfortunately, we have little choice here currently, and
10313 must always use the most general form. GCC does not know the
10314 address delta itself, so we can't use DW_LNS_advance_pc. Many
10315 ports do have length attributes which will give an upper bound
10316 on the address range. We could perhaps use length attributes
10317 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10318 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10320 /* This can handle any delta. This takes
10321 4+DWARF2_ADDR_SIZE bytes. */
10322 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10323 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10324 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10325 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10329 if (ent
->val
== current_line
)
10331 /* We still need to start a new row, so output a copy insn. */
10332 dw2_asm_output_data (1, DW_LNS_copy
,
10333 "copy line %u", current_line
);
10337 int line_offset
= ent
->val
- current_line
;
10338 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10340 current_line
= ent
->val
;
10341 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10343 /* This can handle deltas from -10 to 234, using the current
10344 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10345 This takes 1 byte. */
10346 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10347 "line %u", current_line
);
10351 /* This can handle any delta. This takes at least 4 bytes,
10352 depending on the value being encoded. */
10353 dw2_asm_output_data (1, DW_LNS_advance_line
,
10354 "advance to line %u", current_line
);
10355 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10356 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10362 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10363 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10366 case LI_set_column
:
10367 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10368 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10371 case LI_negate_stmt
:
10372 current_is_stmt
= !current_is_stmt
;
10373 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10374 "is_stmt %d", current_is_stmt
);
10377 case LI_set_prologue_end
:
10378 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10379 "set prologue end");
10382 case LI_set_epilogue_begin
:
10383 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10384 "set epilogue begin");
10387 case LI_set_discriminator
:
10388 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10389 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10390 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10391 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10396 /* Emit debug info for the address of the end of the table. */
10397 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10398 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10399 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10400 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10402 dw2_asm_output_data (1, 0, "end sequence");
10403 dw2_asm_output_data_uleb128 (1, NULL
);
10404 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10407 /* Output the source line number correspondence information. This
10408 information goes into the .debug_line section. */
10411 output_line_info (bool prologue_only
)
10413 char l1
[20], l2
[20], p1
[20], p2
[20];
10414 /* We don't support DWARFv5 line tables yet. */
10415 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10416 bool saw_one
= false;
10419 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10420 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10421 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10422 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10424 if (!XCOFF_DEBUGGING_INFO
)
10426 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10427 dw2_asm_output_data (4, 0xffffffff,
10428 "Initial length escape value indicating 64-bit DWARF extension");
10429 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10430 "Length of Source Line Info");
10433 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10435 dw2_asm_output_data (2, ver
, "DWARF Version");
10436 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10437 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10439 /* Define the architecture-dependent minimum instruction length (in bytes).
10440 In this implementation of DWARF, this field is used for information
10441 purposes only. Since GCC generates assembly language, we have no
10442 a priori knowledge of how many instruction bytes are generated for each
10443 source line, and therefore can use only the DW_LNE_set_address and
10444 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10445 this as '1', which is "correct enough" for all architectures,
10446 and don't let the target override. */
10447 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10450 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10451 "Maximum Operations Per Instruction");
10452 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10453 "Default is_stmt_start flag");
10454 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10455 "Line Base Value (Special Opcodes)");
10456 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10457 "Line Range Value (Special Opcodes)");
10458 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10459 "Special Opcode Base");
10461 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10466 case DW_LNS_advance_pc
:
10467 case DW_LNS_advance_line
:
10468 case DW_LNS_set_file
:
10469 case DW_LNS_set_column
:
10470 case DW_LNS_fixed_advance_pc
:
10471 case DW_LNS_set_isa
:
10479 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10483 /* Write out the information about the files we use. */
10484 output_file_names ();
10485 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10488 /* Output the marker for the end of the line number info. */
10489 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10493 if (separate_line_info
)
10495 dw_line_info_table
*table
;
10498 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10501 output_one_line_info_table (table
);
10505 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10507 output_one_line_info_table (cold_text_section_line_info
);
10511 /* ??? Some Darwin linkers crash on a .debug_line section with no
10512 sequences. Further, merely a DW_LNE_end_sequence entry is not
10513 sufficient -- the address column must also be initialized.
10514 Make sure to output at least one set_address/end_sequence pair,
10515 choosing .text since that section is always present. */
10516 if (text_section_line_info
->in_use
|| !saw_one
)
10517 output_one_line_info_table (text_section_line_info
);
10519 /* Output the marker for the end of the line number info. */
10520 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10523 /* Given a pointer to a tree node for some base type, return a pointer to
10524 a DIE that describes the given type.
10526 This routine must only be called for GCC type nodes that correspond to
10527 Dwarf base (fundamental) types. */
10530 base_type_die (tree type
)
10532 dw_die_ref base_type_result
;
10533 enum dwarf_type encoding
;
10535 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10538 /* If this is a subtype that should not be emitted as a subrange type,
10539 use the base type. See subrange_type_for_debug_p. */
10540 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10541 type
= TREE_TYPE (type
);
10543 switch (TREE_CODE (type
))
10546 if ((dwarf_version
>= 4 || !dwarf_strict
)
10547 && TYPE_NAME (type
)
10548 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10549 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10550 && DECL_NAME (TYPE_NAME (type
)))
10552 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10553 if (strcmp (name
, "char16_t") == 0
10554 || strcmp (name
, "char32_t") == 0)
10556 encoding
= DW_ATE_UTF
;
10560 if (TYPE_STRING_FLAG (type
))
10562 if (TYPE_UNSIGNED (type
))
10563 encoding
= DW_ATE_unsigned_char
;
10565 encoding
= DW_ATE_signed_char
;
10567 else if (TYPE_UNSIGNED (type
))
10568 encoding
= DW_ATE_unsigned
;
10570 encoding
= DW_ATE_signed
;
10574 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10576 if (dwarf_version
>= 3 || !dwarf_strict
)
10577 encoding
= DW_ATE_decimal_float
;
10579 encoding
= DW_ATE_lo_user
;
10582 encoding
= DW_ATE_float
;
10585 case FIXED_POINT_TYPE
:
10586 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10587 encoding
= DW_ATE_lo_user
;
10588 else if (TYPE_UNSIGNED (type
))
10589 encoding
= DW_ATE_unsigned_fixed
;
10591 encoding
= DW_ATE_signed_fixed
;
10594 /* Dwarf2 doesn't know anything about complex ints, so use
10595 a user defined type for it. */
10597 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10598 encoding
= DW_ATE_complex_float
;
10600 encoding
= DW_ATE_lo_user
;
10604 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10605 encoding
= DW_ATE_boolean
;
10609 /* No other TREE_CODEs are Dwarf fundamental types. */
10610 gcc_unreachable ();
10613 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10615 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10616 int_size_in_bytes (type
));
10617 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10618 add_pubtype (type
, base_type_result
);
10620 return base_type_result
;
10623 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10624 named 'auto' in its type: return true for it, false otherwise. */
10627 is_cxx_auto (tree type
)
10631 tree name
= TYPE_IDENTIFIER (type
);
10632 if (name
== get_identifier ("auto")
10633 || name
== get_identifier ("decltype(auto)"))
10639 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10640 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10643 is_base_type (tree type
)
10645 switch (TREE_CODE (type
))
10651 case FIXED_POINT_TYPE
:
10654 case POINTER_BOUNDS_TYPE
:
10660 case QUAL_UNION_TYPE
:
10661 case ENUMERAL_TYPE
:
10662 case FUNCTION_TYPE
:
10665 case REFERENCE_TYPE
:
10673 if (is_cxx_auto (type
))
10675 gcc_unreachable ();
10681 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10682 node, return the size in bits for the type if it is a constant, or else
10683 return the alignment for the type if the type's size is not constant, or
10684 else return BITS_PER_WORD if the type actually turns out to be an
10685 ERROR_MARK node. */
10687 static inline unsigned HOST_WIDE_INT
10688 simple_type_size_in_bits (const_tree type
)
10690 if (TREE_CODE (type
) == ERROR_MARK
)
10691 return BITS_PER_WORD
;
10692 else if (TYPE_SIZE (type
) == NULL_TREE
)
10694 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10695 return tree_to_uhwi (TYPE_SIZE (type
));
10697 return TYPE_ALIGN (type
);
10700 /* Similarly, but return an offset_int instead of UHWI. */
10702 static inline offset_int
10703 offset_int_type_size_in_bits (const_tree type
)
10705 if (TREE_CODE (type
) == ERROR_MARK
)
10706 return BITS_PER_WORD
;
10707 else if (TYPE_SIZE (type
) == NULL_TREE
)
10709 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10710 return wi::to_offset (TYPE_SIZE (type
));
10712 return TYPE_ALIGN (type
);
10715 /* Given a pointer to a tree node for a subrange type, return a pointer
10716 to a DIE that describes the given type. */
10719 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10721 dw_die_ref subrange_die
;
10722 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10724 if (context_die
== NULL
)
10725 context_die
= comp_unit_die ();
10727 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10729 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10731 /* The size of the subrange type and its base type do not match,
10732 so we need to generate a size attribute for the subrange type. */
10733 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10737 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
10739 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
10741 return subrange_die
;
10744 /* Returns the (const and/or volatile) cv_qualifiers associated with
10745 the decl node. This will normally be augmented with the
10746 cv_qualifiers of the underlying type in add_type_attribute. */
10749 decl_quals (const_tree decl
)
10751 return ((TREE_READONLY (decl
)
10752 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
10753 | (TREE_THIS_VOLATILE (decl
)
10754 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
10757 /* Determine the TYPE whose qualifiers match the largest strict subset
10758 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10759 qualifiers outside QUAL_MASK. */
10762 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
10765 int best_rank
= 0, best_qual
= 0, max_rank
;
10767 type_quals
&= qual_mask
;
10768 max_rank
= popcount_hwi (type_quals
) - 1;
10770 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
10771 t
= TYPE_NEXT_VARIANT (t
))
10773 int q
= TYPE_QUALS (t
) & qual_mask
;
10775 if ((q
& type_quals
) == q
&& q
!= type_quals
10776 && check_base_type (t
, type
))
10778 int rank
= popcount_hwi (q
);
10780 if (rank
> best_rank
)
10791 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10792 entry that chains various modifiers in front of the given type. */
10795 modified_type_die (tree type
, int cv_quals
, dw_die_ref context_die
)
10797 enum tree_code code
= TREE_CODE (type
);
10798 dw_die_ref mod_type_die
;
10799 dw_die_ref sub_die
= NULL
;
10800 tree item_type
= NULL
;
10801 tree qualified_type
;
10802 tree name
, low
, high
;
10803 dw_die_ref mod_scope
;
10804 /* Only these cv-qualifiers are currently handled. */
10805 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
10806 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
10808 if (code
== ERROR_MARK
)
10811 cv_quals
&= cv_qual_mask
;
10813 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10814 tag modifier (and not an attribute) old consumers won't be able
10816 if (dwarf_version
< 3)
10817 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
10819 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
10820 if (dwarf_version
< 5)
10821 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
10823 /* See if we already have the appropriately qualified variant of
10825 qualified_type
= get_qualified_type (type
, cv_quals
);
10827 if (qualified_type
== sizetype
10828 && TYPE_NAME (qualified_type
)
10829 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10831 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10833 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10834 && TYPE_PRECISION (t
)
10835 == TYPE_PRECISION (qualified_type
)
10836 && TYPE_UNSIGNED (t
)
10837 == TYPE_UNSIGNED (qualified_type
));
10838 qualified_type
= t
;
10841 /* If we do, then we can just use its DIE, if it exists. */
10842 if (qualified_type
)
10844 mod_type_die
= lookup_type_die (qualified_type
);
10846 return mod_type_die
;
10849 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10851 /* Handle C typedef types. */
10852 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10853 && !DECL_ARTIFICIAL (name
))
10855 tree dtype
= TREE_TYPE (name
);
10857 if (qualified_type
== dtype
)
10859 /* For a named type, use the typedef. */
10860 gen_type_die (qualified_type
, context_die
);
10861 return lookup_type_die (qualified_type
);
10865 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
10866 dquals
&= cv_qual_mask
;
10867 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
10868 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
10869 /* cv-unqualified version of named type. Just use
10870 the unnamed type to which it refers. */
10871 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10872 cv_quals
, context_die
);
10873 /* Else cv-qualified version of named type; fall through. */
10877 mod_scope
= scope_die_for (type
, context_die
);
10881 struct qual_info
{ int q
; enum dwarf_tag t
; };
10882 static const struct qual_info qual_info
[] =
10884 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
},
10885 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
10886 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
10887 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
10892 /* Determine a lesser qualified type that most closely matches
10893 this one. Then generate DW_TAG_* entries for the remaining
10895 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
10897 mod_type_die
= modified_type_die (type
, sub_quals
, context_die
);
10899 for (i
= 0; i
< sizeof (qual_info
) / sizeof (qual_info
[0]); i
++)
10900 if (qual_info
[i
].q
& cv_quals
& ~sub_quals
)
10902 dw_die_ref d
= new_die (qual_info
[i
].t
, mod_scope
, type
);
10904 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
10908 else if (code
== POINTER_TYPE
)
10910 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10911 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10912 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10913 item_type
= TREE_TYPE (type
);
10914 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10915 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10916 TYPE_ADDR_SPACE (item_type
));
10918 else if (code
== REFERENCE_TYPE
)
10920 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10921 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10924 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10925 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10926 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10927 item_type
= TREE_TYPE (type
);
10928 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10929 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10930 TYPE_ADDR_SPACE (item_type
));
10932 else if (code
== INTEGER_TYPE
10933 && TREE_TYPE (type
) != NULL_TREE
10934 && subrange_type_for_debug_p (type
, &low
, &high
))
10936 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10937 item_type
= TREE_TYPE (type
);
10939 else if (is_base_type (type
))
10940 mod_type_die
= base_type_die (type
);
10943 gen_type_die (type
, context_die
);
10945 /* We have to get the type_main_variant here (and pass that to the
10946 `lookup_type_die' routine) because the ..._TYPE node we have
10947 might simply be a *copy* of some original type node (where the
10948 copy was created to help us keep track of typedef names) and
10949 that copy might have a different TYPE_UID from the original
10951 if (TREE_CODE (type
) != VECTOR_TYPE
)
10952 return lookup_type_die (type_main_variant (type
));
10954 /* Vectors have the debugging information in the type,
10955 not the main variant. */
10956 return lookup_type_die (type
);
10959 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10960 don't output a DW_TAG_typedef, since there isn't one in the
10961 user's program; just attach a DW_AT_name to the type.
10962 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10963 if the base type already has the same name. */
10965 && ((TREE_CODE (name
) != TYPE_DECL
10966 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10967 || (cv_quals
== TYPE_UNQUALIFIED
)))
10968 || (TREE_CODE (name
) == TYPE_DECL
10969 && TREE_TYPE (name
) == qualified_type
10970 && DECL_NAME (name
))))
10972 if (TREE_CODE (name
) == TYPE_DECL
)
10973 /* Could just call add_name_and_src_coords_attributes here,
10974 but since this is a builtin type it doesn't have any
10975 useful source coordinates anyway. */
10976 name
= DECL_NAME (name
);
10977 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10979 /* This probably indicates a bug. */
10980 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10982 name
= TYPE_IDENTIFIER (type
);
10983 add_name_attribute (mod_type_die
,
10984 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10987 if (qualified_type
)
10988 equate_type_number_to_die (qualified_type
, mod_type_die
);
10991 /* We must do this after the equate_type_number_to_die call, in case
10992 this is a recursive type. This ensures that the modified_type_die
10993 recursion will terminate even if the type is recursive. Recursive
10994 types are possible in Ada. */
10995 sub_die
= modified_type_die (item_type
,
10996 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
10999 if (sub_die
!= NULL
)
11000 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
11002 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
11003 if (TYPE_ARTIFICIAL (type
))
11004 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
11006 return mod_type_die
;
11009 /* Generate DIEs for the generic parameters of T.
11010 T must be either a generic type or a generic function.
11011 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
11014 gen_generic_params_dies (tree t
)
11018 dw_die_ref die
= NULL
;
11021 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
11025 die
= lookup_type_die (t
);
11026 else if (DECL_P (t
))
11027 die
= lookup_decl_die (t
);
11031 parms
= lang_hooks
.get_innermost_generic_parms (t
);
11033 /* T has no generic parameter. It means T is neither a generic type
11034 or function. End of story. */
11037 parms_num
= TREE_VEC_LENGTH (parms
);
11038 args
= lang_hooks
.get_innermost_generic_args (t
);
11039 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
11040 non_default
= int_cst_value (TREE_CHAIN (args
));
11042 non_default
= TREE_VEC_LENGTH (args
);
11043 for (i
= 0; i
< parms_num
; i
++)
11045 tree parm
, arg
, arg_pack_elems
;
11046 dw_die_ref parm_die
;
11048 parm
= TREE_VEC_ELT (parms
, i
);
11049 arg
= TREE_VEC_ELT (args
, i
);
11050 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11051 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11053 if (parm
&& TREE_VALUE (parm
) && arg
)
11055 /* If PARM represents a template parameter pack,
11056 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11057 by DW_TAG_template_*_parameter DIEs for the argument
11058 pack elements of ARG. Note that ARG would then be
11059 an argument pack. */
11060 if (arg_pack_elems
)
11061 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11065 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11066 true /* emit name */, die
);
11067 if (i
>= non_default
)
11068 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11073 /* Create and return a DIE for PARM which should be
11074 the representation of a generic type parameter.
11075 For instance, in the C++ front end, PARM would be a template parameter.
11076 ARG is the argument to PARM.
11077 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11079 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11080 as a child node. */
11083 generic_parameter_die (tree parm
, tree arg
,
11085 dw_die_ref parent_die
)
11087 dw_die_ref tmpl_die
= NULL
;
11088 const char *name
= NULL
;
11090 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11093 /* We support non-type generic parameters and arguments,
11094 type generic parameters and arguments, as well as
11095 generic generic parameters (a.k.a. template template parameters in C++)
11097 if (TREE_CODE (parm
) == PARM_DECL
)
11098 /* PARM is a nontype generic parameter */
11099 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11100 else if (TREE_CODE (parm
) == TYPE_DECL
)
11101 /* PARM is a type generic parameter. */
11102 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11103 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11104 /* PARM is a generic generic parameter.
11105 Its DIE is a GNU extension. It shall have a
11106 DW_AT_name attribute to represent the name of the template template
11107 parameter, and a DW_AT_GNU_template_name attribute to represent the
11108 name of the template template argument. */
11109 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11112 gcc_unreachable ();
11118 /* If PARM is a generic parameter pack, it means we are
11119 emitting debug info for a template argument pack element.
11120 In other terms, ARG is a template argument pack element.
11121 In that case, we don't emit any DW_AT_name attribute for
11125 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11127 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11130 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11132 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11133 TMPL_DIE should have a child DW_AT_type attribute that is set
11134 to the type of the argument to PARM, which is ARG.
11135 If PARM is a type generic parameter, TMPL_DIE should have a
11136 child DW_AT_type that is set to ARG. */
11137 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11138 add_type_attribute (tmpl_die
, tmpl_type
,
11139 (TREE_THIS_VOLATILE (tmpl_type
)
11140 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11145 /* So TMPL_DIE is a DIE representing a
11146 a generic generic template parameter, a.k.a template template
11147 parameter in C++ and arg is a template. */
11149 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11150 to the name of the argument. */
11151 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11153 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11156 if (TREE_CODE (parm
) == PARM_DECL
)
11157 /* So PARM is a non-type generic parameter.
11158 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11159 attribute of TMPL_DIE which value represents the value
11161 We must be careful here:
11162 The value of ARG might reference some function decls.
11163 We might currently be emitting debug info for a generic
11164 type and types are emitted before function decls, we don't
11165 know if the function decls referenced by ARG will actually be
11166 emitted after cgraph computations.
11167 So must defer the generation of the DW_AT_const_value to
11168 after cgraph is ready. */
11169 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11175 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11176 PARM_PACK must be a template parameter pack. The returned DIE
11177 will be child DIE of PARENT_DIE. */
11180 template_parameter_pack_die (tree parm_pack
,
11181 tree parm_pack_args
,
11182 dw_die_ref parent_die
)
11187 gcc_assert (parent_die
&& parm_pack
);
11189 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11190 add_name_and_src_coords_attributes (die
, parm_pack
);
11191 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11192 generic_parameter_die (parm_pack
,
11193 TREE_VEC_ELT (parm_pack_args
, j
),
11194 false /* Don't emit DW_AT_name */,
11199 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11200 an enumerated type. */
11203 type_is_enum (const_tree type
)
11205 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11208 /* Return the DBX register number described by a given RTL node. */
11210 static unsigned int
11211 dbx_reg_number (const_rtx rtl
)
11213 unsigned regno
= REGNO (rtl
);
11215 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11217 #ifdef LEAF_REG_REMAP
11218 if (crtl
->uses_only_leaf_regs
)
11220 int leaf_reg
= LEAF_REG_REMAP (regno
);
11221 if (leaf_reg
!= -1)
11222 regno
= (unsigned) leaf_reg
;
11226 regno
= DBX_REGISTER_NUMBER (regno
);
11227 gcc_assert (regno
!= INVALID_REGNUM
);
11231 /* Optionally add a DW_OP_piece term to a location description expression.
11232 DW_OP_piece is only added if the location description expression already
11233 doesn't end with DW_OP_piece. */
11236 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11238 dw_loc_descr_ref loc
;
11240 if (*list_head
!= NULL
)
11242 /* Find the end of the chain. */
11243 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11246 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11247 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11251 /* Return a location descriptor that designates a machine register or
11252 zero if there is none. */
11254 static dw_loc_descr_ref
11255 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11259 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11262 /* We only use "frame base" when we're sure we're talking about the
11263 post-prologue local stack frame. We do this by *not* running
11264 register elimination until this point, and recognizing the special
11265 argument pointer and soft frame pointer rtx's.
11266 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11267 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11268 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11270 dw_loc_descr_ref result
= NULL
;
11272 if (dwarf_version
>= 4 || !dwarf_strict
)
11274 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11277 add_loc_descr (&result
,
11278 new_loc_descr (DW_OP_stack_value
, 0, 0));
11283 regs
= targetm
.dwarf_register_span (rtl
);
11285 if (REG_NREGS (rtl
) > 1 || regs
)
11286 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11289 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11290 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11292 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11296 /* Return a location descriptor that designates a machine register for
11297 a given hard register number. */
11299 static dw_loc_descr_ref
11300 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11302 dw_loc_descr_ref reg_loc_descr
;
11306 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11308 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11310 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11311 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11313 return reg_loc_descr
;
11316 /* Given an RTL of a register, return a location descriptor that
11317 designates a value that spans more than one register. */
11319 static dw_loc_descr_ref
11320 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11321 enum var_init_status initialized
)
11324 dw_loc_descr_ref loc_result
= NULL
;
11326 /* Simple, contiguous registers. */
11327 if (regs
== NULL_RTX
)
11329 unsigned reg
= REGNO (rtl
);
11332 #ifdef LEAF_REG_REMAP
11333 if (crtl
->uses_only_leaf_regs
)
11335 int leaf_reg
= LEAF_REG_REMAP (reg
);
11336 if (leaf_reg
!= -1)
11337 reg
= (unsigned) leaf_reg
;
11341 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11342 nregs
= REG_NREGS (rtl
);
11344 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11349 dw_loc_descr_ref t
;
11351 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11352 VAR_INIT_STATUS_INITIALIZED
);
11353 add_loc_descr (&loc_result
, t
);
11354 add_loc_descr_op_piece (&loc_result
, size
);
11360 /* Now onto stupid register sets in non contiguous locations. */
11362 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11364 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11367 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11369 dw_loc_descr_ref t
;
11371 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11372 VAR_INIT_STATUS_INITIALIZED
);
11373 add_loc_descr (&loc_result
, t
);
11374 add_loc_descr_op_piece (&loc_result
, size
);
11377 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11378 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11382 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11384 /* Return a location descriptor that designates a constant i,
11385 as a compound operation from constant (i >> shift), constant shift
11388 static dw_loc_descr_ref
11389 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11391 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11392 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11393 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11397 /* Return a location descriptor that designates a constant. */
11399 static dw_loc_descr_ref
11400 int_loc_descriptor (HOST_WIDE_INT i
)
11402 enum dwarf_location_atom op
;
11404 /* Pick the smallest representation of a constant, rather than just
11405 defaulting to the LEB encoding. */
11408 int clz
= clz_hwi (i
);
11409 int ctz
= ctz_hwi (i
);
11411 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11412 else if (i
<= 0xff)
11413 op
= DW_OP_const1u
;
11414 else if (i
<= 0xffff)
11415 op
= DW_OP_const2u
;
11416 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11417 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11418 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11419 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11420 while DW_OP_const4u is 5 bytes. */
11421 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11422 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11423 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11424 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11425 while DW_OP_const4u is 5 bytes. */
11426 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11427 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11428 op
= DW_OP_const4u
;
11429 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11430 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11431 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11432 while DW_OP_constu of constant >= 0x100000000 takes at least
11434 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11435 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11436 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11437 >= HOST_BITS_PER_WIDE_INT
)
11438 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11439 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11440 while DW_OP_constu takes in this case at least 6 bytes. */
11441 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11442 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11443 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11444 && size_of_uleb128 (i
) > 6)
11445 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11446 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11453 op
= DW_OP_const1s
;
11454 else if (i
>= -0x8000)
11455 op
= DW_OP_const2s
;
11456 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11458 if (size_of_int_loc_descriptor (i
) < 5)
11460 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11461 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11464 op
= DW_OP_const4s
;
11468 if (size_of_int_loc_descriptor (i
)
11469 < (unsigned long) 1 + size_of_sleb128 (i
))
11471 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11472 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11479 return new_loc_descr (op
, i
, 0);
11482 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11483 without actually allocating it. */
11485 static unsigned long
11486 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11488 return size_of_int_loc_descriptor (i
>> shift
)
11489 + size_of_int_loc_descriptor (shift
)
11493 /* Return size_of_locs (int_loc_descriptor (i)) without
11494 actually allocating it. */
11496 static unsigned long
11497 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11506 else if (i
<= 0xff)
11508 else if (i
<= 0xffff)
11512 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11513 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11514 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11516 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11517 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11518 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11520 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11522 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11523 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11524 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11525 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11527 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11528 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11529 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11531 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11532 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11534 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11543 else if (i
>= -0x8000)
11545 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11547 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11549 s
= size_of_int_loc_descriptor (-i
) + 1;
11557 unsigned long r
= 1 + size_of_sleb128 (i
);
11558 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11560 s
= size_of_int_loc_descriptor (-i
) + 1;
11569 /* Return loc description representing "address" of integer value.
11570 This can appear only as toplevel expression. */
11572 static dw_loc_descr_ref
11573 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11576 dw_loc_descr_ref loc_result
= NULL
;
11578 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11581 litsize
= size_of_int_loc_descriptor (i
);
11582 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11583 is more compact. For DW_OP_stack_value we need:
11584 litsize + 1 (DW_OP_stack_value)
11585 and for DW_OP_implicit_value:
11586 1 (DW_OP_implicit_value) + 1 (length) + size. */
11587 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11589 loc_result
= int_loc_descriptor (i
);
11590 add_loc_descr (&loc_result
,
11591 new_loc_descr (DW_OP_stack_value
, 0, 0));
11595 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11597 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11598 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11602 /* Return a location descriptor that designates a base+offset location. */
11604 static dw_loc_descr_ref
11605 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11606 enum var_init_status initialized
)
11608 unsigned int regno
;
11609 dw_loc_descr_ref result
;
11610 dw_fde_ref fde
= cfun
->fde
;
11612 /* We only use "frame base" when we're sure we're talking about the
11613 post-prologue local stack frame. We do this by *not* running
11614 register elimination until this point, and recognizing the special
11615 argument pointer and soft frame pointer rtx's. */
11616 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11618 rtx elim
= (ira_use_lra_p
11619 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11620 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11624 if (GET_CODE (elim
) == PLUS
)
11626 offset
+= INTVAL (XEXP (elim
, 1));
11627 elim
= XEXP (elim
, 0);
11629 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11630 && (elim
== hard_frame_pointer_rtx
11631 || elim
== stack_pointer_rtx
))
11632 || elim
== (frame_pointer_needed
11633 ? hard_frame_pointer_rtx
11634 : stack_pointer_rtx
));
11636 /* If drap register is used to align stack, use frame
11637 pointer + offset to access stack variables. If stack
11638 is aligned without drap, use stack pointer + offset to
11639 access stack variables. */
11640 if (crtl
->stack_realign_tried
11641 && reg
== frame_pointer_rtx
)
11644 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11645 ? HARD_FRAME_POINTER_REGNUM
11647 return new_reg_loc_descr (base_reg
, offset
);
11650 gcc_assert (frame_pointer_fb_offset_valid
);
11651 offset
+= frame_pointer_fb_offset
;
11652 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11656 regno
= REGNO (reg
);
11657 #ifdef LEAF_REG_REMAP
11658 if (crtl
->uses_only_leaf_regs
)
11660 int leaf_reg
= LEAF_REG_REMAP (regno
);
11661 if (leaf_reg
!= -1)
11662 regno
= (unsigned) leaf_reg
;
11665 regno
= DWARF_FRAME_REGNUM (regno
);
11667 if (!optimize
&& fde
11668 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11670 /* Use cfa+offset to represent the location of arguments passed
11671 on the stack when drap is used to align stack.
11672 Only do this when not optimizing, for optimized code var-tracking
11673 is supposed to track where the arguments live and the register
11674 used as vdrap or drap in some spot might be used for something
11675 else in other part of the routine. */
11676 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11680 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11683 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11685 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11686 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11691 /* Return true if this RTL expression describes a base+offset calculation. */
11694 is_based_loc (const_rtx rtl
)
11696 return (GET_CODE (rtl
) == PLUS
11697 && ((REG_P (XEXP (rtl
, 0))
11698 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11699 && CONST_INT_P (XEXP (rtl
, 1)))));
11702 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11705 static dw_loc_descr_ref
11706 tls_mem_loc_descriptor (rtx mem
)
11709 dw_loc_descr_ref loc_result
;
11711 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11714 base
= get_base_address (MEM_EXPR (mem
));
11716 || TREE_CODE (base
) != VAR_DECL
11717 || !DECL_THREAD_LOCAL_P (base
))
11720 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
11721 if (loc_result
== NULL
)
11724 if (MEM_OFFSET (mem
))
11725 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11730 /* Output debug info about reason why we failed to expand expression as dwarf
11734 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11736 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11738 fprintf (dump_file
, "Failed to expand as dwarf: ");
11740 print_generic_expr (dump_file
, expr
, dump_flags
);
11743 fprintf (dump_file
, "\n");
11744 print_rtl (dump_file
, rtl
);
11746 fprintf (dump_file
, "\nReason: %s\n", reason
);
11750 /* Helper function for const_ok_for_output. */
11753 const_ok_for_output_1 (rtx rtl
)
11755 if (GET_CODE (rtl
) == UNSPEC
)
11757 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11758 we can't express it in the debug info. */
11759 /* Don't complain about TLS UNSPECs, those are just too hard to
11760 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11761 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11762 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11764 && (XVECLEN (rtl
, 0) == 0
11765 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11766 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
11767 inform (current_function_decl
11768 ? DECL_SOURCE_LOCATION (current_function_decl
)
11769 : UNKNOWN_LOCATION
,
11770 #if NUM_UNSPEC_VALUES > 0
11771 "non-delegitimized UNSPEC %s (%d) found in variable location",
11772 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11773 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11776 "non-delegitimized UNSPEC %d found in variable location",
11779 expansion_failed (NULL_TREE
, rtl
,
11780 "UNSPEC hasn't been delegitimized.\n");
11784 if (targetm
.const_not_ok_for_debug_p (rtl
))
11786 expansion_failed (NULL_TREE
, rtl
,
11787 "Expression rejected for debug by the backend.\n");
11791 /* FIXME: Refer to PR60655. It is possible for simplification
11792 of rtl expressions in var tracking to produce such expressions.
11793 We should really identify / validate expressions
11794 enclosed in CONST that can be handled by assemblers on various
11795 targets and only handle legitimate cases here. */
11796 if (GET_CODE (rtl
) != SYMBOL_REF
)
11798 if (GET_CODE (rtl
) == NOT
)
11803 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11806 get_pool_constant_mark (rtl
, &marked
);
11807 /* If all references to this pool constant were optimized away,
11808 it was not output and thus we can't represent it. */
11811 expansion_failed (NULL_TREE
, rtl
,
11812 "Constant was removed from constant pool.\n");
11817 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11820 /* Avoid references to external symbols in debug info, on several targets
11821 the linker might even refuse to link when linking a shared library,
11822 and in many other cases the relocations for .debug_info/.debug_loc are
11823 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11824 to be defined within the same shared library or executable are fine. */
11825 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11827 tree decl
= SYMBOL_REF_DECL (rtl
);
11829 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11831 expansion_failed (NULL_TREE
, rtl
,
11832 "Symbol not defined in current TU.\n");
11840 /* Return true if constant RTL can be emitted in DW_OP_addr or
11841 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11842 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11845 const_ok_for_output (rtx rtl
)
11847 if (GET_CODE (rtl
) == SYMBOL_REF
)
11848 return const_ok_for_output_1 (rtl
);
11850 if (GET_CODE (rtl
) == CONST
)
11852 subrtx_var_iterator::array_type array
;
11853 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
11854 if (!const_ok_for_output_1 (*iter
))
11862 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11863 if possible, NULL otherwise. */
11866 base_type_for_mode (machine_mode mode
, bool unsignedp
)
11868 dw_die_ref type_die
;
11869 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11873 switch (TREE_CODE (type
))
11881 type_die
= lookup_type_die (type
);
11883 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, comp_unit_die ());
11884 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11889 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11890 type matching MODE, or, if MODE is narrower than or as wide as
11891 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11894 static dw_loc_descr_ref
11895 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
11897 machine_mode outer_mode
= mode
;
11898 dw_die_ref type_die
;
11899 dw_loc_descr_ref cvt
;
11901 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11903 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11906 type_die
= base_type_for_mode (outer_mode
, 1);
11907 if (type_die
== NULL
)
11909 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11910 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11911 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11912 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11913 add_loc_descr (&op
, cvt
);
11917 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11919 static dw_loc_descr_ref
11920 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11921 dw_loc_descr_ref op1
)
11923 dw_loc_descr_ref ret
= op0
;
11924 add_loc_descr (&ret
, op1
);
11925 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11926 if (STORE_FLAG_VALUE
!= 1)
11928 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11929 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11934 /* Return location descriptor for signed comparison OP RTL. */
11936 static dw_loc_descr_ref
11937 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11938 machine_mode mem_mode
)
11940 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11941 dw_loc_descr_ref op0
, op1
;
11944 if (op_mode
== VOIDmode
)
11945 op_mode
= GET_MODE (XEXP (rtl
, 1));
11946 if (op_mode
== VOIDmode
)
11950 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11951 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11954 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11955 VAR_INIT_STATUS_INITIALIZED
);
11956 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11957 VAR_INIT_STATUS_INITIALIZED
);
11959 if (op0
== NULL
|| op1
== NULL
)
11962 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11963 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11964 return compare_loc_descriptor (op
, op0
, op1
);
11966 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11968 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11969 dw_loc_descr_ref cvt
;
11971 if (type_die
== NULL
)
11973 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11974 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11975 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11976 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11977 add_loc_descr (&op0
, cvt
);
11978 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11979 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11980 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11981 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11982 add_loc_descr (&op1
, cvt
);
11983 return compare_loc_descriptor (op
, op0
, op1
);
11986 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11987 /* For eq/ne, if the operands are known to be zero-extended,
11988 there is no need to do the fancy shifting up. */
11989 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11991 dw_loc_descr_ref last0
, last1
;
11992 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11994 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11996 /* deref_size zero extends, and for constants we can check
11997 whether they are zero extended or not. */
11998 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11999 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12000 || (CONST_INT_P (XEXP (rtl
, 0))
12001 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
12002 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
12003 && ((last1
->dw_loc_opc
== DW_OP_deref_size
12004 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12005 || (CONST_INT_P (XEXP (rtl
, 1))
12006 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
12007 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
12008 return compare_loc_descriptor (op
, op0
, op1
);
12010 /* EQ/NE comparison against constant in narrower type than
12011 DWARF2_ADDR_SIZE can be performed either as
12012 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
12015 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
12016 DW_OP_{eq,ne}. Pick whatever is shorter. */
12017 if (CONST_INT_P (XEXP (rtl
, 1))
12018 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
12019 && (size_of_int_loc_descriptor (shift
) + 1
12020 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
12021 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
12022 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12023 & GET_MODE_MASK (op_mode
))))
12025 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
12026 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12027 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12028 & GET_MODE_MASK (op_mode
));
12029 return compare_loc_descriptor (op
, op0
, op1
);
12032 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12033 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12034 if (CONST_INT_P (XEXP (rtl
, 1)))
12035 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
12038 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12039 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12041 return compare_loc_descriptor (op
, op0
, op1
);
12044 /* Return location descriptor for unsigned comparison OP RTL. */
12046 static dw_loc_descr_ref
12047 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12048 machine_mode mem_mode
)
12050 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12051 dw_loc_descr_ref op0
, op1
;
12053 if (op_mode
== VOIDmode
)
12054 op_mode
= GET_MODE (XEXP (rtl
, 1));
12055 if (op_mode
== VOIDmode
)
12057 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
12060 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12063 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12064 VAR_INIT_STATUS_INITIALIZED
);
12065 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12066 VAR_INIT_STATUS_INITIALIZED
);
12068 if (op0
== NULL
|| op1
== NULL
)
12071 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12073 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12074 dw_loc_descr_ref last0
, last1
;
12075 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12077 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12079 if (CONST_INT_P (XEXP (rtl
, 0)))
12080 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12081 /* deref_size zero extends, so no need to mask it again. */
12082 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12083 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12085 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12086 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12088 if (CONST_INT_P (XEXP (rtl
, 1)))
12089 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12090 /* deref_size zero extends, so no need to mask it again. */
12091 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12092 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12094 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12095 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12098 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12100 HOST_WIDE_INT bias
= 1;
12101 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12102 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12103 if (CONST_INT_P (XEXP (rtl
, 1)))
12104 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12105 + INTVAL (XEXP (rtl
, 1)));
12107 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12110 return compare_loc_descriptor (op
, op0
, op1
);
12113 /* Return location descriptor for {U,S}{MIN,MAX}. */
12115 static dw_loc_descr_ref
12116 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12117 machine_mode mem_mode
)
12119 enum dwarf_location_atom op
;
12120 dw_loc_descr_ref op0
, op1
, ret
;
12121 dw_loc_descr_ref bra_node
, drop_node
;
12124 && (GET_MODE_CLASS (mode
) != MODE_INT
12125 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12128 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12129 VAR_INIT_STATUS_INITIALIZED
);
12130 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12131 VAR_INIT_STATUS_INITIALIZED
);
12133 if (op0
== NULL
|| op1
== NULL
)
12136 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12137 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12138 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12139 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12141 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12143 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12144 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12145 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12146 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12147 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12149 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12151 HOST_WIDE_INT bias
= 1;
12152 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12153 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12154 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12157 else if (GET_MODE_CLASS (mode
) == MODE_INT
12158 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12160 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12161 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12162 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12163 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12164 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12166 else if (GET_MODE_CLASS (mode
) == MODE_INT
12167 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12169 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12170 dw_loc_descr_ref cvt
;
12171 if (type_die
== NULL
)
12173 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12174 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12175 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12176 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12177 add_loc_descr (&op0
, cvt
);
12178 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12179 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12180 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12181 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12182 add_loc_descr (&op1
, cvt
);
12185 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12190 add_loc_descr (&ret
, op1
);
12191 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12192 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12193 add_loc_descr (&ret
, bra_node
);
12194 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12195 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12196 add_loc_descr (&ret
, drop_node
);
12197 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12198 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12199 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12200 && GET_MODE_CLASS (mode
) == MODE_INT
12201 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12202 ret
= convert_descriptor_to_mode (mode
, ret
);
12206 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12207 but after converting arguments to type_die, afterwards
12208 convert back to unsigned. */
12210 static dw_loc_descr_ref
12211 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12212 machine_mode mode
, machine_mode mem_mode
)
12214 dw_loc_descr_ref cvt
, op0
, op1
;
12216 if (type_die
== NULL
)
12218 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12219 VAR_INIT_STATUS_INITIALIZED
);
12220 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12221 VAR_INIT_STATUS_INITIALIZED
);
12222 if (op0
== NULL
|| op1
== NULL
)
12224 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12225 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12226 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12227 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12228 add_loc_descr (&op0
, cvt
);
12229 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12230 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12231 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12232 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12233 add_loc_descr (&op1
, cvt
);
12234 add_loc_descr (&op0
, op1
);
12235 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12236 return convert_descriptor_to_mode (mode
, op0
);
12239 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12240 const0 is DW_OP_lit0 or corresponding typed constant,
12241 const1 is DW_OP_lit1 or corresponding typed constant
12242 and constMSB is constant with just the MSB bit set
12244 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12245 L1: const0 DW_OP_swap
12246 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12247 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12252 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12253 L1: const0 DW_OP_swap
12254 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12255 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12260 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12261 L1: const1 DW_OP_swap
12262 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12263 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12267 static dw_loc_descr_ref
12268 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12269 machine_mode mem_mode
)
12271 dw_loc_descr_ref op0
, ret
, tmp
;
12272 HOST_WIDE_INT valv
;
12273 dw_loc_descr_ref l1jump
, l1label
;
12274 dw_loc_descr_ref l2jump
, l2label
;
12275 dw_loc_descr_ref l3jump
, l3label
;
12276 dw_loc_descr_ref l4jump
, l4label
;
12279 if (GET_MODE_CLASS (mode
) != MODE_INT
12280 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12283 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12284 VAR_INIT_STATUS_INITIALIZED
);
12288 if (GET_CODE (rtl
) == CLZ
)
12290 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12291 valv
= GET_MODE_BITSIZE (mode
);
12293 else if (GET_CODE (rtl
) == FFS
)
12295 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12296 valv
= GET_MODE_BITSIZE (mode
);
12297 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12298 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12299 add_loc_descr (&ret
, l1jump
);
12300 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12301 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12302 VAR_INIT_STATUS_INITIALIZED
);
12305 add_loc_descr (&ret
, tmp
);
12306 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12307 add_loc_descr (&ret
, l4jump
);
12308 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12309 ? const1_rtx
: const0_rtx
,
12311 VAR_INIT_STATUS_INITIALIZED
);
12312 if (l1label
== NULL
)
12314 add_loc_descr (&ret
, l1label
);
12315 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12316 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12317 add_loc_descr (&ret
, l2label
);
12318 if (GET_CODE (rtl
) != CLZ
)
12320 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12321 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12322 << (GET_MODE_BITSIZE (mode
) - 1));
12324 msb
= immed_wide_int_const
12325 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12326 GET_MODE_PRECISION (mode
)), mode
);
12327 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12328 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12329 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12330 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12332 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12333 VAR_INIT_STATUS_INITIALIZED
);
12336 add_loc_descr (&ret
, tmp
);
12337 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12338 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12339 add_loc_descr (&ret
, l3jump
);
12340 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12341 VAR_INIT_STATUS_INITIALIZED
);
12344 add_loc_descr (&ret
, tmp
);
12345 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12346 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12347 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12348 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12349 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12350 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12351 add_loc_descr (&ret
, l2jump
);
12352 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12353 add_loc_descr (&ret
, l3label
);
12354 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12355 add_loc_descr (&ret
, l4label
);
12356 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12357 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12358 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12359 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12360 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12361 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12362 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12363 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12367 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12368 const1 is DW_OP_lit1 or corresponding typed constant):
12370 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12371 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12375 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12376 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12379 static dw_loc_descr_ref
12380 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
12381 machine_mode mem_mode
)
12383 dw_loc_descr_ref op0
, ret
, tmp
;
12384 dw_loc_descr_ref l1jump
, l1label
;
12385 dw_loc_descr_ref l2jump
, l2label
;
12387 if (GET_MODE_CLASS (mode
) != MODE_INT
12388 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12391 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12392 VAR_INIT_STATUS_INITIALIZED
);
12396 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12397 VAR_INIT_STATUS_INITIALIZED
);
12400 add_loc_descr (&ret
, tmp
);
12401 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12402 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12403 add_loc_descr (&ret
, l1label
);
12404 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12405 add_loc_descr (&ret
, l2jump
);
12406 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12407 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12408 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12409 VAR_INIT_STATUS_INITIALIZED
);
12412 add_loc_descr (&ret
, tmp
);
12413 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12414 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12415 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12416 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12417 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12418 VAR_INIT_STATUS_INITIALIZED
);
12419 add_loc_descr (&ret
, tmp
);
12420 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12421 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12422 add_loc_descr (&ret
, l1jump
);
12423 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12424 add_loc_descr (&ret
, l2label
);
12425 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12426 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12427 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12428 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12432 /* BSWAP (constS is initial shift count, either 56 or 24):
12434 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12435 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12436 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12437 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12438 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12440 static dw_loc_descr_ref
12441 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
12442 machine_mode mem_mode
)
12444 dw_loc_descr_ref op0
, ret
, tmp
;
12445 dw_loc_descr_ref l1jump
, l1label
;
12446 dw_loc_descr_ref l2jump
, l2label
;
12448 if (GET_MODE_CLASS (mode
) != MODE_INT
12449 || BITS_PER_UNIT
!= 8
12450 || (GET_MODE_BITSIZE (mode
) != 32
12451 && GET_MODE_BITSIZE (mode
) != 64))
12454 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12455 VAR_INIT_STATUS_INITIALIZED
);
12460 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12462 VAR_INIT_STATUS_INITIALIZED
);
12465 add_loc_descr (&ret
, tmp
);
12466 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12467 VAR_INIT_STATUS_INITIALIZED
);
12470 add_loc_descr (&ret
, tmp
);
12471 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12472 add_loc_descr (&ret
, l1label
);
12473 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12475 VAR_INIT_STATUS_INITIALIZED
);
12476 add_loc_descr (&ret
, tmp
);
12477 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12478 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12479 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12480 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12481 VAR_INIT_STATUS_INITIALIZED
);
12484 add_loc_descr (&ret
, tmp
);
12485 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12486 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12487 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12488 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12489 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12490 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12491 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12492 VAR_INIT_STATUS_INITIALIZED
);
12493 add_loc_descr (&ret
, tmp
);
12494 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12495 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12496 add_loc_descr (&ret
, l2jump
);
12497 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12498 VAR_INIT_STATUS_INITIALIZED
);
12499 add_loc_descr (&ret
, tmp
);
12500 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12501 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12502 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12503 add_loc_descr (&ret
, l1jump
);
12504 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12505 add_loc_descr (&ret
, l2label
);
12506 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12507 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12508 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12509 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12510 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12511 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12515 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12516 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12517 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12518 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12520 ROTATERT is similar:
12521 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12522 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12523 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12525 static dw_loc_descr_ref
12526 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
12527 machine_mode mem_mode
)
12529 rtx rtlop1
= XEXP (rtl
, 1);
12530 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12533 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12536 if (GET_MODE (rtlop1
) != VOIDmode
12537 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12538 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12539 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12540 VAR_INIT_STATUS_INITIALIZED
);
12541 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12542 VAR_INIT_STATUS_INITIALIZED
);
12543 if (op0
== NULL
|| op1
== NULL
)
12545 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12546 for (i
= 0; i
< 2; i
++)
12548 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12549 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12551 VAR_INIT_STATUS_INITIALIZED
);
12552 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12553 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12555 : HOST_BITS_PER_WIDE_INT
== 64
12556 ? DW_OP_const8u
: DW_OP_constu
,
12557 GET_MODE_MASK (mode
), 0);
12560 if (mask
[i
] == NULL
)
12562 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12565 add_loc_descr (&ret
, op1
);
12566 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12567 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12568 if (GET_CODE (rtl
) == ROTATERT
)
12570 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12571 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12572 GET_MODE_BITSIZE (mode
), 0));
12574 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12575 if (mask
[0] != NULL
)
12576 add_loc_descr (&ret
, mask
[0]);
12577 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12578 if (mask
[1] != NULL
)
12580 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12581 add_loc_descr (&ret
, mask
[1]);
12582 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12584 if (GET_CODE (rtl
) == ROTATE
)
12586 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12587 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12588 GET_MODE_BITSIZE (mode
), 0));
12590 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12591 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12595 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12596 for DEBUG_PARAMETER_REF RTL. */
12598 static dw_loc_descr_ref
12599 parameter_ref_descriptor (rtx rtl
)
12601 dw_loc_descr_ref ret
;
12606 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12607 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12608 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12611 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12612 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12613 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12617 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12618 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12623 /* The following routine converts the RTL for a variable or parameter
12624 (resident in memory) into an equivalent Dwarf representation of a
12625 mechanism for getting the address of that same variable onto the top of a
12626 hypothetical "address evaluation" stack.
12628 When creating memory location descriptors, we are effectively transforming
12629 the RTL for a memory-resident object into its Dwarf postfix expression
12630 equivalent. This routine recursively descends an RTL tree, turning
12631 it into Dwarf postfix code as it goes.
12633 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12635 MEM_MODE is the mode of the memory reference, needed to handle some
12636 autoincrement addressing modes.
12638 Return 0 if we can't represent the location. */
12641 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
12642 machine_mode mem_mode
,
12643 enum var_init_status initialized
)
12645 dw_loc_descr_ref mem_loc_result
= NULL
;
12646 enum dwarf_location_atom op
;
12647 dw_loc_descr_ref op0
, op1
;
12648 rtx inner
= NULL_RTX
;
12650 if (mode
== VOIDmode
)
12651 mode
= GET_MODE (rtl
);
12653 /* Note that for a dynamically sized array, the location we will generate a
12654 description of here will be the lowest numbered location which is
12655 actually within the array. That's *not* necessarily the same as the
12656 zeroth element of the array. */
12658 rtl
= targetm
.delegitimize_address (rtl
);
12660 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12663 switch (GET_CODE (rtl
))
12668 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12671 /* The case of a subreg may arise when we have a local (register)
12672 variable or a formal (register) parameter which doesn't quite fill
12673 up an entire register. For now, just assume that it is
12674 legitimate to make the Dwarf info refer to the whole register which
12675 contains the given subreg. */
12676 if (!subreg_lowpart_p (rtl
))
12678 inner
= SUBREG_REG (rtl
);
12680 if (inner
== NULL_RTX
)
12681 inner
= XEXP (rtl
, 0);
12682 if (GET_MODE_CLASS (mode
) == MODE_INT
12683 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12684 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12685 #ifdef POINTERS_EXTEND_UNSIGNED
12686 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12689 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12691 mem_loc_result
= mem_loc_descriptor (inner
,
12693 mem_mode
, initialized
);
12698 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12700 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12701 && (GET_MODE_CLASS (mode
) != MODE_INT
12702 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12706 dw_die_ref type_die
;
12707 dw_loc_descr_ref cvt
;
12709 mem_loc_result
= mem_loc_descriptor (inner
,
12711 mem_mode
, initialized
);
12712 if (mem_loc_result
== NULL
)
12714 type_die
= base_type_for_mode (mode
,
12715 GET_MODE_CLASS (mode
) == MODE_INT
);
12716 if (type_die
== NULL
)
12718 mem_loc_result
= NULL
;
12721 if (GET_MODE_SIZE (mode
)
12722 != GET_MODE_SIZE (GET_MODE (inner
)))
12723 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12725 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12726 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12727 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12728 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12729 add_loc_descr (&mem_loc_result
, cvt
);
12734 if (GET_MODE_CLASS (mode
) != MODE_INT
12735 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12736 && rtl
!= arg_pointer_rtx
12737 && rtl
!= frame_pointer_rtx
12738 #ifdef POINTERS_EXTEND_UNSIGNED
12739 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12743 dw_die_ref type_die
;
12744 unsigned int dbx_regnum
;
12748 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12750 type_die
= base_type_for_mode (mode
,
12751 GET_MODE_CLASS (mode
) == MODE_INT
);
12752 if (type_die
== NULL
)
12755 dbx_regnum
= dbx_reg_number (rtl
);
12756 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12758 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12760 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12761 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12762 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12765 /* Whenever a register number forms a part of the description of the
12766 method for calculating the (dynamic) address of a memory resident
12767 object, DWARF rules require the register number be referred to as
12768 a "base register". This distinction is not based in any way upon
12769 what category of register the hardware believes the given register
12770 belongs to. This is strictly DWARF terminology we're dealing with
12771 here. Note that in cases where the location of a memory-resident
12772 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12773 OP_CONST (0)) the actual DWARF location descriptor that we generate
12774 may just be OP_BASEREG (basereg). This may look deceptively like
12775 the object in question was allocated to a register (rather than in
12776 memory) so DWARF consumers need to be aware of the subtle
12777 distinction between OP_REG and OP_BASEREG. */
12778 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12779 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12780 else if (stack_realign_drap
12782 && crtl
->args
.internal_arg_pointer
== rtl
12783 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12785 /* If RTL is internal_arg_pointer, which has been optimized
12786 out, use DRAP instead. */
12787 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12788 VAR_INIT_STATUS_INITIALIZED
);
12794 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12796 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12797 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12800 else if (GET_CODE (rtl
) == ZERO_EXTEND
12801 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12802 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12803 < HOST_BITS_PER_WIDE_INT
12804 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12805 to expand zero extend as two shifts instead of
12807 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12809 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12810 mem_loc_result
= op0
;
12811 add_loc_descr (&mem_loc_result
,
12812 int_loc_descriptor (GET_MODE_MASK (imode
)));
12813 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12815 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12817 int shift
= DWARF2_ADDR_SIZE
12818 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12819 shift
*= BITS_PER_UNIT
;
12820 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12824 mem_loc_result
= op0
;
12825 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12826 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12827 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12828 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12830 else if (!dwarf_strict
)
12832 dw_die_ref type_die1
, type_die2
;
12833 dw_loc_descr_ref cvt
;
12835 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12836 GET_CODE (rtl
) == ZERO_EXTEND
);
12837 if (type_die1
== NULL
)
12839 type_die2
= base_type_for_mode (mode
, 1);
12840 if (type_die2
== NULL
)
12842 mem_loc_result
= op0
;
12843 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12844 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12845 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12846 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12847 add_loc_descr (&mem_loc_result
, cvt
);
12848 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12849 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12850 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12851 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12852 add_loc_descr (&mem_loc_result
, cvt
);
12858 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12859 if (new_rtl
!= rtl
)
12861 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12863 if (mem_loc_result
!= NULL
)
12864 return mem_loc_result
;
12867 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12868 get_address_mode (rtl
), mode
,
12869 VAR_INIT_STATUS_INITIALIZED
);
12870 if (mem_loc_result
== NULL
)
12871 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12872 if (mem_loc_result
!= NULL
)
12874 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12875 || GET_MODE_CLASS (mode
) != MODE_INT
)
12877 dw_die_ref type_die
;
12878 dw_loc_descr_ref deref
;
12883 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12884 if (type_die
== NULL
)
12886 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12887 GET_MODE_SIZE (mode
), 0);
12888 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12889 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12890 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12891 add_loc_descr (&mem_loc_result
, deref
);
12893 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12894 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12896 add_loc_descr (&mem_loc_result
,
12897 new_loc_descr (DW_OP_deref_size
,
12898 GET_MODE_SIZE (mode
), 0));
12903 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12906 /* Some ports can transform a symbol ref into a label ref, because
12907 the symbol ref is too far away and has to be dumped into a constant
12911 if ((GET_MODE_CLASS (mode
) != MODE_INT
12912 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
12913 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12914 #ifdef POINTERS_EXTEND_UNSIGNED
12915 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12919 if (GET_CODE (rtl
) == SYMBOL_REF
12920 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12922 dw_loc_descr_ref temp
;
12924 /* If this is not defined, we have no way to emit the data. */
12925 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12928 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12930 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12931 add_loc_descr (&mem_loc_result
, temp
);
12936 if (!const_ok_for_output (rtl
))
12938 if (GET_CODE (rtl
) == CONST
)
12939 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12945 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12946 vec_safe_push (used_rtx_array
, rtl
);
12952 case DEBUG_IMPLICIT_PTR
:
12953 expansion_failed (NULL_TREE
, rtl
,
12954 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12960 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12962 if (GET_MODE_CLASS (mode
) != MODE_INT
12963 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12964 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12965 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12968 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12969 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12971 op0
= one_reg_loc_descriptor (dbx_regnum
,
12972 VAR_INIT_STATUS_INITIALIZED
);
12975 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12976 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12978 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12979 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12980 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12984 gcc_unreachable ();
12987 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12988 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12989 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12992 case DEBUG_PARAMETER_REF
:
12993 mem_loc_result
= parameter_ref_descriptor (rtl
);
12997 /* Extract the PLUS expression nested inside and fall into
12998 PLUS code below. */
12999 rtl
= XEXP (rtl
, 1);
13004 /* Turn these into a PLUS expression and fall into the PLUS code
13006 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
13007 gen_int_mode (GET_CODE (rtl
) == PRE_INC
13008 ? GET_MODE_UNIT_SIZE (mem_mode
)
13009 : -GET_MODE_UNIT_SIZE (mem_mode
),
13012 /* ... fall through ... */
13016 if (is_based_loc (rtl
)
13017 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13018 || XEXP (rtl
, 0) == arg_pointer_rtx
13019 || XEXP (rtl
, 0) == frame_pointer_rtx
)
13020 && GET_MODE_CLASS (mode
) == MODE_INT
)
13021 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13022 INTVAL (XEXP (rtl
, 1)),
13023 VAR_INIT_STATUS_INITIALIZED
);
13026 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13027 VAR_INIT_STATUS_INITIALIZED
);
13028 if (mem_loc_result
== 0)
13031 if (CONST_INT_P (XEXP (rtl
, 1))
13032 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13033 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13036 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13037 VAR_INIT_STATUS_INITIALIZED
);
13040 add_loc_descr (&mem_loc_result
, op1
);
13041 add_loc_descr (&mem_loc_result
,
13042 new_loc_descr (DW_OP_plus
, 0, 0));
13047 /* If a pseudo-reg is optimized away, it is possible for it to
13048 be replaced with a MEM containing a multiply or shift. */
13059 && GET_MODE_CLASS (mode
) == MODE_INT
13060 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13062 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13063 base_type_for_mode (mode
, 0),
13087 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13089 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13090 VAR_INIT_STATUS_INITIALIZED
);
13092 rtx rtlop1
= XEXP (rtl
, 1);
13093 if (GET_MODE (rtlop1
) != VOIDmode
13094 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13095 < GET_MODE_BITSIZE (mode
))
13096 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13097 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13098 VAR_INIT_STATUS_INITIALIZED
);
13101 if (op0
== 0 || op1
== 0)
13104 mem_loc_result
= op0
;
13105 add_loc_descr (&mem_loc_result
, op1
);
13106 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13122 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13123 VAR_INIT_STATUS_INITIALIZED
);
13124 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13125 VAR_INIT_STATUS_INITIALIZED
);
13127 if (op0
== 0 || op1
== 0)
13130 mem_loc_result
= op0
;
13131 add_loc_descr (&mem_loc_result
, op1
);
13132 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13136 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13138 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13139 base_type_for_mode (mode
, 0),
13144 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13145 VAR_INIT_STATUS_INITIALIZED
);
13146 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13147 VAR_INIT_STATUS_INITIALIZED
);
13149 if (op0
== 0 || op1
== 0)
13152 mem_loc_result
= op0
;
13153 add_loc_descr (&mem_loc_result
, op1
);
13154 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13155 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13156 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13157 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13158 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13162 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
13164 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13169 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13170 base_type_for_mode (mode
, 1),
13188 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13189 VAR_INIT_STATUS_INITIALIZED
);
13194 mem_loc_result
= op0
;
13195 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13199 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13200 #ifdef POINTERS_EXTEND_UNSIGNED
13202 && mem_mode
!= VOIDmode
13203 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13207 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13211 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13212 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13214 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13215 machine_mode amode
;
13216 if (type_die
== NULL
)
13218 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13220 if (INTVAL (rtl
) >= 0
13221 && amode
!= BLKmode
13222 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13223 /* const DW_OP_GNU_convert <XXX> vs.
13224 DW_OP_GNU_const_type <XXX, 1, const>. */
13225 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13226 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13228 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13229 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13230 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13231 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13232 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13233 add_loc_descr (&mem_loc_result
, op0
);
13234 return mem_loc_result
;
13236 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13238 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13239 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13240 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13241 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13242 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13245 mem_loc_result
->dw_loc_oprnd2
.val_class
13246 = dw_val_class_const_double
;
13247 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13248 = double_int::from_shwi (INTVAL (rtl
));
13256 dw_die_ref type_die
;
13258 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13259 CONST_DOUBLE rtx could represent either a large integer
13260 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13261 the value is always a floating point constant.
13263 When it is an integer, a CONST_DOUBLE is used whenever
13264 the constant requires 2 HWIs to be adequately represented.
13265 We output CONST_DOUBLEs as blocks. */
13266 if (mode
== VOIDmode
13267 || (GET_MODE (rtl
) == VOIDmode
13268 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13270 type_die
= base_type_for_mode (mode
,
13271 GET_MODE_CLASS (mode
) == MODE_INT
);
13272 if (type_die
== NULL
)
13274 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13275 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13276 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13277 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13278 #if TARGET_SUPPORTS_WIDE_INT == 0
13279 if (!SCALAR_FLOAT_MODE_P (mode
))
13281 mem_loc_result
->dw_loc_oprnd2
.val_class
13282 = dw_val_class_const_double
;
13283 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13284 = rtx_to_double_int (rtl
);
13289 unsigned int length
= GET_MODE_SIZE (mode
);
13290 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13292 insert_float (rtl
, array
);
13293 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13294 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13295 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13296 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13301 case CONST_WIDE_INT
:
13304 dw_die_ref type_die
;
13306 type_die
= base_type_for_mode (mode
,
13307 GET_MODE_CLASS (mode
) == MODE_INT
);
13308 if (type_die
== NULL
)
13310 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13311 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13312 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13313 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13314 mem_loc_result
->dw_loc_oprnd2
.val_class
13315 = dw_val_class_wide_int
;
13316 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13317 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13322 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13326 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13330 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13334 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13338 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13342 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
13346 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13350 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13354 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13358 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13363 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13368 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13373 if (CONST_INT_P (XEXP (rtl
, 1))
13374 && CONST_INT_P (XEXP (rtl
, 2))
13375 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13376 + (unsigned) INTVAL (XEXP (rtl
, 2))
13377 <= GET_MODE_BITSIZE (mode
))
13378 && GET_MODE_CLASS (mode
) == MODE_INT
13379 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13380 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13383 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13384 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13387 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13391 mem_loc_result
= op0
;
13392 size
= INTVAL (XEXP (rtl
, 1));
13393 shift
= INTVAL (XEXP (rtl
, 2));
13394 if (BITS_BIG_ENDIAN
)
13395 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13397 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13399 add_loc_descr (&mem_loc_result
,
13400 int_loc_descriptor (DWARF2_ADDR_SIZE
13402 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13404 if (size
!= (int) DWARF2_ADDR_SIZE
)
13406 add_loc_descr (&mem_loc_result
,
13407 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13408 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13415 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13416 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13417 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13418 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13419 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13420 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13421 VAR_INIT_STATUS_INITIALIZED
);
13422 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13423 VAR_INIT_STATUS_INITIALIZED
);
13424 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13427 mem_loc_result
= op1
;
13428 add_loc_descr (&mem_loc_result
, op2
);
13429 add_loc_descr (&mem_loc_result
, op0
);
13430 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13431 add_loc_descr (&mem_loc_result
, bra_node
);
13432 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13433 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13434 add_loc_descr (&mem_loc_result
, drop_node
);
13435 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13436 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13441 case FLOAT_TRUNCATE
:
13443 case UNSIGNED_FLOAT
:
13448 dw_die_ref type_die
;
13449 dw_loc_descr_ref cvt
;
13451 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13452 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13455 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13456 && (GET_CODE (rtl
) == FLOAT
13457 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13458 <= DWARF2_ADDR_SIZE
))
13460 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13461 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13462 if (type_die
== NULL
)
13464 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13465 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13466 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13467 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13468 add_loc_descr (&op0
, cvt
);
13470 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13471 if (type_die
== NULL
)
13473 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13474 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13475 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13476 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13477 add_loc_descr (&op0
, cvt
);
13478 if (GET_MODE_CLASS (mode
) == MODE_INT
13479 && (GET_CODE (rtl
) == FIX
13480 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13482 op0
= convert_descriptor_to_mode (mode
, op0
);
13486 mem_loc_result
= op0
;
13493 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13498 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13502 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13507 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13511 /* In theory, we could implement the above. */
13512 /* DWARF cannot represent the unsigned compare operations
13537 case FRACT_CONVERT
:
13538 case UNSIGNED_FRACT_CONVERT
:
13540 case UNSIGNED_SAT_FRACT
:
13546 case VEC_DUPLICATE
:
13550 case STRICT_LOW_PART
:
13555 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13556 can't express it in the debug info. This can happen e.g. with some
13561 resolve_one_addr (&rtl
);
13567 print_rtl (stderr
, rtl
);
13568 gcc_unreachable ();
13573 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13574 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13576 return mem_loc_result
;
13579 /* Return a descriptor that describes the concatenation of two locations.
13580 This is typically a complex variable. */
13582 static dw_loc_descr_ref
13583 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13585 dw_loc_descr_ref cc_loc_result
= NULL
;
13586 dw_loc_descr_ref x0_ref
13587 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13588 dw_loc_descr_ref x1_ref
13589 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13591 if (x0_ref
== 0 || x1_ref
== 0)
13594 cc_loc_result
= x0_ref
;
13595 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13597 add_loc_descr (&cc_loc_result
, x1_ref
);
13598 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13600 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13601 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13603 return cc_loc_result
;
13606 /* Return a descriptor that describes the concatenation of N
13609 static dw_loc_descr_ref
13610 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13613 dw_loc_descr_ref cc_loc_result
= NULL
;
13614 unsigned int n
= XVECLEN (concatn
, 0);
13616 for (i
= 0; i
< n
; ++i
)
13618 dw_loc_descr_ref ref
;
13619 rtx x
= XVECEXP (concatn
, 0, i
);
13621 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13625 add_loc_descr (&cc_loc_result
, ref
);
13626 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13629 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13630 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13632 return cc_loc_result
;
13635 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13636 for DEBUG_IMPLICIT_PTR RTL. */
13638 static dw_loc_descr_ref
13639 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13641 dw_loc_descr_ref ret
;
13646 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13647 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13648 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13649 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13650 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13651 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13654 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13655 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13656 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13660 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13661 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13666 /* Output a proper Dwarf location descriptor for a variable or parameter
13667 which is either allocated in a register or in a memory location. For a
13668 register, we just generate an OP_REG and the register number. For a
13669 memory location we provide a Dwarf postfix expression describing how to
13670 generate the (dynamic) address of the object onto the address stack.
13672 MODE is mode of the decl if this loc_descriptor is going to be used in
13673 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13674 allowed, VOIDmode otherwise.
13676 If we don't know how to describe it, return 0. */
13678 static dw_loc_descr_ref
13679 loc_descriptor (rtx rtl
, machine_mode mode
,
13680 enum var_init_status initialized
)
13682 dw_loc_descr_ref loc_result
= NULL
;
13684 switch (GET_CODE (rtl
))
13687 /* The case of a subreg may arise when we have a local (register)
13688 variable or a formal (register) parameter which doesn't quite fill
13689 up an entire register. For now, just assume that it is
13690 legitimate to make the Dwarf info refer to the whole register which
13691 contains the given subreg. */
13692 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13693 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13694 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13700 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13704 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13705 GET_MODE (rtl
), initialized
);
13706 if (loc_result
== NULL
)
13707 loc_result
= tls_mem_loc_descriptor (rtl
);
13708 if (loc_result
== NULL
)
13710 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13711 if (new_rtl
!= rtl
)
13712 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13717 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13722 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13727 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13729 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13730 if (GET_CODE (loc
) == EXPR_LIST
)
13731 loc
= XEXP (loc
, 0);
13732 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13736 rtl
= XEXP (rtl
, 1);
13741 rtvec par_elems
= XVEC (rtl
, 0);
13742 int num_elem
= GET_NUM_ELEM (par_elems
);
13746 /* Create the first one, so we have something to add to. */
13747 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13748 VOIDmode
, initialized
);
13749 if (loc_result
== NULL
)
13751 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13752 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13753 for (i
= 1; i
< num_elem
; i
++)
13755 dw_loc_descr_ref temp
;
13757 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13758 VOIDmode
, initialized
);
13761 add_loc_descr (&loc_result
, temp
);
13762 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13763 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13769 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13770 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13775 if (mode
== VOIDmode
)
13776 mode
= GET_MODE (rtl
);
13778 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13780 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13782 /* Note that a CONST_DOUBLE rtx could represent either an integer
13783 or a floating-point constant. A CONST_DOUBLE is used whenever
13784 the constant requires more than one word in order to be
13785 adequately represented. We output CONST_DOUBLEs as blocks. */
13786 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13787 GET_MODE_SIZE (mode
), 0);
13788 #if TARGET_SUPPORTS_WIDE_INT == 0
13789 if (!SCALAR_FLOAT_MODE_P (mode
))
13791 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13792 loc_result
->dw_loc_oprnd2
.v
.val_double
13793 = rtx_to_double_int (rtl
);
13798 unsigned int length
= GET_MODE_SIZE (mode
);
13799 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13801 insert_float (rtl
, array
);
13802 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13803 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13804 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13805 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13810 case CONST_WIDE_INT
:
13811 if (mode
== VOIDmode
)
13812 mode
= GET_MODE (rtl
);
13814 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13816 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13817 GET_MODE_SIZE (mode
), 0);
13818 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13819 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13820 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13825 if (mode
== VOIDmode
)
13826 mode
= GET_MODE (rtl
);
13828 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13830 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13831 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13832 unsigned char *array
13833 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
13836 machine_mode imode
= GET_MODE_INNER (mode
);
13838 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13839 switch (GET_MODE_CLASS (mode
))
13841 case MODE_VECTOR_INT
:
13842 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13844 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13845 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13849 case MODE_VECTOR_FLOAT
:
13850 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13852 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13853 insert_float (elt
, p
);
13858 gcc_unreachable ();
13861 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13862 length
* elt_size
, 0);
13863 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13864 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13865 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13866 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13871 if (mode
== VOIDmode
13872 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13873 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13874 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13876 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13881 if (!const_ok_for_output (rtl
))
13884 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13885 && (dwarf_version
>= 4 || !dwarf_strict
))
13887 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13888 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13889 vec_safe_push (used_rtx_array
, rtl
);
13893 case DEBUG_IMPLICIT_PTR
:
13894 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13898 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13899 && CONST_INT_P (XEXP (rtl
, 1)))
13902 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13908 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13909 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13910 && dwarf_version
>= 4)
13911 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13913 /* Value expression. */
13914 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13916 add_loc_descr (&loc_result
,
13917 new_loc_descr (DW_OP_stack_value
, 0, 0));
13925 /* We need to figure out what section we should use as the base for the
13926 address ranges where a given location is valid.
13927 1. If this particular DECL has a section associated with it, use that.
13928 2. If this function has a section associated with it, use that.
13929 3. Otherwise, use the text section.
13930 XXX: If you split a variable across multiple sections, we won't notice. */
13932 static const char *
13933 secname_for_decl (const_tree decl
)
13935 const char *secname
;
13937 if (VAR_OR_FUNCTION_DECL_P (decl
)
13938 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
13939 && DECL_SECTION_NAME (decl
))
13940 secname
= DECL_SECTION_NAME (decl
);
13941 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13942 secname
= DECL_SECTION_NAME (current_function_decl
);
13943 else if (cfun
&& in_cold_section_p
)
13944 secname
= crtl
->subsections
.cold_section_label
;
13946 secname
= text_section_label
;
13951 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13954 decl_by_reference_p (tree decl
)
13956 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13957 || TREE_CODE (decl
) == VAR_DECL
)
13958 && DECL_BY_REFERENCE (decl
));
13961 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13964 static dw_loc_descr_ref
13965 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13966 enum var_init_status initialized
)
13968 int have_address
= 0;
13969 dw_loc_descr_ref descr
;
13972 if (want_address
!= 2)
13974 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13976 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13978 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13979 if (GET_CODE (varloc
) == EXPR_LIST
)
13980 varloc
= XEXP (varloc
, 0);
13981 mode
= GET_MODE (varloc
);
13982 if (MEM_P (varloc
))
13984 rtx addr
= XEXP (varloc
, 0);
13985 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13986 mode
, initialized
);
13991 rtx x
= avoid_constant_pool_reference (varloc
);
13993 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13998 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
14005 if (GET_CODE (varloc
) == VAR_LOCATION
)
14006 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14008 mode
= DECL_MODE (loc
);
14009 descr
= loc_descriptor (varloc
, mode
, initialized
);
14016 if (want_address
== 2 && !have_address
14017 && (dwarf_version
>= 4 || !dwarf_strict
))
14019 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14021 expansion_failed (loc
, NULL_RTX
,
14022 "DWARF address size mismatch");
14025 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14028 /* Show if we can't fill the request for an address. */
14029 if (want_address
&& !have_address
)
14031 expansion_failed (loc
, NULL_RTX
,
14032 "Want address and only have value");
14036 /* If we've got an address and don't want one, dereference. */
14037 if (!want_address
&& have_address
)
14039 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14040 enum dwarf_location_atom op
;
14042 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14044 expansion_failed (loc
, NULL_RTX
,
14045 "DWARF address size mismatch");
14048 else if (size
== DWARF2_ADDR_SIZE
)
14051 op
= DW_OP_deref_size
;
14053 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14059 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14060 if it is not possible. */
14062 static dw_loc_descr_ref
14063 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14065 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14066 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14067 else if (dwarf_version
>= 3 || !dwarf_strict
)
14068 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14073 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14074 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14076 static dw_loc_descr_ref
14077 dw_sra_loc_expr (tree decl
, rtx loc
)
14080 unsigned HOST_WIDE_INT padsize
= 0;
14081 dw_loc_descr_ref descr
, *descr_tail
;
14082 unsigned HOST_WIDE_INT decl_size
;
14084 enum var_init_status initialized
;
14086 if (DECL_SIZE (decl
) == NULL
14087 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14090 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14092 descr_tail
= &descr
;
14094 for (p
= loc
; p
; p
= XEXP (p
, 1))
14096 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14097 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14098 dw_loc_descr_ref cur_descr
;
14099 dw_loc_descr_ref
*tail
, last
= NULL
;
14100 unsigned HOST_WIDE_INT opsize
= 0;
14102 if (loc_note
== NULL_RTX
14103 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14105 padsize
+= bitsize
;
14108 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14109 varloc
= NOTE_VAR_LOCATION (loc_note
);
14110 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14111 if (cur_descr
== NULL
)
14113 padsize
+= bitsize
;
14117 /* Check that cur_descr either doesn't use
14118 DW_OP_*piece operations, or their sum is equal
14119 to bitsize. Otherwise we can't embed it. */
14120 for (tail
= &cur_descr
; *tail
!= NULL
;
14121 tail
= &(*tail
)->dw_loc_next
)
14122 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14124 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14128 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14130 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14134 if (last
!= NULL
&& opsize
!= bitsize
)
14136 padsize
+= bitsize
;
14137 /* Discard the current piece of the descriptor and release any
14138 addr_table entries it uses. */
14139 remove_loc_list_addr_table_entries (cur_descr
);
14143 /* If there is a hole, add DW_OP_*piece after empty DWARF
14144 expression, which means that those bits are optimized out. */
14147 if (padsize
> decl_size
)
14149 remove_loc_list_addr_table_entries (cur_descr
);
14150 goto discard_descr
;
14152 decl_size
-= padsize
;
14153 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14154 if (*descr_tail
== NULL
)
14156 remove_loc_list_addr_table_entries (cur_descr
);
14157 goto discard_descr
;
14159 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14162 *descr_tail
= cur_descr
;
14164 if (bitsize
> decl_size
)
14165 goto discard_descr
;
14166 decl_size
-= bitsize
;
14169 HOST_WIDE_INT offset
= 0;
14170 if (GET_CODE (varloc
) == VAR_LOCATION
14171 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14173 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14174 if (GET_CODE (varloc
) == EXPR_LIST
)
14175 varloc
= XEXP (varloc
, 0);
14179 if (GET_CODE (varloc
) == CONST
14180 || GET_CODE (varloc
) == SIGN_EXTEND
14181 || GET_CODE (varloc
) == ZERO_EXTEND
)
14182 varloc
= XEXP (varloc
, 0);
14183 else if (GET_CODE (varloc
) == SUBREG
)
14184 varloc
= SUBREG_REG (varloc
);
14189 /* DW_OP_bit_size offset should be zero for register
14190 or implicit location descriptions and empty location
14191 descriptions, but for memory addresses needs big endian
14193 if (MEM_P (varloc
))
14195 unsigned HOST_WIDE_INT memsize
14196 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14197 if (memsize
!= bitsize
)
14199 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14200 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14201 goto discard_descr
;
14202 if (memsize
< bitsize
)
14203 goto discard_descr
;
14204 if (BITS_BIG_ENDIAN
)
14205 offset
= memsize
- bitsize
;
14209 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14210 if (*descr_tail
== NULL
)
14211 goto discard_descr
;
14212 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14216 /* If there were any non-empty expressions, add padding till the end of
14218 if (descr
!= NULL
&& decl_size
!= 0)
14220 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14221 if (*descr_tail
== NULL
)
14222 goto discard_descr
;
14227 /* Discard the descriptor and release any addr_table entries it uses. */
14228 remove_loc_list_addr_table_entries (descr
);
14232 /* Return the dwarf representation of the location list LOC_LIST of
14233 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14236 static dw_loc_list_ref
14237 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14239 const char *endname
, *secname
;
14241 enum var_init_status initialized
;
14242 struct var_loc_node
*node
;
14243 dw_loc_descr_ref descr
;
14244 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14245 dw_loc_list_ref list
= NULL
;
14246 dw_loc_list_ref
*listp
= &list
;
14248 /* Now that we know what section we are using for a base,
14249 actually construct the list of locations.
14250 The first location information is what is passed to the
14251 function that creates the location list, and the remaining
14252 locations just get added on to that list.
14253 Note that we only know the start address for a location
14254 (IE location changes), so to build the range, we use
14255 the range [current location start, next location start].
14256 This means we have to special case the last node, and generate
14257 a range of [last location start, end of function label]. */
14259 secname
= secname_for_decl (decl
);
14261 for (node
= loc_list
->first
; node
; node
= node
->next
)
14262 if (GET_CODE (node
->loc
) == EXPR_LIST
14263 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14265 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14267 /* This requires DW_OP_{,bit_}piece, which is not usable
14268 inside DWARF expressions. */
14269 if (want_address
!= 2)
14271 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14277 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14278 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14279 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14283 bool range_across_switch
= false;
14284 /* If section switch happens in between node->label
14285 and node->next->label (or end of function) and
14286 we can't emit it as a single entry list,
14287 emit two ranges, first one ending at the end
14288 of first partition and second one starting at the
14289 beginning of second partition. */
14290 if (node
== loc_list
->last_before_switch
14291 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14292 && current_function_decl
)
14294 endname
= cfun
->fde
->dw_fde_end
;
14295 range_across_switch
= true;
14297 /* The variable has a location between NODE->LABEL and
14298 NODE->NEXT->LABEL. */
14299 else if (node
->next
)
14300 endname
= node
->next
->label
;
14301 /* If the variable has a location at the last label
14302 it keeps its location until the end of function. */
14303 else if (!current_function_decl
)
14304 endname
= text_end_label
;
14307 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14308 current_function_funcdef_no
);
14309 endname
= ggc_strdup (label_id
);
14312 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14313 if (TREE_CODE (decl
) == PARM_DECL
14314 && node
== loc_list
->first
14315 && NOTE_P (node
->loc
)
14316 && strcmp (node
->label
, endname
) == 0)
14317 (*listp
)->force
= true;
14318 listp
= &(*listp
)->dw_loc_next
;
14320 if (range_across_switch
)
14322 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14323 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14326 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14327 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14328 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
14331 gcc_assert (descr
);
14332 /* The variable has a location between NODE->LABEL and
14333 NODE->NEXT->LABEL. */
14335 endname
= node
->next
->label
;
14337 endname
= cfun
->fde
->dw_fde_second_end
;
14338 *listp
= new_loc_list (descr
,
14339 cfun
->fde
->dw_fde_second_begin
,
14341 listp
= &(*listp
)->dw_loc_next
;
14346 /* Try to avoid the overhead of a location list emitting a location
14347 expression instead, but only if we didn't have more than one
14348 location entry in the first place. If some entries were not
14349 representable, we don't want to pretend a single entry that was
14350 applies to the entire scope in which the variable is
14352 if (list
&& loc_list
->first
->next
)
14358 /* Return if the loc_list has only single element and thus can be represented
14359 as location description. */
14362 single_element_loc_list_p (dw_loc_list_ref list
)
14364 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14365 return !list
->ll_symbol
;
14368 /* To each location in list LIST add loc descr REF. */
14371 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14373 dw_loc_descr_ref copy
;
14374 add_loc_descr (&list
->expr
, ref
);
14375 list
= list
->dw_loc_next
;
14378 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14379 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14380 add_loc_descr (&list
->expr
, copy
);
14381 while (copy
->dw_loc_next
)
14383 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14384 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14385 copy
->dw_loc_next
= new_copy
;
14388 list
= list
->dw_loc_next
;
14392 /* Given two lists RET and LIST
14393 produce location list that is result of adding expression in LIST
14394 to expression in RET on each position in program.
14395 Might be destructive on both RET and LIST.
14397 TODO: We handle only simple cases of RET or LIST having at most one
14398 element. General case would inolve sorting the lists in program order
14399 and merging them that will need some additional work.
14400 Adding that will improve quality of debug info especially for SRA-ed
14404 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14413 if (!list
->dw_loc_next
)
14415 add_loc_descr_to_each (*ret
, list
->expr
);
14418 if (!(*ret
)->dw_loc_next
)
14420 add_loc_descr_to_each (list
, (*ret
)->expr
);
14424 expansion_failed (NULL_TREE
, NULL_RTX
,
14425 "Don't know how to merge two non-trivial"
14426 " location lists.\n");
14431 /* LOC is constant expression. Try a luck, look it up in constant
14432 pool and return its loc_descr of its address. */
14434 static dw_loc_descr_ref
14435 cst_pool_loc_descr (tree loc
)
14437 /* Get an RTL for this, if something has been emitted. */
14438 rtx rtl
= lookup_constant_def (loc
);
14440 if (!rtl
|| !MEM_P (rtl
))
14445 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14447 /* TODO: We might get more coverage if we was actually delaying expansion
14448 of all expressions till end of compilation when constant pools are fully
14450 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14452 expansion_failed (loc
, NULL_RTX
,
14453 "CST value in contant pool but not marked.");
14456 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14457 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14460 /* Return dw_loc_list representing address of addr_expr LOC
14461 by looking for inner INDIRECT_REF expression and turning
14462 it into simple arithmetics.
14464 See loc_list_from_tree for the meaning of CONTEXT. */
14466 static dw_loc_list_ref
14467 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
14468 const loc_descr_context
*context
)
14471 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14473 int unsignedp
, volatilep
= 0;
14474 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14476 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14477 &bitsize
, &bitpos
, &offset
, &mode
,
14478 &unsignedp
, &volatilep
, false);
14480 if (bitpos
% BITS_PER_UNIT
)
14482 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14485 if (!INDIRECT_REF_P (obj
))
14487 expansion_failed (obj
,
14488 NULL_RTX
, "no indirect ref in inner refrence");
14491 if (!offset
&& !bitpos
)
14492 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
14495 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14496 && (dwarf_version
>= 4 || !dwarf_strict
))
14498 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
14503 /* Variable offset. */
14504 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14505 if (list_ret1
== 0)
14507 add_loc_list (&list_ret
, list_ret1
);
14510 add_loc_descr_to_each (list_ret
,
14511 new_loc_descr (DW_OP_plus
, 0, 0));
14513 bytepos
= bitpos
/ BITS_PER_UNIT
;
14515 add_loc_descr_to_each (list_ret
,
14516 new_loc_descr (DW_OP_plus_uconst
,
14518 else if (bytepos
< 0)
14519 loc_list_plus_const (list_ret
, bytepos
);
14520 add_loc_descr_to_each (list_ret
,
14521 new_loc_descr (DW_OP_stack_value
, 0, 0));
14527 /* Helper structure for location descriptions generation. */
14528 struct loc_descr_context
14530 /* The type that is implicitly referenced by DW_OP_push_object_address, or
14531 NULL_TREE if DW_OP_push_object_address in invalid for this location
14532 description. This is used when processing PLACEHOLDER_EXPR nodes. */
14534 /* The ..._DECL node that should be translated as a
14535 DW_OP_push_object_address operation. */
14539 /* Generate Dwarf location list representing LOC.
14540 If WANT_ADDRESS is false, expression computing LOC will be computed
14541 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14542 if WANT_ADDRESS is 2, expression computing address useable in location
14543 will be returned (i.e. DW_OP_reg can be used
14544 to refer to register values).
14546 CONTEXT provides information to customize the location descriptions
14547 generation. Its context_type field specifies what type is implicitly
14548 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
14549 will not be generated.
14551 If CONTEXT is NULL, the behavior is the same as if both context_type and
14552 base_decl fields were NULL_TREE. */
14554 static dw_loc_list_ref
14555 loc_list_from_tree (tree loc
, int want_address
,
14556 const struct loc_descr_context
*context
)
14558 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14559 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14560 int have_address
= 0;
14561 enum dwarf_location_atom op
;
14563 /* ??? Most of the time we do not take proper care for sign/zero
14564 extending the values properly. Hopefully this won't be a real
14567 if (context
!= NULL
14568 && context
->base_decl
== loc
14569 && want_address
== 0)
14571 if (dwarf_version
>= 3 || !dwarf_strict
)
14572 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
14578 switch (TREE_CODE (loc
))
14581 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14584 case PLACEHOLDER_EXPR
:
14585 /* This case involves extracting fields from an object to determine the
14586 position of other fields. It is supposed to appear only as the first
14587 operand of COMPONENT_REF nodes and to reference precisely the type
14588 that the context allows. */
14589 if (context
!= NULL
14590 && TREE_TYPE (loc
) == context
->context_type
14591 && want_address
>= 1)
14593 if (dwarf_version
>= 3 || !dwarf_strict
)
14595 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
14603 expansion_failed (loc
, NULL_RTX
,
14604 "PLACEHOLDER_EXPR for an unexpected type");
14608 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14609 /* There are no opcodes for these operations. */
14612 case PREINCREMENT_EXPR
:
14613 case PREDECREMENT_EXPR
:
14614 case POSTINCREMENT_EXPR
:
14615 case POSTDECREMENT_EXPR
:
14616 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14617 /* There are no opcodes for these operations. */
14621 /* If we already want an address, see if there is INDIRECT_REF inside
14622 e.g. for &this->field. */
14625 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14626 (loc
, want_address
== 2, context
);
14629 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14630 && (ret
= cst_pool_loc_descr (loc
)))
14633 /* Otherwise, process the argument and look for the address. */
14634 if (!list_ret
&& !ret
)
14635 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1, context
);
14639 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14645 if (DECL_THREAD_LOCAL_P (loc
))
14648 enum dwarf_location_atom tls_op
;
14649 enum dtprel_bool dtprel
= dtprel_false
;
14651 if (targetm
.have_tls
)
14653 /* If this is not defined, we have no way to emit the
14655 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14658 /* The way DW_OP_GNU_push_tls_address is specified, we
14659 can only look up addresses of objects in the current
14660 module. We used DW_OP_addr as first op, but that's
14661 wrong, because DW_OP_addr is relocated by the debug
14662 info consumer, while DW_OP_GNU_push_tls_address
14663 operand shouldn't be. */
14664 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14666 dtprel
= dtprel_true
;
14667 tls_op
= DW_OP_GNU_push_tls_address
;
14671 if (!targetm
.emutls
.debug_form_tls_address
14672 || !(dwarf_version
>= 3 || !dwarf_strict
))
14674 /* We stuffed the control variable into the DECL_VALUE_EXPR
14675 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14676 no longer appear in gimple code. We used the control
14677 variable in specific so that we could pick it up here. */
14678 loc
= DECL_VALUE_EXPR (loc
);
14679 tls_op
= DW_OP_form_tls_address
;
14682 rtl
= rtl_for_decl_location (loc
);
14683 if (rtl
== NULL_RTX
)
14688 rtl
= XEXP (rtl
, 0);
14689 if (! CONSTANT_P (rtl
))
14692 ret
= new_addr_loc_descr (rtl
, dtprel
);
14693 ret1
= new_loc_descr (tls_op
, 0, 0);
14694 add_loc_descr (&ret
, ret1
);
14703 if (DECL_HAS_VALUE_EXPR_P (loc
))
14704 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14705 want_address
, context
);
14708 case FUNCTION_DECL
:
14711 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14713 if (loc_list
&& loc_list
->first
)
14715 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14716 have_address
= want_address
!= 0;
14719 rtl
= rtl_for_decl_location (loc
);
14720 if (rtl
== NULL_RTX
)
14722 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14725 else if (CONST_INT_P (rtl
))
14727 HOST_WIDE_INT val
= INTVAL (rtl
);
14728 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14729 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14730 ret
= int_loc_descriptor (val
);
14732 else if (GET_CODE (rtl
) == CONST_STRING
)
14734 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14737 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14738 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14741 machine_mode mode
, mem_mode
;
14743 /* Certain constructs can only be represented at top-level. */
14744 if (want_address
== 2)
14746 ret
= loc_descriptor (rtl
, VOIDmode
,
14747 VAR_INIT_STATUS_INITIALIZED
);
14752 mode
= GET_MODE (rtl
);
14753 mem_mode
= VOIDmode
;
14757 mode
= get_address_mode (rtl
);
14758 rtl
= XEXP (rtl
, 0);
14761 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14762 VAR_INIT_STATUS_INITIALIZED
);
14765 expansion_failed (loc
, rtl
,
14766 "failed to produce loc descriptor for rtl");
14772 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14779 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14783 case TARGET_MEM_REF
:
14785 case DEBUG_EXPR_DECL
:
14788 case COMPOUND_EXPR
:
14789 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
, context
);
14792 case VIEW_CONVERT_EXPR
:
14795 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
, context
);
14797 case COMPONENT_REF
:
14798 case BIT_FIELD_REF
:
14800 case ARRAY_RANGE_REF
:
14801 case REALPART_EXPR
:
14802 case IMAGPART_EXPR
:
14805 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14807 int unsignedp
, volatilep
= 0;
14809 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14810 &unsignedp
, &volatilep
, false);
14812 gcc_assert (obj
!= loc
);
14814 list_ret
= loc_list_from_tree (obj
,
14816 && !bitpos
&& !offset
? 2 : 1,
14818 /* TODO: We can extract value of the small expression via shifting even
14819 for nonzero bitpos. */
14822 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14824 expansion_failed (loc
, NULL_RTX
,
14825 "bitfield access");
14829 if (offset
!= NULL_TREE
)
14831 /* Variable offset. */
14832 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14833 if (list_ret1
== 0)
14835 add_loc_list (&list_ret
, list_ret1
);
14838 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14841 bytepos
= bitpos
/ BITS_PER_UNIT
;
14843 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14844 else if (bytepos
< 0)
14845 loc_list_plus_const (list_ret
, bytepos
);
14852 if ((want_address
|| !tree_fits_shwi_p (loc
))
14853 && (ret
= cst_pool_loc_descr (loc
)))
14855 else if (want_address
== 2
14856 && tree_fits_shwi_p (loc
)
14857 && (ret
= address_of_int_loc_descriptor
14858 (int_size_in_bytes (TREE_TYPE (loc
)),
14859 tree_to_shwi (loc
))))
14861 else if (tree_fits_shwi_p (loc
))
14862 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14865 expansion_failed (loc
, NULL_RTX
,
14866 "Integer operand is not host integer");
14875 if ((ret
= cst_pool_loc_descr (loc
)))
14878 /* We can construct small constants here using int_loc_descriptor. */
14879 expansion_failed (loc
, NULL_RTX
,
14880 "constructor or constant not in constant pool");
14883 case TRUTH_AND_EXPR
:
14884 case TRUTH_ANDIF_EXPR
:
14889 case TRUTH_XOR_EXPR
:
14894 case TRUTH_OR_EXPR
:
14895 case TRUTH_ORIF_EXPR
:
14900 case FLOOR_DIV_EXPR
:
14901 case CEIL_DIV_EXPR
:
14902 case ROUND_DIV_EXPR
:
14903 case TRUNC_DIV_EXPR
:
14904 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14913 case FLOOR_MOD_EXPR
:
14914 case CEIL_MOD_EXPR
:
14915 case ROUND_MOD_EXPR
:
14916 case TRUNC_MOD_EXPR
:
14917 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14922 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14923 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14924 if (list_ret
== 0 || list_ret1
== 0)
14927 add_loc_list (&list_ret
, list_ret1
);
14930 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14931 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14932 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14933 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14934 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14946 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14949 case POINTER_PLUS_EXPR
:
14952 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14954 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14958 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14966 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14973 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14980 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14987 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
15002 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
15003 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
15004 if (list_ret
== 0 || list_ret1
== 0)
15007 add_loc_list (&list_ret
, list_ret1
);
15010 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15013 case TRUTH_NOT_EXPR
:
15027 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
15031 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
15037 const enum tree_code code
=
15038 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
15040 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
15041 build2 (code
, integer_type_node
,
15042 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
15043 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
15046 /* ... fall through ... */
15050 dw_loc_descr_ref lhs
15051 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
15052 dw_loc_list_ref rhs
15053 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0, context
);
15054 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15056 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
15057 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15060 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15061 add_loc_descr_to_each (list_ret
, bra_node
);
15063 add_loc_list (&list_ret
, rhs
);
15064 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15065 add_loc_descr_to_each (list_ret
, jump_node
);
15067 add_loc_descr_to_each (list_ret
, lhs
);
15068 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15069 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15071 /* ??? Need a node to point the skip at. Use a nop. */
15072 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15073 add_loc_descr_to_each (list_ret
, tmp
);
15074 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15075 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15079 case FIX_TRUNC_EXPR
:
15083 /* Leave front-end specific codes as simply unknown. This comes
15084 up, for instance, with the C STMT_EXPR. */
15085 if ((unsigned int) TREE_CODE (loc
)
15086 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15088 expansion_failed (loc
, NULL_RTX
,
15089 "language specific tree node");
15093 /* Otherwise this is a generic code; we should just lists all of
15094 these explicitly. We forgot one. */
15096 gcc_unreachable ();
15098 /* In a release build, we want to degrade gracefully: better to
15099 generate incomplete debugging information than to crash. */
15103 if (!ret
&& !list_ret
)
15106 if (want_address
== 2 && !have_address
15107 && (dwarf_version
>= 4 || !dwarf_strict
))
15109 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15111 expansion_failed (loc
, NULL_RTX
,
15112 "DWARF address size mismatch");
15116 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15118 add_loc_descr_to_each (list_ret
,
15119 new_loc_descr (DW_OP_stack_value
, 0, 0));
15122 /* Show if we can't fill the request for an address. */
15123 if (want_address
&& !have_address
)
15125 expansion_failed (loc
, NULL_RTX
,
15126 "Want address and only have value");
15130 gcc_assert (!ret
|| !list_ret
);
15132 /* If we've got an address and don't want one, dereference. */
15133 if (!want_address
&& have_address
)
15135 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15137 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15139 expansion_failed (loc
, NULL_RTX
,
15140 "DWARF address size mismatch");
15143 else if (size
== DWARF2_ADDR_SIZE
)
15146 op
= DW_OP_deref_size
;
15149 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15151 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15154 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15159 /* Same as above but return only single location expression. */
15160 static dw_loc_descr_ref
15161 loc_descriptor_from_tree (tree loc
, int want_address
,
15162 const struct loc_descr_context
*context
)
15164 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
15167 if (ret
->dw_loc_next
)
15169 expansion_failed (loc
, NULL_RTX
,
15170 "Location list where only loc descriptor needed");
15176 /* Given a value, round it up to the lowest multiple of `boundary'
15177 which is not less than the value itself. */
15179 static inline HOST_WIDE_INT
15180 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15182 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15185 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15186 pointer to the declared type for the relevant field variable, or return
15187 `integer_type_node' if the given node turns out to be an
15188 ERROR_MARK node. */
15191 field_type (const_tree decl
)
15195 if (TREE_CODE (decl
) == ERROR_MARK
)
15196 return integer_type_node
;
15198 type
= DECL_BIT_FIELD_TYPE (decl
);
15199 if (type
== NULL_TREE
)
15200 type
= TREE_TYPE (decl
);
15205 /* Given a pointer to a tree node, return the alignment in bits for
15206 it, or else return BITS_PER_WORD if the node actually turns out to
15207 be an ERROR_MARK node. */
15209 static inline unsigned
15210 simple_type_align_in_bits (const_tree type
)
15212 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15215 static inline unsigned
15216 simple_decl_align_in_bits (const_tree decl
)
15218 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15221 /* Return the result of rounding T up to ALIGN. */
15223 static inline offset_int
15224 round_up_to_align (const offset_int
&t
, unsigned int align
)
15226 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
15229 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15230 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15231 or return 0 if we are unable to determine what that offset is, either
15232 because the argument turns out to be a pointer to an ERROR_MARK node, or
15233 because the offset is actually variable. (We can't handle the latter case
15236 static HOST_WIDE_INT
15237 field_byte_offset (const_tree decl
)
15239 offset_int object_offset_in_bits
;
15240 offset_int object_offset_in_bytes
;
15241 offset_int bitpos_int
;
15243 if (TREE_CODE (decl
) == ERROR_MARK
)
15246 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15248 /* We cannot yet cope with fields whose positions are variable, so
15249 for now, when we see such things, we simply return 0. Someday, we may
15250 be able to handle such cases, but it will be damn difficult. */
15251 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15254 bitpos_int
= wi::to_offset (bit_position (decl
));
15256 if (PCC_BITFIELD_TYPE_MATTERS
)
15259 tree field_size_tree
;
15260 offset_int deepest_bitpos
;
15261 offset_int field_size_in_bits
;
15262 unsigned int type_align_in_bits
;
15263 unsigned int decl_align_in_bits
;
15264 offset_int type_size_in_bits
;
15266 type
= field_type (decl
);
15267 type_size_in_bits
= offset_int_type_size_in_bits (type
);
15268 type_align_in_bits
= simple_type_align_in_bits (type
);
15270 field_size_tree
= DECL_SIZE (decl
);
15272 /* The size could be unspecified if there was an error, or for
15273 a flexible array member. */
15274 if (!field_size_tree
)
15275 field_size_tree
= bitsize_zero_node
;
15277 /* If the size of the field is not constant, use the type size. */
15278 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15279 field_size_in_bits
= wi::to_offset (field_size_tree
);
15281 field_size_in_bits
= type_size_in_bits
;
15283 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15285 /* The GCC front-end doesn't make any attempt to keep track of the
15286 starting bit offset (relative to the start of the containing
15287 structure type) of the hypothetical "containing object" for a
15288 bit-field. Thus, when computing the byte offset value for the
15289 start of the "containing object" of a bit-field, we must deduce
15290 this information on our own. This can be rather tricky to do in
15291 some cases. For example, handling the following structure type
15292 definition when compiling for an i386/i486 target (which only
15293 aligns long long's to 32-bit boundaries) can be very tricky:
15295 struct S { int field1; long long field2:31; };
15297 Fortunately, there is a simple rule-of-thumb which can be used
15298 in such cases. When compiling for an i386/i486, GCC will
15299 allocate 8 bytes for the structure shown above. It decides to
15300 do this based upon one simple rule for bit-field allocation.
15301 GCC allocates each "containing object" for each bit-field at
15302 the first (i.e. lowest addressed) legitimate alignment boundary
15303 (based upon the required minimum alignment for the declared
15304 type of the field) which it can possibly use, subject to the
15305 condition that there is still enough available space remaining
15306 in the containing object (when allocated at the selected point)
15307 to fully accommodate all of the bits of the bit-field itself.
15309 This simple rule makes it obvious why GCC allocates 8 bytes for
15310 each object of the structure type shown above. When looking
15311 for a place to allocate the "containing object" for `field2',
15312 the compiler simply tries to allocate a 64-bit "containing
15313 object" at each successive 32-bit boundary (starting at zero)
15314 until it finds a place to allocate that 64- bit field such that
15315 at least 31 contiguous (and previously unallocated) bits remain
15316 within that selected 64 bit field. (As it turns out, for the
15317 example above, the compiler finds it is OK to allocate the
15318 "containing object" 64-bit field at bit-offset zero within the
15321 Here we attempt to work backwards from the limited set of facts
15322 we're given, and we try to deduce from those facts, where GCC
15323 must have believed that the containing object started (within
15324 the structure type). The value we deduce is then used (by the
15325 callers of this routine) to generate DW_AT_location and
15326 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15327 the case of DW_AT_location, regular fields as well). */
15329 /* Figure out the bit-distance from the start of the structure to
15330 the "deepest" bit of the bit-field. */
15331 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
15333 /* This is the tricky part. Use some fancy footwork to deduce
15334 where the lowest addressed bit of the containing object must
15336 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15338 /* Round up to type_align by default. This works best for
15340 object_offset_in_bits
15341 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15343 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
15345 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15347 /* Round up to decl_align instead. */
15348 object_offset_in_bits
15349 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15353 object_offset_in_bits
= bitpos_int
;
15355 object_offset_in_bytes
15356 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
15357 return object_offset_in_bytes
.to_shwi ();
15360 /* The following routines define various Dwarf attributes and any data
15361 associated with them. */
15363 /* Add a location description attribute value to a DIE.
15365 This emits location attributes suitable for whole variables and
15366 whole parameters. Note that the location attributes for struct fields are
15367 generated by the routine `data_member_location_attribute' below. */
15370 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15371 dw_loc_list_ref descr
)
15375 if (single_element_loc_list_p (descr
))
15376 add_AT_loc (die
, attr_kind
, descr
->expr
);
15378 add_AT_loc_list (die
, attr_kind
, descr
);
15381 /* Add DW_AT_accessibility attribute to DIE if needed. */
15384 add_accessibility_attribute (dw_die_ref die
, tree decl
)
15386 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15387 children, otherwise the default is DW_ACCESS_public. In DWARF2
15388 the default has always been DW_ACCESS_public. */
15389 if (TREE_PROTECTED (decl
))
15390 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
15391 else if (TREE_PRIVATE (decl
))
15393 if (dwarf_version
== 2
15394 || die
->die_parent
== NULL
15395 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
15396 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
15398 else if (dwarf_version
> 2
15400 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15401 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15404 /* Attach the specialized form of location attribute used for data members of
15405 struct and union types. In the special case of a FIELD_DECL node which
15406 represents a bit-field, the "offset" part of this special location
15407 descriptor must indicate the distance in bytes from the lowest-addressed
15408 byte of the containing struct or union type to the lowest-addressed byte of
15409 the "containing object" for the bit-field. (See the `field_byte_offset'
15412 For any given bit-field, the "containing object" is a hypothetical object
15413 (of some integral or enum type) within which the given bit-field lives. The
15414 type of this hypothetical "containing object" is always the same as the
15415 declared type of the individual bit-field itself (for GCC anyway... the
15416 DWARF spec doesn't actually mandate this). Note that it is the size (in
15417 bytes) of the hypothetical "containing object" which will be given in the
15418 DW_AT_byte_size attribute for this bit-field. (See the
15419 `byte_size_attribute' function below.) It is also used when calculating the
15420 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15421 function below.) */
15424 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15426 HOST_WIDE_INT offset
;
15427 dw_loc_descr_ref loc_descr
= 0;
15429 if (TREE_CODE (decl
) == TREE_BINFO
)
15431 /* We're working on the TAG_inheritance for a base class. */
15432 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15434 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15435 aren't at a fixed offset from all (sub)objects of the same
15436 type. We need to extract the appropriate offset from our
15437 vtable. The following dwarf expression means
15439 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15441 This is specific to the V3 ABI, of course. */
15443 dw_loc_descr_ref tmp
;
15445 /* Make a copy of the object address. */
15446 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15447 add_loc_descr (&loc_descr
, tmp
);
15449 /* Extract the vtable address. */
15450 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15451 add_loc_descr (&loc_descr
, tmp
);
15453 /* Calculate the address of the offset. */
15454 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15455 gcc_assert (offset
< 0);
15457 tmp
= int_loc_descriptor (-offset
);
15458 add_loc_descr (&loc_descr
, tmp
);
15459 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15460 add_loc_descr (&loc_descr
, tmp
);
15462 /* Extract the offset. */
15463 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15464 add_loc_descr (&loc_descr
, tmp
);
15466 /* Add it to the object address. */
15467 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15468 add_loc_descr (&loc_descr
, tmp
);
15471 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15474 offset
= field_byte_offset (decl
);
15478 if (dwarf_version
> 2)
15480 /* Don't need to output a location expression, just the constant. */
15482 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15484 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15489 enum dwarf_location_atom op
;
15491 /* The DWARF2 standard says that we should assume that the structure
15492 address is already on the stack, so we can specify a structure
15493 field address by using DW_OP_plus_uconst. */
15494 op
= DW_OP_plus_uconst
;
15495 loc_descr
= new_loc_descr (op
, offset
, 0);
15499 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15502 /* Writes integer values to dw_vec_const array. */
15505 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15509 *dest
++ = val
& 0xff;
15515 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15517 static HOST_WIDE_INT
15518 extract_int (const unsigned char *src
, unsigned int size
)
15520 HOST_WIDE_INT val
= 0;
15526 val
|= *--src
& 0xff;
15532 /* Writes wide_int values to dw_vec_const array. */
15535 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15539 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15541 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15545 /* We'd have to extend this code to support odd sizes. */
15546 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
15548 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
15550 if (WORDS_BIG_ENDIAN
)
15551 for (i
= n
- 1; i
>= 0; i
--)
15553 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15554 dest
+= sizeof (HOST_WIDE_INT
);
15557 for (i
= 0; i
< n
; i
++)
15559 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15560 dest
+= sizeof (HOST_WIDE_INT
);
15564 /* Writes floating point values to dw_vec_const array. */
15567 insert_float (const_rtx rtl
, unsigned char *array
)
15572 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
15574 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15575 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15577 insert_int (val
[i
], 4, array
);
15582 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15583 does not have a "location" either in memory or in a register. These
15584 things can arise in GNU C when a constant is passed as an actual parameter
15585 to an inlined function. They can also arise in C++ where declared
15586 constants do not necessarily get memory "homes". */
15589 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15591 switch (GET_CODE (rtl
))
15595 HOST_WIDE_INT val
= INTVAL (rtl
);
15598 add_AT_int (die
, DW_AT_const_value
, val
);
15600 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15604 case CONST_WIDE_INT
:
15605 add_AT_wide (die
, DW_AT_const_value
,
15606 std::make_pair (rtl
, GET_MODE (rtl
)));
15610 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15611 floating-point constant. A CONST_DOUBLE is used whenever the
15612 constant requires more than one word in order to be adequately
15615 machine_mode mode
= GET_MODE (rtl
);
15617 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15618 add_AT_double (die
, DW_AT_const_value
,
15619 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15622 unsigned int length
= GET_MODE_SIZE (mode
);
15623 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15625 insert_float (rtl
, array
);
15626 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15633 machine_mode mode
= GET_MODE (rtl
);
15634 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15635 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15636 unsigned char *array
15637 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15640 machine_mode imode
= GET_MODE_INNER (mode
);
15642 switch (GET_MODE_CLASS (mode
))
15644 case MODE_VECTOR_INT
:
15645 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15647 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15648 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15652 case MODE_VECTOR_FLOAT
:
15653 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15655 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15656 insert_float (elt
, p
);
15661 gcc_unreachable ();
15664 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15669 if (dwarf_version
>= 4 || !dwarf_strict
)
15671 dw_loc_descr_ref loc_result
;
15672 resolve_one_addr (&rtl
);
15674 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15675 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15676 add_AT_loc (die
, DW_AT_location
, loc_result
);
15677 vec_safe_push (used_rtx_array
, rtl
);
15683 if (CONSTANT_P (XEXP (rtl
, 0)))
15684 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15687 if (!const_ok_for_output (rtl
))
15690 if (dwarf_version
>= 4 || !dwarf_strict
)
15695 /* In cases where an inlined instance of an inline function is passed
15696 the address of an `auto' variable (which is local to the caller) we
15697 can get a situation where the DECL_RTL of the artificial local
15698 variable (for the inlining) which acts as a stand-in for the
15699 corresponding formal parameter (of the inline function) will look
15700 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15701 exactly a compile-time constant expression, but it isn't the address
15702 of the (artificial) local variable either. Rather, it represents the
15703 *value* which the artificial local variable always has during its
15704 lifetime. We currently have no way to represent such quasi-constant
15705 values in Dwarf, so for now we just punt and generate nothing. */
15713 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15714 && MEM_READONLY_P (rtl
)
15715 && GET_MODE (rtl
) == BLKmode
)
15717 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15723 /* No other kinds of rtx should be possible here. */
15724 gcc_unreachable ();
15729 /* Determine whether the evaluation of EXPR references any variables
15730 or functions which aren't otherwise used (and therefore may not be
15733 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15734 void * data ATTRIBUTE_UNUSED
)
15736 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15737 *walk_subtrees
= 0;
15739 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15740 && ! TREE_ASM_WRITTEN (*tp
))
15742 /* ??? The C++ FE emits debug information for using decls, so
15743 putting gcc_unreachable here falls over. See PR31899. For now
15744 be conservative. */
15745 else if (!symtab
->global_info_ready
15746 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15748 else if (TREE_CODE (*tp
) == VAR_DECL
)
15750 varpool_node
*node
= varpool_node::get (*tp
);
15751 if (!node
|| !node
->definition
)
15754 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15755 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15757 /* The call graph machinery must have finished analyzing,
15758 optimizing and gimplifying the CU by now.
15759 So if *TP has no call graph node associated
15760 to it, it means *TP will not be emitted. */
15761 if (!cgraph_node::get (*tp
))
15764 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15770 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15771 for use in a later add_const_value_attribute call. */
15774 rtl_for_decl_init (tree init
, tree type
)
15776 rtx rtl
= NULL_RTX
;
15780 /* If a variable is initialized with a string constant without embedded
15781 zeros, build CONST_STRING. */
15782 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15784 tree enttype
= TREE_TYPE (type
);
15785 tree domain
= TYPE_DOMAIN (type
);
15786 machine_mode mode
= TYPE_MODE (enttype
);
15788 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15790 && integer_zerop (TYPE_MIN_VALUE (domain
))
15791 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15792 TREE_STRING_LENGTH (init
) - 1) == 0
15793 && ((size_t) TREE_STRING_LENGTH (init
)
15794 == strlen (TREE_STRING_POINTER (init
)) + 1))
15796 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15797 ggc_strdup (TREE_STRING_POINTER (init
)));
15798 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15799 MEM_READONLY_P (rtl
) = 1;
15802 /* Other aggregates, and complex values, could be represented using
15804 else if (AGGREGATE_TYPE_P (type
)
15805 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15806 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15807 || TREE_CODE (type
) == COMPLEX_TYPE
)
15809 /* Vectors only work if their mode is supported by the target.
15810 FIXME: generic vectors ought to work too. */
15811 else if (TREE_CODE (type
) == VECTOR_TYPE
15812 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15814 /* If the initializer is something that we know will expand into an
15815 immediate RTL constant, expand it now. We must be careful not to
15816 reference variables which won't be output. */
15817 else if (initializer_constant_valid_p (init
, type
)
15818 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15820 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15822 if (TREE_CODE (type
) == VECTOR_TYPE
)
15823 switch (TREE_CODE (init
))
15828 if (TREE_CONSTANT (init
))
15830 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15831 bool constant_p
= true;
15833 unsigned HOST_WIDE_INT ix
;
15835 /* Even when ctor is constant, it might contain non-*_CST
15836 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15837 belong into VECTOR_CST nodes. */
15838 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15839 if (!CONSTANT_CLASS_P (value
))
15841 constant_p
= false;
15847 init
= build_vector_from_ctor (type
, elts
);
15857 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15859 /* If expand_expr returns a MEM, it wasn't immediate. */
15860 gcc_assert (!rtl
|| !MEM_P (rtl
));
15866 /* Generate RTL for the variable DECL to represent its location. */
15869 rtl_for_decl_location (tree decl
)
15873 /* Here we have to decide where we are going to say the parameter "lives"
15874 (as far as the debugger is concerned). We only have a couple of
15875 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15877 DECL_RTL normally indicates where the parameter lives during most of the
15878 activation of the function. If optimization is enabled however, this
15879 could be either NULL or else a pseudo-reg. Both of those cases indicate
15880 that the parameter doesn't really live anywhere (as far as the code
15881 generation parts of GCC are concerned) during most of the function's
15882 activation. That will happen (for example) if the parameter is never
15883 referenced within the function.
15885 We could just generate a location descriptor here for all non-NULL
15886 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15887 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15888 where DECL_RTL is NULL or is a pseudo-reg.
15890 Note however that we can only get away with using DECL_INCOMING_RTL as
15891 a backup substitute for DECL_RTL in certain limited cases. In cases
15892 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15893 we can be sure that the parameter was passed using the same type as it is
15894 declared to have within the function, and that its DECL_INCOMING_RTL
15895 points us to a place where a value of that type is passed.
15897 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15898 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15899 because in these cases DECL_INCOMING_RTL points us to a value of some
15900 type which is *different* from the type of the parameter itself. Thus,
15901 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15902 such cases, the debugger would end up (for example) trying to fetch a
15903 `float' from a place which actually contains the first part of a
15904 `double'. That would lead to really incorrect and confusing
15905 output at debug-time.
15907 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15908 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15909 are a couple of exceptions however. On little-endian machines we can
15910 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15911 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15912 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15913 when (on a little-endian machine) a non-prototyped function has a
15914 parameter declared to be of type `short' or `char'. In such cases,
15915 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15916 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15917 passed `int' value. If the debugger then uses that address to fetch
15918 a `short' or a `char' (on a little-endian machine) the result will be
15919 the correct data, so we allow for such exceptional cases below.
15921 Note that our goal here is to describe the place where the given formal
15922 parameter lives during most of the function's activation (i.e. between the
15923 end of the prologue and the start of the epilogue). We'll do that as best
15924 as we can. Note however that if the given formal parameter is modified
15925 sometime during the execution of the function, then a stack backtrace (at
15926 debug-time) will show the function as having been called with the *new*
15927 value rather than the value which was originally passed in. This happens
15928 rarely enough that it is not a major problem, but it *is* a problem, and
15929 I'd like to fix it.
15931 A future version of dwarf2out.c may generate two additional attributes for
15932 any given DW_TAG_formal_parameter DIE which will describe the "passed
15933 type" and the "passed location" for the given formal parameter in addition
15934 to the attributes we now generate to indicate the "declared type" and the
15935 "active location" for each parameter. This additional set of attributes
15936 could be used by debuggers for stack backtraces. Separately, note that
15937 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15938 This happens (for example) for inlined-instances of inline function formal
15939 parameters which are never referenced. This really shouldn't be
15940 happening. All PARM_DECL nodes should get valid non-NULL
15941 DECL_INCOMING_RTL values. FIXME. */
15943 /* Use DECL_RTL as the "location" unless we find something better. */
15944 rtl
= DECL_RTL_IF_SET (decl
);
15946 /* When generating abstract instances, ignore everything except
15947 constants, symbols living in memory, and symbols living in
15948 fixed registers. */
15949 if (! reload_completed
)
15952 && (CONSTANT_P (rtl
)
15954 && CONSTANT_P (XEXP (rtl
, 0)))
15956 && TREE_CODE (decl
) == VAR_DECL
15957 && TREE_STATIC (decl
))))
15959 rtl
= targetm
.delegitimize_address (rtl
);
15964 else if (TREE_CODE (decl
) == PARM_DECL
)
15966 if (rtl
== NULL_RTX
15967 || is_pseudo_reg (rtl
)
15969 && is_pseudo_reg (XEXP (rtl
, 0))
15970 && DECL_INCOMING_RTL (decl
)
15971 && MEM_P (DECL_INCOMING_RTL (decl
))
15972 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15974 tree declared_type
= TREE_TYPE (decl
);
15975 tree passed_type
= DECL_ARG_TYPE (decl
);
15976 machine_mode dmode
= TYPE_MODE (declared_type
);
15977 machine_mode pmode
= TYPE_MODE (passed_type
);
15979 /* This decl represents a formal parameter which was optimized out.
15980 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15981 all cases where (rtl == NULL_RTX) just below. */
15982 if (dmode
== pmode
)
15983 rtl
= DECL_INCOMING_RTL (decl
);
15984 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15985 && SCALAR_INT_MODE_P (dmode
)
15986 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15987 && DECL_INCOMING_RTL (decl
))
15989 rtx inc
= DECL_INCOMING_RTL (decl
);
15992 else if (MEM_P (inc
))
15994 if (BYTES_BIG_ENDIAN
)
15995 rtl
= adjust_address_nv (inc
, dmode
,
15996 GET_MODE_SIZE (pmode
)
15997 - GET_MODE_SIZE (dmode
));
16004 /* If the parm was passed in registers, but lives on the stack, then
16005 make a big endian correction if the mode of the type of the
16006 parameter is not the same as the mode of the rtl. */
16007 /* ??? This is the same series of checks that are made in dbxout.c before
16008 we reach the big endian correction code there. It isn't clear if all
16009 of these checks are necessary here, but keeping them all is the safe
16011 else if (MEM_P (rtl
)
16012 && XEXP (rtl
, 0) != const0_rtx
16013 && ! CONSTANT_P (XEXP (rtl
, 0))
16014 /* Not passed in memory. */
16015 && !MEM_P (DECL_INCOMING_RTL (decl
))
16016 /* Not passed by invisible reference. */
16017 && (!REG_P (XEXP (rtl
, 0))
16018 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
16019 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
16020 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16021 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
16024 /* Big endian correction check. */
16025 && BYTES_BIG_ENDIAN
16026 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
16027 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
16030 machine_mode addr_mode
= get_address_mode (rtl
);
16031 int offset
= (UNITS_PER_WORD
16032 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
16034 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16035 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
16038 else if (TREE_CODE (decl
) == VAR_DECL
16041 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
16042 && BYTES_BIG_ENDIAN
)
16044 machine_mode addr_mode
= get_address_mode (rtl
);
16045 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16046 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16048 /* If a variable is declared "register" yet is smaller than
16049 a register, then if we store the variable to memory, it
16050 looks like we're storing a register-sized value, when in
16051 fact we are not. We need to adjust the offset of the
16052 storage location to reflect the actual value's bytes,
16053 else gdb will not be able to display it. */
16055 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16056 plus_constant (addr_mode
, XEXP (rtl
, 0),
16060 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16061 and will have been substituted directly into all expressions that use it.
16062 C does not have such a concept, but C++ and other languages do. */
16063 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16064 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16067 rtl
= targetm
.delegitimize_address (rtl
);
16069 /* If we don't look past the constant pool, we risk emitting a
16070 reference to a constant pool entry that isn't referenced from
16071 code, and thus is not emitted. */
16073 rtl
= avoid_constant_pool_reference (rtl
);
16075 /* Try harder to get a rtl. If this symbol ends up not being emitted
16076 in the current CU, resolve_addr will remove the expression referencing
16078 if (rtl
== NULL_RTX
16079 && TREE_CODE (decl
) == VAR_DECL
16080 && !DECL_EXTERNAL (decl
)
16081 && TREE_STATIC (decl
)
16082 && DECL_NAME (decl
)
16083 && !DECL_HARD_REGISTER (decl
)
16084 && DECL_MODE (decl
) != VOIDmode
)
16086 rtl
= make_decl_rtl_for_debug (decl
);
16088 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16089 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16096 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16097 returned. If so, the decl for the COMMON block is returned, and the
16098 value is the offset into the common block for the symbol. */
16101 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16103 tree val_expr
, cvar
;
16105 HOST_WIDE_INT bitsize
, bitpos
;
16107 int unsignedp
, volatilep
= 0;
16109 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16110 it does not have a value (the offset into the common area), or if it
16111 is thread local (as opposed to global) then it isn't common, and shouldn't
16112 be handled as such. */
16113 if (TREE_CODE (decl
) != VAR_DECL
16114 || !TREE_STATIC (decl
)
16115 || !DECL_HAS_VALUE_EXPR_P (decl
)
16119 val_expr
= DECL_VALUE_EXPR (decl
);
16120 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16123 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16124 &mode
, &unsignedp
, &volatilep
, true);
16126 if (cvar
== NULL_TREE
16127 || TREE_CODE (cvar
) != VAR_DECL
16128 || DECL_ARTIFICIAL (cvar
)
16129 || !TREE_PUBLIC (cvar
))
16133 if (offset
!= NULL
)
16135 if (!tree_fits_shwi_p (offset
))
16137 *value
= tree_to_shwi (offset
);
16140 *value
+= bitpos
/ BITS_PER_UNIT
;
16145 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16146 data attribute for a variable or a parameter. We generate the
16147 DW_AT_const_value attribute only in those cases where the given variable
16148 or parameter does not have a true "location" either in memory or in a
16149 register. This can happen (for example) when a constant is passed as an
16150 actual argument in a call to an inline function. (It's possible that
16151 these things can crop up in other ways also.) Note that one type of
16152 constant value which can be passed into an inlined function is a constant
16153 pointer. This can happen for example if an actual argument in an inlined
16154 function call evaluates to a compile-time constant address.
16156 CACHE_P is true if it is worth caching the location list for DECL,
16157 so that future calls can reuse it rather than regenerate it from scratch.
16158 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16159 since we will need to refer to them each time the function is inlined. */
16162 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
16165 dw_loc_list_ref list
;
16166 var_loc_list
*loc_list
;
16167 cached_dw_loc_list
*cache
;
16172 if (TREE_CODE (decl
) == ERROR_MARK
)
16175 if (get_AT (die
, DW_AT_location
)
16176 || get_AT (die
, DW_AT_const_value
))
16179 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16180 || TREE_CODE (decl
) == RESULT_DECL
);
16182 /* Try to get some constant RTL for this decl, and use that as the value of
16185 rtl
= rtl_for_decl_location (decl
);
16186 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16187 && add_const_value_attribute (die
, rtl
))
16190 /* See if we have single element location list that is equivalent to
16191 a constant value. That way we are better to use add_const_value_attribute
16192 rather than expanding constant value equivalent. */
16193 loc_list
= lookup_decl_loc (decl
);
16196 && loc_list
->first
->next
== NULL
16197 && NOTE_P (loc_list
->first
->loc
)
16198 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16199 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16201 struct var_loc_node
*node
;
16203 node
= loc_list
->first
;
16204 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16205 if (GET_CODE (rtl
) == EXPR_LIST
)
16206 rtl
= XEXP (rtl
, 0);
16207 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16208 && add_const_value_attribute (die
, rtl
))
16211 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16212 list several times. See if we've already cached the contents. */
16214 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
16218 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
16220 list
= cache
->loc_list
;
16224 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
16226 /* It is usually worth caching this result if the decl is from
16227 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16228 if (cache_p
&& list
&& list
->dw_loc_next
)
16230 cached_dw_loc_list
**slot
16231 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
16234 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
16235 cache
->decl_id
= DECL_UID (decl
);
16236 cache
->loc_list
= list
;
16242 add_AT_location_description (die
, DW_AT_location
, list
);
16245 /* None of that worked, so it must not really have a location;
16246 try adding a constant value attribute from the DECL_INITIAL. */
16247 return tree_add_const_value_attribute_for_decl (die
, decl
);
16250 /* Helper function for tree_add_const_value_attribute. Natively encode
16251 initializer INIT into an array. Return true if successful. */
16254 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16258 if (init
== NULL_TREE
)
16262 switch (TREE_CODE (init
))
16265 type
= TREE_TYPE (init
);
16266 if (TREE_CODE (type
) == ARRAY_TYPE
)
16268 tree enttype
= TREE_TYPE (type
);
16269 machine_mode mode
= TYPE_MODE (enttype
);
16271 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16273 if (int_size_in_bytes (type
) != size
)
16275 if (size
> TREE_STRING_LENGTH (init
))
16277 memcpy (array
, TREE_STRING_POINTER (init
),
16278 TREE_STRING_LENGTH (init
));
16279 memset (array
+ TREE_STRING_LENGTH (init
),
16280 '\0', size
- TREE_STRING_LENGTH (init
));
16283 memcpy (array
, TREE_STRING_POINTER (init
), size
);
16288 type
= TREE_TYPE (init
);
16289 if (int_size_in_bytes (type
) != size
)
16291 if (TREE_CODE (type
) == ARRAY_TYPE
)
16293 HOST_WIDE_INT min_index
;
16294 unsigned HOST_WIDE_INT cnt
;
16295 int curpos
= 0, fieldsize
;
16296 constructor_elt
*ce
;
16298 if (TYPE_DOMAIN (type
) == NULL_TREE
16299 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
16302 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
16303 if (fieldsize
<= 0)
16306 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
16307 memset (array
, '\0', size
);
16308 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16310 tree val
= ce
->value
;
16311 tree index
= ce
->index
;
16313 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16314 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
16317 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
16322 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16325 curpos
= pos
+ fieldsize
;
16326 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16328 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
16329 - tree_to_shwi (TREE_OPERAND (index
, 0));
16330 while (count
-- > 0)
16333 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16334 curpos
+= fieldsize
;
16337 gcc_assert (curpos
<= size
);
16341 else if (TREE_CODE (type
) == RECORD_TYPE
16342 || TREE_CODE (type
) == UNION_TYPE
)
16344 tree field
= NULL_TREE
;
16345 unsigned HOST_WIDE_INT cnt
;
16346 constructor_elt
*ce
;
16348 if (int_size_in_bytes (type
) != size
)
16351 if (TREE_CODE (type
) == RECORD_TYPE
)
16352 field
= TYPE_FIELDS (type
);
16354 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16356 tree val
= ce
->value
;
16357 int pos
, fieldsize
;
16359 if (ce
->index
!= 0)
16365 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16368 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16369 && TYPE_DOMAIN (TREE_TYPE (field
))
16370 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16372 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16373 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
16375 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
16376 pos
= int_byte_position (field
);
16377 gcc_assert (pos
+ fieldsize
<= size
);
16379 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16385 case VIEW_CONVERT_EXPR
:
16386 case NON_LVALUE_EXPR
:
16387 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16389 return native_encode_expr (init
, array
, size
) == size
;
16393 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16394 attribute is the const value T. */
16397 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16400 tree type
= TREE_TYPE (t
);
16403 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16407 gcc_assert (!DECL_P (init
));
16409 rtl
= rtl_for_decl_init (init
, type
);
16411 return add_const_value_attribute (die
, rtl
);
16412 /* If the host and target are sane, try harder. */
16413 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16414 && initializer_constant_valid_p (init
, type
))
16416 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16417 if (size
> 0 && (int) size
== size
)
16419 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
16421 if (native_encode_initializer (init
, array
, size
))
16423 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16432 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16433 attribute is the const value of T, where T is an integral constant
16434 variable with static storage duration
16435 (so it can't be a PARM_DECL or a RESULT_DECL). */
16438 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16442 || (TREE_CODE (decl
) != VAR_DECL
16443 && TREE_CODE (decl
) != CONST_DECL
)
16444 || (TREE_CODE (decl
) == VAR_DECL
16445 && !TREE_STATIC (decl
)))
16448 if (TREE_READONLY (decl
)
16449 && ! TREE_THIS_VOLATILE (decl
)
16450 && DECL_INITIAL (decl
))
16455 /* Don't add DW_AT_const_value if abstract origin already has one. */
16456 if (get_AT (var_die
, DW_AT_const_value
))
16459 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16462 /* Convert the CFI instructions for the current function into a
16463 location list. This is used for DW_AT_frame_base when we targeting
16464 a dwarf2 consumer that does not support the dwarf3
16465 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16468 static dw_loc_list_ref
16469 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16473 dw_loc_list_ref list
, *list_tail
;
16475 dw_cfa_location last_cfa
, next_cfa
;
16476 const char *start_label
, *last_label
, *section
;
16477 dw_cfa_location remember
;
16480 gcc_assert (fde
!= NULL
);
16482 section
= secname_for_decl (current_function_decl
);
16486 memset (&next_cfa
, 0, sizeof (next_cfa
));
16487 next_cfa
.reg
= INVALID_REGNUM
;
16488 remember
= next_cfa
;
16490 start_label
= fde
->dw_fde_begin
;
16492 /* ??? Bald assumption that the CIE opcode list does not contain
16493 advance opcodes. */
16494 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16495 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16497 last_cfa
= next_cfa
;
16498 last_label
= start_label
;
16500 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16502 /* If the first partition contained no CFI adjustments, the
16503 CIE opcodes apply to the whole first partition. */
16504 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16505 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16506 list_tail
=&(*list_tail
)->dw_loc_next
;
16507 start_label
= last_label
= fde
->dw_fde_second_begin
;
16510 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16512 switch (cfi
->dw_cfi_opc
)
16514 case DW_CFA_set_loc
:
16515 case DW_CFA_advance_loc1
:
16516 case DW_CFA_advance_loc2
:
16517 case DW_CFA_advance_loc4
:
16518 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16520 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16521 start_label
, last_label
, section
);
16523 list_tail
= &(*list_tail
)->dw_loc_next
;
16524 last_cfa
= next_cfa
;
16525 start_label
= last_label
;
16527 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16530 case DW_CFA_advance_loc
:
16531 /* The encoding is complex enough that we should never emit this. */
16532 gcc_unreachable ();
16535 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16538 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16540 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16542 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16543 start_label
, last_label
, section
);
16545 list_tail
= &(*list_tail
)->dw_loc_next
;
16546 last_cfa
= next_cfa
;
16547 start_label
= last_label
;
16549 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16550 start_label
, fde
->dw_fde_end
, section
);
16551 list_tail
= &(*list_tail
)->dw_loc_next
;
16552 start_label
= last_label
= fde
->dw_fde_second_begin
;
16556 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16558 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16559 start_label
, last_label
, section
);
16560 list_tail
= &(*list_tail
)->dw_loc_next
;
16561 start_label
= last_label
;
16564 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16566 fde
->dw_fde_second_begin
16567 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16570 if (list
&& list
->dw_loc_next
)
16576 /* Compute a displacement from the "steady-state frame pointer" to the
16577 frame base (often the same as the CFA), and store it in
16578 frame_pointer_fb_offset. OFFSET is added to the displacement
16579 before the latter is negated. */
16582 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16586 #ifdef FRAME_POINTER_CFA_OFFSET
16587 reg
= frame_pointer_rtx
;
16588 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16590 reg
= arg_pointer_rtx
;
16591 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16594 elim
= (ira_use_lra_p
16595 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16596 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16597 if (GET_CODE (elim
) == PLUS
)
16599 offset
+= INTVAL (XEXP (elim
, 1));
16600 elim
= XEXP (elim
, 0);
16603 frame_pointer_fb_offset
= -offset
;
16605 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16606 in which to eliminate. This is because it's stack pointer isn't
16607 directly accessible as a register within the ISA. To work around
16608 this, assume that while we cannot provide a proper value for
16609 frame_pointer_fb_offset, we won't need one either. */
16610 frame_pointer_fb_offset_valid
16611 = ((SUPPORTS_STACK_ALIGNMENT
16612 && (elim
== hard_frame_pointer_rtx
16613 || elim
== stack_pointer_rtx
))
16614 || elim
== (frame_pointer_needed
16615 ? hard_frame_pointer_rtx
16616 : stack_pointer_rtx
));
16619 /* Generate a DW_AT_name attribute given some string value to be included as
16620 the value of the attribute. */
16623 add_name_attribute (dw_die_ref die
, const char *name_string
)
16625 if (name_string
!= NULL
&& *name_string
!= 0)
16627 if (demangle_name_func
)
16628 name_string
= (*demangle_name_func
) (name_string
);
16630 add_AT_string (die
, DW_AT_name
, name_string
);
16634 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16635 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16636 of TYPE accordingly.
16638 ??? This is a temporary measure until after we're able to generate
16639 regular DWARF for the complex Ada type system. */
16642 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16643 dw_die_ref context_die
)
16646 dw_die_ref dtype_die
;
16648 if (!lang_hooks
.types
.descriptive_type
)
16651 dtype
= lang_hooks
.types
.descriptive_type (type
);
16655 dtype_die
= lookup_type_die (dtype
);
16658 gen_type_die (dtype
, context_die
);
16659 dtype_die
= lookup_type_die (dtype
);
16660 gcc_assert (dtype_die
);
16663 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16666 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16668 static const char *
16669 comp_dir_string (void)
16673 static const char *cached_wd
= NULL
;
16675 if (cached_wd
!= NULL
)
16678 wd
= get_src_pwd ();
16682 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16686 wdlen
= strlen (wd
);
16687 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
16689 wd1
[wdlen
] = DIR_SEPARATOR
;
16690 wd1
[wdlen
+ 1] = 0;
16694 cached_wd
= remap_debug_filename (wd
);
16698 /* Generate a DW_AT_comp_dir attribute for DIE. */
16701 add_comp_dir_attribute (dw_die_ref die
)
16703 const char * wd
= comp_dir_string ();
16705 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16708 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
16709 pointer computation, ...), output a representation for that bound according
16710 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
16711 loc_list_from_tree for the meaning of CONTEXT. */
16714 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
16715 int forms
, const struct loc_descr_context
*context
)
16717 dw_die_ref ctx
, decl_die
;
16718 dw_loc_list_ref list
;
16720 bool strip_conversions
= true;
16722 while (strip_conversions
)
16723 switch (TREE_CODE (value
))
16730 case VIEW_CONVERT_EXPR
:
16731 value
= TREE_OPERAND (value
, 0);
16735 strip_conversions
= false;
16739 /* If possible and permitted, output the attribute as a constant. */
16740 if ((forms
& dw_scalar_form_constant
) != 0
16741 && TREE_CODE (value
) == INTEGER_CST
)
16743 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
16745 /* If HOST_WIDE_INT is big enough then represent the bound as
16746 a constant value. We need to choose a form based on
16747 whether the type is signed or unsigned. We cannot just
16748 call add_AT_unsigned if the value itself is positive
16749 (add_AT_unsigned might add the unsigned value encoded as
16750 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16751 bounds type and then sign extend any unsigned values found
16752 for signed types. This is needed only for
16753 DW_AT_{lower,upper}_bound, since for most other attributes,
16754 consumers will treat DW_FORM_data[1248] as unsigned values,
16755 regardless of the underlying type. */
16756 if (prec
<= HOST_BITS_PER_WIDE_INT
16757 || tree_fits_uhwi_p (value
))
16759 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
16760 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
16762 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
16765 /* Otherwise represent the bound as an unsigned value with
16766 the precision of its type. The precision and signedness
16767 of the type will be necessary to re-interpret it
16769 add_AT_wide (die
, attr
, value
);
16773 /* Otherwise, if it's possible and permitted too, output a reference to
16775 if ((forms
& dw_scalar_form_reference
) != 0)
16777 tree decl
= NULL_TREE
;
16779 /* Some type attributes reference an outer type. For instance, the upper
16780 bound of an array may reference an embedding record (this happens in
16782 if (TREE_CODE (value
) == COMPONENT_REF
16783 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
16784 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
16785 decl
= TREE_OPERAND (value
, 1);
16787 else if (TREE_CODE (value
) == VAR_DECL
16788 || TREE_CODE (value
) == PARM_DECL
16789 || TREE_CODE (value
) == RESULT_DECL
)
16792 if (decl
!= NULL_TREE
)
16794 dw_die_ref decl_die
= lookup_decl_die (decl
);
16796 /* ??? Can this happen, or should the variable have been bound
16797 first? Probably it can, since I imagine that we try to create
16798 the types of parameters in the order in which they exist in
16799 the list, and won't have created a forward reference to a
16800 later parameter. */
16801 if (decl_die
!= NULL
)
16803 add_AT_die_ref (die
, attr
, decl_die
);
16809 /* Last chance: try to create a stack operation procedure to evaluate the
16810 value. Do nothing if even that is not possible or permitted. */
16811 if ((forms
& dw_scalar_form_exprloc
) == 0)
16814 list
= loc_list_from_tree (value
, 2, context
);
16815 if (list
== NULL
|| single_element_loc_list_p (list
))
16817 /* If this attribute is not a reference nor constant, it is
16818 a DWARF expression rather than location description. For that
16819 loc_list_from_tree (value, 0, &context) is needed. */
16820 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
16821 if (list2
&& single_element_loc_list_p (list2
))
16823 add_AT_loc (die
, attr
, list2
->expr
);
16828 /* If that failed to give a single element location list, fall back to
16829 outputting this as a reference... still if permitted. */
16830 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
16833 if (current_function_decl
== 0)
16834 ctx
= comp_unit_die ();
16836 ctx
= lookup_decl_die (current_function_decl
);
16838 decl_die
= new_die (DW_TAG_variable
, ctx
, value
);
16839 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16840 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, ctx
);
16841 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16842 add_AT_die_ref (die
, attr
, decl_die
);
16845 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16849 lower_bound_default (void)
16851 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16857 case DW_LANG_C_plus_plus
:
16858 case DW_LANG_C_plus_plus_11
:
16859 case DW_LANG_C_plus_plus_14
:
16861 case DW_LANG_ObjC_plus_plus
:
16864 case DW_LANG_Fortran77
:
16865 case DW_LANG_Fortran90
:
16866 case DW_LANG_Fortran95
:
16867 case DW_LANG_Fortran03
:
16868 case DW_LANG_Fortran08
:
16872 case DW_LANG_Python
:
16873 return dwarf_version
>= 4 ? 0 : -1;
16874 case DW_LANG_Ada95
:
16875 case DW_LANG_Ada83
:
16876 case DW_LANG_Cobol74
:
16877 case DW_LANG_Cobol85
:
16878 case DW_LANG_Pascal83
:
16879 case DW_LANG_Modula2
:
16881 return dwarf_version
>= 4 ? 1 : -1;
16887 /* Given a tree node describing an array bound (either lower or upper) output
16888 a representation for that bound. */
16891 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
16892 tree bound
, const struct loc_descr_context
*context
)
16897 switch (TREE_CODE (bound
))
16899 /* Strip all conversions. */
16901 case VIEW_CONVERT_EXPR
:
16902 bound
= TREE_OPERAND (bound
, 0);
16905 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
16906 are even omitted when they are the default. */
16908 /* If the value for this bound is the default one, we can even omit the
16910 if (bound_attr
== DW_AT_lower_bound
16911 && tree_fits_shwi_p (bound
)
16912 && (dflt
= lower_bound_default ()) != -1
16913 && tree_to_shwi (bound
) == dflt
)
16919 add_scalar_info (subrange_die
, bound_attr
, bound
,
16920 dw_scalar_form_constant
16921 | dw_scalar_form_exprloc
16922 | dw_scalar_form_reference
,
16928 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16929 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16930 Note that the block of subscript information for an array type also
16931 includes information about the element type of the given array type.
16933 This function reuses previously set type and bound information if
16937 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16939 unsigned dimension_number
;
16941 dw_die_ref child
= type_die
->die_child
;
16943 for (dimension_number
= 0;
16944 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16945 type
= TREE_TYPE (type
), dimension_number
++)
16947 tree domain
= TYPE_DOMAIN (type
);
16949 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16952 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16953 and (in GNU C only) variable bounds. Handle all three forms
16956 /* Find and reuse a previously generated DW_TAG_subrange_type if
16959 For multi-dimensional arrays, as we iterate through the
16960 various dimensions in the enclosing for loop above, we also
16961 iterate through the DIE children and pick at each
16962 DW_TAG_subrange_type previously generated (if available).
16963 Each child DW_TAG_subrange_type DIE describes the range of
16964 the current dimension. At this point we should have as many
16965 DW_TAG_subrange_type's as we have dimensions in the
16967 dw_die_ref subrange_die
= NULL
;
16971 child
= child
->die_sib
;
16972 if (child
->die_tag
== DW_TAG_subrange_type
)
16973 subrange_die
= child
;
16974 if (child
== type_die
->die_child
)
16976 /* If we wrapped around, stop looking next time. */
16980 if (child
->die_tag
== DW_TAG_subrange_type
)
16984 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16988 /* We have an array type with specified bounds. */
16989 lower
= TYPE_MIN_VALUE (domain
);
16990 upper
= TYPE_MAX_VALUE (domain
);
16992 /* Define the index type. */
16993 if (TREE_TYPE (domain
)
16994 && !get_AT (subrange_die
, DW_AT_type
))
16996 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16997 TREE_TYPE field. We can't emit debug info for this
16998 because it is an unnamed integral type. */
16999 if (TREE_CODE (domain
) == INTEGER_TYPE
17000 && TYPE_NAME (domain
) == NULL_TREE
17001 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
17002 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
17005 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
17006 TYPE_UNQUALIFIED
, type_die
);
17009 /* ??? If upper is NULL, the array has unspecified length,
17010 but it does have a lower bound. This happens with Fortran
17012 Since the debugger is definitely going to need to know N
17013 to produce useful results, go ahead and output the lower
17014 bound solo, and hope the debugger can cope. */
17016 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
17017 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
17018 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
17019 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
17022 /* Otherwise we have an array type with an unspecified length. The
17023 DWARF-2 spec does not say how to handle this; let's just leave out the
17028 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
17031 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
17033 dw_die_ref decl_die
;
17034 HOST_WIDE_INT size
;
17036 switch (TREE_CODE (tree_node
))
17041 case ENUMERAL_TYPE
:
17044 case QUAL_UNION_TYPE
:
17045 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
17046 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
17048 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
17051 size
= int_size_in_bytes (tree_node
);
17054 /* For a data member of a struct or union, the DW_AT_byte_size is
17055 generally given as the number of bytes normally allocated for an
17056 object of the *declared* type of the member itself. This is true
17057 even for bit-fields. */
17058 size
= int_size_in_bytes (field_type (tree_node
));
17061 gcc_unreachable ();
17064 /* Note that `size' might be -1 when we get to this point. If it is, that
17065 indicates that the byte size of the entity in question is variable. We
17066 have no good way of expressing this fact in Dwarf at the present time,
17067 when location description was not used by the caller code instead. */
17069 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17072 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17073 which specifies the distance in bits from the highest order bit of the
17074 "containing object" for the bit-field to the highest order bit of the
17077 For any given bit-field, the "containing object" is a hypothetical object
17078 (of some integral or enum type) within which the given bit-field lives. The
17079 type of this hypothetical "containing object" is always the same as the
17080 declared type of the individual bit-field itself. The determination of the
17081 exact location of the "containing object" for a bit-field is rather
17082 complicated. It's handled by the `field_byte_offset' function (above).
17084 Note that it is the size (in bytes) of the hypothetical "containing object"
17085 which will be given in the DW_AT_byte_size attribute for this bit-field.
17086 (See `byte_size_attribute' above). */
17089 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17091 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17092 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17093 HOST_WIDE_INT bitpos_int
;
17094 HOST_WIDE_INT highest_order_object_bit_offset
;
17095 HOST_WIDE_INT highest_order_field_bit_offset
;
17096 HOST_WIDE_INT bit_offset
;
17098 /* Must be a field and a bit field. */
17099 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17101 /* We can't yet handle bit-fields whose offsets are variable, so if we
17102 encounter such things, just return without generating any attribute
17103 whatsoever. Likewise for variable or too large size. */
17104 if (! tree_fits_shwi_p (bit_position (decl
))
17105 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
17108 bitpos_int
= int_bit_position (decl
);
17110 /* Note that the bit offset is always the distance (in bits) from the
17111 highest-order bit of the "containing object" to the highest-order bit of
17112 the bit-field itself. Since the "high-order end" of any object or field
17113 is different on big-endian and little-endian machines, the computation
17114 below must take account of these differences. */
17115 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17116 highest_order_field_bit_offset
= bitpos_int
;
17118 if (! BYTES_BIG_ENDIAN
)
17120 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
17121 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17125 = (! BYTES_BIG_ENDIAN
17126 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17127 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17129 if (bit_offset
< 0)
17130 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
17132 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
17135 /* For a FIELD_DECL node which represents a bit field, output an attribute
17136 which specifies the length in bits of the given field. */
17139 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17141 /* Must be a field and a bit field. */
17142 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17143 && DECL_BIT_FIELD_TYPE (decl
));
17145 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
17146 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
17149 /* If the compiled language is ANSI C, then add a 'prototyped'
17150 attribute, if arg types are given for the parameters of a function. */
17153 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17155 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17162 if (prototype_p (func_type
))
17163 add_AT_flag (die
, DW_AT_prototyped
, 1);
17170 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17171 by looking in either the type declaration or object declaration
17174 static inline dw_die_ref
17175 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17177 dw_die_ref origin_die
= NULL
;
17179 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17181 /* We may have gotten separated from the block for the inlined
17182 function, if we're in an exception handler or some such; make
17183 sure that the abstract function has been written out.
17185 Doing this for nested functions is wrong, however; functions are
17186 distinct units, and our context might not even be inline. */
17190 fn
= TYPE_STUB_DECL (fn
);
17192 fn
= decl_function_context (fn
);
17194 dwarf2out_abstract_function (fn
);
17197 if (DECL_P (origin
))
17198 origin_die
= lookup_decl_die (origin
);
17199 else if (TYPE_P (origin
))
17200 origin_die
= lookup_type_die (origin
);
17202 /* XXX: Functions that are never lowered don't always have correct block
17203 trees (in the case of java, they simply have no block tree, in some other
17204 languages). For these functions, there is nothing we can really do to
17205 output correct debug info for inlined functions in all cases. Rather
17206 than die, we'll just produce deficient debug info now, in that we will
17207 have variables without a proper abstract origin. In the future, when all
17208 functions are lowered, we should re-add a gcc_assert (origin_die)
17212 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17216 /* We do not currently support the pure_virtual attribute. */
17219 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17221 if (DECL_VINDEX (func_decl
))
17223 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17225 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
17226 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17227 new_loc_descr (DW_OP_constu
,
17228 tree_to_shwi (DECL_VINDEX (func_decl
)),
17231 /* GNU extension: Record what type this method came from originally. */
17232 if (debug_info_level
> DINFO_LEVEL_TERSE
17233 && DECL_CONTEXT (func_decl
))
17234 add_AT_die_ref (die
, DW_AT_containing_type
,
17235 lookup_type_die (DECL_CONTEXT (func_decl
)));
17239 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17240 given decl. This used to be a vendor extension until after DWARF 4
17241 standardized it. */
17244 add_linkage_attr (dw_die_ref die
, tree decl
)
17246 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17248 /* Mimic what assemble_name_raw does with a leading '*'. */
17249 if (name
[0] == '*')
17252 if (dwarf_version
>= 4)
17253 add_AT_string (die
, DW_AT_linkage_name
, name
);
17255 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17258 /* Add source coordinate attributes for the given decl. */
17261 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17263 expanded_location s
;
17265 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
17267 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17268 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17269 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17272 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17275 add_linkage_name (dw_die_ref die
, tree decl
)
17277 if (debug_info_level
> DINFO_LEVEL_NONE
17278 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17279 && TREE_PUBLIC (decl
)
17280 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17281 && die
->die_tag
!= DW_TAG_member
)
17283 /* Defer until we have an assembler name set. */
17284 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17286 limbo_die_node
*asm_name
;
17288 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
17289 asm_name
->die
= die
;
17290 asm_name
->created_for
= decl
;
17291 asm_name
->next
= deferred_asm_name
;
17292 deferred_asm_name
= asm_name
;
17294 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17295 add_linkage_attr (die
, decl
);
17299 /* Add a DW_AT_name attribute and source coordinate attribute for the
17300 given decl, but only if it actually has a name. */
17303 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17307 decl_name
= DECL_NAME (decl
);
17308 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17310 const char *name
= dwarf2_name (decl
, 0);
17312 add_name_attribute (die
, name
);
17313 if (! DECL_ARTIFICIAL (decl
))
17314 add_src_coords_attributes (die
, decl
);
17316 add_linkage_name (die
, decl
);
17319 #ifdef VMS_DEBUGGING_INFO
17320 /* Get the function's name, as described by its RTL. This may be different
17321 from the DECL_NAME name used in the source file. */
17322 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17324 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17325 XEXP (DECL_RTL (decl
), 0), false);
17326 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17328 #endif /* VMS_DEBUGGING_INFO */
17331 #ifdef VMS_DEBUGGING_INFO
17332 /* Output the debug main pointer die for VMS */
17335 dwarf2out_vms_debug_main_pointer (void)
17337 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17340 /* Allocate the VMS debug main subprogram die. */
17341 die
= ggc_cleared_alloc
<die_node
> ();
17342 die
->die_tag
= DW_TAG_subprogram
;
17343 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17344 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17345 current_function_funcdef_no
);
17346 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17348 /* Make it the first child of comp_unit_die (). */
17349 die
->die_parent
= comp_unit_die ();
17350 if (comp_unit_die ()->die_child
)
17352 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17353 comp_unit_die ()->die_child
->die_sib
= die
;
17357 die
->die_sib
= die
;
17358 comp_unit_die ()->die_child
= die
;
17361 #endif /* VMS_DEBUGGING_INFO */
17363 /* Push a new declaration scope. */
17366 push_decl_scope (tree scope
)
17368 vec_safe_push (decl_scope_table
, scope
);
17371 /* Pop a declaration scope. */
17374 pop_decl_scope (void)
17376 decl_scope_table
->pop ();
17379 /* walk_tree helper function for uses_local_type, below. */
17382 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
17385 *walk_subtrees
= 0;
17388 tree name
= TYPE_NAME (*tp
);
17389 if (name
&& DECL_P (name
) && decl_function_context (name
))
17395 /* If TYPE involves a function-local type (including a local typedef to a
17396 non-local type), returns that type; otherwise returns NULL_TREE. */
17399 uses_local_type (tree type
)
17401 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
17405 /* Return the DIE for the scope that immediately contains this type.
17406 Non-named types that do not involve a function-local type get global
17407 scope. Named types nested in namespaces or other types get their
17408 containing scope. All other types (i.e. function-local named types) get
17409 the current active scope. */
17412 scope_die_for (tree t
, dw_die_ref context_die
)
17414 dw_die_ref scope_die
= NULL
;
17415 tree containing_scope
;
17417 /* Non-types always go in the current scope. */
17418 gcc_assert (TYPE_P (t
));
17420 /* Use the scope of the typedef, rather than the scope of the type
17422 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
17423 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
17425 containing_scope
= TYPE_CONTEXT (t
);
17427 /* Use the containing namespace if there is one. */
17428 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17430 if (context_die
== lookup_decl_die (containing_scope
))
17432 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
17433 context_die
= get_context_die (containing_scope
);
17435 containing_scope
= NULL_TREE
;
17438 /* Ignore function type "scopes" from the C frontend. They mean that
17439 a tagged type is local to a parmlist of a function declarator, but
17440 that isn't useful to DWARF. */
17441 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17442 containing_scope
= NULL_TREE
;
17444 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17446 /* If T uses a local type keep it local as well, to avoid references
17447 to function-local DIEs from outside the function. */
17448 if (current_function_decl
&& uses_local_type (t
))
17449 scope_die
= context_die
;
17451 scope_die
= comp_unit_die ();
17453 else if (TYPE_P (containing_scope
))
17455 /* For types, we can just look up the appropriate DIE. */
17456 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17457 scope_die
= get_context_die (containing_scope
);
17460 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
17461 if (scope_die
== NULL
)
17462 scope_die
= comp_unit_die ();
17466 scope_die
= context_die
;
17471 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17474 local_scope_p (dw_die_ref context_die
)
17476 for (; context_die
; context_die
= context_die
->die_parent
)
17477 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17478 || context_die
->die_tag
== DW_TAG_subprogram
)
17484 /* Returns nonzero if CONTEXT_DIE is a class. */
17487 class_scope_p (dw_die_ref context_die
)
17489 return (context_die
17490 && (context_die
->die_tag
== DW_TAG_structure_type
17491 || context_die
->die_tag
== DW_TAG_class_type
17492 || context_die
->die_tag
== DW_TAG_interface_type
17493 || context_die
->die_tag
== DW_TAG_union_type
));
17496 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17497 whether or not to treat a DIE in this context as a declaration. */
17500 class_or_namespace_scope_p (dw_die_ref context_die
)
17502 return (class_scope_p (context_die
)
17503 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17506 /* Many forms of DIEs require a "type description" attribute. This
17507 routine locates the proper "type descriptor" die for the type given
17508 by 'type' plus any additional qualifiers given by 'cv_quals', and
17509 adds a DW_AT_type attribute below the given die. */
17512 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
17513 dw_die_ref context_die
)
17515 enum tree_code code
= TREE_CODE (type
);
17516 dw_die_ref type_die
= NULL
;
17518 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17519 or fixed-point type, use the inner type. This is because we have no
17520 support for unnamed types in base_type_die. This can happen if this is
17521 an Ada subrange type. Correct solution is emit a subrange type die. */
17522 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17523 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17524 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17526 if (code
== ERROR_MARK
17527 /* Handle a special case. For functions whose return type is void, we
17528 generate *no* type attribute. (Note that no object may have type
17529 `void', so this only applies to function return types). */
17530 || code
== VOID_TYPE
)
17533 type_die
= modified_type_die (type
,
17534 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
17537 if (type_die
!= NULL
)
17538 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17541 /* Given an object die, add the calling convention attribute for the
17542 function call type. */
17544 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17546 enum dwarf_calling_convention value
= DW_CC_normal
;
17548 value
= ((enum dwarf_calling_convention
)
17549 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17552 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17554 /* DWARF 2 doesn't provide a way to identify a program's source-level
17555 entry point. DW_AT_calling_convention attributes are only meant
17556 to describe functions' calling conventions. However, lacking a
17557 better way to signal the Fortran main program, we used this for
17558 a long time, following existing custom. Now, DWARF 4 has
17559 DW_AT_main_subprogram, which we add below, but some tools still
17560 rely on the old way, which we thus keep. */
17561 value
= DW_CC_program
;
17563 if (dwarf_version
>= 4 || !dwarf_strict
)
17564 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17567 /* Only add the attribute if the backend requests it, and
17568 is not DW_CC_normal. */
17569 if (value
&& (value
!= DW_CC_normal
))
17570 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17573 /* Given a tree pointer to a struct, class, union, or enum type node, return
17574 a pointer to the (string) tag name for the given type, or zero if the type
17575 was declared without a tag. */
17577 static const char *
17578 type_tag (const_tree type
)
17580 const char *name
= 0;
17582 if (TYPE_NAME (type
) != 0)
17586 /* Find the IDENTIFIER_NODE for the type name. */
17587 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17588 && !TYPE_NAMELESS (type
))
17589 t
= TYPE_NAME (type
);
17591 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17592 a TYPE_DECL node, regardless of whether or not a `typedef' was
17594 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17595 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17597 /* We want to be extra verbose. Don't call dwarf_name if
17598 DECL_NAME isn't set. The default hook for decl_printable_name
17599 doesn't like that, and in this context it's correct to return
17600 0, instead of "<anonymous>" or the like. */
17601 if (DECL_NAME (TYPE_NAME (type
))
17602 && !DECL_NAMELESS (TYPE_NAME (type
)))
17603 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17606 /* Now get the name as a string, or invent one. */
17607 if (!name
&& t
!= 0)
17608 name
= IDENTIFIER_POINTER (t
);
17611 return (name
== 0 || *name
== '\0') ? 0 : name
;
17614 /* Return the type associated with a data member, make a special check
17615 for bit field types. */
17618 member_declared_type (const_tree member
)
17620 return (DECL_BIT_FIELD_TYPE (member
)
17621 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17624 /* Get the decl's label, as described by its RTL. This may be different
17625 from the DECL_NAME name used in the source file. */
17628 static const char *
17629 decl_start_label (tree decl
)
17632 const char *fnname
;
17634 x
= DECL_RTL (decl
);
17635 gcc_assert (MEM_P (x
));
17638 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17640 fnname
= XSTR (x
, 0);
17645 /* For variable-length arrays that have been previously generated, but
17646 may be incomplete due to missing subscript info, fill the subscript
17647 info. Return TRUE if this is one of those cases. */
17649 fill_variable_array_bounds (tree type
)
17651 if (TREE_ASM_WRITTEN (type
)
17652 && TREE_CODE (type
) == ARRAY_TYPE
17653 && variably_modified_type_p (type
, NULL
))
17655 dw_die_ref array_die
= lookup_type_die (type
);
17658 add_subscript_info (array_die
, type
, !is_ada ());
17664 /* These routines generate the internal representation of the DIE's for
17665 the compilation unit. Debugging information is collected by walking
17666 the declaration trees passed in from dwarf2out_decl(). */
17669 gen_array_type_die (tree type
, dw_die_ref context_die
)
17671 dw_die_ref array_die
;
17673 /* GNU compilers represent multidimensional array types as sequences of one
17674 dimensional array types whose element types are themselves array types.
17675 We sometimes squish that down to a single array_type DIE with multiple
17676 subscripts in the Dwarf debugging info. The draft Dwarf specification
17677 say that we are allowed to do this kind of compression in C, because
17678 there is no difference between an array of arrays and a multidimensional
17679 array. We don't do this for Ada to remain as close as possible to the
17680 actual representation, which is especially important against the language
17681 flexibilty wrt arrays of variable size. */
17683 bool collapse_nested_arrays
= !is_ada ();
17685 if (fill_variable_array_bounds (type
))
17688 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17691 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17692 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17693 if (TYPE_STRING_FLAG (type
)
17694 && TREE_CODE (type
) == ARRAY_TYPE
17696 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17698 HOST_WIDE_INT size
;
17700 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17701 add_name_attribute (array_die
, type_tag (type
));
17702 equate_type_number_to_die (type
, array_die
);
17703 size
= int_size_in_bytes (type
);
17705 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17706 else if (TYPE_DOMAIN (type
) != NULL_TREE
17707 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17708 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17710 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17711 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
17713 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17714 if (loc
&& size
> 0)
17716 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17717 if (size
!= DWARF2_ADDR_SIZE
)
17718 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17724 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17725 add_name_attribute (array_die
, type_tag (type
));
17726 equate_type_number_to_die (type
, array_die
);
17728 if (TREE_CODE (type
) == VECTOR_TYPE
)
17729 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17731 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17733 && TREE_CODE (type
) == ARRAY_TYPE
17734 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17735 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17736 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17739 /* We default the array ordering. SDB will probably do
17740 the right things even if DW_AT_ordering is not present. It's not even
17741 an issue until we start to get into multidimensional arrays anyway. If
17742 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17743 then we'll have to put the DW_AT_ordering attribute back in. (But if
17744 and when we find out that we need to put these in, we will only do so
17745 for multidimensional arrays. */
17746 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17749 if (TREE_CODE (type
) == VECTOR_TYPE
)
17751 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17752 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17753 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
17754 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17755 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
17758 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17760 /* Add representation of the type of the elements of this array type and
17761 emit the corresponding DIE if we haven't done it already. */
17762 element_type
= TREE_TYPE (type
);
17763 if (collapse_nested_arrays
)
17764 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17766 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17768 element_type
= TREE_TYPE (element_type
);
17771 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
, context_die
);
17773 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17774 if (TYPE_ARTIFICIAL (type
))
17775 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17777 if (get_AT (array_die
, DW_AT_name
))
17778 add_pubtype (type
, array_die
);
17781 /* This routine generates DIE for array with hidden descriptor, details
17782 are filled into *info by a langhook. */
17785 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17786 dw_die_ref context_die
)
17788 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17789 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17790 const struct loc_descr_context context
= { type
, info
->base_decl
};
17793 add_name_attribute (array_die
, type_tag (type
));
17794 equate_type_number_to_die (type
, array_die
);
17796 if (info
->ndimensions
> 1)
17797 switch (info
->ordering
)
17799 case array_descr_ordering_row_major
:
17800 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17802 case array_descr_ordering_column_major
:
17803 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17809 if (dwarf_version
>= 3 || !dwarf_strict
)
17811 if (info
->data_location
)
17812 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
17813 dw_scalar_form_exprloc
, &context
);
17814 if (info
->associated
)
17815 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
17816 dw_scalar_form_constant
17817 | dw_scalar_form_exprloc
17818 | dw_scalar_form_reference
, &context
);
17819 if (info
->allocated
)
17820 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
17821 dw_scalar_form_constant
17822 | dw_scalar_form_exprloc
17823 | dw_scalar_form_reference
, &context
);
17826 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17828 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17830 dw_die_ref subrange_die
17831 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17833 if (info
->dimen
[dim
].bounds_type
)
17834 add_type_attribute (subrange_die
,
17835 info
->dimen
[dim
].bounds_type
, 0,
17837 if (info
->dimen
[dim
].lower_bound
)
17838 add_bound_info (subrange_die
, DW_AT_lower_bound
,
17839 info
->dimen
[dim
].lower_bound
, &context
);
17840 if (info
->dimen
[dim
].upper_bound
)
17841 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17842 info
->dimen
[dim
].upper_bound
, &context
);
17843 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
17844 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
17845 info
->dimen
[dim
].stride
,
17846 dw_scalar_form_constant
17847 | dw_scalar_form_exprloc
17848 | dw_scalar_form_reference
,
17852 gen_type_die (info
->element_type
, context_die
);
17853 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
17856 if (get_AT (array_die
, DW_AT_name
))
17857 add_pubtype (type
, array_die
);
17862 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17864 tree origin
= decl_ultimate_origin (decl
);
17865 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17867 if (origin
!= NULL
)
17868 add_abstract_origin_attribute (decl_die
, origin
);
17871 add_name_and_src_coords_attributes (decl_die
, decl
);
17872 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17873 TYPE_UNQUALIFIED
, context_die
);
17876 if (DECL_ABSTRACT_P (decl
))
17877 equate_decl_number_to_die (decl
, decl_die
);
17879 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17883 /* Walk through the list of incomplete types again, trying once more to
17884 emit full debugging info for them. */
17887 retry_incomplete_types (void)
17891 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17892 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17893 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17896 /* Determine what tag to use for a record type. */
17898 static enum dwarf_tag
17899 record_type_tag (tree type
)
17901 if (! lang_hooks
.types
.classify_record
)
17902 return DW_TAG_structure_type
;
17904 switch (lang_hooks
.types
.classify_record (type
))
17906 case RECORD_IS_STRUCT
:
17907 return DW_TAG_structure_type
;
17909 case RECORD_IS_CLASS
:
17910 return DW_TAG_class_type
;
17912 case RECORD_IS_INTERFACE
:
17913 if (dwarf_version
>= 3 || !dwarf_strict
)
17914 return DW_TAG_interface_type
;
17915 return DW_TAG_structure_type
;
17918 gcc_unreachable ();
17922 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17923 include all of the information about the enumeration values also. Each
17924 enumerated type name/value is listed as a child of the enumerated type
17928 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17930 dw_die_ref type_die
= lookup_type_die (type
);
17932 if (type_die
== NULL
)
17934 type_die
= new_die (DW_TAG_enumeration_type
,
17935 scope_die_for (type
, context_die
), type
);
17936 equate_type_number_to_die (type
, type_die
);
17937 add_name_attribute (type_die
, type_tag (type
));
17938 if (dwarf_version
>= 4 || !dwarf_strict
)
17940 if (ENUM_IS_SCOPED (type
))
17941 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17942 if (ENUM_IS_OPAQUE (type
))
17943 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17946 else if (! TYPE_SIZE (type
))
17949 remove_AT (type_die
, DW_AT_declaration
);
17951 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17952 given enum type is incomplete, do not generate the DW_AT_byte_size
17953 attribute or the DW_AT_element_list attribute. */
17954 if (TYPE_SIZE (type
))
17958 TREE_ASM_WRITTEN (type
) = 1;
17959 add_byte_size_attribute (type_die
, type
);
17960 if (dwarf_version
>= 3 || !dwarf_strict
)
17962 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
17963 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
,
17966 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17968 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17969 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17972 /* If the first reference to this type was as the return type of an
17973 inline function, then it may not have a parent. Fix this now. */
17974 if (type_die
->die_parent
== NULL
)
17975 add_child_die (scope_die_for (type
, context_die
), type_die
);
17977 for (link
= TYPE_VALUES (type
);
17978 link
!= NULL
; link
= TREE_CHAIN (link
))
17980 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17981 tree value
= TREE_VALUE (link
);
17983 add_name_attribute (enum_die
,
17984 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17986 if (TREE_CODE (value
) == CONST_DECL
)
17987 value
= DECL_INITIAL (value
);
17989 if (simple_type_size_in_bits (TREE_TYPE (value
))
17990 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17992 /* For constant forms created by add_AT_unsigned DWARF
17993 consumers (GDB, elfutils, etc.) always zero extend
17994 the value. Only when the actual value is negative
17995 do we need to use add_AT_int to generate a constant
17996 form that can represent negative values. */
17997 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17998 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17999 add_AT_unsigned (enum_die
, DW_AT_const_value
,
18000 (unsigned HOST_WIDE_INT
) val
);
18002 add_AT_int (enum_die
, DW_AT_const_value
, val
);
18005 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
18006 that here. TODO: This should be re-worked to use correct
18007 signed/unsigned double tags for all cases. */
18008 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
18011 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
18012 if (TYPE_ARTIFICIAL (type
))
18013 add_AT_flag (type_die
, DW_AT_artificial
, 1);
18016 add_AT_flag (type_die
, DW_AT_declaration
, 1);
18018 add_pubtype (type
, type_die
);
18023 /* Generate a DIE to represent either a real live formal parameter decl or to
18024 represent just the type of some formal parameter position in some function
18027 Note that this routine is a bit unusual because its argument may be a
18028 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18029 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18030 node. If it's the former then this function is being called to output a
18031 DIE to represent a formal parameter object (or some inlining thereof). If
18032 it's the latter, then this function is only being called to output a
18033 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18034 argument type of some subprogram type.
18035 If EMIT_NAME_P is true, name and source coordinate attributes
18039 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
18040 dw_die_ref context_die
)
18042 tree node_or_origin
= node
? node
: origin
;
18043 tree ultimate_origin
;
18044 dw_die_ref parm_die
= NULL
;
18046 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
18048 parm_die
= lookup_decl_die (node
);
18050 /* If the contexts differ, we may not be talking about the same
18052 if (parm_die
&& parm_die
->die_parent
!= context_die
)
18054 if (!DECL_ABSTRACT_P (node
))
18056 /* This can happen when creating an inlined instance, in
18057 which case we need to create a new DIE that will get
18058 annotated with DW_AT_abstract_origin. */
18063 /* FIXME: Reuse DIE even with a differing context.
18065 This can happen when calling
18066 dwarf2out_abstract_function to build debug info for
18067 the abstract instance of a function for which we have
18068 already generated a DIE in
18069 dwarf2out_early_global_decl.
18071 Once we remove dwarf2out_abstract_function, we should
18072 have a call to gcc_unreachable here. */
18076 if (parm_die
&& parm_die
->die_parent
== NULL
)
18078 /* Check that parm_die already has the right attributes that
18079 we would have added below. If any attributes are
18080 missing, fall through to add them. */
18081 if (! DECL_ABSTRACT_P (node_or_origin
)
18082 && !get_AT (parm_die
, DW_AT_location
)
18083 && !get_AT (parm_die
, DW_AT_const_value
))
18084 /* We are missing location info, and are about to add it. */
18088 add_child_die (context_die
, parm_die
);
18094 /* If we have a previously generated DIE, use it, unless this is an
18095 concrete instance (origin != NULL), in which case we need a new
18096 DIE with a corresponding DW_AT_abstract_origin. */
18098 if (parm_die
&& origin
== NULL
)
18099 reusing_die
= true;
18102 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
18103 reusing_die
= false;
18106 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18108 case tcc_declaration
:
18109 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18110 if (node
|| ultimate_origin
)
18111 origin
= ultimate_origin
;
18116 if (origin
!= NULL
)
18117 add_abstract_origin_attribute (parm_die
, origin
);
18118 else if (emit_name_p
)
18119 add_name_and_src_coords_attributes (parm_die
, node
);
18121 || (! DECL_ABSTRACT_P (node_or_origin
)
18122 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18123 decl_function_context
18124 (node_or_origin
))))
18126 tree type
= TREE_TYPE (node_or_origin
);
18127 if (decl_by_reference_p (node_or_origin
))
18128 add_type_attribute (parm_die
, TREE_TYPE (type
),
18129 TYPE_UNQUALIFIED
, context_die
);
18131 add_type_attribute (parm_die
, type
,
18132 decl_quals (node_or_origin
),
18135 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18136 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18138 if (node
&& node
!= origin
)
18139 equate_decl_number_to_die (node
, parm_die
);
18140 if (! DECL_ABSTRACT_P (node_or_origin
))
18141 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18147 /* We were called with some kind of a ..._TYPE node. */
18148 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
,
18153 gcc_unreachable ();
18159 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18160 children DW_TAG_formal_parameter DIEs representing the arguments of the
18163 PARM_PACK must be a function parameter pack.
18164 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18165 must point to the subsequent arguments of the function PACK_ARG belongs to.
18166 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18167 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18168 following the last one for which a DIE was generated. */
18171 gen_formal_parameter_pack_die (tree parm_pack
,
18173 dw_die_ref subr_die
,
18177 dw_die_ref parm_pack_die
;
18179 gcc_assert (parm_pack
18180 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18183 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18184 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18186 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18188 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18191 gen_formal_parameter_die (arg
, NULL
,
18192 false /* Don't emit name attribute. */,
18197 return parm_pack_die
;
18200 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18201 at the end of an (ANSI prototyped) formal parameters list. */
18204 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18206 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18209 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18210 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18211 parameters as specified in some function type specification (except for
18212 those which appear as part of a function *definition*). */
18215 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18218 tree formal_type
= NULL
;
18219 tree first_parm_type
;
18222 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18224 arg
= DECL_ARGUMENTS (function_or_method_type
);
18225 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18230 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18232 /* Make our first pass over the list of formal parameter types and output a
18233 DW_TAG_formal_parameter DIE for each one. */
18234 for (link
= first_parm_type
; link
; )
18236 dw_die_ref parm_die
;
18238 formal_type
= TREE_VALUE (link
);
18239 if (formal_type
== void_type_node
)
18242 /* Output a (nameless) DIE to represent the formal parameter itself. */
18243 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
18245 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18246 true /* Emit name attribute. */,
18248 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18249 && link
== first_parm_type
)
18251 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18252 if (dwarf_version
>= 3 || !dwarf_strict
)
18253 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18255 else if (arg
&& DECL_ARTIFICIAL (arg
))
18256 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18259 link
= TREE_CHAIN (link
);
18261 arg
= DECL_CHAIN (arg
);
18264 /* If this function type has an ellipsis, add a
18265 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18266 if (formal_type
!= void_type_node
)
18267 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18269 /* Make our second (and final) pass over the list of formal parameter types
18270 and output DIEs to represent those types (as necessary). */
18271 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18272 link
&& TREE_VALUE (link
);
18273 link
= TREE_CHAIN (link
))
18274 gen_type_die (TREE_VALUE (link
), context_die
);
18277 /* We want to generate the DIE for TYPE so that we can generate the
18278 die for MEMBER, which has been defined; we will need to refer back
18279 to the member declaration nested within TYPE. If we're trying to
18280 generate minimal debug info for TYPE, processing TYPE won't do the
18281 trick; we need to attach the member declaration by hand. */
18284 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18286 gen_type_die (type
, context_die
);
18288 /* If we're trying to avoid duplicate debug info, we may not have
18289 emitted the member decl for this function. Emit it now. */
18290 if (TYPE_STUB_DECL (type
)
18291 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18292 && ! lookup_decl_die (member
))
18294 dw_die_ref type_die
;
18295 gcc_assert (!decl_ultimate_origin (member
));
18297 push_decl_scope (type
);
18298 type_die
= lookup_type_die_strip_naming_typedef (type
);
18299 if (TREE_CODE (member
) == FUNCTION_DECL
)
18300 gen_subprogram_die (member
, type_die
);
18301 else if (TREE_CODE (member
) == FIELD_DECL
)
18303 /* Ignore the nameless fields that are used to skip bits but handle
18304 C++ anonymous unions and structs. */
18305 if (DECL_NAME (member
) != NULL_TREE
18306 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18307 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18309 gen_type_die (member_declared_type (member
), type_die
);
18310 gen_field_die (member
, type_die
);
18314 gen_variable_die (member
, NULL_TREE
, type_die
);
18320 /* Forward declare these functions, because they are mutually recursive
18321 with their set_block_* pairing functions. */
18322 static void set_decl_origin_self (tree
);
18323 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
18325 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
18326 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
18327 that it points to the node itself, thus indicating that the node is its
18328 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
18329 the given node is NULL, recursively descend the decl/block tree which
18330 it is the root of, and for each other ..._DECL or BLOCK node contained
18331 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
18332 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
18333 values to point to themselves. */
18336 set_block_origin_self (tree stmt
)
18338 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
18340 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
18345 for (local_decl
= BLOCK_VARS (stmt
);
18346 local_decl
!= NULL_TREE
;
18347 local_decl
= DECL_CHAIN (local_decl
))
18348 /* Do not recurse on nested functions since the inlining status
18349 of parent and child can be different as per the DWARF spec. */
18350 if (TREE_CODE (local_decl
) != FUNCTION_DECL
18351 && !DECL_EXTERNAL (local_decl
))
18352 set_decl_origin_self (local_decl
);
18358 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18359 subblock
!= NULL_TREE
;
18360 subblock
= BLOCK_CHAIN (subblock
))
18361 set_block_origin_self (subblock
); /* Recurse. */
18366 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
18367 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
18368 node to so that it points to the node itself, thus indicating that the
18369 node represents its own (abstract) origin. Additionally, if the
18370 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
18371 the decl/block tree of which the given node is the root of, and for
18372 each other ..._DECL or BLOCK node contained therein whose
18373 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
18374 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
18375 point to themselves. */
18378 set_decl_origin_self (tree decl
)
18380 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
18382 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
18383 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18387 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18388 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
18389 if (DECL_INITIAL (decl
) != NULL_TREE
18390 && DECL_INITIAL (decl
) != error_mark_node
)
18391 set_block_origin_self (DECL_INITIAL (decl
));
18396 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
18397 and if it wasn't 1 before, push it to abstract_vec vector.
18398 For all local decls and all local sub-blocks (recursively) do it
18402 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
18408 if (!BLOCK_ABSTRACT (stmt
))
18410 abstract_vec
.safe_push (stmt
);
18411 BLOCK_ABSTRACT (stmt
) = 1;
18414 for (local_decl
= BLOCK_VARS (stmt
);
18415 local_decl
!= NULL_TREE
;
18416 local_decl
= DECL_CHAIN (local_decl
))
18417 if (! DECL_EXTERNAL (local_decl
))
18418 set_decl_abstract_flags (local_decl
, abstract_vec
);
18420 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18422 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
18423 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
18424 || TREE_CODE (local_decl
) == PARM_DECL
)
18425 set_decl_abstract_flags (local_decl
, abstract_vec
);
18428 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18429 subblock
!= NULL_TREE
;
18430 subblock
= BLOCK_CHAIN (subblock
))
18431 set_block_abstract_flags (subblock
, abstract_vec
);
18434 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
18435 to 1 and if it wasn't 1 before, push to abstract_vec vector.
18436 In the case where the decl is a FUNCTION_DECL also set the abstract
18437 flags for all of the parameters, local vars, local
18438 blocks and sub-blocks (recursively). */
18441 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
18443 if (!DECL_ABSTRACT_P (decl
))
18445 abstract_vec
.safe_push (decl
);
18446 DECL_ABSTRACT_P (decl
) = 1;
18449 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18453 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18454 if (!DECL_ABSTRACT_P (arg
))
18456 abstract_vec
.safe_push (arg
);
18457 DECL_ABSTRACT_P (arg
) = 1;
18459 if (DECL_INITIAL (decl
) != NULL_TREE
18460 && DECL_INITIAL (decl
) != error_mark_node
)
18461 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
18465 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18466 may later generate inlined and/or out-of-line instances of.
18468 FIXME: In the early-dwarf world, this function, and most of the
18469 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
18470 the abstract instance. All we would need to do is annotate
18471 the early DIE with the appropriate DW_AT_inline in late
18472 dwarf (perhaps in gen_inlined_subroutine_die).
18474 However, we can't do this yet, because LTO streaming of DIEs
18475 has not been implemented yet. */
18478 dwarf2out_abstract_function (tree decl
)
18480 dw_die_ref old_die
;
18483 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
18484 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
18485 int old_call_site_count
, old_tail_call_site_count
;
18486 struct call_arg_loc_node
*old_call_arg_locations
;
18488 /* Make sure we have the actual abstract inline, not a clone. */
18489 decl
= DECL_ORIGIN (decl
);
18491 old_die
= lookup_decl_die (decl
);
18492 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18493 /* We've already generated the abstract instance. */
18496 /* We can be called while recursively when seeing block defining inlined subroutine
18497 DIE. Be sure to not clobber the outer location table nor use it or we would
18498 get locations in abstract instantces. */
18499 old_decl_loc_table
= decl_loc_table
;
18500 decl_loc_table
= NULL
;
18501 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
18502 cached_dw_loc_list_table
= NULL
;
18503 old_call_arg_locations
= call_arg_locations
;
18504 call_arg_locations
= NULL
;
18505 old_call_site_count
= call_site_count
;
18506 call_site_count
= -1;
18507 old_tail_call_site_count
= tail_call_site_count
;
18508 tail_call_site_count
= -1;
18510 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18511 we don't get confused by DECL_ABSTRACT_P. */
18512 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18514 context
= decl_class_context (decl
);
18516 gen_type_die_for_member
18517 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18520 /* Pretend we've just finished compiling this function. */
18521 save_fn
= current_function_decl
;
18522 current_function_decl
= decl
;
18524 auto_vec
<tree
, 64> abstract_vec
;
18525 set_decl_abstract_flags (decl
, abstract_vec
);
18526 dwarf2out_decl (decl
);
18529 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
18530 if (TREE_CODE (t
) == BLOCK
)
18531 BLOCK_ABSTRACT (t
) = 0;
18533 DECL_ABSTRACT_P (t
) = 0;
18535 current_function_decl
= save_fn
;
18536 decl_loc_table
= old_decl_loc_table
;
18537 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
18538 call_arg_locations
= old_call_arg_locations
;
18539 call_site_count
= old_call_site_count
;
18540 tail_call_site_count
= old_tail_call_site_count
;
18543 /* Helper function of premark_used_types() which gets called through
18546 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18547 marked as unused by prune_unused_types. */
18550 premark_used_types_helper (tree
const &type
, void *)
18554 die
= lookup_type_die (type
);
18556 die
->die_perennial_p
= 1;
18560 /* Helper function of premark_types_used_by_global_vars which gets called
18561 through htab_traverse.
18563 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18564 marked as unused by prune_unused_types. The DIE of the type is marked
18565 only if the global variable using the type will actually be emitted. */
18568 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
18571 struct types_used_by_vars_entry
*entry
;
18574 entry
= (struct types_used_by_vars_entry
*) *slot
;
18575 gcc_assert (entry
->type
!= NULL
18576 && entry
->var_decl
!= NULL
);
18577 die
= lookup_type_die (entry
->type
);
18580 /* Ask cgraph if the global variable really is to be emitted.
18581 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18582 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
18583 if (node
&& node
->definition
)
18585 die
->die_perennial_p
= 1;
18586 /* Keep the parent DIEs as well. */
18587 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18588 die
->die_perennial_p
= 1;
18594 /* Mark all members of used_types_hash as perennial. */
18597 premark_used_types (struct function
*fun
)
18599 if (fun
&& fun
->used_types_hash
)
18600 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
18603 /* Mark all members of types_used_by_vars_entry as perennial. */
18606 premark_types_used_by_global_vars (void)
18608 if (types_used_by_vars_hash
)
18609 types_used_by_vars_hash
18610 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
18613 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18614 for CA_LOC call arg loc node. */
18617 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18618 struct call_arg_loc_node
*ca_loc
)
18620 dw_die_ref stmt_die
= NULL
, die
;
18621 tree block
= ca_loc
->block
;
18624 && block
!= DECL_INITIAL (decl
)
18625 && TREE_CODE (block
) == BLOCK
)
18627 stmt_die
= BLOCK_DIE (block
);
18630 block
= BLOCK_SUPERCONTEXT (block
);
18632 if (stmt_die
== NULL
)
18633 stmt_die
= subr_die
;
18634 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18635 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18636 if (ca_loc
->tail_call_p
)
18637 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18638 if (ca_loc
->symbol_ref
)
18640 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18642 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18644 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18649 /* Generate a DIE to represent a declared function (either file-scope or
18653 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18655 tree origin
= decl_ultimate_origin (decl
);
18656 dw_die_ref subr_die
;
18657 dw_die_ref old_die
= lookup_decl_die (decl
);
18659 /* This function gets called multiple times for different stages of
18660 the debug process. For example, for func() in this code:
18664 void func() { ... }
18667 ...we get called 4 times. Twice in early debug and twice in
18673 1. Once while generating func() within the namespace. This is
18674 the declaration. The declaration bit below is set, as the
18675 context is the namespace.
18677 A new DIE will be generated with DW_AT_declaration set.
18679 2. Once for func() itself. This is the specification. The
18680 declaration bit below is clear as the context is the CU.
18682 We will use the cached DIE from (1) to create a new DIE with
18683 DW_AT_specification pointing to the declaration in (1).
18685 Late debug via rest_of_handle_final()
18686 -------------------------------------
18688 3. Once generating func() within the namespace. This is also the
18689 declaration, as in (1), but this time we will early exit below
18690 as we have a cached DIE and a declaration needs no additional
18691 annotations (no locations), as the source declaration line
18694 4. Once for func() itself. As in (2), this is the specification,
18695 but this time we will re-use the cached DIE, and just annotate
18696 it with the location information that should now be available.
18698 For something without namespaces, but with abstract instances, we
18699 are also called a multiple times:
18704 Base (); // constructor declaration (1)
18707 Base::Base () { } // constructor specification (2)
18712 1. Once for the Base() constructor by virtue of it being a
18713 member of the Base class. This is done via
18714 rest_of_type_compilation.
18716 This is a declaration, so a new DIE will be created with
18719 2. Once for the Base() constructor definition, but this time
18720 while generating the abstract instance of the base
18721 constructor (__base_ctor) which is being generated via early
18722 debug of reachable functions.
18724 Even though we have a cached version of the declaration (1),
18725 we will create a DW_AT_specification of the declaration DIE
18728 3. Once for the __base_ctor itself, but this time, we generate
18729 an DW_AT_abstract_origin version of the DW_AT_specification in
18732 Late debug via rest_of_handle_final
18733 -----------------------------------
18735 4. One final time for the __base_ctor (which will have a cached
18736 DIE with DW_AT_abstract_origin created in (3). This time,
18737 we will just annotate the location information now
18740 int declaration
= (current_function_decl
!= decl
18741 || class_or_namespace_scope_p (context_die
));
18743 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18745 /* Now that the C++ front end lazily declares artificial member fns, we
18746 might need to retrofit the declaration into its class. */
18747 if (!declaration
&& !origin
&& !old_die
18748 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18749 && !class_or_namespace_scope_p (context_die
)
18750 && debug_info_level
> DINFO_LEVEL_TERSE
)
18751 old_die
= force_decl_die (decl
);
18753 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
18754 if (origin
!= NULL
)
18756 gcc_assert (!declaration
|| local_scope_p (context_die
));
18758 /* Fixup die_parent for the abstract instance of a nested
18759 inline function. */
18760 if (old_die
&& old_die
->die_parent
== NULL
)
18761 add_child_die (context_die
, old_die
);
18763 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
18765 /* If we have a DW_AT_abstract_origin we have a working
18767 subr_die
= old_die
;
18771 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18772 add_abstract_origin_attribute (subr_die
, origin
);
18773 /* This is where the actual code for a cloned function is.
18774 Let's emit linkage name attribute for it. This helps
18775 debuggers to e.g, set breakpoints into
18776 constructors/destructors when the user asks "break
18778 add_linkage_name (subr_die
, decl
);
18781 /* A cached copy, possibly from early dwarf generation. Reuse as
18782 much as possible. */
18785 /* A declaration that has been previously dumped needs no
18786 additional information. */
18790 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18791 /* We can have a normal definition following an inline one in the
18792 case of redefinition of GNU C extern inlines.
18793 It seems reasonable to use AT_specification in this case. */
18794 && !get_AT (old_die
, DW_AT_inline
))
18796 /* Detect and ignore this case, where we are trying to output
18797 something we have already output. */
18798 if (get_AT (old_die
, DW_AT_low_pc
)
18799 || get_AT (old_die
, DW_AT_ranges
))
18802 /* If we have no location information, this must be a
18803 partially generated DIE from early dwarf generation.
18804 Fall through and generate it. */
18807 /* If the definition comes from the same place as the declaration,
18808 maybe use the old DIE. We always want the DIE for this function
18809 that has the *_pc attributes to be under comp_unit_die so the
18810 debugger can find it. We also need to do this for abstract
18811 instances of inlines, since the spec requires the out-of-line copy
18812 to have the same parent. For local class methods, this doesn't
18813 apply; we just use the old DIE. */
18814 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18815 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18816 if ((is_cu_die (old_die
->die_parent
)
18817 /* This condition fixes the inconsistency/ICE with the
18818 following Fortran test (or some derivative thereof) while
18819 building libgfortran:
18823 logical function funky (FLAG)
18828 || (old_die
->die_parent
18829 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
18830 || context_die
== NULL
)
18831 && (DECL_ARTIFICIAL (decl
)
18832 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18833 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18834 == (unsigned) s
.line
))))
18836 subr_die
= old_die
;
18838 /* Clear out the declaration attribute, but leave the
18839 parameters so they can be augmented with location
18840 information later. Unless this was a declaration, in
18841 which case, wipe out the nameless parameters and recreate
18842 them further down. */
18843 if (remove_AT (subr_die
, DW_AT_declaration
))
18846 remove_AT (subr_die
, DW_AT_object_pointer
);
18847 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18850 /* Make a specification pointing to the previously built
18854 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18855 add_AT_specification (subr_die
, old_die
);
18856 add_pubname (decl
, subr_die
);
18857 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18858 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18859 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18860 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18862 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18863 emit the real type on the definition die. */
18864 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18866 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18867 if (die
== auto_die
|| die
== decltype_auto_die
)
18868 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18869 TYPE_UNQUALIFIED
, context_die
);
18873 /* Create a fresh DIE for anything else. */
18876 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18878 if (TREE_PUBLIC (decl
))
18879 add_AT_flag (subr_die
, DW_AT_external
, 1);
18881 add_name_and_src_coords_attributes (subr_die
, decl
);
18882 add_pubname (decl
, subr_die
);
18883 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18885 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18886 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18887 TYPE_UNQUALIFIED
, context_die
);
18890 add_pure_or_virtual_attribute (subr_die
, decl
);
18891 if (DECL_ARTIFICIAL (decl
))
18892 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18894 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
18895 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
18897 add_accessibility_attribute (subr_die
, decl
);
18900 /* Unless we have an existing non-declaration DIE, equate the new
18902 if (!old_die
|| is_declaration_die (old_die
))
18903 equate_decl_number_to_die (decl
, subr_die
);
18907 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18909 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18911 /* If this is an explicit function declaration then generate
18912 a DW_AT_explicit attribute. */
18913 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18914 && (dwarf_version
>= 3 || !dwarf_strict
))
18915 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18917 /* If this is a C++11 deleted special function member then generate
18918 a DW_AT_GNU_deleted attribute. */
18919 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
18920 && (! dwarf_strict
))
18921 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
18924 /* Tag abstract instances with DW_AT_inline. */
18925 else if (DECL_ABSTRACT_P (decl
))
18927 if (DECL_DECLARED_INLINE_P (decl
))
18929 if (cgraph_function_possibly_inlined_p (decl
))
18930 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18932 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18936 if (cgraph_function_possibly_inlined_p (decl
))
18937 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18939 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18942 if (DECL_DECLARED_INLINE_P (decl
)
18943 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18944 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18946 /* For non DECL_EXTERNALs, if range information is available, fill
18947 the DIE with it. */
18948 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
18950 HOST_WIDE_INT cfa_fb_offset
;
18952 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18954 if (!flag_reorder_blocks_and_partition
)
18956 dw_fde_ref fde
= fun
->fde
;
18957 if (fde
->dw_fde_begin
)
18959 /* We have already generated the labels. */
18960 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18961 fde
->dw_fde_end
, false);
18965 /* Create start/end labels and add the range. */
18966 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18967 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18968 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18969 current_function_funcdef_no
);
18970 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18971 current_function_funcdef_no
);
18972 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18976 #if VMS_DEBUGGING_INFO
18977 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18978 Section 2.3 Prologue and Epilogue Attributes:
18979 When a breakpoint is set on entry to a function, it is generally
18980 desirable for execution to be suspended, not on the very first
18981 instruction of the function, but rather at a point after the
18982 function's frame has been set up, after any language defined local
18983 declaration processing has been completed, and before execution of
18984 the first statement of the function begins. Debuggers generally
18985 cannot properly determine where this point is. Similarly for a
18986 breakpoint set on exit from a function. The prologue and epilogue
18987 attributes allow a compiler to communicate the location(s) to use. */
18990 if (fde
->dw_fde_vms_end_prologue
)
18991 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18992 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18994 if (fde
->dw_fde_vms_begin_epilogue
)
18995 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18996 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
19003 /* Generate pubnames entries for the split function code ranges. */
19004 dw_fde_ref fde
= fun
->fde
;
19006 if (fde
->dw_fde_second_begin
)
19008 if (dwarf_version
>= 3 || !dwarf_strict
)
19010 /* We should use ranges for non-contiguous code section
19011 addresses. Use the actual code range for the initial
19012 section, since the HOT/COLD labels might precede an
19013 alignment offset. */
19014 bool range_list_added
= false;
19015 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
19016 fde
->dw_fde_end
, &range_list_added
,
19018 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
19019 fde
->dw_fde_second_end
,
19020 &range_list_added
, false);
19021 if (range_list_added
)
19026 /* There is no real support in DW2 for this .. so we make
19027 a work-around. First, emit the pub name for the segment
19028 containing the function label. Then make and emit a
19029 simplified subprogram DIE for the second segment with the
19030 name pre-fixed by __hot/cold_sect_of_. We use the same
19031 linkage name for the second die so that gdb will find both
19032 sections when given "b foo". */
19033 const char *name
= NULL
;
19034 tree decl_name
= DECL_NAME (decl
);
19035 dw_die_ref seg_die
;
19037 /* Do the 'primary' section. */
19038 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
19039 fde
->dw_fde_end
, false);
19041 /* Build a minimal DIE for the secondary section. */
19042 seg_die
= new_die (DW_TAG_subprogram
,
19043 subr_die
->die_parent
, decl
);
19045 if (TREE_PUBLIC (decl
))
19046 add_AT_flag (seg_die
, DW_AT_external
, 1);
19048 if (decl_name
!= NULL
19049 && IDENTIFIER_POINTER (decl_name
) != NULL
)
19051 name
= dwarf2_name (decl
, 1);
19052 if (! DECL_ARTIFICIAL (decl
))
19053 add_src_coords_attributes (seg_die
, decl
);
19055 add_linkage_name (seg_die
, decl
);
19057 gcc_assert (name
!= NULL
);
19058 add_pure_or_virtual_attribute (seg_die
, decl
);
19059 if (DECL_ARTIFICIAL (decl
))
19060 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
19062 name
= concat ("__second_sect_of_", name
, NULL
);
19063 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
19064 fde
->dw_fde_second_end
, false);
19065 add_name_attribute (seg_die
, name
);
19066 if (want_pubnames ())
19067 add_pubname_string (name
, seg_die
);
19071 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
19075 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
19077 /* We define the "frame base" as the function's CFA. This is more
19078 convenient for several reasons: (1) It's stable across the prologue
19079 and epilogue, which makes it better than just a frame pointer,
19080 (2) With dwarf3, there exists a one-byte encoding that allows us
19081 to reference the .debug_frame data by proxy, but failing that,
19082 (3) We can at least reuse the code inspection and interpretation
19083 code that determines the CFA position at various points in the
19085 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
19087 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
19088 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
19092 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
19093 if (list
->dw_loc_next
)
19094 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
19096 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
19099 /* Compute a displacement from the "steady-state frame pointer" to
19100 the CFA. The former is what all stack slots and argument slots
19101 will reference in the rtl; the latter is what we've told the
19102 debugger about. We'll need to adjust all frame_base references
19103 by this displacement. */
19104 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19106 if (fun
->static_chain_decl
)
19107 add_AT_location_description
19108 (subr_die
, DW_AT_static_link
,
19109 loc_list_from_tree (fun
->static_chain_decl
, 2, NULL
));
19112 /* Generate child dies for template paramaters. */
19113 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19114 gen_generic_params_dies (decl
);
19116 /* Now output descriptions of the arguments for this function. This gets
19117 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19118 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19119 `...' at the end of the formal parameter list. In order to find out if
19120 there was a trailing ellipsis or not, we must instead look at the type
19121 associated with the FUNCTION_DECL. This will be a node of type
19122 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19123 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19124 an ellipsis at the end. */
19126 /* In the case where we are describing a mere function declaration, all we
19127 need to do here (and all we *can* do here) is to describe the *types* of
19128 its formal parameters. */
19129 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19131 else if (declaration
)
19132 gen_formal_types_die (decl
, subr_die
);
19135 /* Generate DIEs to represent all known formal parameters. */
19136 tree parm
= DECL_ARGUMENTS (decl
);
19137 tree generic_decl
= early_dwarf
19138 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
19139 tree generic_decl_parm
= generic_decl
19140 ? DECL_ARGUMENTS (generic_decl
)
19143 /* Now we want to walk the list of parameters of the function and
19144 emit their relevant DIEs.
19146 We consider the case of DECL being an instance of a generic function
19147 as well as it being a normal function.
19149 If DECL is an instance of a generic function we walk the
19150 parameters of the generic function declaration _and_ the parameters of
19151 DECL itself. This is useful because we want to emit specific DIEs for
19152 function parameter packs and those are declared as part of the
19153 generic function declaration. In that particular case,
19154 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19155 That DIE has children DIEs representing the set of arguments
19156 of the pack. Note that the set of pack arguments can be empty.
19157 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19160 Otherwise, we just consider the parameters of DECL. */
19161 while (generic_decl_parm
|| parm
)
19163 if (generic_decl_parm
19164 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19165 gen_formal_parameter_pack_die (generic_decl_parm
,
19168 else if (parm
&& !POINTER_BOUNDS_P (parm
))
19170 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19172 if (parm
== DECL_ARGUMENTS (decl
)
19173 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19175 && (dwarf_version
>= 3 || !dwarf_strict
))
19176 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19178 parm
= DECL_CHAIN (parm
);
19181 parm
= DECL_CHAIN (parm
);
19183 if (generic_decl_parm
)
19184 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19187 /* Decide whether we need an unspecified_parameters DIE at the end.
19188 There are 2 more cases to do this for: 1) the ansi ... declaration -
19189 this is detectable when the end of the arg list is not a
19190 void_type_node 2) an unprototyped function declaration (not a
19191 definition). This just means that we have no info about the
19192 parameters at all. */
19193 if (prototype_p (TREE_TYPE (decl
)))
19195 /* This is the prototyped case, check for.... */
19196 if (stdarg_p (TREE_TYPE (decl
)))
19197 gen_unspecified_parameters_die (decl
, subr_die
);
19199 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19200 gen_unspecified_parameters_die (decl
, subr_die
);
19203 if (subr_die
!= old_die
)
19204 /* Add the calling convention attribute if requested. */
19205 add_calling_convention_attribute (subr_die
, decl
);
19207 /* Output Dwarf info for all of the stuff within the body of the function
19208 (if it has one - it may be just a declaration).
19210 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19211 a function. This BLOCK actually represents the outermost binding contour
19212 for the function, i.e. the contour in which the function's formal
19213 parameters and labels get declared. Curiously, it appears that the front
19214 end doesn't actually put the PARM_DECL nodes for the current function onto
19215 the BLOCK_VARS list for this outer scope, but are strung off of the
19216 DECL_ARGUMENTS list for the function instead.
19218 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19219 the LABEL_DECL nodes for the function however, and we output DWARF info
19220 for those in decls_for_scope. Just within the `outer_scope' there will be
19221 a BLOCK node representing the function's outermost pair of curly braces,
19222 and any blocks used for the base and member initializers of a C++
19223 constructor function. */
19224 tree outer_scope
= DECL_INITIAL (decl
);
19225 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19227 int call_site_note_count
= 0;
19228 int tail_call_site_note_count
= 0;
19230 /* Emit a DW_TAG_variable DIE for a named return value. */
19231 if (DECL_NAME (DECL_RESULT (decl
)))
19232 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19234 /* The first time through decls_for_scope we will generate the
19235 DIEs for the locals. The second time, we fill in the
19237 decls_for_scope (outer_scope
, subr_die
);
19239 if (call_arg_locations
&& !dwarf_strict
)
19241 struct call_arg_loc_node
*ca_loc
;
19242 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
19244 dw_die_ref die
= NULL
;
19245 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
19248 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
19249 arg
; arg
= next_arg
)
19251 dw_loc_descr_ref reg
, val
;
19252 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
19253 dw_die_ref cdie
, tdie
= NULL
;
19255 next_arg
= XEXP (arg
, 1);
19256 if (REG_P (XEXP (XEXP (arg
, 0), 0))
19258 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
19259 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
19260 && REGNO (XEXP (XEXP (arg
, 0), 0))
19261 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
19262 next_arg
= XEXP (next_arg
, 1);
19263 if (mode
== VOIDmode
)
19265 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
19266 if (mode
== VOIDmode
)
19267 mode
= GET_MODE (XEXP (arg
, 0));
19269 if (mode
== VOIDmode
|| mode
== BLKmode
)
19271 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
19273 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19274 tloc
= XEXP (XEXP (arg
, 0), 1);
19277 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
19278 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
19280 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19281 tlocc
= XEXP (XEXP (arg
, 0), 1);
19285 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
19286 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
19287 VAR_INIT_STATUS_INITIALIZED
);
19288 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
19290 rtx mem
= XEXP (XEXP (arg
, 0), 0);
19291 reg
= mem_loc_descriptor (XEXP (mem
, 0),
19292 get_address_mode (mem
),
19294 VAR_INIT_STATUS_INITIALIZED
);
19296 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
19297 == DEBUG_PARAMETER_REF
)
19300 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
19301 tdie
= lookup_decl_die (tdecl
);
19308 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
19309 != DEBUG_PARAMETER_REF
)
19311 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
19313 VAR_INIT_STATUS_INITIALIZED
);
19317 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19318 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
19321 add_AT_loc (cdie
, DW_AT_location
, reg
);
19322 else if (tdie
!= NULL
)
19323 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
19324 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
19325 if (next_arg
!= XEXP (arg
, 1))
19327 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
19328 if (mode
== VOIDmode
)
19329 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
19330 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
19333 VAR_INIT_STATUS_INITIALIZED
);
19335 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
19339 && (ca_loc
->symbol_ref
|| tloc
))
19340 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19341 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
19343 dw_loc_descr_ref tval
= NULL
;
19345 if (tloc
!= NULL_RTX
)
19346 tval
= mem_loc_descriptor (tloc
,
19347 GET_MODE (tloc
) == VOIDmode
19348 ? Pmode
: GET_MODE (tloc
),
19350 VAR_INIT_STATUS_INITIALIZED
);
19352 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
19353 else if (tlocc
!= NULL_RTX
)
19355 tval
= mem_loc_descriptor (tlocc
,
19356 GET_MODE (tlocc
) == VOIDmode
19357 ? Pmode
: GET_MODE (tlocc
),
19359 VAR_INIT_STATUS_INITIALIZED
);
19361 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
19367 call_site_note_count
++;
19368 if (ca_loc
->tail_call_p
)
19369 tail_call_site_note_count
++;
19373 call_arg_locations
= NULL
;
19374 call_arg_loc_last
= NULL
;
19375 if (tail_call_site_count
>= 0
19376 && tail_call_site_count
== tail_call_site_note_count
19379 if (call_site_count
>= 0
19380 && call_site_count
== call_site_note_count
)
19381 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
19383 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
19385 call_site_count
= -1;
19386 tail_call_site_count
= -1;
19390 /* Returns a hash value for X (which really is a die_struct). */
19393 block_die_hasher::hash (die_struct
*d
)
19395 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19398 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19399 as decl_id and die_parent of die_struct Y. */
19402 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
19404 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
19407 /* Return TRUE if DECL, which may have been previously generated as
19408 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
19409 true if decl (or its origin) is either an extern declaration or a
19410 class/namespace scoped declaration.
19412 The declare_in_namespace support causes us to get two DIEs for one
19413 variable, both of which are declarations. We want to avoid
19414 considering one to be a specification, so we must test for
19415 DECLARATION and DW_AT_declaration. */
19417 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
19419 return (old_die
&& TREE_STATIC (decl
) && !declaration
19420 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
19423 /* Return true if DECL is a local static. */
19426 local_function_static (tree decl
)
19428 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
19429 return TREE_STATIC (decl
)
19430 && DECL_CONTEXT (decl
)
19431 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
19434 /* Generate a DIE to represent a declared data object.
19435 Either DECL or ORIGIN must be non-null. */
19438 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19440 HOST_WIDE_INT off
= 0;
19442 tree decl_or_origin
= decl
? decl
: origin
;
19443 tree ultimate_origin
;
19444 dw_die_ref var_die
;
19445 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19446 dw_die_ref origin_die
= NULL
;
19447 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19448 || class_or_namespace_scope_p (context_die
));
19449 bool specialization_p
= false;
19451 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19452 if (decl
|| ultimate_origin
)
19453 origin
= ultimate_origin
;
19454 com_decl
= fortran_common (decl_or_origin
, &off
);
19456 /* Symbol in common gets emitted as a child of the common block, in the form
19457 of a data member. */
19460 dw_die_ref com_die
;
19461 dw_loc_list_ref loc
;
19462 die_node com_die_arg
;
19464 var_die
= lookup_decl_die (decl_or_origin
);
19467 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19469 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
19474 /* Optimize the common case. */
19475 if (single_element_loc_list_p (loc
)
19476 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19477 && loc
->expr
->dw_loc_next
== NULL
19478 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19481 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19482 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19483 = plus_constant (GET_MODE (x
), x
, off
);
19486 loc_list_plus_const (loc
, off
);
19488 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19489 remove_AT (var_die
, DW_AT_declaration
);
19495 if (common_block_die_table
== NULL
)
19496 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
19498 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19499 com_die_arg
.die_parent
= context_die
;
19500 com_die
= common_block_die_table
->find (&com_die_arg
);
19501 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19502 if (com_die
== NULL
)
19505 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19508 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19509 add_name_and_src_coords_attributes (com_die
, com_decl
);
19512 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19513 /* Avoid sharing the same loc descriptor between
19514 DW_TAG_common_block and DW_TAG_variable. */
19515 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19517 else if (DECL_EXTERNAL (decl
))
19518 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19519 if (want_pubnames ())
19520 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19521 com_die
->decl_id
= DECL_UID (com_decl
);
19522 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
19525 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19527 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19528 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19529 remove_AT (com_die
, DW_AT_declaration
);
19531 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19532 add_name_and_src_coords_attributes (var_die
, decl
);
19533 add_type_attribute (var_die
, TREE_TYPE (decl
), decl_quals (decl
),
19535 add_AT_flag (var_die
, DW_AT_external
, 1);
19540 /* Optimize the common case. */
19541 if (single_element_loc_list_p (loc
)
19542 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19543 && loc
->expr
->dw_loc_next
== NULL
19544 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19546 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19547 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19548 = plus_constant (GET_MODE (x
), x
, off
);
19551 loc_list_plus_const (loc
, off
);
19553 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19555 else if (DECL_EXTERNAL (decl
))
19556 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19557 equate_decl_number_to_die (decl
, var_die
);
19565 /* A declaration that has been previously dumped, needs no
19566 further annotations, since it doesn't need location on
19567 the second pass. */
19570 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
19571 && !get_AT (old_die
, DW_AT_specification
))
19573 /* Fall-thru so we can make a new variable die along with a
19574 DW_AT_specification. */
19576 else if (origin
&& old_die
->die_parent
!= context_die
)
19578 /* If we will be creating an inlined instance, we need a
19579 new DIE that will get annotated with
19580 DW_AT_abstract_origin. Clear things so we can get a
19582 gcc_assert (!DECL_ABSTRACT_P (decl
));
19587 /* If a DIE was dumped early, it still needs location info.
19588 Skip to where we fill the location bits. */
19590 goto gen_variable_die_location
;
19594 /* For static data members, the declaration in the class is supposed
19595 to have DW_TAG_member tag; the specification should still be
19596 DW_TAG_variable referencing the DW_TAG_member DIE. */
19597 if (declaration
&& class_scope_p (context_die
))
19598 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19600 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19602 if (origin
!= NULL
)
19603 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19605 /* Loop unrolling can create multiple blocks that refer to the same
19606 static variable, so we must test for the DW_AT_declaration flag.
19608 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19609 copy decls and set the DECL_ABSTRACT_P flag on them instead of
19612 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
19613 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
19615 /* This is a definition of a C++ class level static. */
19616 add_AT_specification (var_die
, old_die
);
19617 specialization_p
= true;
19618 if (DECL_NAME (decl
))
19620 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19621 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19623 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19624 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19626 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19627 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19629 if (old_die
->die_tag
== DW_TAG_member
)
19630 add_linkage_name (var_die
, decl
);
19634 add_name_and_src_coords_attributes (var_die
, decl
);
19636 if ((origin
== NULL
&& !specialization_p
)
19638 && !DECL_ABSTRACT_P (decl_or_origin
)
19639 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19640 decl_function_context
19641 (decl_or_origin
))))
19643 tree type
= TREE_TYPE (decl_or_origin
);
19645 if (decl_by_reference_p (decl_or_origin
))
19646 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19649 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
19653 if (origin
== NULL
&& !specialization_p
)
19655 if (TREE_PUBLIC (decl
))
19656 add_AT_flag (var_die
, DW_AT_external
, 1);
19658 if (DECL_ARTIFICIAL (decl
))
19659 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19661 add_accessibility_attribute (var_die
, decl
);
19665 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19667 if (decl
&& (DECL_ABSTRACT_P (decl
)
19668 || !old_die
|| is_declaration_die (old_die
)))
19669 equate_decl_number_to_die (decl
, var_die
);
19671 gen_variable_die_location
:
19673 && (! DECL_ABSTRACT_P (decl_or_origin
)
19674 /* Local static vars are shared between all clones/inlines,
19675 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19677 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19678 && TREE_STATIC (decl_or_origin
)
19679 && DECL_RTL_SET_P (decl_or_origin
)))
19680 /* When abstract origin already has DW_AT_location attribute, no need
19681 to add it again. */
19682 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19685 add_pubname (decl_or_origin
, var_die
);
19687 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
19691 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19694 /* Generate a DIE to represent a named constant. */
19697 gen_const_die (tree decl
, dw_die_ref context_die
)
19699 dw_die_ref const_die
;
19700 tree type
= TREE_TYPE (decl
);
19702 const_die
= lookup_decl_die (decl
);
19706 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19707 equate_decl_number_to_die (decl
, const_die
);
19708 add_name_and_src_coords_attributes (const_die
, decl
);
19709 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, context_die
);
19710 if (TREE_PUBLIC (decl
))
19711 add_AT_flag (const_die
, DW_AT_external
, 1);
19712 if (DECL_ARTIFICIAL (decl
))
19713 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19714 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19717 /* Generate a DIE to represent a label identifier. */
19720 gen_label_die (tree decl
, dw_die_ref context_die
)
19722 tree origin
= decl_ultimate_origin (decl
);
19723 dw_die_ref lbl_die
= lookup_decl_die (decl
);
19725 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19729 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19730 equate_decl_number_to_die (decl
, lbl_die
);
19732 if (origin
!= NULL
)
19733 add_abstract_origin_attribute (lbl_die
, origin
);
19735 add_name_and_src_coords_attributes (lbl_die
, decl
);
19738 if (DECL_ABSTRACT_P (decl
))
19739 equate_decl_number_to_die (decl
, lbl_die
);
19742 insn
= DECL_RTL_IF_SET (decl
);
19744 /* Deleted labels are programmer specified labels which have been
19745 eliminated because of various optimizations. We still emit them
19746 here so that it is possible to put breakpoints on them. */
19750 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19752 /* When optimization is enabled (via -O) some parts of the compiler
19753 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19754 represent source-level labels which were explicitly declared by
19755 the user. This really shouldn't be happening though, so catch
19756 it if it ever does happen. */
19757 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
19759 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19760 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19764 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19765 && CODE_LABEL_NUMBER (insn
) != -1)
19767 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19768 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19773 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19774 attributes to the DIE for a block STMT, to describe where the inlined
19775 function was called from. This is similar to add_src_coords_attributes. */
19778 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19780 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19782 if (dwarf_version
>= 3 || !dwarf_strict
)
19784 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19785 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19790 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19791 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19794 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19796 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19798 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19799 && (dwarf_version
>= 3 || !dwarf_strict
))
19801 tree chain
, superblock
= NULL_TREE
;
19803 dw_attr_node
*attr
= NULL
;
19805 if (inlined_function_outer_scope_p (stmt
))
19807 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19808 BLOCK_NUMBER (stmt
));
19809 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19812 /* Optimize duplicate .debug_ranges lists or even tails of
19813 lists. If this BLOCK has same ranges as its supercontext,
19814 lookup DW_AT_ranges attribute in the supercontext (and
19815 recursively so), verify that the ranges_table contains the
19816 right values and use it instead of adding a new .debug_range. */
19817 for (chain
= stmt
, pdie
= die
;
19818 BLOCK_SAME_RANGE (chain
);
19819 chain
= BLOCK_SUPERCONTEXT (chain
))
19821 dw_attr_node
*new_attr
;
19823 pdie
= pdie
->die_parent
;
19826 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19828 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19829 if (new_attr
== NULL
19830 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19833 superblock
= BLOCK_SUPERCONTEXT (chain
);
19836 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19837 / 2 / DWARF2_ADDR_SIZE
].num
19838 == BLOCK_NUMBER (superblock
))
19839 && BLOCK_FRAGMENT_CHAIN (superblock
))
19841 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19842 / 2 / DWARF2_ADDR_SIZE
;
19843 unsigned long supercnt
= 0, thiscnt
= 0;
19844 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19845 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19848 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19849 == BLOCK_NUMBER (chain
));
19851 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19852 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19853 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19855 gcc_assert (supercnt
>= thiscnt
);
19856 add_AT_range_list (die
, DW_AT_ranges
,
19857 ((off
+ supercnt
- thiscnt
)
19858 * 2 * DWARF2_ADDR_SIZE
),
19863 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19865 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19868 add_ranges (chain
);
19869 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19876 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19877 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19878 BLOCK_NUMBER (stmt
));
19879 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19880 BLOCK_NUMBER (stmt
));
19881 add_AT_low_high_pc (die
, label
, label_high
, false);
19885 /* Generate a DIE for a lexical block. */
19888 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
19890 dw_die_ref old_die
= BLOCK_DIE (stmt
);
19891 dw_die_ref stmt_die
= NULL
;
19894 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19895 BLOCK_DIE (stmt
) = stmt_die
;
19898 if (BLOCK_ABSTRACT (stmt
))
19902 /* This must have been generated early and it won't even
19903 need location information since it's a DW_AT_inline
19906 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
19907 if (c
->die_tag
== DW_TAG_inlined_subroutine
19908 || c
->die_tag
== DW_TAG_subprogram
)
19910 gcc_assert (get_AT (c
, DW_AT_inline
));
19916 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
19918 /* If this is an inlined instance, create a new lexical die for
19919 anything below to attach DW_AT_abstract_origin to. */
19922 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19923 BLOCK_DIE (stmt
) = stmt_die
;
19929 stmt_die
= old_die
;
19931 /* A non abstract block whose blocks have already been reordered
19932 should have the instruction range for this block. If so, set the
19933 high/low attributes. */
19934 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19936 gcc_assert (stmt_die
);
19937 add_high_low_attributes (stmt
, stmt_die
);
19940 decls_for_scope (stmt
, stmt_die
);
19943 /* Generate a DIE for an inlined subprogram. */
19946 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
19950 /* The instance of function that is effectively being inlined shall not
19952 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19954 decl
= block_ultimate_origin (stmt
);
19956 /* Make sure any inlined functions are known to be inlineable. */
19957 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
19958 || cgraph_function_possibly_inlined_p (decl
));
19960 /* Emit info for the abstract instance first, if we haven't yet. We
19961 must emit this even if the block is abstract, otherwise when we
19962 emit the block below (or elsewhere), we may end up trying to emit
19963 a die whose origin die hasn't been emitted, and crashing. */
19964 dwarf2out_abstract_function (decl
);
19966 if (! BLOCK_ABSTRACT (stmt
))
19968 dw_die_ref subr_die
19969 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19971 if (call_arg_locations
)
19972 BLOCK_DIE (stmt
) = subr_die
;
19973 add_abstract_origin_attribute (subr_die
, decl
);
19974 if (TREE_ASM_WRITTEN (stmt
))
19975 add_high_low_attributes (stmt
, subr_die
);
19976 add_call_src_coords_attributes (stmt
, subr_die
);
19978 decls_for_scope (stmt
, subr_die
);
19982 /* Generate a DIE for a field in a record, or structure. */
19985 gen_field_die (tree decl
, dw_die_ref context_die
)
19987 dw_die_ref decl_die
;
19989 if (TREE_TYPE (decl
) == error_mark_node
)
19992 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19993 add_name_and_src_coords_attributes (decl_die
, decl
);
19994 add_type_attribute (decl_die
, member_declared_type (decl
),
19995 decl_quals (decl
), context_die
);
19997 if (DECL_BIT_FIELD_TYPE (decl
))
19999 add_byte_size_attribute (decl_die
, decl
);
20000 add_bit_size_attribute (decl_die
, decl
);
20001 add_bit_offset_attribute (decl_die
, decl
);
20004 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
20005 add_data_member_location_attribute (decl_die
, decl
);
20007 if (DECL_ARTIFICIAL (decl
))
20008 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
20010 add_accessibility_attribute (decl_die
, decl
);
20012 /* Equate decl number to die, so that we can look up this decl later on. */
20013 equate_decl_number_to_die (decl
, decl_die
);
20017 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20018 Use modified_type_die instead.
20019 We keep this code here just in case these types of DIEs may be needed to
20020 represent certain things in other languages (e.g. Pascal) someday. */
20023 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
20026 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
20028 equate_type_number_to_die (type
, ptr_die
);
20029 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20031 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20034 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20035 Use modified_type_die instead.
20036 We keep this code here just in case these types of DIEs may be needed to
20037 represent certain things in other languages (e.g. Pascal) someday. */
20040 gen_reference_type_die (tree type
, dw_die_ref context_die
)
20042 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
20044 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
20045 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
20047 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
20049 equate_type_number_to_die (type
, ref_die
);
20050 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20052 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20056 /* Generate a DIE for a pointer to a member type. */
20059 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
20062 = new_die (DW_TAG_ptr_to_member_type
,
20063 scope_die_for (type
, context_die
), type
);
20065 equate_type_number_to_die (type
, ptr_die
);
20066 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
20067 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
20068 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20072 static char *producer_string
;
20074 /* Return a heap allocated producer string including command line options
20075 if -grecord-gcc-switches. */
20078 gen_producer_string (void)
20081 auto_vec
<const char *> switches
;
20082 const char *language_string
= lang_hooks
.name
;
20083 char *producer
, *tail
;
20085 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
20086 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
20088 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
20089 switch (save_decoded_options
[j
].opt_index
)
20096 case OPT_auxbase_strip
:
20105 case OPT_SPECIAL_unknown
:
20106 case OPT_SPECIAL_ignore
:
20107 case OPT_SPECIAL_program_name
:
20108 case OPT_SPECIAL_input_file
:
20109 case OPT_grecord_gcc_switches
:
20110 case OPT_gno_record_gcc_switches
:
20111 case OPT__output_pch_
:
20112 case OPT_fdiagnostics_show_location_
:
20113 case OPT_fdiagnostics_show_option
:
20114 case OPT_fdiagnostics_show_caret
:
20115 case OPT_fdiagnostics_color_
:
20116 case OPT_fverbose_asm
:
20118 case OPT__sysroot_
:
20120 case OPT_nostdinc__
:
20121 case OPT_fpreprocessed
:
20122 case OPT_fltrans_output_list_
:
20123 case OPT_fresolution_
:
20124 /* Ignore these. */
20127 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
20128 & CL_NO_DWARF_RECORD
)
20130 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
20132 switch (save_decoded_options
[j
].canonical_option
[0][1])
20139 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
20146 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
20147 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
20151 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
20153 sprintf (tail
, "%s %s", language_string
, version_string
);
20156 FOR_EACH_VEC_ELT (switches
, j
, p
)
20160 memcpy (tail
+ 1, p
, len
);
20168 /* Given a C and/or C++ language/version string return the "highest".
20169 C++ is assumed to be "higher" than C in this case. Used for merging
20170 LTO translation unit languages. */
20171 static const char *
20172 highest_c_language (const char *lang1
, const char *lang2
)
20174 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
20175 return "GNU C++14";
20176 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
20177 return "GNU C++11";
20178 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
20179 return "GNU C++98";
20181 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
20183 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
20185 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
20188 gcc_unreachable ();
20192 /* Generate the DIE for the compilation unit. */
20195 gen_compile_unit_die (const char *filename
)
20198 const char *language_string
= lang_hooks
.name
;
20201 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
20205 add_name_attribute (die
, filename
);
20206 /* Don't add cwd for <built-in>. */
20207 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
20208 add_comp_dir_attribute (die
);
20211 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
20213 /* If our producer is LTO try to figure out a common language to use
20214 from the global list of translation units. */
20215 if (strcmp (language_string
, "GNU GIMPLE") == 0)
20219 const char *common_lang
= NULL
;
20221 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
20223 if (!TRANSLATION_UNIT_LANGUAGE (t
))
20226 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
20227 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
20229 else if (strncmp (common_lang
, "GNU C", 5) == 0
20230 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
20231 /* Mixing C and C++ is ok, use C++ in that case. */
20232 common_lang
= highest_c_language (common_lang
,
20233 TRANSLATION_UNIT_LANGUAGE (t
));
20236 /* Fall back to C. */
20237 common_lang
= NULL
;
20243 language_string
= common_lang
;
20246 language
= DW_LANG_C
;
20247 if (strncmp (language_string
, "GNU C", 5) == 0
20248 && ISDIGIT (language_string
[5]))
20250 language
= DW_LANG_C89
;
20251 if (dwarf_version
>= 3 || !dwarf_strict
)
20253 if (strcmp (language_string
, "GNU C89") != 0)
20254 language
= DW_LANG_C99
;
20256 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20257 if (strcmp (language_string
, "GNU C11") == 0)
20258 language
= DW_LANG_C11
;
20261 else if (strncmp (language_string
, "GNU C++", 7) == 0)
20263 language
= DW_LANG_C_plus_plus
;
20264 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20266 if (strcmp (language_string
, "GNU C++11") == 0)
20267 language
= DW_LANG_C_plus_plus_11
;
20268 else if (strcmp (language_string
, "GNU C++14") == 0)
20269 language
= DW_LANG_C_plus_plus_14
;
20272 else if (strcmp (language_string
, "GNU F77") == 0)
20273 language
= DW_LANG_Fortran77
;
20274 else if (strcmp (language_string
, "GNU Pascal") == 0)
20275 language
= DW_LANG_Pascal83
;
20276 else if (dwarf_version
>= 3 || !dwarf_strict
)
20278 if (strcmp (language_string
, "GNU Ada") == 0)
20279 language
= DW_LANG_Ada95
;
20280 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20282 language
= DW_LANG_Fortran95
;
20283 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20285 if (strcmp (language_string
, "GNU Fortran2003") == 0)
20286 language
= DW_LANG_Fortran03
;
20287 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
20288 language
= DW_LANG_Fortran08
;
20291 else if (strcmp (language_string
, "GNU Java") == 0)
20292 language
= DW_LANG_Java
;
20293 else if (strcmp (language_string
, "GNU Objective-C") == 0)
20294 language
= DW_LANG_ObjC
;
20295 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
20296 language
= DW_LANG_ObjC_plus_plus
;
20297 else if (dwarf_version
>= 5 || !dwarf_strict
)
20299 if (strcmp (language_string
, "GNU Go") == 0)
20300 language
= DW_LANG_Go
;
20303 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
20304 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20305 language
= DW_LANG_Fortran90
;
20307 add_AT_unsigned (die
, DW_AT_language
, language
);
20311 case DW_LANG_Fortran77
:
20312 case DW_LANG_Fortran90
:
20313 case DW_LANG_Fortran95
:
20314 case DW_LANG_Fortran03
:
20315 case DW_LANG_Fortran08
:
20316 /* Fortran has case insensitive identifiers and the front-end
20317 lowercases everything. */
20318 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
20321 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20327 /* Generate the DIE for a base class. */
20330 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
20332 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
20334 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, context_die
);
20335 add_data_member_location_attribute (die
, binfo
);
20337 if (BINFO_VIRTUAL_P (binfo
))
20338 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20340 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20341 children, otherwise the default is DW_ACCESS_public. In DWARF2
20342 the default has always been DW_ACCESS_private. */
20343 if (access
== access_public_node
)
20345 if (dwarf_version
== 2
20346 || context_die
->die_tag
== DW_TAG_class_type
)
20347 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20349 else if (access
== access_protected_node
)
20350 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20351 else if (dwarf_version
> 2
20352 && context_die
->die_tag
!= DW_TAG_class_type
)
20353 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20356 /* Generate a DIE for a class member. */
20359 gen_member_die (tree type
, dw_die_ref context_die
)
20362 tree binfo
= TYPE_BINFO (type
);
20365 /* If this is not an incomplete type, output descriptions of each of its
20366 members. Note that as we output the DIEs necessary to represent the
20367 members of this record or union type, we will also be trying to output
20368 DIEs to represent the *types* of those members. However the `type'
20369 function (above) will specifically avoid generating type DIEs for member
20370 types *within* the list of member DIEs for this (containing) type except
20371 for those types (of members) which are explicitly marked as also being
20372 members of this (containing) type themselves. The g++ front- end can
20373 force any given type to be treated as a member of some other (containing)
20374 type by setting the TYPE_CONTEXT of the given (member) type to point to
20375 the TREE node representing the appropriate (containing) type. */
20377 /* First output info about the base classes. */
20380 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
20384 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
20385 gen_inheritance_die (base
,
20386 (accesses
? (*accesses
)[i
] : access_public_node
),
20390 /* Now output info about the data members and type members. */
20391 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
20393 /* If we thought we were generating minimal debug info for TYPE
20394 and then changed our minds, some of the member declarations
20395 may have already been defined. Don't define them again, but
20396 do put them in the right order. */
20398 child
= lookup_decl_die (member
);
20400 splice_child_die (context_die
, child
);
20402 gen_decl_die (member
, NULL
, context_die
);
20405 /* We do not keep type methods in type variants. */
20406 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
20407 /* Now output info about the function members (if any). */
20408 if (TYPE_METHODS (type
) != error_mark_node
)
20409 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
20411 /* Don't include clones in the member list. */
20412 if (DECL_ABSTRACT_ORIGIN (member
))
20414 /* Nor constructors for anonymous classes. */
20415 if (DECL_ARTIFICIAL (member
)
20416 && dwarf2_name (member
, 0) == NULL
)
20419 child
= lookup_decl_die (member
);
20421 splice_child_die (context_die
, child
);
20423 gen_decl_die (member
, NULL
, context_die
);
20427 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20428 is set, we pretend that the type was never defined, so we only get the
20429 member DIEs needed by later specification DIEs. */
20432 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
20433 enum debug_info_usage usage
)
20435 if (TREE_ASM_WRITTEN (type
))
20437 /* Fill in the bound of variable-length fields in late dwarf if
20438 still incomplete. */
20439 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
20440 for (tree member
= TYPE_FIELDS (type
);
20442 member
= DECL_CHAIN (member
))
20443 fill_variable_array_bounds (TREE_TYPE (member
));
20447 dw_die_ref type_die
= lookup_type_die (type
);
20448 dw_die_ref scope_die
= 0;
20450 int complete
= (TYPE_SIZE (type
)
20451 && (! TYPE_STUB_DECL (type
)
20452 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
20453 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
20454 complete
= complete
&& should_emit_struct_debug (type
, usage
);
20456 if (type_die
&& ! complete
)
20459 if (TYPE_CONTEXT (type
) != NULL_TREE
20460 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20461 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
20464 scope_die
= scope_die_for (type
, context_die
);
20466 /* Generate child dies for template paramaters. */
20467 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20468 schedule_generic_params_dies_gen (type
);
20470 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
20471 /* First occurrence of type or toplevel definition of nested class. */
20473 dw_die_ref old_die
= type_die
;
20475 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
20476 ? record_type_tag (type
) : DW_TAG_union_type
,
20478 equate_type_number_to_die (type
, type_die
);
20480 add_AT_specification (type_die
, old_die
);
20482 add_name_attribute (type_die
, type_tag (type
));
20485 remove_AT (type_die
, DW_AT_declaration
);
20487 /* If this type has been completed, then give it a byte_size attribute and
20488 then give a list of members. */
20489 if (complete
&& !ns_decl
)
20491 /* Prevent infinite recursion in cases where the type of some member of
20492 this type is expressed in terms of this type itself. */
20493 TREE_ASM_WRITTEN (type
) = 1;
20494 add_byte_size_attribute (type_die
, type
);
20495 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20497 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20498 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20501 /* If the first reference to this type was as the return type of an
20502 inline function, then it may not have a parent. Fix this now. */
20503 if (type_die
->die_parent
== NULL
)
20504 add_child_die (scope_die
, type_die
);
20506 push_decl_scope (type
);
20507 gen_member_die (type
, type_die
);
20510 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
20511 if (TYPE_ARTIFICIAL (type
))
20512 add_AT_flag (type_die
, DW_AT_artificial
, 1);
20514 /* GNU extension: Record what type our vtable lives in. */
20515 if (TYPE_VFIELD (type
))
20517 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
20519 gen_type_die (vtype
, context_die
);
20520 add_AT_die_ref (type_die
, DW_AT_containing_type
,
20521 lookup_type_die (vtype
));
20526 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20528 /* We don't need to do this for function-local types. */
20529 if (TYPE_STUB_DECL (type
)
20530 && ! decl_function_context (TYPE_STUB_DECL (type
)))
20531 vec_safe_push (incomplete_types
, type
);
20534 if (get_AT (type_die
, DW_AT_name
))
20535 add_pubtype (type
, type_die
);
20538 /* Generate a DIE for a subroutine _type_. */
20541 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
20543 tree return_type
= TREE_TYPE (type
);
20544 dw_die_ref subr_die
20545 = new_die (DW_TAG_subroutine_type
,
20546 scope_die_for (type
, context_die
), type
);
20548 equate_type_number_to_die (type
, subr_die
);
20549 add_prototyped_attribute (subr_die
, type
);
20550 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, context_die
);
20551 gen_formal_types_die (type
, subr_die
);
20553 if (get_AT (subr_die
, DW_AT_name
))
20554 add_pubtype (type
, subr_die
);
20557 /* Generate a DIE for a type definition. */
20560 gen_typedef_die (tree decl
, dw_die_ref context_die
)
20562 dw_die_ref type_die
;
20565 if (TREE_ASM_WRITTEN (decl
))
20567 if (DECL_ORIGINAL_TYPE (decl
))
20568 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
20572 TREE_ASM_WRITTEN (decl
) = 1;
20573 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
20574 origin
= decl_ultimate_origin (decl
);
20575 if (origin
!= NULL
)
20576 add_abstract_origin_attribute (type_die
, origin
);
20581 add_name_and_src_coords_attributes (type_die
, decl
);
20582 if (DECL_ORIGINAL_TYPE (decl
))
20584 type
= DECL_ORIGINAL_TYPE (decl
);
20586 if (type
== error_mark_node
)
20589 gcc_assert (type
!= TREE_TYPE (decl
));
20590 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
20594 type
= TREE_TYPE (decl
);
20596 if (type
== error_mark_node
)
20599 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20601 /* Here, we are in the case of decl being a typedef naming
20602 an anonymous type, e.g:
20603 typedef struct {...} foo;
20604 In that case TREE_TYPE (decl) is not a typedef variant
20605 type and TYPE_NAME of the anonymous type is set to the
20606 TYPE_DECL of the typedef. This construct is emitted by
20609 TYPE is the anonymous struct named by the typedef
20610 DECL. As we need the DW_AT_type attribute of the
20611 DW_TAG_typedef to point to the DIE of TYPE, let's
20612 generate that DIE right away. add_type_attribute
20613 called below will then pick (via lookup_type_die) that
20614 anonymous struct DIE. */
20615 if (!TREE_ASM_WRITTEN (type
))
20616 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20618 /* This is a GNU Extension. We are adding a
20619 DW_AT_linkage_name attribute to the DIE of the
20620 anonymous struct TYPE. The value of that attribute
20621 is the name of the typedef decl naming the anonymous
20622 struct. This greatly eases the work of consumers of
20623 this debug info. */
20624 add_linkage_attr (lookup_type_die (type
), decl
);
20628 add_type_attribute (type_die
, type
, decl_quals (decl
), context_die
);
20630 if (is_naming_typedef_decl (decl
))
20631 /* We want that all subsequent calls to lookup_type_die with
20632 TYPE in argument yield the DW_TAG_typedef we have just
20634 equate_type_number_to_die (type
, type_die
);
20636 add_accessibility_attribute (type_die
, decl
);
20639 if (DECL_ABSTRACT_P (decl
))
20640 equate_decl_number_to_die (decl
, type_die
);
20642 if (get_AT (type_die
, DW_AT_name
))
20643 add_pubtype (decl
, type_die
);
20646 /* Generate a DIE for a struct, class, enum or union type. */
20649 gen_tagged_type_die (tree type
,
20650 dw_die_ref context_die
,
20651 enum debug_info_usage usage
)
20655 if (type
== NULL_TREE
20656 || !is_tagged_type (type
))
20659 if (TREE_ASM_WRITTEN (type
))
20661 /* If this is a nested type whose containing class hasn't been written
20662 out yet, writing it out will cover this one, too. This does not apply
20663 to instantiations of member class templates; they need to be added to
20664 the containing class as they are generated. FIXME: This hurts the
20665 idea of combining type decls from multiple TUs, since we can't predict
20666 what set of template instantiations we'll get. */
20667 else if (TYPE_CONTEXT (type
)
20668 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20669 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20671 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20673 if (TREE_ASM_WRITTEN (type
))
20676 /* If that failed, attach ourselves to the stub. */
20677 push_decl_scope (TYPE_CONTEXT (type
));
20678 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20681 else if (TYPE_CONTEXT (type
) != NULL_TREE
20682 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20684 /* If this type is local to a function that hasn't been written
20685 out yet, use a NULL context for now; it will be fixed up in
20686 decls_for_scope. */
20687 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20688 /* A declaration DIE doesn't count; nested types need to go in the
20690 if (context_die
&& is_declaration_die (context_die
))
20691 context_die
= NULL
;
20696 context_die
= declare_in_namespace (type
, context_die
);
20700 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20702 /* This might have been written out by the call to
20703 declare_in_namespace. */
20704 if (!TREE_ASM_WRITTEN (type
))
20705 gen_enumeration_type_die (type
, context_die
);
20708 gen_struct_or_union_type_die (type
, context_die
, usage
);
20713 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20714 it up if it is ever completed. gen_*_type_die will set it for us
20715 when appropriate. */
20718 /* Generate a type description DIE. */
20721 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20722 enum debug_info_usage usage
)
20724 struct array_descr_info info
;
20726 if (type
== NULL_TREE
|| type
== error_mark_node
)
20729 if (flag_checking
&& type
)
20730 verify_type (type
);
20732 if (TYPE_NAME (type
) != NULL_TREE
20733 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20734 && is_redundant_typedef (TYPE_NAME (type
))
20735 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
20736 /* The DECL of this type is a typedef we don't want to emit debug
20737 info for but we want debug info for its underlying typedef.
20738 This can happen for e.g, the injected-class-name of a C++
20740 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
20742 /* If TYPE is a typedef type variant, let's generate debug info
20743 for the parent typedef which TYPE is a type of. */
20744 if (typedef_variant_p (type
))
20746 if (TREE_ASM_WRITTEN (type
))
20749 /* Prevent broken recursion; we can't hand off to the same type. */
20750 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20752 /* Give typedefs the right scope. */
20753 context_die
= scope_die_for (type
, context_die
);
20755 TREE_ASM_WRITTEN (type
) = 1;
20757 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20761 /* If type is an anonymous tagged type named by a typedef, let's
20762 generate debug info for the typedef. */
20763 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20765 /* Use the DIE of the containing namespace as the parent DIE of
20766 the type description DIE we want to generate. */
20767 if (DECL_CONTEXT (TYPE_NAME (type
))
20768 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20769 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20771 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20775 /* We are going to output a DIE to represent the unqualified version
20776 of this type (i.e. without any const or volatile qualifiers) so
20777 get the main variant (i.e. the unqualified version) of this type
20778 now. (Vectors are special because the debugging info is in the
20779 cloned type itself). */
20780 if (TREE_CODE (type
) != VECTOR_TYPE
)
20781 type
= type_main_variant (type
);
20783 /* If this is an array type with hidden descriptor, handle it first. */
20784 if (!TREE_ASM_WRITTEN (type
)
20785 && lang_hooks
.types
.get_array_descr_info
)
20787 memset (&info
, 0, sizeof (info
));
20788 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
20790 gen_descr_array_type_die (type
, &info
, context_die
);
20791 TREE_ASM_WRITTEN (type
) = 1;
20796 if (TREE_ASM_WRITTEN (type
))
20798 /* Variable-length types may be incomplete even if
20799 TREE_ASM_WRITTEN. For such types, fall through to
20800 gen_array_type_die() and possibly fill in
20801 DW_AT_{upper,lower}_bound attributes. */
20802 if ((TREE_CODE (type
) != ARRAY_TYPE
20803 && TREE_CODE (type
) != RECORD_TYPE
20804 && TREE_CODE (type
) != UNION_TYPE
20805 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
20806 || !variably_modified_type_p (type
, NULL
))
20810 switch (TREE_CODE (type
))
20816 case REFERENCE_TYPE
:
20817 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20818 ensures that the gen_type_die recursion will terminate even if the
20819 type is recursive. Recursive types are possible in Ada. */
20820 /* ??? We could perhaps do this for all types before the switch
20822 TREE_ASM_WRITTEN (type
) = 1;
20824 /* For these types, all that is required is that we output a DIE (or a
20825 set of DIEs) to represent the "basis" type. */
20826 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20827 DINFO_USAGE_IND_USE
);
20831 /* This code is used for C++ pointer-to-data-member types.
20832 Output a description of the relevant class type. */
20833 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20834 DINFO_USAGE_IND_USE
);
20836 /* Output a description of the type of the object pointed to. */
20837 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20838 DINFO_USAGE_IND_USE
);
20840 /* Now output a DIE to represent this pointer-to-data-member type
20842 gen_ptr_to_mbr_type_die (type
, context_die
);
20845 case FUNCTION_TYPE
:
20846 /* Force out return type (in case it wasn't forced out already). */
20847 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20848 DINFO_USAGE_DIR_USE
);
20849 gen_subroutine_type_die (type
, context_die
);
20853 /* Force out return type (in case it wasn't forced out already). */
20854 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20855 DINFO_USAGE_DIR_USE
);
20856 gen_subroutine_type_die (type
, context_die
);
20861 gen_array_type_die (type
, context_die
);
20864 case ENUMERAL_TYPE
:
20867 case QUAL_UNION_TYPE
:
20868 gen_tagged_type_die (type
, context_die
, usage
);
20874 case FIXED_POINT_TYPE
:
20877 case POINTER_BOUNDS_TYPE
:
20878 /* No DIEs needed for fundamental types. */
20883 /* Just use DW_TAG_unspecified_type. */
20885 dw_die_ref type_die
= lookup_type_die (type
);
20886 if (type_die
== NULL
)
20888 tree name
= TYPE_IDENTIFIER (type
);
20889 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
20891 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20892 equate_type_number_to_die (type
, type_die
);
20898 if (is_cxx_auto (type
))
20900 tree name
= TYPE_IDENTIFIER (type
);
20901 dw_die_ref
*die
= (name
== get_identifier ("auto")
20902 ? &auto_die
: &decltype_auto_die
);
20905 *die
= new_die (DW_TAG_unspecified_type
,
20906 comp_unit_die (), NULL_TREE
);
20907 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20909 equate_type_number_to_die (type
, *die
);
20912 gcc_unreachable ();
20915 TREE_ASM_WRITTEN (type
) = 1;
20919 gen_type_die (tree type
, dw_die_ref context_die
)
20921 if (type
!= error_mark_node
)
20923 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20926 dw_die_ref die
= lookup_type_die (type
);
20933 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20934 things which are local to the given block. */
20937 gen_block_die (tree stmt
, dw_die_ref context_die
)
20939 int must_output_die
= 0;
20942 /* Ignore blocks that are NULL. */
20943 if (stmt
== NULL_TREE
)
20946 inlined_func
= inlined_function_outer_scope_p (stmt
);
20948 /* If the block is one fragment of a non-contiguous block, do not
20949 process the variables, since they will have been done by the
20950 origin block. Do process subblocks. */
20951 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20955 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20956 gen_block_die (sub
, context_die
);
20961 /* Determine if we need to output any Dwarf DIEs at all to represent this
20964 /* The outer scopes for inlinings *must* always be represented. We
20965 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20966 must_output_die
= 1;
20969 /* Determine if this block directly contains any "significant"
20970 local declarations which we will need to output DIEs for. */
20971 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20972 /* We are not in terse mode so *any* local declaration counts
20973 as being a "significant" one. */
20974 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20975 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20976 && (TREE_USED (stmt
)
20977 || TREE_ASM_WRITTEN (stmt
)
20978 || BLOCK_ABSTRACT (stmt
)));
20979 else if ((TREE_USED (stmt
)
20980 || TREE_ASM_WRITTEN (stmt
)
20981 || BLOCK_ABSTRACT (stmt
))
20982 && !dwarf2out_ignore_block (stmt
))
20983 must_output_die
= 1;
20986 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20987 DIE for any block which contains no significant local declarations at
20988 all. Rather, in such cases we just call `decls_for_scope' so that any
20989 needed Dwarf info for any sub-blocks will get properly generated. Note
20990 that in terse mode, our definition of what constitutes a "significant"
20991 local declaration gets restricted to include only inlined function
20992 instances and local (nested) function definitions. */
20993 if (must_output_die
)
20997 /* If STMT block is abstract, that means we have been called
20998 indirectly from dwarf2out_abstract_function.
20999 That function rightfully marks the descendent blocks (of
21000 the abstract function it is dealing with) as being abstract,
21001 precisely to prevent us from emitting any
21002 DW_TAG_inlined_subroutine DIE as a descendent
21003 of an abstract function instance. So in that case, we should
21004 not call gen_inlined_subroutine_die.
21006 Later though, when cgraph asks dwarf2out to emit info
21007 for the concrete instance of the function decl into which
21008 the concrete instance of STMT got inlined, the later will lead
21009 to the generation of a DW_TAG_inlined_subroutine DIE. */
21010 if (! BLOCK_ABSTRACT (stmt
))
21011 gen_inlined_subroutine_die (stmt
, context_die
);
21014 gen_lexical_block_die (stmt
, context_die
);
21017 decls_for_scope (stmt
, context_die
);
21020 /* Process variable DECL (or variable with origin ORIGIN) within
21021 block STMT and add it to CONTEXT_DIE. */
21023 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
21026 tree decl_or_origin
= decl
? decl
: origin
;
21028 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
21029 die
= lookup_decl_die (decl_or_origin
);
21030 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
21031 && TYPE_DECL_IS_STUB (decl_or_origin
))
21032 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
21036 if (die
!= NULL
&& die
->die_parent
== NULL
)
21037 add_child_die (context_die
, die
);
21038 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
21041 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
21042 stmt
, context_die
);
21045 gen_decl_die (decl
, origin
, context_die
);
21048 /* Generate all of the decls declared within a given scope and (recursively)
21049 all of its sub-blocks. */
21052 decls_for_scope (tree stmt
, dw_die_ref context_die
)
21058 /* Ignore NULL blocks. */
21059 if (stmt
== NULL_TREE
)
21062 /* Output the DIEs to represent all of the data objects and typedefs
21063 declared directly within this block but not within any nested
21064 sub-blocks. Also, nested function and tag DIEs have been
21065 generated with a parent of NULL; fix that up now. We don't
21066 have to do this if we're at -g1. */
21067 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21069 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
21070 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
21071 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21072 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
21076 /* Even if we're at -g1, we need to process the subblocks in order to get
21077 inlined call information. */
21079 /* Output the DIEs to represent all sub-blocks (and the items declared
21080 therein) of this block. */
21081 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
21083 subblocks
= BLOCK_CHAIN (subblocks
))
21084 gen_block_die (subblocks
, context_die
);
21087 /* Is this a typedef we can avoid emitting? */
21090 is_redundant_typedef (const_tree decl
)
21092 if (TYPE_DECL_IS_STUB (decl
))
21095 if (DECL_ARTIFICIAL (decl
)
21096 && DECL_CONTEXT (decl
)
21097 && is_tagged_type (DECL_CONTEXT (decl
))
21098 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
21099 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
21100 /* Also ignore the artificial member typedef for the class name. */
21106 /* Return TRUE if TYPE is a typedef that names a type for linkage
21107 purposes. This kind of typedefs is produced by the C++ FE for
21110 typedef struct {...} foo;
21112 In that case, there is no typedef variant type produced for foo.
21113 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21117 is_naming_typedef_decl (const_tree decl
)
21119 if (decl
== NULL_TREE
21120 || TREE_CODE (decl
) != TYPE_DECL
21121 || !is_tagged_type (TREE_TYPE (decl
))
21122 || DECL_IS_BUILTIN (decl
)
21123 || is_redundant_typedef (decl
)
21124 /* It looks like Ada produces TYPE_DECLs that are very similar
21125 to C++ naming typedefs but that have different
21126 semantics. Let's be specific to c++ for now. */
21130 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
21131 && TYPE_NAME (TREE_TYPE (decl
)) == decl
21132 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
21133 != TYPE_NAME (TREE_TYPE (decl
))));
21136 /* Looks up the DIE for a context. */
21138 static inline dw_die_ref
21139 lookup_context_die (tree context
)
21143 /* Find die that represents this context. */
21144 if (TYPE_P (context
))
21146 context
= TYPE_MAIN_VARIANT (context
);
21147 dw_die_ref ctx
= lookup_type_die (context
);
21150 return strip_naming_typedef (context
, ctx
);
21153 return lookup_decl_die (context
);
21155 return comp_unit_die ();
21158 /* Returns the DIE for a context. */
21160 static inline dw_die_ref
21161 get_context_die (tree context
)
21165 /* Find die that represents this context. */
21166 if (TYPE_P (context
))
21168 context
= TYPE_MAIN_VARIANT (context
);
21169 return strip_naming_typedef (context
, force_type_die (context
));
21172 return force_decl_die (context
);
21174 return comp_unit_die ();
21177 /* Returns the DIE for decl. A DIE will always be returned. */
21180 force_decl_die (tree decl
)
21182 dw_die_ref decl_die
;
21183 unsigned saved_external_flag
;
21184 tree save_fn
= NULL_TREE
;
21185 decl_die
= lookup_decl_die (decl
);
21188 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
21190 decl_die
= lookup_decl_die (decl
);
21194 switch (TREE_CODE (decl
))
21196 case FUNCTION_DECL
:
21197 /* Clear current_function_decl, so that gen_subprogram_die thinks
21198 that this is a declaration. At this point, we just want to force
21199 declaration die. */
21200 save_fn
= current_function_decl
;
21201 current_function_decl
= NULL_TREE
;
21202 gen_subprogram_die (decl
, context_die
);
21203 current_function_decl
= save_fn
;
21207 /* Set external flag to force declaration die. Restore it after
21208 gen_decl_die() call. */
21209 saved_external_flag
= DECL_EXTERNAL (decl
);
21210 DECL_EXTERNAL (decl
) = 1;
21211 gen_decl_die (decl
, NULL
, context_die
);
21212 DECL_EXTERNAL (decl
) = saved_external_flag
;
21215 case NAMESPACE_DECL
:
21216 if (dwarf_version
>= 3 || !dwarf_strict
)
21217 dwarf2out_decl (decl
);
21219 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21220 decl_die
= comp_unit_die ();
21223 case TRANSLATION_UNIT_DECL
:
21224 decl_die
= comp_unit_die ();
21228 gcc_unreachable ();
21231 /* We should be able to find the DIE now. */
21233 decl_die
= lookup_decl_die (decl
);
21234 gcc_assert (decl_die
);
21240 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21241 always returned. */
21244 force_type_die (tree type
)
21246 dw_die_ref type_die
;
21248 type_die
= lookup_type_die (type
);
21251 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
21253 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
21255 gcc_assert (type_die
);
21260 /* Force out any required namespaces to be able to output DECL,
21261 and return the new context_die for it, if it's changed. */
21264 setup_namespace_context (tree thing
, dw_die_ref context_die
)
21266 tree context
= (DECL_P (thing
)
21267 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
21268 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
21269 /* Force out the namespace. */
21270 context_die
= force_decl_die (context
);
21272 return context_die
;
21275 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21276 type) within its namespace, if appropriate.
21278 For compatibility with older debuggers, namespace DIEs only contain
21279 declarations; all definitions are emitted at CU scope, with
21280 DW_AT_specification pointing to the declaration (like with class
21284 declare_in_namespace (tree thing
, dw_die_ref context_die
)
21286 dw_die_ref ns_context
;
21288 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21289 return context_die
;
21291 /* External declarations in the local scope only need to be emitted
21292 once, not once in the namespace and once in the scope.
21294 This avoids declaring the `extern' below in the
21295 namespace DIE as well as in the innermost scope:
21308 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
21309 return context_die
;
21311 /* If this decl is from an inlined function, then don't try to emit it in its
21312 namespace, as we will get confused. It would have already been emitted
21313 when the abstract instance of the inline function was emitted anyways. */
21314 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
21315 return context_die
;
21317 ns_context
= setup_namespace_context (thing
, context_die
);
21319 if (ns_context
!= context_die
)
21323 if (DECL_P (thing
))
21324 gen_decl_die (thing
, NULL
, ns_context
);
21326 gen_type_die (thing
, ns_context
);
21328 return context_die
;
21331 /* Generate a DIE for a namespace or namespace alias. */
21334 gen_namespace_die (tree decl
, dw_die_ref context_die
)
21336 dw_die_ref namespace_die
;
21338 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21339 they are an alias of. */
21340 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
21342 /* Output a real namespace or module. */
21343 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21344 namespace_die
= new_die (is_fortran ()
21345 ? DW_TAG_module
: DW_TAG_namespace
,
21346 context_die
, decl
);
21347 /* For Fortran modules defined in different CU don't add src coords. */
21348 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
21350 const char *name
= dwarf2_name (decl
, 0);
21352 add_name_attribute (namespace_die
, name
);
21355 add_name_and_src_coords_attributes (namespace_die
, decl
);
21356 if (DECL_EXTERNAL (decl
))
21357 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
21358 equate_decl_number_to_die (decl
, namespace_die
);
21362 /* Output a namespace alias. */
21364 /* Force out the namespace we are an alias of, if necessary. */
21365 dw_die_ref origin_die
21366 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
21368 if (DECL_FILE_SCOPE_P (decl
)
21369 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
21370 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21371 /* Now create the namespace alias DIE. */
21372 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
21373 add_name_and_src_coords_attributes (namespace_die
, decl
);
21374 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
21375 equate_decl_number_to_die (decl
, namespace_die
);
21377 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
21378 if (want_pubnames ())
21379 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
21382 /* Generate Dwarf debug information for a decl described by DECL.
21383 The return value is currently only meaningful for PARM_DECLs,
21384 for all other decls it returns NULL. */
21387 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
21389 tree decl_or_origin
= decl
? decl
: origin
;
21390 tree class_origin
= NULL
, ultimate_origin
;
21392 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
21395 /* Ignore pointer bounds decls. */
21396 if (DECL_P (decl_or_origin
)
21397 && TREE_TYPE (decl_or_origin
)
21398 && POINTER_BOUNDS_P (decl_or_origin
))
21401 switch (TREE_CODE (decl_or_origin
))
21407 if (!is_fortran () && !is_ada ())
21409 /* The individual enumerators of an enum type get output when we output
21410 the Dwarf representation of the relevant enum type itself. */
21414 /* Emit its type. */
21415 gen_type_die (TREE_TYPE (decl
), context_die
);
21417 /* And its containing namespace. */
21418 context_die
= declare_in_namespace (decl
, context_die
);
21420 gen_const_die (decl
, context_die
);
21423 case FUNCTION_DECL
:
21424 /* Don't output any DIEs to represent mere function declarations,
21425 unless they are class members or explicit block externs. */
21426 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
21427 && DECL_FILE_SCOPE_P (decl_or_origin
)
21428 && (current_function_decl
== NULL_TREE
21429 || DECL_ARTIFICIAL (decl_or_origin
)))
21434 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21435 on local redeclarations of global functions. That seems broken. */
21436 if (current_function_decl
!= decl
)
21437 /* This is only a declaration. */;
21440 /* If we're emitting a clone, emit info for the abstract instance. */
21441 if (origin
|| DECL_ORIGIN (decl
) != decl
)
21442 dwarf2out_abstract_function (origin
21443 ? DECL_ORIGIN (origin
)
21444 : DECL_ABSTRACT_ORIGIN (decl
));
21446 /* If we're emitting an out-of-line copy of an inline function,
21447 emit info for the abstract instance and set up to refer to it. */
21448 else if (cgraph_function_possibly_inlined_p (decl
)
21449 && ! DECL_ABSTRACT_P (decl
)
21450 && ! class_or_namespace_scope_p (context_die
)
21451 /* dwarf2out_abstract_function won't emit a die if this is just
21452 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21453 that case, because that works only if we have a die. */
21454 && DECL_INITIAL (decl
) != NULL_TREE
)
21456 dwarf2out_abstract_function (decl
);
21457 set_decl_origin_self (decl
);
21460 /* Otherwise we're emitting the primary DIE for this decl. */
21461 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21463 /* Before we describe the FUNCTION_DECL itself, make sure that we
21464 have its containing type. */
21466 origin
= decl_class_context (decl
);
21467 if (origin
!= NULL_TREE
)
21468 gen_type_die (origin
, context_die
);
21470 /* And its return type. */
21471 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
21473 /* And its virtual context. */
21474 if (DECL_VINDEX (decl
) != NULL_TREE
)
21475 gen_type_die (DECL_CONTEXT (decl
), context_die
);
21477 /* Make sure we have a member DIE for decl. */
21478 if (origin
!= NULL_TREE
)
21479 gen_type_die_for_member (origin
, decl
, context_die
);
21481 /* And its containing namespace. */
21482 context_die
= declare_in_namespace (decl
, context_die
);
21485 /* Now output a DIE to represent the function itself. */
21487 gen_subprogram_die (decl
, context_die
);
21491 /* If we are in terse mode, don't generate any DIEs to represent any
21492 actual typedefs. */
21493 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21496 /* In the special case of a TYPE_DECL node representing the declaration
21497 of some type tag, if the given TYPE_DECL is marked as having been
21498 instantiated from some other (original) TYPE_DECL node (e.g. one which
21499 was generated within the original definition of an inline function) we
21500 used to generate a special (abbreviated) DW_TAG_structure_type,
21501 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21502 should be actually referencing those DIEs, as variable DIEs with that
21503 type would be emitted already in the abstract origin, so it was always
21504 removed during unused type prunning. Don't add anything in this
21506 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
21509 if (is_redundant_typedef (decl
))
21510 gen_type_die (TREE_TYPE (decl
), context_die
);
21512 /* Output a DIE to represent the typedef itself. */
21513 gen_typedef_die (decl
, context_die
);
21517 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
21518 gen_label_die (decl
, context_die
);
21523 /* If we are in terse mode, don't generate any DIEs to represent any
21524 variable declarations or definitions. */
21525 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21528 /* Output any DIEs that are needed to specify the type of this data
21530 if (decl_by_reference_p (decl_or_origin
))
21531 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21533 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21535 /* And its containing type. */
21536 class_origin
= decl_class_context (decl_or_origin
);
21537 if (class_origin
!= NULL_TREE
)
21538 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
21540 /* And its containing namespace. */
21541 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
21543 /* Now output the DIE to represent the data object itself. This gets
21544 complicated because of the possibility that the VAR_DECL really
21545 represents an inlined instance of a formal parameter for an inline
21547 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21548 if (ultimate_origin
!= NULL_TREE
21549 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
21550 gen_formal_parameter_die (decl
, origin
,
21551 true /* Emit name attribute. */,
21554 gen_variable_die (decl
, origin
, context_die
);
21558 /* Ignore the nameless fields that are used to skip bits but handle C++
21559 anonymous unions and structs. */
21560 if (DECL_NAME (decl
) != NULL_TREE
21561 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
21562 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
21564 gen_type_die (member_declared_type (decl
), context_die
);
21565 gen_field_die (decl
, context_die
);
21570 if (DECL_BY_REFERENCE (decl_or_origin
))
21571 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21573 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21574 return gen_formal_parameter_die (decl
, origin
,
21575 true /* Emit name attribute. */,
21578 case NAMESPACE_DECL
:
21579 case IMPORTED_DECL
:
21580 if (dwarf_version
>= 3 || !dwarf_strict
)
21581 gen_namespace_die (decl
, context_die
);
21584 case NAMELIST_DECL
:
21585 gen_namelist_decl (DECL_NAME (decl
), context_die
,
21586 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
21590 /* Probably some frontend-internal decl. Assume we don't care. */
21591 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
21598 /* Output initial debug information for global DECL. Called at the
21599 end of the parsing process.
21601 This is the initial debug generation process. As such, the DIEs
21602 generated may be incomplete. A later debug generation pass
21603 (dwarf2out_late_global_decl) will augment the information generated
21604 in this pass (e.g., with complete location info). */
21607 dwarf2out_early_global_decl (tree decl
)
21611 /* gen_decl_die() will set DECL_ABSTRACT because
21612 cgraph_function_possibly_inlined_p() returns true. This is in
21613 turn will cause DW_AT_inline attributes to be set.
21615 This happens because at early dwarf generation, there is no
21616 cgraph information, causing cgraph_function_possibly_inlined_p()
21617 to return true. Trick cgraph_function_possibly_inlined_p()
21618 while we generate dwarf early. */
21619 bool save
= symtab
->global_info_ready
;
21620 symtab
->global_info_ready
= true;
21622 /* We don't handle TYPE_DECLs. If required, they'll be reached via
21623 other DECLs and they can point to template types or other things
21624 that dwarf2out can't handle when done via dwarf2out_decl. */
21625 if (TREE_CODE (decl
) != TYPE_DECL
21626 && TREE_CODE (decl
) != PARM_DECL
)
21628 tree save_fndecl
= current_function_decl
;
21629 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21631 /* No cfun means the symbol has no body, so there's nothing
21633 if (!DECL_STRUCT_FUNCTION (decl
))
21634 goto early_decl_exit
;
21636 current_function_decl
= decl
;
21638 dwarf2out_decl (decl
);
21639 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21640 current_function_decl
= save_fndecl
;
21643 symtab
->global_info_ready
= save
;
21646 /* Output debug information for global decl DECL. Called from
21647 toplev.c after compilation proper has finished. */
21650 dwarf2out_late_global_decl (tree decl
)
21652 /* We have to generate early debug late for LTO. */
21654 dwarf2out_early_global_decl (decl
);
21656 /* Fill-in any location information we were unable to determine
21657 on the first pass. */
21658 if (TREE_CODE (decl
) == VAR_DECL
21659 && !POINTER_BOUNDS_P (decl
))
21661 dw_die_ref die
= lookup_decl_die (decl
);
21663 add_location_or_const_value_attribute (die
, decl
, false);
21667 /* Output debug information for type decl DECL. Called from toplev.c
21668 and from language front ends (to record built-in types). */
21670 dwarf2out_type_decl (tree decl
, int local
)
21675 dwarf2out_decl (decl
);
21679 /* Output debug information for imported module or decl DECL.
21680 NAME is non-NULL name in the lexical block if the decl has been renamed.
21681 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21682 that DECL belongs to.
21683 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21685 dwarf2out_imported_module_or_decl_1 (tree decl
,
21687 tree lexical_block
,
21688 dw_die_ref lexical_block_die
)
21690 expanded_location xloc
;
21691 dw_die_ref imported_die
= NULL
;
21692 dw_die_ref at_import_die
;
21694 if (TREE_CODE (decl
) == IMPORTED_DECL
)
21696 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
21697 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
21701 xloc
= expand_location (input_location
);
21703 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
21705 at_import_die
= force_type_die (TREE_TYPE (decl
));
21706 /* For namespace N { typedef void T; } using N::T; base_type_die
21707 returns NULL, but DW_TAG_imported_declaration requires
21708 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21709 if (!at_import_die
)
21711 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
21712 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
21713 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
21714 gcc_assert (at_import_die
);
21719 at_import_die
= lookup_decl_die (decl
);
21720 if (!at_import_die
)
21722 /* If we're trying to avoid duplicate debug info, we may not have
21723 emitted the member decl for this field. Emit it now. */
21724 if (TREE_CODE (decl
) == FIELD_DECL
)
21726 tree type
= DECL_CONTEXT (decl
);
21728 if (TYPE_CONTEXT (type
)
21729 && TYPE_P (TYPE_CONTEXT (type
))
21730 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
21731 DINFO_USAGE_DIR_USE
))
21733 gen_type_die_for_member (type
, decl
,
21734 get_context_die (TYPE_CONTEXT (type
)));
21736 if (TREE_CODE (decl
) == NAMELIST_DECL
)
21737 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
21738 get_context_die (DECL_CONTEXT (decl
)),
21741 at_import_die
= force_decl_die (decl
);
21745 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
21747 if (dwarf_version
>= 3 || !dwarf_strict
)
21748 imported_die
= new_die (DW_TAG_imported_module
,
21755 imported_die
= new_die (DW_TAG_imported_declaration
,
21759 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
21760 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
21762 add_AT_string (imported_die
, DW_AT_name
,
21763 IDENTIFIER_POINTER (name
));
21764 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
21767 /* Output debug information for imported module or decl DECL.
21768 NAME is non-NULL name in context if the decl has been renamed.
21769 CHILD is true if decl is one of the renamed decls as part of
21770 importing whole module. */
21773 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
21776 /* dw_die_ref at_import_die; */
21777 dw_die_ref scope_die
;
21779 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21786 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21787 We need decl DIE for reference and scope die. First, get DIE for the decl
21790 /* Get the scope die for decl context. Use comp_unit_die for global module
21791 or decl. If die is not found for non globals, force new die. */
21793 && TYPE_P (context
)
21794 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
21797 if (!(dwarf_version
>= 3 || !dwarf_strict
))
21800 scope_die
= get_context_die (context
);
21804 gcc_assert (scope_die
->die_child
);
21805 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21806 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21807 scope_die
= scope_die
->die_child
;
21810 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21811 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21814 /* Output debug information for namelists. */
21817 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
21819 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
21823 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21826 gcc_assert (scope_die
!= NULL
);
21827 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
21828 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
21830 /* If there are no item_decls, we have a nondefining namelist, e.g.
21831 with USE association; hence, set DW_AT_declaration. */
21832 if (item_decls
== NULL_TREE
)
21834 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
21838 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
21840 nml_item_ref_die
= lookup_decl_die (value
);
21841 if (!nml_item_ref_die
)
21842 nml_item_ref_die
= force_decl_die (value
);
21844 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
21845 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
21851 /* Write the debugging output for DECL and return the DIE. */
21854 dwarf2out_decl (tree decl
)
21856 dw_die_ref context_die
= comp_unit_die ();
21858 switch (TREE_CODE (decl
))
21863 case FUNCTION_DECL
:
21864 /* What we would really like to do here is to filter out all mere
21865 file-scope declarations of file-scope functions which are never
21866 referenced later within this translation unit (and keep all of ones
21867 that *are* referenced later on) but we aren't clairvoyant, so we have
21868 no idea which functions will be referenced in the future (i.e. later
21869 on within the current translation unit). So here we just ignore all
21870 file-scope function declarations which are not also definitions. If
21871 and when the debugger needs to know something about these functions,
21872 it will have to hunt around and find the DWARF information associated
21873 with the definition of the function.
21875 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21876 nodes represent definitions and which ones represent mere
21877 declarations. We have to check DECL_INITIAL instead. That's because
21878 the C front-end supports some weird semantics for "extern inline"
21879 function definitions. These can get inlined within the current
21880 translation unit (and thus, we need to generate Dwarf info for their
21881 abstract instances so that the Dwarf info for the concrete inlined
21882 instances can have something to refer to) but the compiler never
21883 generates any out-of-lines instances of such things (despite the fact
21884 that they *are* definitions).
21886 The important point is that the C front-end marks these "extern
21887 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21888 them anyway. Note that the C++ front-end also plays some similar games
21889 for inline function definitions appearing within include files which
21890 also contain `#pragma interface' pragmas.
21892 If we are called from dwarf2out_abstract_function output a DIE
21893 anyway. We can end up here this way with early inlining and LTO
21894 where the inlined function is output in a different LTRANS unit
21896 if (DECL_INITIAL (decl
) == NULL_TREE
21897 && ! DECL_ABSTRACT_P (decl
))
21900 /* If we're a nested function, initially use a parent of NULL; if we're
21901 a plain function, this will be fixed up in decls_for_scope. If
21902 we're a method, it will be ignored, since we already have a DIE. */
21903 if (decl_function_context (decl
)
21904 /* But if we're in terse mode, we don't care about scope. */
21905 && debug_info_level
> DINFO_LEVEL_TERSE
)
21906 context_die
= NULL
;
21910 /* For local statics lookup proper context die. */
21911 if (local_function_static (decl
))
21912 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21914 /* If we are in terse mode, don't generate any DIEs to represent any
21915 variable declarations or definitions. */
21916 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21921 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21923 if (!is_fortran () && !is_ada ())
21925 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21926 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21929 case NAMESPACE_DECL
:
21930 case IMPORTED_DECL
:
21931 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21933 if (lookup_decl_die (decl
) != NULL
)
21938 /* Don't emit stubs for types unless they are needed by other DIEs. */
21939 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21942 /* Don't bother trying to generate any DIEs to represent any of the
21943 normal built-in types for the language we are compiling. */
21944 if (DECL_IS_BUILTIN (decl
))
21947 /* If we are in terse mode, don't generate any DIEs for types. */
21948 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21951 /* If we're a function-scope tag, initially use a parent of NULL;
21952 this will be fixed up in decls_for_scope. */
21953 if (decl_function_context (decl
))
21954 context_die
= NULL
;
21958 case NAMELIST_DECL
:
21965 gen_decl_die (decl
, NULL
, context_die
);
21969 dw_die_ref die
= lookup_decl_die (decl
);
21975 /* Write the debugging output for DECL. */
21978 dwarf2out_function_decl (tree decl
)
21980 dwarf2out_decl (decl
);
21981 call_arg_locations
= NULL
;
21982 call_arg_loc_last
= NULL
;
21983 call_site_count
= -1;
21984 tail_call_site_count
= -1;
21985 decl_loc_table
->empty ();
21986 cached_dw_loc_list_table
->empty ();
21989 /* Output a marker (i.e. a label) for the beginning of the generated code for
21990 a lexical block. */
21993 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21994 unsigned int blocknum
)
21996 switch_to_section (current_function_section ());
21997 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
22000 /* Output a marker (i.e. a label) for the end of the generated code for a
22004 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
22006 switch_to_section (current_function_section ());
22007 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
22010 /* Returns nonzero if it is appropriate not to emit any debugging
22011 information for BLOCK, because it doesn't contain any instructions.
22013 Don't allow this for blocks with nested functions or local classes
22014 as we would end up with orphans, and in the presence of scheduling
22015 we may end up calling them anyway. */
22018 dwarf2out_ignore_block (const_tree block
)
22023 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
22024 if (TREE_CODE (decl
) == FUNCTION_DECL
22025 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
22027 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
22029 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
22030 if (TREE_CODE (decl
) == FUNCTION_DECL
22031 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
22038 /* Hash table routines for file_hash. */
22041 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
22043 return filename_cmp (p1
->filename
, p2
) == 0;
22047 dwarf_file_hasher::hash (dwarf_file_data
*p
)
22049 return htab_hash_string (p
->filename
);
22052 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22053 dwarf2out.c) and return its "index". The index of each (known) filename is
22054 just a unique number which is associated with only that one filename. We
22055 need such numbers for the sake of generating labels (in the .debug_sfnames
22056 section) and references to those files numbers (in the .debug_srcinfo
22057 and .debug_macinfo sections). If the filename given as an argument is not
22058 found in our current list, add it to the list and assign it the next
22059 available unique index number. */
22061 static struct dwarf_file_data
*
22062 lookup_filename (const char *file_name
)
22064 struct dwarf_file_data
* created
;
22069 dwarf_file_data
**slot
22070 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
22075 created
= ggc_alloc
<dwarf_file_data
> ();
22076 created
->filename
= file_name
;
22077 created
->emitted_number
= 0;
22082 /* If the assembler will construct the file table, then translate the compiler
22083 internal file table number into the assembler file table number, and emit
22084 a .file directive if we haven't already emitted one yet. The file table
22085 numbers are different because we prune debug info for unused variables and
22086 types, which may include filenames. */
22089 maybe_emit_file (struct dwarf_file_data
* fd
)
22091 if (! fd
->emitted_number
)
22093 if (last_emitted_file
)
22094 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
22096 fd
->emitted_number
= 1;
22097 last_emitted_file
= fd
;
22099 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22101 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
22102 output_quoted_string (asm_out_file
,
22103 remap_debug_filename (fd
->filename
));
22104 fputc ('\n', asm_out_file
);
22108 return fd
->emitted_number
;
22111 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22112 That generation should happen after function debug info has been
22113 generated. The value of the attribute is the constant value of ARG. */
22116 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
22118 die_arg_entry entry
;
22123 gcc_assert (early_dwarf
);
22125 if (!tmpl_value_parm_die_table
)
22126 vec_alloc (tmpl_value_parm_die_table
, 32);
22130 vec_safe_push (tmpl_value_parm_die_table
, entry
);
22133 /* Return TRUE if T is an instance of generic type, FALSE
22137 generic_type_p (tree t
)
22139 if (t
== NULL_TREE
|| !TYPE_P (t
))
22141 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
22144 /* Schedule the generation of the generic parameter dies for the
22145 instance of generic type T. The proper generation itself is later
22146 done by gen_scheduled_generic_parms_dies. */
22149 schedule_generic_params_dies_gen (tree t
)
22151 if (!generic_type_p (t
))
22154 gcc_assert (early_dwarf
);
22156 if (!generic_type_instances
)
22157 vec_alloc (generic_type_instances
, 256);
22159 vec_safe_push (generic_type_instances
, t
);
22162 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22163 by append_entry_to_tmpl_value_parm_die_table. This function must
22164 be called after function DIEs have been generated. */
22167 gen_remaining_tmpl_value_param_die_attribute (void)
22169 if (tmpl_value_parm_die_table
)
22174 /* We do this in two phases - first get the cases we can
22175 handle during early-finish, preserving those we cannot
22176 (containing symbolic constants where we don't yet know
22177 whether we are going to output the referenced symbols).
22178 For those we try again at late-finish. */
22180 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
22182 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
22183 (*tmpl_value_parm_die_table
)[j
++] = *e
;
22185 tmpl_value_parm_die_table
->truncate (j
);
22189 /* Generate generic parameters DIEs for instances of generic types
22190 that have been previously scheduled by
22191 schedule_generic_params_dies_gen. This function must be called
22192 after all the types of the CU have been laid out. */
22195 gen_scheduled_generic_parms_dies (void)
22200 if (!generic_type_instances
)
22203 /* We end up "recursing" into schedule_generic_params_dies_gen, so
22204 pretend this generation is part of "early dwarf" as well. */
22207 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
22208 if (COMPLETE_TYPE_P (t
))
22209 gen_generic_params_dies (t
);
22211 generic_type_instances
= NULL
;
22215 /* Replace DW_AT_name for the decl with name. */
22218 dwarf2out_set_name (tree decl
, tree name
)
22221 dw_attr_node
*attr
;
22224 die
= TYPE_SYMTAB_DIE (decl
);
22228 dname
= dwarf2_name (name
, 0);
22232 attr
= get_AT (die
, DW_AT_name
);
22235 struct indirect_string_node
*node
;
22237 node
= find_AT_string (dname
);
22238 /* replace the string. */
22239 attr
->dw_attr_val
.v
.val_str
= node
;
22243 add_name_attribute (die
, dname
);
22246 /* True if before or during processing of the first function being emitted. */
22247 static bool in_first_function_p
= true;
22248 /* True if loc_note during dwarf2out_var_location call might still be
22249 before first real instruction at address equal to .Ltext0. */
22250 static bool maybe_at_text_label_p
= true;
22251 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
22252 static unsigned int first_loclabel_num_not_at_text_label
;
22254 /* Called by the final INSN scan whenever we see a var location. We
22255 use it to drop labels in the right places, and throw the location in
22256 our lookup table. */
22259 dwarf2out_var_location (rtx_insn
*loc_note
)
22261 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
22262 struct var_loc_node
*newloc
;
22263 rtx_insn
*next_real
, *next_note
;
22264 static const char *last_label
;
22265 static const char *last_postcall_label
;
22266 static bool last_in_cold_section_p
;
22267 static rtx_insn
*expected_next_loc_note
;
22271 if (!NOTE_P (loc_note
))
22273 if (CALL_P (loc_note
))
22276 if (SIBLING_CALL_P (loc_note
))
22277 tail_call_site_count
++;
22282 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
22283 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
22286 /* Optimize processing a large consecutive sequence of location
22287 notes so we don't spend too much time in next_real_insn. If the
22288 next insn is another location note, remember the next_real_insn
22289 calculation for next time. */
22290 next_real
= cached_next_real_insn
;
22293 if (expected_next_loc_note
!= loc_note
)
22297 next_note
= NEXT_INSN (loc_note
);
22299 || next_note
->deleted ()
22300 || ! NOTE_P (next_note
)
22301 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
22302 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
22306 next_real
= next_real_insn (loc_note
);
22310 expected_next_loc_note
= next_note
;
22311 cached_next_real_insn
= next_real
;
22314 cached_next_real_insn
= NULL
;
22316 /* If there are no instructions which would be affected by this note,
22317 don't do anything. */
22319 && next_real
== NULL_RTX
22320 && !NOTE_DURING_CALL_P (loc_note
))
22323 if (next_real
== NULL_RTX
)
22324 next_real
= get_last_insn ();
22326 /* If there were any real insns between note we processed last time
22327 and this note (or if it is the first note), clear
22328 last_{,postcall_}label so that they are not reused this time. */
22329 if (last_var_location_insn
== NULL_RTX
22330 || last_var_location_insn
!= next_real
22331 || last_in_cold_section_p
!= in_cold_section_p
)
22334 last_postcall_label
= NULL
;
22339 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
22340 newloc
= add_var_loc_to_decl (decl
, loc_note
,
22341 NOTE_DURING_CALL_P (loc_note
)
22342 ? last_postcall_label
: last_label
);
22343 if (newloc
== NULL
)
22352 /* If there were no real insns between note we processed last time
22353 and this note, use the label we emitted last time. Otherwise
22354 create a new label and emit it. */
22355 if (last_label
== NULL
)
22357 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
22358 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
22360 last_label
= ggc_strdup (loclabel
);
22361 /* See if loclabel might be equal to .Ltext0. If yes,
22362 bump first_loclabel_num_not_at_text_label. */
22363 if (!have_multiple_function_sections
22364 && in_first_function_p
22365 && maybe_at_text_label_p
)
22367 static rtx_insn
*last_start
;
22369 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
22370 if (insn
== last_start
)
22372 else if (!NONDEBUG_INSN_P (insn
))
22376 rtx body
= PATTERN (insn
);
22377 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
22379 /* Inline asm could occupy zero bytes. */
22380 else if (GET_CODE (body
) == ASM_INPUT
22381 || asm_noperands (body
) >= 0)
22383 #ifdef HAVE_attr_length
22384 else if (get_attr_min_length (insn
) == 0)
22389 /* Assume insn has non-zero length. */
22390 maybe_at_text_label_p
= false;
22394 if (maybe_at_text_label_p
)
22396 last_start
= loc_note
;
22397 first_loclabel_num_not_at_text_label
= loclabel_num
;
22404 struct call_arg_loc_node
*ca_loc
22405 = ggc_cleared_alloc
<call_arg_loc_node
> ();
22406 rtx_insn
*prev
= prev_real_insn (loc_note
);
22408 ca_loc
->call_arg_loc_note
= loc_note
;
22409 ca_loc
->next
= NULL
;
22410 ca_loc
->label
= last_label
;
22413 || (NONJUMP_INSN_P (prev
)
22414 && GET_CODE (PATTERN (prev
)) == SEQUENCE
22415 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
22416 if (!CALL_P (prev
))
22417 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
22418 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
22419 x
= get_call_rtx_from (PATTERN (prev
));
22422 x
= XEXP (XEXP (x
, 0), 0);
22423 if (GET_CODE (x
) == SYMBOL_REF
22424 && SYMBOL_REF_DECL (x
)
22425 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
22426 ca_loc
->symbol_ref
= x
;
22428 ca_loc
->block
= insn_scope (prev
);
22429 if (call_arg_locations
)
22430 call_arg_loc_last
->next
= ca_loc
;
22432 call_arg_locations
= ca_loc
;
22433 call_arg_loc_last
= ca_loc
;
22435 else if (!NOTE_DURING_CALL_P (loc_note
))
22436 newloc
->label
= last_label
;
22439 if (!last_postcall_label
)
22441 sprintf (loclabel
, "%s-1", last_label
);
22442 last_postcall_label
= ggc_strdup (loclabel
);
22444 newloc
->label
= last_postcall_label
;
22447 last_var_location_insn
= next_real
;
22448 last_in_cold_section_p
= in_cold_section_p
;
22451 /* Note in one location list that text section has changed. */
22454 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
22456 var_loc_list
*list
= *slot
;
22458 list
->last_before_switch
22459 = list
->last
->next
? list
->last
->next
: list
->last
;
22463 /* Note in all location lists that text section has changed. */
22466 var_location_switch_text_section (void)
22468 if (decl_loc_table
== NULL
)
22471 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
22474 /* Create a new line number table. */
22476 static dw_line_info_table
*
22477 new_line_info_table (void)
22479 dw_line_info_table
*table
;
22481 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
22482 table
->file_num
= 1;
22483 table
->line_num
= 1;
22484 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
22489 /* Lookup the "current" table into which we emit line info, so
22490 that we don't have to do it for every source line. */
22493 set_cur_line_info_table (section
*sec
)
22495 dw_line_info_table
*table
;
22497 if (sec
== text_section
)
22498 table
= text_section_line_info
;
22499 else if (sec
== cold_text_section
)
22501 table
= cold_text_section_line_info
;
22504 cold_text_section_line_info
= table
= new_line_info_table ();
22505 table
->end_label
= cold_end_label
;
22510 const char *end_label
;
22512 if (flag_reorder_blocks_and_partition
)
22514 if (in_cold_section_p
)
22515 end_label
= crtl
->subsections
.cold_section_end_label
;
22517 end_label
= crtl
->subsections
.hot_section_end_label
;
22521 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22522 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
22523 current_function_funcdef_no
);
22524 end_label
= ggc_strdup (label
);
22527 table
= new_line_info_table ();
22528 table
->end_label
= end_label
;
22530 vec_safe_push (separate_line_info
, table
);
22533 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22534 table
->is_stmt
= (cur_line_info_table
22535 ? cur_line_info_table
->is_stmt
22536 : DWARF_LINE_DEFAULT_IS_STMT_START
);
22537 cur_line_info_table
= table
;
22541 /* We need to reset the locations at the beginning of each
22542 function. We can't do this in the end_function hook, because the
22543 declarations that use the locations won't have been output when
22544 that hook is called. Also compute have_multiple_function_sections here. */
22547 dwarf2out_begin_function (tree fun
)
22549 section
*sec
= function_section (fun
);
22551 if (sec
!= text_section
)
22552 have_multiple_function_sections
= true;
22554 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
22556 gcc_assert (current_function_decl
== fun
);
22557 cold_text_section
= unlikely_text_section ();
22558 switch_to_section (cold_text_section
);
22559 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
22560 switch_to_section (sec
);
22563 dwarf2out_note_section_used ();
22564 call_site_count
= 0;
22565 tail_call_site_count
= 0;
22567 set_cur_line_info_table (sec
);
22570 /* Helper function of dwarf2out_end_function, called only after emitting
22571 the very first function into assembly. Check if some .debug_loc range
22572 might end with a .LVL* label that could be equal to .Ltext0.
22573 In that case we must force using absolute addresses in .debug_loc ranges,
22574 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
22575 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
22577 Set have_multiple_function_sections to true in that case and
22578 terminate htab traversal. */
22581 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
22583 var_loc_list
*entry
= *slot
;
22584 struct var_loc_node
*node
;
22586 node
= entry
->first
;
22587 if (node
&& node
->next
&& node
->next
->label
)
22590 const char *label
= node
->next
->label
;
22591 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
22593 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
22595 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
22596 if (strcmp (label
, loclabel
) == 0)
22598 have_multiple_function_sections
= true;
22606 /* Hook called after emitting a function into assembly.
22607 This does something only for the very first function emitted. */
22610 dwarf2out_end_function (unsigned int)
22612 if (in_first_function_p
22613 && !have_multiple_function_sections
22614 && first_loclabel_num_not_at_text_label
22616 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
22617 in_first_function_p
= false;
22618 maybe_at_text_label_p
= false;
22621 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
22622 front-ends register a translation unit even before dwarf2out_init is
22624 static tree main_translation_unit
= NULL_TREE
;
22626 /* Hook called by front-ends after they built their main translation unit.
22627 Associate comp_unit_die to UNIT. */
22630 dwarf2out_register_main_translation_unit (tree unit
)
22632 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
22633 && main_translation_unit
== NULL_TREE
);
22634 main_translation_unit
= unit
;
22635 /* If dwarf2out_init has not been called yet, it will perform the association
22636 itself looking at main_translation_unit. */
22637 if (decl_die_table
!= NULL
)
22638 equate_decl_number_to_die (unit
, comp_unit_die ());
22641 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22644 push_dw_line_info_entry (dw_line_info_table
*table
,
22645 enum dw_line_info_opcode opcode
, unsigned int val
)
22647 dw_line_info_entry e
;
22650 vec_safe_push (table
->entries
, e
);
22653 /* Output a label to mark the beginning of a source code line entry
22654 and record information relating to this source line, in
22655 'line_info_table' for later output of the .debug_line section. */
22656 /* ??? The discriminator parameter ought to be unsigned. */
22659 dwarf2out_source_line (unsigned int line
, const char *filename
,
22660 int discriminator
, bool is_stmt
)
22662 unsigned int file_num
;
22663 dw_line_info_table
*table
;
22665 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
22668 /* The discriminator column was added in dwarf4. Simplify the below
22669 by simply removing it if we're not supposed to output it. */
22670 if (dwarf_version
< 4 && dwarf_strict
)
22673 table
= cur_line_info_table
;
22674 file_num
= maybe_emit_file (lookup_filename (filename
));
22676 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22677 the debugger has used the second (possibly duplicate) line number
22678 at the beginning of the function to mark the end of the prologue.
22679 We could eliminate any other duplicates within the function. For
22680 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22681 that second line number entry. */
22682 /* Recall that this end-of-prologue indication is *not* the same thing
22683 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22684 to which the hook corresponds, follows the last insn that was
22685 emitted by gen_prologue. What we need is to precede the first insn
22686 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22687 insn that corresponds to something the user wrote. These may be
22688 very different locations once scheduling is enabled. */
22690 if (0 && file_num
== table
->file_num
22691 && line
== table
->line_num
22692 && discriminator
== table
->discrim_num
22693 && is_stmt
== table
->is_stmt
)
22696 switch_to_section (current_function_section ());
22698 /* If requested, emit something human-readable. */
22699 if (flag_debug_asm
)
22700 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
22702 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22704 /* Emit the .loc directive understood by GNU as. */
22705 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
22706 file_num, line, is_stmt, discriminator */
22707 fputs ("\t.loc ", asm_out_file
);
22708 fprint_ul (asm_out_file
, file_num
);
22709 putc (' ', asm_out_file
);
22710 fprint_ul (asm_out_file
, line
);
22711 putc (' ', asm_out_file
);
22712 putc ('0', asm_out_file
);
22714 if (is_stmt
!= table
->is_stmt
)
22716 fputs (" is_stmt ", asm_out_file
);
22717 putc (is_stmt
? '1' : '0', asm_out_file
);
22719 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
22721 gcc_assert (discriminator
> 0);
22722 fputs (" discriminator ", asm_out_file
);
22723 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
22725 putc ('\n', asm_out_file
);
22729 unsigned int label_num
= ++line_info_label_num
;
22731 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
22733 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
22734 if (file_num
!= table
->file_num
)
22735 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
22736 if (discriminator
!= table
->discrim_num
)
22737 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
22738 if (is_stmt
!= table
->is_stmt
)
22739 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
22740 push_dw_line_info_entry (table
, LI_set_line
, line
);
22743 table
->file_num
= file_num
;
22744 table
->line_num
= line
;
22745 table
->discrim_num
= discriminator
;
22746 table
->is_stmt
= is_stmt
;
22747 table
->in_use
= true;
22750 /* Record the beginning of a new source file. */
22753 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
22755 if (flag_eliminate_dwarf2_dups
)
22757 /* Record the beginning of the file for break_out_includes. */
22758 dw_die_ref bincl_die
;
22760 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
22761 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
22764 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22767 e
.code
= DW_MACINFO_start_file
;
22769 e
.info
= ggc_strdup (filename
);
22770 vec_safe_push (macinfo_table
, e
);
22774 /* Record the end of a source file. */
22777 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
22779 if (flag_eliminate_dwarf2_dups
)
22780 /* Record the end of the file for break_out_includes. */
22781 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
22783 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22786 e
.code
= DW_MACINFO_end_file
;
22789 vec_safe_push (macinfo_table
, e
);
22793 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22794 the tail part of the directive line, i.e. the part which is past the
22795 initial whitespace, #, whitespace, directive-name, whitespace part. */
22798 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
22799 const char *buffer ATTRIBUTE_UNUSED
)
22801 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22804 /* Insert a dummy first entry to be able to optimize the whole
22805 predefined macro block using DW_MACRO_GNU_transparent_include. */
22806 if (macinfo_table
->is_empty () && lineno
<= 1)
22811 vec_safe_push (macinfo_table
, e
);
22813 e
.code
= DW_MACINFO_define
;
22815 e
.info
= ggc_strdup (buffer
);
22816 vec_safe_push (macinfo_table
, e
);
22820 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22821 the tail part of the directive line, i.e. the part which is past the
22822 initial whitespace, #, whitespace, directive-name, whitespace part. */
22825 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
22826 const char *buffer ATTRIBUTE_UNUSED
)
22828 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22831 /* Insert a dummy first entry to be able to optimize the whole
22832 predefined macro block using DW_MACRO_GNU_transparent_include. */
22833 if (macinfo_table
->is_empty () && lineno
<= 1)
22838 vec_safe_push (macinfo_table
, e
);
22840 e
.code
= DW_MACINFO_undef
;
22842 e
.info
= ggc_strdup (buffer
);
22843 vec_safe_push (macinfo_table
, e
);
22847 /* Helpers to manipulate hash table of CUs. */
22849 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
22851 static inline hashval_t
hash (const macinfo_entry
*);
22852 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
22856 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
22858 return htab_hash_string (entry
->info
);
22862 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
22863 const macinfo_entry
*entry2
)
22865 return !strcmp (entry1
->info
, entry2
->info
);
22868 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
22870 /* Output a single .debug_macinfo entry. */
22873 output_macinfo_op (macinfo_entry
*ref
)
22877 struct indirect_string_node
*node
;
22878 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22879 struct dwarf_file_data
*fd
;
22883 case DW_MACINFO_start_file
:
22884 fd
= lookup_filename (ref
->info
);
22885 file_num
= maybe_emit_file (fd
);
22886 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22887 dw2_asm_output_data_uleb128 (ref
->lineno
,
22888 "Included from line number %lu",
22889 (unsigned long) ref
->lineno
);
22890 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22892 case DW_MACINFO_end_file
:
22893 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22895 case DW_MACINFO_define
:
22896 case DW_MACINFO_undef
:
22897 len
= strlen (ref
->info
) + 1;
22899 && len
> DWARF_OFFSET_SIZE
22900 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22901 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22903 ref
->code
= ref
->code
== DW_MACINFO_define
22904 ? DW_MACRO_GNU_define_indirect
22905 : DW_MACRO_GNU_undef_indirect
;
22906 output_macinfo_op (ref
);
22909 dw2_asm_output_data (1, ref
->code
,
22910 ref
->code
== DW_MACINFO_define
22911 ? "Define macro" : "Undefine macro");
22912 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22913 (unsigned long) ref
->lineno
);
22914 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22916 case DW_MACRO_GNU_define_indirect
:
22917 case DW_MACRO_GNU_undef_indirect
:
22918 node
= find_AT_string (ref
->info
);
22920 && ((node
->form
== DW_FORM_strp
)
22921 || (node
->form
== DW_FORM_GNU_str_index
)));
22922 dw2_asm_output_data (1, ref
->code
,
22923 ref
->code
== DW_MACRO_GNU_define_indirect
22924 ? "Define macro indirect"
22925 : "Undefine macro indirect");
22926 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22927 (unsigned long) ref
->lineno
);
22928 if (node
->form
== DW_FORM_strp
)
22929 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
22930 debug_str_section
, "The macro: \"%s\"",
22933 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
22936 case DW_MACRO_GNU_transparent_include
:
22937 dw2_asm_output_data (1, ref
->code
, "Transparent include");
22938 ASM_GENERATE_INTERNAL_LABEL (label
,
22939 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
22940 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
22943 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22944 ASM_COMMENT_START
, (unsigned long) ref
->code
);
22949 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22950 other compilation unit .debug_macinfo sections. IDX is the first
22951 index of a define/undef, return the number of ops that should be
22952 emitted in a comdat .debug_macinfo section and emit
22953 a DW_MACRO_GNU_transparent_include entry referencing it.
22954 If the define/undef entry should be emitted normally, return 0. */
22957 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
22958 macinfo_hash_type
**macinfo_htab
)
22960 macinfo_entry
*first
, *second
, *cur
, *inc
;
22961 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
22962 unsigned char checksum
[16];
22963 struct md5_ctx ctx
;
22964 char *grp_name
, *tail
;
22966 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
22967 macinfo_entry
**slot
;
22969 first
= &(*macinfo_table
)[idx
];
22970 second
= &(*macinfo_table
)[idx
+ 1];
22972 /* Optimize only if there are at least two consecutive define/undef ops,
22973 and either all of them are before first DW_MACINFO_start_file
22974 with lineno {0,1} (i.e. predefined macro block), or all of them are
22975 in some included header file. */
22976 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
22978 if (vec_safe_is_empty (files
))
22980 if (first
->lineno
> 1 || second
->lineno
> 1)
22983 else if (first
->lineno
== 0)
22986 /* Find the last define/undef entry that can be grouped together
22987 with first and at the same time compute md5 checksum of their
22988 codes, linenumbers and strings. */
22989 md5_init_ctx (&ctx
);
22990 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
22991 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
22993 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
22997 unsigned char code
= cur
->code
;
22998 md5_process_bytes (&code
, 1, &ctx
);
22999 checksum_uleb128 (cur
->lineno
, &ctx
);
23000 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
23002 md5_finish_ctx (&ctx
, checksum
);
23005 /* From the containing include filename (if any) pick up just
23006 usable characters from its basename. */
23007 if (vec_safe_is_empty (files
))
23010 base
= lbasename (files
->last ().info
);
23011 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
23012 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
23013 encoded_filename_len
++;
23014 /* Count . at the end. */
23015 if (encoded_filename_len
)
23016 encoded_filename_len
++;
23018 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
23019 linebuf_len
= strlen (linebuf
);
23021 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
23022 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
23024 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
23025 tail
= grp_name
+ 4;
23026 if (encoded_filename_len
)
23028 for (i
= 0; base
[i
]; i
++)
23029 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
23033 memcpy (tail
, linebuf
, linebuf_len
);
23034 tail
+= linebuf_len
;
23036 for (i
= 0; i
< 16; i
++)
23037 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
23039 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
23040 in the empty vector entry before the first define/undef. */
23041 inc
= &(*macinfo_table
)[idx
- 1];
23042 inc
->code
= DW_MACRO_GNU_transparent_include
;
23044 inc
->info
= ggc_strdup (grp_name
);
23045 if (!*macinfo_htab
)
23046 *macinfo_htab
= new macinfo_hash_type (10);
23047 /* Avoid emitting duplicates. */
23048 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
23053 /* If such an entry has been used before, just emit
23054 a DW_MACRO_GNU_transparent_include op. */
23056 output_macinfo_op (inc
);
23057 /* And clear all macinfo_entry in the range to avoid emitting them
23058 in the second pass. */
23059 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
23068 inc
->lineno
= (*macinfo_htab
)->elements ();
23069 output_macinfo_op (inc
);
23074 /* Save any strings needed by the macinfo table in the debug str
23075 table. All strings must be collected into the table by the time
23076 index_string is called. */
23079 save_macinfo_strings (void)
23083 macinfo_entry
*ref
;
23085 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
23089 /* Match the logic in output_macinfo_op to decide on
23090 indirect strings. */
23091 case DW_MACINFO_define
:
23092 case DW_MACINFO_undef
:
23093 len
= strlen (ref
->info
) + 1;
23095 && len
> DWARF_OFFSET_SIZE
23096 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
23097 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
23098 set_indirect_string (find_AT_string (ref
->info
));
23100 case DW_MACRO_GNU_define_indirect
:
23101 case DW_MACRO_GNU_undef_indirect
:
23102 set_indirect_string (find_AT_string (ref
->info
));
23110 /* Output macinfo section(s). */
23113 output_macinfo (void)
23116 unsigned long length
= vec_safe_length (macinfo_table
);
23117 macinfo_entry
*ref
;
23118 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
23119 macinfo_hash_type
*macinfo_htab
= NULL
;
23124 /* output_macinfo* uses these interchangeably. */
23125 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
23126 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
23127 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
23128 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
23130 /* For .debug_macro emit the section header. */
23133 dw2_asm_output_data (2, 4, "DWARF macro version number");
23134 if (DWARF_OFFSET_SIZE
== 8)
23135 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
23137 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
23138 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
23139 (!dwarf_split_debug_info
? debug_line_section_label
23140 : debug_skeleton_line_section_label
),
23141 debug_line_section
, NULL
);
23144 /* In the first loop, it emits the primary .debug_macinfo section
23145 and after each emitted op the macinfo_entry is cleared.
23146 If a longer range of define/undef ops can be optimized using
23147 DW_MACRO_GNU_transparent_include, the
23148 DW_MACRO_GNU_transparent_include op is emitted and kept in
23149 the vector before the first define/undef in the range and the
23150 whole range of define/undef ops is not emitted and kept. */
23151 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23155 case DW_MACINFO_start_file
:
23156 vec_safe_push (files
, *ref
);
23158 case DW_MACINFO_end_file
:
23159 if (!vec_safe_is_empty (files
))
23162 case DW_MACINFO_define
:
23163 case DW_MACINFO_undef
:
23165 && HAVE_COMDAT_GROUP
23166 && vec_safe_length (files
) != 1
23169 && (*macinfo_table
)[i
- 1].code
== 0)
23171 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
23180 /* A dummy entry may be inserted at the beginning to be able
23181 to optimize the whole block of predefined macros. */
23187 output_macinfo_op (ref
);
23195 delete macinfo_htab
;
23196 macinfo_htab
= NULL
;
23198 /* If any DW_MACRO_GNU_transparent_include were used, on those
23199 DW_MACRO_GNU_transparent_include entries terminate the
23200 current chain and switch to a new comdat .debug_macinfo
23201 section and emit the define/undef entries within it. */
23202 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23207 case DW_MACRO_GNU_transparent_include
:
23209 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23210 tree comdat_key
= get_identifier (ref
->info
);
23211 /* Terminate the previous .debug_macinfo section. */
23212 dw2_asm_output_data (1, 0, "End compilation unit");
23213 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
23215 | SECTION_LINKONCE
,
23217 ASM_GENERATE_INTERNAL_LABEL (label
,
23218 DEBUG_MACRO_SECTION_LABEL
,
23220 ASM_OUTPUT_LABEL (asm_out_file
, label
);
23223 dw2_asm_output_data (2, 4, "DWARF macro version number");
23224 if (DWARF_OFFSET_SIZE
== 8)
23225 dw2_asm_output_data (1, 1, "Flags: 64-bit");
23227 dw2_asm_output_data (1, 0, "Flags: 32-bit");
23230 case DW_MACINFO_define
:
23231 case DW_MACINFO_undef
:
23232 output_macinfo_op (ref
);
23237 gcc_unreachable ();
23241 /* Set up for Dwarf output at the start of compilation. */
23244 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
23246 /* This option is currently broken, see (PR53118 and PR46102). */
23247 if (flag_eliminate_dwarf2_dups
23248 && strstr (lang_hooks
.name
, "C++"))
23250 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
23251 flag_eliminate_dwarf2_dups
= 0;
23254 /* Allocate the file_table. */
23255 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
23257 #ifndef DWARF2_LINENO_DEBUGGING_INFO
23258 /* Allocate the decl_die_table. */
23259 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
23261 /* Allocate the decl_loc_table. */
23262 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
23264 /* Allocate the cached_dw_loc_list_table. */
23265 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
23267 /* Allocate the initial hunk of the decl_scope_table. */
23268 vec_alloc (decl_scope_table
, 256);
23270 /* Allocate the initial hunk of the abbrev_die_table. */
23271 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
23272 (ABBREV_DIE_TABLE_INCREMENT
);
23273 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
23274 /* Zero-th entry is allocated, but unused. */
23275 abbrev_die_table_in_use
= 1;
23277 /* Allocate the pubtypes and pubnames vectors. */
23278 vec_alloc (pubname_table
, 32);
23279 vec_alloc (pubtype_table
, 32);
23281 vec_alloc (incomplete_types
, 64);
23283 vec_alloc (used_rtx_array
, 32);
23285 if (!dwarf_split_debug_info
)
23287 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
23288 SECTION_DEBUG
, NULL
);
23289 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23290 SECTION_DEBUG
, NULL
);
23291 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
23292 SECTION_DEBUG
, NULL
);
23296 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
23297 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23298 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
23299 SECTION_DEBUG
| SECTION_EXCLUDE
,
23301 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
23302 SECTION_DEBUG
, NULL
);
23303 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
23304 SECTION_DEBUG
, NULL
);
23305 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23306 SECTION_DEBUG
, NULL
);
23307 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
23308 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
23310 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
23311 the main .o, but the skeleton_line goes into the split off dwo. */
23312 debug_skeleton_line_section
23313 = get_section (DEBUG_DWO_LINE_SECTION
,
23314 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23315 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
23316 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
23317 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
23318 SECTION_DEBUG
| SECTION_EXCLUDE
,
23320 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
23321 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
23322 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
23323 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23324 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
23325 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
23327 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
23328 SECTION_DEBUG
, NULL
);
23329 debug_macinfo_section
= get_section (dwarf_strict
23330 ? DEBUG_MACINFO_SECTION
23331 : DEBUG_MACRO_SECTION
,
23332 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
23333 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
23334 SECTION_DEBUG
, NULL
);
23335 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
23336 SECTION_DEBUG
, NULL
);
23337 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
23338 SECTION_DEBUG
, NULL
);
23339 debug_str_section
= get_section (DEBUG_STR_SECTION
,
23340 DEBUG_STR_SECTION_FLAGS
, NULL
);
23341 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
23342 SECTION_DEBUG
, NULL
);
23343 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
23344 SECTION_DEBUG
, NULL
);
23346 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
23347 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
23348 DEBUG_ABBREV_SECTION_LABEL
, 0);
23349 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
23350 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
23351 COLD_TEXT_SECTION_LABEL
, 0);
23352 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
23354 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
23355 DEBUG_INFO_SECTION_LABEL
, 0);
23356 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
23357 DEBUG_LINE_SECTION_LABEL
, 0);
23358 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
23359 DEBUG_RANGES_SECTION_LABEL
, 0);
23360 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
23361 DEBUG_ADDR_SECTION_LABEL
, 0);
23362 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
23364 ? DEBUG_MACINFO_SECTION_LABEL
23365 : DEBUG_MACRO_SECTION_LABEL
, 0);
23366 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
23368 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23369 vec_alloc (macinfo_table
, 64);
23371 switch_to_section (text_section
);
23372 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
23375 /* Make sure the line number table for .text always exists. */
23376 text_section_line_info
= new_line_info_table ();
23377 text_section_line_info
->end_label
= text_end_label
;
23379 #ifdef DWARF2_LINENO_DEBUGGING_INFO
23380 cur_line_info_table
= text_section_line_info
;
23383 /* If front-ends already registered a main translation unit but we were not
23384 ready to perform the association, do this now. */
23385 if (main_translation_unit
!= NULL_TREE
)
23386 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
23389 /* Called before compile () starts outputtting functions, variables
23390 and toplevel asms into assembly. */
23393 dwarf2out_assembly_start (void)
23395 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23396 && dwarf2out_do_cfi_asm ()
23397 && (!(flag_unwind_tables
|| flag_exceptions
)
23398 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
23399 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
23402 /* A helper function for dwarf2out_finish called through
23403 htab_traverse. Assign a string its index. All strings must be
23404 collected into the table by the time index_string is called,
23405 because the indexing code relies on htab_traverse to traverse nodes
23406 in the same order for each run. */
23409 index_string (indirect_string_node
**h
, unsigned int *index
)
23411 indirect_string_node
*node
= *h
;
23413 find_string_form (node
);
23414 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23416 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
23417 node
->index
= *index
;
23423 /* A helper function for output_indirect_strings called through
23424 htab_traverse. Output the offset to a string and update the
23428 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
23430 indirect_string_node
*node
= *h
;
23432 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23434 /* Assert that this node has been assigned an index. */
23435 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
23436 && node
->index
!= NOT_INDEXED
);
23437 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
23438 "indexed string 0x%x: %s", node
->index
, node
->str
);
23439 *offset
+= strlen (node
->str
) + 1;
23444 /* A helper function for dwarf2out_finish called through
23445 htab_traverse. Output the indexed string. */
23448 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
23450 struct indirect_string_node
*node
= *h
;
23452 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23454 /* Assert that the strings are output in the same order as their
23455 indexes were assigned. */
23456 gcc_assert (*cur_idx
== node
->index
);
23457 assemble_string (node
->str
, strlen (node
->str
) + 1);
23463 /* A helper function for dwarf2out_finish called through
23464 htab_traverse. Emit one queued .debug_str string. */
23467 output_indirect_string (indirect_string_node
**h
, void *)
23469 struct indirect_string_node
*node
= *h
;
23471 node
->form
= find_string_form (node
);
23472 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
23474 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
23475 assemble_string (node
->str
, strlen (node
->str
) + 1);
23481 /* Output the indexed string table. */
23484 output_indirect_strings (void)
23486 switch_to_section (debug_str_section
);
23487 if (!dwarf_split_debug_info
)
23488 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23491 unsigned int offset
= 0;
23492 unsigned int cur_idx
= 0;
23494 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23496 switch_to_section (debug_str_offsets_section
);
23497 debug_str_hash
->traverse_noresize
23498 <unsigned int *, output_index_string_offset
> (&offset
);
23499 switch_to_section (debug_str_dwo_section
);
23500 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
23505 /* Callback for htab_traverse to assign an index to an entry in the
23506 table, and to write that entry to the .debug_addr section. */
23509 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
23511 addr_table_entry
*entry
= *slot
;
23513 if (entry
->refcount
== 0)
23515 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
23516 || entry
->index
== NOT_INDEXED
);
23520 gcc_assert (entry
->index
== *cur_index
);
23523 switch (entry
->kind
)
23526 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
23527 "0x%x", entry
->index
);
23529 case ate_kind_rtx_dtprel
:
23530 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
23531 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
23534 fputc ('\n', asm_out_file
);
23536 case ate_kind_label
:
23537 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
23538 "0x%x", entry
->index
);
23541 gcc_unreachable ();
23546 /* Produce the .debug_addr section. */
23549 output_addr_table (void)
23551 unsigned int index
= 0;
23552 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
23555 switch_to_section (debug_addr_section
);
23557 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
23560 #if ENABLE_ASSERT_CHECKING
23561 /* Verify that all marks are clear. */
23564 verify_marks_clear (dw_die_ref die
)
23568 gcc_assert (! die
->die_mark
);
23569 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
23571 #endif /* ENABLE_ASSERT_CHECKING */
23573 /* Clear the marks for a die and its children.
23574 Be cool if the mark isn't set. */
23577 prune_unmark_dies (dw_die_ref die
)
23583 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
23586 /* Given DIE that we're marking as used, find any other dies
23587 it references as attributes and mark them as used. */
23590 prune_unused_types_walk_attribs (dw_die_ref die
)
23595 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23597 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
23599 /* A reference to another DIE.
23600 Make sure that it will get emitted.
23601 If it was broken out into a comdat group, don't follow it. */
23602 if (! AT_ref (a
)->comdat_type_p
23603 || a
->dw_attr
== DW_AT_specification
)
23604 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
23606 /* Set the string's refcount to 0 so that prune_unused_types_mark
23607 accounts properly for it. */
23608 if (AT_class (a
) == dw_val_class_str
)
23609 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
23613 /* Mark the generic parameters and arguments children DIEs of DIE. */
23616 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
23620 if (die
== NULL
|| die
->die_child
== NULL
)
23622 c
= die
->die_child
;
23625 if (is_template_parameter (c
))
23626 prune_unused_types_mark (c
, 1);
23628 } while (c
&& c
!= die
->die_child
);
23631 /* Mark DIE as being used. If DOKIDS is true, then walk down
23632 to DIE's children. */
23635 prune_unused_types_mark (dw_die_ref die
, int dokids
)
23639 if (die
->die_mark
== 0)
23641 /* We haven't done this node yet. Mark it as used. */
23643 /* If this is the DIE of a generic type instantiation,
23644 mark the children DIEs that describe its generic parms and
23646 prune_unused_types_mark_generic_parms_dies (die
);
23648 /* We also have to mark its parents as used.
23649 (But we don't want to mark our parent's kids due to this,
23650 unless it is a class.) */
23651 if (die
->die_parent
)
23652 prune_unused_types_mark (die
->die_parent
,
23653 class_scope_p (die
->die_parent
));
23655 /* Mark any referenced nodes. */
23656 prune_unused_types_walk_attribs (die
);
23658 /* If this node is a specification,
23659 also mark the definition, if it exists. */
23660 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
23661 prune_unused_types_mark (die
->die_definition
, 1);
23664 if (dokids
&& die
->die_mark
!= 2)
23666 /* We need to walk the children, but haven't done so yet.
23667 Remember that we've walked the kids. */
23670 /* If this is an array type, we need to make sure our
23671 kids get marked, even if they're types. If we're
23672 breaking out types into comdat sections, do this
23673 for all type definitions. */
23674 if (die
->die_tag
== DW_TAG_array_type
23675 || (use_debug_types
23676 && is_type_die (die
) && ! is_declaration_die (die
)))
23677 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
23679 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23683 /* For local classes, look if any static member functions were emitted
23684 and if so, mark them. */
23687 prune_unused_types_walk_local_classes (dw_die_ref die
)
23691 if (die
->die_mark
== 2)
23694 switch (die
->die_tag
)
23696 case DW_TAG_structure_type
:
23697 case DW_TAG_union_type
:
23698 case DW_TAG_class_type
:
23701 case DW_TAG_subprogram
:
23702 if (!get_AT_flag (die
, DW_AT_declaration
)
23703 || die
->die_definition
!= NULL
)
23704 prune_unused_types_mark (die
, 1);
23711 /* Mark children. */
23712 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
23715 /* Walk the tree DIE and mark types that we actually use. */
23718 prune_unused_types_walk (dw_die_ref die
)
23722 /* Don't do anything if this node is already marked and
23723 children have been marked as well. */
23724 if (die
->die_mark
== 2)
23727 switch (die
->die_tag
)
23729 case DW_TAG_structure_type
:
23730 case DW_TAG_union_type
:
23731 case DW_TAG_class_type
:
23732 if (die
->die_perennial_p
)
23735 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
23736 if (c
->die_tag
== DW_TAG_subprogram
)
23739 /* Finding used static member functions inside of classes
23740 is needed just for local classes, because for other classes
23741 static member function DIEs with DW_AT_specification
23742 are emitted outside of the DW_TAG_*_type. If we ever change
23743 it, we'd need to call this even for non-local classes. */
23745 prune_unused_types_walk_local_classes (die
);
23747 /* It's a type node --- don't mark it. */
23750 case DW_TAG_const_type
:
23751 case DW_TAG_packed_type
:
23752 case DW_TAG_pointer_type
:
23753 case DW_TAG_reference_type
:
23754 case DW_TAG_rvalue_reference_type
:
23755 case DW_TAG_volatile_type
:
23756 case DW_TAG_typedef
:
23757 case DW_TAG_array_type
:
23758 case DW_TAG_interface_type
:
23759 case DW_TAG_friend
:
23760 case DW_TAG_variant_part
:
23761 case DW_TAG_enumeration_type
:
23762 case DW_TAG_subroutine_type
:
23763 case DW_TAG_string_type
:
23764 case DW_TAG_set_type
:
23765 case DW_TAG_subrange_type
:
23766 case DW_TAG_ptr_to_member_type
:
23767 case DW_TAG_file_type
:
23768 if (die
->die_perennial_p
)
23771 /* It's a type node --- don't mark it. */
23775 /* Mark everything else. */
23779 if (die
->die_mark
== 0)
23783 /* Now, mark any dies referenced from here. */
23784 prune_unused_types_walk_attribs (die
);
23789 /* Mark children. */
23790 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23793 /* Increment the string counts on strings referred to from DIE's
23797 prune_unused_types_update_strings (dw_die_ref die
)
23802 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23803 if (AT_class (a
) == dw_val_class_str
)
23805 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
23807 /* Avoid unnecessarily putting strings that are used less than
23808 twice in the hash table. */
23810 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
23812 indirect_string_node
**slot
23813 = debug_str_hash
->find_slot_with_hash (s
->str
,
23814 htab_hash_string (s
->str
),
23816 gcc_assert (*slot
== NULL
);
23822 /* Remove from the tree DIE any dies that aren't marked. */
23825 prune_unused_types_prune (dw_die_ref die
)
23829 gcc_assert (die
->die_mark
);
23830 prune_unused_types_update_strings (die
);
23832 if (! die
->die_child
)
23835 c
= die
->die_child
;
23837 dw_die_ref prev
= c
;
23838 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
23839 if (c
== die
->die_child
)
23841 /* No marked children between 'prev' and the end of the list. */
23843 /* No marked children at all. */
23844 die
->die_child
= NULL
;
23847 prev
->die_sib
= c
->die_sib
;
23848 die
->die_child
= prev
;
23853 if (c
!= prev
->die_sib
)
23855 prune_unused_types_prune (c
);
23856 } while (c
!= die
->die_child
);
23859 /* Remove dies representing declarations that we never use. */
23862 prune_unused_types (void)
23865 limbo_die_node
*node
;
23866 comdat_type_node
*ctnode
;
23867 pubname_entry
*pub
;
23868 dw_die_ref base_type
;
23870 #if ENABLE_ASSERT_CHECKING
23871 /* All the marks should already be clear. */
23872 verify_marks_clear (comp_unit_die ());
23873 for (node
= limbo_die_list
; node
; node
= node
->next
)
23874 verify_marks_clear (node
->die
);
23875 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23876 verify_marks_clear (ctnode
->root_die
);
23877 #endif /* ENABLE_ASSERT_CHECKING */
23879 /* Mark types that are used in global variables. */
23880 premark_types_used_by_global_vars ();
23882 /* Set the mark on nodes that are actually used. */
23883 prune_unused_types_walk (comp_unit_die ());
23884 for (node
= limbo_die_list
; node
; node
= node
->next
)
23885 prune_unused_types_walk (node
->die
);
23886 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23888 prune_unused_types_walk (ctnode
->root_die
);
23889 prune_unused_types_mark (ctnode
->type_die
, 1);
23892 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
23893 are unusual in that they are pubnames that are the children of pubtypes.
23894 They should only be marked via their parent DW_TAG_enumeration_type die,
23895 not as roots in themselves. */
23896 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
23897 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
23898 prune_unused_types_mark (pub
->die
, 1);
23899 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23900 prune_unused_types_mark (base_type
, 1);
23902 if (debug_str_hash
)
23903 debug_str_hash
->empty ();
23904 if (skeleton_debug_str_hash
)
23905 skeleton_debug_str_hash
->empty ();
23906 prune_unused_types_prune (comp_unit_die ());
23907 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
23910 if (!node
->die
->die_mark
)
23911 *pnode
= node
->next
;
23914 prune_unused_types_prune (node
->die
);
23915 pnode
= &node
->next
;
23918 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23919 prune_unused_types_prune (ctnode
->root_die
);
23921 /* Leave the marks clear. */
23922 prune_unmark_dies (comp_unit_die ());
23923 for (node
= limbo_die_list
; node
; node
= node
->next
)
23924 prune_unmark_dies (node
->die
);
23925 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23926 prune_unmark_dies (ctnode
->root_die
);
23929 /* Set the parameter to true if there are any relative pathnames in
23932 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
23934 struct dwarf_file_data
*d
= *slot
;
23935 if (!IS_ABSOLUTE_PATH (d
->filename
))
23943 /* Helpers to manipulate hash table of comdat type units. */
23945 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
23947 static inline hashval_t
hash (const comdat_type_node
*);
23948 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
23952 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
23955 memcpy (&h
, type_node
->signature
, sizeof (h
));
23960 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
23961 const comdat_type_node
*type_node_2
)
23963 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
23964 DWARF_TYPE_SIGNATURE_SIZE
));
23967 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23968 to the location it would have been added, should we know its
23969 DECL_ASSEMBLER_NAME when we added other attributes. This will
23970 probably improve compactness of debug info, removing equivalent
23971 abbrevs, and hide any differences caused by deferring the
23972 computation of the assembler name, triggered by e.g. PCH. */
23975 move_linkage_attr (dw_die_ref die
)
23977 unsigned ix
= vec_safe_length (die
->die_attr
);
23978 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
23980 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
23981 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
23985 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
23987 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
23991 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
23993 die
->die_attr
->pop ();
23994 die
->die_attr
->quick_insert (ix
, linkage
);
23998 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23999 referenced from typed stack ops and count how often they are used. */
24002 mark_base_types (dw_loc_descr_ref loc
)
24004 dw_die_ref base_type
= NULL
;
24006 for (; loc
; loc
= loc
->dw_loc_next
)
24008 switch (loc
->dw_loc_opc
)
24010 case DW_OP_GNU_regval_type
:
24011 case DW_OP_GNU_deref_type
:
24012 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
24014 case DW_OP_GNU_convert
:
24015 case DW_OP_GNU_reinterpret
:
24016 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
24019 case DW_OP_GNU_const_type
:
24020 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24022 case DW_OP_GNU_entry_value
:
24023 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
24028 gcc_assert (base_type
->die_parent
== comp_unit_die ());
24029 if (base_type
->die_mark
)
24030 base_type
->die_mark
++;
24033 base_types
.safe_push (base_type
);
24034 base_type
->die_mark
= 1;
24039 /* Comparison function for sorting marked base types. */
24042 base_type_cmp (const void *x
, const void *y
)
24044 dw_die_ref dx
= *(const dw_die_ref
*) x
;
24045 dw_die_ref dy
= *(const dw_die_ref
*) y
;
24046 unsigned int byte_size1
, byte_size2
;
24047 unsigned int encoding1
, encoding2
;
24048 if (dx
->die_mark
> dy
->die_mark
)
24050 if (dx
->die_mark
< dy
->die_mark
)
24052 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
24053 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
24054 if (byte_size1
< byte_size2
)
24056 if (byte_size1
> byte_size2
)
24058 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
24059 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
24060 if (encoding1
< encoding2
)
24062 if (encoding1
> encoding2
)
24067 /* Move base types marked by mark_base_types as early as possible
24068 in the CU, sorted by decreasing usage count both to make the
24069 uleb128 references as small as possible and to make sure they
24070 will have die_offset already computed by calc_die_sizes when
24071 sizes of typed stack loc ops is computed. */
24074 move_marked_base_types (void)
24077 dw_die_ref base_type
, die
, c
;
24079 if (base_types
.is_empty ())
24082 /* Sort by decreasing usage count, they will be added again in that
24084 base_types
.qsort (base_type_cmp
);
24085 die
= comp_unit_die ();
24086 c
= die
->die_child
;
24089 dw_die_ref prev
= c
;
24091 while (c
->die_mark
)
24093 remove_child_with_prev (c
, prev
);
24094 /* As base types got marked, there must be at least
24095 one node other than DW_TAG_base_type. */
24096 gcc_assert (c
!= c
->die_sib
);
24100 while (c
!= die
->die_child
);
24101 gcc_assert (die
->die_child
);
24102 c
= die
->die_child
;
24103 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
24105 base_type
->die_mark
= 0;
24106 base_type
->die_sib
= c
->die_sib
;
24107 c
->die_sib
= base_type
;
24112 /* Helper function for resolve_addr, attempt to resolve
24113 one CONST_STRING, return true if successful. Similarly verify that
24114 SYMBOL_REFs refer to variables emitted in the current CU. */
24117 resolve_one_addr (rtx
*addr
)
24121 if (GET_CODE (rtl
) == CONST_STRING
)
24123 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24124 tree t
= build_string (len
, XSTR (rtl
, 0));
24125 tree tlen
= size_int (len
- 1);
24127 = build_array_type (char_type_node
, build_index_type (tlen
));
24128 rtl
= lookup_constant_def (t
);
24129 if (!rtl
|| !MEM_P (rtl
))
24131 rtl
= XEXP (rtl
, 0);
24132 if (GET_CODE (rtl
) == SYMBOL_REF
24133 && SYMBOL_REF_DECL (rtl
)
24134 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24136 vec_safe_push (used_rtx_array
, rtl
);
24141 if (GET_CODE (rtl
) == SYMBOL_REF
24142 && SYMBOL_REF_DECL (rtl
))
24144 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
24146 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
24149 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24153 if (GET_CODE (rtl
) == CONST
)
24155 subrtx_ptr_iterator::array_type array
;
24156 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
24157 if (!resolve_one_addr (*iter
))
24164 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
24165 if possible, and create DW_TAG_dwarf_procedure that can be referenced
24166 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
24169 string_cst_pool_decl (tree t
)
24171 rtx rtl
= output_constant_def (t
, 1);
24172 unsigned char *array
;
24173 dw_loc_descr_ref l
;
24178 if (!rtl
|| !MEM_P (rtl
))
24180 rtl
= XEXP (rtl
, 0);
24181 if (GET_CODE (rtl
) != SYMBOL_REF
24182 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
24185 decl
= SYMBOL_REF_DECL (rtl
);
24186 if (!lookup_decl_die (decl
))
24188 len
= TREE_STRING_LENGTH (t
);
24189 vec_safe_push (used_rtx_array
, rtl
);
24190 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
24191 array
= ggc_vec_alloc
<unsigned char> (len
);
24192 memcpy (array
, TREE_STRING_POINTER (t
), len
);
24193 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
24194 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
24195 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
24196 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
24197 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
24198 add_AT_loc (ref
, DW_AT_location
, l
);
24199 equate_decl_number_to_die (decl
, ref
);
24204 /* Helper function of resolve_addr_in_expr. LOC is
24205 a DW_OP_addr followed by DW_OP_stack_value, either at the start
24206 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
24207 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
24208 with DW_OP_GNU_implicit_pointer if possible
24209 and return true, if unsuccessful, return false. */
24212 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
24214 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
24215 HOST_WIDE_INT offset
= 0;
24216 dw_die_ref ref
= NULL
;
24219 if (GET_CODE (rtl
) == CONST
24220 && GET_CODE (XEXP (rtl
, 0)) == PLUS
24221 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
24223 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
24224 rtl
= XEXP (XEXP (rtl
, 0), 0);
24226 if (GET_CODE (rtl
) == CONST_STRING
)
24228 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24229 tree t
= build_string (len
, XSTR (rtl
, 0));
24230 tree tlen
= size_int (len
- 1);
24233 = build_array_type (char_type_node
, build_index_type (tlen
));
24234 rtl
= string_cst_pool_decl (t
);
24238 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
24240 decl
= SYMBOL_REF_DECL (rtl
);
24241 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
24243 ref
= lookup_decl_die (decl
);
24244 if (ref
&& (get_AT (ref
, DW_AT_location
)
24245 || get_AT (ref
, DW_AT_const_value
)))
24247 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
24248 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24249 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
24250 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24251 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24252 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24253 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
24261 /* Helper function for resolve_addr, handle one location
24262 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24263 the location list couldn't be resolved. */
24266 resolve_addr_in_expr (dw_loc_descr_ref loc
)
24268 dw_loc_descr_ref keep
= NULL
;
24269 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
24270 switch (loc
->dw_loc_opc
)
24273 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24276 || prev
->dw_loc_opc
== DW_OP_piece
24277 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
24278 && loc
->dw_loc_next
24279 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
24281 && optimize_one_addr_into_implicit_ptr (loc
))
24286 case DW_OP_GNU_addr_index
:
24287 case DW_OP_GNU_const_index
:
24288 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
24289 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
24291 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
24292 if (!resolve_one_addr (&rtl
))
24294 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
24295 loc
->dw_loc_oprnd1
.val_entry
=
24296 add_addr_table_entry (rtl
, ate_kind_rtx
);
24299 case DW_OP_const4u
:
24300 case DW_OP_const8u
:
24302 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24305 case DW_OP_plus_uconst
:
24306 if (size_of_loc_descr (loc
)
24307 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
24309 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
24311 dw_loc_descr_ref repl
24312 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
24313 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
24314 add_loc_descr (&repl
, loc
->dw_loc_next
);
24318 case DW_OP_implicit_value
:
24319 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
24320 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
24323 case DW_OP_GNU_implicit_pointer
:
24324 case DW_OP_GNU_parameter_ref
:
24325 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
24328 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
24331 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24332 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24333 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24336 case DW_OP_GNU_const_type
:
24337 case DW_OP_GNU_regval_type
:
24338 case DW_OP_GNU_deref_type
:
24339 case DW_OP_GNU_convert
:
24340 case DW_OP_GNU_reinterpret
:
24341 while (loc
->dw_loc_next
24342 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
24344 dw_die_ref base1
, base2
;
24345 unsigned enc1
, enc2
, size1
, size2
;
24346 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24347 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24348 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
24349 else if (loc
->dw_loc_oprnd1
.val_class
24350 == dw_val_class_unsigned_const
)
24353 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24354 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
24355 == dw_val_class_unsigned_const
)
24357 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24358 gcc_assert (base1
->die_tag
== DW_TAG_base_type
24359 && base2
->die_tag
== DW_TAG_base_type
);
24360 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
24361 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
24362 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
24363 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
24365 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
24366 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
24370 /* Optimize away next DW_OP_GNU_convert after
24371 adjusting LOC's base type die reference. */
24372 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24373 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24374 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
24376 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
24377 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24380 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24381 point typed stack entry. */
24382 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
24383 keep
= loc
->dw_loc_next
;
24393 /* Helper function of resolve_addr. DIE had DW_AT_location of
24394 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
24395 and DW_OP_addr couldn't be resolved. resolve_addr has already
24396 removed the DW_AT_location attribute. This function attempts to
24397 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
24398 to it or DW_AT_const_value attribute, if possible. */
24401 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
24403 if (TREE_CODE (decl
) != VAR_DECL
24404 || lookup_decl_die (decl
) != die
24405 || DECL_EXTERNAL (decl
)
24406 || !TREE_STATIC (decl
)
24407 || DECL_INITIAL (decl
) == NULL_TREE
24408 || DECL_P (DECL_INITIAL (decl
))
24409 || get_AT (die
, DW_AT_const_value
))
24412 tree init
= DECL_INITIAL (decl
);
24413 HOST_WIDE_INT offset
= 0;
24414 /* For variables that have been optimized away and thus
24415 don't have a memory location, see if we can emit
24416 DW_AT_const_value instead. */
24417 if (tree_add_const_value_attribute (die
, init
))
24421 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
24422 and ADDR_EXPR refers to a decl that has DW_AT_location or
24423 DW_AT_const_value (but isn't addressable, otherwise
24424 resolving the original DW_OP_addr wouldn't fail), see if
24425 we can add DW_OP_GNU_implicit_pointer. */
24427 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
24428 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
24430 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
24431 init
= TREE_OPERAND (init
, 0);
24434 if (TREE_CODE (init
) != ADDR_EXPR
)
24436 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
24437 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
24438 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
24439 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
24440 && TREE_OPERAND (init
, 0) != decl
))
24443 dw_loc_descr_ref l
;
24445 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
24447 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
24450 decl
= SYMBOL_REF_DECL (rtl
);
24453 decl
= TREE_OPERAND (init
, 0);
24454 ref
= lookup_decl_die (decl
);
24456 || (!get_AT (ref
, DW_AT_location
)
24457 && !get_AT (ref
, DW_AT_const_value
)))
24459 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
24460 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24461 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24462 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24463 add_AT_loc (die
, DW_AT_location
, l
);
24467 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24468 an address in .rodata section if the string literal is emitted there,
24469 or remove the containing location list or replace DW_AT_const_value
24470 with DW_AT_location and empty location expression, if it isn't found
24471 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24472 to something that has been emitted in the current CU. */
24475 resolve_addr (dw_die_ref die
)
24479 dw_loc_list_ref
*curr
, *start
, loc
;
24482 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24483 switch (AT_class (a
))
24485 case dw_val_class_loc_list
:
24486 start
= curr
= AT_loc_list_ptr (a
);
24489 /* The same list can be referenced more than once. See if we have
24490 already recorded the result from a previous pass. */
24492 *curr
= loc
->dw_loc_next
;
24493 else if (!loc
->resolved_addr
)
24495 /* As things stand, we do not expect or allow one die to
24496 reference a suffix of another die's location list chain.
24497 References must be identical or completely separate.
24498 There is therefore no need to cache the result of this
24499 pass on any list other than the first; doing so
24500 would lead to unnecessary writes. */
24503 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
24504 if (!resolve_addr_in_expr ((*curr
)->expr
))
24506 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
24507 dw_loc_descr_ref l
= (*curr
)->expr
;
24509 if (next
&& (*curr
)->ll_symbol
)
24511 gcc_assert (!next
->ll_symbol
);
24512 next
->ll_symbol
= (*curr
)->ll_symbol
;
24514 if (dwarf_split_debug_info
)
24515 remove_loc_list_addr_table_entries (l
);
24520 mark_base_types ((*curr
)->expr
);
24521 curr
= &(*curr
)->dw_loc_next
;
24525 loc
->resolved_addr
= 1;
24529 loc
->dw_loc_next
= *start
;
24534 remove_AT (die
, a
->dw_attr
);
24538 case dw_val_class_loc
:
24540 dw_loc_descr_ref l
= AT_loc (a
);
24541 /* For -gdwarf-2 don't attempt to optimize
24542 DW_AT_data_member_location containing
24543 DW_OP_plus_uconst - older consumers might
24544 rely on it being that op instead of a more complex,
24545 but shorter, location description. */
24546 if ((dwarf_version
> 2
24547 || a
->dw_attr
!= DW_AT_data_member_location
24549 || l
->dw_loc_opc
!= DW_OP_plus_uconst
24550 || l
->dw_loc_next
!= NULL
)
24551 && !resolve_addr_in_expr (l
))
24553 if (dwarf_split_debug_info
)
24554 remove_loc_list_addr_table_entries (l
);
24556 && l
->dw_loc_next
== NULL
24557 && l
->dw_loc_opc
== DW_OP_addr
24558 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
24559 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
24560 && a
->dw_attr
== DW_AT_location
)
24562 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
24563 remove_AT (die
, a
->dw_attr
);
24565 optimize_location_into_implicit_ptr (die
, decl
);
24568 remove_AT (die
, a
->dw_attr
);
24572 mark_base_types (l
);
24575 case dw_val_class_addr
:
24576 if (a
->dw_attr
== DW_AT_const_value
24577 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
24579 if (AT_index (a
) != NOT_INDEXED
)
24580 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24581 remove_AT (die
, a
->dw_attr
);
24584 if (die
->die_tag
== DW_TAG_GNU_call_site
24585 && a
->dw_attr
== DW_AT_abstract_origin
)
24587 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
24588 dw_die_ref tdie
= lookup_decl_die (tdecl
);
24591 && DECL_EXTERNAL (tdecl
)
24592 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
24593 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
24595 /* Creating a full DIE for tdecl is overly expensive and
24596 at this point even wrong when in the LTO phase
24597 as it can end up generating new type DIEs we didn't
24598 output and thus optimize_external_refs will crash. */
24599 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
24600 add_AT_flag (tdie
, DW_AT_external
, 1);
24601 add_AT_flag (tdie
, DW_AT_declaration
, 1);
24602 add_linkage_attr (tdie
, tdecl
);
24603 add_name_and_src_coords_attributes (tdie
, tdecl
);
24604 equate_decl_number_to_die (tdecl
, tdie
);
24608 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
24609 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
24610 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
24614 if (AT_index (a
) != NOT_INDEXED
)
24615 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24616 remove_AT (die
, a
->dw_attr
);
24625 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
24628 /* Helper routines for optimize_location_lists.
24629 This pass tries to share identical local lists in .debug_loc
24632 /* Iteratively hash operands of LOC opcode into HSTATE. */
24635 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24637 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
24638 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
24640 switch (loc
->dw_loc_opc
)
24642 case DW_OP_const4u
:
24643 case DW_OP_const8u
:
24647 case DW_OP_const1u
:
24648 case DW_OP_const1s
:
24649 case DW_OP_const2u
:
24650 case DW_OP_const2s
:
24651 case DW_OP_const4s
:
24652 case DW_OP_const8s
:
24656 case DW_OP_plus_uconst
:
24692 case DW_OP_deref_size
:
24693 case DW_OP_xderef_size
:
24694 hstate
.add_object (val1
->v
.val_int
);
24701 gcc_assert (val1
->val_class
== dw_val_class_loc
);
24702 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
24703 hstate
.add_object (offset
);
24706 case DW_OP_implicit_value
:
24707 hstate
.add_object (val1
->v
.val_unsigned
);
24708 switch (val2
->val_class
)
24710 case dw_val_class_const
:
24711 hstate
.add_object (val2
->v
.val_int
);
24713 case dw_val_class_vec
:
24715 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24716 unsigned int len
= val2
->v
.val_vec
.length
;
24718 hstate
.add_int (elt_size
);
24719 hstate
.add_int (len
);
24720 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24723 case dw_val_class_const_double
:
24724 hstate
.add_object (val2
->v
.val_double
.low
);
24725 hstate
.add_object (val2
->v
.val_double
.high
);
24727 case dw_val_class_wide_int
:
24728 hstate
.add (val2
->v
.val_wide
->get_val (),
24729 get_full_len (*val2
->v
.val_wide
)
24730 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24732 case dw_val_class_addr
:
24733 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
24736 gcc_unreachable ();
24740 case DW_OP_bit_piece
:
24741 hstate
.add_object (val1
->v
.val_int
);
24742 hstate
.add_object (val2
->v
.val_int
);
24748 unsigned char dtprel
= 0xd1;
24749 hstate
.add_object (dtprel
);
24751 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
24753 case DW_OP_GNU_addr_index
:
24754 case DW_OP_GNU_const_index
:
24758 unsigned char dtprel
= 0xd1;
24759 hstate
.add_object (dtprel
);
24761 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
24764 case DW_OP_GNU_implicit_pointer
:
24765 hstate
.add_int (val2
->v
.val_int
);
24767 case DW_OP_GNU_entry_value
:
24768 hstate
.add_object (val1
->v
.val_loc
);
24770 case DW_OP_GNU_regval_type
:
24771 case DW_OP_GNU_deref_type
:
24773 unsigned int byte_size
24774 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24775 unsigned int encoding
24776 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
24777 hstate
.add_object (val1
->v
.val_int
);
24778 hstate
.add_object (byte_size
);
24779 hstate
.add_object (encoding
);
24782 case DW_OP_GNU_convert
:
24783 case DW_OP_GNU_reinterpret
:
24784 if (val1
->val_class
== dw_val_class_unsigned_const
)
24786 hstate
.add_object (val1
->v
.val_unsigned
);
24790 case DW_OP_GNU_const_type
:
24792 unsigned int byte_size
24793 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24794 unsigned int encoding
24795 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
24796 hstate
.add_object (byte_size
);
24797 hstate
.add_object (encoding
);
24798 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
24800 hstate
.add_object (val2
->val_class
);
24801 switch (val2
->val_class
)
24803 case dw_val_class_const
:
24804 hstate
.add_object (val2
->v
.val_int
);
24806 case dw_val_class_vec
:
24808 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24809 unsigned int len
= val2
->v
.val_vec
.length
;
24811 hstate
.add_object (elt_size
);
24812 hstate
.add_object (len
);
24813 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24816 case dw_val_class_const_double
:
24817 hstate
.add_object (val2
->v
.val_double
.low
);
24818 hstate
.add_object (val2
->v
.val_double
.high
);
24820 case dw_val_class_wide_int
:
24821 hstate
.add (val2
->v
.val_wide
->get_val (),
24822 get_full_len (*val2
->v
.val_wide
)
24823 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24826 gcc_unreachable ();
24832 /* Other codes have no operands. */
24837 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
24840 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24842 dw_loc_descr_ref l
;
24843 bool sizes_computed
= false;
24844 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24845 size_of_locs (loc
);
24847 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
24849 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
24850 hstate
.add_object (opc
);
24851 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
24853 size_of_locs (loc
);
24854 sizes_computed
= true;
24856 hash_loc_operands (l
, hstate
);
24860 /* Compute hash of the whole location list LIST_HEAD. */
24863 hash_loc_list (dw_loc_list_ref list_head
)
24865 dw_loc_list_ref curr
= list_head
;
24866 inchash::hash hstate
;
24868 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24870 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
24871 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
24873 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
24874 hash_locs (curr
->expr
, hstate
);
24876 list_head
->hash
= hstate
.end ();
24879 /* Return true if X and Y opcodes have the same operands. */
24882 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24884 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
24885 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
24886 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
24887 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
24889 switch (x
->dw_loc_opc
)
24891 case DW_OP_const4u
:
24892 case DW_OP_const8u
:
24896 case DW_OP_const1u
:
24897 case DW_OP_const1s
:
24898 case DW_OP_const2u
:
24899 case DW_OP_const2s
:
24900 case DW_OP_const4s
:
24901 case DW_OP_const8s
:
24905 case DW_OP_plus_uconst
:
24941 case DW_OP_deref_size
:
24942 case DW_OP_xderef_size
:
24943 return valx1
->v
.val_int
== valy1
->v
.val_int
;
24946 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24947 can cause irrelevant differences in dw_loc_addr. */
24948 gcc_assert (valx1
->val_class
== dw_val_class_loc
24949 && valy1
->val_class
== dw_val_class_loc
24950 && (dwarf_split_debug_info
24951 || x
->dw_loc_addr
== y
->dw_loc_addr
));
24952 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
24953 case DW_OP_implicit_value
:
24954 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
24955 || valx2
->val_class
!= valy2
->val_class
)
24957 switch (valx2
->val_class
)
24959 case dw_val_class_const
:
24960 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24961 case dw_val_class_vec
:
24962 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24963 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24964 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24965 valx2
->v
.val_vec
.elt_size
24966 * valx2
->v
.val_vec
.length
) == 0;
24967 case dw_val_class_const_double
:
24968 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24969 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24970 case dw_val_class_wide_int
:
24971 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24972 case dw_val_class_addr
:
24973 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
24975 gcc_unreachable ();
24978 case DW_OP_bit_piece
:
24979 return valx1
->v
.val_int
== valy1
->v
.val_int
24980 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24983 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
24984 case DW_OP_GNU_addr_index
:
24985 case DW_OP_GNU_const_index
:
24987 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
24988 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
24989 return rtx_equal_p (ax1
, ay1
);
24991 case DW_OP_GNU_implicit_pointer
:
24992 return valx1
->val_class
== dw_val_class_die_ref
24993 && valx1
->val_class
== valy1
->val_class
24994 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
24995 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24996 case DW_OP_GNU_entry_value
:
24997 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
24998 case DW_OP_GNU_const_type
:
24999 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
25000 || valx2
->val_class
!= valy2
->val_class
)
25002 switch (valx2
->val_class
)
25004 case dw_val_class_const
:
25005 return valx2
->v
.val_int
== valy2
->v
.val_int
;
25006 case dw_val_class_vec
:
25007 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
25008 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
25009 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
25010 valx2
->v
.val_vec
.elt_size
25011 * valx2
->v
.val_vec
.length
) == 0;
25012 case dw_val_class_const_double
:
25013 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
25014 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
25015 case dw_val_class_wide_int
:
25016 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
25018 gcc_unreachable ();
25020 case DW_OP_GNU_regval_type
:
25021 case DW_OP_GNU_deref_type
:
25022 return valx1
->v
.val_int
== valy1
->v
.val_int
25023 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
25024 case DW_OP_GNU_convert
:
25025 case DW_OP_GNU_reinterpret
:
25026 if (valx1
->val_class
!= valy1
->val_class
)
25028 if (valx1
->val_class
== dw_val_class_unsigned_const
)
25029 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
25030 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
25031 case DW_OP_GNU_parameter_ref
:
25032 return valx1
->val_class
== dw_val_class_die_ref
25033 && valx1
->val_class
== valy1
->val_class
25034 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
25036 /* Other codes have no operands. */
25041 /* Return true if DWARF location expressions X and Y are the same. */
25044 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
25046 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
25047 if (x
->dw_loc_opc
!= y
->dw_loc_opc
25048 || x
->dtprel
!= y
->dtprel
25049 || !compare_loc_operands (x
, y
))
25051 return x
== NULL
&& y
== NULL
;
25054 /* Hashtable helpers. */
25056 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
25058 static inline hashval_t
hash (const dw_loc_list_struct
*);
25059 static inline bool equal (const dw_loc_list_struct
*,
25060 const dw_loc_list_struct
*);
25063 /* Return precomputed hash of location list X. */
25066 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
25071 /* Return true if location lists A and B are the same. */
25074 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
25075 const dw_loc_list_struct
*b
)
25079 if (a
->hash
!= b
->hash
)
25081 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
25082 if (strcmp (a
->begin
, b
->begin
) != 0
25083 || strcmp (a
->end
, b
->end
) != 0
25084 || (a
->section
== NULL
) != (b
->section
== NULL
)
25085 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
25086 || !compare_locs (a
->expr
, b
->expr
))
25088 return a
== NULL
&& b
== NULL
;
25091 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
25094 /* Recursively optimize location lists referenced from DIE
25095 children and share them whenever possible. */
25098 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
25103 dw_loc_list_struct
**slot
;
25105 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25106 if (AT_class (a
) == dw_val_class_loc_list
)
25108 dw_loc_list_ref list
= AT_loc_list (a
);
25109 /* TODO: perform some optimizations here, before hashing
25110 it and storing into the hash table. */
25111 hash_loc_list (list
);
25112 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
25116 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
25119 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
25123 /* Recursively assign each location list a unique index into the debug_addr
25127 index_location_lists (dw_die_ref die
)
25133 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25134 if (AT_class (a
) == dw_val_class_loc_list
)
25136 dw_loc_list_ref list
= AT_loc_list (a
);
25137 dw_loc_list_ref curr
;
25138 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
25140 /* Don't index an entry that has already been indexed
25141 or won't be output. */
25142 if (curr
->begin_entry
!= NULL
25143 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
25147 = add_addr_table_entry (xstrdup (curr
->begin
),
25152 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
25155 /* Optimize location lists referenced from DIE
25156 children and share them whenever possible. */
25159 optimize_location_lists (dw_die_ref die
)
25161 loc_list_hash_type
htab (500);
25162 optimize_location_lists_1 (die
, &htab
);
25165 /* Traverse the limbo die list, and add parent/child links. The only
25166 dies without parents that should be here are concrete instances of
25167 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25168 For concrete instances, we can get the parent die from the abstract
25172 flush_limbo_die_list (void)
25174 limbo_die_node
*node
, *next_node
;
25176 for (node
= limbo_die_list
; node
; node
= next_node
)
25178 dw_die_ref die
= node
->die
;
25179 next_node
= node
->next
;
25181 if (die
->die_parent
== NULL
)
25183 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
25185 if (origin
&& origin
->die_parent
)
25186 add_child_die (origin
->die_parent
, die
);
25187 else if (is_cu_die (die
))
25189 else if (seen_error ())
25190 /* It's OK to be confused by errors in the input. */
25191 add_child_die (comp_unit_die (), die
);
25194 /* In certain situations, the lexical block containing a
25195 nested function can be optimized away, which results
25196 in the nested function die being orphaned. Likewise
25197 with the return type of that nested function. Force
25198 this to be a child of the containing function.
25200 It may happen that even the containing function got fully
25201 inlined and optimized out. In that case we are lost and
25202 assign the empty child. This should not be big issue as
25203 the function is likely unreachable too. */
25204 gcc_assert (node
->created_for
);
25206 if (DECL_P (node
->created_for
))
25207 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
25208 else if (TYPE_P (node
->created_for
))
25209 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
25211 origin
= comp_unit_die ();
25213 add_child_die (origin
, die
);
25218 limbo_die_list
= NULL
;
25221 /* Output stuff that dwarf requires at the end of every file,
25222 and generate the DWARF-2 debugging info. */
25225 dwarf2out_finish (const char *filename
)
25227 comdat_type_node
*ctnode
;
25228 dw_die_ref main_comp_unit_die
;
25230 /* Flush out any latecomers to the limbo party. */
25231 flush_limbo_die_list ();
25233 /* We shouldn't have any symbols with delayed asm names for
25234 DIEs generated after early finish. */
25235 gcc_assert (deferred_asm_name
== NULL
);
25237 /* PCH might result in DW_AT_producer string being restored from the
25238 header compilation, so always fill it with empty string initially
25239 and overwrite only here. */
25240 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
25241 producer_string
= gen_producer_string ();
25242 producer
->dw_attr_val
.v
.val_str
->refcount
--;
25243 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
25245 gen_remaining_tmpl_value_param_die_attribute ();
25247 /* Add the name for the main input file now. We delayed this from
25248 dwarf2out_init to avoid complications with PCH.
25249 For LTO produced units use a fixed artificial name to avoid
25250 leaking tempfile names into the dwarf. */
25252 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
25254 add_name_attribute (comp_unit_die (), "<artificial>");
25255 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
25256 add_comp_dir_attribute (comp_unit_die ());
25257 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
25260 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
25262 add_comp_dir_attribute (comp_unit_die ());
25265 #if ENABLE_ASSERT_CHECKING
25267 dw_die_ref die
= comp_unit_die (), c
;
25268 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
25271 resolve_addr (comp_unit_die ());
25272 move_marked_base_types ();
25274 /* Walk through the list of incomplete types again, trying once more to
25275 emit full debugging info for them. */
25276 retry_incomplete_types ();
25278 if (flag_eliminate_unused_debug_types
)
25279 prune_unused_types ();
25281 /* Generate separate COMDAT sections for type DIEs. */
25282 if (use_debug_types
)
25284 break_out_comdat_types (comp_unit_die ());
25286 /* Each new type_unit DIE was added to the limbo die list when created.
25287 Since these have all been added to comdat_type_list, clear the
25289 limbo_die_list
= NULL
;
25291 /* For each new comdat type unit, copy declarations for incomplete
25292 types to make the new unit self-contained (i.e., no direct
25293 references to the main compile unit). */
25294 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25295 copy_decls_for_unworthy_types (ctnode
->root_die
);
25296 copy_decls_for_unworthy_types (comp_unit_die ());
25298 /* In the process of copying declarations from one unit to another,
25299 we may have left some declarations behind that are no longer
25300 referenced. Prune them. */
25301 prune_unused_types ();
25304 /* Generate separate CUs for each of the include files we've seen.
25305 They will go into limbo_die_list. */
25306 if (flag_eliminate_dwarf2_dups
)
25307 break_out_includes (comp_unit_die ());
25309 /* Traverse the DIE's and add sibling attributes to those DIE's that
25311 add_sibling_attributes (comp_unit_die ());
25312 limbo_die_node
*node
;
25313 for (node
= limbo_die_list
; node
; node
= node
->next
)
25314 add_sibling_attributes (node
->die
);
25315 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25316 add_sibling_attributes (ctnode
->root_die
);
25318 /* When splitting DWARF info, we put some attributes in the
25319 skeleton compile_unit DIE that remains in the .o, while
25320 most attributes go in the DWO compile_unit_die. */
25321 if (dwarf_split_debug_info
)
25322 main_comp_unit_die
= gen_compile_unit_die (NULL
);
25324 main_comp_unit_die
= comp_unit_die ();
25326 /* Output a terminator label for the .text section. */
25327 switch_to_section (text_section
);
25328 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
25329 if (cold_text_section
)
25331 switch_to_section (cold_text_section
);
25332 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
25335 /* We can only use the low/high_pc attributes if all of the code was
25337 if (!have_multiple_function_sections
25338 || (dwarf_version
< 3 && dwarf_strict
))
25340 /* Don't add if the CU has no associated code. */
25341 if (text_section_used
)
25342 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
25343 text_end_label
, true);
25349 bool range_list_added
= false;
25351 if (text_section_used
)
25352 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
25353 text_end_label
, &range_list_added
, true);
25354 if (cold_text_section_used
)
25355 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
25356 cold_end_label
, &range_list_added
, true);
25358 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
25360 if (DECL_IGNORED_P (fde
->decl
))
25362 if (!fde
->in_std_section
)
25363 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
25364 fde
->dw_fde_end
, &range_list_added
,
25366 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
25367 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
25368 fde
->dw_fde_second_end
, &range_list_added
,
25372 if (range_list_added
)
25374 /* We need to give .debug_loc and .debug_ranges an appropriate
25375 "base address". Use zero so that these addresses become
25376 absolute. Historically, we've emitted the unexpected
25377 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25378 Emit both to give time for other tools to adapt. */
25379 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
25380 if (! dwarf_strict
&& dwarf_version
< 4)
25381 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
25387 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25388 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
25389 debug_line_section_label
);
25392 add_AT_macptr (comp_unit_die (),
25393 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
25394 macinfo_section_label
);
25396 if (dwarf_split_debug_info
)
25398 /* optimize_location_lists calculates the size of the lists,
25399 so index them first, and assign indices to the entries.
25400 Although optimize_location_lists will remove entries from
25401 the table, it only does so for duplicates, and therefore
25402 only reduces ref_counts to 1. */
25403 index_location_lists (comp_unit_die ());
25405 if (addr_index_table
!= NULL
)
25407 unsigned int index
= 0;
25409 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
25414 if (have_location_lists
)
25415 optimize_location_lists (comp_unit_die ());
25417 save_macinfo_strings ();
25419 if (dwarf_split_debug_info
)
25421 unsigned int index
= 0;
25423 /* Add attributes common to skeleton compile_units and
25424 type_units. Because these attributes include strings, it
25425 must be done before freezing the string table. Top-level
25426 skeleton die attrs are added when the skeleton type unit is
25427 created, so ensure it is created by this point. */
25428 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
25429 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
25432 /* Output all of the compilation units. We put the main one last so that
25433 the offsets are available to output_pubnames. */
25434 for (node
= limbo_die_list
; node
; node
= node
->next
)
25435 output_comp_unit (node
->die
, 0);
25437 hash_table
<comdat_type_hasher
> comdat_type_table (100);
25438 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25440 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
25442 /* Don't output duplicate types. */
25443 if (*slot
!= HTAB_EMPTY_ENTRY
)
25446 /* Add a pointer to the line table for the main compilation unit
25447 so that the debugger can make sense of DW_AT_decl_file
25449 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25450 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
25451 (!dwarf_split_debug_info
25452 ? debug_line_section_label
25453 : debug_skeleton_line_section_label
));
25455 output_comdat_type_unit (ctnode
);
25459 /* The AT_pubnames attribute needs to go in all skeleton dies, including
25460 both the main_cu and all skeleton TUs. Making this call unconditional
25461 would end up either adding a second copy of the AT_pubnames attribute, or
25462 requiring a special case in add_top_level_skeleton_die_attrs. */
25463 if (!dwarf_split_debug_info
)
25464 add_AT_pubnames (comp_unit_die ());
25466 if (dwarf_split_debug_info
)
25469 unsigned char checksum
[16];
25470 struct md5_ctx ctx
;
25472 /* Compute a checksum of the comp_unit to use as the dwo_id. */
25473 md5_init_ctx (&ctx
);
25475 die_checksum (comp_unit_die (), &ctx
, &mark
);
25476 unmark_all_dies (comp_unit_die ());
25477 md5_finish_ctx (&ctx
, checksum
);
25479 /* Use the first 8 bytes of the checksum as the dwo_id,
25480 and add it to both comp-unit DIEs. */
25481 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
25482 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
25484 /* Add the base offset of the ranges table to the skeleton
25486 if (ranges_table_in_use
)
25487 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
25488 ranges_section_label
);
25490 switch_to_section (debug_addr_section
);
25491 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
25492 output_addr_table ();
25495 /* Output the main compilation unit if non-empty or if .debug_macinfo
25496 or .debug_macro will be emitted. */
25497 output_comp_unit (comp_unit_die (), have_macinfo
);
25499 if (dwarf_split_debug_info
&& info_section_emitted
)
25500 output_skeleton_debug_sections (main_comp_unit_die
);
25502 /* Output the abbreviation table. */
25503 if (abbrev_die_table_in_use
!= 1)
25505 switch_to_section (debug_abbrev_section
);
25506 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
25507 output_abbrev_section ();
25510 /* Output location list section if necessary. */
25511 if (have_location_lists
)
25513 /* Output the location lists info. */
25514 switch_to_section (debug_loc_section
);
25515 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
25516 output_location_lists (comp_unit_die ());
25519 output_pubtables ();
25521 /* Output the address range information if a CU (.debug_info section)
25522 was emitted. We output an empty table even if we had no functions
25523 to put in it. This because the consumer has no way to tell the
25524 difference between an empty table that we omitted and failure to
25525 generate a table that would have contained data. */
25526 if (info_section_emitted
)
25528 switch_to_section (debug_aranges_section
);
25532 /* Output ranges section if necessary. */
25533 if (ranges_table_in_use
)
25535 switch_to_section (debug_ranges_section
);
25536 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
25540 /* Have to end the macro section. */
25543 switch_to_section (debug_macinfo_section
);
25544 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
25546 dw2_asm_output_data (1, 0, "End compilation unit");
25549 /* Output the source line correspondence table. We must do this
25550 even if there is no line information. Otherwise, on an empty
25551 translation unit, we will generate a present, but empty,
25552 .debug_info section. IRIX 6.5 `nm' will then complain when
25553 examining the file. This is done late so that any filenames
25554 used by the debug_info section are marked as 'used'. */
25555 switch_to_section (debug_line_section
);
25556 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
25557 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
25558 output_line_info (false);
25560 if (dwarf_split_debug_info
&& info_section_emitted
)
25562 switch_to_section (debug_skeleton_line_section
);
25563 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
25564 output_line_info (true);
25567 /* If we emitted any indirect strings, output the string table too. */
25568 if (debug_str_hash
|| skeleton_debug_str_hash
)
25569 output_indirect_strings ();
25572 /* Perform any cleanups needed after the early debug generation pass
25576 dwarf2out_early_finish (void)
25578 limbo_die_node
*node
;
25580 /* Add DW_AT_linkage_name for all deferred DIEs. */
25581 for (node
= deferred_asm_name
; node
; node
= node
->next
)
25583 tree decl
= node
->created_for
;
25584 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
25585 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
25586 ended up in deferred_asm_name before we knew it was
25587 constant and never written to disk. */
25588 && DECL_ASSEMBLER_NAME (decl
))
25590 add_linkage_attr (node
->die
, decl
);
25591 move_linkage_attr (node
->die
);
25594 deferred_asm_name
= NULL
;
25596 /* The point here is to flush out the limbo list so that it is empty
25597 and we don't need to stream it for LTO. */
25598 flush_limbo_die_list ();
25600 gen_scheduled_generic_parms_dies ();
25601 gen_remaining_tmpl_value_param_die_attribute ();
25604 /* Reset all state within dwarf2out.c so that we can rerun the compiler
25605 within the same process. For use by toplev::finalize. */
25608 dwarf2out_c_finalize (void)
25610 last_var_location_insn
= NULL
;
25611 cached_next_real_insn
= NULL
;
25612 used_rtx_array
= NULL
;
25613 incomplete_types
= NULL
;
25614 decl_scope_table
= NULL
;
25615 debug_info_section
= NULL
;
25616 debug_skeleton_info_section
= NULL
;
25617 debug_abbrev_section
= NULL
;
25618 debug_skeleton_abbrev_section
= NULL
;
25619 debug_aranges_section
= NULL
;
25620 debug_addr_section
= NULL
;
25621 debug_macinfo_section
= NULL
;
25622 debug_line_section
= NULL
;
25623 debug_skeleton_line_section
= NULL
;
25624 debug_loc_section
= NULL
;
25625 debug_pubnames_section
= NULL
;
25626 debug_pubtypes_section
= NULL
;
25627 debug_str_section
= NULL
;
25628 debug_str_dwo_section
= NULL
;
25629 debug_str_offsets_section
= NULL
;
25630 debug_ranges_section
= NULL
;
25631 debug_frame_section
= NULL
;
25633 debug_str_hash
= NULL
;
25634 skeleton_debug_str_hash
= NULL
;
25635 dw2_string_counter
= 0;
25636 have_multiple_function_sections
= false;
25637 text_section_used
= false;
25638 cold_text_section_used
= false;
25639 cold_text_section
= NULL
;
25640 current_unit_personality
= NULL
;
25642 next_die_offset
= 0;
25643 single_comp_unit_die
= NULL
;
25644 comdat_type_list
= NULL
;
25645 limbo_die_list
= NULL
;
25647 decl_die_table
= NULL
;
25648 common_block_die_table
= NULL
;
25649 decl_loc_table
= NULL
;
25650 call_arg_locations
= NULL
;
25651 call_arg_loc_last
= NULL
;
25652 call_site_count
= -1;
25653 tail_call_site_count
= -1;
25654 cached_dw_loc_list_table
= NULL
;
25655 abbrev_die_table
= NULL
;
25656 abbrev_die_table_allocated
= 0;
25657 abbrev_die_table_in_use
= 0;
25658 line_info_label_num
= 0;
25659 cur_line_info_table
= NULL
;
25660 text_section_line_info
= NULL
;
25661 cold_text_section_line_info
= NULL
;
25662 separate_line_info
= NULL
;
25663 info_section_emitted
= false;
25664 pubname_table
= NULL
;
25665 pubtype_table
= NULL
;
25666 macinfo_table
= NULL
;
25667 ranges_table
= NULL
;
25668 ranges_table_allocated
= 0;
25669 ranges_table_in_use
= 0;
25670 ranges_by_label
= 0;
25671 ranges_by_label_allocated
= 0;
25672 ranges_by_label_in_use
= 0;
25673 have_location_lists
= false;
25676 last_emitted_file
= NULL
;
25678 tmpl_value_parm_die_table
= NULL
;
25679 generic_type_instances
= NULL
;
25680 frame_pointer_fb_offset
= 0;
25681 frame_pointer_fb_offset_valid
= false;
25682 base_types
.release ();
25683 XDELETEVEC (producer_string
);
25684 producer_string
= NULL
;
25687 #include "gt-dwarf2out.h"