1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
62 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
77 #include "dwarf2out.h"
78 #include "dwarf2asm.h"
83 #include "diagnostic.h"
84 #include "tree-pretty-print.h"
87 #include "common/common-target.h"
88 #include "langhooks.h"
98 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn
;
100 static rtx cached_next_real_insn
;
102 #ifdef VMS_DEBUGGING_INFO
103 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
105 /* Define this macro to be a nonzero value if the directory specifications
106 which are output in the debug info should end with a separator. */
107 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
108 /* Define this macro to evaluate to a nonzero value if GCC should refrain
109 from generating indirect strings in DWARF2 debug information, for instance
110 if your target is stuck with an old version of GDB that is unable to
111 process them properly or uses VMS Debug. */
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
118 /* ??? Poison these here until it can be done generically. They've been
119 totally replaced in this file; make sure it stays that way. */
120 #undef DWARF2_UNWIND_INFO
121 #undef DWARF2_FRAME_INFO
122 #if (GCC_VERSION >= 3000)
123 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
126 /* The size of the target's pointer type. */
128 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
131 /* Array of RTXes referenced by the debugging information, which therefore
132 must be kept around forever. */
133 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
135 /* A pointer to the base of a list of incomplete types which might be
136 completed at some later time. incomplete_types_list needs to be a
137 vec<tree, va_gc> *because we want to tell the garbage collector about
139 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
141 /* A pointer to the base of a table of references to declaration
142 scopes. This table is a display which tracks the nesting
143 of declaration scopes at the current scope and containing
144 scopes. This table is used to find the proper place to
145 define type declaration DIE's. */
146 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
148 /* Pointers to various DWARF2 sections. */
149 static GTY(()) section
*debug_info_section
;
150 static GTY(()) section
*debug_skeleton_info_section
;
151 static GTY(()) section
*debug_abbrev_section
;
152 static GTY(()) section
*debug_skeleton_abbrev_section
;
153 static GTY(()) section
*debug_aranges_section
;
154 static GTY(()) section
*debug_addr_section
;
155 static GTY(()) section
*debug_macinfo_section
;
156 static GTY(()) section
*debug_line_section
;
157 static GTY(()) section
*debug_skeleton_line_section
;
158 static GTY(()) section
*debug_loc_section
;
159 static GTY(()) section
*debug_pubnames_section
;
160 static GTY(()) section
*debug_pubtypes_section
;
161 static GTY(()) section
*debug_str_section
;
162 static GTY(()) section
*debug_str_offsets_section
;
163 static GTY(()) section
*debug_ranges_section
;
164 static GTY(()) section
*debug_frame_section
;
166 /* Maximum size (in bytes) of an artificially generated label. */
167 #define MAX_ARTIFICIAL_LABEL_BYTES 30
169 /* According to the (draft) DWARF 3 specification, the initial length
170 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
171 bytes are 0xffffffff, followed by the length stored in the next 8
174 However, the SGI/MIPS ABI uses an initial length which is equal to
175 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
177 #ifndef DWARF_INITIAL_LENGTH_SIZE
178 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
181 /* Round SIZE up to the nearest BOUNDARY. */
182 #define DWARF_ROUND(SIZE,BOUNDARY) \
183 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
185 /* CIE identifier. */
186 #if HOST_BITS_PER_WIDE_INT >= 64
187 #define DWARF_CIE_ID \
188 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
190 #define DWARF_CIE_ID DW_CIE_ID
194 /* A vector for a table that contains frame description
195 information for each routine. */
196 #define NOT_INDEXED (-1U)
197 #define NO_INDEX_ASSIGNED (-2U)
199 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
201 struct GTY(()) indirect_string_node
{
203 unsigned int refcount
;
204 enum dwarf_form form
;
209 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
211 static GTY(()) int dw2_string_counter
;
213 /* True if the compilation unit places functions in more than one section. */
214 static GTY(()) bool have_multiple_function_sections
= false;
216 /* Whether the default text and cold text sections have been used at all. */
218 static GTY(()) bool text_section_used
= false;
219 static GTY(()) bool cold_text_section_used
= false;
221 /* The default cold text section. */
222 static GTY(()) section
*cold_text_section
;
224 /* Forward declarations for functions defined in this file. */
226 static char *stripattributes (const char *);
227 static void output_call_frame_info (int);
228 static void dwarf2out_note_section_used (void);
230 /* Personality decl of current unit. Used only when assembler does not support
232 static GTY(()) rtx current_unit_personality
;
234 /* Data and reference forms for relocatable data. */
235 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
236 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
238 #ifndef DEBUG_FRAME_SECTION
239 #define DEBUG_FRAME_SECTION ".debug_frame"
242 #ifndef FUNC_BEGIN_LABEL
243 #define FUNC_BEGIN_LABEL "LFB"
246 #ifndef FUNC_END_LABEL
247 #define FUNC_END_LABEL "LFE"
250 #ifndef PROLOGUE_END_LABEL
251 #define PROLOGUE_END_LABEL "LPE"
254 #ifndef EPILOGUE_BEGIN_LABEL
255 #define EPILOGUE_BEGIN_LABEL "LEB"
258 #ifndef FRAME_BEGIN_LABEL
259 #define FRAME_BEGIN_LABEL "Lframe"
261 #define CIE_AFTER_SIZE_LABEL "LSCIE"
262 #define CIE_END_LABEL "LECIE"
263 #define FDE_LABEL "LSFDE"
264 #define FDE_AFTER_SIZE_LABEL "LASFDE"
265 #define FDE_END_LABEL "LEFDE"
266 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
267 #define LINE_NUMBER_END_LABEL "LELT"
268 #define LN_PROLOG_AS_LABEL "LASLTP"
269 #define LN_PROLOG_END_LABEL "LELTP"
270 #define DIE_LABEL_PREFIX "DW"
272 /* Match the base name of a file to the base name of a compilation unit. */
275 matches_main_base (const char *path
)
277 /* Cache the last query. */
278 static const char *last_path
= NULL
;
279 static int last_match
= 0;
280 if (path
!= last_path
)
283 int length
= base_of_path (path
, &base
);
285 last_match
= (length
== main_input_baselength
286 && memcmp (base
, main_input_basename
, length
) == 0);
291 #ifdef DEBUG_DEBUG_STRUCT
294 dump_struct_debug (tree type
, enum debug_info_usage usage
,
295 enum debug_struct_file criterion
, int generic
,
296 int matches
, int result
)
298 /* Find the type name. */
299 tree type_decl
= TYPE_STUB_DECL (type
);
301 const char *name
= 0;
302 if (TREE_CODE (t
) == TYPE_DECL
)
305 name
= IDENTIFIER_POINTER (t
);
307 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
309 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
310 matches
? "bas" : "hdr",
311 generic
? "gen" : "ord",
312 usage
== DINFO_USAGE_DFN
? ";" :
313 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
315 (void*) type_decl
, name
);
318 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
319 dump_struct_debug (type, usage, criterion, generic, matches, result)
323 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
329 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
331 enum debug_struct_file criterion
;
333 bool generic
= lang_hooks
.types
.generic_p (type
);
336 criterion
= debug_struct_generic
[usage
];
338 criterion
= debug_struct_ordinary
[usage
];
340 if (criterion
== DINFO_STRUCT_FILE_NONE
)
341 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
342 if (criterion
== DINFO_STRUCT_FILE_ANY
)
343 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
345 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
347 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
348 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
350 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
351 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
352 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
355 /* Return a pointer to a copy of the section string name S with all
356 attributes stripped off, and an asterisk prepended (for assemble_name). */
359 stripattributes (const char *s
)
361 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
366 while (*s
&& *s
!= ',')
373 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
374 switch to the data section instead, and write out a synthetic start label
375 for collect2 the first time around. */
378 switch_to_eh_frame_section (bool back
)
382 #ifdef EH_FRAME_SECTION_NAME
383 if (eh_frame_section
== 0)
387 if (EH_TABLES_CAN_BE_READ_ONLY
)
393 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
395 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
397 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
400 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
401 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
402 && (per_encoding
& 0x70) != DW_EH_PE_absptr
403 && (per_encoding
& 0x70) != DW_EH_PE_aligned
404 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
405 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
406 ? 0 : SECTION_WRITE
);
409 flags
= SECTION_WRITE
;
410 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
412 #endif /* EH_FRAME_SECTION_NAME */
414 if (eh_frame_section
)
415 switch_to_section (eh_frame_section
);
418 /* We have no special eh_frame section. Put the information in
419 the data section and emit special labels to guide collect2. */
420 switch_to_section (data_section
);
424 label
= get_file_function_name ("F");
425 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
426 targetm
.asm_out
.globalize_label (asm_out_file
,
427 IDENTIFIER_POINTER (label
));
428 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
433 /* Switch [BACK] to the eh or debug frame table section, depending on
437 switch_to_frame_table_section (int for_eh
, bool back
)
440 switch_to_eh_frame_section (back
);
443 if (!debug_frame_section
)
444 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
445 SECTION_DEBUG
, NULL
);
446 switch_to_section (debug_frame_section
);
450 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
452 enum dw_cfi_oprnd_type
453 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
458 case DW_CFA_GNU_window_save
:
459 case DW_CFA_remember_state
:
460 case DW_CFA_restore_state
:
461 return dw_cfi_oprnd_unused
;
464 case DW_CFA_advance_loc1
:
465 case DW_CFA_advance_loc2
:
466 case DW_CFA_advance_loc4
:
467 case DW_CFA_MIPS_advance_loc8
:
468 return dw_cfi_oprnd_addr
;
471 case DW_CFA_offset_extended
:
473 case DW_CFA_offset_extended_sf
:
474 case DW_CFA_def_cfa_sf
:
476 case DW_CFA_restore_extended
:
477 case DW_CFA_undefined
:
478 case DW_CFA_same_value
:
479 case DW_CFA_def_cfa_register
:
480 case DW_CFA_register
:
481 case DW_CFA_expression
:
482 return dw_cfi_oprnd_reg_num
;
484 case DW_CFA_def_cfa_offset
:
485 case DW_CFA_GNU_args_size
:
486 case DW_CFA_def_cfa_offset_sf
:
487 return dw_cfi_oprnd_offset
;
489 case DW_CFA_def_cfa_expression
:
490 return dw_cfi_oprnd_loc
;
497 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
499 enum dw_cfi_oprnd_type
500 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
505 case DW_CFA_def_cfa_sf
:
507 case DW_CFA_offset_extended_sf
:
508 case DW_CFA_offset_extended
:
509 return dw_cfi_oprnd_offset
;
511 case DW_CFA_register
:
512 return dw_cfi_oprnd_reg_num
;
514 case DW_CFA_expression
:
515 return dw_cfi_oprnd_loc
;
518 return dw_cfi_oprnd_unused
;
522 /* Output one FDE. */
525 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
526 char *section_start_label
, int fde_encoding
, char *augmentation
,
527 bool any_lsda_needed
, int lsda_encoding
)
529 const char *begin
, *end
;
530 static unsigned int j
;
533 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
535 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
537 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
538 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
539 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
540 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
541 " indicating 64-bit DWARF extension");
542 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
544 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
547 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
549 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
550 debug_frame_section
, "FDE CIE offset");
552 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
553 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
557 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
558 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
559 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
560 "FDE initial location");
561 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
562 end
, begin
, "FDE address range");
566 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
567 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
574 int size
= size_of_encoded_value (lsda_encoding
);
576 if (lsda_encoding
== DW_EH_PE_aligned
)
578 int offset
= ( 4 /* Length */
580 + 2 * size_of_encoded_value (fde_encoding
)
581 + 1 /* Augmentation size */ );
582 int pad
= -offset
& (PTR_SIZE
- 1);
585 gcc_assert (size_of_uleb128 (size
) == 1);
588 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
590 if (fde
->uses_eh_lsda
)
592 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
593 fde
->funcdef_number
);
594 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
595 gen_rtx_SYMBOL_REF (Pmode
, l1
),
597 "Language Specific Data Area");
601 if (lsda_encoding
== DW_EH_PE_aligned
)
602 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
603 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
604 "Language Specific Data Area (none)");
608 dw2_asm_output_data_uleb128 (0, "Augmentation size");
611 /* Loop through the Call Frame Instructions associated with this FDE. */
612 fde
->dw_fde_current_label
= begin
;
614 size_t from
, until
, i
;
617 until
= vec_safe_length (fde
->dw_fde_cfi
);
619 if (fde
->dw_fde_second_begin
== NULL
)
622 until
= fde
->dw_fde_switch_cfi_index
;
624 from
= fde
->dw_fde_switch_cfi_index
;
626 for (i
= from
; i
< until
; i
++)
627 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
630 /* If we are to emit a ref/link from function bodies to their frame tables,
631 do it now. This is typically performed to make sure that tables
632 associated with functions are dragged with them and not discarded in
633 garbage collecting links. We need to do this on a per function basis to
634 cope with -ffunction-sections. */
636 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
637 /* Switch to the function section, emit the ref to the tables, and
638 switch *back* into the table section. */
639 switch_to_section (function_section (fde
->decl
));
640 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
641 switch_to_frame_table_section (for_eh
, true);
644 /* Pad the FDE out to an address sized boundary. */
645 ASM_OUTPUT_ALIGN (asm_out_file
,
646 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
647 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
652 /* Return true if frame description entry FDE is needed for EH. */
655 fde_needed_for_eh_p (dw_fde_ref fde
)
657 if (flag_asynchronous_unwind_tables
)
660 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
663 if (fde
->uses_eh_lsda
)
666 /* If exceptions are enabled, we have collected nothrow info. */
667 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
673 /* Output the call frame information used to record information
674 that relates to calculating the frame pointer, and records the
675 location of saved registers. */
678 output_call_frame_info (int for_eh
)
683 char l1
[20], l2
[20], section_start_label
[20];
684 bool any_lsda_needed
= false;
685 char augmentation
[6];
686 int augmentation_size
;
687 int fde_encoding
= DW_EH_PE_absptr
;
688 int per_encoding
= DW_EH_PE_absptr
;
689 int lsda_encoding
= DW_EH_PE_absptr
;
691 rtx personality
= NULL
;
694 /* Don't emit a CIE if there won't be any FDEs. */
698 /* Nothing to do if the assembler's doing it all. */
699 if (dwarf2out_do_cfi_asm ())
702 /* If we don't have any functions we'll want to unwind out of, don't emit
703 any EH unwind information. If we make FDEs linkonce, we may have to
704 emit an empty label for an FDE that wouldn't otherwise be emitted. We
705 want to avoid having an FDE kept around when the function it refers to
706 is discarded. Example where this matters: a primary function template
707 in C++ requires EH information, an explicit specialization doesn't. */
710 bool any_eh_needed
= false;
712 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
714 if (fde
->uses_eh_lsda
)
715 any_eh_needed
= any_lsda_needed
= true;
716 else if (fde_needed_for_eh_p (fde
))
717 any_eh_needed
= true;
718 else if (TARGET_USES_WEAK_UNWIND_INFO
)
719 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
726 /* We're going to be generating comments, so turn on app. */
730 /* Switch to the proper frame section, first time. */
731 switch_to_frame_table_section (for_eh
, false);
733 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
734 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
736 /* Output the CIE. */
737 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
738 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
739 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
740 dw2_asm_output_data (4, 0xffffffff,
741 "Initial length escape value indicating 64-bit DWARF extension");
742 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
743 "Length of Common Information Entry");
744 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
746 /* Now that the CIE pointer is PC-relative for EH,
747 use 0 to identify the CIE. */
748 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
749 (for_eh
? 0 : DWARF_CIE_ID
),
750 "CIE Identifier Tag");
752 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
753 use CIE version 1, unless that would produce incorrect results
754 due to overflowing the return register column. */
755 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
757 if (return_reg
>= 256 || dwarf_version
> 2)
759 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
762 augmentation_size
= 0;
764 personality
= current_unit_personality
;
770 z Indicates that a uleb128 is present to size the
771 augmentation section.
772 L Indicates the encoding (and thus presence) of
773 an LSDA pointer in the FDE augmentation.
774 R Indicates a non-default pointer encoding for
776 P Indicates the presence of an encoding + language
777 personality routine in the CIE augmentation. */
779 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
780 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
781 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
783 p
= augmentation
+ 1;
787 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
788 assemble_external_libcall (personality
);
793 augmentation_size
+= 1;
795 if (fde_encoding
!= DW_EH_PE_absptr
)
798 augmentation_size
+= 1;
800 if (p
> augmentation
+ 1)
802 augmentation
[0] = 'z';
806 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
807 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
809 int offset
= ( 4 /* Length */
811 + 1 /* CIE version */
812 + strlen (augmentation
) + 1 /* Augmentation */
813 + size_of_uleb128 (1) /* Code alignment */
814 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
816 + 1 /* Augmentation size */
817 + 1 /* Personality encoding */ );
818 int pad
= -offset
& (PTR_SIZE
- 1);
820 augmentation_size
+= pad
;
822 /* Augmentations should be small, so there's scarce need to
823 iterate for a solution. Die if we exceed one uleb128 byte. */
824 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
828 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
829 if (dw_cie_version
>= 4)
831 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
832 dw2_asm_output_data (1, 0, "CIE Segment Size");
834 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
835 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
836 "CIE Data Alignment Factor");
838 if (dw_cie_version
== 1)
839 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
841 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
845 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
848 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
849 eh_data_format_name (per_encoding
));
850 dw2_asm_output_encoded_addr_rtx (per_encoding
,
856 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
857 eh_data_format_name (lsda_encoding
));
859 if (fde_encoding
!= DW_EH_PE_absptr
)
860 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
861 eh_data_format_name (fde_encoding
));
864 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
865 output_cfi (cfi
, NULL
, for_eh
);
867 /* Pad the CIE out to an address sized boundary. */
868 ASM_OUTPUT_ALIGN (asm_out_file
,
869 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
870 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
872 /* Loop through all of the FDE's. */
873 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
877 /* Don't emit EH unwind info for leaf functions that don't need it. */
878 if (for_eh
&& !fde_needed_for_eh_p (fde
))
881 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
882 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
883 augmentation
, any_lsda_needed
, lsda_encoding
);
886 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
887 dw2_asm_output_data (4, 0, "End of Table");
889 /* Turn off app to make assembly quicker. */
894 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
897 dwarf2out_do_cfi_startproc (bool second
)
901 rtx personality
= get_personality_function (current_function_decl
);
903 fprintf (asm_out_file
, "\t.cfi_startproc\n");
907 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
910 /* ??? The GAS support isn't entirely consistent. We have to
911 handle indirect support ourselves, but PC-relative is done
912 in the assembler. Further, the assembler can't handle any
913 of the weirder relocation types. */
914 if (enc
& DW_EH_PE_indirect
)
915 ref
= dw2_force_const_mem (ref
, true);
917 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
918 output_addr_const (asm_out_file
, ref
);
919 fputc ('\n', asm_out_file
);
922 if (crtl
->uses_eh_lsda
)
926 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
927 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
928 current_function_funcdef_no
);
929 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
930 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
932 if (enc
& DW_EH_PE_indirect
)
933 ref
= dw2_force_const_mem (ref
, true);
935 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
936 output_addr_const (asm_out_file
, ref
);
937 fputc ('\n', asm_out_file
);
941 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
942 this allocation may be done before pass_final. */
945 dwarf2out_alloc_current_fde (void)
949 fde
= ggc_alloc_cleared_dw_fde_node ();
950 fde
->decl
= current_function_decl
;
951 fde
->funcdef_number
= current_function_funcdef_no
;
952 fde
->fde_index
= vec_safe_length (fde_vec
);
953 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
954 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
955 fde
->nothrow
= crtl
->nothrow
;
956 fde
->drap_reg
= INVALID_REGNUM
;
957 fde
->vdrap_reg
= INVALID_REGNUM
;
959 /* Record the FDE associated with this function. */
961 vec_safe_push (fde_vec
, fde
);
966 /* Output a marker (i.e. a label) for the beginning of a function, before
970 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
971 const char *file ATTRIBUTE_UNUSED
)
973 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
979 current_function_func_begin_label
= NULL
;
981 do_frame
= dwarf2out_do_frame ();
983 /* ??? current_function_func_begin_label is also used by except.c for
984 call-site information. We must emit this label if it might be used. */
987 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
990 fnsec
= function_section (current_function_decl
);
991 switch_to_section (fnsec
);
992 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
993 current_function_funcdef_no
);
994 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
995 current_function_funcdef_no
);
996 dup_label
= xstrdup (label
);
997 current_function_func_begin_label
= dup_label
;
999 /* We can elide the fde allocation if we're not emitting debug info. */
1003 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1004 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1005 would include pass_dwarf2_frame. If we've not created the FDE yet,
1009 fde
= dwarf2out_alloc_current_fde ();
1011 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1012 fde
->dw_fde_begin
= dup_label
;
1013 fde
->dw_fde_current_label
= dup_label
;
1014 fde
->in_std_section
= (fnsec
== text_section
1015 || (cold_text_section
&& fnsec
== cold_text_section
));
1017 /* We only want to output line number information for the genuine dwarf2
1018 prologue case, not the eh frame case. */
1019 #ifdef DWARF2_DEBUGGING_INFO
1021 dwarf2out_source_line (line
, file
, 0, true);
1024 if (dwarf2out_do_cfi_asm ())
1025 dwarf2out_do_cfi_startproc (false);
1028 rtx personality
= get_personality_function (current_function_decl
);
1029 if (!current_unit_personality
)
1030 current_unit_personality
= personality
;
1032 /* We cannot keep a current personality per function as without CFI
1033 asm, at the point where we emit the CFI data, there is no current
1034 function anymore. */
1035 if (personality
&& current_unit_personality
!= personality
)
1036 sorry ("multiple EH personalities are supported only with assemblers "
1037 "supporting .cfi_personality directive");
1041 /* Output a marker (i.e. a label) for the end of the generated code
1042 for a function prologue. This gets called *after* the prologue code has
1046 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1047 const char *file ATTRIBUTE_UNUSED
)
1049 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1051 /* Output a label to mark the endpoint of the code generated for this
1053 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1054 current_function_funcdef_no
);
1055 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1056 current_function_funcdef_no
);
1057 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1060 /* Output a marker (i.e. a label) for the beginning of the generated code
1061 for a function epilogue. This gets called *before* the prologue code has
1065 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1066 const char *file ATTRIBUTE_UNUSED
)
1068 dw_fde_ref fde
= cfun
->fde
;
1069 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1071 if (fde
->dw_fde_vms_begin_epilogue
)
1074 /* Output a label to mark the endpoint of the code generated for this
1076 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1077 current_function_funcdef_no
);
1078 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1079 current_function_funcdef_no
);
1080 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1083 /* Output a marker (i.e. a label) for the absolute end of the generated code
1084 for a function definition. This gets called *after* the epilogue code has
1088 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1089 const char *file ATTRIBUTE_UNUSED
)
1092 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1094 last_var_location_insn
= NULL_RTX
;
1095 cached_next_real_insn
= NULL_RTX
;
1097 if (dwarf2out_do_cfi_asm ())
1098 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1100 /* Output a label to mark the endpoint of the code generated for this
1102 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1103 current_function_funcdef_no
);
1104 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1106 gcc_assert (fde
!= NULL
);
1107 if (fde
->dw_fde_second_begin
== NULL
)
1108 fde
->dw_fde_end
= xstrdup (label
);
1112 dwarf2out_frame_finish (void)
1114 /* Output call frame information. */
1115 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1116 output_call_frame_info (0);
1118 /* Output another copy for the unwinder. */
1119 if ((flag_unwind_tables
|| flag_exceptions
)
1120 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1121 output_call_frame_info (1);
1124 /* Note that the current function section is being used for code. */
1127 dwarf2out_note_section_used (void)
1129 section
*sec
= current_function_section ();
1130 if (sec
== text_section
)
1131 text_section_used
= true;
1132 else if (sec
== cold_text_section
)
1133 cold_text_section_used
= true;
1136 static void var_location_switch_text_section (void);
1137 static void set_cur_line_info_table (section
*);
1140 dwarf2out_switch_text_section (void)
1143 dw_fde_ref fde
= cfun
->fde
;
1145 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1147 if (!in_cold_section_p
)
1149 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1150 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1151 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1155 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1156 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1157 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1159 have_multiple_function_sections
= true;
1161 /* There is no need to mark used sections when not debugging. */
1162 if (cold_text_section
!= NULL
)
1163 dwarf2out_note_section_used ();
1165 if (dwarf2out_do_cfi_asm ())
1166 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1168 /* Now do the real section switch. */
1169 sect
= current_function_section ();
1170 switch_to_section (sect
);
1172 fde
->second_in_std_section
1173 = (sect
== text_section
1174 || (cold_text_section
&& sect
== cold_text_section
));
1176 if (dwarf2out_do_cfi_asm ())
1177 dwarf2out_do_cfi_startproc (true);
1179 var_location_switch_text_section ();
1181 if (cold_text_section
!= NULL
)
1182 set_cur_line_info_table (sect
);
1185 /* And now, the subset of the debugging information support code necessary
1186 for emitting location expressions. */
1188 /* Data about a single source file. */
1189 struct GTY(()) dwarf_file_data
{
1190 const char * filename
;
1194 typedef struct GTY(()) deferred_locations_struct
1198 } deferred_locations
;
1201 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1204 /* Describe an entry into the .debug_addr section. */
1208 ate_kind_rtx_dtprel
,
1212 typedef struct GTY(()) addr_table_entry_struct
{
1214 unsigned int refcount
;
1216 union addr_table_entry_struct_union
1218 rtx
GTY ((tag ("0"))) rtl
;
1219 char * GTY ((tag ("1"))) label
;
1221 GTY ((desc ("%1.kind"))) addr
;
1225 /* Location lists are ranges + location descriptions for that range,
1226 so you can track variables that are in different places over
1227 their entire life. */
1228 typedef struct GTY(()) dw_loc_list_struct
{
1229 dw_loc_list_ref dw_loc_next
;
1230 const char *begin
; /* Label and addr_entry for start of range */
1231 addr_table_entry
*begin_entry
;
1232 const char *end
; /* Label for end of range */
1233 char *ll_symbol
; /* Label for beginning of location list.
1234 Only on head of list */
1235 const char *section
; /* Section this loclist is relative to */
1236 dw_loc_descr_ref expr
;
1238 /* True if all addresses in this and subsequent lists are known to be
1241 /* True if this list has been replaced by dw_loc_next. */
1244 /* True if the range should be emitted even if begin and end
1249 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1251 /* Convert a DWARF stack opcode into its string name. */
1254 dwarf_stack_op_name (unsigned int op
)
1256 const char *name
= get_DW_OP_name (op
);
1261 return "OP_<unknown>";
1264 /* Return a pointer to a newly allocated location description. Location
1265 descriptions are simple expression terms that can be strung
1266 together to form more complicated location (address) descriptions. */
1268 static inline dw_loc_descr_ref
1269 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1270 unsigned HOST_WIDE_INT oprnd2
)
1272 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1274 descr
->dw_loc_opc
= op
;
1275 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1276 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1277 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1278 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1279 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1280 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1285 /* Return a pointer to a newly allocated location description for
1288 static inline dw_loc_descr_ref
1289 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1292 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1295 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1298 /* Add a location description term to a location description expression. */
1301 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1303 dw_loc_descr_ref
*d
;
1305 /* Find the end of the chain. */
1306 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1312 /* Compare two location operands for exact equality. */
1315 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1317 if (a
->val_class
!= b
->val_class
)
1319 switch (a
->val_class
)
1321 case dw_val_class_none
:
1323 case dw_val_class_addr
:
1324 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1326 case dw_val_class_offset
:
1327 case dw_val_class_unsigned_const
:
1328 case dw_val_class_const
:
1329 case dw_val_class_range_list
:
1330 case dw_val_class_lineptr
:
1331 case dw_val_class_macptr
:
1332 /* These are all HOST_WIDE_INT, signed or unsigned. */
1333 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1335 case dw_val_class_loc
:
1336 return a
->v
.val_loc
== b
->v
.val_loc
;
1337 case dw_val_class_loc_list
:
1338 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1339 case dw_val_class_die_ref
:
1340 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1341 case dw_val_class_fde_ref
:
1342 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1343 case dw_val_class_lbl_id
:
1344 case dw_val_class_high_pc
:
1345 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1346 case dw_val_class_str
:
1347 return a
->v
.val_str
== b
->v
.val_str
;
1348 case dw_val_class_flag
:
1349 return a
->v
.val_flag
== b
->v
.val_flag
;
1350 case dw_val_class_file
:
1351 return a
->v
.val_file
== b
->v
.val_file
;
1352 case dw_val_class_decl_ref
:
1353 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1355 case dw_val_class_const_double
:
1356 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1357 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1359 case dw_val_class_vec
:
1361 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1362 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1364 return (a_len
== b_len
1365 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1368 case dw_val_class_data8
:
1369 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1371 case dw_val_class_vms_delta
:
1372 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1373 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1378 /* Compare two location atoms for exact equality. */
1381 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1383 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1386 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1387 address size, but since we always allocate cleared storage it
1388 should be zero for other types of locations. */
1389 if (a
->dtprel
!= b
->dtprel
)
1392 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1393 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1396 /* Compare two complete location expressions for exact equality. */
1399 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1405 if (a
== NULL
|| b
== NULL
)
1407 if (!loc_descr_equal_p_1 (a
, b
))
1416 /* Add a constant OFFSET to a location expression. */
1419 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1421 dw_loc_descr_ref loc
;
1424 gcc_assert (*list_head
!= NULL
);
1429 /* Find the end of the chain. */
1430 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1434 if (loc
->dw_loc_opc
== DW_OP_fbreg
1435 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1436 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1437 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1438 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1440 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1441 offset. Don't optimize if an signed integer overflow would happen. */
1443 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1444 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1447 else if (offset
> 0)
1448 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1452 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1453 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1457 /* Add a constant OFFSET to a location list. */
1460 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1463 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1464 loc_descr_plus_const (&d
->expr
, offset
);
1467 #define DWARF_REF_SIZE \
1468 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1470 static unsigned long int get_base_type_offset (dw_die_ref
);
1472 /* Return the size of a location descriptor. */
1474 static unsigned long
1475 size_of_loc_descr (dw_loc_descr_ref loc
)
1477 unsigned long size
= 1;
1479 switch (loc
->dw_loc_opc
)
1482 size
+= DWARF2_ADDR_SIZE
;
1484 case DW_OP_GNU_addr_index
:
1485 case DW_OP_GNU_const_index
:
1486 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1487 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1506 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1509 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1514 case DW_OP_plus_uconst
:
1515 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1553 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1556 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1559 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1562 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1563 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1566 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1568 case DW_OP_bit_piece
:
1569 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1570 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1572 case DW_OP_deref_size
:
1573 case DW_OP_xderef_size
:
1582 case DW_OP_call_ref
:
1583 size
+= DWARF_REF_SIZE
;
1585 case DW_OP_implicit_value
:
1586 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1587 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1589 case DW_OP_GNU_implicit_pointer
:
1590 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1592 case DW_OP_GNU_entry_value
:
1594 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1595 size
+= size_of_uleb128 (op_size
) + op_size
;
1598 case DW_OP_GNU_const_type
:
1601 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1602 size
+= size_of_uleb128 (o
) + 1;
1603 switch (loc
->dw_loc_oprnd2
.val_class
)
1605 case dw_val_class_vec
:
1606 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1607 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1609 case dw_val_class_const
:
1610 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1612 case dw_val_class_const_double
:
1613 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1620 case DW_OP_GNU_regval_type
:
1623 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1624 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1625 + size_of_uleb128 (o
);
1628 case DW_OP_GNU_deref_type
:
1631 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1632 size
+= 1 + size_of_uleb128 (o
);
1635 case DW_OP_GNU_convert
:
1636 case DW_OP_GNU_reinterpret
:
1637 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1638 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1642 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1643 size
+= size_of_uleb128 (o
);
1646 case DW_OP_GNU_parameter_ref
:
1656 /* Return the size of a series of location descriptors. */
1659 size_of_locs (dw_loc_descr_ref loc
)
1664 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1665 field, to avoid writing to a PCH file. */
1666 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1668 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1670 size
+= size_of_loc_descr (l
);
1675 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1677 l
->dw_loc_addr
= size
;
1678 size
+= size_of_loc_descr (l
);
1684 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1685 static void get_ref_die_offset_label (char *, dw_die_ref
);
1686 static unsigned long int get_ref_die_offset (dw_die_ref
);
1688 /* Output location description stack opcode's operands (if any).
1689 The for_eh_or_skip parameter controls whether register numbers are
1690 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1691 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1692 info). This should be suppressed for the cases that have not been converted
1693 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1696 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1698 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1699 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1701 switch (loc
->dw_loc_opc
)
1703 #ifdef DWARF2_DEBUGGING_INFO
1706 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1711 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1712 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1714 fputc ('\n', asm_out_file
);
1719 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1724 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1725 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1727 fputc ('\n', asm_out_file
);
1732 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1733 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1740 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1741 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1743 dw2_asm_output_data (2, offset
, NULL
);
1746 case DW_OP_implicit_value
:
1747 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1748 switch (val2
->val_class
)
1750 case dw_val_class_const
:
1751 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1753 case dw_val_class_vec
:
1755 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1756 unsigned int len
= val2
->v
.val_vec
.length
;
1760 if (elt_size
> sizeof (HOST_WIDE_INT
))
1765 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1768 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1769 "fp or vector constant word %u", i
);
1772 case dw_val_class_const_double
:
1774 unsigned HOST_WIDE_INT first
, second
;
1776 if (WORDS_BIG_ENDIAN
)
1778 first
= val2
->v
.val_double
.high
;
1779 second
= val2
->v
.val_double
.low
;
1783 first
= val2
->v
.val_double
.low
;
1784 second
= val2
->v
.val_double
.high
;
1786 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1788 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1792 case dw_val_class_addr
:
1793 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1794 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1809 case DW_OP_implicit_value
:
1810 /* We currently don't make any attempt to make sure these are
1811 aligned properly like we do for the main unwind info, so
1812 don't support emitting things larger than a byte if we're
1813 only doing unwinding. */
1818 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1821 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1824 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1827 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1829 case DW_OP_plus_uconst
:
1830 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1864 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1868 unsigned r
= val1
->v
.val_unsigned
;
1869 if (for_eh_or_skip
>= 0)
1870 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1871 gcc_assert (size_of_uleb128 (r
)
1872 == size_of_uleb128 (val1
->v
.val_unsigned
));
1873 dw2_asm_output_data_uleb128 (r
, NULL
);
1877 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1881 unsigned r
= val1
->v
.val_unsigned
;
1882 if (for_eh_or_skip
>= 0)
1883 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1884 gcc_assert (size_of_uleb128 (r
)
1885 == size_of_uleb128 (val1
->v
.val_unsigned
));
1886 dw2_asm_output_data_uleb128 (r
, NULL
);
1887 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1891 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1893 case DW_OP_bit_piece
:
1894 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1895 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1897 case DW_OP_deref_size
:
1898 case DW_OP_xderef_size
:
1899 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1905 if (targetm
.asm_out
.output_dwarf_dtprel
)
1907 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1910 fputc ('\n', asm_out_file
);
1917 #ifdef DWARF2_DEBUGGING_INFO
1918 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1925 case DW_OP_GNU_addr_index
:
1926 case DW_OP_GNU_const_index
:
1927 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1928 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1929 "(index into .debug_addr)");
1932 case DW_OP_GNU_implicit_pointer
:
1934 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1935 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1936 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1937 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1938 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1939 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1943 case DW_OP_GNU_entry_value
:
1944 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1945 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1948 case DW_OP_GNU_const_type
:
1950 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1952 dw2_asm_output_data_uleb128 (o
, NULL
);
1953 switch (val2
->val_class
)
1955 case dw_val_class_const
:
1956 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1957 dw2_asm_output_data (1, l
, NULL
);
1958 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1960 case dw_val_class_vec
:
1962 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1963 unsigned int len
= val2
->v
.val_vec
.length
;
1968 dw2_asm_output_data (1, l
, NULL
);
1969 if (elt_size
> sizeof (HOST_WIDE_INT
))
1974 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1977 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1978 "fp or vector constant word %u", i
);
1981 case dw_val_class_const_double
:
1983 unsigned HOST_WIDE_INT first
, second
;
1984 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1986 dw2_asm_output_data (1, 2 * l
, NULL
);
1987 if (WORDS_BIG_ENDIAN
)
1989 first
= val2
->v
.val_double
.high
;
1990 second
= val2
->v
.val_double
.low
;
1994 first
= val2
->v
.val_double
.low
;
1995 second
= val2
->v
.val_double
.high
;
1997 dw2_asm_output_data (l
, first
, NULL
);
1998 dw2_asm_output_data (l
, second
, NULL
);
2006 case DW_OP_GNU_regval_type
:
2008 unsigned r
= val1
->v
.val_unsigned
;
2009 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2011 if (for_eh_or_skip
>= 0)
2013 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2014 gcc_assert (size_of_uleb128 (r
)
2015 == size_of_uleb128 (val1
->v
.val_unsigned
));
2017 dw2_asm_output_data_uleb128 (r
, NULL
);
2018 dw2_asm_output_data_uleb128 (o
, NULL
);
2021 case DW_OP_GNU_deref_type
:
2023 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2025 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2026 dw2_asm_output_data_uleb128 (o
, NULL
);
2029 case DW_OP_GNU_convert
:
2030 case DW_OP_GNU_reinterpret
:
2031 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2032 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2035 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2037 dw2_asm_output_data_uleb128 (o
, NULL
);
2041 case DW_OP_GNU_parameter_ref
:
2044 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2045 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2046 dw2_asm_output_data (4, o
, NULL
);
2051 /* Other codes have no operands. */
2056 /* Output a sequence of location operations.
2057 The for_eh_or_skip parameter controls whether register numbers are
2058 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2059 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2060 info). This should be suppressed for the cases that have not been converted
2061 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2064 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2066 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2068 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2069 /* Output the opcode. */
2070 if (for_eh_or_skip
>= 0
2071 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2073 unsigned r
= (opc
- DW_OP_breg0
);
2074 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2075 gcc_assert (r
<= 31);
2076 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2078 else if (for_eh_or_skip
>= 0
2079 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2081 unsigned r
= (opc
- DW_OP_reg0
);
2082 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2083 gcc_assert (r
<= 31);
2084 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2087 dw2_asm_output_data (1, opc
,
2088 "%s", dwarf_stack_op_name (opc
));
2090 /* Output the operand(s) (if any). */
2091 output_loc_operands (loc
, for_eh_or_skip
);
2095 /* Output location description stack opcode's operands (if any).
2096 The output is single bytes on a line, suitable for .cfi_escape. */
2099 output_loc_operands_raw (dw_loc_descr_ref loc
)
2101 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2102 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2104 switch (loc
->dw_loc_opc
)
2107 case DW_OP_GNU_addr_index
:
2108 case DW_OP_GNU_const_index
:
2109 case DW_OP_implicit_value
:
2110 /* We cannot output addresses in .cfi_escape, only bytes. */
2116 case DW_OP_deref_size
:
2117 case DW_OP_xderef_size
:
2118 fputc (',', asm_out_file
);
2119 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2124 fputc (',', asm_out_file
);
2125 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2130 fputc (',', asm_out_file
);
2131 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2136 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2137 fputc (',', asm_out_file
);
2138 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2146 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2147 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2149 fputc (',', asm_out_file
);
2150 dw2_asm_output_data_raw (2, offset
);
2156 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2157 gcc_assert (size_of_uleb128 (r
)
2158 == size_of_uleb128 (val1
->v
.val_unsigned
));
2159 fputc (',', asm_out_file
);
2160 dw2_asm_output_data_uleb128_raw (r
);
2165 case DW_OP_plus_uconst
:
2167 fputc (',', asm_out_file
);
2168 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2171 case DW_OP_bit_piece
:
2172 fputc (',', asm_out_file
);
2173 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2174 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2211 fputc (',', asm_out_file
);
2212 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2217 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2218 gcc_assert (size_of_uleb128 (r
)
2219 == size_of_uleb128 (val1
->v
.val_unsigned
));
2220 fputc (',', asm_out_file
);
2221 dw2_asm_output_data_uleb128_raw (r
);
2222 fputc (',', asm_out_file
);
2223 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2227 case DW_OP_GNU_implicit_pointer
:
2228 case DW_OP_GNU_entry_value
:
2229 case DW_OP_GNU_const_type
:
2230 case DW_OP_GNU_regval_type
:
2231 case DW_OP_GNU_deref_type
:
2232 case DW_OP_GNU_convert
:
2233 case DW_OP_GNU_reinterpret
:
2234 case DW_OP_GNU_parameter_ref
:
2239 /* Other codes have no operands. */
2245 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2249 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2250 /* Output the opcode. */
2251 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2253 unsigned r
= (opc
- DW_OP_breg0
);
2254 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2255 gcc_assert (r
<= 31);
2256 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2258 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2260 unsigned r
= (opc
- DW_OP_reg0
);
2261 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2262 gcc_assert (r
<= 31);
2263 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2265 /* Output the opcode. */
2266 fprintf (asm_out_file
, "%#x", opc
);
2267 output_loc_operands_raw (loc
);
2269 if (!loc
->dw_loc_next
)
2271 loc
= loc
->dw_loc_next
;
2273 fputc (',', asm_out_file
);
2277 /* This function builds a dwarf location descriptor sequence from a
2278 dw_cfa_location, adding the given OFFSET to the result of the
2281 struct dw_loc_descr_struct
*
2282 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2284 struct dw_loc_descr_struct
*head
, *tmp
;
2286 offset
+= cfa
->offset
;
2290 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2291 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2292 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2293 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2294 add_loc_descr (&head
, tmp
);
2297 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2298 add_loc_descr (&head
, tmp
);
2302 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2307 /* This function builds a dwarf location descriptor sequence for
2308 the address at OFFSET from the CFA when stack is aligned to
2311 struct dw_loc_descr_struct
*
2312 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2313 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2315 struct dw_loc_descr_struct
*head
;
2316 unsigned int dwarf_fp
2317 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2319 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2320 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2322 head
= new_reg_loc_descr (dwarf_fp
, 0);
2323 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2324 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2325 loc_descr_plus_const (&head
, offset
);
2328 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2332 /* And now, the support for symbolic debugging information. */
2334 /* .debug_str support. */
2335 static int output_indirect_string (void **, void *);
2337 static void dwarf2out_init (const char *);
2338 static void dwarf2out_finish (const char *);
2339 static void dwarf2out_assembly_start (void);
2340 static void dwarf2out_define (unsigned int, const char *);
2341 static void dwarf2out_undef (unsigned int, const char *);
2342 static void dwarf2out_start_source_file (unsigned, const char *);
2343 static void dwarf2out_end_source_file (unsigned);
2344 static void dwarf2out_function_decl (tree
);
2345 static void dwarf2out_begin_block (unsigned, unsigned);
2346 static void dwarf2out_end_block (unsigned, unsigned);
2347 static bool dwarf2out_ignore_block (const_tree
);
2348 static void dwarf2out_global_decl (tree
);
2349 static void dwarf2out_type_decl (tree
, int);
2350 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2351 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2353 static void dwarf2out_abstract_function (tree
);
2354 static void dwarf2out_var_location (rtx
);
2355 static void dwarf2out_begin_function (tree
);
2356 static void dwarf2out_set_name (tree
, tree
);
2358 /* The debug hooks structure. */
2360 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2364 dwarf2out_assembly_start
,
2367 dwarf2out_start_source_file
,
2368 dwarf2out_end_source_file
,
2369 dwarf2out_begin_block
,
2370 dwarf2out_end_block
,
2371 dwarf2out_ignore_block
,
2372 dwarf2out_source_line
,
2373 dwarf2out_begin_prologue
,
2374 #if VMS_DEBUGGING_INFO
2375 dwarf2out_vms_end_prologue
,
2376 dwarf2out_vms_begin_epilogue
,
2378 debug_nothing_int_charstar
,
2379 debug_nothing_int_charstar
,
2381 dwarf2out_end_epilogue
,
2382 dwarf2out_begin_function
,
2383 debug_nothing_int
, /* end_function */
2384 dwarf2out_function_decl
, /* function_decl */
2385 dwarf2out_global_decl
,
2386 dwarf2out_type_decl
, /* type_decl */
2387 dwarf2out_imported_module_or_decl
,
2388 debug_nothing_tree
, /* deferred_inline_function */
2389 /* The DWARF 2 backend tries to reduce debugging bloat by not
2390 emitting the abstract description of inline functions until
2391 something tries to reference them. */
2392 dwarf2out_abstract_function
, /* outlining_inline_function */
2393 debug_nothing_rtx
, /* label */
2394 debug_nothing_int
, /* handle_pch */
2395 dwarf2out_var_location
,
2396 dwarf2out_switch_text_section
,
2398 1, /* start_end_main_source_file */
2399 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2402 /* NOTE: In the comments in this file, many references are made to
2403 "Debugging Information Entries". This term is abbreviated as `DIE'
2404 throughout the remainder of this file. */
2406 /* An internal representation of the DWARF output is built, and then
2407 walked to generate the DWARF debugging info. The walk of the internal
2408 representation is done after the entire program has been compiled.
2409 The types below are used to describe the internal representation. */
2411 /* Whether to put type DIEs into their own section .debug_types instead
2412 of making them part of the .debug_info section. Only supported for
2413 Dwarf V4 or higher and the user didn't disable them through
2414 -fno-debug-types-section. It is more efficient to put them in a
2415 separate comdat sections since the linker will then be able to
2416 remove duplicates. But not all tools support .debug_types sections
2419 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2421 /* Various DIE's use offsets relative to the beginning of the
2422 .debug_info section to refer to each other. */
2424 typedef long int dw_offset
;
2426 /* Define typedefs here to avoid circular dependencies. */
2428 typedef struct dw_attr_struct
*dw_attr_ref
;
2429 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2430 typedef struct pubname_struct
*pubname_ref
;
2431 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2432 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2433 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2435 /* The entries in the line_info table more-or-less mirror the opcodes
2436 that are used in the real dwarf line table. Arrays of these entries
2437 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2440 enum dw_line_info_opcode
{
2441 /* Emit DW_LNE_set_address; the operand is the label index. */
2444 /* Emit a row to the matrix with the given line. This may be done
2445 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2449 /* Emit a DW_LNS_set_file. */
2452 /* Emit a DW_LNS_set_column. */
2455 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2458 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2459 LI_set_prologue_end
,
2460 LI_set_epilogue_begin
,
2462 /* Emit a DW_LNE_set_discriminator. */
2463 LI_set_discriminator
2466 typedef struct GTY(()) dw_line_info_struct
{
2467 enum dw_line_info_opcode opcode
;
2469 } dw_line_info_entry
;
2472 typedef struct GTY(()) dw_line_info_table_struct
{
2473 /* The label that marks the end of this section. */
2474 const char *end_label
;
2476 /* The values for the last row of the matrix, as collected in the table.
2477 These are used to minimize the changes to the next row. */
2478 unsigned int file_num
;
2479 unsigned int line_num
;
2480 unsigned int column_num
;
2485 vec
<dw_line_info_entry
, va_gc
> *entries
;
2486 } dw_line_info_table
;
2488 typedef dw_line_info_table
*dw_line_info_table_p
;
2491 /* Each DIE attribute has a field specifying the attribute kind,
2492 a link to the next attribute in the chain, and an attribute value.
2493 Attributes are typically linked below the DIE they modify. */
2495 typedef struct GTY(()) dw_attr_struct
{
2496 enum dwarf_attribute dw_attr
;
2497 dw_val_node dw_attr_val
;
2502 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2503 The children of each node form a circular list linked by
2504 die_sib. die_child points to the node *before* the "first" child node. */
2506 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2507 union die_symbol_or_type_node
2509 const char * GTY ((tag ("0"))) die_symbol
;
2510 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2512 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2513 vec
<dw_attr_node
, va_gc
> *die_attr
;
2514 dw_die_ref die_parent
;
2515 dw_die_ref die_child
;
2517 dw_die_ref die_definition
; /* ref from a specification to its definition */
2518 dw_offset die_offset
;
2519 unsigned long die_abbrev
;
2521 unsigned int decl_id
;
2522 enum dwarf_tag die_tag
;
2523 /* Die is used and must not be pruned as unused. */
2524 BOOL_BITFIELD die_perennial_p
: 1;
2525 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2526 /* Lots of spare bits. */
2530 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2531 #define FOR_EACH_CHILD(die, c, expr) do { \
2532 c = die->die_child; \
2536 } while (c != die->die_child); \
2539 /* The pubname structure */
2541 typedef struct GTY(()) pubname_struct
{
2548 struct GTY(()) dw_ranges_struct
{
2549 /* If this is positive, it's a block number, otherwise it's a
2550 bitwise-negated index into dw_ranges_by_label. */
2554 /* A structure to hold a macinfo entry. */
2556 typedef struct GTY(()) macinfo_struct
{
2558 unsigned HOST_WIDE_INT lineno
;
2564 struct GTY(()) dw_ranges_by_label_struct
{
2569 /* The comdat type node structure. */
2570 typedef struct GTY(()) comdat_type_struct
2572 dw_die_ref root_die
;
2573 dw_die_ref type_die
;
2574 dw_die_ref skeleton_die
;
2575 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2576 struct comdat_type_struct
*next
;
2580 /* The limbo die list structure. */
2581 typedef struct GTY(()) limbo_die_struct
{
2584 struct limbo_die_struct
*next
;
2588 typedef struct skeleton_chain_struct
2592 struct skeleton_chain_struct
*parent
;
2594 skeleton_chain_node
;
2596 /* Define a macro which returns nonzero for a TYPE_DECL which was
2597 implicitly generated for a type.
2599 Note that, unlike the C front-end (which generates a NULL named
2600 TYPE_DECL node for each complete tagged type, each array type,
2601 and each function type node created) the C++ front-end generates
2602 a _named_ TYPE_DECL node for each tagged type node created.
2603 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2604 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2605 front-end, but for each type, tagged or not. */
2607 #define TYPE_DECL_IS_STUB(decl) \
2608 (DECL_NAME (decl) == NULL_TREE \
2609 || (DECL_ARTIFICIAL (decl) \
2610 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2611 /* This is necessary for stub decls that \
2612 appear in nested inline functions. */ \
2613 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2614 && (decl_ultimate_origin (decl) \
2615 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2617 /* Information concerning the compilation unit's programming
2618 language, and compiler version. */
2620 /* Fixed size portion of the DWARF compilation unit header. */
2621 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2622 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2624 /* Fixed size portion of the DWARF comdat type unit header. */
2625 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2626 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2627 + DWARF_OFFSET_SIZE)
2629 /* Fixed size portion of public names info. */
2630 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2632 /* Fixed size portion of the address range info. */
2633 #define DWARF_ARANGES_HEADER_SIZE \
2634 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2635 DWARF2_ADDR_SIZE * 2) \
2636 - DWARF_INITIAL_LENGTH_SIZE)
2638 /* Size of padding portion in the address range info. It must be
2639 aligned to twice the pointer size. */
2640 #define DWARF_ARANGES_PAD_SIZE \
2641 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2642 DWARF2_ADDR_SIZE * 2) \
2643 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2645 /* Use assembler line directives if available. */
2646 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2647 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2648 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2650 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2654 /* Minimum line offset in a special line info. opcode.
2655 This value was chosen to give a reasonable range of values. */
2656 #define DWARF_LINE_BASE -10
2658 /* First special line opcode - leave room for the standard opcodes. */
2659 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2661 /* Range of line offsets in a special line info. opcode. */
2662 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2664 /* Flag that indicates the initial value of the is_stmt_start flag.
2665 In the present implementation, we do not mark any lines as
2666 the beginning of a source statement, because that information
2667 is not made available by the GCC front-end. */
2668 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2670 /* Maximum number of operations per instruction bundle. */
2671 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2672 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2675 /* This location is used by calc_die_sizes() to keep track
2676 the offset of each DIE within the .debug_info section. */
2677 static unsigned long next_die_offset
;
2679 /* Record the root of the DIE's built for the current compilation unit. */
2680 static GTY(()) dw_die_ref single_comp_unit_die
;
2682 /* A list of type DIEs that have been separated into comdat sections. */
2683 static GTY(()) comdat_type_node
*comdat_type_list
;
2685 /* A list of DIEs with a NULL parent waiting to be relocated. */
2686 static GTY(()) limbo_die_node
*limbo_die_list
;
2688 /* A list of DIEs for which we may have to generate
2689 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2690 static GTY(()) limbo_die_node
*deferred_asm_name
;
2692 /* Filenames referenced by this compilation unit. */
2693 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2695 /* A hash table of references to DIE's that describe declarations.
2696 The key is a DECL_UID() which is a unique number identifying each decl. */
2697 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2699 /* A hash table of references to DIE's that describe COMMON blocks.
2700 The key is DECL_UID() ^ die_parent. */
2701 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2703 typedef struct GTY(()) die_arg_entry_struct
{
2709 /* Node of the variable location list. */
2710 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2711 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2712 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2713 in mode of the EXPR_LIST node and first EXPR_LIST operand
2714 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2715 location or NULL for padding. For larger bitsizes,
2716 mode is 0 and first operand is a CONCAT with bitsize
2717 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2718 NULL as second operand. */
2720 const char * GTY (()) label
;
2721 struct var_loc_node
* GTY (()) next
;
2724 /* Variable location list. */
2725 struct GTY (()) var_loc_list_def
{
2726 struct var_loc_node
* GTY (()) first
;
2728 /* Pointer to the last but one or last element of the
2729 chained list. If the list is empty, both first and
2730 last are NULL, if the list contains just one node
2731 or the last node certainly is not redundant, it points
2732 to the last node, otherwise points to the last but one.
2733 Do not mark it for GC because it is marked through the chain. */
2734 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2736 /* Pointer to the last element before section switch,
2737 if NULL, either sections weren't switched or first
2738 is after section switch. */
2739 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2741 /* DECL_UID of the variable decl. */
2742 unsigned int decl_id
;
2744 typedef struct var_loc_list_def var_loc_list
;
2746 /* Call argument location list. */
2747 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2748 rtx
GTY (()) call_arg_loc_note
;
2749 const char * GTY (()) label
;
2750 tree
GTY (()) block
;
2752 rtx
GTY (()) symbol_ref
;
2753 struct call_arg_loc_node
* GTY (()) next
;
2757 /* Table of decl location linked lists. */
2758 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2760 /* Head and tail of call_arg_loc chain. */
2761 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2762 static struct call_arg_loc_node
*call_arg_loc_last
;
2764 /* Number of call sites in the current function. */
2765 static int call_site_count
= -1;
2766 /* Number of tail call sites in the current function. */
2767 static int tail_call_site_count
= -1;
2769 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2771 static vec
<dw_die_ref
> block_map
;
2773 /* A cached location list. */
2774 struct GTY (()) cached_dw_loc_list_def
{
2775 /* The DECL_UID of the decl that this entry describes. */
2776 unsigned int decl_id
;
2778 /* The cached location list. */
2779 dw_loc_list_ref loc_list
;
2781 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2783 /* Table of cached location lists. */
2784 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2786 /* A pointer to the base of a list of references to DIE's that
2787 are uniquely identified by their tag, presence/absence of
2788 children DIE's, and list of attribute/value pairs. */
2789 static GTY((length ("abbrev_die_table_allocated")))
2790 dw_die_ref
*abbrev_die_table
;
2792 /* Number of elements currently allocated for abbrev_die_table. */
2793 static GTY(()) unsigned abbrev_die_table_allocated
;
2795 /* Number of elements in type_die_table currently in use. */
2796 static GTY(()) unsigned abbrev_die_table_in_use
;
2798 /* Size (in elements) of increments by which we may expand the
2799 abbrev_die_table. */
2800 #define ABBREV_DIE_TABLE_INCREMENT 256
2802 /* A global counter for generating labels for line number data. */
2803 static unsigned int line_info_label_num
;
2805 /* The current table to which we should emit line number information
2806 for the current function. This will be set up at the beginning of
2807 assembly for the function. */
2808 static dw_line_info_table
*cur_line_info_table
;
2810 /* The two default tables of line number info. */
2811 static GTY(()) dw_line_info_table
*text_section_line_info
;
2812 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2814 /* The set of all non-default tables of line number info. */
2815 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2817 /* A flag to tell pubnames/types export if there is an info section to
2819 static bool info_section_emitted
;
2821 /* A pointer to the base of a table that contains a list of publicly
2822 accessible names. */
2823 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2825 /* A pointer to the base of a table that contains a list of publicly
2826 accessible types. */
2827 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2829 /* A pointer to the base of a table that contains a list of macro
2830 defines/undefines (and file start/end markers). */
2831 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2833 /* True if .debug_macinfo or .debug_macros section is going to be
2835 #define have_macinfo \
2836 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2837 && !macinfo_table->is_empty ())
2839 /* Array of dies for which we should generate .debug_ranges info. */
2840 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2842 /* Number of elements currently allocated for ranges_table. */
2843 static GTY(()) unsigned ranges_table_allocated
;
2845 /* Number of elements in ranges_table currently in use. */
2846 static GTY(()) unsigned ranges_table_in_use
;
2848 /* Array of pairs of labels referenced in ranges_table. */
2849 static GTY ((length ("ranges_by_label_allocated")))
2850 dw_ranges_by_label_ref ranges_by_label
;
2852 /* Number of elements currently allocated for ranges_by_label. */
2853 static GTY(()) unsigned ranges_by_label_allocated
;
2855 /* Number of elements in ranges_by_label currently in use. */
2856 static GTY(()) unsigned ranges_by_label_in_use
;
2858 /* Size (in elements) of increments by which we may expand the
2860 #define RANGES_TABLE_INCREMENT 64
2862 /* Whether we have location lists that need outputting */
2863 static GTY(()) bool have_location_lists
;
2865 /* Unique label counter. */
2866 static GTY(()) unsigned int loclabel_num
;
2868 /* Unique label counter for point-of-call tables. */
2869 static GTY(()) unsigned int poc_label_num
;
2871 /* Record whether the function being analyzed contains inlined functions. */
2872 static int current_function_has_inlines
;
2874 /* The last file entry emitted by maybe_emit_file(). */
2875 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2877 /* Number of internal labels generated by gen_internal_sym(). */
2878 static GTY(()) int label_num
;
2880 /* Cached result of previous call to lookup_filename. */
2881 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2883 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2885 /* Instances of generic types for which we need to generate debug
2886 info that describe their generic parameters and arguments. That
2887 generation needs to happen once all types are properly laid out so
2888 we do it at the end of compilation. */
2889 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2891 /* Offset from the "steady-state frame pointer" to the frame base,
2892 within the current function. */
2893 static HOST_WIDE_INT frame_pointer_fb_offset
;
2894 static bool frame_pointer_fb_offset_valid
;
2896 static vec
<dw_die_ref
> base_types
;
2898 /* Forward declarations for functions defined in this file. */
2900 static int is_pseudo_reg (const_rtx
);
2901 static tree
type_main_variant (tree
);
2902 static int is_tagged_type (const_tree
);
2903 static const char *dwarf_tag_name (unsigned);
2904 static const char *dwarf_attr_name (unsigned);
2905 static const char *dwarf_form_name (unsigned);
2906 static tree
decl_ultimate_origin (const_tree
);
2907 static tree
decl_class_context (tree
);
2908 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2909 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2910 static inline unsigned int AT_index (dw_attr_ref
);
2911 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2912 static inline unsigned AT_flag (dw_attr_ref
);
2913 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2914 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2915 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2916 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2917 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2918 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2919 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2920 unsigned int, unsigned char *);
2921 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2922 static hashval_t
debug_str_do_hash (const void *);
2923 static int debug_str_eq (const void *, const void *);
2924 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2925 static inline const char *AT_string (dw_attr_ref
);
2926 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2927 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2928 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2929 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2930 static inline int AT_ref_external (dw_attr_ref
);
2931 static inline void set_AT_ref_external (dw_attr_ref
, int);
2932 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2933 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2934 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2935 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2937 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2938 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2939 static void remove_addr_table_entry (addr_table_entry
*);
2940 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2941 static inline rtx
AT_addr (dw_attr_ref
);
2942 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2943 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2944 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2945 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2946 unsigned HOST_WIDE_INT
);
2947 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2948 unsigned long, bool);
2949 static inline const char *AT_lbl (dw_attr_ref
);
2950 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2951 static const char *get_AT_low_pc (dw_die_ref
);
2952 static const char *get_AT_hi_pc (dw_die_ref
);
2953 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2954 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2955 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2956 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2957 static bool is_cxx (void);
2958 static bool is_fortran (void);
2959 static bool is_ada (void);
2960 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2961 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2962 static void add_child_die (dw_die_ref
, dw_die_ref
);
2963 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2964 static dw_die_ref
lookup_type_die (tree
);
2965 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2966 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2967 static void equate_type_number_to_die (tree
, dw_die_ref
);
2968 static hashval_t
decl_die_table_hash (const void *);
2969 static int decl_die_table_eq (const void *, const void *);
2970 static dw_die_ref
lookup_decl_die (tree
);
2971 static hashval_t
common_block_die_table_hash (const void *);
2972 static int common_block_die_table_eq (const void *, const void *);
2973 static hashval_t
decl_loc_table_hash (const void *);
2974 static int decl_loc_table_eq (const void *, const void *);
2975 static var_loc_list
*lookup_decl_loc (const_tree
);
2976 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2977 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
2978 static void print_spaces (FILE *);
2979 static void print_die (dw_die_ref
, FILE *);
2980 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
2981 static dw_die_ref
pop_compile_unit (dw_die_ref
);
2982 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
2983 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
2984 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
2985 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
2986 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
2987 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
2988 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
2989 struct md5_ctx
*, int *);
2990 struct checksum_attributes
;
2991 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
2992 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
2993 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
2994 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
2995 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
2996 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
2997 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
2998 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
2999 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3000 static void compute_section_prefix (dw_die_ref
);
3001 static int is_type_die (dw_die_ref
);
3002 static int is_comdat_die (dw_die_ref
);
3003 static int is_symbol_die (dw_die_ref
);
3004 static void assign_symbol_names (dw_die_ref
);
3005 static void break_out_includes (dw_die_ref
);
3006 static int is_declaration_die (dw_die_ref
);
3007 static int should_move_die_to_comdat (dw_die_ref
);
3008 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3009 static dw_die_ref
clone_die (dw_die_ref
);
3010 static dw_die_ref
clone_tree (dw_die_ref
);
3011 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3012 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3013 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3014 static dw_die_ref
generate_skeleton (dw_die_ref
);
3015 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3018 static void break_out_comdat_types (dw_die_ref
);
3019 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
3020 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
3021 static void copy_decls_for_unworthy_types (dw_die_ref
);
3023 static hashval_t
htab_cu_hash (const void *);
3024 static int htab_cu_eq (const void *, const void *);
3025 static void htab_cu_del (void *);
3026 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3027 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3028 static void add_sibling_attributes (dw_die_ref
);
3029 static void build_abbrev_table (dw_die_ref
, htab_t
);
3030 static void output_location_lists (dw_die_ref
);
3031 static int constant_size (unsigned HOST_WIDE_INT
);
3032 static unsigned long size_of_die (dw_die_ref
);
3033 static void calc_die_sizes (dw_die_ref
);
3034 static void calc_base_type_die_sizes (void);
3035 static void mark_dies (dw_die_ref
);
3036 static void unmark_dies (dw_die_ref
);
3037 static void unmark_all_dies (dw_die_ref
);
3038 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3039 static unsigned long size_of_aranges (void);
3040 static enum dwarf_form
value_format (dw_attr_ref
);
3041 static void output_value_format (dw_attr_ref
);
3042 static void output_abbrev_section (void);
3043 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3044 static void output_die_symbol (dw_die_ref
);
3045 static void output_die (dw_die_ref
);
3046 static void output_compilation_unit_header (void);
3047 static void output_comp_unit (dw_die_ref
, int);
3048 static void output_comdat_type_unit (comdat_type_node
*);
3049 static const char *dwarf2_name (tree
, int);
3050 static void add_pubname (tree
, dw_die_ref
);
3051 static void add_enumerator_pubname (const char *, dw_die_ref
);
3052 static void add_pubname_string (const char *, dw_die_ref
);
3053 static void add_pubtype (tree
, dw_die_ref
);
3054 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3055 static void output_aranges (unsigned long);
3056 static unsigned int add_ranges_num (int);
3057 static unsigned int add_ranges (const_tree
);
3058 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3060 static void output_ranges (void);
3061 static dw_line_info_table
*new_line_info_table (void);
3062 static void output_line_info (bool);
3063 static void output_file_names (void);
3064 static dw_die_ref
base_type_die (tree
);
3065 static int is_base_type (tree
);
3066 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3067 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3068 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3069 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3070 static int type_is_enum (const_tree
);
3071 static unsigned int dbx_reg_number (const_rtx
);
3072 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3073 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3074 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3075 enum var_init_status
);
3076 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3077 enum var_init_status
);
3078 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3079 enum var_init_status
);
3080 static int is_based_loc (const_rtx
);
3081 static int resolve_one_addr (rtx
*, void *);
3082 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3083 enum var_init_status
);
3084 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3085 enum var_init_status
);
3086 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3087 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3088 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3089 static tree
field_type (const_tree
);
3090 static unsigned int simple_type_align_in_bits (const_tree
);
3091 static unsigned int simple_decl_align_in_bits (const_tree
);
3092 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3093 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3094 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3096 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3097 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3098 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3099 static void insert_double (double_int
, unsigned char *);
3100 static void insert_float (const_rtx
, unsigned char *);
3101 static rtx
rtl_for_decl_location (tree
);
3102 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3103 enum dwarf_attribute
);
3104 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3105 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3106 static void add_name_attribute (dw_die_ref
, const char *);
3107 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3108 static void add_comp_dir_attribute (dw_die_ref
);
3109 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3110 static void add_subscript_info (dw_die_ref
, tree
, bool);
3111 static void add_byte_size_attribute (dw_die_ref
, tree
);
3112 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3113 static void add_bit_size_attribute (dw_die_ref
, tree
);
3114 static void add_prototyped_attribute (dw_die_ref
, tree
);
3115 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3116 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3117 static void add_src_coords_attributes (dw_die_ref
, tree
);
3118 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3119 static void push_decl_scope (tree
);
3120 static void pop_decl_scope (void);
3121 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3122 static inline int local_scope_p (dw_die_ref
);
3123 static inline int class_scope_p (dw_die_ref
);
3124 static inline int class_or_namespace_scope_p (dw_die_ref
);
3125 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3126 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3127 static const char *type_tag (const_tree
);
3128 static tree
member_declared_type (const_tree
);
3130 static const char *decl_start_label (tree
);
3132 static void gen_array_type_die (tree
, dw_die_ref
);
3133 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3135 static void gen_entry_point_die (tree
, dw_die_ref
);
3137 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3138 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3139 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3140 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3141 static void gen_formal_types_die (tree
, dw_die_ref
);
3142 static void gen_subprogram_die (tree
, dw_die_ref
);
3143 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3144 static void gen_const_die (tree
, dw_die_ref
);
3145 static void gen_label_die (tree
, dw_die_ref
);
3146 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3147 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3148 static void gen_field_die (tree
, dw_die_ref
);
3149 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3150 static dw_die_ref
gen_compile_unit_die (const char *);
3151 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3152 static void gen_member_die (tree
, dw_die_ref
);
3153 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3154 enum debug_info_usage
);
3155 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3156 static void gen_typedef_die (tree
, dw_die_ref
);
3157 static void gen_type_die (tree
, dw_die_ref
);
3158 static void gen_block_die (tree
, dw_die_ref
, int);
3159 static void decls_for_scope (tree
, dw_die_ref
, int);
3160 static inline int is_redundant_typedef (const_tree
);
3161 static bool is_naming_typedef_decl (const_tree
);
3162 static inline dw_die_ref
get_context_die (tree
);
3163 static void gen_namespace_die (tree
, dw_die_ref
);
3164 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3165 static dw_die_ref
force_decl_die (tree
);
3166 static dw_die_ref
force_type_die (tree
);
3167 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3168 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3169 static struct dwarf_file_data
* lookup_filename (const char *);
3170 static void retry_incomplete_types (void);
3171 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3172 static void gen_generic_params_dies (tree
);
3173 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3174 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3175 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3176 static int file_info_cmp (const void *, const void *);
3177 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3178 const char *, const char *);
3179 static void output_loc_list (dw_loc_list_ref
);
3180 static char *gen_internal_sym (const char *);
3181 static bool want_pubnames (void);
3183 static void prune_unmark_dies (dw_die_ref
);
3184 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3185 static void prune_unused_types_mark (dw_die_ref
, int);
3186 static void prune_unused_types_walk (dw_die_ref
);
3187 static void prune_unused_types_walk_attribs (dw_die_ref
);
3188 static void prune_unused_types_prune (dw_die_ref
);
3189 static void prune_unused_types (void);
3190 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3191 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3192 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3193 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3194 const char *, const char *);
3195 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3196 static void gen_remaining_tmpl_value_param_die_attribute (void);
3197 static bool generic_type_p (tree
);
3198 static void schedule_generic_params_dies_gen (tree t
);
3199 static void gen_scheduled_generic_parms_dies (void);
3201 /* enum for tracking thread-local variables whose address is really an offset
3202 relative to the TLS pointer, which will need link-time relocation, but will
3203 not need relocation by the DWARF consumer. */
3211 /* Return the operator to use for an address of a variable. For dtprel_true, we
3212 use DW_OP_const*. For regular variables, which need both link-time
3213 relocation and consumer-level relocation (e.g., to account for shared objects
3214 loaded at a random address), we use DW_OP_addr*. */
3216 static inline enum dwarf_location_atom
3217 dw_addr_op (enum dtprel_bool dtprel
)
3219 if (dtprel
== dtprel_true
)
3220 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3221 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3223 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3226 /* Return a pointer to a newly allocated address location description. If
3227 dwarf_split_debug_info is true, then record the address with the appropriate
3229 static inline dw_loc_descr_ref
3230 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3232 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3234 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3235 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3236 ref
->dtprel
= dtprel
;
3237 if (dwarf_split_debug_info
)
3238 ref
->dw_loc_oprnd1
.val_entry
3239 = add_addr_table_entry (addr
,
3240 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3242 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3247 /* Section names used to hold DWARF debugging information. */
3249 #ifndef DEBUG_INFO_SECTION
3250 #define DEBUG_INFO_SECTION ".debug_info"
3252 #ifndef DEBUG_DWO_INFO_SECTION
3253 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3255 #ifndef DEBUG_ABBREV_SECTION
3256 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3258 #ifndef DEBUG_DWO_ABBREV_SECTION
3259 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3261 #ifndef DEBUG_ARANGES_SECTION
3262 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3264 #ifndef DEBUG_ADDR_SECTION
3265 #define DEBUG_ADDR_SECTION ".debug_addr"
3267 #ifndef DEBUG_NORM_MACINFO_SECTION
3268 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3270 #ifndef DEBUG_DWO_MACINFO_SECTION
3271 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3273 #ifndef DEBUG_MACINFO_SECTION
3274 #define DEBUG_MACINFO_SECTION \
3275 (!dwarf_split_debug_info \
3276 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3278 #ifndef DEBUG_NORM_MACRO_SECTION
3279 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3281 #ifndef DEBUG_DWO_MACRO_SECTION
3282 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3284 #ifndef DEBUG_MACRO_SECTION
3285 #define DEBUG_MACRO_SECTION \
3286 (!dwarf_split_debug_info \
3287 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3289 #ifndef DEBUG_LINE_SECTION
3290 #define DEBUG_LINE_SECTION ".debug_line"
3292 #ifndef DEBUG_DWO_LINE_SECTION
3293 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3295 #ifndef DEBUG_LOC_SECTION
3296 #define DEBUG_LOC_SECTION ".debug_loc"
3298 #ifndef DEBUG_DWO_LOC_SECTION
3299 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3301 #ifndef DEBUG_PUBNAMES_SECTION
3302 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3304 #ifndef DEBUG_PUBTYPES_SECTION
3305 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3307 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3308 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3309 #ifndef DEBUG_STR_OFFSETS_SECTION
3310 #define DEBUG_STR_OFFSETS_SECTION \
3311 (!dwarf_split_debug_info \
3312 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3314 #define DEBUG_DWO_STR_SECTION ".debug_str.dwo"
3315 #define DEBUG_NORM_STR_SECTION ".debug_str"
3316 #ifndef DEBUG_STR_SECTION
3317 #define DEBUG_STR_SECTION \
3318 (!dwarf_split_debug_info ? (DEBUG_NORM_STR_SECTION) : (DEBUG_DWO_STR_SECTION))
3320 #ifndef DEBUG_RANGES_SECTION
3321 #define DEBUG_RANGES_SECTION ".debug_ranges"
3324 /* Standard ELF section names for compiled code and data. */
3325 #ifndef TEXT_SECTION_NAME
3326 #define TEXT_SECTION_NAME ".text"
3329 /* Section flags for .debug_macinfo/.debug_macro section. */
3330 #define DEBUG_MACRO_SECTION_FLAGS \
3331 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3333 /* Section flags for .debug_str section. */
3334 #define DEBUG_STR_SECTION_FLAGS \
3335 (dwarf_split_debug_info \
3336 ? SECTION_DEBUG | SECTION_EXCLUDE \
3337 : (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3338 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3341 /* Labels we insert at beginning sections we can reference instead of
3342 the section names themselves. */
3344 #ifndef TEXT_SECTION_LABEL
3345 #define TEXT_SECTION_LABEL "Ltext"
3347 #ifndef COLD_TEXT_SECTION_LABEL
3348 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3350 #ifndef DEBUG_LINE_SECTION_LABEL
3351 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3353 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3354 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3356 #ifndef DEBUG_INFO_SECTION_LABEL
3357 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3359 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3360 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3362 #ifndef DEBUG_ABBREV_SECTION_LABEL
3363 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3365 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3366 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3368 #ifndef DEBUG_ADDR_SECTION_LABEL
3369 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3371 #ifndef DEBUG_LOC_SECTION_LABEL
3372 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3374 #ifndef DEBUG_RANGES_SECTION_LABEL
3375 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3377 #ifndef DEBUG_MACINFO_SECTION_LABEL
3378 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3380 #ifndef DEBUG_MACRO_SECTION_LABEL
3381 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3383 #define SKELETON_COMP_DIE_ABBREV 1
3384 #define SKELETON_TYPE_DIE_ABBREV 2
3386 /* Definitions of defaults for formats and names of various special
3387 (artificial) labels which may be generated within this file (when the -g
3388 options is used and DWARF2_DEBUGGING_INFO is in effect.
3389 If necessary, these may be overridden from within the tm.h file, but
3390 typically, overriding these defaults is unnecessary. */
3392 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3393 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3394 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3395 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3396 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3397 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3398 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3399 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3400 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3401 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3402 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3403 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3404 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3405 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3407 #ifndef TEXT_END_LABEL
3408 #define TEXT_END_LABEL "Letext"
3410 #ifndef COLD_END_LABEL
3411 #define COLD_END_LABEL "Letext_cold"
3413 #ifndef BLOCK_BEGIN_LABEL
3414 #define BLOCK_BEGIN_LABEL "LBB"
3416 #ifndef BLOCK_END_LABEL
3417 #define BLOCK_END_LABEL "LBE"
3419 #ifndef LINE_CODE_LABEL
3420 #define LINE_CODE_LABEL "LM"
3424 /* Return the root of the DIE's built for the current compilation unit. */
3426 comp_unit_die (void)
3428 if (!single_comp_unit_die
)
3429 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3430 return single_comp_unit_die
;
3433 /* We allow a language front-end to designate a function that is to be
3434 called to "demangle" any name before it is put into a DIE. */
3436 static const char *(*demangle_name_func
) (const char *);
3439 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3441 demangle_name_func
= func
;
3444 /* Test if rtl node points to a pseudo register. */
3447 is_pseudo_reg (const_rtx rtl
)
3449 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3450 || (GET_CODE (rtl
) == SUBREG
3451 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3454 /* Return a reference to a type, with its const and volatile qualifiers
3458 type_main_variant (tree type
)
3460 type
= TYPE_MAIN_VARIANT (type
);
3462 /* ??? There really should be only one main variant among any group of
3463 variants of a given type (and all of the MAIN_VARIANT values for all
3464 members of the group should point to that one type) but sometimes the C
3465 front-end messes this up for array types, so we work around that bug
3467 if (TREE_CODE (type
) == ARRAY_TYPE
)
3468 while (type
!= TYPE_MAIN_VARIANT (type
))
3469 type
= TYPE_MAIN_VARIANT (type
);
3474 /* Return nonzero if the given type node represents a tagged type. */
3477 is_tagged_type (const_tree type
)
3479 enum tree_code code
= TREE_CODE (type
);
3481 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3482 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3485 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3488 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3490 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3493 /* Return die_offset of a DIE reference to a base type. */
3495 static unsigned long int
3496 get_base_type_offset (dw_die_ref ref
)
3498 if (ref
->die_offset
)
3499 return ref
->die_offset
;
3500 if (comp_unit_die ()->die_abbrev
)
3502 calc_base_type_die_sizes ();
3503 gcc_assert (ref
->die_offset
);
3505 return ref
->die_offset
;
3508 /* Return die_offset of a DIE reference other than base type. */
3510 static unsigned long int
3511 get_ref_die_offset (dw_die_ref ref
)
3513 gcc_assert (ref
->die_offset
);
3514 return ref
->die_offset
;
3517 /* Convert a DIE tag into its string name. */
3520 dwarf_tag_name (unsigned int tag
)
3522 const char *name
= get_DW_TAG_name (tag
);
3527 return "DW_TAG_<unknown>";
3530 /* Convert a DWARF attribute code into its string name. */
3533 dwarf_attr_name (unsigned int attr
)
3539 #if VMS_DEBUGGING_INFO
3540 case DW_AT_HP_prologue
:
3541 return "DW_AT_HP_prologue";
3543 case DW_AT_MIPS_loop_unroll_factor
:
3544 return "DW_AT_MIPS_loop_unroll_factor";
3547 #if VMS_DEBUGGING_INFO
3548 case DW_AT_HP_epilogue
:
3549 return "DW_AT_HP_epilogue";
3551 case DW_AT_MIPS_stride
:
3552 return "DW_AT_MIPS_stride";
3556 name
= get_DW_AT_name (attr
);
3561 return "DW_AT_<unknown>";
3564 /* Convert a DWARF value form code into its string name. */
3567 dwarf_form_name (unsigned int form
)
3569 const char *name
= get_DW_FORM_name (form
);
3574 return "DW_FORM_<unknown>";
3577 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3578 instance of an inlined instance of a decl which is local to an inline
3579 function, so we have to trace all of the way back through the origin chain
3580 to find out what sort of node actually served as the original seed for the
3584 decl_ultimate_origin (const_tree decl
)
3586 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3589 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3590 nodes in the function to point to themselves; ignore that if
3591 we're trying to output the abstract instance of this function. */
3592 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3595 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3596 most distant ancestor, this should never happen. */
3597 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3599 return DECL_ABSTRACT_ORIGIN (decl
);
3602 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3603 of a virtual function may refer to a base class, so we check the 'this'
3607 decl_class_context (tree decl
)
3609 tree context
= NULL_TREE
;
3611 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3612 context
= DECL_CONTEXT (decl
);
3614 context
= TYPE_MAIN_VARIANT
3615 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3617 if (context
&& !TYPE_P (context
))
3618 context
= NULL_TREE
;
3623 /* Add an attribute/value pair to a DIE. */
3626 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3628 /* Maybe this should be an assert? */
3632 vec_safe_reserve (die
->die_attr
, 1);
3633 vec_safe_push (die
->die_attr
, *attr
);
3636 static inline enum dw_val_class
3637 AT_class (dw_attr_ref a
)
3639 return a
->dw_attr_val
.val_class
;
3642 /* Return the index for any attribute that will be referenced with a
3643 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3644 are stored in dw_attr_val.v.val_str for reference counting
3647 static inline unsigned int
3648 AT_index (dw_attr_ref a
)
3650 if (AT_class (a
) == dw_val_class_str
)
3651 return a
->dw_attr_val
.v
.val_str
->index
;
3652 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3653 return a
->dw_attr_val
.val_entry
->index
;
3657 /* Add a flag value attribute to a DIE. */
3660 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3664 attr
.dw_attr
= attr_kind
;
3665 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3666 attr
.dw_attr_val
.val_entry
= NULL
;
3667 attr
.dw_attr_val
.v
.val_flag
= flag
;
3668 add_dwarf_attr (die
, &attr
);
3671 static inline unsigned
3672 AT_flag (dw_attr_ref a
)
3674 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3675 return a
->dw_attr_val
.v
.val_flag
;
3678 /* Add a signed integer attribute value to a DIE. */
3681 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3685 attr
.dw_attr
= attr_kind
;
3686 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3687 attr
.dw_attr_val
.val_entry
= NULL
;
3688 attr
.dw_attr_val
.v
.val_int
= int_val
;
3689 add_dwarf_attr (die
, &attr
);
3692 static inline HOST_WIDE_INT
3693 AT_int (dw_attr_ref a
)
3695 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3696 return a
->dw_attr_val
.v
.val_int
;
3699 /* Add an unsigned integer attribute value to a DIE. */
3702 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3703 unsigned HOST_WIDE_INT unsigned_val
)
3707 attr
.dw_attr
= attr_kind
;
3708 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3709 attr
.dw_attr_val
.val_entry
= NULL
;
3710 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3711 add_dwarf_attr (die
, &attr
);
3714 static inline unsigned HOST_WIDE_INT
3715 AT_unsigned (dw_attr_ref a
)
3717 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3718 return a
->dw_attr_val
.v
.val_unsigned
;
3721 /* Add an unsigned double integer attribute value to a DIE. */
3724 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3725 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3729 attr
.dw_attr
= attr_kind
;
3730 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3731 attr
.dw_attr_val
.val_entry
= NULL
;
3732 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3733 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3734 add_dwarf_attr (die
, &attr
);
3737 /* Add a floating point attribute value to a DIE and return it. */
3740 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3741 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3745 attr
.dw_attr
= attr_kind
;
3746 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3747 attr
.dw_attr_val
.val_entry
= NULL
;
3748 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3749 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3750 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3751 add_dwarf_attr (die
, &attr
);
3754 /* Add an 8-byte data attribute value to a DIE. */
3757 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3758 unsigned char data8
[8])
3762 attr
.dw_attr
= attr_kind
;
3763 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3764 attr
.dw_attr_val
.val_entry
= NULL
;
3765 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3766 add_dwarf_attr (die
, &attr
);
3769 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3770 dwarf_split_debug_info, address attributes in dies destined for the
3771 final executable have force_direct set to avoid using indexed
3775 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3781 lbl_id
= xstrdup (lbl_low
);
3782 attr
.dw_attr
= DW_AT_low_pc
;
3783 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3784 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3785 if (dwarf_split_debug_info
&& !force_direct
)
3786 attr
.dw_attr_val
.val_entry
3787 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3789 attr
.dw_attr_val
.val_entry
= NULL
;
3790 add_dwarf_attr (die
, &attr
);
3792 attr
.dw_attr
= DW_AT_high_pc
;
3793 if (dwarf_version
< 4)
3794 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3796 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3797 lbl_id
= xstrdup (lbl_high
);
3798 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3799 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3800 && dwarf_split_debug_info
&& !force_direct
)
3801 attr
.dw_attr_val
.val_entry
3802 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3804 attr
.dw_attr_val
.val_entry
= NULL
;
3805 add_dwarf_attr (die
, &attr
);
3808 /* Hash and equality functions for debug_str_hash. */
3811 debug_str_do_hash (const void *x
)
3813 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3817 debug_str_eq (const void *x1
, const void *x2
)
3819 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3820 (const char *)x2
) == 0;
3823 /* Add STR to the indirect string hash table. */
3825 static struct indirect_string_node
*
3826 find_AT_string (const char *str
)
3828 struct indirect_string_node
*node
;
3831 if (! debug_str_hash
)
3832 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3833 debug_str_eq
, NULL
);
3835 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
3836 htab_hash_string (str
), INSERT
);
3839 node
= ggc_alloc_cleared_indirect_string_node ();
3840 node
->str
= ggc_strdup (str
);
3844 node
= (struct indirect_string_node
*) *slot
;
3850 /* Add a string attribute value to a DIE. */
3853 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3856 struct indirect_string_node
*node
;
3858 node
= find_AT_string (str
);
3860 attr
.dw_attr
= attr_kind
;
3861 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3862 attr
.dw_attr_val
.val_entry
= NULL
;
3863 attr
.dw_attr_val
.v
.val_str
= node
;
3864 add_dwarf_attr (die
, &attr
);
3867 static inline const char *
3868 AT_string (dw_attr_ref a
)
3870 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3871 return a
->dw_attr_val
.v
.val_str
->str
;
3874 /* Call this function directly to bypass AT_string_form's logic to put
3875 the string inline in the die. */
3878 set_indirect_string (struct indirect_string_node
*node
)
3881 /* Already indirect is a no op. */
3882 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3884 gcc_assert (node
->label
);
3887 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3888 ++dw2_string_counter
;
3889 node
->label
= xstrdup (label
);
3891 if (!dwarf_split_debug_info
)
3893 node
->form
= DW_FORM_strp
;
3894 node
->index
= NOT_INDEXED
;
3898 node
->form
= DW_FORM_GNU_str_index
;
3899 node
->index
= NO_INDEX_ASSIGNED
;
3903 /* Find out whether a string should be output inline in DIE
3904 or out-of-line in .debug_str section. */
3906 static enum dwarf_form
3907 find_string_form (struct indirect_string_node
*node
)
3914 len
= strlen (node
->str
) + 1;
3916 /* If the string is shorter or equal to the size of the reference, it is
3917 always better to put it inline. */
3918 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3919 return node
->form
= DW_FORM_string
;
3921 /* If we cannot expect the linker to merge strings in .debug_str
3922 section, only put it into .debug_str if it is worth even in this
3924 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3925 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3926 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3927 return node
->form
= DW_FORM_string
;
3929 set_indirect_string (node
);
3934 /* Find out whether the string referenced from the attribute should be
3935 output inline in DIE or out-of-line in .debug_str section. */
3937 static enum dwarf_form
3938 AT_string_form (dw_attr_ref a
)
3940 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3941 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3944 /* Add a DIE reference attribute value to a DIE. */
3947 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3951 #ifdef ENABLE_CHECKING
3952 gcc_assert (targ_die
!= NULL
);
3954 /* With LTO we can end up trying to reference something we didn't create
3955 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3956 if (targ_die
== NULL
)
3960 attr
.dw_attr
= attr_kind
;
3961 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3962 attr
.dw_attr_val
.val_entry
= NULL
;
3963 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3964 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3965 add_dwarf_attr (die
, &attr
);
3968 /* Change DIE reference REF to point to NEW_DIE instead. */
3971 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
3973 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
3974 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
3975 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
3978 /* Add an AT_specification attribute to a DIE, and also make the back
3979 pointer from the specification to the definition. */
3982 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
3984 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
3985 gcc_assert (!targ_die
->die_definition
);
3986 targ_die
->die_definition
= die
;
3989 static inline dw_die_ref
3990 AT_ref (dw_attr_ref a
)
3992 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3993 return a
->dw_attr_val
.v
.val_die_ref
.die
;
3997 AT_ref_external (dw_attr_ref a
)
3999 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4000 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4006 set_AT_ref_external (dw_attr_ref a
, int i
)
4008 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4009 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4012 /* Add an FDE reference attribute value to a DIE. */
4015 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4019 attr
.dw_attr
= attr_kind
;
4020 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4021 attr
.dw_attr_val
.val_entry
= NULL
;
4022 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4023 add_dwarf_attr (die
, &attr
);
4026 /* Add a location description attribute value to a DIE. */
4029 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4033 attr
.dw_attr
= attr_kind
;
4034 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4035 attr
.dw_attr_val
.val_entry
= NULL
;
4036 attr
.dw_attr_val
.v
.val_loc
= loc
;
4037 add_dwarf_attr (die
, &attr
);
4040 static inline dw_loc_descr_ref
4041 AT_loc (dw_attr_ref a
)
4043 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4044 return a
->dw_attr_val
.v
.val_loc
;
4048 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4052 attr
.dw_attr
= attr_kind
;
4053 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4054 attr
.dw_attr_val
.val_entry
= NULL
;
4055 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4056 add_dwarf_attr (die
, &attr
);
4057 have_location_lists
= true;
4060 static inline dw_loc_list_ref
4061 AT_loc_list (dw_attr_ref a
)
4063 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4064 return a
->dw_attr_val
.v
.val_loc_list
;
4067 static inline dw_loc_list_ref
*
4068 AT_loc_list_ptr (dw_attr_ref a
)
4070 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4071 return &a
->dw_attr_val
.v
.val_loc_list
;
4074 /* Table of entries into the .debug_addr section. */
4076 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4078 /* Hash an address_table_entry. */
4081 addr_table_entry_do_hash (const void *x
)
4083 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4087 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4088 case ate_kind_rtx_dtprel
:
4089 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4090 case ate_kind_label
:
4091 return htab_hash_string (a
->addr
.label
);
4097 /* Determine equality for two address_table_entries. */
4100 addr_table_entry_eq (const void *x1
, const void *x2
)
4102 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4103 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4105 if (a1
->kind
!= a2
->kind
)
4110 case ate_kind_rtx_dtprel
:
4111 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4112 case ate_kind_label
:
4113 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4119 /* Initialize an addr_table_entry. */
4122 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4128 case ate_kind_rtx_dtprel
:
4129 e
->addr
.rtl
= (rtx
) addr
;
4131 case ate_kind_label
:
4132 e
->addr
.label
= (char *) addr
;
4136 e
->index
= NO_INDEX_ASSIGNED
;
4139 /* Add attr to the address table entry to the table. Defer setting an
4140 index until output time. */
4142 static addr_table_entry
*
4143 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4145 addr_table_entry
*node
;
4146 addr_table_entry finder
;
4149 gcc_assert (dwarf_split_debug_info
);
4150 if (! addr_index_table
)
4151 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4152 addr_table_entry_eq
, NULL
);
4153 init_addr_table_entry (&finder
, kind
, addr
);
4154 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4156 if (*slot
== HTAB_EMPTY_ENTRY
)
4158 node
= ggc_alloc_cleared_addr_table_entry ();
4159 init_addr_table_entry (node
, kind
, addr
);
4163 node
= (addr_table_entry
*) *slot
;
4169 /* Remove an entry from the addr table by decrementing its refcount.
4170 Strictly, decrementing the refcount would be enough, but the
4171 assertion that the entry is actually in the table has found
4175 remove_addr_table_entry (addr_table_entry
*entry
)
4177 addr_table_entry
*node
;
4179 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4180 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4181 /* After an index is assigned, the table is frozen. */
4182 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4186 /* Given a location list, remove all addresses it refers to from the
4190 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4192 for (; descr
; descr
= descr
->dw_loc_next
)
4193 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4195 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4196 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4200 /* A helper function for dwarf2out_finish called through
4201 htab_traverse. Assign an addr_table_entry its index. All entries
4202 must be collected into the table when this function is called,
4203 because the indexing code relies on htab_traverse to traverse nodes
4204 in the same order for each run. */
4207 index_addr_table_entry (void **h
, void *v
)
4209 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4210 unsigned int *index
= (unsigned int *) v
;
4212 /* Don't index unreferenced nodes. */
4213 if (node
->refcount
== 0)
4216 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4217 node
->index
= *index
;
4223 /* Add an address constant attribute value to a DIE. When using
4224 dwarf_split_debug_info, address attributes in dies destined for the
4225 final executable should be direct references--setting the parameter
4226 force_direct ensures this behavior. */
4229 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4234 attr
.dw_attr
= attr_kind
;
4235 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4236 attr
.dw_attr_val
.v
.val_addr
= addr
;
4237 if (dwarf_split_debug_info
&& !force_direct
)
4238 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4240 attr
.dw_attr_val
.val_entry
= NULL
;
4241 add_dwarf_attr (die
, &attr
);
4244 /* Get the RTX from to an address DIE attribute. */
4247 AT_addr (dw_attr_ref a
)
4249 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4250 return a
->dw_attr_val
.v
.val_addr
;
4253 /* Add a file attribute value to a DIE. */
4256 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4257 struct dwarf_file_data
*fd
)
4261 attr
.dw_attr
= attr_kind
;
4262 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4263 attr
.dw_attr_val
.val_entry
= NULL
;
4264 attr
.dw_attr_val
.v
.val_file
= fd
;
4265 add_dwarf_attr (die
, &attr
);
4268 /* Get the dwarf_file_data from a file DIE attribute. */
4270 static inline struct dwarf_file_data
*
4271 AT_file (dw_attr_ref a
)
4273 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4274 return a
->dw_attr_val
.v
.val_file
;
4277 /* Add a vms delta attribute value to a DIE. */
4280 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4281 const char *lbl1
, const char *lbl2
)
4285 attr
.dw_attr
= attr_kind
;
4286 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4287 attr
.dw_attr_val
.val_entry
= NULL
;
4288 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4289 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4290 add_dwarf_attr (die
, &attr
);
4293 /* Add a label identifier attribute value to a DIE. */
4296 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4301 attr
.dw_attr
= attr_kind
;
4302 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4303 attr
.dw_attr_val
.val_entry
= NULL
;
4304 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4305 if (dwarf_split_debug_info
)
4306 attr
.dw_attr_val
.val_entry
4307 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4309 add_dwarf_attr (die
, &attr
);
4312 /* Add a section offset attribute value to a DIE, an offset into the
4313 debug_line section. */
4316 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4321 attr
.dw_attr
= attr_kind
;
4322 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4323 attr
.dw_attr_val
.val_entry
= NULL
;
4324 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4325 add_dwarf_attr (die
, &attr
);
4328 /* Add a section offset attribute value to a DIE, an offset into the
4329 debug_macinfo section. */
4332 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4337 attr
.dw_attr
= attr_kind
;
4338 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4339 attr
.dw_attr_val
.val_entry
= NULL
;
4340 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4341 add_dwarf_attr (die
, &attr
);
4344 /* Add an offset attribute value to a DIE. */
4347 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4348 unsigned HOST_WIDE_INT offset
)
4352 attr
.dw_attr
= attr_kind
;
4353 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4354 attr
.dw_attr_val
.val_entry
= NULL
;
4355 attr
.dw_attr_val
.v
.val_offset
= offset
;
4356 add_dwarf_attr (die
, &attr
);
4359 /* Add a range_list attribute value to a DIE. When using
4360 dwarf_split_debug_info, address attributes in dies destined for the
4361 final executable should be direct references--setting the parameter
4362 force_direct ensures this behavior. */
4364 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4365 #define RELOCATED_OFFSET (NULL)
4368 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4369 long unsigned int offset
, bool force_direct
)
4373 attr
.dw_attr
= attr_kind
;
4374 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4375 /* For the range_list attribute, use val_entry to store whether the
4376 offset should follow split-debug-info or normal semantics. This
4377 value is read in output_range_list_offset. */
4378 if (dwarf_split_debug_info
&& !force_direct
)
4379 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4381 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4382 attr
.dw_attr_val
.v
.val_offset
= offset
;
4383 add_dwarf_attr (die
, &attr
);
4386 /* Return the start label of a delta attribute. */
4388 static inline const char *
4389 AT_vms_delta1 (dw_attr_ref a
)
4391 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4392 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4395 /* Return the end label of a delta attribute. */
4397 static inline const char *
4398 AT_vms_delta2 (dw_attr_ref a
)
4400 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4401 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4404 static inline const char *
4405 AT_lbl (dw_attr_ref a
)
4407 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4408 || AT_class (a
) == dw_val_class_lineptr
4409 || AT_class (a
) == dw_val_class_macptr
4410 || AT_class (a
) == dw_val_class_high_pc
));
4411 return a
->dw_attr_val
.v
.val_lbl_id
;
4414 /* Get the attribute of type attr_kind. */
4417 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4421 dw_die_ref spec
= NULL
;
4426 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4427 if (a
->dw_attr
== attr_kind
)
4429 else if (a
->dw_attr
== DW_AT_specification
4430 || a
->dw_attr
== DW_AT_abstract_origin
)
4434 return get_AT (spec
, attr_kind
);
4439 /* Returns the parent of the declaration of DIE. */
4442 get_die_parent (dw_die_ref die
)
4449 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4450 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4453 return die
->die_parent
;
4456 /* Return the "low pc" attribute value, typically associated with a subprogram
4457 DIE. Return null if the "low pc" attribute is either not present, or if it
4458 cannot be represented as an assembler label identifier. */
4460 static inline const char *
4461 get_AT_low_pc (dw_die_ref die
)
4463 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4465 return a
? AT_lbl (a
) : NULL
;
4468 /* Return the "high pc" attribute value, typically associated with a subprogram
4469 DIE. Return null if the "high pc" attribute is either not present, or if it
4470 cannot be represented as an assembler label identifier. */
4472 static inline const char *
4473 get_AT_hi_pc (dw_die_ref die
)
4475 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4477 return a
? AT_lbl (a
) : NULL
;
4480 /* Return the value of the string attribute designated by ATTR_KIND, or
4481 NULL if it is not present. */
4483 static inline const char *
4484 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4486 dw_attr_ref a
= get_AT (die
, attr_kind
);
4488 return a
? AT_string (a
) : NULL
;
4491 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4492 if it is not present. */
4495 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4497 dw_attr_ref a
= get_AT (die
, attr_kind
);
4499 return a
? AT_flag (a
) : 0;
4502 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4503 if it is not present. */
4505 static inline unsigned
4506 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4508 dw_attr_ref a
= get_AT (die
, attr_kind
);
4510 return a
? AT_unsigned (a
) : 0;
4513 static inline dw_die_ref
4514 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4516 dw_attr_ref a
= get_AT (die
, attr_kind
);
4518 return a
? AT_ref (a
) : NULL
;
4521 static inline struct dwarf_file_data
*
4522 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4524 dw_attr_ref a
= get_AT (die
, attr_kind
);
4526 return a
? AT_file (a
) : NULL
;
4529 /* Return TRUE if the language is C++. */
4534 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4536 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4539 /* Return TRUE if the language is Fortran. */
4544 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4546 return (lang
== DW_LANG_Fortran77
4547 || lang
== DW_LANG_Fortran90
4548 || lang
== DW_LANG_Fortran95
);
4551 /* Return TRUE if the language is Ada. */
4556 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4558 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4561 /* Remove the specified attribute if present. */
4564 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4572 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4573 if (a
->dw_attr
== attr_kind
)
4575 if (AT_class (a
) == dw_val_class_str
)
4576 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4577 a
->dw_attr_val
.v
.val_str
->refcount
--;
4579 /* vec::ordered_remove should help reduce the number of abbrevs
4581 die
->die_attr
->ordered_remove (ix
);
4586 /* Remove CHILD from its parent. PREV must have the property that
4587 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4590 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4592 gcc_assert (child
->die_parent
== prev
->die_parent
);
4593 gcc_assert (prev
->die_sib
== child
);
4596 gcc_assert (child
->die_parent
->die_child
== child
);
4600 prev
->die_sib
= child
->die_sib
;
4601 if (child
->die_parent
->die_child
== child
)
4602 child
->die_parent
->die_child
= prev
;
4605 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4606 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4609 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4611 dw_die_ref parent
= old_child
->die_parent
;
4613 gcc_assert (parent
== prev
->die_parent
);
4614 gcc_assert (prev
->die_sib
== old_child
);
4616 new_child
->die_parent
= parent
;
4617 if (prev
== old_child
)
4619 gcc_assert (parent
->die_child
== old_child
);
4620 new_child
->die_sib
= new_child
;
4624 prev
->die_sib
= new_child
;
4625 new_child
->die_sib
= old_child
->die_sib
;
4627 if (old_child
->die_parent
->die_child
== old_child
)
4628 old_child
->die_parent
->die_child
= new_child
;
4631 /* Move all children from OLD_PARENT to NEW_PARENT. */
4634 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4637 new_parent
->die_child
= old_parent
->die_child
;
4638 old_parent
->die_child
= NULL
;
4639 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4642 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4646 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4652 dw_die_ref prev
= c
;
4654 while (c
->die_tag
== tag
)
4656 remove_child_with_prev (c
, prev
);
4657 /* Might have removed every child. */
4658 if (c
== c
->die_sib
)
4662 } while (c
!= die
->die_child
);
4665 /* Add a CHILD_DIE as the last child of DIE. */
4668 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4670 /* FIXME this should probably be an assert. */
4671 if (! die
|| ! child_die
)
4673 gcc_assert (die
!= child_die
);
4675 child_die
->die_parent
= die
;
4678 child_die
->die_sib
= die
->die_child
->die_sib
;
4679 die
->die_child
->die_sib
= child_die
;
4682 child_die
->die_sib
= child_die
;
4683 die
->die_child
= child_die
;
4686 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4687 is the specification, to the end of PARENT's list of children.
4688 This is done by removing and re-adding it. */
4691 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4695 /* We want the declaration DIE from inside the class, not the
4696 specification DIE at toplevel. */
4697 if (child
->die_parent
!= parent
)
4699 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4705 gcc_assert (child
->die_parent
== parent
4706 || (child
->die_parent
4707 == get_AT_ref (parent
, DW_AT_specification
)));
4709 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4710 if (p
->die_sib
== child
)
4712 remove_child_with_prev (child
, p
);
4716 add_child_die (parent
, child
);
4719 /* Return a pointer to a newly created DIE node. */
4721 static inline dw_die_ref
4722 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4724 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4726 die
->die_tag
= tag_value
;
4728 if (parent_die
!= NULL
)
4729 add_child_die (parent_die
, die
);
4732 limbo_die_node
*limbo_node
;
4734 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4735 limbo_node
->die
= die
;
4736 limbo_node
->created_for
= t
;
4737 limbo_node
->next
= limbo_die_list
;
4738 limbo_die_list
= limbo_node
;
4744 /* Return the DIE associated with the given type specifier. */
4746 static inline dw_die_ref
4747 lookup_type_die (tree type
)
4749 return TYPE_SYMTAB_DIE (type
);
4752 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4753 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4754 anonymous type instead the one of the naming typedef. */
4756 static inline dw_die_ref
4757 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4760 && TREE_CODE (type
) == RECORD_TYPE
4762 && type_die
->die_tag
== DW_TAG_typedef
4763 && is_naming_typedef_decl (TYPE_NAME (type
)))
4764 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4768 /* Like lookup_type_die, but if type is an anonymous type named by a
4769 typedef[1], return the DIE of the anonymous type instead the one of
4770 the naming typedef. This is because in gen_typedef_die, we did
4771 equate the anonymous struct named by the typedef with the DIE of
4772 the naming typedef. So by default, lookup_type_die on an anonymous
4773 struct yields the DIE of the naming typedef.
4775 [1]: Read the comment of is_naming_typedef_decl to learn about what
4776 a naming typedef is. */
4778 static inline dw_die_ref
4779 lookup_type_die_strip_naming_typedef (tree type
)
4781 dw_die_ref die
= lookup_type_die (type
);
4782 return strip_naming_typedef (type
, die
);
4785 /* Equate a DIE to a given type specifier. */
4788 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4790 TYPE_SYMTAB_DIE (type
) = type_die
;
4793 /* Returns a hash value for X (which really is a die_struct). */
4796 decl_die_table_hash (const void *x
)
4798 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4801 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4804 decl_die_table_eq (const void *x
, const void *y
)
4806 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4809 /* Return the DIE associated with a given declaration. */
4811 static inline dw_die_ref
4812 lookup_decl_die (tree decl
)
4814 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4817 /* Returns a hash value for X (which really is a var_loc_list). */
4820 decl_loc_table_hash (const void *x
)
4822 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4825 /* Return nonzero if decl_id of var_loc_list X is the same as
4829 decl_loc_table_eq (const void *x
, const void *y
)
4831 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4834 /* Return the var_loc list associated with a given declaration. */
4836 static inline var_loc_list
*
4837 lookup_decl_loc (const_tree decl
)
4839 if (!decl_loc_table
)
4841 return (var_loc_list
*)
4842 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4845 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4848 cached_dw_loc_list_table_hash (const void *x
)
4850 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4853 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4857 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4859 return (((const cached_dw_loc_list
*) x
)->decl_id
4860 == DECL_UID ((const_tree
) y
));
4863 /* Equate a DIE to a particular declaration. */
4866 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4868 unsigned int decl_id
= DECL_UID (decl
);
4871 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4873 decl_die
->decl_id
= decl_id
;
4876 /* Return how many bits covers PIECE EXPR_LIST. */
4879 decl_piece_bitsize (rtx piece
)
4881 int ret
= (int) GET_MODE (piece
);
4884 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4885 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4886 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4889 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4892 decl_piece_varloc_ptr (rtx piece
)
4894 if ((int) GET_MODE (piece
))
4895 return &XEXP (piece
, 0);
4897 return &XEXP (XEXP (piece
, 0), 1);
4900 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4901 Next is the chain of following piece nodes. */
4904 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4906 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4907 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4909 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4914 /* Return rtx that should be stored into loc field for
4915 LOC_NOTE and BITPOS/BITSIZE. */
4918 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4919 HOST_WIDE_INT bitsize
)
4923 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4925 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4930 /* This function either modifies location piece list *DEST in
4931 place (if SRC and INNER is NULL), or copies location piece list
4932 *SRC to *DEST while modifying it. Location BITPOS is modified
4933 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4934 not copied and if needed some padding around it is added.
4935 When modifying in place, DEST should point to EXPR_LIST where
4936 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4937 to the start of the whole list and INNER points to the EXPR_LIST
4938 where earlier pieces cover PIECE_BITPOS bits. */
4941 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4942 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4943 HOST_WIDE_INT bitsize
, rtx loc_note
)
4946 bool copy
= inner
!= NULL
;
4950 /* First copy all nodes preceding the current bitpos. */
4951 while (src
!= inner
)
4953 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4954 decl_piece_bitsize (*src
), NULL_RTX
);
4955 dest
= &XEXP (*dest
, 1);
4956 src
= &XEXP (*src
, 1);
4959 /* Add padding if needed. */
4960 if (bitpos
!= piece_bitpos
)
4962 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4963 copy
? NULL_RTX
: *dest
);
4964 dest
= &XEXP (*dest
, 1);
4966 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4969 /* A piece with correct bitpos and bitsize already exist,
4970 just update the location for it and return. */
4971 *decl_piece_varloc_ptr (*dest
) = loc_note
;
4974 /* Add the piece that changed. */
4975 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
4976 dest
= &XEXP (*dest
, 1);
4977 /* Skip over pieces that overlap it. */
4978 diff
= bitpos
- piece_bitpos
+ bitsize
;
4981 while (diff
> 0 && *src
)
4984 diff
-= decl_piece_bitsize (piece
);
4986 src
= &XEXP (piece
, 1);
4989 *src
= XEXP (piece
, 1);
4990 free_EXPR_LIST_node (piece
);
4993 /* Add padding if needed. */
4994 if (diff
< 0 && *src
)
4998 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
4999 dest
= &XEXP (*dest
, 1);
5003 /* Finally copy all nodes following it. */
5006 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5007 decl_piece_bitsize (*src
), NULL_RTX
);
5008 dest
= &XEXP (*dest
, 1);
5009 src
= &XEXP (*src
, 1);
5013 /* Add a variable location node to the linked list for DECL. */
5015 static struct var_loc_node
*
5016 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5018 unsigned int decl_id
;
5021 struct var_loc_node
*loc
= NULL
;
5022 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5024 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
5026 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5028 && (handled_component_p (realdecl
)
5029 || (TREE_CODE (realdecl
) == MEM_REF
5030 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
)))
5032 HOST_WIDE_INT maxsize
;
5035 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5036 if (!DECL_P (innerdecl
)
5037 || DECL_IGNORED_P (innerdecl
)
5038 || TREE_STATIC (innerdecl
)
5040 || bitpos
+ bitsize
> 256
5041 || bitsize
!= maxsize
)
5047 decl_id
= DECL_UID (decl
);
5048 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5051 temp
= ggc_alloc_cleared_var_loc_list ();
5052 temp
->decl_id
= decl_id
;
5056 temp
= (var_loc_list
*) *slot
;
5058 /* For PARM_DECLs try to keep around the original incoming value,
5059 even if that means we'll emit a zero-range .debug_loc entry. */
5061 && temp
->first
== temp
->last
5062 && TREE_CODE (decl
) == PARM_DECL
5063 && GET_CODE (temp
->first
->loc
) == NOTE
5064 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5065 && DECL_INCOMING_RTL (decl
)
5066 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5067 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5068 == GET_CODE (DECL_INCOMING_RTL (decl
))
5069 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5071 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5072 NOTE_VAR_LOCATION_LOC (loc_note
))
5073 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5074 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5076 loc
= ggc_alloc_cleared_var_loc_node ();
5077 temp
->first
->next
= loc
;
5079 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5081 else if (temp
->last
)
5083 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5084 rtx
*piece_loc
= NULL
, last_loc_note
;
5085 int piece_bitpos
= 0;
5089 gcc_assert (last
->next
== NULL
);
5091 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5093 piece_loc
= &last
->loc
;
5096 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5097 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5099 piece_bitpos
+= cur_bitsize
;
5100 piece_loc
= &XEXP (*piece_loc
, 1);
5104 /* TEMP->LAST here is either pointer to the last but one or
5105 last element in the chained list, LAST is pointer to the
5107 if (label
&& strcmp (last
->label
, label
) == 0)
5109 /* For SRA optimized variables if there weren't any real
5110 insns since last note, just modify the last node. */
5111 if (piece_loc
!= NULL
)
5113 adjust_piece_list (piece_loc
, NULL
, NULL
,
5114 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5117 /* If the last note doesn't cover any instructions, remove it. */
5118 if (temp
->last
!= last
)
5120 temp
->last
->next
= NULL
;
5123 gcc_assert (strcmp (last
->label
, label
) != 0);
5127 gcc_assert (temp
->first
== temp
->last
5128 || (temp
->first
->next
== temp
->last
5129 && TREE_CODE (decl
) == PARM_DECL
));
5130 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5131 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5135 if (bitsize
== -1 && NOTE_P (last
->loc
))
5136 last_loc_note
= last
->loc
;
5137 else if (piece_loc
!= NULL
5138 && *piece_loc
!= NULL_RTX
5139 && piece_bitpos
== bitpos
5140 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5141 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5143 last_loc_note
= NULL_RTX
;
5144 /* If the current location is the same as the end of the list,
5145 and either both or neither of the locations is uninitialized,
5146 we have nothing to do. */
5147 if (last_loc_note
== NULL_RTX
5148 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5149 NOTE_VAR_LOCATION_LOC (loc_note
)))
5150 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5151 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5152 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5153 == VAR_INIT_STATUS_UNINITIALIZED
)
5154 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5155 == VAR_INIT_STATUS_UNINITIALIZED
))))
5157 /* Add LOC to the end of list and update LAST. If the last
5158 element of the list has been removed above, reuse its
5159 memory for the new node, otherwise allocate a new one. */
5163 memset (loc
, '\0', sizeof (*loc
));
5166 loc
= ggc_alloc_cleared_var_loc_node ();
5167 if (bitsize
== -1 || piece_loc
== NULL
)
5168 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5170 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5171 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5173 /* Ensure TEMP->LAST will point either to the new last but one
5174 element of the chain, or to the last element in it. */
5175 if (last
!= temp
->last
)
5183 loc
= ggc_alloc_cleared_var_loc_node ();
5186 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5191 /* Keep track of the number of spaces used to indent the
5192 output of the debugging routines that print the structure of
5193 the DIE internal representation. */
5194 static int print_indent
;
5196 /* Indent the line the number of spaces given by print_indent. */
5199 print_spaces (FILE *outfile
)
5201 fprintf (outfile
, "%*s", print_indent
, "");
5204 /* Print a type signature in hex. */
5207 print_signature (FILE *outfile
, char *sig
)
5211 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5212 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5215 /* Print the information associated with a given DIE, and its children.
5216 This routine is a debugging aid only. */
5219 print_die (dw_die_ref die
, FILE *outfile
)
5225 print_spaces (outfile
);
5226 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5227 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5229 print_spaces (outfile
);
5230 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5231 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5232 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5234 if (die
->comdat_type_p
)
5236 print_spaces (outfile
);
5237 fprintf (outfile
, " signature: ");
5238 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5239 fprintf (outfile
, "\n");
5242 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5244 print_spaces (outfile
);
5245 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5247 switch (AT_class (a
))
5249 case dw_val_class_addr
:
5250 fprintf (outfile
, "address");
5252 case dw_val_class_offset
:
5253 fprintf (outfile
, "offset");
5255 case dw_val_class_loc
:
5256 fprintf (outfile
, "location descriptor");
5258 case dw_val_class_loc_list
:
5259 fprintf (outfile
, "location list -> label:%s",
5260 AT_loc_list (a
)->ll_symbol
);
5262 case dw_val_class_range_list
:
5263 fprintf (outfile
, "range list");
5265 case dw_val_class_const
:
5266 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5268 case dw_val_class_unsigned_const
:
5269 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5271 case dw_val_class_const_double
:
5272 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5273 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5274 a
->dw_attr_val
.v
.val_double
.high
,
5275 a
->dw_attr_val
.v
.val_double
.low
);
5277 case dw_val_class_vec
:
5278 fprintf (outfile
, "floating-point or vector constant");
5280 case dw_val_class_flag
:
5281 fprintf (outfile
, "%u", AT_flag (a
));
5283 case dw_val_class_die_ref
:
5284 if (AT_ref (a
) != NULL
)
5286 if (AT_ref (a
)->comdat_type_p
)
5288 fprintf (outfile
, "die -> signature: ");
5289 print_signature (outfile
,
5290 AT_ref (a
)->die_id
.die_type_node
->signature
);
5292 else if (AT_ref (a
)->die_id
.die_symbol
)
5293 fprintf (outfile
, "die -> label: %s",
5294 AT_ref (a
)->die_id
.die_symbol
);
5296 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5297 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5300 fprintf (outfile
, "die -> <null>");
5302 case dw_val_class_vms_delta
:
5303 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5304 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5306 case dw_val_class_lbl_id
:
5307 case dw_val_class_lineptr
:
5308 case dw_val_class_macptr
:
5309 case dw_val_class_high_pc
:
5310 fprintf (outfile
, "label: %s", AT_lbl (a
));
5312 case dw_val_class_str
:
5313 if (AT_string (a
) != NULL
)
5314 fprintf (outfile
, "\"%s\"", AT_string (a
));
5316 fprintf (outfile
, "<null>");
5318 case dw_val_class_file
:
5319 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5320 AT_file (a
)->emitted_number
);
5322 case dw_val_class_data8
:
5326 for (i
= 0; i
< 8; i
++)
5327 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5334 fprintf (outfile
, "\n");
5337 if (die
->die_child
!= NULL
)
5340 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5343 if (print_indent
== 0)
5344 fprintf (outfile
, "\n");
5347 /* Print the information collected for a given DIE. */
5350 debug_dwarf_die (dw_die_ref die
)
5352 print_die (die
, stderr
);
5355 /* Print all DWARF information collected for the compilation unit.
5356 This routine is a debugging aid only. */
5362 print_die (comp_unit_die (), stderr
);
5365 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5366 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5367 DIE that marks the start of the DIEs for this include file. */
5370 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5372 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5373 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5375 new_unit
->die_sib
= old_unit
;
5379 /* Close an include-file CU and reopen the enclosing one. */
5382 pop_compile_unit (dw_die_ref old_unit
)
5384 dw_die_ref new_unit
= old_unit
->die_sib
;
5386 old_unit
->die_sib
= NULL
;
5390 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5391 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5393 /* Calculate the checksum of a location expression. */
5396 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5400 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5402 CHECKSUM (loc
->dw_loc_oprnd1
);
5403 CHECKSUM (loc
->dw_loc_oprnd2
);
5406 /* Calculate the checksum of an attribute. */
5409 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5411 dw_loc_descr_ref loc
;
5414 CHECKSUM (at
->dw_attr
);
5416 /* We don't care that this was compiled with a different compiler
5417 snapshot; if the output is the same, that's what matters. */
5418 if (at
->dw_attr
== DW_AT_producer
)
5421 switch (AT_class (at
))
5423 case dw_val_class_const
:
5424 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5426 case dw_val_class_unsigned_const
:
5427 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5429 case dw_val_class_const_double
:
5430 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5432 case dw_val_class_vec
:
5433 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5435 case dw_val_class_flag
:
5436 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5438 case dw_val_class_str
:
5439 CHECKSUM_STRING (AT_string (at
));
5442 case dw_val_class_addr
:
5444 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5445 CHECKSUM_STRING (XSTR (r
, 0));
5448 case dw_val_class_offset
:
5449 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5452 case dw_val_class_loc
:
5453 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5454 loc_checksum (loc
, ctx
);
5457 case dw_val_class_die_ref
:
5458 die_checksum (AT_ref (at
), ctx
, mark
);
5461 case dw_val_class_fde_ref
:
5462 case dw_val_class_vms_delta
:
5463 case dw_val_class_lbl_id
:
5464 case dw_val_class_lineptr
:
5465 case dw_val_class_macptr
:
5466 case dw_val_class_high_pc
:
5469 case dw_val_class_file
:
5470 CHECKSUM_STRING (AT_file (at
)->filename
);
5473 case dw_val_class_data8
:
5474 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5482 /* Calculate the checksum of a DIE. */
5485 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5491 /* To avoid infinite recursion. */
5494 CHECKSUM (die
->die_mark
);
5497 die
->die_mark
= ++(*mark
);
5499 CHECKSUM (die
->die_tag
);
5501 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5502 attr_checksum (a
, ctx
, mark
);
5504 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5508 #undef CHECKSUM_STRING
5510 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5511 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5512 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5513 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5514 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5515 #define CHECKSUM_ATTR(FOO) \
5516 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5518 /* Calculate the checksum of a number in signed LEB128 format. */
5521 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5528 byte
= (value
& 0x7f);
5530 more
= !((value
== 0 && (byte
& 0x40) == 0)
5531 || (value
== -1 && (byte
& 0x40) != 0));
5540 /* Calculate the checksum of a number in unsigned LEB128 format. */
5543 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5547 unsigned char byte
= (value
& 0x7f);
5550 /* More bytes to follow. */
5558 /* Checksum the context of the DIE. This adds the names of any
5559 surrounding namespaces or structures to the checksum. */
5562 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5566 int tag
= die
->die_tag
;
5568 if (tag
!= DW_TAG_namespace
5569 && tag
!= DW_TAG_structure_type
5570 && tag
!= DW_TAG_class_type
)
5573 name
= get_AT_string (die
, DW_AT_name
);
5575 spec
= get_AT_ref (die
, DW_AT_specification
);
5579 if (die
->die_parent
!= NULL
)
5580 checksum_die_context (die
->die_parent
, ctx
);
5582 CHECKSUM_ULEB128 ('C');
5583 CHECKSUM_ULEB128 (tag
);
5585 CHECKSUM_STRING (name
);
5588 /* Calculate the checksum of a location expression. */
5591 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5593 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5594 were emitted as a DW_FORM_sdata instead of a location expression. */
5595 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5597 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5598 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5602 /* Otherwise, just checksum the raw location expression. */
5605 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5606 CHECKSUM (loc
->dw_loc_oprnd1
);
5607 CHECKSUM (loc
->dw_loc_oprnd2
);
5608 loc
= loc
->dw_loc_next
;
5612 /* Calculate the checksum of an attribute. */
5615 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5616 struct md5_ctx
*ctx
, int *mark
)
5618 dw_loc_descr_ref loc
;
5621 if (AT_class (at
) == dw_val_class_die_ref
)
5623 dw_die_ref target_die
= AT_ref (at
);
5625 /* For pointer and reference types, we checksum only the (qualified)
5626 name of the target type (if there is a name). For friend entries,
5627 we checksum only the (qualified) name of the target type or function.
5628 This allows the checksum to remain the same whether the target type
5629 is complete or not. */
5630 if ((at
->dw_attr
== DW_AT_type
5631 && (tag
== DW_TAG_pointer_type
5632 || tag
== DW_TAG_reference_type
5633 || tag
== DW_TAG_rvalue_reference_type
5634 || tag
== DW_TAG_ptr_to_member_type
))
5635 || (at
->dw_attr
== DW_AT_friend
5636 && tag
== DW_TAG_friend
))
5638 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5640 if (name_attr
!= NULL
)
5642 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5646 CHECKSUM_ULEB128 ('N');
5647 CHECKSUM_ULEB128 (at
->dw_attr
);
5648 if (decl
->die_parent
!= NULL
)
5649 checksum_die_context (decl
->die_parent
, ctx
);
5650 CHECKSUM_ULEB128 ('E');
5651 CHECKSUM_STRING (AT_string (name_attr
));
5656 /* For all other references to another DIE, we check to see if the
5657 target DIE has already been visited. If it has, we emit a
5658 backward reference; if not, we descend recursively. */
5659 if (target_die
->die_mark
> 0)
5661 CHECKSUM_ULEB128 ('R');
5662 CHECKSUM_ULEB128 (at
->dw_attr
);
5663 CHECKSUM_ULEB128 (target_die
->die_mark
);
5667 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5671 target_die
->die_mark
= ++(*mark
);
5672 CHECKSUM_ULEB128 ('T');
5673 CHECKSUM_ULEB128 (at
->dw_attr
);
5674 if (decl
->die_parent
!= NULL
)
5675 checksum_die_context (decl
->die_parent
, ctx
);
5676 die_checksum_ordered (target_die
, ctx
, mark
);
5681 CHECKSUM_ULEB128 ('A');
5682 CHECKSUM_ULEB128 (at
->dw_attr
);
5684 switch (AT_class (at
))
5686 case dw_val_class_const
:
5687 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5688 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5691 case dw_val_class_unsigned_const
:
5692 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5693 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5696 case dw_val_class_const_double
:
5697 CHECKSUM_ULEB128 (DW_FORM_block
);
5698 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5699 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5702 case dw_val_class_vec
:
5703 CHECKSUM_ULEB128 (DW_FORM_block
);
5704 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5705 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5708 case dw_val_class_flag
:
5709 CHECKSUM_ULEB128 (DW_FORM_flag
);
5710 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5713 case dw_val_class_str
:
5714 CHECKSUM_ULEB128 (DW_FORM_string
);
5715 CHECKSUM_STRING (AT_string (at
));
5718 case dw_val_class_addr
:
5720 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5721 CHECKSUM_ULEB128 (DW_FORM_string
);
5722 CHECKSUM_STRING (XSTR (r
, 0));
5725 case dw_val_class_offset
:
5726 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5727 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5730 case dw_val_class_loc
:
5731 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5732 loc_checksum_ordered (loc
, ctx
);
5735 case dw_val_class_fde_ref
:
5736 case dw_val_class_lbl_id
:
5737 case dw_val_class_lineptr
:
5738 case dw_val_class_macptr
:
5739 case dw_val_class_high_pc
:
5742 case dw_val_class_file
:
5743 CHECKSUM_ULEB128 (DW_FORM_string
);
5744 CHECKSUM_STRING (AT_file (at
)->filename
);
5747 case dw_val_class_data8
:
5748 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5756 struct checksum_attributes
5758 dw_attr_ref at_name
;
5759 dw_attr_ref at_type
;
5760 dw_attr_ref at_friend
;
5761 dw_attr_ref at_accessibility
;
5762 dw_attr_ref at_address_class
;
5763 dw_attr_ref at_allocated
;
5764 dw_attr_ref at_artificial
;
5765 dw_attr_ref at_associated
;
5766 dw_attr_ref at_binary_scale
;
5767 dw_attr_ref at_bit_offset
;
5768 dw_attr_ref at_bit_size
;
5769 dw_attr_ref at_bit_stride
;
5770 dw_attr_ref at_byte_size
;
5771 dw_attr_ref at_byte_stride
;
5772 dw_attr_ref at_const_value
;
5773 dw_attr_ref at_containing_type
;
5774 dw_attr_ref at_count
;
5775 dw_attr_ref at_data_location
;
5776 dw_attr_ref at_data_member_location
;
5777 dw_attr_ref at_decimal_scale
;
5778 dw_attr_ref at_decimal_sign
;
5779 dw_attr_ref at_default_value
;
5780 dw_attr_ref at_digit_count
;
5781 dw_attr_ref at_discr
;
5782 dw_attr_ref at_discr_list
;
5783 dw_attr_ref at_discr_value
;
5784 dw_attr_ref at_encoding
;
5785 dw_attr_ref at_endianity
;
5786 dw_attr_ref at_explicit
;
5787 dw_attr_ref at_is_optional
;
5788 dw_attr_ref at_location
;
5789 dw_attr_ref at_lower_bound
;
5790 dw_attr_ref at_mutable
;
5791 dw_attr_ref at_ordering
;
5792 dw_attr_ref at_picture_string
;
5793 dw_attr_ref at_prototyped
;
5794 dw_attr_ref at_small
;
5795 dw_attr_ref at_segment
;
5796 dw_attr_ref at_string_length
;
5797 dw_attr_ref at_threads_scaled
;
5798 dw_attr_ref at_upper_bound
;
5799 dw_attr_ref at_use_location
;
5800 dw_attr_ref at_use_UTF8
;
5801 dw_attr_ref at_variable_parameter
;
5802 dw_attr_ref at_virtuality
;
5803 dw_attr_ref at_visibility
;
5804 dw_attr_ref at_vtable_elem_location
;
5807 /* Collect the attributes that we will want to use for the checksum. */
5810 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5815 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5826 attrs
->at_friend
= a
;
5828 case DW_AT_accessibility
:
5829 attrs
->at_accessibility
= a
;
5831 case DW_AT_address_class
:
5832 attrs
->at_address_class
= a
;
5834 case DW_AT_allocated
:
5835 attrs
->at_allocated
= a
;
5837 case DW_AT_artificial
:
5838 attrs
->at_artificial
= a
;
5840 case DW_AT_associated
:
5841 attrs
->at_associated
= a
;
5843 case DW_AT_binary_scale
:
5844 attrs
->at_binary_scale
= a
;
5846 case DW_AT_bit_offset
:
5847 attrs
->at_bit_offset
= a
;
5849 case DW_AT_bit_size
:
5850 attrs
->at_bit_size
= a
;
5852 case DW_AT_bit_stride
:
5853 attrs
->at_bit_stride
= a
;
5855 case DW_AT_byte_size
:
5856 attrs
->at_byte_size
= a
;
5858 case DW_AT_byte_stride
:
5859 attrs
->at_byte_stride
= a
;
5861 case DW_AT_const_value
:
5862 attrs
->at_const_value
= a
;
5864 case DW_AT_containing_type
:
5865 attrs
->at_containing_type
= a
;
5868 attrs
->at_count
= a
;
5870 case DW_AT_data_location
:
5871 attrs
->at_data_location
= a
;
5873 case DW_AT_data_member_location
:
5874 attrs
->at_data_member_location
= a
;
5876 case DW_AT_decimal_scale
:
5877 attrs
->at_decimal_scale
= a
;
5879 case DW_AT_decimal_sign
:
5880 attrs
->at_decimal_sign
= a
;
5882 case DW_AT_default_value
:
5883 attrs
->at_default_value
= a
;
5885 case DW_AT_digit_count
:
5886 attrs
->at_digit_count
= a
;
5889 attrs
->at_discr
= a
;
5891 case DW_AT_discr_list
:
5892 attrs
->at_discr_list
= a
;
5894 case DW_AT_discr_value
:
5895 attrs
->at_discr_value
= a
;
5897 case DW_AT_encoding
:
5898 attrs
->at_encoding
= a
;
5900 case DW_AT_endianity
:
5901 attrs
->at_endianity
= a
;
5903 case DW_AT_explicit
:
5904 attrs
->at_explicit
= a
;
5906 case DW_AT_is_optional
:
5907 attrs
->at_is_optional
= a
;
5909 case DW_AT_location
:
5910 attrs
->at_location
= a
;
5912 case DW_AT_lower_bound
:
5913 attrs
->at_lower_bound
= a
;
5916 attrs
->at_mutable
= a
;
5918 case DW_AT_ordering
:
5919 attrs
->at_ordering
= a
;
5921 case DW_AT_picture_string
:
5922 attrs
->at_picture_string
= a
;
5924 case DW_AT_prototyped
:
5925 attrs
->at_prototyped
= a
;
5928 attrs
->at_small
= a
;
5931 attrs
->at_segment
= a
;
5933 case DW_AT_string_length
:
5934 attrs
->at_string_length
= a
;
5936 case DW_AT_threads_scaled
:
5937 attrs
->at_threads_scaled
= a
;
5939 case DW_AT_upper_bound
:
5940 attrs
->at_upper_bound
= a
;
5942 case DW_AT_use_location
:
5943 attrs
->at_use_location
= a
;
5945 case DW_AT_use_UTF8
:
5946 attrs
->at_use_UTF8
= a
;
5948 case DW_AT_variable_parameter
:
5949 attrs
->at_variable_parameter
= a
;
5951 case DW_AT_virtuality
:
5952 attrs
->at_virtuality
= a
;
5954 case DW_AT_visibility
:
5955 attrs
->at_visibility
= a
;
5957 case DW_AT_vtable_elem_location
:
5958 attrs
->at_vtable_elem_location
= a
;
5966 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
5969 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5973 struct checksum_attributes attrs
;
5975 CHECKSUM_ULEB128 ('D');
5976 CHECKSUM_ULEB128 (die
->die_tag
);
5978 memset (&attrs
, 0, sizeof (attrs
));
5980 decl
= get_AT_ref (die
, DW_AT_specification
);
5982 collect_checksum_attributes (&attrs
, decl
);
5983 collect_checksum_attributes (&attrs
, die
);
5985 CHECKSUM_ATTR (attrs
.at_name
);
5986 CHECKSUM_ATTR (attrs
.at_accessibility
);
5987 CHECKSUM_ATTR (attrs
.at_address_class
);
5988 CHECKSUM_ATTR (attrs
.at_allocated
);
5989 CHECKSUM_ATTR (attrs
.at_artificial
);
5990 CHECKSUM_ATTR (attrs
.at_associated
);
5991 CHECKSUM_ATTR (attrs
.at_binary_scale
);
5992 CHECKSUM_ATTR (attrs
.at_bit_offset
);
5993 CHECKSUM_ATTR (attrs
.at_bit_size
);
5994 CHECKSUM_ATTR (attrs
.at_bit_stride
);
5995 CHECKSUM_ATTR (attrs
.at_byte_size
);
5996 CHECKSUM_ATTR (attrs
.at_byte_stride
);
5997 CHECKSUM_ATTR (attrs
.at_const_value
);
5998 CHECKSUM_ATTR (attrs
.at_containing_type
);
5999 CHECKSUM_ATTR (attrs
.at_count
);
6000 CHECKSUM_ATTR (attrs
.at_data_location
);
6001 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6002 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6003 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6004 CHECKSUM_ATTR (attrs
.at_default_value
);
6005 CHECKSUM_ATTR (attrs
.at_digit_count
);
6006 CHECKSUM_ATTR (attrs
.at_discr
);
6007 CHECKSUM_ATTR (attrs
.at_discr_list
);
6008 CHECKSUM_ATTR (attrs
.at_discr_value
);
6009 CHECKSUM_ATTR (attrs
.at_encoding
);
6010 CHECKSUM_ATTR (attrs
.at_endianity
);
6011 CHECKSUM_ATTR (attrs
.at_explicit
);
6012 CHECKSUM_ATTR (attrs
.at_is_optional
);
6013 CHECKSUM_ATTR (attrs
.at_location
);
6014 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6015 CHECKSUM_ATTR (attrs
.at_mutable
);
6016 CHECKSUM_ATTR (attrs
.at_ordering
);
6017 CHECKSUM_ATTR (attrs
.at_picture_string
);
6018 CHECKSUM_ATTR (attrs
.at_prototyped
);
6019 CHECKSUM_ATTR (attrs
.at_small
);
6020 CHECKSUM_ATTR (attrs
.at_segment
);
6021 CHECKSUM_ATTR (attrs
.at_string_length
);
6022 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6023 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6024 CHECKSUM_ATTR (attrs
.at_use_location
);
6025 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6026 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6027 CHECKSUM_ATTR (attrs
.at_virtuality
);
6028 CHECKSUM_ATTR (attrs
.at_visibility
);
6029 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6030 CHECKSUM_ATTR (attrs
.at_type
);
6031 CHECKSUM_ATTR (attrs
.at_friend
);
6033 /* Checksum the child DIEs, except for nested types and member functions. */
6036 dw_attr_ref name_attr
;
6039 name_attr
= get_AT (c
, DW_AT_name
);
6040 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6041 && name_attr
!= NULL
)
6043 CHECKSUM_ULEB128 ('S');
6044 CHECKSUM_ULEB128 (c
->die_tag
);
6045 CHECKSUM_STRING (AT_string (name_attr
));
6049 /* Mark this DIE so it gets processed when unmarking. */
6050 if (c
->die_mark
== 0)
6052 die_checksum_ordered (c
, ctx
, mark
);
6054 } while (c
!= die
->die_child
);
6056 CHECKSUM_ULEB128 (0);
6060 #undef CHECKSUM_STRING
6061 #undef CHECKSUM_ATTR
6062 #undef CHECKSUM_LEB128
6063 #undef CHECKSUM_ULEB128
6065 /* Generate the type signature for DIE. This is computed by generating an
6066 MD5 checksum over the DIE's tag, its relevant attributes, and its
6067 children. Attributes that are references to other DIEs are processed
6068 by recursion, using the MARK field to prevent infinite recursion.
6069 If the DIE is nested inside a namespace or another type, we also
6070 need to include that context in the signature. The lower 64 bits
6071 of the resulting MD5 checksum comprise the signature. */
6074 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6078 unsigned char checksum
[16];
6083 name
= get_AT_string (die
, DW_AT_name
);
6084 decl
= get_AT_ref (die
, DW_AT_specification
);
6085 parent
= get_die_parent (die
);
6087 /* First, compute a signature for just the type name (and its surrounding
6088 context, if any. This is stored in the type unit DIE for link-time
6089 ODR (one-definition rule) checking. */
6091 if (is_cxx() && name
!= NULL
)
6093 md5_init_ctx (&ctx
);
6095 /* Checksum the names of surrounding namespaces and structures. */
6097 checksum_die_context (parent
, &ctx
);
6099 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6100 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6101 md5_finish_ctx (&ctx
, checksum
);
6103 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6106 /* Next, compute the complete type signature. */
6108 md5_init_ctx (&ctx
);
6110 die
->die_mark
= mark
;
6112 /* Checksum the names of surrounding namespaces and structures. */
6114 checksum_die_context (parent
, &ctx
);
6116 /* Checksum the DIE and its children. */
6117 die_checksum_ordered (die
, &ctx
, &mark
);
6118 unmark_all_dies (die
);
6119 md5_finish_ctx (&ctx
, checksum
);
6121 /* Store the signature in the type node and link the type DIE and the
6122 type node together. */
6123 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6124 DWARF_TYPE_SIGNATURE_SIZE
);
6125 die
->comdat_type_p
= true;
6126 die
->die_id
.die_type_node
= type_node
;
6127 type_node
->type_die
= die
;
6129 /* If the DIE is a specification, link its declaration to the type node
6133 decl
->comdat_type_p
= true;
6134 decl
->die_id
.die_type_node
= type_node
;
6138 /* Do the location expressions look same? */
6140 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6142 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6143 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6144 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6147 /* Do the values look the same? */
6149 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6151 dw_loc_descr_ref loc1
, loc2
;
6154 if (v1
->val_class
!= v2
->val_class
)
6157 switch (v1
->val_class
)
6159 case dw_val_class_const
:
6160 return v1
->v
.val_int
== v2
->v
.val_int
;
6161 case dw_val_class_unsigned_const
:
6162 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6163 case dw_val_class_const_double
:
6164 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6165 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6166 case dw_val_class_vec
:
6167 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6168 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6170 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6171 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6174 case dw_val_class_flag
:
6175 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6176 case dw_val_class_str
:
6177 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6179 case dw_val_class_addr
:
6180 r1
= v1
->v
.val_addr
;
6181 r2
= v2
->v
.val_addr
;
6182 if (GET_CODE (r1
) != GET_CODE (r2
))
6184 return !rtx_equal_p (r1
, r2
);
6186 case dw_val_class_offset
:
6187 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6189 case dw_val_class_loc
:
6190 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6192 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6193 if (!same_loc_p (loc1
, loc2
, mark
))
6195 return !loc1
&& !loc2
;
6197 case dw_val_class_die_ref
:
6198 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6200 case dw_val_class_fde_ref
:
6201 case dw_val_class_vms_delta
:
6202 case dw_val_class_lbl_id
:
6203 case dw_val_class_lineptr
:
6204 case dw_val_class_macptr
:
6205 case dw_val_class_high_pc
:
6208 case dw_val_class_file
:
6209 return v1
->v
.val_file
== v2
->v
.val_file
;
6211 case dw_val_class_data8
:
6212 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6219 /* Do the attributes look the same? */
6222 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6224 if (at1
->dw_attr
!= at2
->dw_attr
)
6227 /* We don't care that this was compiled with a different compiler
6228 snapshot; if the output is the same, that's what matters. */
6229 if (at1
->dw_attr
== DW_AT_producer
)
6232 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6235 /* Do the dies look the same? */
6238 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6244 /* To avoid infinite recursion. */
6246 return die1
->die_mark
== die2
->die_mark
;
6247 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6249 if (die1
->die_tag
!= die2
->die_tag
)
6252 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6255 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6256 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6259 c1
= die1
->die_child
;
6260 c2
= die2
->die_child
;
6269 if (!same_die_p (c1
, c2
, mark
))
6273 if (c1
== die1
->die_child
)
6275 if (c2
== die2
->die_child
)
6285 /* Do the dies look the same? Wrapper around same_die_p. */
6288 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6291 int ret
= same_die_p (die1
, die2
, &mark
);
6293 unmark_all_dies (die1
);
6294 unmark_all_dies (die2
);
6299 /* The prefix to attach to symbols on DIEs in the current comdat debug
6301 static const char *comdat_symbol_id
;
6303 /* The index of the current symbol within the current comdat CU. */
6304 static unsigned int comdat_symbol_number
;
6306 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6307 children, and set comdat_symbol_id accordingly. */
6310 compute_section_prefix (dw_die_ref unit_die
)
6312 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6313 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6314 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6317 unsigned char checksum
[16];
6320 /* Compute the checksum of the DIE, then append part of it as hex digits to
6321 the name filename of the unit. */
6323 md5_init_ctx (&ctx
);
6325 die_checksum (unit_die
, &ctx
, &mark
);
6326 unmark_all_dies (unit_die
);
6327 md5_finish_ctx (&ctx
, checksum
);
6329 sprintf (name
, "%s.", base
);
6330 clean_symbol_name (name
);
6332 p
= name
+ strlen (name
);
6333 for (i
= 0; i
< 4; i
++)
6335 sprintf (p
, "%.2x", checksum
[i
]);
6339 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6340 comdat_symbol_number
= 0;
6343 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6346 is_type_die (dw_die_ref die
)
6348 switch (die
->die_tag
)
6350 case DW_TAG_array_type
:
6351 case DW_TAG_class_type
:
6352 case DW_TAG_interface_type
:
6353 case DW_TAG_enumeration_type
:
6354 case DW_TAG_pointer_type
:
6355 case DW_TAG_reference_type
:
6356 case DW_TAG_rvalue_reference_type
:
6357 case DW_TAG_string_type
:
6358 case DW_TAG_structure_type
:
6359 case DW_TAG_subroutine_type
:
6360 case DW_TAG_union_type
:
6361 case DW_TAG_ptr_to_member_type
:
6362 case DW_TAG_set_type
:
6363 case DW_TAG_subrange_type
:
6364 case DW_TAG_base_type
:
6365 case DW_TAG_const_type
:
6366 case DW_TAG_file_type
:
6367 case DW_TAG_packed_type
:
6368 case DW_TAG_volatile_type
:
6369 case DW_TAG_typedef
:
6376 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6377 Basically, we want to choose the bits that are likely to be shared between
6378 compilations (types) and leave out the bits that are specific to individual
6379 compilations (functions). */
6382 is_comdat_die (dw_die_ref c
)
6384 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6385 we do for stabs. The advantage is a greater likelihood of sharing between
6386 objects that don't include headers in the same order (and therefore would
6387 put the base types in a different comdat). jason 8/28/00 */
6389 if (c
->die_tag
== DW_TAG_base_type
)
6392 if (c
->die_tag
== DW_TAG_pointer_type
6393 || c
->die_tag
== DW_TAG_reference_type
6394 || c
->die_tag
== DW_TAG_rvalue_reference_type
6395 || c
->die_tag
== DW_TAG_const_type
6396 || c
->die_tag
== DW_TAG_volatile_type
)
6398 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6400 return t
? is_comdat_die (t
) : 0;
6403 return is_type_die (c
);
6406 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6407 compilation unit. */
6410 is_symbol_die (dw_die_ref c
)
6412 return (is_type_die (c
)
6413 || is_declaration_die (c
)
6414 || c
->die_tag
== DW_TAG_namespace
6415 || c
->die_tag
== DW_TAG_module
);
6418 /* Returns true iff C is a compile-unit DIE. */
6421 is_cu_die (dw_die_ref c
)
6423 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6426 /* Returns true iff C is a unit DIE of some sort. */
6429 is_unit_die (dw_die_ref c
)
6431 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6432 || c
->die_tag
== DW_TAG_partial_unit
6433 || c
->die_tag
== DW_TAG_type_unit
);
6436 /* Returns true iff C is a namespace DIE. */
6439 is_namespace_die (dw_die_ref c
)
6441 return c
&& c
->die_tag
== DW_TAG_namespace
;
6444 /* Returns true iff C is a class or structure DIE. */
6447 is_class_die (dw_die_ref c
)
6449 return c
&& (c
->die_tag
== DW_TAG_class_type
6450 || c
->die_tag
== DW_TAG_structure_type
);
6454 gen_internal_sym (const char *prefix
)
6458 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6459 return xstrdup (buf
);
6462 /* Assign symbols to all worthy DIEs under DIE. */
6465 assign_symbol_names (dw_die_ref die
)
6469 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6471 if (comdat_symbol_id
)
6473 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6475 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6476 comdat_symbol_id
, comdat_symbol_number
++);
6477 die
->die_id
.die_symbol
= xstrdup (p
);
6480 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6483 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6486 struct cu_hash_table_entry
6489 unsigned min_comdat_num
, max_comdat_num
;
6490 struct cu_hash_table_entry
*next
;
6493 /* Routines to manipulate hash table of CUs. */
6495 htab_cu_hash (const void *of
)
6497 const struct cu_hash_table_entry
*const entry
=
6498 (const struct cu_hash_table_entry
*) of
;
6500 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6504 htab_cu_eq (const void *of1
, const void *of2
)
6506 const struct cu_hash_table_entry
*const entry1
=
6507 (const struct cu_hash_table_entry
*) of1
;
6508 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6510 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6514 htab_cu_del (void *what
)
6516 struct cu_hash_table_entry
*next
,
6517 *entry
= (struct cu_hash_table_entry
*) what
;
6527 /* Check whether we have already seen this CU and set up SYM_NUM
6530 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6532 struct cu_hash_table_entry dummy
;
6533 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6535 dummy
.max_comdat_num
= 0;
6537 slot
= (struct cu_hash_table_entry
**)
6538 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6542 for (; entry
; last
= entry
, entry
= entry
->next
)
6544 if (same_die_p_wrap (cu
, entry
->cu
))
6550 *sym_num
= entry
->min_comdat_num
;
6554 entry
= XCNEW (struct cu_hash_table_entry
);
6556 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6557 entry
->next
= *slot
;
6563 /* Record SYM_NUM to record of CU in HTABLE. */
6565 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6567 struct cu_hash_table_entry
**slot
, *entry
;
6569 slot
= (struct cu_hash_table_entry
**)
6570 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6574 entry
->max_comdat_num
= sym_num
;
6577 /* Traverse the DIE (which is always comp_unit_die), and set up
6578 additional compilation units for each of the include files we see
6579 bracketed by BINCL/EINCL. */
6582 break_out_includes (dw_die_ref die
)
6585 dw_die_ref unit
= NULL
;
6586 limbo_die_node
*node
, **pnode
;
6587 htab_t cu_hash_table
;
6591 dw_die_ref prev
= c
;
6593 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6594 || (unit
&& is_comdat_die (c
)))
6596 dw_die_ref next
= c
->die_sib
;
6598 /* This DIE is for a secondary CU; remove it from the main one. */
6599 remove_child_with_prev (c
, prev
);
6601 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6602 unit
= push_new_compile_unit (unit
, c
);
6603 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6604 unit
= pop_compile_unit (unit
);
6606 add_child_die (unit
, c
);
6608 if (c
== die
->die_child
)
6611 } while (c
!= die
->die_child
);
6614 /* We can only use this in debugging, since the frontend doesn't check
6615 to make sure that we leave every include file we enter. */
6619 assign_symbol_names (die
);
6620 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6621 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6627 compute_section_prefix (node
->die
);
6628 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6629 &comdat_symbol_number
);
6630 assign_symbol_names (node
->die
);
6632 *pnode
= node
->next
;
6635 pnode
= &node
->next
;
6636 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6637 comdat_symbol_number
);
6640 htab_delete (cu_hash_table
);
6643 /* Return non-zero if this DIE is a declaration. */
6646 is_declaration_die (dw_die_ref die
)
6651 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6652 if (a
->dw_attr
== DW_AT_declaration
)
6658 /* Return non-zero if this DIE is nested inside a subprogram. */
6661 is_nested_in_subprogram (dw_die_ref die
)
6663 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6667 return local_scope_p (decl
);
6670 /* Return non-zero if this DIE contains a defining declaration of a
6674 contains_subprogram_definition (dw_die_ref die
)
6678 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6680 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6684 /* Return non-zero if this is a type DIE that should be moved to a
6685 COMDAT .debug_types section. */
6688 should_move_die_to_comdat (dw_die_ref die
)
6690 switch (die
->die_tag
)
6692 case DW_TAG_class_type
:
6693 case DW_TAG_structure_type
:
6694 case DW_TAG_enumeration_type
:
6695 case DW_TAG_union_type
:
6696 /* Don't move declarations, inlined instances, or types nested in a
6698 if (is_declaration_die (die
)
6699 || get_AT (die
, DW_AT_abstract_origin
)
6700 || is_nested_in_subprogram (die
))
6702 /* A type definition should never contain a subprogram definition. */
6703 gcc_assert (!contains_subprogram_definition (die
));
6705 case DW_TAG_array_type
:
6706 case DW_TAG_interface_type
:
6707 case DW_TAG_pointer_type
:
6708 case DW_TAG_reference_type
:
6709 case DW_TAG_rvalue_reference_type
:
6710 case DW_TAG_string_type
:
6711 case DW_TAG_subroutine_type
:
6712 case DW_TAG_ptr_to_member_type
:
6713 case DW_TAG_set_type
:
6714 case DW_TAG_subrange_type
:
6715 case DW_TAG_base_type
:
6716 case DW_TAG_const_type
:
6717 case DW_TAG_file_type
:
6718 case DW_TAG_packed_type
:
6719 case DW_TAG_volatile_type
:
6720 case DW_TAG_typedef
:
6726 /* Make a clone of DIE. */
6729 clone_die (dw_die_ref die
)
6735 clone
= ggc_alloc_cleared_die_node ();
6736 clone
->die_tag
= die
->die_tag
;
6738 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6739 add_dwarf_attr (clone
, a
);
6744 /* Make a clone of the tree rooted at DIE. */
6747 clone_tree (dw_die_ref die
)
6750 dw_die_ref clone
= clone_die (die
);
6752 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6757 /* Make a clone of DIE as a declaration. */
6760 clone_as_declaration (dw_die_ref die
)
6767 /* If the DIE is already a declaration, just clone it. */
6768 if (is_declaration_die (die
))
6769 return clone_die (die
);
6771 /* If the DIE is a specification, just clone its declaration DIE. */
6772 decl
= get_AT_ref (die
, DW_AT_specification
);
6775 clone
= clone_die (decl
);
6776 if (die
->comdat_type_p
)
6777 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6781 clone
= ggc_alloc_cleared_die_node ();
6782 clone
->die_tag
= die
->die_tag
;
6784 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6786 /* We don't want to copy over all attributes.
6787 For example we don't want DW_AT_byte_size because otherwise we will no
6788 longer have a declaration and GDB will treat it as a definition. */
6792 case DW_AT_artificial
:
6793 case DW_AT_containing_type
:
6794 case DW_AT_external
:
6797 case DW_AT_virtuality
:
6798 case DW_AT_linkage_name
:
6799 case DW_AT_MIPS_linkage_name
:
6800 add_dwarf_attr (clone
, a
);
6802 case DW_AT_byte_size
:
6808 if (die
->comdat_type_p
)
6809 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6811 add_AT_flag (clone
, DW_AT_declaration
, 1);
6815 /* Copy the declaration context to the new type unit DIE. This includes
6816 any surrounding namespace or type declarations. If the DIE has an
6817 AT_specification attribute, it also includes attributes and children
6818 attached to the specification, and returns a pointer to the original
6819 parent of the declaration DIE. Returns NULL otherwise. */
6822 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6825 dw_die_ref new_decl
;
6826 dw_die_ref orig_parent
= NULL
;
6828 decl
= get_AT_ref (die
, DW_AT_specification
);
6837 /* The original DIE will be changed to a declaration, and must
6838 be moved to be a child of the original declaration DIE. */
6839 orig_parent
= decl
->die_parent
;
6841 /* Copy the type node pointer from the new DIE to the original
6842 declaration DIE so we can forward references later. */
6843 decl
->comdat_type_p
= true;
6844 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6846 remove_AT (die
, DW_AT_specification
);
6848 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6850 if (a
->dw_attr
!= DW_AT_name
6851 && a
->dw_attr
!= DW_AT_declaration
6852 && a
->dw_attr
!= DW_AT_external
)
6853 add_dwarf_attr (die
, a
);
6856 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6859 if (decl
->die_parent
!= NULL
6860 && !is_unit_die (decl
->die_parent
))
6862 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6863 if (new_decl
!= NULL
)
6865 remove_AT (new_decl
, DW_AT_signature
);
6866 add_AT_specification (die
, new_decl
);
6873 /* Generate the skeleton ancestor tree for the given NODE, then clone
6874 the DIE and add the clone into the tree. */
6877 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6879 if (node
->new_die
!= NULL
)
6882 node
->new_die
= clone_as_declaration (node
->old_die
);
6884 if (node
->parent
!= NULL
)
6886 generate_skeleton_ancestor_tree (node
->parent
);
6887 add_child_die (node
->parent
->new_die
, node
->new_die
);
6891 /* Generate a skeleton tree of DIEs containing any declarations that are
6892 found in the original tree. We traverse the tree looking for declaration
6893 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6896 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6898 skeleton_chain_node node
;
6901 dw_die_ref prev
= NULL
;
6902 dw_die_ref next
= NULL
;
6904 node
.parent
= parent
;
6906 first
= c
= parent
->old_die
->die_child
;
6910 if (prev
== NULL
|| prev
->die_sib
== c
)
6913 next
= (c
== first
? NULL
: c
->die_sib
);
6915 node
.new_die
= NULL
;
6916 if (is_declaration_die (c
))
6918 /* Clone the existing DIE, move the original to the skeleton
6919 tree (which is in the main CU), and put the clone, with
6920 all the original's children, where the original came from. */
6921 dw_die_ref clone
= clone_die (c
);
6922 move_all_children (c
, clone
);
6924 replace_child (c
, clone
, prev
);
6925 generate_skeleton_ancestor_tree (parent
);
6926 add_child_die (parent
->new_die
, c
);
6930 generate_skeleton_bottom_up (&node
);
6931 } while (next
!= NULL
);
6934 /* Wrapper function for generate_skeleton_bottom_up. */
6937 generate_skeleton (dw_die_ref die
)
6939 skeleton_chain_node node
;
6942 node
.new_die
= NULL
;
6945 /* If this type definition is nested inside another type,
6946 always leave at least a declaration in its place. */
6947 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
6948 node
.new_die
= clone_as_declaration (die
);
6950 generate_skeleton_bottom_up (&node
);
6951 return node
.new_die
;
6954 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
6955 declaration. The original DIE is moved to a new compile unit so that
6956 existing references to it follow it to the new location. If any of the
6957 original DIE's descendants is a declaration, we need to replace the
6958 original DIE with a skeleton tree and move the declarations back into the
6962 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
6965 dw_die_ref skeleton
, orig_parent
;
6967 /* Copy the declaration context to the type unit DIE. If the returned
6968 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
6970 orig_parent
= copy_declaration_context (unit
, child
);
6972 skeleton
= generate_skeleton (child
);
6973 if (skeleton
== NULL
)
6974 remove_child_with_prev (child
, prev
);
6977 skeleton
->comdat_type_p
= true;
6978 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
6980 /* If the original DIE was a specification, we need to put
6981 the skeleton under the parent DIE of the declaration.
6982 This leaves the original declaration in the tree, but
6983 it will be pruned later since there are no longer any
6984 references to it. */
6985 if (orig_parent
!= NULL
)
6987 remove_child_with_prev (child
, prev
);
6988 add_child_die (orig_parent
, skeleton
);
6991 replace_child (child
, skeleton
, prev
);
6997 /* Traverse the DIE and set up additional .debug_types sections for each
6998 type worthy of being placed in a COMDAT section. */
7001 break_out_comdat_types (dw_die_ref die
)
7005 dw_die_ref prev
= NULL
;
7006 dw_die_ref next
= NULL
;
7007 dw_die_ref unit
= NULL
;
7009 first
= c
= die
->die_child
;
7013 if (prev
== NULL
|| prev
->die_sib
== c
)
7016 next
= (c
== first
? NULL
: c
->die_sib
);
7017 if (should_move_die_to_comdat (c
))
7019 dw_die_ref replacement
;
7020 comdat_type_node_ref type_node
;
7022 /* Create a new type unit DIE as the root for the new tree, and
7023 add it to the list of comdat types. */
7024 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7025 add_AT_unsigned (unit
, DW_AT_language
,
7026 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7027 type_node
= ggc_alloc_cleared_comdat_type_node ();
7028 type_node
->root_die
= unit
;
7029 type_node
->next
= comdat_type_list
;
7030 comdat_type_list
= type_node
;
7032 /* Generate the type signature. */
7033 generate_type_signature (c
, type_node
);
7035 /* Copy the declaration context, attributes, and children of the
7036 declaration into the new type unit DIE, then remove this DIE
7037 from the main CU (or replace it with a skeleton if necessary). */
7038 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7039 type_node
->skeleton_die
= replacement
;
7041 /* Break out nested types into their own type units. */
7042 break_out_comdat_types (c
);
7044 /* Add the DIE to the new compunit. */
7045 add_child_die (unit
, c
);
7047 if (replacement
!= NULL
)
7050 else if (c
->die_tag
== DW_TAG_namespace
7051 || c
->die_tag
== DW_TAG_class_type
7052 || c
->die_tag
== DW_TAG_structure_type
7053 || c
->die_tag
== DW_TAG_union_type
)
7055 /* Look for nested types that can be broken out. */
7056 break_out_comdat_types (c
);
7058 } while (next
!= NULL
);
7061 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7063 struct decl_table_entry
7069 /* Routines to manipulate hash table of copied declarations. */
7072 htab_decl_hash (const void *of
)
7074 const struct decl_table_entry
*const entry
=
7075 (const struct decl_table_entry
*) of
;
7077 return htab_hash_pointer (entry
->orig
);
7081 htab_decl_eq (const void *of1
, const void *of2
)
7083 const struct decl_table_entry
*const entry1
=
7084 (const struct decl_table_entry
*) of1
;
7085 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7087 return entry1
->orig
== entry2
;
7091 htab_decl_del (void *what
)
7093 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7098 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7099 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7100 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7101 to check if the ancestor has already been copied into UNIT. */
7104 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7106 dw_die_ref parent
= die
->die_parent
;
7107 dw_die_ref new_parent
= unit
;
7110 struct decl_table_entry
*entry
= NULL
;
7114 /* Check if the entry has already been copied to UNIT. */
7115 slot
= htab_find_slot_with_hash (decl_table
, die
,
7116 htab_hash_pointer (die
), INSERT
);
7117 if (*slot
!= HTAB_EMPTY_ENTRY
)
7119 entry
= (struct decl_table_entry
*) *slot
;
7123 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7124 entry
= XCNEW (struct decl_table_entry
);
7132 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7135 if (!is_unit_die (parent
))
7136 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7139 copy
= clone_as_declaration (die
);
7140 add_child_die (new_parent
, copy
);
7142 if (decl_table
!= NULL
)
7144 /* Record the pointer to the copy. */
7151 /* Like clone_tree, but additionally enter all the children into
7152 the hash table decl_table. */
7155 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
7158 dw_die_ref clone
= clone_die (die
);
7159 struct decl_table_entry
*entry
;
7160 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
7161 htab_hash_pointer (die
), INSERT
);
7162 /* Assert that DIE isn't in the hash table yet. If it would be there
7163 before, the ancestors would be necessarily there as well, therefore
7164 clone_tree_hash wouldn't be called. */
7165 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7166 entry
= XCNEW (struct decl_table_entry
);
7168 entry
->copy
= clone
;
7171 FOR_EACH_CHILD (die
, c
,
7172 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7177 /* Walk the DIE and its children, looking for references to incomplete
7178 or trivial types that are unmarked (i.e., that are not in the current
7182 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7188 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7190 if (AT_class (a
) == dw_val_class_die_ref
)
7192 dw_die_ref targ
= AT_ref (a
);
7194 struct decl_table_entry
*entry
;
7196 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7199 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7200 htab_hash_pointer (targ
), INSERT
);
7202 if (*slot
!= HTAB_EMPTY_ENTRY
)
7204 /* TARG has already been copied, so we just need to
7205 modify the reference to point to the copy. */
7206 entry
= (struct decl_table_entry
*) *slot
;
7207 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7211 dw_die_ref parent
= unit
;
7212 dw_die_ref copy
= clone_die (targ
);
7214 /* Record in DECL_TABLE that TARG has been copied.
7215 Need to do this now, before the recursive call,
7216 because DECL_TABLE may be expanded and SLOT
7217 would no longer be a valid pointer. */
7218 entry
= XCNEW (struct decl_table_entry
);
7223 FOR_EACH_CHILD (targ
, c
,
7224 add_child_die (copy
,
7225 clone_tree_hash (c
, decl_table
)));
7227 /* Make sure the cloned tree is marked as part of the
7231 /* If TARG has surrounding context, copy its ancestor tree
7232 into the new type unit. */
7233 if (targ
->die_parent
!= NULL
7234 && !is_unit_die (targ
->die_parent
))
7235 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7238 add_child_die (parent
, copy
);
7239 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7241 /* Make sure the newly-copied DIE is walked. If it was
7242 installed in a previously-added context, it won't
7243 get visited otherwise. */
7246 /* Find the highest point of the newly-added tree,
7247 mark each node along the way, and walk from there. */
7248 parent
->die_mark
= 1;
7249 while (parent
->die_parent
7250 && parent
->die_parent
->die_mark
== 0)
7252 parent
= parent
->die_parent
;
7253 parent
->die_mark
= 1;
7255 copy_decls_walk (unit
, parent
, decl_table
);
7261 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7264 /* Copy declarations for "unworthy" types into the new comdat section.
7265 Incomplete types, modified types, and certain other types aren't broken
7266 out into comdat sections of their own, so they don't have a signature,
7267 and we need to copy the declaration into the same section so that we
7268 don't have an external reference. */
7271 copy_decls_for_unworthy_types (dw_die_ref unit
)
7276 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7277 copy_decls_walk (unit
, unit
, decl_table
);
7278 htab_delete (decl_table
);
7282 /* Traverse the DIE and add a sibling attribute if it may have the
7283 effect of speeding up access to siblings. To save some space,
7284 avoid generating sibling attributes for DIE's without children. */
7287 add_sibling_attributes (dw_die_ref die
)
7291 if (! die
->die_child
)
7294 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7295 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7297 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7300 /* Output all location lists for the DIE and its children. */
7303 output_location_lists (dw_die_ref die
)
7309 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7310 if (AT_class (a
) == dw_val_class_loc_list
)
7311 output_loc_list (AT_loc_list (a
));
7313 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7316 /* We want to limit the number of external references, because they are
7317 larger than local references: a relocation takes multiple words, and
7318 even a sig8 reference is always eight bytes, whereas a local reference
7319 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7320 So if we encounter multiple external references to the same type DIE, we
7321 make a local typedef stub for it and redirect all references there.
7323 This is the element of the hash table for keeping track of these
7333 /* Hash an external_ref. */
7336 hash_external_ref (const void *p
)
7338 const struct external_ref
*r
= (const struct external_ref
*)p
;
7339 return htab_hash_pointer (r
->type
);
7342 /* Compare external_refs. */
7345 external_ref_eq (const void *p1
, const void *p2
)
7347 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
7348 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
7349 return r1
->type
== r2
->type
;
7352 /* Return a pointer to the external_ref for references to DIE. */
7354 static struct external_ref
*
7355 lookup_external_ref (htab_t map
, dw_die_ref die
)
7357 struct external_ref ref
, *ref_p
;
7361 slot
= htab_find_slot (map
, &ref
, INSERT
);
7362 if (*slot
!= HTAB_EMPTY_ENTRY
)
7363 return (struct external_ref
*) *slot
;
7365 ref_p
= XCNEW (struct external_ref
);
7371 /* Subroutine of optimize_external_refs, below.
7373 If we see a type skeleton, record it as our stub. If we see external
7374 references, remember how many we've seen. */
7377 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
7382 struct external_ref
*ref_p
;
7384 if (is_type_die (die
)
7385 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7387 /* This is a local skeleton; use it for local references. */
7388 ref_p
= lookup_external_ref (map
, c
);
7392 /* Scan the DIE references, and remember any that refer to DIEs from
7393 other CUs (i.e. those which are not marked). */
7394 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7395 if (AT_class (a
) == dw_val_class_die_ref
7396 && (c
= AT_ref (a
))->die_mark
== 0
7399 ref_p
= lookup_external_ref (map
, c
);
7403 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7406 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7407 points to an external_ref, DATA is the CU we're processing. If we don't
7408 already have a local stub, and we have multiple refs, build a stub. */
7411 build_local_stub (void **slot
, void *data
)
7413 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7415 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7417 /* We have multiple references to this type, so build a small stub.
7418 Both of these forms are a bit dodgy from the perspective of the
7419 DWARF standard, since technically they should have names. */
7420 dw_die_ref cu
= (dw_die_ref
) data
;
7421 dw_die_ref type
= ref_p
->type
;
7422 dw_die_ref stub
= NULL
;
7424 if (type
->comdat_type_p
)
7426 /* If we refer to this type via sig8, use AT_signature. */
7427 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7428 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7432 /* Otherwise, use a typedef with no name. */
7433 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7434 add_AT_die_ref (stub
, DW_AT_type
, type
);
7443 /* DIE is a unit; look through all the DIE references to see if there are
7444 any external references to types, and if so, create local stubs for
7445 them which will be applied in build_abbrev_table. This is useful because
7446 references to local DIEs are smaller. */
7449 optimize_external_refs (dw_die_ref die
)
7451 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7452 optimize_external_refs_1 (die
, map
);
7453 htab_traverse (map
, build_local_stub
, die
);
7457 /* The format of each DIE (and its attribute value pairs) is encoded in an
7458 abbreviation table. This routine builds the abbreviation table and assigns
7459 a unique abbreviation id for each abbreviation entry. The children of each
7460 die are visited recursively. */
7463 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7465 unsigned long abbrev_id
;
7466 unsigned int n_alloc
;
7471 /* Scan the DIE references, and replace any that refer to
7472 DIEs from other CUs (i.e. those which are not marked) with
7473 the local stubs we built in optimize_external_refs. */
7474 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7475 if (AT_class (a
) == dw_val_class_die_ref
7476 && (c
= AT_ref (a
))->die_mark
== 0)
7478 struct external_ref
*ref_p
;
7479 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7481 ref_p
= lookup_external_ref (extern_map
, c
);
7482 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7483 change_AT_die_ref (a
, ref_p
->stub
);
7485 /* We aren't changing this reference, so mark it external. */
7486 set_AT_ref_external (a
, 1);
7489 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7491 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7492 dw_attr_ref die_a
, abbrev_a
;
7496 if (abbrev
->die_tag
!= die
->die_tag
)
7498 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7501 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7504 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7506 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7507 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7508 || (value_format (abbrev_a
) != value_format (die_a
)))
7518 if (abbrev_id
>= abbrev_die_table_in_use
)
7520 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7522 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7523 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7526 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7527 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7528 abbrev_die_table_allocated
= n_alloc
;
7531 ++abbrev_die_table_in_use
;
7532 abbrev_die_table
[abbrev_id
] = die
;
7535 die
->die_abbrev
= abbrev_id
;
7536 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7539 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7542 constant_size (unsigned HOST_WIDE_INT value
)
7549 log
= floor_log2 (value
);
7552 log
= 1 << (floor_log2 (log
) + 1);
7557 /* Return the size of a DIE as it is represented in the
7558 .debug_info section. */
7560 static unsigned long
7561 size_of_die (dw_die_ref die
)
7563 unsigned long size
= 0;
7566 enum dwarf_form form
;
7568 size
+= size_of_uleb128 (die
->die_abbrev
);
7569 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7571 switch (AT_class (a
))
7573 case dw_val_class_addr
:
7574 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7576 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7577 size
+= size_of_uleb128 (AT_index (a
));
7580 size
+= DWARF2_ADDR_SIZE
;
7582 case dw_val_class_offset
:
7583 size
+= DWARF_OFFSET_SIZE
;
7585 case dw_val_class_loc
:
7587 unsigned long lsize
= size_of_locs (AT_loc (a
));
7590 if (dwarf_version
>= 4)
7591 size
+= size_of_uleb128 (lsize
);
7593 size
+= constant_size (lsize
);
7597 case dw_val_class_loc_list
:
7598 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7600 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7601 size
+= size_of_uleb128 (AT_index (a
));
7604 size
+= DWARF_OFFSET_SIZE
;
7606 case dw_val_class_range_list
:
7607 size
+= DWARF_OFFSET_SIZE
;
7609 case dw_val_class_const
:
7610 size
+= size_of_sleb128 (AT_int (a
));
7612 case dw_val_class_unsigned_const
:
7614 int csize
= constant_size (AT_unsigned (a
));
7615 if (dwarf_version
== 3
7616 && a
->dw_attr
== DW_AT_data_member_location
7618 size
+= size_of_uleb128 (AT_unsigned (a
));
7623 case dw_val_class_const_double
:
7624 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7625 if (HOST_BITS_PER_WIDE_INT
>= 64)
7628 case dw_val_class_vec
:
7629 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7630 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7631 + a
->dw_attr_val
.v
.val_vec
.length
7632 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7634 case dw_val_class_flag
:
7635 if (dwarf_version
>= 4)
7636 /* Currently all add_AT_flag calls pass in 1 as last argument,
7637 so DW_FORM_flag_present can be used. If that ever changes,
7638 we'll need to use DW_FORM_flag and have some optimization
7639 in build_abbrev_table that will change those to
7640 DW_FORM_flag_present if it is set to 1 in all DIEs using
7641 the same abbrev entry. */
7642 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7646 case dw_val_class_die_ref
:
7647 if (AT_ref_external (a
))
7649 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7650 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7651 is sized by target address length, whereas in DWARF3
7652 it's always sized as an offset. */
7653 if (use_debug_types
)
7654 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7655 else if (dwarf_version
== 2)
7656 size
+= DWARF2_ADDR_SIZE
;
7658 size
+= DWARF_OFFSET_SIZE
;
7661 size
+= DWARF_OFFSET_SIZE
;
7663 case dw_val_class_fde_ref
:
7664 size
+= DWARF_OFFSET_SIZE
;
7666 case dw_val_class_lbl_id
:
7667 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7669 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7670 size
+= size_of_uleb128 (AT_index (a
));
7673 size
+= DWARF2_ADDR_SIZE
;
7675 case dw_val_class_lineptr
:
7676 case dw_val_class_macptr
:
7677 size
+= DWARF_OFFSET_SIZE
;
7679 case dw_val_class_str
:
7680 form
= AT_string_form (a
);
7681 if (form
== DW_FORM_strp
)
7682 size
+= DWARF_OFFSET_SIZE
;
7683 else if (form
== DW_FORM_GNU_str_index
)
7684 size
+= size_of_uleb128 (AT_index (a
));
7686 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7688 case dw_val_class_file
:
7689 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7691 case dw_val_class_data8
:
7694 case dw_val_class_vms_delta
:
7695 size
+= DWARF_OFFSET_SIZE
;
7697 case dw_val_class_high_pc
:
7698 size
+= DWARF2_ADDR_SIZE
;
7708 /* Size the debugging information associated with a given DIE. Visits the
7709 DIE's children recursively. Updates the global variable next_die_offset, on
7710 each time through. Uses the current value of next_die_offset to update the
7711 die_offset field in each DIE. */
7714 calc_die_sizes (dw_die_ref die
)
7718 gcc_assert (die
->die_offset
== 0
7719 || (unsigned long int) die
->die_offset
== next_die_offset
);
7720 die
->die_offset
= next_die_offset
;
7721 next_die_offset
+= size_of_die (die
);
7723 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7725 if (die
->die_child
!= NULL
)
7726 /* Count the null byte used to terminate sibling lists. */
7727 next_die_offset
+= 1;
7730 /* Size just the base type children at the start of the CU.
7731 This is needed because build_abbrev needs to size locs
7732 and sizing of type based stack ops needs to know die_offset
7733 values for the base types. */
7736 calc_base_type_die_sizes (void)
7738 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7740 dw_die_ref base_type
;
7741 #if ENABLE_ASSERT_CHECKING
7742 dw_die_ref prev
= comp_unit_die ()->die_child
;
7745 die_offset
+= size_of_die (comp_unit_die ());
7746 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7748 #if ENABLE_ASSERT_CHECKING
7749 gcc_assert (base_type
->die_offset
== 0
7750 && prev
->die_sib
== base_type
7751 && base_type
->die_child
== NULL
7752 && base_type
->die_abbrev
);
7755 base_type
->die_offset
= die_offset
;
7756 die_offset
+= size_of_die (base_type
);
7760 /* Set the marks for a die and its children. We do this so
7761 that we know whether or not a reference needs to use FORM_ref_addr; only
7762 DIEs in the same CU will be marked. We used to clear out the offset
7763 and use that as the flag, but ran into ordering problems. */
7766 mark_dies (dw_die_ref die
)
7770 gcc_assert (!die
->die_mark
);
7773 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7776 /* Clear the marks for a die and its children. */
7779 unmark_dies (dw_die_ref die
)
7783 if (! use_debug_types
)
7784 gcc_assert (die
->die_mark
);
7787 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7790 /* Clear the marks for a die, its children and referred dies. */
7793 unmark_all_dies (dw_die_ref die
)
7803 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7805 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7806 if (AT_class (a
) == dw_val_class_die_ref
)
7807 unmark_all_dies (AT_ref (a
));
7810 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7811 generated for the compilation unit. */
7813 static unsigned long
7814 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7820 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7821 FOR_EACH_VEC_ELT (*names
, i
, p
)
7822 if (names
!= pubtype_table
7823 || p
->die
->die_offset
!= 0
7824 || !flag_eliminate_unused_debug_types
)
7825 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7827 size
+= DWARF_OFFSET_SIZE
;
7831 /* Return the size of the information in the .debug_aranges section. */
7833 static unsigned long
7834 size_of_aranges (void)
7838 size
= DWARF_ARANGES_HEADER_SIZE
;
7840 /* Count the address/length pair for this compilation unit. */
7841 if (text_section_used
)
7842 size
+= 2 * DWARF2_ADDR_SIZE
;
7843 if (cold_text_section_used
)
7844 size
+= 2 * DWARF2_ADDR_SIZE
;
7845 if (have_multiple_function_sections
)
7850 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
7852 if (!fde
->in_std_section
)
7853 size
+= 2 * DWARF2_ADDR_SIZE
;
7854 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7855 size
+= 2 * DWARF2_ADDR_SIZE
;
7859 /* Count the two zero words used to terminated the address range table. */
7860 size
+= 2 * DWARF2_ADDR_SIZE
;
7864 /* Select the encoding of an attribute value. */
7866 static enum dwarf_form
7867 value_format (dw_attr_ref a
)
7869 switch (AT_class (a
))
7871 case dw_val_class_addr
:
7872 /* Only very few attributes allow DW_FORM_addr. */
7877 case DW_AT_entry_pc
:
7878 case DW_AT_trampoline
:
7879 return (AT_index (a
) == NOT_INDEXED
7880 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7884 switch (DWARF2_ADDR_SIZE
)
7887 return DW_FORM_data1
;
7889 return DW_FORM_data2
;
7891 return DW_FORM_data4
;
7893 return DW_FORM_data8
;
7897 case dw_val_class_range_list
:
7898 case dw_val_class_loc_list
:
7899 if (dwarf_version
>= 4)
7900 return DW_FORM_sec_offset
;
7902 case dw_val_class_vms_delta
:
7903 case dw_val_class_offset
:
7904 switch (DWARF_OFFSET_SIZE
)
7907 return DW_FORM_data4
;
7909 return DW_FORM_data8
;
7913 case dw_val_class_loc
:
7914 if (dwarf_version
>= 4)
7915 return DW_FORM_exprloc
;
7916 switch (constant_size (size_of_locs (AT_loc (a
))))
7919 return DW_FORM_block1
;
7921 return DW_FORM_block2
;
7923 return DW_FORM_block4
;
7927 case dw_val_class_const
:
7928 return DW_FORM_sdata
;
7929 case dw_val_class_unsigned_const
:
7930 switch (constant_size (AT_unsigned (a
)))
7933 return DW_FORM_data1
;
7935 return DW_FORM_data2
;
7937 /* In DWARF3 DW_AT_data_member_location with
7938 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7939 constant, so we need to use DW_FORM_udata if we need
7940 a large constant. */
7941 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7942 return DW_FORM_udata
;
7943 return DW_FORM_data4
;
7945 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7946 return DW_FORM_udata
;
7947 return DW_FORM_data8
;
7951 case dw_val_class_const_double
:
7952 switch (HOST_BITS_PER_WIDE_INT
)
7955 return DW_FORM_data2
;
7957 return DW_FORM_data4
;
7959 return DW_FORM_data8
;
7962 return DW_FORM_block1
;
7964 case dw_val_class_vec
:
7965 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7966 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7969 return DW_FORM_block1
;
7971 return DW_FORM_block2
;
7973 return DW_FORM_block4
;
7977 case dw_val_class_flag
:
7978 if (dwarf_version
>= 4)
7980 /* Currently all add_AT_flag calls pass in 1 as last argument,
7981 so DW_FORM_flag_present can be used. If that ever changes,
7982 we'll need to use DW_FORM_flag and have some optimization
7983 in build_abbrev_table that will change those to
7984 DW_FORM_flag_present if it is set to 1 in all DIEs using
7985 the same abbrev entry. */
7986 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7987 return DW_FORM_flag_present
;
7989 return DW_FORM_flag
;
7990 case dw_val_class_die_ref
:
7991 if (AT_ref_external (a
))
7992 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
7995 case dw_val_class_fde_ref
:
7996 return DW_FORM_data
;
7997 case dw_val_class_lbl_id
:
7998 return (AT_index (a
) == NOT_INDEXED
7999 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8000 case dw_val_class_lineptr
:
8001 case dw_val_class_macptr
:
8002 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8003 case dw_val_class_str
:
8004 return AT_string_form (a
);
8005 case dw_val_class_file
:
8006 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8009 return DW_FORM_data1
;
8011 return DW_FORM_data2
;
8013 return DW_FORM_data4
;
8018 case dw_val_class_data8
:
8019 return DW_FORM_data8
;
8021 case dw_val_class_high_pc
:
8022 switch (DWARF2_ADDR_SIZE
)
8025 return DW_FORM_data1
;
8027 return DW_FORM_data2
;
8029 return DW_FORM_data4
;
8031 return DW_FORM_data8
;
8041 /* Output the encoding of an attribute value. */
8044 output_value_format (dw_attr_ref a
)
8046 enum dwarf_form form
= value_format (a
);
8048 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8051 /* Given a die and id, produce the appropriate abbreviations. */
8054 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8059 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8060 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8061 dwarf_tag_name (abbrev
->die_tag
));
8063 if (abbrev
->die_child
!= NULL
)
8064 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8066 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8068 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8070 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8071 dwarf_attr_name (a_attr
->dw_attr
));
8072 output_value_format (a_attr
);
8075 dw2_asm_output_data (1, 0, NULL
);
8076 dw2_asm_output_data (1, 0, NULL
);
8080 /* Output the .debug_abbrev section which defines the DIE abbreviation
8084 output_abbrev_section (void)
8086 unsigned long abbrev_id
;
8088 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8089 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8091 /* Terminate the table. */
8092 dw2_asm_output_data (1, 0, NULL
);
8095 /* Output a symbol we can use to refer to this DIE from another CU. */
8098 output_die_symbol (dw_die_ref die
)
8100 const char *sym
= die
->die_id
.die_symbol
;
8102 gcc_assert (!die
->comdat_type_p
);
8107 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8108 /* We make these global, not weak; if the target doesn't support
8109 .linkonce, it doesn't support combining the sections, so debugging
8111 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8113 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8116 /* Return a new location list, given the begin and end range, and the
8119 static inline dw_loc_list_ref
8120 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8121 const char *section
)
8123 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8125 retlist
->begin
= begin
;
8126 retlist
->begin_entry
= NULL
;
8128 retlist
->expr
= expr
;
8129 retlist
->section
= section
;
8134 /* Generate a new internal symbol for this location list node, if it
8135 hasn't got one yet. */
8138 gen_llsym (dw_loc_list_ref list
)
8140 gcc_assert (!list
->ll_symbol
);
8141 list
->ll_symbol
= gen_internal_sym ("LLST");
8144 /* Output the location list given to us. */
8147 output_loc_list (dw_loc_list_ref list_head
)
8149 dw_loc_list_ref curr
= list_head
;
8151 if (list_head
->emitted
)
8153 list_head
->emitted
= true;
8155 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8157 /* Walk the location list, and output each range + expression. */
8158 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8161 /* Don't output an entry that starts and ends at the same address. */
8162 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8164 size
= size_of_locs (curr
->expr
);
8165 /* If the expression is too large, drop it on the floor. We could
8166 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8167 in the expression, but >= 64KB expressions for a single value
8168 in a single range are unlikely very useful. */
8171 if (dwarf_split_debug_info
)
8173 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8174 "Location list start/length entry (%s)",
8175 list_head
->ll_symbol
);
8176 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8177 "Location list range start index (%s)",
8179 /* The length field is 4 bytes. If we ever need to support
8180 an 8-byte length, we can add a new DW_LLE code or fall back
8181 to DW_LLE_GNU_start_end_entry. */
8182 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8183 "Location list range length (%s)",
8184 list_head
->ll_symbol
);
8186 else if (!have_multiple_function_sections
)
8188 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8189 "Location list begin address (%s)",
8190 list_head
->ll_symbol
);
8191 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8192 "Location list end address (%s)",
8193 list_head
->ll_symbol
);
8197 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8198 "Location list begin address (%s)",
8199 list_head
->ll_symbol
);
8200 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8201 "Location list end address (%s)",
8202 list_head
->ll_symbol
);
8205 /* Output the block length for this list of location operations. */
8206 gcc_assert (size
<= 0xffff);
8207 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8209 output_loc_sequence (curr
->expr
, -1);
8212 if (dwarf_split_debug_info
)
8213 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8214 "Location list terminator (%s)",
8215 list_head
->ll_symbol
);
8218 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8219 "Location list terminator begin (%s)",
8220 list_head
->ll_symbol
);
8221 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8222 "Location list terminator end (%s)",
8223 list_head
->ll_symbol
);
8227 /* Output a range_list offset into the debug_range section. Emit a
8228 relocated reference if val_entry is NULL, otherwise, emit an
8229 indirect reference. */
8232 output_range_list_offset (dw_attr_ref a
)
8234 const char *name
= dwarf_attr_name (a
->dw_attr
);
8236 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8238 char *p
= strchr (ranges_section_label
, '\0');
8239 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8240 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8241 debug_ranges_section
, "%s", name
);
8245 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8246 "%s (offset from %s)", name
, ranges_section_label
);
8249 /* Output the offset into the debug_loc section. */
8252 output_loc_list_offset (dw_attr_ref a
)
8254 char *sym
= AT_loc_list (a
)->ll_symbol
;
8257 if (dwarf_split_debug_info
)
8258 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8259 "%s", dwarf_attr_name (a
->dw_attr
));
8261 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8262 "%s", dwarf_attr_name (a
->dw_attr
));
8265 /* Output an attribute's index or value appropriately. */
8268 output_attr_index_or_value (dw_attr_ref a
)
8270 const char *name
= dwarf_attr_name (a
->dw_attr
);
8272 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8274 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8277 switch (AT_class (a
))
8279 case dw_val_class_addr
:
8280 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8282 case dw_val_class_high_pc
:
8283 case dw_val_class_lbl_id
:
8284 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8286 case dw_val_class_loc_list
:
8287 output_loc_list_offset (a
);
8294 /* Output a type signature. */
8297 output_signature (const char *sig
, const char *name
)
8301 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8302 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8305 /* Output the DIE and its attributes. Called recursively to generate
8306 the definitions of each child DIE. */
8309 output_die (dw_die_ref die
)
8316 /* If someone in another CU might refer to us, set up a symbol for
8317 them to point to. */
8318 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8319 output_die_symbol (die
);
8321 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8322 (unsigned long)die
->die_offset
,
8323 dwarf_tag_name (die
->die_tag
));
8325 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8327 const char *name
= dwarf_attr_name (a
->dw_attr
);
8329 switch (AT_class (a
))
8331 case dw_val_class_addr
:
8332 output_attr_index_or_value (a
);
8335 case dw_val_class_offset
:
8336 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8340 case dw_val_class_range_list
:
8341 output_range_list_offset (a
);
8344 case dw_val_class_loc
:
8345 size
= size_of_locs (AT_loc (a
));
8347 /* Output the block length for this list of location operations. */
8348 if (dwarf_version
>= 4)
8349 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8351 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8353 output_loc_sequence (AT_loc (a
), -1);
8356 case dw_val_class_const
:
8357 /* ??? It would be slightly more efficient to use a scheme like is
8358 used for unsigned constants below, but gdb 4.x does not sign
8359 extend. Gdb 5.x does sign extend. */
8360 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8363 case dw_val_class_unsigned_const
:
8365 int csize
= constant_size (AT_unsigned (a
));
8366 if (dwarf_version
== 3
8367 && a
->dw_attr
== DW_AT_data_member_location
8369 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8371 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8375 case dw_val_class_const_double
:
8377 unsigned HOST_WIDE_INT first
, second
;
8379 if (HOST_BITS_PER_WIDE_INT
>= 64)
8380 dw2_asm_output_data (1,
8381 HOST_BITS_PER_DOUBLE_INT
8382 / HOST_BITS_PER_CHAR
,
8385 if (WORDS_BIG_ENDIAN
)
8387 first
= a
->dw_attr_val
.v
.val_double
.high
;
8388 second
= a
->dw_attr_val
.v
.val_double
.low
;
8392 first
= a
->dw_attr_val
.v
.val_double
.low
;
8393 second
= a
->dw_attr_val
.v
.val_double
.high
;
8396 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8398 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8403 case dw_val_class_vec
:
8405 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8406 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8410 dw2_asm_output_data (constant_size (len
* elt_size
),
8411 len
* elt_size
, "%s", name
);
8412 if (elt_size
> sizeof (HOST_WIDE_INT
))
8417 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8420 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8421 "fp or vector constant word %u", i
);
8425 case dw_val_class_flag
:
8426 if (dwarf_version
>= 4)
8428 /* Currently all add_AT_flag calls pass in 1 as last argument,
8429 so DW_FORM_flag_present can be used. If that ever changes,
8430 we'll need to use DW_FORM_flag and have some optimization
8431 in build_abbrev_table that will change those to
8432 DW_FORM_flag_present if it is set to 1 in all DIEs using
8433 the same abbrev entry. */
8434 gcc_assert (AT_flag (a
) == 1);
8436 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8437 ASM_COMMENT_START
, name
);
8440 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8443 case dw_val_class_loc_list
:
8444 output_attr_index_or_value (a
);
8447 case dw_val_class_die_ref
:
8448 if (AT_ref_external (a
))
8450 if (AT_ref (a
)->comdat_type_p
)
8452 comdat_type_node_ref type_node
=
8453 AT_ref (a
)->die_id
.die_type_node
;
8455 gcc_assert (type_node
);
8456 output_signature (type_node
->signature
, name
);
8460 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8464 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8465 length, whereas in DWARF3 it's always sized as an
8467 if (dwarf_version
== 2)
8468 size
= DWARF2_ADDR_SIZE
;
8470 size
= DWARF_OFFSET_SIZE
;
8471 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8477 gcc_assert (AT_ref (a
)->die_offset
);
8478 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8483 case dw_val_class_fde_ref
:
8487 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8488 a
->dw_attr_val
.v
.val_fde_index
* 2);
8489 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8494 case dw_val_class_vms_delta
:
8495 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8496 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8500 case dw_val_class_lbl_id
:
8501 output_attr_index_or_value (a
);
8504 case dw_val_class_lineptr
:
8505 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8506 debug_line_section
, "%s", name
);
8509 case dw_val_class_macptr
:
8510 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8511 debug_macinfo_section
, "%s", name
);
8514 case dw_val_class_str
:
8515 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8516 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8517 a
->dw_attr_val
.v
.val_str
->label
,
8519 "%s: \"%s\"", name
, AT_string (a
));
8520 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8521 dw2_asm_output_data_uleb128 (AT_index (a
),
8522 "%s: \"%s\"", name
, AT_string (a
));
8524 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8527 case dw_val_class_file
:
8529 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8531 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8532 a
->dw_attr_val
.v
.val_file
->filename
);
8536 case dw_val_class_data8
:
8540 for (i
= 0; i
< 8; i
++)
8541 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8542 i
== 0 ? "%s" : NULL
, name
);
8546 case dw_val_class_high_pc
:
8547 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8548 get_AT_low_pc (die
), "DW_AT_high_pc");
8556 FOR_EACH_CHILD (die
, c
, output_die (c
));
8558 /* Add null byte to terminate sibling list. */
8559 if (die
->die_child
!= NULL
)
8560 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8561 (unsigned long) die
->die_offset
);
8564 /* Output the compilation unit that appears at the beginning of the
8565 .debug_info section, and precedes the DIE descriptions. */
8568 output_compilation_unit_header (void)
8570 int ver
= dwarf_version
;
8572 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8573 dw2_asm_output_data (4, 0xffffffff,
8574 "Initial length escape value indicating 64-bit DWARF extension");
8575 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8576 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8577 "Length of Compilation Unit Info");
8578 dw2_asm_output_data (2, ver
, "DWARF version number");
8579 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8580 debug_abbrev_section
,
8581 "Offset Into Abbrev. Section");
8582 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8585 /* Output the compilation unit DIE and its children. */
8588 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8590 const char *secname
, *oldsym
;
8594 /* Unless we are outputting main CU, we may throw away empty ones. */
8595 if (!output_if_empty
&& die
->die_child
== NULL
)
8598 /* Even if there are no children of this DIE, we must output the information
8599 about the compilation unit. Otherwise, on an empty translation unit, we
8600 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8601 will then complain when examining the file. First mark all the DIEs in
8602 this CU so we know which get local refs. */
8605 extern_map
= optimize_external_refs (die
);
8607 build_abbrev_table (die
, extern_map
);
8609 htab_delete (extern_map
);
8611 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8612 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8613 calc_die_sizes (die
);
8615 oldsym
= die
->die_id
.die_symbol
;
8618 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8620 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8622 die
->die_id
.die_symbol
= NULL
;
8623 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8627 switch_to_section (debug_info_section
);
8628 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8629 info_section_emitted
= true;
8632 /* Output debugging information. */
8633 output_compilation_unit_header ();
8636 /* Leave the marks on the main CU, so we can check them in
8641 die
->die_id
.die_symbol
= oldsym
;
8645 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8646 and .debug_pubtypes. This is configured per-target, but can be
8647 overridden by the -gpubnames or -gno-pubnames options. */
8650 want_pubnames (void)
8652 return (debug_generate_pub_sections
!= -1
8653 ? debug_generate_pub_sections
8654 : targetm
.want_debug_pub_sections
);
8657 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8660 add_AT_pubnames (dw_die_ref die
)
8662 if (want_pubnames ())
8663 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8666 /* Helper function to generate top-level dies for skeleton debug_info and
8670 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8672 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8675 add_comp_dir_attribute (die
);
8676 add_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8677 /* The specification suggests that these attributes be inline to avoid
8678 having a .debug_str section. We know that they exist in the die because
8679 we just added them. */
8680 attr
= get_AT (die
, DW_AT_GNU_dwo_name
);
8681 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8682 attr
= get_AT (die
, DW_AT_comp_dir
);
8683 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8685 add_AT_pubnames (die
);
8686 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8689 /* Return the single type-unit die for skeleton type units. */
8692 get_skeleton_type_unit (void)
8694 /* For dwarf_split_debug_sections with use_type info, all type units in the
8695 skeleton sections have identical dies (but different headers). This
8696 single die will be output many times. */
8698 static dw_die_ref skeleton_type_unit
= NULL
;
8700 if (skeleton_type_unit
== NULL
)
8702 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8703 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8704 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8706 return skeleton_type_unit
;
8709 /* Output skeleton debug sections that point to the dwo file. */
8712 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8714 /* These attributes will be found in the full debug_info section. */
8715 remove_AT (comp_unit
, DW_AT_producer
);
8716 remove_AT (comp_unit
, DW_AT_language
);
8718 /* Add attributes common to skeleton compile_units and type_units. */
8719 add_top_level_skeleton_die_attrs (comp_unit
);
8721 switch_to_section (debug_skeleton_info_section
);
8722 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8724 /* Produce the skeleton compilation-unit header. This one differs enough from
8725 a normal CU header that it's better not to call output_compilation_unit
8727 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8728 dw2_asm_output_data (4, 0xffffffff,
8729 "Initial length escape value indicating 64-bit DWARF extension");
8731 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8732 DWARF_COMPILE_UNIT_HEADER_SIZE
8733 - DWARF_INITIAL_LENGTH_SIZE
8734 + size_of_die (comp_unit
),
8735 "Length of Compilation Unit Info");
8736 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8737 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8738 debug_abbrev_section
,
8739 "Offset Into Abbrev. Section");
8740 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8742 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8743 output_die (comp_unit
);
8745 /* Build the skeleton debug_abbrev section. */
8746 switch_to_section (debug_skeleton_abbrev_section
);
8747 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8749 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8750 if (use_debug_types
)
8751 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8753 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8756 /* Output a comdat type unit DIE and its children. */
8759 output_comdat_type_unit (comdat_type_node
*node
)
8761 const char *secname
;
8764 #if defined (OBJECT_FORMAT_ELF)
8769 /* First mark all the DIEs in this CU so we know which get local refs. */
8770 mark_dies (node
->root_die
);
8772 extern_map
= optimize_external_refs (node
->root_die
);
8774 build_abbrev_table (node
->root_die
, extern_map
);
8776 htab_delete (extern_map
);
8778 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8779 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8780 calc_die_sizes (node
->root_die
);
8782 #if defined (OBJECT_FORMAT_ELF)
8783 if (!dwarf_split_debug_info
)
8784 secname
= ".debug_types";
8786 secname
= ".debug_types.dwo";
8788 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8789 sprintf (tmp
, "wt.");
8790 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8791 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8792 comdat_key
= get_identifier (tmp
);
8793 targetm
.asm_out
.named_section (secname
,
8794 SECTION_DEBUG
| SECTION_LINKONCE
,
8797 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8798 sprintf (tmp
, ".gnu.linkonce.wt.");
8799 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8800 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8802 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8805 /* Output debugging information. */
8806 output_compilation_unit_header ();
8807 output_signature (node
->signature
, "Type Signature");
8808 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8809 "Offset to Type DIE");
8810 output_die (node
->root_die
);
8812 unmark_dies (node
->root_die
);
8814 #if defined (OBJECT_FORMAT_ELF)
8815 if (dwarf_split_debug_info
)
8817 /* Produce the skeleton type-unit header. */
8818 const char *secname
= ".debug_types";
8820 targetm
.asm_out
.named_section (secname
,
8821 SECTION_DEBUG
| SECTION_LINKONCE
,
8823 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8824 dw2_asm_output_data (4, 0xffffffff,
8825 "Initial length escape value indicating 64-bit DWARF extension");
8827 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8828 DWARF_COMPILE_UNIT_HEADER_SIZE
8829 - DWARF_INITIAL_LENGTH_SIZE
8830 + size_of_die (get_skeleton_type_unit ())
8831 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
8832 "Length of Type Unit Info");
8833 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8834 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8835 debug_skeleton_abbrev_section_label
,
8836 debug_abbrev_section
,
8837 "Offset Into Abbrev. Section");
8838 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8839 output_signature (node
->signature
, "Type Signature");
8840 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
8842 output_die (get_skeleton_type_unit ());
8847 /* Return the DWARF2/3 pubname associated with a decl. */
8850 dwarf2_name (tree decl
, int scope
)
8852 if (DECL_NAMELESS (decl
))
8854 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8857 /* Add a new entry to .debug_pubnames if appropriate. */
8860 add_pubname_string (const char *str
, dw_die_ref die
)
8865 e
.name
= xstrdup (str
);
8866 vec_safe_push (pubname_table
, e
);
8870 add_pubname (tree decl
, dw_die_ref die
)
8872 if (!want_pubnames ())
8875 /* Don't add items to the table when we expect that the consumer will have
8876 just read the enclosing die. For example, if the consumer is looking at a
8877 class_member, it will either be inside the class already, or will have just
8878 looked up the class to find the member. Either way, searching the class is
8879 faster than searching the index. */
8880 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
8881 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8883 const char *name
= dwarf2_name (decl
, 1);
8886 add_pubname_string (name
, die
);
8890 /* Add an enumerator to the pubnames section. */
8893 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8897 gcc_assert (scope_name
);
8898 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8900 vec_safe_push (pubname_table
, e
);
8903 /* Add a new entry to .debug_pubtypes if appropriate. */
8906 add_pubtype (tree decl
, dw_die_ref die
)
8910 if (!want_pubnames ())
8913 if ((TREE_PUBLIC (decl
)
8914 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8915 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8918 const char *scope_name
= "";
8919 const char *sep
= is_cxx () ? "::" : ".";
8922 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8923 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8925 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8926 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8927 scope_name
= concat (scope_name
, sep
, NULL
);
8933 name
= type_tag (decl
);
8935 name
= lang_hooks
.dwarf_name (decl
, 1);
8937 /* If we don't have a name for the type, there's no point in adding
8939 if (name
!= NULL
&& name
[0] != '\0')
8942 e
.name
= concat (scope_name
, name
, NULL
);
8943 vec_safe_push (pubtype_table
, e
);
8946 /* Although it might be more consistent to add the pubinfo for the
8947 enumerators as their dies are created, they should only be added if the
8948 enum type meets the criteria above. So rather than re-check the parent
8949 enum type whenever an enumerator die is created, just output them all
8950 here. This isn't protected by the name conditional because anonymous
8951 enums don't have names. */
8952 if (die
->die_tag
== DW_TAG_enumeration_type
)
8956 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
8961 /* Output the public names table used to speed up access to externally
8962 visible names; or the public types table used to find type definitions. */
8965 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8968 unsigned long pubnames_length
= size_of_pubnames (names
);
8971 if (!want_pubnames () || !info_section_emitted
)
8973 if (names
== pubname_table
)
8974 switch_to_section (debug_pubnames_section
);
8976 switch_to_section (debug_pubtypes_section
);
8977 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8978 dw2_asm_output_data (4, 0xffffffff,
8979 "Initial length escape value indicating 64-bit DWARF extension");
8980 if (names
== pubname_table
)
8981 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8982 "Length of Public Names Info");
8984 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8985 "Length of Public Type Names Info");
8986 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8987 dw2_asm_output_data (2, 2, "DWARF Version");
8988 if (dwarf_split_debug_info
)
8989 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
8990 debug_skeleton_info_section
,
8991 "Offset of Compilation Unit Info");
8993 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8995 "Offset of Compilation Unit Info");
8996 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8997 "Compilation Unit Length");
8999 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9001 /* Enumerator names are part of the pubname table, but the parent
9002 DW_TAG_enumeration_type die may have been pruned. Don't output
9003 them if that is the case. */
9004 if (pub
->die
->die_tag
== DW_TAG_enumerator
&& !pub
->die
->die_mark
)
9007 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9008 if (names
== pubname_table
)
9009 gcc_assert (pub
->die
->die_mark
);
9011 if (names
!= pubtype_table
9012 || pub
->die
->die_offset
!= 0
9013 || !flag_eliminate_unused_debug_types
)
9015 dw_offset die_offset
= pub
->die
->die_offset
;
9017 /* If we're putting types in their own .debug_types sections,
9018 the .debug_pubtypes table will still point to the compile
9019 unit (not the type unit), so we want to use the offset of
9020 the skeleton DIE (if there is one). */
9021 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9023 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9025 if (type_node
!= NULL
)
9026 die_offset
= (type_node
->skeleton_die
!= NULL
9027 ? type_node
->skeleton_die
->die_offset
9031 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9033 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9037 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9040 /* Output the information that goes into the .debug_aranges table.
9041 Namely, define the beginning and ending address range of the
9042 text section generated for this compilation unit. */
9045 output_aranges (unsigned long aranges_length
)
9049 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9050 dw2_asm_output_data (4, 0xffffffff,
9051 "Initial length escape value indicating 64-bit DWARF extension");
9052 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9053 "Length of Address Ranges Info");
9054 /* Version number for aranges is still 2, even in DWARF3. */
9055 dw2_asm_output_data (2, 2, "DWARF Version");
9056 if (dwarf_split_debug_info
)
9057 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9058 debug_skeleton_info_section
,
9059 "Offset of Compilation Unit Info");
9061 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9063 "Offset of Compilation Unit Info");
9064 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9065 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9067 /* We need to align to twice the pointer size here. */
9068 if (DWARF_ARANGES_PAD_SIZE
)
9070 /* Pad using a 2 byte words so that padding is correct for any
9072 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9073 2 * DWARF2_ADDR_SIZE
);
9074 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9075 dw2_asm_output_data (2, 0, NULL
);
9078 /* It is necessary not to output these entries if the sections were
9079 not used; if the sections were not used, the length will be 0 and
9080 the address may end up as 0 if the section is discarded by ld
9081 --gc-sections, leaving an invalid (0, 0) entry that can be
9082 confused with the terminator. */
9083 if (text_section_used
)
9085 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9086 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9087 text_section_label
, "Length");
9089 if (cold_text_section_used
)
9091 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9093 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9094 cold_text_section_label
, "Length");
9097 if (have_multiple_function_sections
)
9102 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9104 if (DECL_IGNORED_P (fde
->decl
))
9106 if (!fde
->in_std_section
)
9108 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9110 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9111 fde
->dw_fde_begin
, "Length");
9113 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9115 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9117 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9118 fde
->dw_fde_second_begin
, "Length");
9123 /* Output the terminator words. */
9124 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9125 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9128 /* Add a new entry to .debug_ranges. Return the offset at which it
9132 add_ranges_num (int num
)
9134 unsigned int in_use
= ranges_table_in_use
;
9136 if (in_use
== ranges_table_allocated
)
9138 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9139 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9140 ranges_table_allocated
);
9141 memset (ranges_table
+ ranges_table_in_use
, 0,
9142 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9145 ranges_table
[in_use
].num
= num
;
9146 ranges_table_in_use
= in_use
+ 1;
9148 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9151 /* Add a new entry to .debug_ranges corresponding to a block, or a
9152 range terminator if BLOCK is NULL. */
9155 add_ranges (const_tree block
)
9157 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9160 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9161 When using dwarf_split_debug_info, address attributes in dies destined
9162 for the final executable should be direct references--setting the
9163 parameter force_direct ensures this behavior. */
9166 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9167 bool *added
, bool force_direct
)
9169 unsigned int in_use
= ranges_by_label_in_use
;
9170 unsigned int offset
;
9172 if (in_use
== ranges_by_label_allocated
)
9174 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9175 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9177 ranges_by_label_allocated
);
9178 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9179 RANGES_TABLE_INCREMENT
9180 * sizeof (struct dw_ranges_by_label_struct
));
9183 ranges_by_label
[in_use
].begin
= begin
;
9184 ranges_by_label
[in_use
].end
= end
;
9185 ranges_by_label_in_use
= in_use
+ 1;
9187 offset
= add_ranges_num (-(int)in_use
- 1);
9190 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9196 output_ranges (void)
9199 static const char *const start_fmt
= "Offset %#x";
9200 const char *fmt
= start_fmt
;
9202 for (i
= 0; i
< ranges_table_in_use
; i
++)
9204 int block_num
= ranges_table
[i
].num
;
9208 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9209 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9211 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9212 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9214 /* If all code is in the text section, then the compilation
9215 unit base address defaults to DW_AT_low_pc, which is the
9216 base of the text section. */
9217 if (!have_multiple_function_sections
)
9219 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9221 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9222 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9223 text_section_label
, NULL
);
9226 /* Otherwise, the compilation unit base address is zero,
9227 which allows us to use absolute addresses, and not worry
9228 about whether the target supports cross-section
9232 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9233 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9234 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9240 /* Negative block_num stands for an index into ranges_by_label. */
9241 else if (block_num
< 0)
9243 int lab_idx
= - block_num
- 1;
9245 if (!have_multiple_function_sections
)
9249 /* If we ever use add_ranges_by_labels () for a single
9250 function section, all we have to do is to take out
9252 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9253 ranges_by_label
[lab_idx
].begin
,
9255 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9256 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9257 ranges_by_label
[lab_idx
].end
,
9258 text_section_label
, NULL
);
9263 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9264 ranges_by_label
[lab_idx
].begin
,
9265 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9266 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9267 ranges_by_label
[lab_idx
].end
,
9273 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9274 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9280 /* Data structure containing information about input files. */
9283 const char *path
; /* Complete file name. */
9284 const char *fname
; /* File name part. */
9285 int length
; /* Length of entire string. */
9286 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9287 int dir_idx
; /* Index in directory table. */
9290 /* Data structure containing information about directories with source
9294 const char *path
; /* Path including directory name. */
9295 int length
; /* Path length. */
9296 int prefix
; /* Index of directory entry which is a prefix. */
9297 int count
; /* Number of files in this directory. */
9298 int dir_idx
; /* Index of directory used as base. */
9301 /* Callback function for file_info comparison. We sort by looking at
9302 the directories in the path. */
9305 file_info_cmp (const void *p1
, const void *p2
)
9307 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9308 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9309 const unsigned char *cp1
;
9310 const unsigned char *cp2
;
9312 /* Take care of file names without directories. We need to make sure that
9313 we return consistent values to qsort since some will get confused if
9314 we return the same value when identical operands are passed in opposite
9315 orders. So if neither has a directory, return 0 and otherwise return
9316 1 or -1 depending on which one has the directory. */
9317 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9318 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9320 cp1
= (const unsigned char *) s1
->path
;
9321 cp2
= (const unsigned char *) s2
->path
;
9327 /* Reached the end of the first path? If so, handle like above. */
9328 if ((cp1
== (const unsigned char *) s1
->fname
)
9329 || (cp2
== (const unsigned char *) s2
->fname
))
9330 return ((cp2
== (const unsigned char *) s2
->fname
)
9331 - (cp1
== (const unsigned char *) s1
->fname
));
9333 /* Character of current path component the same? */
9334 else if (*cp1
!= *cp2
)
9339 struct file_name_acquire_data
9341 struct file_info
*files
;
9346 /* Traversal function for the hash table. */
9349 file_name_acquire (void ** slot
, void *data
)
9351 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9352 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9353 struct file_info
*fi
;
9356 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9358 if (! d
->emitted_number
)
9361 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9363 fi
= fnad
->files
+ fnad
->used_files
++;
9365 /* Skip all leading "./". */
9367 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9370 /* Create a new array entry. */
9372 fi
->length
= strlen (f
);
9375 /* Search for the file name part. */
9376 f
= strrchr (f
, DIR_SEPARATOR
);
9377 #if defined (DIR_SEPARATOR_2)
9379 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9383 if (f
== NULL
|| f
< g
)
9389 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9393 /* Output the directory table and the file name table. We try to minimize
9394 the total amount of memory needed. A heuristic is used to avoid large
9395 slowdowns with many input files. */
9398 output_file_names (void)
9400 struct file_name_acquire_data fnad
;
9402 struct file_info
*files
;
9403 struct dir_info
*dirs
;
9411 if (!last_emitted_file
)
9413 dw2_asm_output_data (1, 0, "End directory table");
9414 dw2_asm_output_data (1, 0, "End file name table");
9418 numfiles
= last_emitted_file
->emitted_number
;
9420 /* Allocate the various arrays we need. */
9421 files
= XALLOCAVEC (struct file_info
, numfiles
);
9422 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9425 fnad
.used_files
= 0;
9426 fnad
.max_files
= numfiles
;
9427 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9428 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9430 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9432 /* Find all the different directories used. */
9433 dirs
[0].path
= files
[0].path
;
9434 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9435 dirs
[0].prefix
= -1;
9437 dirs
[0].dir_idx
= 0;
9438 files
[0].dir_idx
= 0;
9441 for (i
= 1; i
< numfiles
; i
++)
9442 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9443 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9444 dirs
[ndirs
- 1].length
) == 0)
9446 /* Same directory as last entry. */
9447 files
[i
].dir_idx
= ndirs
- 1;
9448 ++dirs
[ndirs
- 1].count
;
9454 /* This is a new directory. */
9455 dirs
[ndirs
].path
= files
[i
].path
;
9456 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9457 dirs
[ndirs
].count
= 1;
9458 dirs
[ndirs
].dir_idx
= ndirs
;
9459 files
[i
].dir_idx
= ndirs
;
9461 /* Search for a prefix. */
9462 dirs
[ndirs
].prefix
= -1;
9463 for (j
= 0; j
< ndirs
; j
++)
9464 if (dirs
[j
].length
< dirs
[ndirs
].length
9465 && dirs
[j
].length
> 1
9466 && (dirs
[ndirs
].prefix
== -1
9467 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9468 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9469 dirs
[ndirs
].prefix
= j
;
9474 /* Now to the actual work. We have to find a subset of the directories which
9475 allow expressing the file name using references to the directory table
9476 with the least amount of characters. We do not do an exhaustive search
9477 where we would have to check out every combination of every single
9478 possible prefix. Instead we use a heuristic which provides nearly optimal
9479 results in most cases and never is much off. */
9480 saved
= XALLOCAVEC (int, ndirs
);
9481 savehere
= XALLOCAVEC (int, ndirs
);
9483 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9484 for (i
= 0; i
< ndirs
; i
++)
9489 /* We can always save some space for the current directory. But this
9490 does not mean it will be enough to justify adding the directory. */
9491 savehere
[i
] = dirs
[i
].length
;
9492 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9494 for (j
= i
+ 1; j
< ndirs
; j
++)
9497 if (saved
[j
] < dirs
[i
].length
)
9499 /* Determine whether the dirs[i] path is a prefix of the
9504 while (k
!= -1 && k
!= (int) i
)
9509 /* Yes it is. We can possibly save some memory by
9510 writing the filenames in dirs[j] relative to
9512 savehere
[j
] = dirs
[i
].length
;
9513 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9518 /* Check whether we can save enough to justify adding the dirs[i]
9520 if (total
> dirs
[i
].length
+ 1)
9522 /* It's worthwhile adding. */
9523 for (j
= i
; j
< ndirs
; j
++)
9524 if (savehere
[j
] > 0)
9526 /* Remember how much we saved for this directory so far. */
9527 saved
[j
] = savehere
[j
];
9529 /* Remember the prefix directory. */
9530 dirs
[j
].dir_idx
= i
;
9535 /* Emit the directory name table. */
9536 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9537 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9538 dw2_asm_output_nstring (dirs
[i
].path
,
9540 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9541 "Directory Entry: %#x", i
+ idx_offset
);
9543 dw2_asm_output_data (1, 0, "End directory table");
9545 /* We have to emit them in the order of emitted_number since that's
9546 used in the debug info generation. To do this efficiently we
9547 generate a back-mapping of the indices first. */
9548 backmap
= XALLOCAVEC (int, numfiles
);
9549 for (i
= 0; i
< numfiles
; i
++)
9550 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9552 /* Now write all the file names. */
9553 for (i
= 0; i
< numfiles
; i
++)
9555 int file_idx
= backmap
[i
];
9556 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9558 #ifdef VMS_DEBUGGING_INFO
9559 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9561 /* Setting these fields can lead to debugger miscomparisons,
9562 but VMS Debug requires them to be set correctly. */
9567 int maxfilelen
= strlen (files
[file_idx
].path
)
9568 + dirs
[dir_idx
].length
9569 + MAX_VMS_VERSION_LEN
+ 1;
9570 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9572 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9573 snprintf (filebuf
, maxfilelen
, "%s;%d",
9574 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9576 dw2_asm_output_nstring
9577 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9579 /* Include directory index. */
9580 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9582 /* Modification time. */
9583 dw2_asm_output_data_uleb128
9584 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9588 /* File length in bytes. */
9589 dw2_asm_output_data_uleb128
9590 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9594 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9595 "File Entry: %#x", (unsigned) i
+ 1);
9597 /* Include directory index. */
9598 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9600 /* Modification time. */
9601 dw2_asm_output_data_uleb128 (0, NULL
);
9603 /* File length in bytes. */
9604 dw2_asm_output_data_uleb128 (0, NULL
);
9605 #endif /* VMS_DEBUGGING_INFO */
9608 dw2_asm_output_data (1, 0, "End file name table");
9612 /* Output one line number table into the .debug_line section. */
9615 output_one_line_info_table (dw_line_info_table
*table
)
9617 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9618 unsigned int current_line
= 1;
9619 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9620 dw_line_info_entry
*ent
;
9623 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9625 switch (ent
->opcode
)
9627 case LI_set_address
:
9628 /* ??? Unfortunately, we have little choice here currently, and
9629 must always use the most general form. GCC does not know the
9630 address delta itself, so we can't use DW_LNS_advance_pc. Many
9631 ports do have length attributes which will give an upper bound
9632 on the address range. We could perhaps use length attributes
9633 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9634 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9636 /* This can handle any delta. This takes
9637 4+DWARF2_ADDR_SIZE bytes. */
9638 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9639 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9640 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9641 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9645 if (ent
->val
== current_line
)
9647 /* We still need to start a new row, so output a copy insn. */
9648 dw2_asm_output_data (1, DW_LNS_copy
,
9649 "copy line %u", current_line
);
9653 int line_offset
= ent
->val
- current_line
;
9654 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9656 current_line
= ent
->val
;
9657 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9659 /* This can handle deltas from -10 to 234, using the current
9660 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9661 This takes 1 byte. */
9662 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9663 "line %u", current_line
);
9667 /* This can handle any delta. This takes at least 4 bytes,
9668 depending on the value being encoded. */
9669 dw2_asm_output_data (1, DW_LNS_advance_line
,
9670 "advance to line %u", current_line
);
9671 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9672 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9678 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9679 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9683 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9684 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9687 case LI_negate_stmt
:
9688 current_is_stmt
= !current_is_stmt
;
9689 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9690 "is_stmt %d", current_is_stmt
);
9693 case LI_set_prologue_end
:
9694 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9695 "set prologue end");
9698 case LI_set_epilogue_begin
:
9699 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9700 "set epilogue begin");
9703 case LI_set_discriminator
:
9704 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9705 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9706 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9707 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9712 /* Emit debug info for the address of the end of the table. */
9713 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9714 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9715 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9716 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9718 dw2_asm_output_data (1, 0, "end sequence");
9719 dw2_asm_output_data_uleb128 (1, NULL
);
9720 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9723 /* Output the source line number correspondence information. This
9724 information goes into the .debug_line section. */
9727 output_line_info (bool prologue_only
)
9729 char l1
[20], l2
[20], p1
[20], p2
[20];
9730 int ver
= dwarf_version
;
9731 bool saw_one
= false;
9734 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9735 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9736 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9737 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9739 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9740 dw2_asm_output_data (4, 0xffffffff,
9741 "Initial length escape value indicating 64-bit DWARF extension");
9742 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9743 "Length of Source Line Info");
9744 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9746 dw2_asm_output_data (2, ver
, "DWARF Version");
9747 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9748 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9750 /* Define the architecture-dependent minimum instruction length (in bytes).
9751 In this implementation of DWARF, this field is used for information
9752 purposes only. Since GCC generates assembly language, we have no
9753 a priori knowledge of how many instruction bytes are generated for each
9754 source line, and therefore can use only the DW_LNE_set_address and
9755 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9756 this as '1', which is "correct enough" for all architectures,
9757 and don't let the target override. */
9758 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9761 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9762 "Maximum Operations Per Instruction");
9763 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9764 "Default is_stmt_start flag");
9765 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9766 "Line Base Value (Special Opcodes)");
9767 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9768 "Line Range Value (Special Opcodes)");
9769 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9770 "Special Opcode Base");
9772 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9777 case DW_LNS_advance_pc
:
9778 case DW_LNS_advance_line
:
9779 case DW_LNS_set_file
:
9780 case DW_LNS_set_column
:
9781 case DW_LNS_fixed_advance_pc
:
9782 case DW_LNS_set_isa
:
9790 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9794 /* Write out the information about the files we use. */
9795 output_file_names ();
9796 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9799 /* Output the marker for the end of the line number info. */
9800 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9804 if (separate_line_info
)
9806 dw_line_info_table
*table
;
9809 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9812 output_one_line_info_table (table
);
9816 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9818 output_one_line_info_table (cold_text_section_line_info
);
9822 /* ??? Some Darwin linkers crash on a .debug_line section with no
9823 sequences. Further, merely a DW_LNE_end_sequence entry is not
9824 sufficient -- the address column must also be initialized.
9825 Make sure to output at least one set_address/end_sequence pair,
9826 choosing .text since that section is always present. */
9827 if (text_section_line_info
->in_use
|| !saw_one
)
9828 output_one_line_info_table (text_section_line_info
);
9830 /* Output the marker for the end of the line number info. */
9831 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9834 /* Given a pointer to a tree node for some base type, return a pointer to
9835 a DIE that describes the given type.
9837 This routine must only be called for GCC type nodes that correspond to
9838 Dwarf base (fundamental) types. */
9841 base_type_die (tree type
)
9843 dw_die_ref base_type_result
;
9844 enum dwarf_type encoding
;
9846 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9849 /* If this is a subtype that should not be emitted as a subrange type,
9850 use the base type. See subrange_type_for_debug_p. */
9851 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9852 type
= TREE_TYPE (type
);
9854 switch (TREE_CODE (type
))
9857 if ((dwarf_version
>= 4 || !dwarf_strict
)
9859 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9860 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9861 && DECL_NAME (TYPE_NAME (type
)))
9863 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9864 if (strcmp (name
, "char16_t") == 0
9865 || strcmp (name
, "char32_t") == 0)
9867 encoding
= DW_ATE_UTF
;
9871 if (TYPE_STRING_FLAG (type
))
9873 if (TYPE_UNSIGNED (type
))
9874 encoding
= DW_ATE_unsigned_char
;
9876 encoding
= DW_ATE_signed_char
;
9878 else if (TYPE_UNSIGNED (type
))
9879 encoding
= DW_ATE_unsigned
;
9881 encoding
= DW_ATE_signed
;
9885 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9887 if (dwarf_version
>= 3 || !dwarf_strict
)
9888 encoding
= DW_ATE_decimal_float
;
9890 encoding
= DW_ATE_lo_user
;
9893 encoding
= DW_ATE_float
;
9896 case FIXED_POINT_TYPE
:
9897 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9898 encoding
= DW_ATE_lo_user
;
9899 else if (TYPE_UNSIGNED (type
))
9900 encoding
= DW_ATE_unsigned_fixed
;
9902 encoding
= DW_ATE_signed_fixed
;
9905 /* Dwarf2 doesn't know anything about complex ints, so use
9906 a user defined type for it. */
9908 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9909 encoding
= DW_ATE_complex_float
;
9911 encoding
= DW_ATE_lo_user
;
9915 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9916 encoding
= DW_ATE_boolean
;
9920 /* No other TREE_CODEs are Dwarf fundamental types. */
9924 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9926 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9927 int_size_in_bytes (type
));
9928 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9929 add_pubtype (type
, base_type_result
);
9931 return base_type_result
;
9934 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9935 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9938 is_base_type (tree type
)
9940 switch (TREE_CODE (type
))
9946 case FIXED_POINT_TYPE
:
9954 case QUAL_UNION_TYPE
:
9959 case REFERENCE_TYPE
:
9973 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9974 node, return the size in bits for the type if it is a constant, or else
9975 return the alignment for the type if the type's size is not constant, or
9976 else return BITS_PER_WORD if the type actually turns out to be an
9979 static inline unsigned HOST_WIDE_INT
9980 simple_type_size_in_bits (const_tree type
)
9982 if (TREE_CODE (type
) == ERROR_MARK
)
9983 return BITS_PER_WORD
;
9984 else if (TYPE_SIZE (type
) == NULL_TREE
)
9986 else if (host_integerp (TYPE_SIZE (type
), 1))
9987 return tree_low_cst (TYPE_SIZE (type
), 1);
9989 return TYPE_ALIGN (type
);
9992 /* Similarly, but return a double_int instead of UHWI. */
9994 static inline double_int
9995 double_int_type_size_in_bits (const_tree type
)
9997 if (TREE_CODE (type
) == ERROR_MARK
)
9998 return double_int::from_uhwi (BITS_PER_WORD
);
9999 else if (TYPE_SIZE (type
) == NULL_TREE
)
10000 return double_int_zero
;
10001 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10002 return tree_to_double_int (TYPE_SIZE (type
));
10004 return double_int::from_uhwi (TYPE_ALIGN (type
));
10007 /* Given a pointer to a tree node for a subrange type, return a pointer
10008 to a DIE that describes the given type. */
10011 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10013 dw_die_ref subrange_die
;
10014 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10016 if (context_die
== NULL
)
10017 context_die
= comp_unit_die ();
10019 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10021 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10023 /* The size of the subrange type and its base type do not match,
10024 so we need to generate a size attribute for the subrange type. */
10025 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10029 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10031 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10033 return subrange_die
;
10036 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10037 entry that chains various modifiers in front of the given type. */
10040 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10041 dw_die_ref context_die
)
10043 enum tree_code code
= TREE_CODE (type
);
10044 dw_die_ref mod_type_die
;
10045 dw_die_ref sub_die
= NULL
;
10046 tree item_type
= NULL
;
10047 tree qualified_type
;
10048 tree name
, low
, high
;
10049 dw_die_ref mod_scope
;
10051 if (code
== ERROR_MARK
)
10054 /* See if we already have the appropriately qualified variant of
10057 = get_qualified_type (type
,
10058 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10059 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10061 if (qualified_type
== sizetype
10062 && TYPE_NAME (qualified_type
)
10063 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10065 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10067 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10068 && TYPE_PRECISION (t
)
10069 == TYPE_PRECISION (qualified_type
)
10070 && TYPE_UNSIGNED (t
)
10071 == TYPE_UNSIGNED (qualified_type
));
10072 qualified_type
= t
;
10075 /* If we do, then we can just use its DIE, if it exists. */
10076 if (qualified_type
)
10078 mod_type_die
= lookup_type_die (qualified_type
);
10080 return mod_type_die
;
10083 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10085 /* Handle C typedef types. */
10086 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10087 && !DECL_ARTIFICIAL (name
))
10089 tree dtype
= TREE_TYPE (name
);
10091 if (qualified_type
== dtype
)
10093 /* For a named type, use the typedef. */
10094 gen_type_die (qualified_type
, context_die
);
10095 return lookup_type_die (qualified_type
);
10097 else if (is_const_type
< TYPE_READONLY (dtype
)
10098 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10099 || (is_const_type
<= TYPE_READONLY (dtype
)
10100 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10101 && DECL_ORIGINAL_TYPE (name
) != type
))
10102 /* cv-unqualified version of named type. Just use the unnamed
10103 type to which it refers. */
10104 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10105 is_const_type
, is_volatile_type
,
10107 /* Else cv-qualified version of named type; fall through. */
10110 mod_scope
= scope_die_for (type
, context_die
);
10113 /* If both is_const_type and is_volatile_type, prefer the path
10114 which leads to a qualified type. */
10115 && (!is_volatile_type
10116 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10117 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10119 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10120 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10122 else if (is_volatile_type
)
10124 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10125 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10127 else if (code
== POINTER_TYPE
)
10129 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10130 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10131 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10132 item_type
= TREE_TYPE (type
);
10133 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10134 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10135 TYPE_ADDR_SPACE (item_type
));
10137 else if (code
== REFERENCE_TYPE
)
10139 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10140 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10143 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10144 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10145 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10146 item_type
= TREE_TYPE (type
);
10147 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10148 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10149 TYPE_ADDR_SPACE (item_type
));
10151 else if (code
== INTEGER_TYPE
10152 && TREE_TYPE (type
) != NULL_TREE
10153 && subrange_type_for_debug_p (type
, &low
, &high
))
10155 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10156 item_type
= TREE_TYPE (type
);
10158 else if (is_base_type (type
))
10159 mod_type_die
= base_type_die (type
);
10162 gen_type_die (type
, context_die
);
10164 /* We have to get the type_main_variant here (and pass that to the
10165 `lookup_type_die' routine) because the ..._TYPE node we have
10166 might simply be a *copy* of some original type node (where the
10167 copy was created to help us keep track of typedef names) and
10168 that copy might have a different TYPE_UID from the original
10170 if (TREE_CODE (type
) != VECTOR_TYPE
)
10171 return lookup_type_die (type_main_variant (type
));
10173 /* Vectors have the debugging information in the type,
10174 not the main variant. */
10175 return lookup_type_die (type
);
10178 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10179 don't output a DW_TAG_typedef, since there isn't one in the
10180 user's program; just attach a DW_AT_name to the type.
10181 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10182 if the base type already has the same name. */
10184 && ((TREE_CODE (name
) != TYPE_DECL
10185 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10186 || (!is_const_type
&& !is_volatile_type
)))
10187 || (TREE_CODE (name
) == TYPE_DECL
10188 && TREE_TYPE (name
) == qualified_type
10189 && DECL_NAME (name
))))
10191 if (TREE_CODE (name
) == TYPE_DECL
)
10192 /* Could just call add_name_and_src_coords_attributes here,
10193 but since this is a builtin type it doesn't have any
10194 useful source coordinates anyway. */
10195 name
= DECL_NAME (name
);
10196 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10198 /* This probably indicates a bug. */
10199 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10201 name
= TYPE_NAME (type
);
10203 && TREE_CODE (name
) == TYPE_DECL
)
10204 name
= DECL_NAME (name
);
10205 add_name_attribute (mod_type_die
,
10206 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10209 if (qualified_type
)
10210 equate_type_number_to_die (qualified_type
, mod_type_die
);
10213 /* We must do this after the equate_type_number_to_die call, in case
10214 this is a recursive type. This ensures that the modified_type_die
10215 recursion will terminate even if the type is recursive. Recursive
10216 types are possible in Ada. */
10217 sub_die
= modified_type_die (item_type
,
10218 TYPE_READONLY (item_type
),
10219 TYPE_VOLATILE (item_type
),
10222 if (sub_die
!= NULL
)
10223 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10225 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10226 if (TYPE_ARTIFICIAL (type
))
10227 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10229 return mod_type_die
;
10232 /* Generate DIEs for the generic parameters of T.
10233 T must be either a generic type or a generic function.
10234 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10237 gen_generic_params_dies (tree t
)
10241 dw_die_ref die
= NULL
;
10243 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10247 die
= lookup_type_die (t
);
10248 else if (DECL_P (t
))
10249 die
= lookup_decl_die (t
);
10253 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10255 /* T has no generic parameter. It means T is neither a generic type
10256 or function. End of story. */
10259 parms_num
= TREE_VEC_LENGTH (parms
);
10260 args
= lang_hooks
.get_innermost_generic_args (t
);
10261 for (i
= 0; i
< parms_num
; i
++)
10263 tree parm
, arg
, arg_pack_elems
;
10265 parm
= TREE_VEC_ELT (parms
, i
);
10266 arg
= TREE_VEC_ELT (args
, i
);
10267 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10268 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10270 if (parm
&& TREE_VALUE (parm
) && arg
)
10272 /* If PARM represents a template parameter pack,
10273 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10274 by DW_TAG_template_*_parameter DIEs for the argument
10275 pack elements of ARG. Note that ARG would then be
10276 an argument pack. */
10277 if (arg_pack_elems
)
10278 template_parameter_pack_die (TREE_VALUE (parm
),
10282 generic_parameter_die (TREE_VALUE (parm
), arg
,
10283 true /* Emit DW_AT_name */, die
);
10288 /* Create and return a DIE for PARM which should be
10289 the representation of a generic type parameter.
10290 For instance, in the C++ front end, PARM would be a template parameter.
10291 ARG is the argument to PARM.
10292 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10294 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10295 as a child node. */
10298 generic_parameter_die (tree parm
, tree arg
,
10300 dw_die_ref parent_die
)
10302 dw_die_ref tmpl_die
= NULL
;
10303 const char *name
= NULL
;
10305 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10308 /* We support non-type generic parameters and arguments,
10309 type generic parameters and arguments, as well as
10310 generic generic parameters (a.k.a. template template parameters in C++)
10312 if (TREE_CODE (parm
) == PARM_DECL
)
10313 /* PARM is a nontype generic parameter */
10314 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10315 else if (TREE_CODE (parm
) == TYPE_DECL
)
10316 /* PARM is a type generic parameter. */
10317 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10318 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10319 /* PARM is a generic generic parameter.
10320 Its DIE is a GNU extension. It shall have a
10321 DW_AT_name attribute to represent the name of the template template
10322 parameter, and a DW_AT_GNU_template_name attribute to represent the
10323 name of the template template argument. */
10324 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10327 gcc_unreachable ();
10333 /* If PARM is a generic parameter pack, it means we are
10334 emitting debug info for a template argument pack element.
10335 In other terms, ARG is a template argument pack element.
10336 In that case, we don't emit any DW_AT_name attribute for
10340 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10342 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10345 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10347 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10348 TMPL_DIE should have a child DW_AT_type attribute that is set
10349 to the type of the argument to PARM, which is ARG.
10350 If PARM is a type generic parameter, TMPL_DIE should have a
10351 child DW_AT_type that is set to ARG. */
10352 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10353 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10354 TREE_THIS_VOLATILE (tmpl_type
),
10359 /* So TMPL_DIE is a DIE representing a
10360 a generic generic template parameter, a.k.a template template
10361 parameter in C++ and arg is a template. */
10363 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10364 to the name of the argument. */
10365 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10367 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10370 if (TREE_CODE (parm
) == PARM_DECL
)
10371 /* So PARM is a non-type generic parameter.
10372 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10373 attribute of TMPL_DIE which value represents the value
10375 We must be careful here:
10376 The value of ARG might reference some function decls.
10377 We might currently be emitting debug info for a generic
10378 type and types are emitted before function decls, we don't
10379 know if the function decls referenced by ARG will actually be
10380 emitted after cgraph computations.
10381 So must defer the generation of the DW_AT_const_value to
10382 after cgraph is ready. */
10383 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10389 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10390 PARM_PACK must be a template parameter pack. The returned DIE
10391 will be child DIE of PARENT_DIE. */
10394 template_parameter_pack_die (tree parm_pack
,
10395 tree parm_pack_args
,
10396 dw_die_ref parent_die
)
10401 gcc_assert (parent_die
&& parm_pack
);
10403 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10404 add_name_and_src_coords_attributes (die
, parm_pack
);
10405 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10406 generic_parameter_die (parm_pack
,
10407 TREE_VEC_ELT (parm_pack_args
, j
),
10408 false /* Don't emit DW_AT_name */,
10413 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10414 an enumerated type. */
10417 type_is_enum (const_tree type
)
10419 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10422 /* Return the DBX register number described by a given RTL node. */
10424 static unsigned int
10425 dbx_reg_number (const_rtx rtl
)
10427 unsigned regno
= REGNO (rtl
);
10429 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10431 #ifdef LEAF_REG_REMAP
10432 if (crtl
->uses_only_leaf_regs
)
10434 int leaf_reg
= LEAF_REG_REMAP (regno
);
10435 if (leaf_reg
!= -1)
10436 regno
= (unsigned) leaf_reg
;
10440 regno
= DBX_REGISTER_NUMBER (regno
);
10441 gcc_assert (regno
!= INVALID_REGNUM
);
10445 /* Optionally add a DW_OP_piece term to a location description expression.
10446 DW_OP_piece is only added if the location description expression already
10447 doesn't end with DW_OP_piece. */
10450 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10452 dw_loc_descr_ref loc
;
10454 if (*list_head
!= NULL
)
10456 /* Find the end of the chain. */
10457 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10460 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10461 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10465 /* Return a location descriptor that designates a machine register or
10466 zero if there is none. */
10468 static dw_loc_descr_ref
10469 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10473 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10476 /* We only use "frame base" when we're sure we're talking about the
10477 post-prologue local stack frame. We do this by *not* running
10478 register elimination until this point, and recognizing the special
10479 argument pointer and soft frame pointer rtx's.
10480 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10481 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10482 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10484 dw_loc_descr_ref result
= NULL
;
10486 if (dwarf_version
>= 4 || !dwarf_strict
)
10488 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10491 add_loc_descr (&result
,
10492 new_loc_descr (DW_OP_stack_value
, 0, 0));
10497 regs
= targetm
.dwarf_register_span (rtl
);
10499 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10500 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10502 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
10505 /* Return a location descriptor that designates a machine register for
10506 a given hard register number. */
10508 static dw_loc_descr_ref
10509 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10511 dw_loc_descr_ref reg_loc_descr
;
10515 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10517 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10519 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10520 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10522 return reg_loc_descr
;
10525 /* Given an RTL of a register, return a location descriptor that
10526 designates a value that spans more than one register. */
10528 static dw_loc_descr_ref
10529 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10530 enum var_init_status initialized
)
10532 int nregs
, size
, i
;
10534 dw_loc_descr_ref loc_result
= NULL
;
10537 #ifdef LEAF_REG_REMAP
10538 if (crtl
->uses_only_leaf_regs
)
10540 int leaf_reg
= LEAF_REG_REMAP (reg
);
10541 if (leaf_reg
!= -1)
10542 reg
= (unsigned) leaf_reg
;
10545 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10546 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10548 /* Simple, contiguous registers. */
10549 if (regs
== NULL_RTX
)
10551 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10556 dw_loc_descr_ref t
;
10558 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10559 VAR_INIT_STATUS_INITIALIZED
);
10560 add_loc_descr (&loc_result
, t
);
10561 add_loc_descr_op_piece (&loc_result
, size
);
10567 /* Now onto stupid register sets in non contiguous locations. */
10569 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10571 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10574 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10576 dw_loc_descr_ref t
;
10578 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10579 VAR_INIT_STATUS_INITIALIZED
);
10580 add_loc_descr (&loc_result
, t
);
10581 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10582 add_loc_descr_op_piece (&loc_result
, size
);
10585 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10586 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10590 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10592 /* Return a location descriptor that designates a constant i,
10593 as a compound operation from constant (i >> shift), constant shift
10596 static dw_loc_descr_ref
10597 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10599 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10600 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10601 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10605 /* Return a location descriptor that designates a constant. */
10607 static dw_loc_descr_ref
10608 int_loc_descriptor (HOST_WIDE_INT i
)
10610 enum dwarf_location_atom op
;
10612 /* Pick the smallest representation of a constant, rather than just
10613 defaulting to the LEB encoding. */
10616 int clz
= clz_hwi (i
);
10617 int ctz
= ctz_hwi (i
);
10619 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10620 else if (i
<= 0xff)
10621 op
= DW_OP_const1u
;
10622 else if (i
<= 0xffff)
10623 op
= DW_OP_const2u
;
10624 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10625 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10626 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10627 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10628 while DW_OP_const4u is 5 bytes. */
10629 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10630 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10631 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10632 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10633 while DW_OP_const4u is 5 bytes. */
10634 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10635 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10636 op
= DW_OP_const4u
;
10637 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10638 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10639 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10640 while DW_OP_constu of constant >= 0x100000000 takes at least
10642 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10643 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10644 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10645 >= HOST_BITS_PER_WIDE_INT
)
10646 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10647 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10648 while DW_OP_constu takes in this case at least 6 bytes. */
10649 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10650 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10651 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10652 && size_of_uleb128 (i
) > 6)
10653 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10654 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10661 op
= DW_OP_const1s
;
10662 else if (i
>= -0x8000)
10663 op
= DW_OP_const2s
;
10664 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10666 if (size_of_int_loc_descriptor (i
) < 5)
10668 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10669 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10672 op
= DW_OP_const4s
;
10676 if (size_of_int_loc_descriptor (i
)
10677 < (unsigned long) 1 + size_of_sleb128 (i
))
10679 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10680 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10687 return new_loc_descr (op
, i
, 0);
10690 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10691 without actually allocating it. */
10693 static unsigned long
10694 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10696 return size_of_int_loc_descriptor (i
>> shift
)
10697 + size_of_int_loc_descriptor (shift
)
10701 /* Return size_of_locs (int_loc_descriptor (i)) without
10702 actually allocating it. */
10704 static unsigned long
10705 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10714 else if (i
<= 0xff)
10716 else if (i
<= 0xffff)
10720 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10721 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10722 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10724 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10725 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10726 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10728 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10730 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10731 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10732 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10733 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10735 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10736 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10737 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10739 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10740 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10742 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10751 else if (i
>= -0x8000)
10753 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10755 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10757 s
= size_of_int_loc_descriptor (-i
) + 1;
10765 unsigned long r
= 1 + size_of_sleb128 (i
);
10766 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10768 s
= size_of_int_loc_descriptor (-i
) + 1;
10777 /* Return loc description representing "address" of integer value.
10778 This can appear only as toplevel expression. */
10780 static dw_loc_descr_ref
10781 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10784 dw_loc_descr_ref loc_result
= NULL
;
10786 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10789 litsize
= size_of_int_loc_descriptor (i
);
10790 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10791 is more compact. For DW_OP_stack_value we need:
10792 litsize + 1 (DW_OP_stack_value)
10793 and for DW_OP_implicit_value:
10794 1 (DW_OP_implicit_value) + 1 (length) + size. */
10795 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10797 loc_result
= int_loc_descriptor (i
);
10798 add_loc_descr (&loc_result
,
10799 new_loc_descr (DW_OP_stack_value
, 0, 0));
10803 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10805 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10806 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10810 /* Return a location descriptor that designates a base+offset location. */
10812 static dw_loc_descr_ref
10813 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10814 enum var_init_status initialized
)
10816 unsigned int regno
;
10817 dw_loc_descr_ref result
;
10818 dw_fde_ref fde
= cfun
->fde
;
10820 /* We only use "frame base" when we're sure we're talking about the
10821 post-prologue local stack frame. We do this by *not* running
10822 register elimination until this point, and recognizing the special
10823 argument pointer and soft frame pointer rtx's. */
10824 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10826 rtx elim
= (ira_use_lra_p
10827 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10828 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10832 if (GET_CODE (elim
) == PLUS
)
10834 offset
+= INTVAL (XEXP (elim
, 1));
10835 elim
= XEXP (elim
, 0);
10837 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10838 && (elim
== hard_frame_pointer_rtx
10839 || elim
== stack_pointer_rtx
))
10840 || elim
== (frame_pointer_needed
10841 ? hard_frame_pointer_rtx
10842 : stack_pointer_rtx
));
10844 /* If drap register is used to align stack, use frame
10845 pointer + offset to access stack variables. If stack
10846 is aligned without drap, use stack pointer + offset to
10847 access stack variables. */
10848 if (crtl
->stack_realign_tried
10849 && reg
== frame_pointer_rtx
)
10852 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10853 ? HARD_FRAME_POINTER_REGNUM
10855 return new_reg_loc_descr (base_reg
, offset
);
10858 gcc_assert (frame_pointer_fb_offset_valid
);
10859 offset
+= frame_pointer_fb_offset
;
10860 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10864 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10866 if (!optimize
&& fde
10867 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10869 /* Use cfa+offset to represent the location of arguments passed
10870 on the stack when drap is used to align stack.
10871 Only do this when not optimizing, for optimized code var-tracking
10872 is supposed to track where the arguments live and the register
10873 used as vdrap or drap in some spot might be used for something
10874 else in other part of the routine. */
10875 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10879 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10882 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10884 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10885 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10890 /* Return true if this RTL expression describes a base+offset calculation. */
10893 is_based_loc (const_rtx rtl
)
10895 return (GET_CODE (rtl
) == PLUS
10896 && ((REG_P (XEXP (rtl
, 0))
10897 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10898 && CONST_INT_P (XEXP (rtl
, 1)))));
10901 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10904 static dw_loc_descr_ref
10905 tls_mem_loc_descriptor (rtx mem
)
10908 dw_loc_descr_ref loc_result
;
10910 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10913 base
= get_base_address (MEM_EXPR (mem
));
10915 || TREE_CODE (base
) != VAR_DECL
10916 || !DECL_THREAD_LOCAL_P (base
))
10919 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10920 if (loc_result
== NULL
)
10923 if (MEM_OFFSET (mem
))
10924 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10929 /* Output debug info about reason why we failed to expand expression as dwarf
10933 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10935 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10937 fprintf (dump_file
, "Failed to expand as dwarf: ");
10939 print_generic_expr (dump_file
, expr
, dump_flags
);
10942 fprintf (dump_file
, "\n");
10943 print_rtl (dump_file
, rtl
);
10945 fprintf (dump_file
, "\nReason: %s\n", reason
);
10949 /* Helper function for const_ok_for_output, called either directly
10950 or via for_each_rtx. */
10953 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10957 if (GET_CODE (rtl
) == UNSPEC
)
10959 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10960 we can't express it in the debug info. */
10961 #ifdef ENABLE_CHECKING
10962 /* Don't complain about TLS UNSPECs, those are just too hard to
10963 delegitimize. Note this could be a non-decl SYMBOL_REF such as
10964 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
10965 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
10966 if (XVECLEN (rtl
, 0) == 0
10967 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10968 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
10969 inform (current_function_decl
10970 ? DECL_SOURCE_LOCATION (current_function_decl
)
10971 : UNKNOWN_LOCATION
,
10972 #if NUM_UNSPEC_VALUES > 0
10973 "non-delegitimized UNSPEC %s (%d) found in variable location",
10974 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10975 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10978 "non-delegitimized UNSPEC %d found in variable location",
10982 expansion_failed (NULL_TREE
, rtl
,
10983 "UNSPEC hasn't been delegitimized.\n");
10987 if (targetm
.const_not_ok_for_debug_p (rtl
))
10989 expansion_failed (NULL_TREE
, rtl
,
10990 "Expression rejected for debug by the backend.\n");
10994 if (GET_CODE (rtl
) != SYMBOL_REF
)
10997 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11000 get_pool_constant_mark (rtl
, &marked
);
11001 /* If all references to this pool constant were optimized away,
11002 it was not output and thus we can't represent it. */
11005 expansion_failed (NULL_TREE
, rtl
,
11006 "Constant was removed from constant pool.\n");
11011 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11014 /* Avoid references to external symbols in debug info, on several targets
11015 the linker might even refuse to link when linking a shared library,
11016 and in many other cases the relocations for .debug_info/.debug_loc are
11017 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11018 to be defined within the same shared library or executable are fine. */
11019 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11021 tree decl
= SYMBOL_REF_DECL (rtl
);
11023 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11025 expansion_failed (NULL_TREE
, rtl
,
11026 "Symbol not defined in current TU.\n");
11034 /* Return true if constant RTL can be emitted in DW_OP_addr or
11035 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11036 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11039 const_ok_for_output (rtx rtl
)
11041 if (GET_CODE (rtl
) == SYMBOL_REF
)
11042 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11044 if (GET_CODE (rtl
) == CONST
)
11045 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11050 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11051 if possible, NULL otherwise. */
11054 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11056 dw_die_ref type_die
;
11057 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11061 switch (TREE_CODE (type
))
11069 type_die
= lookup_type_die (type
);
11071 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11072 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11077 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11078 type matching MODE, or, if MODE is narrower than or as wide as
11079 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11082 static dw_loc_descr_ref
11083 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11085 enum machine_mode outer_mode
= mode
;
11086 dw_die_ref type_die
;
11087 dw_loc_descr_ref cvt
;
11089 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11091 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11094 type_die
= base_type_for_mode (outer_mode
, 1);
11095 if (type_die
== NULL
)
11097 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11098 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11099 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11100 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11101 add_loc_descr (&op
, cvt
);
11105 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11107 static dw_loc_descr_ref
11108 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11109 dw_loc_descr_ref op1
)
11111 dw_loc_descr_ref ret
= op0
;
11112 add_loc_descr (&ret
, op1
);
11113 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11114 if (STORE_FLAG_VALUE
!= 1)
11116 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11117 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11122 /* Return location descriptor for signed comparison OP RTL. */
11124 static dw_loc_descr_ref
11125 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11126 enum machine_mode mem_mode
)
11128 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11129 dw_loc_descr_ref op0
, op1
;
11132 if (op_mode
== VOIDmode
)
11133 op_mode
= GET_MODE (XEXP (rtl
, 1));
11134 if (op_mode
== VOIDmode
)
11138 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11139 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11142 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11143 VAR_INIT_STATUS_INITIALIZED
);
11144 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11145 VAR_INIT_STATUS_INITIALIZED
);
11147 if (op0
== NULL
|| op1
== NULL
)
11150 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11151 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11152 return compare_loc_descriptor (op
, op0
, op1
);
11154 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11156 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11157 dw_loc_descr_ref cvt
;
11159 if (type_die
== NULL
)
11161 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11162 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11163 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11164 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11165 add_loc_descr (&op0
, cvt
);
11166 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11167 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11168 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11169 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11170 add_loc_descr (&op1
, cvt
);
11171 return compare_loc_descriptor (op
, op0
, op1
);
11174 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11175 /* For eq/ne, if the operands are known to be zero-extended,
11176 there is no need to do the fancy shifting up. */
11177 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11179 dw_loc_descr_ref last0
, last1
;
11180 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11182 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11184 /* deref_size zero extends, and for constants we can check
11185 whether they are zero extended or not. */
11186 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11187 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11188 || (CONST_INT_P (XEXP (rtl
, 0))
11189 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11190 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11191 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11192 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11193 || (CONST_INT_P (XEXP (rtl
, 1))
11194 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11195 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11196 return compare_loc_descriptor (op
, op0
, op1
);
11198 /* EQ/NE comparison against constant in narrower type than
11199 DWARF2_ADDR_SIZE can be performed either as
11200 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11203 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11204 DW_OP_{eq,ne}. Pick whatever is shorter. */
11205 if (CONST_INT_P (XEXP (rtl
, 1))
11206 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11207 && (size_of_int_loc_descriptor (shift
) + 1
11208 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11209 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11210 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11211 & GET_MODE_MASK (op_mode
))))
11213 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11214 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11215 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11216 & GET_MODE_MASK (op_mode
));
11217 return compare_loc_descriptor (op
, op0
, op1
);
11220 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11221 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11222 if (CONST_INT_P (XEXP (rtl
, 1)))
11223 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11226 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11227 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11229 return compare_loc_descriptor (op
, op0
, op1
);
11232 /* Return location descriptor for unsigned comparison OP RTL. */
11234 static dw_loc_descr_ref
11235 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11236 enum machine_mode mem_mode
)
11238 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11239 dw_loc_descr_ref op0
, op1
;
11241 if (op_mode
== VOIDmode
)
11242 op_mode
= GET_MODE (XEXP (rtl
, 1));
11243 if (op_mode
== VOIDmode
)
11245 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11248 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11251 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11252 VAR_INIT_STATUS_INITIALIZED
);
11253 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11254 VAR_INIT_STATUS_INITIALIZED
);
11256 if (op0
== NULL
|| op1
== NULL
)
11259 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11261 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11262 dw_loc_descr_ref last0
, last1
;
11263 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11265 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11267 if (CONST_INT_P (XEXP (rtl
, 0)))
11268 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11269 /* deref_size zero extends, so no need to mask it again. */
11270 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11271 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11273 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11274 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11276 if (CONST_INT_P (XEXP (rtl
, 1)))
11277 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11278 /* deref_size zero extends, so no need to mask it again. */
11279 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11280 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11282 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11283 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11286 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11288 HOST_WIDE_INT bias
= 1;
11289 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11290 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11291 if (CONST_INT_P (XEXP (rtl
, 1)))
11292 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11293 + INTVAL (XEXP (rtl
, 1)));
11295 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11298 return compare_loc_descriptor (op
, op0
, op1
);
11301 /* Return location descriptor for {U,S}{MIN,MAX}. */
11303 static dw_loc_descr_ref
11304 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11305 enum machine_mode mem_mode
)
11307 enum dwarf_location_atom op
;
11308 dw_loc_descr_ref op0
, op1
, ret
;
11309 dw_loc_descr_ref bra_node
, drop_node
;
11312 && (GET_MODE_CLASS (mode
) != MODE_INT
11313 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11316 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11317 VAR_INIT_STATUS_INITIALIZED
);
11318 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11319 VAR_INIT_STATUS_INITIALIZED
);
11321 if (op0
== NULL
|| op1
== NULL
)
11324 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11325 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11326 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11327 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11329 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11331 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11332 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11333 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11334 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11335 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11337 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11339 HOST_WIDE_INT bias
= 1;
11340 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11341 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11342 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11345 else if (GET_MODE_CLASS (mode
) == MODE_INT
11346 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11348 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11349 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11350 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11351 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11352 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11354 else if (GET_MODE_CLASS (mode
) == MODE_INT
11355 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11357 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11358 dw_loc_descr_ref cvt
;
11359 if (type_die
== NULL
)
11361 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11362 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11363 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11364 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11365 add_loc_descr (&op0
, cvt
);
11366 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11367 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11368 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11369 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11370 add_loc_descr (&op1
, cvt
);
11373 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11378 add_loc_descr (&ret
, op1
);
11379 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11380 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11381 add_loc_descr (&ret
, bra_node
);
11382 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11383 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11384 add_loc_descr (&ret
, drop_node
);
11385 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11386 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11387 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11388 && GET_MODE_CLASS (mode
) == MODE_INT
11389 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11390 ret
= convert_descriptor_to_mode (mode
, ret
);
11394 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11395 but after converting arguments to type_die, afterwards
11396 convert back to unsigned. */
11398 static dw_loc_descr_ref
11399 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11400 enum machine_mode mode
, enum machine_mode mem_mode
)
11402 dw_loc_descr_ref cvt
, op0
, op1
;
11404 if (type_die
== NULL
)
11406 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11407 VAR_INIT_STATUS_INITIALIZED
);
11408 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11409 VAR_INIT_STATUS_INITIALIZED
);
11410 if (op0
== NULL
|| op1
== NULL
)
11412 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11413 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11414 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11415 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11416 add_loc_descr (&op0
, cvt
);
11417 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11418 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11419 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11420 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11421 add_loc_descr (&op1
, cvt
);
11422 add_loc_descr (&op0
, op1
);
11423 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11424 return convert_descriptor_to_mode (mode
, op0
);
11427 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11428 const0 is DW_OP_lit0 or corresponding typed constant,
11429 const1 is DW_OP_lit1 or corresponding typed constant
11430 and constMSB is constant with just the MSB bit set
11432 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11433 L1: const0 DW_OP_swap
11434 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11435 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11440 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11441 L1: const0 DW_OP_swap
11442 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11443 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11448 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11449 L1: const1 DW_OP_swap
11450 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11451 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11455 static dw_loc_descr_ref
11456 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11457 enum machine_mode mem_mode
)
11459 dw_loc_descr_ref op0
, ret
, tmp
;
11460 HOST_WIDE_INT valv
;
11461 dw_loc_descr_ref l1jump
, l1label
;
11462 dw_loc_descr_ref l2jump
, l2label
;
11463 dw_loc_descr_ref l3jump
, l3label
;
11464 dw_loc_descr_ref l4jump
, l4label
;
11467 if (GET_MODE_CLASS (mode
) != MODE_INT
11468 || GET_MODE (XEXP (rtl
, 0)) != mode
11469 || (GET_CODE (rtl
) == CLZ
11470 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11473 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11474 VAR_INIT_STATUS_INITIALIZED
);
11478 if (GET_CODE (rtl
) == CLZ
)
11480 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11481 valv
= GET_MODE_BITSIZE (mode
);
11483 else if (GET_CODE (rtl
) == FFS
)
11485 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11486 valv
= GET_MODE_BITSIZE (mode
);
11487 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11488 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11489 add_loc_descr (&ret
, l1jump
);
11490 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11491 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11492 VAR_INIT_STATUS_INITIALIZED
);
11495 add_loc_descr (&ret
, tmp
);
11496 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11497 add_loc_descr (&ret
, l4jump
);
11498 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11499 ? const1_rtx
: const0_rtx
,
11501 VAR_INIT_STATUS_INITIALIZED
);
11502 if (l1label
== NULL
)
11504 add_loc_descr (&ret
, l1label
);
11505 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11506 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11507 add_loc_descr (&ret
, l2label
);
11508 if (GET_CODE (rtl
) != CLZ
)
11510 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11511 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11512 << (GET_MODE_BITSIZE (mode
) - 1));
11514 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11515 << (GET_MODE_BITSIZE (mode
)
11516 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11517 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11518 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11519 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11520 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11522 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11523 VAR_INIT_STATUS_INITIALIZED
);
11526 add_loc_descr (&ret
, tmp
);
11527 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11528 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11529 add_loc_descr (&ret
, l3jump
);
11530 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11531 VAR_INIT_STATUS_INITIALIZED
);
11534 add_loc_descr (&ret
, tmp
);
11535 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11536 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11537 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11538 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11539 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11540 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11541 add_loc_descr (&ret
, l2jump
);
11542 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11543 add_loc_descr (&ret
, l3label
);
11544 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11545 add_loc_descr (&ret
, l4label
);
11546 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11547 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11548 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11549 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11550 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11551 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11552 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11553 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11557 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11558 const1 is DW_OP_lit1 or corresponding typed constant):
11560 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11561 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11565 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11566 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11569 static dw_loc_descr_ref
11570 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11571 enum machine_mode mem_mode
)
11573 dw_loc_descr_ref op0
, ret
, tmp
;
11574 dw_loc_descr_ref l1jump
, l1label
;
11575 dw_loc_descr_ref l2jump
, l2label
;
11577 if (GET_MODE_CLASS (mode
) != MODE_INT
11578 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11581 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11582 VAR_INIT_STATUS_INITIALIZED
);
11586 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11587 VAR_INIT_STATUS_INITIALIZED
);
11590 add_loc_descr (&ret
, tmp
);
11591 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11592 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11593 add_loc_descr (&ret
, l1label
);
11594 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11595 add_loc_descr (&ret
, l2jump
);
11596 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11597 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11598 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11599 VAR_INIT_STATUS_INITIALIZED
);
11602 add_loc_descr (&ret
, tmp
);
11603 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11604 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11605 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11606 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11607 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11608 VAR_INIT_STATUS_INITIALIZED
);
11609 add_loc_descr (&ret
, tmp
);
11610 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11611 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11612 add_loc_descr (&ret
, l1jump
);
11613 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11614 add_loc_descr (&ret
, l2label
);
11615 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11616 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11617 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11618 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11622 /* BSWAP (constS is initial shift count, either 56 or 24):
11624 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11625 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11626 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11627 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11628 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11630 static dw_loc_descr_ref
11631 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11632 enum machine_mode mem_mode
)
11634 dw_loc_descr_ref op0
, ret
, tmp
;
11635 dw_loc_descr_ref l1jump
, l1label
;
11636 dw_loc_descr_ref l2jump
, l2label
;
11638 if (GET_MODE_CLASS (mode
) != MODE_INT
11639 || BITS_PER_UNIT
!= 8
11640 || (GET_MODE_BITSIZE (mode
) != 32
11641 && GET_MODE_BITSIZE (mode
) != 64))
11644 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11645 VAR_INIT_STATUS_INITIALIZED
);
11650 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11652 VAR_INIT_STATUS_INITIALIZED
);
11655 add_loc_descr (&ret
, tmp
);
11656 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11657 VAR_INIT_STATUS_INITIALIZED
);
11660 add_loc_descr (&ret
, tmp
);
11661 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11662 add_loc_descr (&ret
, l1label
);
11663 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11665 VAR_INIT_STATUS_INITIALIZED
);
11666 add_loc_descr (&ret
, tmp
);
11667 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11668 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11669 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11670 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11671 VAR_INIT_STATUS_INITIALIZED
);
11674 add_loc_descr (&ret
, tmp
);
11675 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11676 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11677 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11678 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11679 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11680 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11681 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11682 VAR_INIT_STATUS_INITIALIZED
);
11683 add_loc_descr (&ret
, tmp
);
11684 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11685 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11686 add_loc_descr (&ret
, l2jump
);
11687 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11688 VAR_INIT_STATUS_INITIALIZED
);
11689 add_loc_descr (&ret
, tmp
);
11690 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11691 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11692 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11693 add_loc_descr (&ret
, l1jump
);
11694 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11695 add_loc_descr (&ret
, l2label
);
11696 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11697 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11698 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11699 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11700 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11701 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11705 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11706 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11707 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11708 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11710 ROTATERT is similar:
11711 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11712 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11713 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11715 static dw_loc_descr_ref
11716 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11717 enum machine_mode mem_mode
)
11719 rtx rtlop1
= XEXP (rtl
, 1);
11720 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11723 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11726 if (GET_MODE (rtlop1
) != VOIDmode
11727 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11728 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11729 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11730 VAR_INIT_STATUS_INITIALIZED
);
11731 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11732 VAR_INIT_STATUS_INITIALIZED
);
11733 if (op0
== NULL
|| op1
== NULL
)
11735 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11736 for (i
= 0; i
< 2; i
++)
11738 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11739 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11741 VAR_INIT_STATUS_INITIALIZED
);
11742 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11743 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11745 : HOST_BITS_PER_WIDE_INT
== 64
11746 ? DW_OP_const8u
: DW_OP_constu
,
11747 GET_MODE_MASK (mode
), 0);
11750 if (mask
[i
] == NULL
)
11752 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11755 add_loc_descr (&ret
, op1
);
11756 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11757 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11758 if (GET_CODE (rtl
) == ROTATERT
)
11760 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11761 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11762 GET_MODE_BITSIZE (mode
), 0));
11764 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11765 if (mask
[0] != NULL
)
11766 add_loc_descr (&ret
, mask
[0]);
11767 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11768 if (mask
[1] != NULL
)
11770 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11771 add_loc_descr (&ret
, mask
[1]);
11772 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11774 if (GET_CODE (rtl
) == ROTATE
)
11776 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11777 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11778 GET_MODE_BITSIZE (mode
), 0));
11780 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11781 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11785 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11786 for DEBUG_PARAMETER_REF RTL. */
11788 static dw_loc_descr_ref
11789 parameter_ref_descriptor (rtx rtl
)
11791 dw_loc_descr_ref ret
;
11796 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11797 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11798 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11801 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11802 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11803 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11807 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11808 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11813 /* The following routine converts the RTL for a variable or parameter
11814 (resident in memory) into an equivalent Dwarf representation of a
11815 mechanism for getting the address of that same variable onto the top of a
11816 hypothetical "address evaluation" stack.
11818 When creating memory location descriptors, we are effectively transforming
11819 the RTL for a memory-resident object into its Dwarf postfix expression
11820 equivalent. This routine recursively descends an RTL tree, turning
11821 it into Dwarf postfix code as it goes.
11823 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11825 MEM_MODE is the mode of the memory reference, needed to handle some
11826 autoincrement addressing modes.
11828 Return 0 if we can't represent the location. */
11831 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11832 enum machine_mode mem_mode
,
11833 enum var_init_status initialized
)
11835 dw_loc_descr_ref mem_loc_result
= NULL
;
11836 enum dwarf_location_atom op
;
11837 dw_loc_descr_ref op0
, op1
;
11839 if (mode
== VOIDmode
)
11840 mode
= GET_MODE (rtl
);
11842 /* Note that for a dynamically sized array, the location we will generate a
11843 description of here will be the lowest numbered location which is
11844 actually within the array. That's *not* necessarily the same as the
11845 zeroth element of the array. */
11847 rtl
= targetm
.delegitimize_address (rtl
);
11849 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11852 switch (GET_CODE (rtl
))
11857 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11860 /* The case of a subreg may arise when we have a local (register)
11861 variable or a formal (register) parameter which doesn't quite fill
11862 up an entire register. For now, just assume that it is
11863 legitimate to make the Dwarf info refer to the whole register which
11864 contains the given subreg. */
11865 if (!subreg_lowpart_p (rtl
))
11867 if (GET_MODE_CLASS (mode
) == MODE_INT
11868 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) == MODE_INT
11869 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11870 #ifdef POINTERS_EXTEND_UNSIGNED
11871 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11874 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))) <= DWARF2_ADDR_SIZE
)
11876 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11877 GET_MODE (SUBREG_REG (rtl
)),
11878 mem_mode
, initialized
);
11883 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11885 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
)))
11886 && (GET_MODE_CLASS (mode
) != MODE_INT
11887 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) != MODE_INT
))
11891 dw_die_ref type_die
;
11892 dw_loc_descr_ref cvt
;
11894 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11895 GET_MODE (SUBREG_REG (rtl
)),
11896 mem_mode
, initialized
);
11897 if (mem_loc_result
== NULL
)
11899 type_die
= base_type_for_mode (mode
,
11900 GET_MODE_CLASS (mode
) == MODE_INT
);
11901 if (type_die
== NULL
)
11903 mem_loc_result
= NULL
;
11906 if (GET_MODE_SIZE (mode
)
11907 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11908 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11910 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11911 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11912 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11913 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11914 add_loc_descr (&mem_loc_result
, cvt
);
11919 if (GET_MODE_CLASS (mode
) != MODE_INT
11920 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11921 && rtl
!= arg_pointer_rtx
11922 && rtl
!= frame_pointer_rtx
11923 #ifdef POINTERS_EXTEND_UNSIGNED
11924 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11928 dw_die_ref type_die
;
11932 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11934 type_die
= base_type_for_mode (mode
,
11935 GET_MODE_CLASS (mode
) == MODE_INT
);
11936 if (type_die
== NULL
)
11938 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11939 dbx_reg_number (rtl
), 0);
11940 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11941 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11942 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11945 /* Whenever a register number forms a part of the description of the
11946 method for calculating the (dynamic) address of a memory resident
11947 object, DWARF rules require the register number be referred to as
11948 a "base register". This distinction is not based in any way upon
11949 what category of register the hardware believes the given register
11950 belongs to. This is strictly DWARF terminology we're dealing with
11951 here. Note that in cases where the location of a memory-resident
11952 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11953 OP_CONST (0)) the actual DWARF location descriptor that we generate
11954 may just be OP_BASEREG (basereg). This may look deceptively like
11955 the object in question was allocated to a register (rather than in
11956 memory) so DWARF consumers need to be aware of the subtle
11957 distinction between OP_REG and OP_BASEREG. */
11958 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11959 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11960 else if (stack_realign_drap
11962 && crtl
->args
.internal_arg_pointer
== rtl
11963 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11965 /* If RTL is internal_arg_pointer, which has been optimized
11966 out, use DRAP instead. */
11967 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11968 VAR_INIT_STATUS_INITIALIZED
);
11974 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11976 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11977 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11980 else if (GET_CODE (rtl
) == ZERO_EXTEND
11981 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11982 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11983 < HOST_BITS_PER_WIDE_INT
11984 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11985 to expand zero extend as two shifts instead of
11987 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
11989 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
11990 mem_loc_result
= op0
;
11991 add_loc_descr (&mem_loc_result
,
11992 int_loc_descriptor (GET_MODE_MASK (imode
)));
11993 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
11995 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11997 int shift
= DWARF2_ADDR_SIZE
11998 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
11999 shift
*= BITS_PER_UNIT
;
12000 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12004 mem_loc_result
= op0
;
12005 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12006 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12007 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12008 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12010 else if (!dwarf_strict
)
12012 dw_die_ref type_die1
, type_die2
;
12013 dw_loc_descr_ref cvt
;
12015 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12016 GET_CODE (rtl
) == ZERO_EXTEND
);
12017 if (type_die1
== NULL
)
12019 type_die2
= base_type_for_mode (mode
, 1);
12020 if (type_die2
== NULL
)
12022 mem_loc_result
= op0
;
12023 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12024 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12025 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12026 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12027 add_loc_descr (&mem_loc_result
, cvt
);
12028 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12029 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12030 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12031 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12032 add_loc_descr (&mem_loc_result
, cvt
);
12038 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12039 if (new_rtl
!= rtl
)
12041 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12043 if (mem_loc_result
!= NULL
)
12044 return mem_loc_result
;
12047 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12048 get_address_mode (rtl
), mode
,
12049 VAR_INIT_STATUS_INITIALIZED
);
12050 if (mem_loc_result
== NULL
)
12051 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12052 if (mem_loc_result
!= NULL
)
12054 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12055 || GET_MODE_CLASS (mode
) != MODE_INT
)
12057 dw_die_ref type_die
;
12058 dw_loc_descr_ref deref
;
12063 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12064 if (type_die
== NULL
)
12066 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12067 GET_MODE_SIZE (mode
), 0);
12068 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12069 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12070 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12071 add_loc_descr (&mem_loc_result
, deref
);
12073 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12074 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12076 add_loc_descr (&mem_loc_result
,
12077 new_loc_descr (DW_OP_deref_size
,
12078 GET_MODE_SIZE (mode
), 0));
12083 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12086 /* Some ports can transform a symbol ref into a label ref, because
12087 the symbol ref is too far away and has to be dumped into a constant
12091 if (GET_MODE_CLASS (mode
) != MODE_INT
12092 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12093 #ifdef POINTERS_EXTEND_UNSIGNED
12094 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12098 if (GET_CODE (rtl
) == SYMBOL_REF
12099 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12101 dw_loc_descr_ref temp
;
12103 /* If this is not defined, we have no way to emit the data. */
12104 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12107 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12109 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12110 add_loc_descr (&mem_loc_result
, temp
);
12115 if (!const_ok_for_output (rtl
))
12119 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12120 vec_safe_push (used_rtx_array
, rtl
);
12126 case DEBUG_IMPLICIT_PTR
:
12127 expansion_failed (NULL_TREE
, rtl
,
12128 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12134 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12136 if (GET_MODE_CLASS (mode
) != MODE_INT
12137 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12138 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12139 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12142 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl
)),
12143 VAR_INIT_STATUS_INITIALIZED
);
12145 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12146 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12148 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12149 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12150 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12154 gcc_unreachable ();
12157 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12158 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12159 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12162 case DEBUG_PARAMETER_REF
:
12163 mem_loc_result
= parameter_ref_descriptor (rtl
);
12167 /* Extract the PLUS expression nested inside and fall into
12168 PLUS code below. */
12169 rtl
= XEXP (rtl
, 1);
12174 /* Turn these into a PLUS expression and fall into the PLUS code
12176 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12177 GEN_INT (GET_CODE (rtl
) == PRE_INC
12178 ? GET_MODE_UNIT_SIZE (mem_mode
)
12179 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12181 /* ... fall through ... */
12185 if (is_based_loc (rtl
)
12186 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12187 || XEXP (rtl
, 0) == arg_pointer_rtx
12188 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12189 && GET_MODE_CLASS (mode
) == MODE_INT
)
12190 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12191 INTVAL (XEXP (rtl
, 1)),
12192 VAR_INIT_STATUS_INITIALIZED
);
12195 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12196 VAR_INIT_STATUS_INITIALIZED
);
12197 if (mem_loc_result
== 0)
12200 if (CONST_INT_P (XEXP (rtl
, 1))
12201 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12202 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12205 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12206 VAR_INIT_STATUS_INITIALIZED
);
12209 add_loc_descr (&mem_loc_result
, op1
);
12210 add_loc_descr (&mem_loc_result
,
12211 new_loc_descr (DW_OP_plus
, 0, 0));
12216 /* If a pseudo-reg is optimized away, it is possible for it to
12217 be replaced with a MEM containing a multiply or shift. */
12228 && GET_MODE_CLASS (mode
) == MODE_INT
12229 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12231 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12232 base_type_for_mode (mode
, 0),
12256 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12258 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12259 VAR_INIT_STATUS_INITIALIZED
);
12261 rtx rtlop1
= XEXP (rtl
, 1);
12262 if (GET_MODE (rtlop1
) != VOIDmode
12263 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12264 < GET_MODE_BITSIZE (mode
))
12265 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12266 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12267 VAR_INIT_STATUS_INITIALIZED
);
12270 if (op0
== 0 || op1
== 0)
12273 mem_loc_result
= op0
;
12274 add_loc_descr (&mem_loc_result
, op1
);
12275 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12291 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12292 VAR_INIT_STATUS_INITIALIZED
);
12293 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12294 VAR_INIT_STATUS_INITIALIZED
);
12296 if (op0
== 0 || op1
== 0)
12299 mem_loc_result
= op0
;
12300 add_loc_descr (&mem_loc_result
, op1
);
12301 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12305 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12307 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12308 base_type_for_mode (mode
, 0),
12313 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12314 VAR_INIT_STATUS_INITIALIZED
);
12315 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12316 VAR_INIT_STATUS_INITIALIZED
);
12318 if (op0
== 0 || op1
== 0)
12321 mem_loc_result
= op0
;
12322 add_loc_descr (&mem_loc_result
, op1
);
12323 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12324 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12325 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12326 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12327 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12331 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12333 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12338 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12339 base_type_for_mode (mode
, 1),
12357 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12358 VAR_INIT_STATUS_INITIALIZED
);
12363 mem_loc_result
= op0
;
12364 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12368 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12369 #ifdef POINTERS_EXTEND_UNSIGNED
12371 && mem_mode
!= VOIDmode
12372 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12376 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12380 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12381 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12383 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12384 enum machine_mode amode
;
12385 if (type_die
== NULL
)
12387 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12389 if (INTVAL (rtl
) >= 0
12390 && amode
!= BLKmode
12391 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12392 /* const DW_OP_GNU_convert <XXX> vs.
12393 DW_OP_GNU_const_type <XXX, 1, const>. */
12394 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12395 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12397 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12398 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12399 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12400 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12401 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12402 add_loc_descr (&mem_loc_result
, op0
);
12403 return mem_loc_result
;
12405 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12407 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12408 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12409 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12410 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12411 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12414 mem_loc_result
->dw_loc_oprnd2
.val_class
12415 = dw_val_class_const_double
;
12416 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12417 = double_int::from_shwi (INTVAL (rtl
));
12425 dw_die_ref type_die
;
12427 /* Note that a CONST_DOUBLE rtx could represent either an integer
12428 or a floating-point constant. A CONST_DOUBLE is used whenever
12429 the constant requires more than one word in order to be
12430 adequately represented. We output CONST_DOUBLEs as blocks. */
12431 if (mode
== VOIDmode
12432 || (GET_MODE (rtl
) == VOIDmode
12433 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12435 type_die
= base_type_for_mode (mode
,
12436 GET_MODE_CLASS (mode
) == MODE_INT
);
12437 if (type_die
== NULL
)
12439 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12440 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12441 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12442 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12443 if (SCALAR_FLOAT_MODE_P (mode
))
12445 unsigned int length
= GET_MODE_SIZE (mode
);
12446 unsigned char *array
12447 = (unsigned char*) ggc_alloc_atomic (length
);
12449 insert_float (rtl
, array
);
12450 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12451 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12452 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12453 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12457 mem_loc_result
->dw_loc_oprnd2
.val_class
12458 = dw_val_class_const_double
;
12459 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12460 = rtx_to_double_int (rtl
);
12466 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12470 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12474 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12478 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12482 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12486 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12490 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12494 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12498 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12502 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12507 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12512 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12517 if (CONST_INT_P (XEXP (rtl
, 1))
12518 && CONST_INT_P (XEXP (rtl
, 2))
12519 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12520 + (unsigned) INTVAL (XEXP (rtl
, 2))
12521 <= GET_MODE_BITSIZE (mode
))
12522 && GET_MODE_CLASS (mode
) == MODE_INT
12523 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12524 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12527 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12528 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12531 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12535 mem_loc_result
= op0
;
12536 size
= INTVAL (XEXP (rtl
, 1));
12537 shift
= INTVAL (XEXP (rtl
, 2));
12538 if (BITS_BIG_ENDIAN
)
12539 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12541 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12543 add_loc_descr (&mem_loc_result
,
12544 int_loc_descriptor (DWARF2_ADDR_SIZE
12546 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12548 if (size
!= (int) DWARF2_ADDR_SIZE
)
12550 add_loc_descr (&mem_loc_result
,
12551 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12552 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12559 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12560 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12561 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12562 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12563 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12564 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12565 VAR_INIT_STATUS_INITIALIZED
);
12566 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12567 VAR_INIT_STATUS_INITIALIZED
);
12568 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12571 mem_loc_result
= op1
;
12572 add_loc_descr (&mem_loc_result
, op2
);
12573 add_loc_descr (&mem_loc_result
, op0
);
12574 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12575 add_loc_descr (&mem_loc_result
, bra_node
);
12576 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12577 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12578 add_loc_descr (&mem_loc_result
, drop_node
);
12579 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12580 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12585 case FLOAT_TRUNCATE
:
12587 case UNSIGNED_FLOAT
:
12592 dw_die_ref type_die
;
12593 dw_loc_descr_ref cvt
;
12595 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12596 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12599 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12600 && (GET_CODE (rtl
) == FLOAT
12601 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12602 <= DWARF2_ADDR_SIZE
))
12604 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12605 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12606 if (type_die
== NULL
)
12608 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12609 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12610 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12611 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12612 add_loc_descr (&op0
, cvt
);
12614 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12615 if (type_die
== NULL
)
12617 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12618 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12619 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12620 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12621 add_loc_descr (&op0
, cvt
);
12622 if (GET_MODE_CLASS (mode
) == MODE_INT
12623 && (GET_CODE (rtl
) == FIX
12624 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12626 op0
= convert_descriptor_to_mode (mode
, op0
);
12630 mem_loc_result
= op0
;
12637 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12642 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12646 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12651 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12656 /* In theory, we could implement the above. */
12657 /* DWARF cannot represent the unsigned compare operations
12682 case FRACT_CONVERT
:
12683 case UNSIGNED_FRACT_CONVERT
:
12685 case UNSIGNED_SAT_FRACT
:
12691 case VEC_DUPLICATE
:
12695 case STRICT_LOW_PART
:
12699 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12700 can't express it in the debug info. This can happen e.g. with some
12705 resolve_one_addr (&rtl
, NULL
);
12709 #ifdef ENABLE_CHECKING
12710 print_rtl (stderr
, rtl
);
12711 gcc_unreachable ();
12717 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12718 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12720 return mem_loc_result
;
12723 /* Return a descriptor that describes the concatenation of two locations.
12724 This is typically a complex variable. */
12726 static dw_loc_descr_ref
12727 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12729 dw_loc_descr_ref cc_loc_result
= NULL
;
12730 dw_loc_descr_ref x0_ref
12731 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12732 dw_loc_descr_ref x1_ref
12733 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12735 if (x0_ref
== 0 || x1_ref
== 0)
12738 cc_loc_result
= x0_ref
;
12739 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12741 add_loc_descr (&cc_loc_result
, x1_ref
);
12742 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12744 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12745 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12747 return cc_loc_result
;
12750 /* Return a descriptor that describes the concatenation of N
12753 static dw_loc_descr_ref
12754 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12757 dw_loc_descr_ref cc_loc_result
= NULL
;
12758 unsigned int n
= XVECLEN (concatn
, 0);
12760 for (i
= 0; i
< n
; ++i
)
12762 dw_loc_descr_ref ref
;
12763 rtx x
= XVECEXP (concatn
, 0, i
);
12765 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12769 add_loc_descr (&cc_loc_result
, ref
);
12770 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12773 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12774 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12776 return cc_loc_result
;
12779 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12780 for DEBUG_IMPLICIT_PTR RTL. */
12782 static dw_loc_descr_ref
12783 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12785 dw_loc_descr_ref ret
;
12790 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12791 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12792 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12793 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12794 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12795 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12798 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12799 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12800 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12804 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12805 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12810 /* Output a proper Dwarf location descriptor for a variable or parameter
12811 which is either allocated in a register or in a memory location. For a
12812 register, we just generate an OP_REG and the register number. For a
12813 memory location we provide a Dwarf postfix expression describing how to
12814 generate the (dynamic) address of the object onto the address stack.
12816 MODE is mode of the decl if this loc_descriptor is going to be used in
12817 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12818 allowed, VOIDmode otherwise.
12820 If we don't know how to describe it, return 0. */
12822 static dw_loc_descr_ref
12823 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12824 enum var_init_status initialized
)
12826 dw_loc_descr_ref loc_result
= NULL
;
12828 switch (GET_CODE (rtl
))
12831 /* The case of a subreg may arise when we have a local (register)
12832 variable or a formal (register) parameter which doesn't quite fill
12833 up an entire register. For now, just assume that it is
12834 legitimate to make the Dwarf info refer to the whole register which
12835 contains the given subreg. */
12836 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12837 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12838 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12844 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12848 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12849 GET_MODE (rtl
), initialized
);
12850 if (loc_result
== NULL
)
12851 loc_result
= tls_mem_loc_descriptor (rtl
);
12852 if (loc_result
== NULL
)
12854 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12855 if (new_rtl
!= rtl
)
12856 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12861 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12866 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12871 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12873 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12874 if (GET_CODE (loc
) == EXPR_LIST
)
12875 loc
= XEXP (loc
, 0);
12876 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12880 rtl
= XEXP (rtl
, 1);
12885 rtvec par_elems
= XVEC (rtl
, 0);
12886 int num_elem
= GET_NUM_ELEM (par_elems
);
12887 enum machine_mode mode
;
12890 /* Create the first one, so we have something to add to. */
12891 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12892 VOIDmode
, initialized
);
12893 if (loc_result
== NULL
)
12895 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12896 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12897 for (i
= 1; i
< num_elem
; i
++)
12899 dw_loc_descr_ref temp
;
12901 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12902 VOIDmode
, initialized
);
12905 add_loc_descr (&loc_result
, temp
);
12906 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12907 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12913 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12914 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12919 if (mode
== VOIDmode
)
12920 mode
= GET_MODE (rtl
);
12922 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12924 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12926 /* Note that a CONST_DOUBLE rtx could represent either an integer
12927 or a floating-point constant. A CONST_DOUBLE is used whenever
12928 the constant requires more than one word in order to be
12929 adequately represented. We output CONST_DOUBLEs as blocks. */
12930 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12931 GET_MODE_SIZE (mode
), 0);
12932 if (SCALAR_FLOAT_MODE_P (mode
))
12934 unsigned int length
= GET_MODE_SIZE (mode
);
12935 unsigned char *array
12936 = (unsigned char*) ggc_alloc_atomic (length
);
12938 insert_float (rtl
, array
);
12939 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12940 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12941 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12942 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12946 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12947 loc_result
->dw_loc_oprnd2
.v
.val_double
12948 = rtx_to_double_int (rtl
);
12954 if (mode
== VOIDmode
)
12955 mode
= GET_MODE (rtl
);
12957 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12959 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12960 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12961 unsigned char *array
= (unsigned char *)
12962 ggc_alloc_atomic (length
* elt_size
);
12966 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12967 switch (GET_MODE_CLASS (mode
))
12969 case MODE_VECTOR_INT
:
12970 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12972 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12973 double_int val
= rtx_to_double_int (elt
);
12975 if (elt_size
<= sizeof (HOST_WIDE_INT
))
12976 insert_int (val
.to_shwi (), elt_size
, p
);
12979 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
12980 insert_double (val
, p
);
12985 case MODE_VECTOR_FLOAT
:
12986 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12988 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12989 insert_float (elt
, p
);
12994 gcc_unreachable ();
12997 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12998 length
* elt_size
, 0);
12999 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13000 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13001 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13002 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13007 if (mode
== VOIDmode
13008 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13009 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13010 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13012 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13017 if (!const_ok_for_output (rtl
))
13020 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13021 && (dwarf_version
>= 4 || !dwarf_strict
))
13023 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13024 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13025 vec_safe_push (used_rtx_array
, rtl
);
13029 case DEBUG_IMPLICIT_PTR
:
13030 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13034 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13035 && CONST_INT_P (XEXP (rtl
, 1)))
13038 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13044 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13045 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13046 && dwarf_version
>= 4)
13047 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13049 /* Value expression. */
13050 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13052 add_loc_descr (&loc_result
,
13053 new_loc_descr (DW_OP_stack_value
, 0, 0));
13061 /* We need to figure out what section we should use as the base for the
13062 address ranges where a given location is valid.
13063 1. If this particular DECL has a section associated with it, use that.
13064 2. If this function has a section associated with it, use that.
13065 3. Otherwise, use the text section.
13066 XXX: If you split a variable across multiple sections, we won't notice. */
13068 static const char *
13069 secname_for_decl (const_tree decl
)
13071 const char *secname
;
13073 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13075 tree sectree
= DECL_SECTION_NAME (decl
);
13076 secname
= TREE_STRING_POINTER (sectree
);
13078 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13080 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13081 secname
= TREE_STRING_POINTER (sectree
);
13083 else if (cfun
&& in_cold_section_p
)
13084 secname
= crtl
->subsections
.cold_section_label
;
13086 secname
= text_section_label
;
13091 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13094 decl_by_reference_p (tree decl
)
13096 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13097 || TREE_CODE (decl
) == VAR_DECL
)
13098 && DECL_BY_REFERENCE (decl
));
13101 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13104 static dw_loc_descr_ref
13105 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13106 enum var_init_status initialized
)
13108 int have_address
= 0;
13109 dw_loc_descr_ref descr
;
13110 enum machine_mode mode
;
13112 if (want_address
!= 2)
13114 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13116 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13118 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13119 if (GET_CODE (varloc
) == EXPR_LIST
)
13120 varloc
= XEXP (varloc
, 0);
13121 mode
= GET_MODE (varloc
);
13122 if (MEM_P (varloc
))
13124 rtx addr
= XEXP (varloc
, 0);
13125 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13126 mode
, initialized
);
13131 rtx x
= avoid_constant_pool_reference (varloc
);
13133 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13138 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13145 if (GET_CODE (varloc
) == VAR_LOCATION
)
13146 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13148 mode
= DECL_MODE (loc
);
13149 descr
= loc_descriptor (varloc
, mode
, initialized
);
13156 if (want_address
== 2 && !have_address
13157 && (dwarf_version
>= 4 || !dwarf_strict
))
13159 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13161 expansion_failed (loc
, NULL_RTX
,
13162 "DWARF address size mismatch");
13165 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13168 /* Show if we can't fill the request for an address. */
13169 if (want_address
&& !have_address
)
13171 expansion_failed (loc
, NULL_RTX
,
13172 "Want address and only have value");
13176 /* If we've got an address and don't want one, dereference. */
13177 if (!want_address
&& have_address
)
13179 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13180 enum dwarf_location_atom op
;
13182 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13184 expansion_failed (loc
, NULL_RTX
,
13185 "DWARF address size mismatch");
13188 else if (size
== DWARF2_ADDR_SIZE
)
13191 op
= DW_OP_deref_size
;
13193 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13199 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13200 if it is not possible. */
13202 static dw_loc_descr_ref
13203 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13205 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13206 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13207 else if (dwarf_version
>= 3 || !dwarf_strict
)
13208 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13213 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13214 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13216 static dw_loc_descr_ref
13217 dw_sra_loc_expr (tree decl
, rtx loc
)
13220 unsigned int padsize
= 0;
13221 dw_loc_descr_ref descr
, *descr_tail
;
13222 unsigned HOST_WIDE_INT decl_size
;
13224 enum var_init_status initialized
;
13226 if (DECL_SIZE (decl
) == NULL
13227 || !host_integerp (DECL_SIZE (decl
), 1))
13230 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13232 descr_tail
= &descr
;
13234 for (p
= loc
; p
; p
= XEXP (p
, 1))
13236 unsigned int bitsize
= decl_piece_bitsize (p
);
13237 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13238 dw_loc_descr_ref cur_descr
;
13239 dw_loc_descr_ref
*tail
, last
= NULL
;
13240 unsigned int opsize
= 0;
13242 if (loc_note
== NULL_RTX
13243 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13245 padsize
+= bitsize
;
13248 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13249 varloc
= NOTE_VAR_LOCATION (loc_note
);
13250 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13251 if (cur_descr
== NULL
)
13253 padsize
+= bitsize
;
13257 /* Check that cur_descr either doesn't use
13258 DW_OP_*piece operations, or their sum is equal
13259 to bitsize. Otherwise we can't embed it. */
13260 for (tail
= &cur_descr
; *tail
!= NULL
;
13261 tail
= &(*tail
)->dw_loc_next
)
13262 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13264 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13268 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13270 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13274 if (last
!= NULL
&& opsize
!= bitsize
)
13276 padsize
+= bitsize
;
13280 /* If there is a hole, add DW_OP_*piece after empty DWARF
13281 expression, which means that those bits are optimized out. */
13284 if (padsize
> decl_size
)
13286 decl_size
-= padsize
;
13287 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13288 if (*descr_tail
== NULL
)
13290 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13293 *descr_tail
= cur_descr
;
13295 if (bitsize
> decl_size
)
13297 decl_size
-= bitsize
;
13300 HOST_WIDE_INT offset
= 0;
13301 if (GET_CODE (varloc
) == VAR_LOCATION
13302 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13304 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13305 if (GET_CODE (varloc
) == EXPR_LIST
)
13306 varloc
= XEXP (varloc
, 0);
13310 if (GET_CODE (varloc
) == CONST
13311 || GET_CODE (varloc
) == SIGN_EXTEND
13312 || GET_CODE (varloc
) == ZERO_EXTEND
)
13313 varloc
= XEXP (varloc
, 0);
13314 else if (GET_CODE (varloc
) == SUBREG
)
13315 varloc
= SUBREG_REG (varloc
);
13320 /* DW_OP_bit_size offset should be zero for register
13321 or implicit location descriptions and empty location
13322 descriptions, but for memory addresses needs big endian
13324 if (MEM_P (varloc
))
13326 unsigned HOST_WIDE_INT memsize
13327 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13328 if (memsize
!= bitsize
)
13330 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13331 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13333 if (memsize
< bitsize
)
13335 if (BITS_BIG_ENDIAN
)
13336 offset
= memsize
- bitsize
;
13340 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13341 if (*descr_tail
== NULL
)
13343 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13347 /* If there were any non-empty expressions, add padding till the end of
13349 if (descr
!= NULL
&& decl_size
!= 0)
13351 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13352 if (*descr_tail
== NULL
)
13358 /* Return the dwarf representation of the location list LOC_LIST of
13359 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13362 static dw_loc_list_ref
13363 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13365 const char *endname
, *secname
;
13367 enum var_init_status initialized
;
13368 struct var_loc_node
*node
;
13369 dw_loc_descr_ref descr
;
13370 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13371 dw_loc_list_ref list
= NULL
;
13372 dw_loc_list_ref
*listp
= &list
;
13374 /* Now that we know what section we are using for a base,
13375 actually construct the list of locations.
13376 The first location information is what is passed to the
13377 function that creates the location list, and the remaining
13378 locations just get added on to that list.
13379 Note that we only know the start address for a location
13380 (IE location changes), so to build the range, we use
13381 the range [current location start, next location start].
13382 This means we have to special case the last node, and generate
13383 a range of [last location start, end of function label]. */
13385 secname
= secname_for_decl (decl
);
13387 for (node
= loc_list
->first
; node
; node
= node
->next
)
13388 if (GET_CODE (node
->loc
) == EXPR_LIST
13389 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13391 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13393 /* This requires DW_OP_{,bit_}piece, which is not usable
13394 inside DWARF expressions. */
13395 if (want_address
!= 2)
13397 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13403 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13404 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13405 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13409 bool range_across_switch
= false;
13410 /* If section switch happens in between node->label
13411 and node->next->label (or end of function) and
13412 we can't emit it as a single entry list,
13413 emit two ranges, first one ending at the end
13414 of first partition and second one starting at the
13415 beginning of second partition. */
13416 if (node
== loc_list
->last_before_switch
13417 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13418 && current_function_decl
)
13420 endname
= cfun
->fde
->dw_fde_end
;
13421 range_across_switch
= true;
13423 /* The variable has a location between NODE->LABEL and
13424 NODE->NEXT->LABEL. */
13425 else if (node
->next
)
13426 endname
= node
->next
->label
;
13427 /* If the variable has a location at the last label
13428 it keeps its location until the end of function. */
13429 else if (!current_function_decl
)
13430 endname
= text_end_label
;
13433 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13434 current_function_funcdef_no
);
13435 endname
= ggc_strdup (label_id
);
13438 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13439 if (TREE_CODE (decl
) == PARM_DECL
13440 && node
== loc_list
->first
13441 && GET_CODE (node
->loc
) == NOTE
13442 && strcmp (node
->label
, endname
) == 0)
13443 (*listp
)->force
= true;
13444 listp
= &(*listp
)->dw_loc_next
;
13446 if (range_across_switch
)
13448 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13449 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13452 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13453 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13454 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13457 gcc_assert (descr
);
13458 /* The variable has a location between NODE->LABEL and
13459 NODE->NEXT->LABEL. */
13461 endname
= node
->next
->label
;
13463 endname
= cfun
->fde
->dw_fde_second_end
;
13464 *listp
= new_loc_list (descr
,
13465 cfun
->fde
->dw_fde_second_begin
,
13467 listp
= &(*listp
)->dw_loc_next
;
13472 /* Try to avoid the overhead of a location list emitting a location
13473 expression instead, but only if we didn't have more than one
13474 location entry in the first place. If some entries were not
13475 representable, we don't want to pretend a single entry that was
13476 applies to the entire scope in which the variable is
13478 if (list
&& loc_list
->first
->next
)
13484 /* Return if the loc_list has only single element and thus can be represented
13485 as location description. */
13488 single_element_loc_list_p (dw_loc_list_ref list
)
13490 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13491 return !list
->ll_symbol
;
13494 /* To each location in list LIST add loc descr REF. */
13497 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13499 dw_loc_descr_ref copy
;
13500 add_loc_descr (&list
->expr
, ref
);
13501 list
= list
->dw_loc_next
;
13504 copy
= ggc_alloc_dw_loc_descr_node ();
13505 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13506 add_loc_descr (&list
->expr
, copy
);
13507 while (copy
->dw_loc_next
)
13509 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13510 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13511 copy
->dw_loc_next
= new_copy
;
13514 list
= list
->dw_loc_next
;
13518 /* Given two lists RET and LIST
13519 produce location list that is result of adding expression in LIST
13520 to expression in RET on each position in program.
13521 Might be destructive on both RET and LIST.
13523 TODO: We handle only simple cases of RET or LIST having at most one
13524 element. General case would inolve sorting the lists in program order
13525 and merging them that will need some additional work.
13526 Adding that will improve quality of debug info especially for SRA-ed
13530 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13539 if (!list
->dw_loc_next
)
13541 add_loc_descr_to_each (*ret
, list
->expr
);
13544 if (!(*ret
)->dw_loc_next
)
13546 add_loc_descr_to_each (list
, (*ret
)->expr
);
13550 expansion_failed (NULL_TREE
, NULL_RTX
,
13551 "Don't know how to merge two non-trivial"
13552 " location lists.\n");
13557 /* LOC is constant expression. Try a luck, look it up in constant
13558 pool and return its loc_descr of its address. */
13560 static dw_loc_descr_ref
13561 cst_pool_loc_descr (tree loc
)
13563 /* Get an RTL for this, if something has been emitted. */
13564 rtx rtl
= lookup_constant_def (loc
);
13566 if (!rtl
|| !MEM_P (rtl
))
13571 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13573 /* TODO: We might get more coverage if we was actually delaying expansion
13574 of all expressions till end of compilation when constant pools are fully
13576 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13578 expansion_failed (loc
, NULL_RTX
,
13579 "CST value in contant pool but not marked.");
13582 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13583 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13586 /* Return dw_loc_list representing address of addr_expr LOC
13587 by looking for inner INDIRECT_REF expression and turning
13588 it into simple arithmetics. */
13590 static dw_loc_list_ref
13591 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13594 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13595 enum machine_mode mode
;
13596 int unsignedp
, volatilep
= 0;
13597 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13599 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13600 &bitsize
, &bitpos
, &offset
, &mode
,
13601 &unsignedp
, &volatilep
, false);
13603 if (bitpos
% BITS_PER_UNIT
)
13605 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13608 if (!INDIRECT_REF_P (obj
))
13610 expansion_failed (obj
,
13611 NULL_RTX
, "no indirect ref in inner refrence");
13614 if (!offset
&& !bitpos
)
13615 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13617 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13618 && (dwarf_version
>= 4 || !dwarf_strict
))
13620 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13625 /* Variable offset. */
13626 list_ret1
= loc_list_from_tree (offset
, 0);
13627 if (list_ret1
== 0)
13629 add_loc_list (&list_ret
, list_ret1
);
13632 add_loc_descr_to_each (list_ret
,
13633 new_loc_descr (DW_OP_plus
, 0, 0));
13635 bytepos
= bitpos
/ BITS_PER_UNIT
;
13637 add_loc_descr_to_each (list_ret
,
13638 new_loc_descr (DW_OP_plus_uconst
,
13640 else if (bytepos
< 0)
13641 loc_list_plus_const (list_ret
, bytepos
);
13642 add_loc_descr_to_each (list_ret
,
13643 new_loc_descr (DW_OP_stack_value
, 0, 0));
13649 /* Generate Dwarf location list representing LOC.
13650 If WANT_ADDRESS is false, expression computing LOC will be computed
13651 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13652 if WANT_ADDRESS is 2, expression computing address useable in location
13653 will be returned (i.e. DW_OP_reg can be used
13654 to refer to register values). */
13656 static dw_loc_list_ref
13657 loc_list_from_tree (tree loc
, int want_address
)
13659 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13660 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13661 int have_address
= 0;
13662 enum dwarf_location_atom op
;
13664 /* ??? Most of the time we do not take proper care for sign/zero
13665 extending the values properly. Hopefully this won't be a real
13668 switch (TREE_CODE (loc
))
13671 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13674 case PLACEHOLDER_EXPR
:
13675 /* This case involves extracting fields from an object to determine the
13676 position of other fields. We don't try to encode this here. The
13677 only user of this is Ada, which encodes the needed information using
13678 the names of types. */
13679 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13683 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13684 /* There are no opcodes for these operations. */
13687 case PREINCREMENT_EXPR
:
13688 case PREDECREMENT_EXPR
:
13689 case POSTINCREMENT_EXPR
:
13690 case POSTDECREMENT_EXPR
:
13691 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13692 /* There are no opcodes for these operations. */
13696 /* If we already want an address, see if there is INDIRECT_REF inside
13697 e.g. for &this->field. */
13700 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13701 (loc
, want_address
== 2);
13704 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13705 && (ret
= cst_pool_loc_descr (loc
)))
13708 /* Otherwise, process the argument and look for the address. */
13709 if (!list_ret
&& !ret
)
13710 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13714 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13720 if (DECL_THREAD_LOCAL_P (loc
))
13723 enum dwarf_location_atom tls_op
;
13724 enum dtprel_bool dtprel
= dtprel_false
;
13726 if (targetm
.have_tls
)
13728 /* If this is not defined, we have no way to emit the
13730 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13733 /* The way DW_OP_GNU_push_tls_address is specified, we
13734 can only look up addresses of objects in the current
13735 module. We used DW_OP_addr as first op, but that's
13736 wrong, because DW_OP_addr is relocated by the debug
13737 info consumer, while DW_OP_GNU_push_tls_address
13738 operand shouldn't be. */
13739 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13741 dtprel
= dtprel_true
;
13742 tls_op
= DW_OP_GNU_push_tls_address
;
13746 if (!targetm
.emutls
.debug_form_tls_address
13747 || !(dwarf_version
>= 3 || !dwarf_strict
))
13749 /* We stuffed the control variable into the DECL_VALUE_EXPR
13750 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13751 no longer appear in gimple code. We used the control
13752 variable in specific so that we could pick it up here. */
13753 loc
= DECL_VALUE_EXPR (loc
);
13754 tls_op
= DW_OP_form_tls_address
;
13757 rtl
= rtl_for_decl_location (loc
);
13758 if (rtl
== NULL_RTX
)
13763 rtl
= XEXP (rtl
, 0);
13764 if (! CONSTANT_P (rtl
))
13767 ret
= new_addr_loc_descr (rtl
, dtprel
);
13768 ret1
= new_loc_descr (tls_op
, 0, 0);
13769 add_loc_descr (&ret
, ret1
);
13778 if (DECL_HAS_VALUE_EXPR_P (loc
))
13779 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13783 case FUNCTION_DECL
:
13786 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13788 if (loc_list
&& loc_list
->first
)
13790 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13791 have_address
= want_address
!= 0;
13794 rtl
= rtl_for_decl_location (loc
);
13795 if (rtl
== NULL_RTX
)
13797 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13800 else if (CONST_INT_P (rtl
))
13802 HOST_WIDE_INT val
= INTVAL (rtl
);
13803 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13804 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13805 ret
= int_loc_descriptor (val
);
13807 else if (GET_CODE (rtl
) == CONST_STRING
)
13809 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13812 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13813 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13816 enum machine_mode mode
, mem_mode
;
13818 /* Certain constructs can only be represented at top-level. */
13819 if (want_address
== 2)
13821 ret
= loc_descriptor (rtl
, VOIDmode
,
13822 VAR_INIT_STATUS_INITIALIZED
);
13827 mode
= GET_MODE (rtl
);
13828 mem_mode
= VOIDmode
;
13832 mode
= get_address_mode (rtl
);
13833 rtl
= XEXP (rtl
, 0);
13836 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13837 VAR_INIT_STATUS_INITIALIZED
);
13840 expansion_failed (loc
, rtl
,
13841 "failed to produce loc descriptor for rtl");
13848 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13852 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13856 case COMPOUND_EXPR
:
13857 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13860 case VIEW_CONVERT_EXPR
:
13863 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13865 case COMPONENT_REF
:
13866 case BIT_FIELD_REF
:
13868 case ARRAY_RANGE_REF
:
13869 case REALPART_EXPR
:
13870 case IMAGPART_EXPR
:
13873 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13874 enum machine_mode mode
;
13875 int unsignedp
, volatilep
= 0;
13877 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13878 &unsignedp
, &volatilep
, false);
13880 gcc_assert (obj
!= loc
);
13882 list_ret
= loc_list_from_tree (obj
,
13884 && !bitpos
&& !offset
? 2 : 1);
13885 /* TODO: We can extract value of the small expression via shifting even
13886 for nonzero bitpos. */
13889 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13891 expansion_failed (loc
, NULL_RTX
,
13892 "bitfield access");
13896 if (offset
!= NULL_TREE
)
13898 /* Variable offset. */
13899 list_ret1
= loc_list_from_tree (offset
, 0);
13900 if (list_ret1
== 0)
13902 add_loc_list (&list_ret
, list_ret1
);
13905 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13908 bytepos
= bitpos
/ BITS_PER_UNIT
;
13910 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13911 else if (bytepos
< 0)
13912 loc_list_plus_const (list_ret
, bytepos
);
13919 if ((want_address
|| !host_integerp (loc
, 0))
13920 && (ret
= cst_pool_loc_descr (loc
)))
13922 else if (want_address
== 2
13923 && host_integerp (loc
, 0)
13924 && (ret
= address_of_int_loc_descriptor
13925 (int_size_in_bytes (TREE_TYPE (loc
)),
13926 tree_low_cst (loc
, 0))))
13928 else if (host_integerp (loc
, 0))
13929 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13932 expansion_failed (loc
, NULL_RTX
,
13933 "Integer operand is not host integer");
13942 if ((ret
= cst_pool_loc_descr (loc
)))
13945 /* We can construct small constants here using int_loc_descriptor. */
13946 expansion_failed (loc
, NULL_RTX
,
13947 "constructor or constant not in constant pool");
13950 case TRUTH_AND_EXPR
:
13951 case TRUTH_ANDIF_EXPR
:
13956 case TRUTH_XOR_EXPR
:
13961 case TRUTH_OR_EXPR
:
13962 case TRUTH_ORIF_EXPR
:
13967 case FLOOR_DIV_EXPR
:
13968 case CEIL_DIV_EXPR
:
13969 case ROUND_DIV_EXPR
:
13970 case TRUNC_DIV_EXPR
:
13971 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13980 case FLOOR_MOD_EXPR
:
13981 case CEIL_MOD_EXPR
:
13982 case ROUND_MOD_EXPR
:
13983 case TRUNC_MOD_EXPR
:
13984 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13989 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13990 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
13991 if (list_ret
== 0 || list_ret1
== 0)
13994 add_loc_list (&list_ret
, list_ret1
);
13997 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13998 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
13999 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14000 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14001 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14013 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14016 case POINTER_PLUS_EXPR
:
14018 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14020 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14024 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14032 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14039 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14046 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14053 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14068 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14069 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14070 if (list_ret
== 0 || list_ret1
== 0)
14073 add_loc_list (&list_ret
, list_ret1
);
14076 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14079 case TRUTH_NOT_EXPR
:
14093 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14097 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14103 const enum tree_code code
=
14104 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14106 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14107 build2 (code
, integer_type_node
,
14108 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14109 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14112 /* ... fall through ... */
14116 dw_loc_descr_ref lhs
14117 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14118 dw_loc_list_ref rhs
14119 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14120 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14122 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14123 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14126 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14127 add_loc_descr_to_each (list_ret
, bra_node
);
14129 add_loc_list (&list_ret
, rhs
);
14130 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14131 add_loc_descr_to_each (list_ret
, jump_node
);
14133 add_loc_descr_to_each (list_ret
, lhs
);
14134 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14135 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14137 /* ??? Need a node to point the skip at. Use a nop. */
14138 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14139 add_loc_descr_to_each (list_ret
, tmp
);
14140 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14141 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14145 case FIX_TRUNC_EXPR
:
14149 /* Leave front-end specific codes as simply unknown. This comes
14150 up, for instance, with the C STMT_EXPR. */
14151 if ((unsigned int) TREE_CODE (loc
)
14152 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14154 expansion_failed (loc
, NULL_RTX
,
14155 "language specific tree node");
14159 #ifdef ENABLE_CHECKING
14160 /* Otherwise this is a generic code; we should just lists all of
14161 these explicitly. We forgot one. */
14162 gcc_unreachable ();
14164 /* In a release build, we want to degrade gracefully: better to
14165 generate incomplete debugging information than to crash. */
14170 if (!ret
&& !list_ret
)
14173 if (want_address
== 2 && !have_address
14174 && (dwarf_version
>= 4 || !dwarf_strict
))
14176 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14178 expansion_failed (loc
, NULL_RTX
,
14179 "DWARF address size mismatch");
14183 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14185 add_loc_descr_to_each (list_ret
,
14186 new_loc_descr (DW_OP_stack_value
, 0, 0));
14189 /* Show if we can't fill the request for an address. */
14190 if (want_address
&& !have_address
)
14192 expansion_failed (loc
, NULL_RTX
,
14193 "Want address and only have value");
14197 gcc_assert (!ret
|| !list_ret
);
14199 /* If we've got an address and don't want one, dereference. */
14200 if (!want_address
&& have_address
)
14202 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14204 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14206 expansion_failed (loc
, NULL_RTX
,
14207 "DWARF address size mismatch");
14210 else if (size
== DWARF2_ADDR_SIZE
)
14213 op
= DW_OP_deref_size
;
14216 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14218 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14221 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14226 /* Same as above but return only single location expression. */
14227 static dw_loc_descr_ref
14228 loc_descriptor_from_tree (tree loc
, int want_address
)
14230 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14233 if (ret
->dw_loc_next
)
14235 expansion_failed (loc
, NULL_RTX
,
14236 "Location list where only loc descriptor needed");
14242 /* Given a value, round it up to the lowest multiple of `boundary'
14243 which is not less than the value itself. */
14245 static inline HOST_WIDE_INT
14246 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14248 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14251 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14252 pointer to the declared type for the relevant field variable, or return
14253 `integer_type_node' if the given node turns out to be an
14254 ERROR_MARK node. */
14257 field_type (const_tree decl
)
14261 if (TREE_CODE (decl
) == ERROR_MARK
)
14262 return integer_type_node
;
14264 type
= DECL_BIT_FIELD_TYPE (decl
);
14265 if (type
== NULL_TREE
)
14266 type
= TREE_TYPE (decl
);
14271 /* Given a pointer to a tree node, return the alignment in bits for
14272 it, or else return BITS_PER_WORD if the node actually turns out to
14273 be an ERROR_MARK node. */
14275 static inline unsigned
14276 simple_type_align_in_bits (const_tree type
)
14278 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14281 static inline unsigned
14282 simple_decl_align_in_bits (const_tree decl
)
14284 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14287 /* Return the result of rounding T up to ALIGN. */
14289 static inline double_int
14290 round_up_to_align (double_int t
, unsigned int align
)
14292 double_int alignd
= double_int::from_uhwi (align
);
14294 t
+= double_int_minus_one
;
14295 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14300 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14301 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14302 or return 0 if we are unable to determine what that offset is, either
14303 because the argument turns out to be a pointer to an ERROR_MARK node, or
14304 because the offset is actually variable. (We can't handle the latter case
14307 static HOST_WIDE_INT
14308 field_byte_offset (const_tree decl
)
14310 double_int object_offset_in_bits
;
14311 double_int object_offset_in_bytes
;
14312 double_int bitpos_int
;
14314 if (TREE_CODE (decl
) == ERROR_MARK
)
14317 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14319 /* We cannot yet cope with fields whose positions are variable, so
14320 for now, when we see such things, we simply return 0. Someday, we may
14321 be able to handle such cases, but it will be damn difficult. */
14322 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14325 bitpos_int
= tree_to_double_int (bit_position (decl
));
14327 #ifdef PCC_BITFIELD_TYPE_MATTERS
14328 if (PCC_BITFIELD_TYPE_MATTERS
)
14331 tree field_size_tree
;
14332 double_int deepest_bitpos
;
14333 double_int field_size_in_bits
;
14334 unsigned int type_align_in_bits
;
14335 unsigned int decl_align_in_bits
;
14336 double_int type_size_in_bits
;
14338 type
= field_type (decl
);
14339 type_size_in_bits
= double_int_type_size_in_bits (type
);
14340 type_align_in_bits
= simple_type_align_in_bits (type
);
14342 field_size_tree
= DECL_SIZE (decl
);
14344 /* The size could be unspecified if there was an error, or for
14345 a flexible array member. */
14346 if (!field_size_tree
)
14347 field_size_tree
= bitsize_zero_node
;
14349 /* If the size of the field is not constant, use the type size. */
14350 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14351 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14353 field_size_in_bits
= type_size_in_bits
;
14355 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14357 /* The GCC front-end doesn't make any attempt to keep track of the
14358 starting bit offset (relative to the start of the containing
14359 structure type) of the hypothetical "containing object" for a
14360 bit-field. Thus, when computing the byte offset value for the
14361 start of the "containing object" of a bit-field, we must deduce
14362 this information on our own. This can be rather tricky to do in
14363 some cases. For example, handling the following structure type
14364 definition when compiling for an i386/i486 target (which only
14365 aligns long long's to 32-bit boundaries) can be very tricky:
14367 struct S { int field1; long long field2:31; };
14369 Fortunately, there is a simple rule-of-thumb which can be used
14370 in such cases. When compiling for an i386/i486, GCC will
14371 allocate 8 bytes for the structure shown above. It decides to
14372 do this based upon one simple rule for bit-field allocation.
14373 GCC allocates each "containing object" for each bit-field at
14374 the first (i.e. lowest addressed) legitimate alignment boundary
14375 (based upon the required minimum alignment for the declared
14376 type of the field) which it can possibly use, subject to the
14377 condition that there is still enough available space remaining
14378 in the containing object (when allocated at the selected point)
14379 to fully accommodate all of the bits of the bit-field itself.
14381 This simple rule makes it obvious why GCC allocates 8 bytes for
14382 each object of the structure type shown above. When looking
14383 for a place to allocate the "containing object" for `field2',
14384 the compiler simply tries to allocate a 64-bit "containing
14385 object" at each successive 32-bit boundary (starting at zero)
14386 until it finds a place to allocate that 64- bit field such that
14387 at least 31 contiguous (and previously unallocated) bits remain
14388 within that selected 64 bit field. (As it turns out, for the
14389 example above, the compiler finds it is OK to allocate the
14390 "containing object" 64-bit field at bit-offset zero within the
14393 Here we attempt to work backwards from the limited set of facts
14394 we're given, and we try to deduce from those facts, where GCC
14395 must have believed that the containing object started (within
14396 the structure type). The value we deduce is then used (by the
14397 callers of this routine) to generate DW_AT_location and
14398 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14399 the case of DW_AT_location, regular fields as well). */
14401 /* Figure out the bit-distance from the start of the structure to
14402 the "deepest" bit of the bit-field. */
14403 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14405 /* This is the tricky part. Use some fancy footwork to deduce
14406 where the lowest addressed bit of the containing object must
14408 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14410 /* Round up to type_align by default. This works best for
14412 object_offset_in_bits
14413 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14415 if (object_offset_in_bits
.ugt (bitpos_int
))
14417 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14419 /* Round up to decl_align instead. */
14420 object_offset_in_bits
14421 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14425 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14426 object_offset_in_bits
= bitpos_int
;
14428 object_offset_in_bytes
14429 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14430 true, TRUNC_DIV_EXPR
);
14431 return object_offset_in_bytes
.to_shwi ();
14434 /* The following routines define various Dwarf attributes and any data
14435 associated with them. */
14437 /* Add a location description attribute value to a DIE.
14439 This emits location attributes suitable for whole variables and
14440 whole parameters. Note that the location attributes for struct fields are
14441 generated by the routine `data_member_location_attribute' below. */
14444 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14445 dw_loc_list_ref descr
)
14449 if (single_element_loc_list_p (descr
))
14450 add_AT_loc (die
, attr_kind
, descr
->expr
);
14452 add_AT_loc_list (die
, attr_kind
, descr
);
14455 /* Add DW_AT_accessibility attribute to DIE if needed. */
14458 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14460 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14461 children, otherwise the default is DW_ACCESS_public. In DWARF2
14462 the default has always been DW_ACCESS_public. */
14463 if (TREE_PROTECTED (decl
))
14464 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14465 else if (TREE_PRIVATE (decl
))
14467 if (dwarf_version
== 2
14468 || die
->die_parent
== NULL
14469 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14470 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14472 else if (dwarf_version
> 2
14474 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14475 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14478 /* Attach the specialized form of location attribute used for data members of
14479 struct and union types. In the special case of a FIELD_DECL node which
14480 represents a bit-field, the "offset" part of this special location
14481 descriptor must indicate the distance in bytes from the lowest-addressed
14482 byte of the containing struct or union type to the lowest-addressed byte of
14483 the "containing object" for the bit-field. (See the `field_byte_offset'
14486 For any given bit-field, the "containing object" is a hypothetical object
14487 (of some integral or enum type) within which the given bit-field lives. The
14488 type of this hypothetical "containing object" is always the same as the
14489 declared type of the individual bit-field itself (for GCC anyway... the
14490 DWARF spec doesn't actually mandate this). Note that it is the size (in
14491 bytes) of the hypothetical "containing object" which will be given in the
14492 DW_AT_byte_size attribute for this bit-field. (See the
14493 `byte_size_attribute' function below.) It is also used when calculating the
14494 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14495 function below.) */
14498 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14500 HOST_WIDE_INT offset
;
14501 dw_loc_descr_ref loc_descr
= 0;
14503 if (TREE_CODE (decl
) == TREE_BINFO
)
14505 /* We're working on the TAG_inheritance for a base class. */
14506 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14508 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14509 aren't at a fixed offset from all (sub)objects of the same
14510 type. We need to extract the appropriate offset from our
14511 vtable. The following dwarf expression means
14513 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14515 This is specific to the V3 ABI, of course. */
14517 dw_loc_descr_ref tmp
;
14519 /* Make a copy of the object address. */
14520 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14521 add_loc_descr (&loc_descr
, tmp
);
14523 /* Extract the vtable address. */
14524 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14525 add_loc_descr (&loc_descr
, tmp
);
14527 /* Calculate the address of the offset. */
14528 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14529 gcc_assert (offset
< 0);
14531 tmp
= int_loc_descriptor (-offset
);
14532 add_loc_descr (&loc_descr
, tmp
);
14533 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14534 add_loc_descr (&loc_descr
, tmp
);
14536 /* Extract the offset. */
14537 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14538 add_loc_descr (&loc_descr
, tmp
);
14540 /* Add it to the object address. */
14541 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14542 add_loc_descr (&loc_descr
, tmp
);
14545 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14548 offset
= field_byte_offset (decl
);
14552 if (dwarf_version
> 2)
14554 /* Don't need to output a location expression, just the constant. */
14556 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14558 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14563 enum dwarf_location_atom op
;
14565 /* The DWARF2 standard says that we should assume that the structure
14566 address is already on the stack, so we can specify a structure
14567 field address by using DW_OP_plus_uconst. */
14568 op
= DW_OP_plus_uconst
;
14569 loc_descr
= new_loc_descr (op
, offset
, 0);
14573 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14576 /* Writes integer values to dw_vec_const array. */
14579 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14583 *dest
++ = val
& 0xff;
14589 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14591 static HOST_WIDE_INT
14592 extract_int (const unsigned char *src
, unsigned int size
)
14594 HOST_WIDE_INT val
= 0;
14600 val
|= *--src
& 0xff;
14606 /* Writes double_int values to dw_vec_const array. */
14609 insert_double (double_int val
, unsigned char *dest
)
14611 unsigned char *p0
= dest
;
14612 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14614 if (WORDS_BIG_ENDIAN
)
14620 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14621 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14624 /* Writes floating point values to dw_vec_const array. */
14627 insert_float (const_rtx rtl
, unsigned char *array
)
14629 REAL_VALUE_TYPE rv
;
14633 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14634 real_to_target (val
, &rv
, GET_MODE (rtl
));
14636 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14637 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14639 insert_int (val
[i
], 4, array
);
14644 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14645 does not have a "location" either in memory or in a register. These
14646 things can arise in GNU C when a constant is passed as an actual parameter
14647 to an inlined function. They can also arise in C++ where declared
14648 constants do not necessarily get memory "homes". */
14651 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14653 switch (GET_CODE (rtl
))
14657 HOST_WIDE_INT val
= INTVAL (rtl
);
14660 add_AT_int (die
, DW_AT_const_value
, val
);
14662 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14667 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14668 floating-point constant. A CONST_DOUBLE is used whenever the
14669 constant requires more than one word in order to be adequately
14672 enum machine_mode mode
= GET_MODE (rtl
);
14674 if (SCALAR_FLOAT_MODE_P (mode
))
14676 unsigned int length
= GET_MODE_SIZE (mode
);
14677 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14679 insert_float (rtl
, array
);
14680 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14683 add_AT_double (die
, DW_AT_const_value
,
14684 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14690 enum machine_mode mode
= GET_MODE (rtl
);
14691 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14692 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14693 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14694 (length
* elt_size
);
14698 switch (GET_MODE_CLASS (mode
))
14700 case MODE_VECTOR_INT
:
14701 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14703 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14704 double_int val
= rtx_to_double_int (elt
);
14706 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14707 insert_int (val
.to_shwi (), elt_size
, p
);
14710 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14711 insert_double (val
, p
);
14716 case MODE_VECTOR_FLOAT
:
14717 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14719 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14720 insert_float (elt
, p
);
14725 gcc_unreachable ();
14728 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14733 if (dwarf_version
>= 4 || !dwarf_strict
)
14735 dw_loc_descr_ref loc_result
;
14736 resolve_one_addr (&rtl
, NULL
);
14738 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14739 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14740 add_AT_loc (die
, DW_AT_location
, loc_result
);
14741 vec_safe_push (used_rtx_array
, rtl
);
14747 if (CONSTANT_P (XEXP (rtl
, 0)))
14748 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14751 if (!const_ok_for_output (rtl
))
14754 if (dwarf_version
>= 4 || !dwarf_strict
)
14759 /* In cases where an inlined instance of an inline function is passed
14760 the address of an `auto' variable (which is local to the caller) we
14761 can get a situation where the DECL_RTL of the artificial local
14762 variable (for the inlining) which acts as a stand-in for the
14763 corresponding formal parameter (of the inline function) will look
14764 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14765 exactly a compile-time constant expression, but it isn't the address
14766 of the (artificial) local variable either. Rather, it represents the
14767 *value* which the artificial local variable always has during its
14768 lifetime. We currently have no way to represent such quasi-constant
14769 values in Dwarf, so for now we just punt and generate nothing. */
14777 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14778 && MEM_READONLY_P (rtl
)
14779 && GET_MODE (rtl
) == BLKmode
)
14781 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14787 /* No other kinds of rtx should be possible here. */
14788 gcc_unreachable ();
14793 /* Determine whether the evaluation of EXPR references any variables
14794 or functions which aren't otherwise used (and therefore may not be
14797 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14798 void * data ATTRIBUTE_UNUSED
)
14800 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14801 *walk_subtrees
= 0;
14803 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14804 && ! TREE_ASM_WRITTEN (*tp
))
14806 /* ??? The C++ FE emits debug information for using decls, so
14807 putting gcc_unreachable here falls over. See PR31899. For now
14808 be conservative. */
14809 else if (!cgraph_global_info_ready
14810 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14812 else if (TREE_CODE (*tp
) == VAR_DECL
)
14814 struct varpool_node
*node
= varpool_get_node (*tp
);
14815 if (!node
|| !node
->analyzed
)
14818 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14819 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14821 /* The call graph machinery must have finished analyzing,
14822 optimizing and gimplifying the CU by now.
14823 So if *TP has no call graph node associated
14824 to it, it means *TP will not be emitted. */
14825 if (!cgraph_get_node (*tp
))
14828 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14834 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14835 for use in a later add_const_value_attribute call. */
14838 rtl_for_decl_init (tree init
, tree type
)
14840 rtx rtl
= NULL_RTX
;
14844 /* If a variable is initialized with a string constant without embedded
14845 zeros, build CONST_STRING. */
14846 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14848 tree enttype
= TREE_TYPE (type
);
14849 tree domain
= TYPE_DOMAIN (type
);
14850 enum machine_mode mode
= TYPE_MODE (enttype
);
14852 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14854 && integer_zerop (TYPE_MIN_VALUE (domain
))
14855 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14856 TREE_STRING_LENGTH (init
) - 1) == 0
14857 && ((size_t) TREE_STRING_LENGTH (init
)
14858 == strlen (TREE_STRING_POINTER (init
)) + 1))
14860 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14861 ggc_strdup (TREE_STRING_POINTER (init
)));
14862 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14863 MEM_READONLY_P (rtl
) = 1;
14866 /* Other aggregates, and complex values, could be represented using
14868 else if (AGGREGATE_TYPE_P (type
)
14869 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14870 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14871 || TREE_CODE (type
) == COMPLEX_TYPE
)
14873 /* Vectors only work if their mode is supported by the target.
14874 FIXME: generic vectors ought to work too. */
14875 else if (TREE_CODE (type
) == VECTOR_TYPE
14876 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14878 /* If the initializer is something that we know will expand into an
14879 immediate RTL constant, expand it now. We must be careful not to
14880 reference variables which won't be output. */
14881 else if (initializer_constant_valid_p (init
, type
)
14882 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14884 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14886 if (TREE_CODE (type
) == VECTOR_TYPE
)
14887 switch (TREE_CODE (init
))
14892 if (TREE_CONSTANT (init
))
14894 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
14895 bool constant_p
= true;
14897 unsigned HOST_WIDE_INT ix
;
14899 /* Even when ctor is constant, it might contain non-*_CST
14900 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14901 belong into VECTOR_CST nodes. */
14902 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14903 if (!CONSTANT_CLASS_P (value
))
14905 constant_p
= false;
14911 init
= build_vector_from_ctor (type
, elts
);
14921 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14923 /* If expand_expr returns a MEM, it wasn't immediate. */
14924 gcc_assert (!rtl
|| !MEM_P (rtl
));
14930 /* Generate RTL for the variable DECL to represent its location. */
14933 rtl_for_decl_location (tree decl
)
14937 /* Here we have to decide where we are going to say the parameter "lives"
14938 (as far as the debugger is concerned). We only have a couple of
14939 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14941 DECL_RTL normally indicates where the parameter lives during most of the
14942 activation of the function. If optimization is enabled however, this
14943 could be either NULL or else a pseudo-reg. Both of those cases indicate
14944 that the parameter doesn't really live anywhere (as far as the code
14945 generation parts of GCC are concerned) during most of the function's
14946 activation. That will happen (for example) if the parameter is never
14947 referenced within the function.
14949 We could just generate a location descriptor here for all non-NULL
14950 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14951 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14952 where DECL_RTL is NULL or is a pseudo-reg.
14954 Note however that we can only get away with using DECL_INCOMING_RTL as
14955 a backup substitute for DECL_RTL in certain limited cases. In cases
14956 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14957 we can be sure that the parameter was passed using the same type as it is
14958 declared to have within the function, and that its DECL_INCOMING_RTL
14959 points us to a place where a value of that type is passed.
14961 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14962 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14963 because in these cases DECL_INCOMING_RTL points us to a value of some
14964 type which is *different* from the type of the parameter itself. Thus,
14965 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14966 such cases, the debugger would end up (for example) trying to fetch a
14967 `float' from a place which actually contains the first part of a
14968 `double'. That would lead to really incorrect and confusing
14969 output at debug-time.
14971 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14972 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14973 are a couple of exceptions however. On little-endian machines we can
14974 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14975 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14976 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14977 when (on a little-endian machine) a non-prototyped function has a
14978 parameter declared to be of type `short' or `char'. In such cases,
14979 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14980 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14981 passed `int' value. If the debugger then uses that address to fetch
14982 a `short' or a `char' (on a little-endian machine) the result will be
14983 the correct data, so we allow for such exceptional cases below.
14985 Note that our goal here is to describe the place where the given formal
14986 parameter lives during most of the function's activation (i.e. between the
14987 end of the prologue and the start of the epilogue). We'll do that as best
14988 as we can. Note however that if the given formal parameter is modified
14989 sometime during the execution of the function, then a stack backtrace (at
14990 debug-time) will show the function as having been called with the *new*
14991 value rather than the value which was originally passed in. This happens
14992 rarely enough that it is not a major problem, but it *is* a problem, and
14993 I'd like to fix it.
14995 A future version of dwarf2out.c may generate two additional attributes for
14996 any given DW_TAG_formal_parameter DIE which will describe the "passed
14997 type" and the "passed location" for the given formal parameter in addition
14998 to the attributes we now generate to indicate the "declared type" and the
14999 "active location" for each parameter. This additional set of attributes
15000 could be used by debuggers for stack backtraces. Separately, note that
15001 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15002 This happens (for example) for inlined-instances of inline function formal
15003 parameters which are never referenced. This really shouldn't be
15004 happening. All PARM_DECL nodes should get valid non-NULL
15005 DECL_INCOMING_RTL values. FIXME. */
15007 /* Use DECL_RTL as the "location" unless we find something better. */
15008 rtl
= DECL_RTL_IF_SET (decl
);
15010 /* When generating abstract instances, ignore everything except
15011 constants, symbols living in memory, and symbols living in
15012 fixed registers. */
15013 if (! reload_completed
)
15016 && (CONSTANT_P (rtl
)
15018 && CONSTANT_P (XEXP (rtl
, 0)))
15020 && TREE_CODE (decl
) == VAR_DECL
15021 && TREE_STATIC (decl
))))
15023 rtl
= targetm
.delegitimize_address (rtl
);
15028 else if (TREE_CODE (decl
) == PARM_DECL
)
15030 if (rtl
== NULL_RTX
15031 || is_pseudo_reg (rtl
)
15033 && is_pseudo_reg (XEXP (rtl
, 0))
15034 && DECL_INCOMING_RTL (decl
)
15035 && MEM_P (DECL_INCOMING_RTL (decl
))
15036 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15038 tree declared_type
= TREE_TYPE (decl
);
15039 tree passed_type
= DECL_ARG_TYPE (decl
);
15040 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15041 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15043 /* This decl represents a formal parameter which was optimized out.
15044 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15045 all cases where (rtl == NULL_RTX) just below. */
15046 if (dmode
== pmode
)
15047 rtl
= DECL_INCOMING_RTL (decl
);
15048 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15049 && SCALAR_INT_MODE_P (dmode
)
15050 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15051 && DECL_INCOMING_RTL (decl
))
15053 rtx inc
= DECL_INCOMING_RTL (decl
);
15056 else if (MEM_P (inc
))
15058 if (BYTES_BIG_ENDIAN
)
15059 rtl
= adjust_address_nv (inc
, dmode
,
15060 GET_MODE_SIZE (pmode
)
15061 - GET_MODE_SIZE (dmode
));
15068 /* If the parm was passed in registers, but lives on the stack, then
15069 make a big endian correction if the mode of the type of the
15070 parameter is not the same as the mode of the rtl. */
15071 /* ??? This is the same series of checks that are made in dbxout.c before
15072 we reach the big endian correction code there. It isn't clear if all
15073 of these checks are necessary here, but keeping them all is the safe
15075 else if (MEM_P (rtl
)
15076 && XEXP (rtl
, 0) != const0_rtx
15077 && ! CONSTANT_P (XEXP (rtl
, 0))
15078 /* Not passed in memory. */
15079 && !MEM_P (DECL_INCOMING_RTL (decl
))
15080 /* Not passed by invisible reference. */
15081 && (!REG_P (XEXP (rtl
, 0))
15082 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15083 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15084 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15085 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15088 /* Big endian correction check. */
15089 && BYTES_BIG_ENDIAN
15090 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15091 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15094 enum machine_mode addr_mode
= get_address_mode (rtl
);
15095 int offset
= (UNITS_PER_WORD
15096 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15098 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15099 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15102 else if (TREE_CODE (decl
) == VAR_DECL
15105 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15106 && BYTES_BIG_ENDIAN
)
15108 enum machine_mode addr_mode
= get_address_mode (rtl
);
15109 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15110 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15112 /* If a variable is declared "register" yet is smaller than
15113 a register, then if we store the variable to memory, it
15114 looks like we're storing a register-sized value, when in
15115 fact we are not. We need to adjust the offset of the
15116 storage location to reflect the actual value's bytes,
15117 else gdb will not be able to display it. */
15119 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15120 plus_constant (addr_mode
, XEXP (rtl
, 0),
15124 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15125 and will have been substituted directly into all expressions that use it.
15126 C does not have such a concept, but C++ and other languages do. */
15127 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15128 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15131 rtl
= targetm
.delegitimize_address (rtl
);
15133 /* If we don't look past the constant pool, we risk emitting a
15134 reference to a constant pool entry that isn't referenced from
15135 code, and thus is not emitted. */
15137 rtl
= avoid_constant_pool_reference (rtl
);
15139 /* Try harder to get a rtl. If this symbol ends up not being emitted
15140 in the current CU, resolve_addr will remove the expression referencing
15142 if (rtl
== NULL_RTX
15143 && TREE_CODE (decl
) == VAR_DECL
15144 && !DECL_EXTERNAL (decl
)
15145 && TREE_STATIC (decl
)
15146 && DECL_NAME (decl
)
15147 && !DECL_HARD_REGISTER (decl
)
15148 && DECL_MODE (decl
) != VOIDmode
)
15150 rtl
= make_decl_rtl_for_debug (decl
);
15152 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15153 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15160 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15161 returned. If so, the decl for the COMMON block is returned, and the
15162 value is the offset into the common block for the symbol. */
15165 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15167 tree val_expr
, cvar
;
15168 enum machine_mode mode
;
15169 HOST_WIDE_INT bitsize
, bitpos
;
15171 int unsignedp
, volatilep
= 0;
15173 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15174 it does not have a value (the offset into the common area), or if it
15175 is thread local (as opposed to global) then it isn't common, and shouldn't
15176 be handled as such. */
15177 if (TREE_CODE (decl
) != VAR_DECL
15178 || !TREE_STATIC (decl
)
15179 || !DECL_HAS_VALUE_EXPR_P (decl
)
15183 val_expr
= DECL_VALUE_EXPR (decl
);
15184 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15187 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15188 &mode
, &unsignedp
, &volatilep
, true);
15190 if (cvar
== NULL_TREE
15191 || TREE_CODE (cvar
) != VAR_DECL
15192 || DECL_ARTIFICIAL (cvar
)
15193 || !TREE_PUBLIC (cvar
))
15197 if (offset
!= NULL
)
15199 if (!host_integerp (offset
, 0))
15201 *value
= tree_low_cst (offset
, 0);
15204 *value
+= bitpos
/ BITS_PER_UNIT
;
15209 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15210 data attribute for a variable or a parameter. We generate the
15211 DW_AT_const_value attribute only in those cases where the given variable
15212 or parameter does not have a true "location" either in memory or in a
15213 register. This can happen (for example) when a constant is passed as an
15214 actual argument in a call to an inline function. (It's possible that
15215 these things can crop up in other ways also.) Note that one type of
15216 constant value which can be passed into an inlined function is a constant
15217 pointer. This can happen for example if an actual argument in an inlined
15218 function call evaluates to a compile-time constant address.
15220 CACHE_P is true if it is worth caching the location list for DECL,
15221 so that future calls can reuse it rather than regenerate it from scratch.
15222 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15223 since we will need to refer to them each time the function is inlined. */
15226 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15227 enum dwarf_attribute attr
)
15230 dw_loc_list_ref list
;
15231 var_loc_list
*loc_list
;
15232 cached_dw_loc_list
*cache
;
15235 if (TREE_CODE (decl
) == ERROR_MARK
)
15238 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15239 || TREE_CODE (decl
) == RESULT_DECL
);
15241 /* Try to get some constant RTL for this decl, and use that as the value of
15244 rtl
= rtl_for_decl_location (decl
);
15245 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15246 && add_const_value_attribute (die
, rtl
))
15249 /* See if we have single element location list that is equivalent to
15250 a constant value. That way we are better to use add_const_value_attribute
15251 rather than expanding constant value equivalent. */
15252 loc_list
= lookup_decl_loc (decl
);
15255 && loc_list
->first
->next
== NULL
15256 && NOTE_P (loc_list
->first
->loc
)
15257 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15258 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15260 struct var_loc_node
*node
;
15262 node
= loc_list
->first
;
15263 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15264 if (GET_CODE (rtl
) == EXPR_LIST
)
15265 rtl
= XEXP (rtl
, 0);
15266 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15267 && add_const_value_attribute (die
, rtl
))
15270 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15271 list several times. See if we've already cached the contents. */
15273 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15277 cache
= (cached_dw_loc_list
*)
15278 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15280 list
= cache
->loc_list
;
15284 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15285 /* It is usually worth caching this result if the decl is from
15286 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15287 if (cache_p
&& list
&& list
->dw_loc_next
)
15289 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15290 DECL_UID (decl
), INSERT
);
15291 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15292 cache
->decl_id
= DECL_UID (decl
);
15293 cache
->loc_list
= list
;
15299 add_AT_location_description (die
, attr
, list
);
15302 /* None of that worked, so it must not really have a location;
15303 try adding a constant value attribute from the DECL_INITIAL. */
15304 return tree_add_const_value_attribute_for_decl (die
, decl
);
15307 /* Add VARIABLE and DIE into deferred locations list. */
15310 defer_location (tree variable
, dw_die_ref die
)
15312 deferred_locations entry
;
15313 entry
.variable
= variable
;
15315 vec_safe_push (deferred_locations_list
, entry
);
15318 /* Helper function for tree_add_const_value_attribute. Natively encode
15319 initializer INIT into an array. Return true if successful. */
15322 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15326 if (init
== NULL_TREE
)
15330 switch (TREE_CODE (init
))
15333 type
= TREE_TYPE (init
);
15334 if (TREE_CODE (type
) == ARRAY_TYPE
)
15336 tree enttype
= TREE_TYPE (type
);
15337 enum machine_mode mode
= TYPE_MODE (enttype
);
15339 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15341 if (int_size_in_bytes (type
) != size
)
15343 if (size
> TREE_STRING_LENGTH (init
))
15345 memcpy (array
, TREE_STRING_POINTER (init
),
15346 TREE_STRING_LENGTH (init
));
15347 memset (array
+ TREE_STRING_LENGTH (init
),
15348 '\0', size
- TREE_STRING_LENGTH (init
));
15351 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15356 type
= TREE_TYPE (init
);
15357 if (int_size_in_bytes (type
) != size
)
15359 if (TREE_CODE (type
) == ARRAY_TYPE
)
15361 HOST_WIDE_INT min_index
;
15362 unsigned HOST_WIDE_INT cnt
;
15363 int curpos
= 0, fieldsize
;
15364 constructor_elt
*ce
;
15366 if (TYPE_DOMAIN (type
) == NULL_TREE
15367 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15370 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15371 if (fieldsize
<= 0)
15374 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15375 memset (array
, '\0', size
);
15376 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15378 tree val
= ce
->value
;
15379 tree index
= ce
->index
;
15381 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15382 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15385 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15390 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15393 curpos
= pos
+ fieldsize
;
15394 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15396 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15397 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15398 while (count
-- > 0)
15401 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15402 curpos
+= fieldsize
;
15405 gcc_assert (curpos
<= size
);
15409 else if (TREE_CODE (type
) == RECORD_TYPE
15410 || TREE_CODE (type
) == UNION_TYPE
)
15412 tree field
= NULL_TREE
;
15413 unsigned HOST_WIDE_INT cnt
;
15414 constructor_elt
*ce
;
15416 if (int_size_in_bytes (type
) != size
)
15419 if (TREE_CODE (type
) == RECORD_TYPE
)
15420 field
= TYPE_FIELDS (type
);
15422 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15424 tree val
= ce
->value
;
15425 int pos
, fieldsize
;
15427 if (ce
->index
!= 0)
15433 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15436 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15437 && TYPE_DOMAIN (TREE_TYPE (field
))
15438 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15440 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15441 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15443 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15444 pos
= int_byte_position (field
);
15445 gcc_assert (pos
+ fieldsize
<= size
);
15447 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15453 case VIEW_CONVERT_EXPR
:
15454 case NON_LVALUE_EXPR
:
15455 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15457 return native_encode_expr (init
, array
, size
) == size
;
15461 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15462 attribute is the const value T. */
15465 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15468 tree type
= TREE_TYPE (t
);
15471 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15475 gcc_assert (!DECL_P (init
));
15477 rtl
= rtl_for_decl_init (init
, type
);
15479 return add_const_value_attribute (die
, rtl
);
15480 /* If the host and target are sane, try harder. */
15481 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15482 && initializer_constant_valid_p (init
, type
))
15484 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15485 if (size
> 0 && (int) size
== size
)
15487 unsigned char *array
= (unsigned char *)
15488 ggc_alloc_cleared_atomic (size
);
15490 if (native_encode_initializer (init
, array
, size
))
15492 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15500 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15501 attribute is the const value of T, where T is an integral constant
15502 variable with static storage duration
15503 (so it can't be a PARM_DECL or a RESULT_DECL). */
15506 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15510 || (TREE_CODE (decl
) != VAR_DECL
15511 && TREE_CODE (decl
) != CONST_DECL
)
15512 || (TREE_CODE (decl
) == VAR_DECL
15513 && !TREE_STATIC (decl
)))
15516 if (TREE_READONLY (decl
)
15517 && ! TREE_THIS_VOLATILE (decl
)
15518 && DECL_INITIAL (decl
))
15523 /* Don't add DW_AT_const_value if abstract origin already has one. */
15524 if (get_AT (var_die
, DW_AT_const_value
))
15527 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15530 /* Convert the CFI instructions for the current function into a
15531 location list. This is used for DW_AT_frame_base when we targeting
15532 a dwarf2 consumer that does not support the dwarf3
15533 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15536 static dw_loc_list_ref
15537 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15541 dw_loc_list_ref list
, *list_tail
;
15543 dw_cfa_location last_cfa
, next_cfa
;
15544 const char *start_label
, *last_label
, *section
;
15545 dw_cfa_location remember
;
15548 gcc_assert (fde
!= NULL
);
15550 section
= secname_for_decl (current_function_decl
);
15554 memset (&next_cfa
, 0, sizeof (next_cfa
));
15555 next_cfa
.reg
= INVALID_REGNUM
;
15556 remember
= next_cfa
;
15558 start_label
= fde
->dw_fde_begin
;
15560 /* ??? Bald assumption that the CIE opcode list does not contain
15561 advance opcodes. */
15562 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15563 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15565 last_cfa
= next_cfa
;
15566 last_label
= start_label
;
15568 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15570 /* If the first partition contained no CFI adjustments, the
15571 CIE opcodes apply to the whole first partition. */
15572 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15573 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15574 list_tail
=&(*list_tail
)->dw_loc_next
;
15575 start_label
= last_label
= fde
->dw_fde_second_begin
;
15578 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15580 switch (cfi
->dw_cfi_opc
)
15582 case DW_CFA_set_loc
:
15583 case DW_CFA_advance_loc1
:
15584 case DW_CFA_advance_loc2
:
15585 case DW_CFA_advance_loc4
:
15586 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15588 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15589 start_label
, last_label
, section
);
15591 list_tail
= &(*list_tail
)->dw_loc_next
;
15592 last_cfa
= next_cfa
;
15593 start_label
= last_label
;
15595 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15598 case DW_CFA_advance_loc
:
15599 /* The encoding is complex enough that we should never emit this. */
15600 gcc_unreachable ();
15603 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15606 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15608 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15610 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15611 start_label
, last_label
, section
);
15613 list_tail
= &(*list_tail
)->dw_loc_next
;
15614 last_cfa
= next_cfa
;
15615 start_label
= last_label
;
15617 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15618 start_label
, fde
->dw_fde_end
, section
);
15619 list_tail
= &(*list_tail
)->dw_loc_next
;
15620 start_label
= last_label
= fde
->dw_fde_second_begin
;
15624 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15626 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15627 start_label
, last_label
, section
);
15628 list_tail
= &(*list_tail
)->dw_loc_next
;
15629 start_label
= last_label
;
15632 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15634 fde
->dw_fde_second_begin
15635 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15638 if (list
&& list
->dw_loc_next
)
15644 /* Compute a displacement from the "steady-state frame pointer" to the
15645 frame base (often the same as the CFA), and store it in
15646 frame_pointer_fb_offset. OFFSET is added to the displacement
15647 before the latter is negated. */
15650 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15654 #ifdef FRAME_POINTER_CFA_OFFSET
15655 reg
= frame_pointer_rtx
;
15656 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15658 reg
= arg_pointer_rtx
;
15659 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15662 elim
= (ira_use_lra_p
15663 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15664 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15665 if (GET_CODE (elim
) == PLUS
)
15667 offset
+= INTVAL (XEXP (elim
, 1));
15668 elim
= XEXP (elim
, 0);
15671 frame_pointer_fb_offset
= -offset
;
15673 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15674 in which to eliminate. This is because it's stack pointer isn't
15675 directly accessible as a register within the ISA. To work around
15676 this, assume that while we cannot provide a proper value for
15677 frame_pointer_fb_offset, we won't need one either. */
15678 frame_pointer_fb_offset_valid
15679 = ((SUPPORTS_STACK_ALIGNMENT
15680 && (elim
== hard_frame_pointer_rtx
15681 || elim
== stack_pointer_rtx
))
15682 || elim
== (frame_pointer_needed
15683 ? hard_frame_pointer_rtx
15684 : stack_pointer_rtx
));
15687 /* Generate a DW_AT_name attribute given some string value to be included as
15688 the value of the attribute. */
15691 add_name_attribute (dw_die_ref die
, const char *name_string
)
15693 if (name_string
!= NULL
&& *name_string
!= 0)
15695 if (demangle_name_func
)
15696 name_string
= (*demangle_name_func
) (name_string
);
15698 add_AT_string (die
, DW_AT_name
, name_string
);
15702 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15703 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15704 of TYPE accordingly.
15706 ??? This is a temporary measure until after we're able to generate
15707 regular DWARF for the complex Ada type system. */
15710 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15711 dw_die_ref context_die
)
15714 dw_die_ref dtype_die
;
15716 if (!lang_hooks
.types
.descriptive_type
)
15719 dtype
= lang_hooks
.types
.descriptive_type (type
);
15723 dtype_die
= lookup_type_die (dtype
);
15726 gen_type_die (dtype
, context_die
);
15727 dtype_die
= lookup_type_die (dtype
);
15728 gcc_assert (dtype_die
);
15731 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15734 /* Generate a DW_AT_comp_dir attribute for DIE. */
15737 add_comp_dir_attribute (dw_die_ref die
)
15739 const char *wd
= get_src_pwd ();
15745 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15749 wdlen
= strlen (wd
);
15750 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15752 wd1
[wdlen
] = DIR_SEPARATOR
;
15753 wd1
[wdlen
+ 1] = 0;
15757 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15760 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15764 lower_bound_default (void)
15766 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15771 case DW_LANG_C_plus_plus
:
15773 case DW_LANG_ObjC_plus_plus
:
15776 case DW_LANG_Fortran77
:
15777 case DW_LANG_Fortran90
:
15778 case DW_LANG_Fortran95
:
15782 case DW_LANG_Python
:
15783 return dwarf_version
>= 4 ? 0 : -1;
15784 case DW_LANG_Ada95
:
15785 case DW_LANG_Ada83
:
15786 case DW_LANG_Cobol74
:
15787 case DW_LANG_Cobol85
:
15788 case DW_LANG_Pascal83
:
15789 case DW_LANG_Modula2
:
15791 return dwarf_version
>= 4 ? 1 : -1;
15797 /* Given a tree node describing an array bound (either lower or upper) output
15798 a representation for that bound. */
15801 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15803 switch (TREE_CODE (bound
))
15808 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15811 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15814 /* Use the default if possible. */
15815 if (bound_attr
== DW_AT_lower_bound
15816 && host_integerp (bound
, 0)
15817 && (dflt
= lower_bound_default ()) != -1
15818 && tree_low_cst (bound
, 0) == dflt
)
15821 /* Otherwise represent the bound as an unsigned value with the
15822 precision of its type. The precision and signedness of the
15823 type will be necessary to re-interpret it unambiguously. */
15824 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15826 unsigned HOST_WIDE_INT mask
15827 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15828 add_AT_unsigned (subrange_die
, bound_attr
,
15829 TREE_INT_CST_LOW (bound
) & mask
);
15831 else if (prec
== HOST_BITS_PER_WIDE_INT
15832 || TREE_INT_CST_HIGH (bound
) == 0)
15833 add_AT_unsigned (subrange_die
, bound_attr
,
15834 TREE_INT_CST_LOW (bound
));
15836 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15837 TREE_INT_CST_LOW (bound
));
15842 case VIEW_CONVERT_EXPR
:
15843 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15853 dw_die_ref decl_die
= lookup_decl_die (bound
);
15855 /* ??? Can this happen, or should the variable have been bound
15856 first? Probably it can, since I imagine that we try to create
15857 the types of parameters in the order in which they exist in
15858 the list, and won't have created a forward reference to a
15859 later parameter. */
15860 if (decl_die
!= NULL
)
15862 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15870 /* Otherwise try to create a stack operation procedure to
15871 evaluate the value of the array bound. */
15873 dw_die_ref ctx
, decl_die
;
15874 dw_loc_list_ref list
;
15876 list
= loc_list_from_tree (bound
, 2);
15877 if (list
== NULL
|| single_element_loc_list_p (list
))
15879 /* If DW_AT_*bound is not a reference nor constant, it is
15880 a DWARF expression rather than location description.
15881 For that loc_list_from_tree (bound, 0) is needed.
15882 If that fails to give a single element list,
15883 fall back to outputting this as a reference anyway. */
15884 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15885 if (list2
&& single_element_loc_list_p (list2
))
15887 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15894 if (current_function_decl
== 0)
15895 ctx
= comp_unit_die ();
15897 ctx
= lookup_decl_die (current_function_decl
);
15899 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15900 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15901 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15902 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15903 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15909 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15910 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15911 Note that the block of subscript information for an array type also
15912 includes information about the element type of the given array type. */
15915 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15917 unsigned dimension_number
;
15919 dw_die_ref subrange_die
;
15921 for (dimension_number
= 0;
15922 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15923 type
= TREE_TYPE (type
), dimension_number
++)
15925 tree domain
= TYPE_DOMAIN (type
);
15927 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15930 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15931 and (in GNU C only) variable bounds. Handle all three forms
15933 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15936 /* We have an array type with specified bounds. */
15937 lower
= TYPE_MIN_VALUE (domain
);
15938 upper
= TYPE_MAX_VALUE (domain
);
15940 /* Define the index type. */
15941 if (TREE_TYPE (domain
))
15943 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15944 TREE_TYPE field. We can't emit debug info for this
15945 because it is an unnamed integral type. */
15946 if (TREE_CODE (domain
) == INTEGER_TYPE
15947 && TYPE_NAME (domain
) == NULL_TREE
15948 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15949 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15952 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15956 /* ??? If upper is NULL, the array has unspecified length,
15957 but it does have a lower bound. This happens with Fortran
15959 Since the debugger is definitely going to need to know N
15960 to produce useful results, go ahead and output the lower
15961 bound solo, and hope the debugger can cope. */
15963 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15965 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15968 /* Otherwise we have an array type with an unspecified length. The
15969 DWARF-2 spec does not say how to handle this; let's just leave out the
15975 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
15977 dw_die_ref decl_die
;
15980 switch (TREE_CODE (tree_node
))
15985 case ENUMERAL_TYPE
:
15988 case QUAL_UNION_TYPE
:
15989 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
15990 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
15992 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
15995 size
= int_size_in_bytes (tree_node
);
15998 /* For a data member of a struct or union, the DW_AT_byte_size is
15999 generally given as the number of bytes normally allocated for an
16000 object of the *declared* type of the member itself. This is true
16001 even for bit-fields. */
16002 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16005 gcc_unreachable ();
16008 /* Note that `size' might be -1 when we get to this point. If it is, that
16009 indicates that the byte size of the entity in question is variable. We
16010 have no good way of expressing this fact in Dwarf at the present time,
16011 so just let the -1 pass on through. */
16012 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16015 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16016 which specifies the distance in bits from the highest order bit of the
16017 "containing object" for the bit-field to the highest order bit of the
16020 For any given bit-field, the "containing object" is a hypothetical object
16021 (of some integral or enum type) within which the given bit-field lives. The
16022 type of this hypothetical "containing object" is always the same as the
16023 declared type of the individual bit-field itself. The determination of the
16024 exact location of the "containing object" for a bit-field is rather
16025 complicated. It's handled by the `field_byte_offset' function (above).
16027 Note that it is the size (in bytes) of the hypothetical "containing object"
16028 which will be given in the DW_AT_byte_size attribute for this bit-field.
16029 (See `byte_size_attribute' above). */
16032 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16034 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16035 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16036 HOST_WIDE_INT bitpos_int
;
16037 HOST_WIDE_INT highest_order_object_bit_offset
;
16038 HOST_WIDE_INT highest_order_field_bit_offset
;
16039 HOST_WIDE_INT bit_offset
;
16041 /* Must be a field and a bit field. */
16042 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16044 /* We can't yet handle bit-fields whose offsets are variable, so if we
16045 encounter such things, just return without generating any attribute
16046 whatsoever. Likewise for variable or too large size. */
16047 if (! host_integerp (bit_position (decl
), 0)
16048 || ! host_integerp (DECL_SIZE (decl
), 1))
16051 bitpos_int
= int_bit_position (decl
);
16053 /* Note that the bit offset is always the distance (in bits) from the
16054 highest-order bit of the "containing object" to the highest-order bit of
16055 the bit-field itself. Since the "high-order end" of any object or field
16056 is different on big-endian and little-endian machines, the computation
16057 below must take account of these differences. */
16058 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16059 highest_order_field_bit_offset
= bitpos_int
;
16061 if (! BYTES_BIG_ENDIAN
)
16063 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16064 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16068 = (! BYTES_BIG_ENDIAN
16069 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16070 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16072 if (bit_offset
< 0)
16073 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16075 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16078 /* For a FIELD_DECL node which represents a bit field, output an attribute
16079 which specifies the length in bits of the given field. */
16082 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16084 /* Must be a field and a bit field. */
16085 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16086 && DECL_BIT_FIELD_TYPE (decl
));
16088 if (host_integerp (DECL_SIZE (decl
), 1))
16089 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16092 /* If the compiled language is ANSI C, then add a 'prototyped'
16093 attribute, if arg types are given for the parameters of a function. */
16096 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16098 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16099 && prototype_p (func_type
))
16100 add_AT_flag (die
, DW_AT_prototyped
, 1);
16103 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16104 by looking in either the type declaration or object declaration
16107 static inline dw_die_ref
16108 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16110 dw_die_ref origin_die
= NULL
;
16112 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16114 /* We may have gotten separated from the block for the inlined
16115 function, if we're in an exception handler or some such; make
16116 sure that the abstract function has been written out.
16118 Doing this for nested functions is wrong, however; functions are
16119 distinct units, and our context might not even be inline. */
16123 fn
= TYPE_STUB_DECL (fn
);
16125 fn
= decl_function_context (fn
);
16127 dwarf2out_abstract_function (fn
);
16130 if (DECL_P (origin
))
16131 origin_die
= lookup_decl_die (origin
);
16132 else if (TYPE_P (origin
))
16133 origin_die
= lookup_type_die (origin
);
16135 /* XXX: Functions that are never lowered don't always have correct block
16136 trees (in the case of java, they simply have no block tree, in some other
16137 languages). For these functions, there is nothing we can really do to
16138 output correct debug info for inlined functions in all cases. Rather
16139 than die, we'll just produce deficient debug info now, in that we will
16140 have variables without a proper abstract origin. In the future, when all
16141 functions are lowered, we should re-add a gcc_assert (origin_die)
16145 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16149 /* We do not currently support the pure_virtual attribute. */
16152 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16154 if (DECL_VINDEX (func_decl
))
16156 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16158 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16159 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16160 new_loc_descr (DW_OP_constu
,
16161 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16164 /* GNU extension: Record what type this method came from originally. */
16165 if (debug_info_level
> DINFO_LEVEL_TERSE
16166 && DECL_CONTEXT (func_decl
))
16167 add_AT_die_ref (die
, DW_AT_containing_type
,
16168 lookup_type_die (DECL_CONTEXT (func_decl
)));
16172 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16173 given decl. This used to be a vendor extension until after DWARF 4
16174 standardized it. */
16177 add_linkage_attr (dw_die_ref die
, tree decl
)
16179 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16181 /* Mimic what assemble_name_raw does with a leading '*'. */
16182 if (name
[0] == '*')
16185 if (dwarf_version
>= 4)
16186 add_AT_string (die
, DW_AT_linkage_name
, name
);
16188 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16191 /* Add source coordinate attributes for the given decl. */
16194 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16196 expanded_location s
;
16198 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16200 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16201 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16202 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16205 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16208 add_linkage_name (dw_die_ref die
, tree decl
)
16210 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16211 && TREE_PUBLIC (decl
)
16212 && !DECL_ABSTRACT (decl
)
16213 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16214 && die
->die_tag
!= DW_TAG_member
)
16216 /* Defer until we have an assembler name set. */
16217 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16219 limbo_die_node
*asm_name
;
16221 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16222 asm_name
->die
= die
;
16223 asm_name
->created_for
= decl
;
16224 asm_name
->next
= deferred_asm_name
;
16225 deferred_asm_name
= asm_name
;
16227 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16228 add_linkage_attr (die
, decl
);
16232 /* Add a DW_AT_name attribute and source coordinate attribute for the
16233 given decl, but only if it actually has a name. */
16236 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16240 decl_name
= DECL_NAME (decl
);
16241 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16243 const char *name
= dwarf2_name (decl
, 0);
16245 add_name_attribute (die
, name
);
16246 if (! DECL_ARTIFICIAL (decl
))
16247 add_src_coords_attributes (die
, decl
);
16249 add_linkage_name (die
, decl
);
16252 #ifdef VMS_DEBUGGING_INFO
16253 /* Get the function's name, as described by its RTL. This may be different
16254 from the DECL_NAME name used in the source file. */
16255 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16257 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16258 XEXP (DECL_RTL (decl
), 0), false);
16259 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16261 #endif /* VMS_DEBUGGING_INFO */
16264 #ifdef VMS_DEBUGGING_INFO
16265 /* Output the debug main pointer die for VMS */
16268 dwarf2out_vms_debug_main_pointer (void)
16270 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16273 /* Allocate the VMS debug main subprogram die. */
16274 die
= ggc_alloc_cleared_die_node ();
16275 die
->die_tag
= DW_TAG_subprogram
;
16276 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16277 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16278 current_function_funcdef_no
);
16279 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16281 /* Make it the first child of comp_unit_die (). */
16282 die
->die_parent
= comp_unit_die ();
16283 if (comp_unit_die ()->die_child
)
16285 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16286 comp_unit_die ()->die_child
->die_sib
= die
;
16290 die
->die_sib
= die
;
16291 comp_unit_die ()->die_child
= die
;
16294 #endif /* VMS_DEBUGGING_INFO */
16296 /* Push a new declaration scope. */
16299 push_decl_scope (tree scope
)
16301 vec_safe_push (decl_scope_table
, scope
);
16304 /* Pop a declaration scope. */
16307 pop_decl_scope (void)
16309 decl_scope_table
->pop ();
16312 /* walk_tree helper function for uses_local_type, below. */
16315 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16318 *walk_subtrees
= 0;
16321 tree name
= TYPE_NAME (*tp
);
16322 if (name
&& DECL_P (name
) && decl_function_context (name
))
16328 /* If TYPE involves a function-local type (including a local typedef to a
16329 non-local type), returns that type; otherwise returns NULL_TREE. */
16332 uses_local_type (tree type
)
16334 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16338 /* Return the DIE for the scope that immediately contains this type.
16339 Non-named types that do not involve a function-local type get global
16340 scope. Named types nested in namespaces or other types get their
16341 containing scope. All other types (i.e. function-local named types) get
16342 the current active scope. */
16345 scope_die_for (tree t
, dw_die_ref context_die
)
16347 dw_die_ref scope_die
= NULL
;
16348 tree containing_scope
;
16350 /* Non-types always go in the current scope. */
16351 gcc_assert (TYPE_P (t
));
16353 /* Use the scope of the typedef, rather than the scope of the type
16355 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16356 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16358 containing_scope
= TYPE_CONTEXT (t
);
16360 /* Use the containing namespace if there is one. */
16361 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16363 if (context_die
== lookup_decl_die (containing_scope
))
16365 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16366 context_die
= get_context_die (containing_scope
);
16368 containing_scope
= NULL_TREE
;
16371 /* Ignore function type "scopes" from the C frontend. They mean that
16372 a tagged type is local to a parmlist of a function declarator, but
16373 that isn't useful to DWARF. */
16374 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16375 containing_scope
= NULL_TREE
;
16377 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16379 /* If T uses a local type keep it local as well, to avoid references
16380 to function-local DIEs from outside the function. */
16381 if (current_function_decl
&& uses_local_type (t
))
16382 scope_die
= context_die
;
16384 scope_die
= comp_unit_die ();
16386 else if (TYPE_P (containing_scope
))
16388 /* For types, we can just look up the appropriate DIE. */
16389 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16390 scope_die
= get_context_die (containing_scope
);
16393 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16394 if (scope_die
== NULL
)
16395 scope_die
= comp_unit_die ();
16399 scope_die
= context_die
;
16404 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16407 local_scope_p (dw_die_ref context_die
)
16409 for (; context_die
; context_die
= context_die
->die_parent
)
16410 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16411 || context_die
->die_tag
== DW_TAG_subprogram
)
16417 /* Returns nonzero if CONTEXT_DIE is a class. */
16420 class_scope_p (dw_die_ref context_die
)
16422 return (context_die
16423 && (context_die
->die_tag
== DW_TAG_structure_type
16424 || context_die
->die_tag
== DW_TAG_class_type
16425 || context_die
->die_tag
== DW_TAG_interface_type
16426 || context_die
->die_tag
== DW_TAG_union_type
));
16429 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16430 whether or not to treat a DIE in this context as a declaration. */
16433 class_or_namespace_scope_p (dw_die_ref context_die
)
16435 return (class_scope_p (context_die
)
16436 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16439 /* Many forms of DIEs require a "type description" attribute. This
16440 routine locates the proper "type descriptor" die for the type given
16441 by 'type', and adds a DW_AT_type attribute below the given die. */
16444 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16445 int decl_volatile
, dw_die_ref context_die
)
16447 enum tree_code code
= TREE_CODE (type
);
16448 dw_die_ref type_die
= NULL
;
16450 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16451 or fixed-point type, use the inner type. This is because we have no
16452 support for unnamed types in base_type_die. This can happen if this is
16453 an Ada subrange type. Correct solution is emit a subrange type die. */
16454 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16455 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16456 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16458 if (code
== ERROR_MARK
16459 /* Handle a special case. For functions whose return type is void, we
16460 generate *no* type attribute. (Note that no object may have type
16461 `void', so this only applies to function return types). */
16462 || code
== VOID_TYPE
)
16465 type_die
= modified_type_die (type
,
16466 decl_const
|| TYPE_READONLY (type
),
16467 decl_volatile
|| TYPE_VOLATILE (type
),
16470 if (type_die
!= NULL
)
16471 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16474 /* Given an object die, add the calling convention attribute for the
16475 function call type. */
16477 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16479 enum dwarf_calling_convention value
= DW_CC_normal
;
16481 value
= ((enum dwarf_calling_convention
)
16482 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16485 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16487 /* DWARF 2 doesn't provide a way to identify a program's source-level
16488 entry point. DW_AT_calling_convention attributes are only meant
16489 to describe functions' calling conventions. However, lacking a
16490 better way to signal the Fortran main program, we used this for
16491 a long time, following existing custom. Now, DWARF 4 has
16492 DW_AT_main_subprogram, which we add below, but some tools still
16493 rely on the old way, which we thus keep. */
16494 value
= DW_CC_program
;
16496 if (dwarf_version
>= 4 || !dwarf_strict
)
16497 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16500 /* Only add the attribute if the backend requests it, and
16501 is not DW_CC_normal. */
16502 if (value
&& (value
!= DW_CC_normal
))
16503 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16506 /* Given a tree pointer to a struct, class, union, or enum type node, return
16507 a pointer to the (string) tag name for the given type, or zero if the type
16508 was declared without a tag. */
16510 static const char *
16511 type_tag (const_tree type
)
16513 const char *name
= 0;
16515 if (TYPE_NAME (type
) != 0)
16519 /* Find the IDENTIFIER_NODE for the type name. */
16520 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16521 && !TYPE_NAMELESS (type
))
16522 t
= TYPE_NAME (type
);
16524 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16525 a TYPE_DECL node, regardless of whether or not a `typedef' was
16527 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16528 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16530 /* We want to be extra verbose. Don't call dwarf_name if
16531 DECL_NAME isn't set. The default hook for decl_printable_name
16532 doesn't like that, and in this context it's correct to return
16533 0, instead of "<anonymous>" or the like. */
16534 if (DECL_NAME (TYPE_NAME (type
))
16535 && !DECL_NAMELESS (TYPE_NAME (type
)))
16536 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16539 /* Now get the name as a string, or invent one. */
16540 if (!name
&& t
!= 0)
16541 name
= IDENTIFIER_POINTER (t
);
16544 return (name
== 0 || *name
== '\0') ? 0 : name
;
16547 /* Return the type associated with a data member, make a special check
16548 for bit field types. */
16551 member_declared_type (const_tree member
)
16553 return (DECL_BIT_FIELD_TYPE (member
)
16554 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16557 /* Get the decl's label, as described by its RTL. This may be different
16558 from the DECL_NAME name used in the source file. */
16561 static const char *
16562 decl_start_label (tree decl
)
16565 const char *fnname
;
16567 x
= DECL_RTL (decl
);
16568 gcc_assert (MEM_P (x
));
16571 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16573 fnname
= XSTR (x
, 0);
16578 /* These routines generate the internal representation of the DIE's for
16579 the compilation unit. Debugging information is collected by walking
16580 the declaration trees passed in from dwarf2out_decl(). */
16583 gen_array_type_die (tree type
, dw_die_ref context_die
)
16585 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16586 dw_die_ref array_die
;
16588 /* GNU compilers represent multidimensional array types as sequences of one
16589 dimensional array types whose element types are themselves array types.
16590 We sometimes squish that down to a single array_type DIE with multiple
16591 subscripts in the Dwarf debugging info. The draft Dwarf specification
16592 say that we are allowed to do this kind of compression in C, because
16593 there is no difference between an array of arrays and a multidimensional
16594 array. We don't do this for Ada to remain as close as possible to the
16595 actual representation, which is especially important against the language
16596 flexibilty wrt arrays of variable size. */
16598 bool collapse_nested_arrays
= !is_ada ();
16601 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16602 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16603 if (TYPE_STRING_FLAG (type
)
16604 && TREE_CODE (type
) == ARRAY_TYPE
16606 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16608 HOST_WIDE_INT size
;
16610 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16611 add_name_attribute (array_die
, type_tag (type
));
16612 equate_type_number_to_die (type
, array_die
);
16613 size
= int_size_in_bytes (type
);
16615 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16616 else if (TYPE_DOMAIN (type
) != NULL_TREE
16617 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16618 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16620 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16621 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16623 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16624 if (loc
&& size
> 0)
16626 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16627 if (size
!= DWARF2_ADDR_SIZE
)
16628 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16634 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16635 add_name_attribute (array_die
, type_tag (type
));
16636 equate_type_number_to_die (type
, array_die
);
16638 if (TREE_CODE (type
) == VECTOR_TYPE
)
16639 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16641 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16643 && TREE_CODE (type
) == ARRAY_TYPE
16644 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16645 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16646 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16649 /* We default the array ordering. SDB will probably do
16650 the right things even if DW_AT_ordering is not present. It's not even
16651 an issue until we start to get into multidimensional arrays anyway. If
16652 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16653 then we'll have to put the DW_AT_ordering attribute back in. (But if
16654 and when we find out that we need to put these in, we will only do so
16655 for multidimensional arrays. */
16656 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16659 if (TREE_CODE (type
) == VECTOR_TYPE
)
16661 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16662 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16663 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16664 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16665 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16668 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16670 /* Add representation of the type of the elements of this array type and
16671 emit the corresponding DIE if we haven't done it already. */
16672 element_type
= TREE_TYPE (type
);
16673 if (collapse_nested_arrays
)
16674 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16676 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16678 element_type
= TREE_TYPE (element_type
);
16681 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16683 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16684 if (TYPE_ARTIFICIAL (type
))
16685 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16687 if (get_AT (array_die
, DW_AT_name
))
16688 add_pubtype (type
, array_die
);
16691 static dw_loc_descr_ref
16692 descr_info_loc (tree val
, tree base_decl
)
16694 HOST_WIDE_INT size
;
16695 dw_loc_descr_ref loc
, loc2
;
16696 enum dwarf_location_atom op
;
16698 if (val
== base_decl
)
16699 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16701 switch (TREE_CODE (val
))
16704 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16706 return loc_descriptor_from_tree (val
, 0);
16708 if (host_integerp (val
, 0))
16709 return int_loc_descriptor (tree_low_cst (val
, 0));
16712 size
= int_size_in_bytes (TREE_TYPE (val
));
16715 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16718 if (size
== DWARF2_ADDR_SIZE
)
16719 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16721 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16723 case POINTER_PLUS_EXPR
:
16725 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16726 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16729 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16732 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16738 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16741 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16744 add_loc_descr (&loc
, loc2
);
16745 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16767 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16768 tree val
, tree base_decl
)
16770 dw_loc_descr_ref loc
;
16772 if (host_integerp (val
, 0))
16774 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16778 loc
= descr_info_loc (val
, base_decl
);
16782 add_AT_loc (die
, attr
, loc
);
16785 /* This routine generates DIE for array with hidden descriptor, details
16786 are filled into *info by a langhook. */
16789 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16790 dw_die_ref context_die
)
16792 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16793 dw_die_ref array_die
;
16796 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16797 add_name_attribute (array_die
, type_tag (type
));
16798 equate_type_number_to_die (type
, array_die
);
16800 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16802 && info
->ndimensions
>= 2)
16803 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16805 if (info
->data_location
)
16806 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16808 if (info
->associated
)
16809 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16811 if (info
->allocated
)
16812 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16815 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16817 dw_die_ref subrange_die
16818 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16820 if (info
->dimen
[dim
].lower_bound
)
16822 /* If it is the default value, omit it. */
16825 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16826 && (dflt
= lower_bound_default ()) != -1
16827 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16830 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16831 info
->dimen
[dim
].lower_bound
,
16834 if (info
->dimen
[dim
].upper_bound
)
16835 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16836 info
->dimen
[dim
].upper_bound
,
16838 if (info
->dimen
[dim
].stride
)
16839 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16840 info
->dimen
[dim
].stride
,
16844 gen_type_die (info
->element_type
, context_die
);
16845 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16847 if (get_AT (array_die
, DW_AT_name
))
16848 add_pubtype (type
, array_die
);
16853 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16855 tree origin
= decl_ultimate_origin (decl
);
16856 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16858 if (origin
!= NULL
)
16859 add_abstract_origin_attribute (decl_die
, origin
);
16862 add_name_and_src_coords_attributes (decl_die
, decl
);
16863 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16864 0, 0, context_die
);
16867 if (DECL_ABSTRACT (decl
))
16868 equate_decl_number_to_die (decl
, decl_die
);
16870 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16874 /* Walk through the list of incomplete types again, trying once more to
16875 emit full debugging info for them. */
16878 retry_incomplete_types (void)
16882 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
16883 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
16884 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
16887 /* Determine what tag to use for a record type. */
16889 static enum dwarf_tag
16890 record_type_tag (tree type
)
16892 if (! lang_hooks
.types
.classify_record
)
16893 return DW_TAG_structure_type
;
16895 switch (lang_hooks
.types
.classify_record (type
))
16897 case RECORD_IS_STRUCT
:
16898 return DW_TAG_structure_type
;
16900 case RECORD_IS_CLASS
:
16901 return DW_TAG_class_type
;
16903 case RECORD_IS_INTERFACE
:
16904 if (dwarf_version
>= 3 || !dwarf_strict
)
16905 return DW_TAG_interface_type
;
16906 return DW_TAG_structure_type
;
16909 gcc_unreachable ();
16913 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16914 include all of the information about the enumeration values also. Each
16915 enumerated type name/value is listed as a child of the enumerated type
16919 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16921 dw_die_ref type_die
= lookup_type_die (type
);
16923 if (type_die
== NULL
)
16925 type_die
= new_die (DW_TAG_enumeration_type
,
16926 scope_die_for (type
, context_die
), type
);
16927 equate_type_number_to_die (type
, type_die
);
16928 add_name_attribute (type_die
, type_tag (type
));
16929 if (dwarf_version
>= 4 || !dwarf_strict
)
16931 if (ENUM_IS_SCOPED (type
))
16932 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16933 if (ENUM_IS_OPAQUE (type
))
16934 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16937 else if (! TYPE_SIZE (type
))
16940 remove_AT (type_die
, DW_AT_declaration
);
16942 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16943 given enum type is incomplete, do not generate the DW_AT_byte_size
16944 attribute or the DW_AT_element_list attribute. */
16945 if (TYPE_SIZE (type
))
16949 TREE_ASM_WRITTEN (type
) = 1;
16950 add_byte_size_attribute (type_die
, type
);
16951 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16953 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16954 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16957 /* If the first reference to this type was as the return type of an
16958 inline function, then it may not have a parent. Fix this now. */
16959 if (type_die
->die_parent
== NULL
)
16960 add_child_die (scope_die_for (type
, context_die
), type_die
);
16962 for (link
= TYPE_VALUES (type
);
16963 link
!= NULL
; link
= TREE_CHAIN (link
))
16965 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16966 tree value
= TREE_VALUE (link
);
16968 add_name_attribute (enum_die
,
16969 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16971 if (TREE_CODE (value
) == CONST_DECL
)
16972 value
= DECL_INITIAL (value
);
16974 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
16975 /* DWARF2 does not provide a way of indicating whether or
16976 not enumeration constants are signed or unsigned. GDB
16977 always assumes the values are signed, so we output all
16978 values as if they were signed. That means that
16979 enumeration constants with very large unsigned values
16980 will appear to have negative values in the debugger. */
16981 add_AT_int (enum_die
, DW_AT_const_value
,
16982 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
16985 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
16986 if (TYPE_ARTIFICIAL (type
))
16987 add_AT_flag (type_die
, DW_AT_artificial
, 1);
16990 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16992 add_pubtype (type
, type_die
);
16997 /* Generate a DIE to represent either a real live formal parameter decl or to
16998 represent just the type of some formal parameter position in some function
17001 Note that this routine is a bit unusual because its argument may be a
17002 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17003 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17004 node. If it's the former then this function is being called to output a
17005 DIE to represent a formal parameter object (or some inlining thereof). If
17006 it's the latter, then this function is only being called to output a
17007 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17008 argument type of some subprogram type.
17009 If EMIT_NAME_P is true, name and source coordinate attributes
17013 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17014 dw_die_ref context_die
)
17016 tree node_or_origin
= node
? node
: origin
;
17017 tree ultimate_origin
;
17018 dw_die_ref parm_die
17019 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17021 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17023 case tcc_declaration
:
17024 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17025 if (node
|| ultimate_origin
)
17026 origin
= ultimate_origin
;
17027 if (origin
!= NULL
)
17028 add_abstract_origin_attribute (parm_die
, origin
);
17029 else if (emit_name_p
)
17030 add_name_and_src_coords_attributes (parm_die
, node
);
17032 || (! DECL_ABSTRACT (node_or_origin
)
17033 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17034 decl_function_context
17035 (node_or_origin
))))
17037 tree type
= TREE_TYPE (node_or_origin
);
17038 if (decl_by_reference_p (node_or_origin
))
17039 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17042 add_type_attribute (parm_die
, type
,
17043 TREE_READONLY (node_or_origin
),
17044 TREE_THIS_VOLATILE (node_or_origin
),
17047 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17048 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17050 if (node
&& node
!= origin
)
17051 equate_decl_number_to_die (node
, parm_die
);
17052 if (! DECL_ABSTRACT (node_or_origin
))
17053 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17054 node
== NULL
, DW_AT_location
);
17059 /* We were called with some kind of a ..._TYPE node. */
17060 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17064 gcc_unreachable ();
17070 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17071 children DW_TAG_formal_parameter DIEs representing the arguments of the
17074 PARM_PACK must be a function parameter pack.
17075 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17076 must point to the subsequent arguments of the function PACK_ARG belongs to.
17077 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17078 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17079 following the last one for which a DIE was generated. */
17082 gen_formal_parameter_pack_die (tree parm_pack
,
17084 dw_die_ref subr_die
,
17088 dw_die_ref parm_pack_die
;
17090 gcc_assert (parm_pack
17091 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17094 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17095 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17097 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17099 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17102 gen_formal_parameter_die (arg
, NULL
,
17103 false /* Don't emit name attribute. */,
17108 return parm_pack_die
;
17111 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17112 at the end of an (ANSI prototyped) formal parameters list. */
17115 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17117 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17120 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17121 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17122 parameters as specified in some function type specification (except for
17123 those which appear as part of a function *definition*). */
17126 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17129 tree formal_type
= NULL
;
17130 tree first_parm_type
;
17133 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17135 arg
= DECL_ARGUMENTS (function_or_method_type
);
17136 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17141 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17143 /* Make our first pass over the list of formal parameter types and output a
17144 DW_TAG_formal_parameter DIE for each one. */
17145 for (link
= first_parm_type
; link
; )
17147 dw_die_ref parm_die
;
17149 formal_type
= TREE_VALUE (link
);
17150 if (formal_type
== void_type_node
)
17153 /* Output a (nameless) DIE to represent the formal parameter itself. */
17154 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17155 true /* Emit name attribute. */,
17157 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17158 && link
== first_parm_type
)
17160 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17161 if (dwarf_version
>= 3 || !dwarf_strict
)
17162 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17164 else if (arg
&& DECL_ARTIFICIAL (arg
))
17165 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17167 link
= TREE_CHAIN (link
);
17169 arg
= DECL_CHAIN (arg
);
17172 /* If this function type has an ellipsis, add a
17173 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17174 if (formal_type
!= void_type_node
)
17175 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17177 /* Make our second (and final) pass over the list of formal parameter types
17178 and output DIEs to represent those types (as necessary). */
17179 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17180 link
&& TREE_VALUE (link
);
17181 link
= TREE_CHAIN (link
))
17182 gen_type_die (TREE_VALUE (link
), context_die
);
17185 /* We want to generate the DIE for TYPE so that we can generate the
17186 die for MEMBER, which has been defined; we will need to refer back
17187 to the member declaration nested within TYPE. If we're trying to
17188 generate minimal debug info for TYPE, processing TYPE won't do the
17189 trick; we need to attach the member declaration by hand. */
17192 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17194 gen_type_die (type
, context_die
);
17196 /* If we're trying to avoid duplicate debug info, we may not have
17197 emitted the member decl for this function. Emit it now. */
17198 if (TYPE_STUB_DECL (type
)
17199 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17200 && ! lookup_decl_die (member
))
17202 dw_die_ref type_die
;
17203 gcc_assert (!decl_ultimate_origin (member
));
17205 push_decl_scope (type
);
17206 type_die
= lookup_type_die_strip_naming_typedef (type
);
17207 if (TREE_CODE (member
) == FUNCTION_DECL
)
17208 gen_subprogram_die (member
, type_die
);
17209 else if (TREE_CODE (member
) == FIELD_DECL
)
17211 /* Ignore the nameless fields that are used to skip bits but handle
17212 C++ anonymous unions and structs. */
17213 if (DECL_NAME (member
) != NULL_TREE
17214 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17215 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17217 gen_type_die (member_declared_type (member
), type_die
);
17218 gen_field_die (member
, type_die
);
17222 gen_variable_die (member
, NULL_TREE
, type_die
);
17228 /* Forward declare these functions, because they are mutually recursive
17229 with their set_block_* pairing functions. */
17230 static void set_decl_origin_self (tree
);
17231 static void set_decl_abstract_flags (tree
, int);
17233 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17234 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17235 that it points to the node itself, thus indicating that the node is its
17236 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17237 the given node is NULL, recursively descend the decl/block tree which
17238 it is the root of, and for each other ..._DECL or BLOCK node contained
17239 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17240 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17241 values to point to themselves. */
17244 set_block_origin_self (tree stmt
)
17246 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17248 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17253 for (local_decl
= BLOCK_VARS (stmt
);
17254 local_decl
!= NULL_TREE
;
17255 local_decl
= DECL_CHAIN (local_decl
))
17256 if (! DECL_EXTERNAL (local_decl
))
17257 set_decl_origin_self (local_decl
); /* Potential recursion. */
17263 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17264 subblock
!= NULL_TREE
;
17265 subblock
= BLOCK_CHAIN (subblock
))
17266 set_block_origin_self (subblock
); /* Recurse. */
17271 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17272 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17273 node to so that it points to the node itself, thus indicating that the
17274 node represents its own (abstract) origin. Additionally, if the
17275 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17276 the decl/block tree of which the given node is the root of, and for
17277 each other ..._DECL or BLOCK node contained therein whose
17278 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17279 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17280 point to themselves. */
17283 set_decl_origin_self (tree decl
)
17285 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17287 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17288 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17292 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17293 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17294 if (DECL_INITIAL (decl
) != NULL_TREE
17295 && DECL_INITIAL (decl
) != error_mark_node
)
17296 set_block_origin_self (DECL_INITIAL (decl
));
17301 /* Given a pointer to some BLOCK node, and a boolean value to set the
17302 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17303 the given block, and for all local decls and all local sub-blocks
17304 (recursively) which are contained therein. */
17307 set_block_abstract_flags (tree stmt
, int setting
)
17313 BLOCK_ABSTRACT (stmt
) = setting
;
17315 for (local_decl
= BLOCK_VARS (stmt
);
17316 local_decl
!= NULL_TREE
;
17317 local_decl
= DECL_CHAIN (local_decl
))
17318 if (! DECL_EXTERNAL (local_decl
))
17319 set_decl_abstract_flags (local_decl
, setting
);
17321 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17323 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17324 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17325 || TREE_CODE (local_decl
) == PARM_DECL
)
17326 set_decl_abstract_flags (local_decl
, setting
);
17329 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17330 subblock
!= NULL_TREE
;
17331 subblock
= BLOCK_CHAIN (subblock
))
17332 set_block_abstract_flags (subblock
, setting
);
17335 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17336 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17337 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17338 set the abstract flags for all of the parameters, local vars, local
17339 blocks and sub-blocks (recursively) to the same setting. */
17342 set_decl_abstract_flags (tree decl
, int setting
)
17344 DECL_ABSTRACT (decl
) = setting
;
17345 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17349 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17350 DECL_ABSTRACT (arg
) = setting
;
17351 if (DECL_INITIAL (decl
) != NULL_TREE
17352 && DECL_INITIAL (decl
) != error_mark_node
)
17353 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17357 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17358 may later generate inlined and/or out-of-line instances of. */
17361 dwarf2out_abstract_function (tree decl
)
17363 dw_die_ref old_die
;
17367 htab_t old_decl_loc_table
;
17368 htab_t old_cached_dw_loc_list_table
;
17369 int old_call_site_count
, old_tail_call_site_count
;
17370 struct call_arg_loc_node
*old_call_arg_locations
;
17372 /* Make sure we have the actual abstract inline, not a clone. */
17373 decl
= DECL_ORIGIN (decl
);
17375 old_die
= lookup_decl_die (decl
);
17376 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17377 /* We've already generated the abstract instance. */
17380 /* We can be called while recursively when seeing block defining inlined subroutine
17381 DIE. Be sure to not clobber the outer location table nor use it or we would
17382 get locations in abstract instantces. */
17383 old_decl_loc_table
= decl_loc_table
;
17384 decl_loc_table
= NULL
;
17385 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17386 cached_dw_loc_list_table
= NULL
;
17387 old_call_arg_locations
= call_arg_locations
;
17388 call_arg_locations
= NULL
;
17389 old_call_site_count
= call_site_count
;
17390 call_site_count
= -1;
17391 old_tail_call_site_count
= tail_call_site_count
;
17392 tail_call_site_count
= -1;
17394 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17395 we don't get confused by DECL_ABSTRACT. */
17396 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17398 context
= decl_class_context (decl
);
17400 gen_type_die_for_member
17401 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17404 /* Pretend we've just finished compiling this function. */
17405 save_fn
= current_function_decl
;
17406 current_function_decl
= decl
;
17408 was_abstract
= DECL_ABSTRACT (decl
);
17409 set_decl_abstract_flags (decl
, 1);
17410 dwarf2out_decl (decl
);
17411 if (! was_abstract
)
17412 set_decl_abstract_flags (decl
, 0);
17414 current_function_decl
= save_fn
;
17415 decl_loc_table
= old_decl_loc_table
;
17416 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17417 call_arg_locations
= old_call_arg_locations
;
17418 call_site_count
= old_call_site_count
;
17419 tail_call_site_count
= old_tail_call_site_count
;
17422 /* Helper function of premark_used_types() which gets called through
17425 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17426 marked as unused by prune_unused_types. */
17429 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17434 type
= (tree
) *slot
;
17435 die
= lookup_type_die (type
);
17437 die
->die_perennial_p
= 1;
17441 /* Helper function of premark_types_used_by_global_vars which gets called
17442 through htab_traverse.
17444 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17445 marked as unused by prune_unused_types. The DIE of the type is marked
17446 only if the global variable using the type will actually be emitted. */
17449 premark_types_used_by_global_vars_helper (void **slot
,
17450 void *data ATTRIBUTE_UNUSED
)
17452 struct types_used_by_vars_entry
*entry
;
17455 entry
= (struct types_used_by_vars_entry
*) *slot
;
17456 gcc_assert (entry
->type
!= NULL
17457 && entry
->var_decl
!= NULL
);
17458 die
= lookup_type_die (entry
->type
);
17461 /* Ask cgraph if the global variable really is to be emitted.
17462 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17463 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17464 if (node
&& node
->analyzed
)
17466 die
->die_perennial_p
= 1;
17467 /* Keep the parent DIEs as well. */
17468 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17469 die
->die_perennial_p
= 1;
17475 /* Mark all members of used_types_hash as perennial. */
17478 premark_used_types (struct function
*fun
)
17480 if (fun
&& fun
->used_types_hash
)
17481 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17484 /* Mark all members of types_used_by_vars_entry as perennial. */
17487 premark_types_used_by_global_vars (void)
17489 if (types_used_by_vars_hash
)
17490 htab_traverse (types_used_by_vars_hash
,
17491 premark_types_used_by_global_vars_helper
, NULL
);
17494 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17495 for CA_LOC call arg loc node. */
17498 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17499 struct call_arg_loc_node
*ca_loc
)
17501 dw_die_ref stmt_die
= NULL
, die
;
17502 tree block
= ca_loc
->block
;
17505 && block
!= DECL_INITIAL (decl
)
17506 && TREE_CODE (block
) == BLOCK
)
17508 if (block_map
.length () > BLOCK_NUMBER (block
))
17509 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17512 block
= BLOCK_SUPERCONTEXT (block
);
17514 if (stmt_die
== NULL
)
17515 stmt_die
= subr_die
;
17516 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17517 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17518 if (ca_loc
->tail_call_p
)
17519 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17520 if (ca_loc
->symbol_ref
)
17522 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17524 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17526 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17531 /* Generate a DIE to represent a declared function (either file-scope or
17535 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17537 tree origin
= decl_ultimate_origin (decl
);
17538 dw_die_ref subr_die
;
17540 dw_die_ref old_die
= lookup_decl_die (decl
);
17541 int declaration
= (current_function_decl
!= decl
17542 || class_or_namespace_scope_p (context_die
));
17544 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17546 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17547 started to generate the abstract instance of an inline, decided to output
17548 its containing class, and proceeded to emit the declaration of the inline
17549 from the member list for the class. If so, DECLARATION takes priority;
17550 we'll get back to the abstract instance when done with the class. */
17552 /* The class-scope declaration DIE must be the primary DIE. */
17553 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17556 gcc_assert (!old_die
);
17559 /* Now that the C++ front end lazily declares artificial member fns, we
17560 might need to retrofit the declaration into its class. */
17561 if (!declaration
&& !origin
&& !old_die
17562 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17563 && !class_or_namespace_scope_p (context_die
)
17564 && debug_info_level
> DINFO_LEVEL_TERSE
)
17565 old_die
= force_decl_die (decl
);
17567 if (origin
!= NULL
)
17569 gcc_assert (!declaration
|| local_scope_p (context_die
));
17571 /* Fixup die_parent for the abstract instance of a nested
17572 inline function. */
17573 if (old_die
&& old_die
->die_parent
== NULL
)
17574 add_child_die (context_die
, old_die
);
17576 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17577 add_abstract_origin_attribute (subr_die
, origin
);
17578 /* This is where the actual code for a cloned function is.
17579 Let's emit linkage name attribute for it. This helps
17580 debuggers to e.g, set breakpoints into
17581 constructors/destructors when the user asks "break
17583 add_linkage_name (subr_die
, decl
);
17587 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17588 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17590 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17591 /* We can have a normal definition following an inline one in the
17592 case of redefinition of GNU C extern inlines.
17593 It seems reasonable to use AT_specification in this case. */
17594 && !get_AT (old_die
, DW_AT_inline
))
17596 /* Detect and ignore this case, where we are trying to output
17597 something we have already output. */
17601 /* If the definition comes from the same place as the declaration,
17602 maybe use the old DIE. We always want the DIE for this function
17603 that has the *_pc attributes to be under comp_unit_die so the
17604 debugger can find it. We also need to do this for abstract
17605 instances of inlines, since the spec requires the out-of-line copy
17606 to have the same parent. For local class methods, this doesn't
17607 apply; we just use the old DIE. */
17608 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17609 && (DECL_ARTIFICIAL (decl
)
17610 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17611 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17612 == (unsigned) s
.line
))))
17614 subr_die
= old_die
;
17616 /* Clear out the declaration attribute and the formal parameters.
17617 Do not remove all children, because it is possible that this
17618 declaration die was forced using force_decl_die(). In such
17619 cases die that forced declaration die (e.g. TAG_imported_module)
17620 is one of the children that we do not want to remove. */
17621 remove_AT (subr_die
, DW_AT_declaration
);
17622 remove_AT (subr_die
, DW_AT_object_pointer
);
17623 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17627 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17628 add_AT_specification (subr_die
, old_die
);
17629 add_pubname (decl
, subr_die
);
17630 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17631 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17632 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17633 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17638 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17640 if (TREE_PUBLIC (decl
))
17641 add_AT_flag (subr_die
, DW_AT_external
, 1);
17643 add_name_and_src_coords_attributes (subr_die
, decl
);
17644 add_pubname (decl
, subr_die
);
17645 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17647 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17648 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17649 0, 0, context_die
);
17652 add_pure_or_virtual_attribute (subr_die
, decl
);
17653 if (DECL_ARTIFICIAL (decl
))
17654 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17656 add_accessibility_attribute (subr_die
, decl
);
17661 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17663 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17665 /* If this is an explicit function declaration then generate
17666 a DW_AT_explicit attribute. */
17667 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17668 && (dwarf_version
>= 3 || !dwarf_strict
))
17669 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17671 /* The first time we see a member function, it is in the context of
17672 the class to which it belongs. We make sure of this by emitting
17673 the class first. The next time is the definition, which is
17674 handled above. The two may come from the same source text.
17676 Note that force_decl_die() forces function declaration die. It is
17677 later reused to represent definition. */
17678 equate_decl_number_to_die (decl
, subr_die
);
17681 else if (DECL_ABSTRACT (decl
))
17683 if (DECL_DECLARED_INLINE_P (decl
))
17685 if (cgraph_function_possibly_inlined_p (decl
))
17686 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17688 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17692 if (cgraph_function_possibly_inlined_p (decl
))
17693 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17695 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17698 if (DECL_DECLARED_INLINE_P (decl
)
17699 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17700 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17702 equate_decl_number_to_die (decl
, subr_die
);
17704 else if (!DECL_EXTERNAL (decl
))
17706 HOST_WIDE_INT cfa_fb_offset
;
17707 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17709 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17710 equate_decl_number_to_die (decl
, subr_die
);
17712 gcc_checking_assert (fun
);
17713 if (!flag_reorder_blocks_and_partition
)
17715 dw_fde_ref fde
= fun
->fde
;
17716 if (fde
->dw_fde_begin
)
17718 /* We have already generated the labels. */
17719 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17720 fde
->dw_fde_end
, false);
17724 /* Create start/end labels and add the range. */
17725 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17726 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17727 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17728 current_function_funcdef_no
);
17729 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17730 current_function_funcdef_no
);
17731 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17735 #if VMS_DEBUGGING_INFO
17736 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17737 Section 2.3 Prologue and Epilogue Attributes:
17738 When a breakpoint is set on entry to a function, it is generally
17739 desirable for execution to be suspended, not on the very first
17740 instruction of the function, but rather at a point after the
17741 function's frame has been set up, after any language defined local
17742 declaration processing has been completed, and before execution of
17743 the first statement of the function begins. Debuggers generally
17744 cannot properly determine where this point is. Similarly for a
17745 breakpoint set on exit from a function. The prologue and epilogue
17746 attributes allow a compiler to communicate the location(s) to use. */
17749 if (fde
->dw_fde_vms_end_prologue
)
17750 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17751 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17753 if (fde
->dw_fde_vms_begin_epilogue
)
17754 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17755 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17762 /* Generate pubnames entries for the split function code ranges. */
17763 dw_fde_ref fde
= fun
->fde
;
17765 if (fde
->dw_fde_second_begin
)
17767 if (dwarf_version
>= 3 || !dwarf_strict
)
17769 /* We should use ranges for non-contiguous code section
17770 addresses. Use the actual code range for the initial
17771 section, since the HOT/COLD labels might precede an
17772 alignment offset. */
17773 bool range_list_added
= false;
17774 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17775 fde
->dw_fde_end
, &range_list_added
,
17777 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17778 fde
->dw_fde_second_end
,
17779 &range_list_added
, false);
17780 if (range_list_added
)
17785 /* There is no real support in DW2 for this .. so we make
17786 a work-around. First, emit the pub name for the segment
17787 containing the function label. Then make and emit a
17788 simplified subprogram DIE for the second segment with the
17789 name pre-fixed by __hot/cold_sect_of_. We use the same
17790 linkage name for the second die so that gdb will find both
17791 sections when given "b foo". */
17792 const char *name
= NULL
;
17793 tree decl_name
= DECL_NAME (decl
);
17794 dw_die_ref seg_die
;
17796 /* Do the 'primary' section. */
17797 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17798 fde
->dw_fde_end
, false);
17800 /* Build a minimal DIE for the secondary section. */
17801 seg_die
= new_die (DW_TAG_subprogram
,
17802 subr_die
->die_parent
, decl
);
17804 if (TREE_PUBLIC (decl
))
17805 add_AT_flag (seg_die
, DW_AT_external
, 1);
17807 if (decl_name
!= NULL
17808 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17810 name
= dwarf2_name (decl
, 1);
17811 if (! DECL_ARTIFICIAL (decl
))
17812 add_src_coords_attributes (seg_die
, decl
);
17814 add_linkage_name (seg_die
, decl
);
17816 gcc_assert (name
!= NULL
);
17817 add_pure_or_virtual_attribute (seg_die
, decl
);
17818 if (DECL_ARTIFICIAL (decl
))
17819 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17821 name
= concat ("__second_sect_of_", name
, NULL
);
17822 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17823 fde
->dw_fde_second_end
, false);
17824 add_name_attribute (seg_die
, name
);
17825 if (want_pubnames ())
17826 add_pubname_string (name
, seg_die
);
17830 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17834 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17836 /* We define the "frame base" as the function's CFA. This is more
17837 convenient for several reasons: (1) It's stable across the prologue
17838 and epilogue, which makes it better than just a frame pointer,
17839 (2) With dwarf3, there exists a one-byte encoding that allows us
17840 to reference the .debug_frame data by proxy, but failing that,
17841 (3) We can at least reuse the code inspection and interpretation
17842 code that determines the CFA position at various points in the
17844 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17846 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17847 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17851 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17852 if (list
->dw_loc_next
)
17853 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17855 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17858 /* Compute a displacement from the "steady-state frame pointer" to
17859 the CFA. The former is what all stack slots and argument slots
17860 will reference in the rtl; the later is what we've told the
17861 debugger about. We'll need to adjust all frame_base references
17862 by this displacement. */
17863 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17865 if (fun
->static_chain_decl
)
17866 add_AT_location_description (subr_die
, DW_AT_static_link
,
17867 loc_list_from_tree (fun
->static_chain_decl
, 2));
17870 /* Generate child dies for template paramaters. */
17871 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17872 gen_generic_params_dies (decl
);
17874 /* Now output descriptions of the arguments for this function. This gets
17875 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17876 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17877 `...' at the end of the formal parameter list. In order to find out if
17878 there was a trailing ellipsis or not, we must instead look at the type
17879 associated with the FUNCTION_DECL. This will be a node of type
17880 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17881 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17882 an ellipsis at the end. */
17884 /* In the case where we are describing a mere function declaration, all we
17885 need to do here (and all we *can* do here) is to describe the *types* of
17886 its formal parameters. */
17887 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17889 else if (declaration
)
17890 gen_formal_types_die (decl
, subr_die
);
17893 /* Generate DIEs to represent all known formal parameters. */
17894 tree parm
= DECL_ARGUMENTS (decl
);
17895 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17896 tree generic_decl_parm
= generic_decl
17897 ? DECL_ARGUMENTS (generic_decl
)
17900 /* Now we want to walk the list of parameters of the function and
17901 emit their relevant DIEs.
17903 We consider the case of DECL being an instance of a generic function
17904 as well as it being a normal function.
17906 If DECL is an instance of a generic function we walk the
17907 parameters of the generic function declaration _and_ the parameters of
17908 DECL itself. This is useful because we want to emit specific DIEs for
17909 function parameter packs and those are declared as part of the
17910 generic function declaration. In that particular case,
17911 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17912 That DIE has children DIEs representing the set of arguments
17913 of the pack. Note that the set of pack arguments can be empty.
17914 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17917 Otherwise, we just consider the parameters of DECL. */
17918 while (generic_decl_parm
|| parm
)
17920 if (generic_decl_parm
17921 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17922 gen_formal_parameter_pack_die (generic_decl_parm
,
17927 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17929 if (parm
== DECL_ARGUMENTS (decl
)
17930 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17932 && (dwarf_version
>= 3 || !dwarf_strict
))
17933 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17935 parm
= DECL_CHAIN (parm
);
17938 if (generic_decl_parm
)
17939 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17942 /* Decide whether we need an unspecified_parameters DIE at the end.
17943 There are 2 more cases to do this for: 1) the ansi ... declaration -
17944 this is detectable when the end of the arg list is not a
17945 void_type_node 2) an unprototyped function declaration (not a
17946 definition). This just means that we have no info about the
17947 parameters at all. */
17948 if (prototype_p (TREE_TYPE (decl
)))
17950 /* This is the prototyped case, check for.... */
17951 if (stdarg_p (TREE_TYPE (decl
)))
17952 gen_unspecified_parameters_die (decl
, subr_die
);
17954 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17955 gen_unspecified_parameters_die (decl
, subr_die
);
17958 /* Output Dwarf info for all of the stuff within the body of the function
17959 (if it has one - it may be just a declaration). */
17960 outer_scope
= DECL_INITIAL (decl
);
17962 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17963 a function. This BLOCK actually represents the outermost binding contour
17964 for the function, i.e. the contour in which the function's formal
17965 parameters and labels get declared. Curiously, it appears that the front
17966 end doesn't actually put the PARM_DECL nodes for the current function onto
17967 the BLOCK_VARS list for this outer scope, but are strung off of the
17968 DECL_ARGUMENTS list for the function instead.
17970 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17971 the LABEL_DECL nodes for the function however, and we output DWARF info
17972 for those in decls_for_scope. Just within the `outer_scope' there will be
17973 a BLOCK node representing the function's outermost pair of curly braces,
17974 and any blocks used for the base and member initializers of a C++
17975 constructor function. */
17976 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17978 int call_site_note_count
= 0;
17979 int tail_call_site_note_count
= 0;
17981 /* Emit a DW_TAG_variable DIE for a named return value. */
17982 if (DECL_NAME (DECL_RESULT (decl
)))
17983 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17985 current_function_has_inlines
= 0;
17986 decls_for_scope (outer_scope
, subr_die
, 0);
17988 if (call_arg_locations
&& !dwarf_strict
)
17990 struct call_arg_loc_node
*ca_loc
;
17991 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
17993 dw_die_ref die
= NULL
;
17994 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
17997 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
17998 arg
; arg
= next_arg
)
18000 dw_loc_descr_ref reg
, val
;
18001 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18002 dw_die_ref cdie
, tdie
= NULL
;
18004 next_arg
= XEXP (arg
, 1);
18005 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18007 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18008 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18009 && REGNO (XEXP (XEXP (arg
, 0), 0))
18010 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18011 next_arg
= XEXP (next_arg
, 1);
18012 if (mode
== VOIDmode
)
18014 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18015 if (mode
== VOIDmode
)
18016 mode
= GET_MODE (XEXP (arg
, 0));
18018 if (mode
== VOIDmode
|| mode
== BLKmode
)
18020 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18022 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18023 tloc
= XEXP (XEXP (arg
, 0), 1);
18026 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18027 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18029 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18030 tlocc
= XEXP (XEXP (arg
, 0), 1);
18034 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18035 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18036 VAR_INIT_STATUS_INITIALIZED
);
18037 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18039 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18040 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18041 get_address_mode (mem
),
18043 VAR_INIT_STATUS_INITIALIZED
);
18045 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18046 == DEBUG_PARAMETER_REF
)
18049 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18050 tdie
= lookup_decl_die (tdecl
);
18057 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18058 != DEBUG_PARAMETER_REF
)
18060 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18062 VAR_INIT_STATUS_INITIALIZED
);
18066 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18067 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18070 add_AT_loc (cdie
, DW_AT_location
, reg
);
18071 else if (tdie
!= NULL
)
18072 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18073 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18074 if (next_arg
!= XEXP (arg
, 1))
18076 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18077 if (mode
== VOIDmode
)
18078 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18079 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18082 VAR_INIT_STATUS_INITIALIZED
);
18084 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18088 && (ca_loc
->symbol_ref
|| tloc
))
18089 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18090 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18092 dw_loc_descr_ref tval
= NULL
;
18094 if (tloc
!= NULL_RTX
)
18095 tval
= mem_loc_descriptor (tloc
,
18096 GET_MODE (tloc
) == VOIDmode
18097 ? Pmode
: GET_MODE (tloc
),
18099 VAR_INIT_STATUS_INITIALIZED
);
18101 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18102 else if (tlocc
!= NULL_RTX
)
18104 tval
= mem_loc_descriptor (tlocc
,
18105 GET_MODE (tlocc
) == VOIDmode
18106 ? Pmode
: GET_MODE (tlocc
),
18108 VAR_INIT_STATUS_INITIALIZED
);
18110 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18116 call_site_note_count
++;
18117 if (ca_loc
->tail_call_p
)
18118 tail_call_site_note_count
++;
18122 call_arg_locations
= NULL
;
18123 call_arg_loc_last
= NULL
;
18124 if (tail_call_site_count
>= 0
18125 && tail_call_site_count
== tail_call_site_note_count
18128 if (call_site_count
>= 0
18129 && call_site_count
== call_site_note_count
)
18130 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18132 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18134 call_site_count
= -1;
18135 tail_call_site_count
= -1;
18137 /* Add the calling convention attribute if requested. */
18138 add_calling_convention_attribute (subr_die
, decl
);
18142 /* Returns a hash value for X (which really is a die_struct). */
18145 common_block_die_table_hash (const void *x
)
18147 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18148 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18151 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18152 as decl_id and die_parent of die_struct Y. */
18155 common_block_die_table_eq (const void *x
, const void *y
)
18157 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18158 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18159 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18162 /* Generate a DIE to represent a declared data object.
18163 Either DECL or ORIGIN must be non-null. */
18166 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18168 HOST_WIDE_INT off
= 0;
18170 tree decl_or_origin
= decl
? decl
: origin
;
18171 tree ultimate_origin
;
18172 dw_die_ref var_die
;
18173 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18174 dw_die_ref origin_die
;
18175 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18176 || class_or_namespace_scope_p (context_die
));
18177 bool specialization_p
= false;
18179 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18180 if (decl
|| ultimate_origin
)
18181 origin
= ultimate_origin
;
18182 com_decl
= fortran_common (decl_or_origin
, &off
);
18184 /* Symbol in common gets emitted as a child of the common block, in the form
18185 of a data member. */
18188 dw_die_ref com_die
;
18189 dw_loc_list_ref loc
;
18190 die_node com_die_arg
;
18192 var_die
= lookup_decl_die (decl_or_origin
);
18195 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18197 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18202 /* Optimize the common case. */
18203 if (single_element_loc_list_p (loc
)
18204 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18205 && loc
->expr
->dw_loc_next
== NULL
18206 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18209 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18210 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18211 = plus_constant (GET_MODE (x
), x
, off
);
18214 loc_list_plus_const (loc
, off
);
18216 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18217 remove_AT (var_die
, DW_AT_declaration
);
18223 if (common_block_die_table
== NULL
)
18224 common_block_die_table
18225 = htab_create_ggc (10, common_block_die_table_hash
,
18226 common_block_die_table_eq
, NULL
);
18228 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18229 com_die_arg
.die_parent
= context_die
;
18230 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18231 loc
= loc_list_from_tree (com_decl
, 2);
18232 if (com_die
== NULL
)
18235 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18238 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18239 add_name_and_src_coords_attributes (com_die
, com_decl
);
18242 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18243 /* Avoid sharing the same loc descriptor between
18244 DW_TAG_common_block and DW_TAG_variable. */
18245 loc
= loc_list_from_tree (com_decl
, 2);
18247 else if (DECL_EXTERNAL (decl
))
18248 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18249 if (want_pubnames ())
18250 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18251 com_die
->decl_id
= DECL_UID (com_decl
);
18252 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18253 *slot
= (void *) com_die
;
18255 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18257 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18258 loc
= loc_list_from_tree (com_decl
, 2);
18259 remove_AT (com_die
, DW_AT_declaration
);
18261 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18262 add_name_and_src_coords_attributes (var_die
, decl
);
18263 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18264 TREE_THIS_VOLATILE (decl
), context_die
);
18265 add_AT_flag (var_die
, DW_AT_external
, 1);
18270 /* Optimize the common case. */
18271 if (single_element_loc_list_p (loc
)
18272 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18273 && loc
->expr
->dw_loc_next
== NULL
18274 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18276 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18277 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18278 = plus_constant (GET_MODE (x
), x
, off
);
18281 loc_list_plus_const (loc
, off
);
18283 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18285 else if (DECL_EXTERNAL (decl
))
18286 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18287 equate_decl_number_to_die (decl
, var_die
);
18291 /* If the compiler emitted a definition for the DECL declaration
18292 and if we already emitted a DIE for it, don't emit a second
18293 DIE for it again. Allow re-declarations of DECLs that are
18294 inside functions, though. */
18295 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18298 /* For static data members, the declaration in the class is supposed
18299 to have DW_TAG_member tag; the specification should still be
18300 DW_TAG_variable referencing the DW_TAG_member DIE. */
18301 if (declaration
&& class_scope_p (context_die
))
18302 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18304 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18307 if (origin
!= NULL
)
18308 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18310 /* Loop unrolling can create multiple blocks that refer to the same
18311 static variable, so we must test for the DW_AT_declaration flag.
18313 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18314 copy decls and set the DECL_ABSTRACT flag on them instead of
18317 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18319 ??? The declare_in_namespace support causes us to get two DIEs for one
18320 variable, both of which are declarations. We want to avoid considering
18321 one to be a specification, so we must test that this DIE is not a
18323 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18324 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18326 /* This is a definition of a C++ class level static. */
18327 add_AT_specification (var_die
, old_die
);
18328 specialization_p
= true;
18329 if (DECL_NAME (decl
))
18331 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18332 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18334 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18335 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18337 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18338 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18340 if (old_die
->die_tag
== DW_TAG_member
)
18341 add_linkage_name (var_die
, decl
);
18345 add_name_and_src_coords_attributes (var_die
, decl
);
18347 if ((origin
== NULL
&& !specialization_p
)
18349 && !DECL_ABSTRACT (decl_or_origin
)
18350 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18351 decl_function_context
18352 (decl_or_origin
))))
18354 tree type
= TREE_TYPE (decl_or_origin
);
18356 if (decl_by_reference_p (decl_or_origin
))
18357 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18359 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18360 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18363 if (origin
== NULL
&& !specialization_p
)
18365 if (TREE_PUBLIC (decl
))
18366 add_AT_flag (var_die
, DW_AT_external
, 1);
18368 if (DECL_ARTIFICIAL (decl
))
18369 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18371 add_accessibility_attribute (var_die
, decl
);
18375 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18377 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18378 equate_decl_number_to_die (decl
, var_die
);
18381 && (! DECL_ABSTRACT (decl_or_origin
)
18382 /* Local static vars are shared between all clones/inlines,
18383 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18385 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18386 && TREE_STATIC (decl_or_origin
)
18387 && DECL_RTL_SET_P (decl_or_origin
)))
18388 /* When abstract origin already has DW_AT_location attribute, no need
18389 to add it again. */
18390 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18392 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18393 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18394 defer_location (decl_or_origin
, var_die
);
18396 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18397 decl
== NULL
, DW_AT_location
);
18398 add_pubname (decl_or_origin
, var_die
);
18401 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18404 /* Generate a DIE to represent a named constant. */
18407 gen_const_die (tree decl
, dw_die_ref context_die
)
18409 dw_die_ref const_die
;
18410 tree type
= TREE_TYPE (decl
);
18412 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18413 add_name_and_src_coords_attributes (const_die
, decl
);
18414 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18415 if (TREE_PUBLIC (decl
))
18416 add_AT_flag (const_die
, DW_AT_external
, 1);
18417 if (DECL_ARTIFICIAL (decl
))
18418 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18419 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18422 /* Generate a DIE to represent a label identifier. */
18425 gen_label_die (tree decl
, dw_die_ref context_die
)
18427 tree origin
= decl_ultimate_origin (decl
);
18428 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18430 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18432 if (origin
!= NULL
)
18433 add_abstract_origin_attribute (lbl_die
, origin
);
18435 add_name_and_src_coords_attributes (lbl_die
, decl
);
18437 if (DECL_ABSTRACT (decl
))
18438 equate_decl_number_to_die (decl
, lbl_die
);
18441 insn
= DECL_RTL_IF_SET (decl
);
18443 /* Deleted labels are programmer specified labels which have been
18444 eliminated because of various optimizations. We still emit them
18445 here so that it is possible to put breakpoints on them. */
18449 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18451 /* When optimization is enabled (via -O) some parts of the compiler
18452 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18453 represent source-level labels which were explicitly declared by
18454 the user. This really shouldn't be happening though, so catch
18455 it if it ever does happen. */
18456 gcc_assert (!INSN_DELETED_P (insn
));
18458 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18459 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18463 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18464 && CODE_LABEL_NUMBER (insn
) != -1)
18466 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18467 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18472 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18473 attributes to the DIE for a block STMT, to describe where the inlined
18474 function was called from. This is similar to add_src_coords_attributes. */
18477 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18479 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18481 if (dwarf_version
>= 3 || !dwarf_strict
)
18483 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18484 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18489 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18490 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18493 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18495 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18497 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18498 && (dwarf_version
>= 3 || !dwarf_strict
))
18500 tree chain
, superblock
= NULL_TREE
;
18502 dw_attr_ref attr
= NULL
;
18504 if (inlined_function_outer_scope_p (stmt
))
18506 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18507 BLOCK_NUMBER (stmt
));
18508 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18511 /* Optimize duplicate .debug_ranges lists or even tails of
18512 lists. If this BLOCK has same ranges as its supercontext,
18513 lookup DW_AT_ranges attribute in the supercontext (and
18514 recursively so), verify that the ranges_table contains the
18515 right values and use it instead of adding a new .debug_range. */
18516 for (chain
= stmt
, pdie
= die
;
18517 BLOCK_SAME_RANGE (chain
);
18518 chain
= BLOCK_SUPERCONTEXT (chain
))
18520 dw_attr_ref new_attr
;
18522 pdie
= pdie
->die_parent
;
18525 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18527 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18528 if (new_attr
== NULL
18529 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18532 superblock
= BLOCK_SUPERCONTEXT (chain
);
18535 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18536 / 2 / DWARF2_ADDR_SIZE
].num
18537 == BLOCK_NUMBER (superblock
))
18538 && BLOCK_FRAGMENT_CHAIN (superblock
))
18540 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18541 / 2 / DWARF2_ADDR_SIZE
;
18542 unsigned long supercnt
= 0, thiscnt
= 0;
18543 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18544 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18547 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18548 == BLOCK_NUMBER (chain
));
18550 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18551 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18552 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18554 gcc_assert (supercnt
>= thiscnt
);
18555 add_AT_range_list (die
, DW_AT_ranges
,
18556 ((off
+ supercnt
- thiscnt
)
18557 * 2 * DWARF2_ADDR_SIZE
),
18562 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18564 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18567 add_ranges (chain
);
18568 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18575 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18576 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18577 BLOCK_NUMBER (stmt
));
18578 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18579 BLOCK_NUMBER (stmt
));
18580 add_AT_low_high_pc (die
, label
, label_high
, false);
18584 /* Generate a DIE for a lexical block. */
18587 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18589 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18591 if (call_arg_locations
)
18593 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18594 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18595 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18598 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18599 add_high_low_attributes (stmt
, stmt_die
);
18601 decls_for_scope (stmt
, stmt_die
, depth
);
18604 /* Generate a DIE for an inlined subprogram. */
18607 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18611 /* The instance of function that is effectively being inlined shall not
18613 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18615 decl
= block_ultimate_origin (stmt
);
18617 /* Emit info for the abstract instance first, if we haven't yet. We
18618 must emit this even if the block is abstract, otherwise when we
18619 emit the block below (or elsewhere), we may end up trying to emit
18620 a die whose origin die hasn't been emitted, and crashing. */
18621 dwarf2out_abstract_function (decl
);
18623 if (! BLOCK_ABSTRACT (stmt
))
18625 dw_die_ref subr_die
18626 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18628 if (call_arg_locations
)
18630 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18631 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18632 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18634 add_abstract_origin_attribute (subr_die
, decl
);
18635 if (TREE_ASM_WRITTEN (stmt
))
18636 add_high_low_attributes (stmt
, subr_die
);
18637 add_call_src_coords_attributes (stmt
, subr_die
);
18639 decls_for_scope (stmt
, subr_die
, depth
);
18640 current_function_has_inlines
= 1;
18644 /* Generate a DIE for a field in a record, or structure. */
18647 gen_field_die (tree decl
, dw_die_ref context_die
)
18649 dw_die_ref decl_die
;
18651 if (TREE_TYPE (decl
) == error_mark_node
)
18654 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18655 add_name_and_src_coords_attributes (decl_die
, decl
);
18656 add_type_attribute (decl_die
, member_declared_type (decl
),
18657 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18660 if (DECL_BIT_FIELD_TYPE (decl
))
18662 add_byte_size_attribute (decl_die
, decl
);
18663 add_bit_size_attribute (decl_die
, decl
);
18664 add_bit_offset_attribute (decl_die
, decl
);
18667 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18668 add_data_member_location_attribute (decl_die
, decl
);
18670 if (DECL_ARTIFICIAL (decl
))
18671 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18673 add_accessibility_attribute (decl_die
, decl
);
18675 /* Equate decl number to die, so that we can look up this decl later on. */
18676 equate_decl_number_to_die (decl
, decl_die
);
18680 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18681 Use modified_type_die instead.
18682 We keep this code here just in case these types of DIEs may be needed to
18683 represent certain things in other languages (e.g. Pascal) someday. */
18686 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18689 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18691 equate_type_number_to_die (type
, ptr_die
);
18692 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18693 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18696 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18697 Use modified_type_die instead.
18698 We keep this code here just in case these types of DIEs may be needed to
18699 represent certain things in other languages (e.g. Pascal) someday. */
18702 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18704 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18706 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18707 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18709 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18711 equate_type_number_to_die (type
, ref_die
);
18712 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18713 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18717 /* Generate a DIE for a pointer to a member type. */
18720 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18723 = new_die (DW_TAG_ptr_to_member_type
,
18724 scope_die_for (type
, context_die
), type
);
18726 equate_type_number_to_die (type
, ptr_die
);
18727 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18728 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18729 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18732 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18734 static char *producer_string
;
18736 /* Return a heap allocated producer string including command line options
18737 if -grecord-gcc-switches. */
18740 gen_producer_string (void)
18743 vec
<dchar_p
> switches
= vNULL
;
18744 const char *language_string
= lang_hooks
.name
;
18745 char *producer
, *tail
;
18747 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18748 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18750 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18751 switch (save_decoded_options
[j
].opt_index
)
18758 case OPT_auxbase_strip
:
18767 case OPT_SPECIAL_unknown
:
18768 case OPT_SPECIAL_ignore
:
18769 case OPT_SPECIAL_program_name
:
18770 case OPT_SPECIAL_input_file
:
18771 case OPT_grecord_gcc_switches
:
18772 case OPT_gno_record_gcc_switches
:
18773 case OPT__output_pch_
:
18774 case OPT_fdiagnostics_show_location_
:
18775 case OPT_fdiagnostics_show_option
:
18776 case OPT_fdiagnostics_show_caret
:
18777 case OPT_fverbose_asm
:
18779 case OPT__sysroot_
:
18781 case OPT_nostdinc__
:
18782 /* Ignore these. */
18785 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18786 & CL_NO_DWARF_RECORD
)
18788 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18790 switch (save_decoded_options
[j
].canonical_option
[0][1])
18797 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18804 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18805 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18809 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18811 sprintf (tail
, "%s %s", language_string
, version_string
);
18814 FOR_EACH_VEC_ELT (switches
, j
, p
)
18818 memcpy (tail
+ 1, p
, len
);
18823 switches
.release ();
18827 /* Generate the DIE for the compilation unit. */
18830 gen_compile_unit_die (const char *filename
)
18833 const char *language_string
= lang_hooks
.name
;
18836 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18840 add_name_attribute (die
, filename
);
18841 /* Don't add cwd for <built-in>. */
18842 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18843 add_comp_dir_attribute (die
);
18846 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
18848 /* If our producer is LTO try to figure out a common language to use
18849 from the global list of translation units. */
18850 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18854 const char *common_lang
= NULL
;
18856 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
18858 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18861 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18862 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18864 else if (strncmp (common_lang
, "GNU C", 5) == 0
18865 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18866 /* Mixing C and C++ is ok, use C++ in that case. */
18867 common_lang
= "GNU C++";
18870 /* Fall back to C. */
18871 common_lang
= NULL
;
18877 language_string
= common_lang
;
18880 language
= DW_LANG_C89
;
18881 if (strcmp (language_string
, "GNU C++") == 0)
18882 language
= DW_LANG_C_plus_plus
;
18883 else if (strcmp (language_string
, "GNU F77") == 0)
18884 language
= DW_LANG_Fortran77
;
18885 else if (strcmp (language_string
, "GNU Pascal") == 0)
18886 language
= DW_LANG_Pascal83
;
18887 else if (dwarf_version
>= 3 || !dwarf_strict
)
18889 if (strcmp (language_string
, "GNU Ada") == 0)
18890 language
= DW_LANG_Ada95
;
18891 else if (strcmp (language_string
, "GNU Fortran") == 0)
18892 language
= DW_LANG_Fortran95
;
18893 else if (strcmp (language_string
, "GNU Java") == 0)
18894 language
= DW_LANG_Java
;
18895 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18896 language
= DW_LANG_ObjC
;
18897 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18898 language
= DW_LANG_ObjC_plus_plus
;
18899 else if (dwarf_version
>= 5 || !dwarf_strict
)
18901 if (strcmp (language_string
, "GNU Go") == 0)
18902 language
= DW_LANG_Go
;
18905 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18906 else if (strcmp (language_string
, "GNU Fortran") == 0)
18907 language
= DW_LANG_Fortran90
;
18909 add_AT_unsigned (die
, DW_AT_language
, language
);
18913 case DW_LANG_Fortran77
:
18914 case DW_LANG_Fortran90
:
18915 case DW_LANG_Fortran95
:
18916 /* Fortran has case insensitive identifiers and the front-end
18917 lowercases everything. */
18918 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18921 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18927 /* Generate the DIE for a base class. */
18930 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18932 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18934 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18935 add_data_member_location_attribute (die
, binfo
);
18937 if (BINFO_VIRTUAL_P (binfo
))
18938 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18940 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18941 children, otherwise the default is DW_ACCESS_public. In DWARF2
18942 the default has always been DW_ACCESS_private. */
18943 if (access
== access_public_node
)
18945 if (dwarf_version
== 2
18946 || context_die
->die_tag
== DW_TAG_class_type
)
18947 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18949 else if (access
== access_protected_node
)
18950 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18951 else if (dwarf_version
> 2
18952 && context_die
->die_tag
!= DW_TAG_class_type
)
18953 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18956 /* Generate a DIE for a class member. */
18959 gen_member_die (tree type
, dw_die_ref context_die
)
18962 tree binfo
= TYPE_BINFO (type
);
18965 /* If this is not an incomplete type, output descriptions of each of its
18966 members. Note that as we output the DIEs necessary to represent the
18967 members of this record or union type, we will also be trying to output
18968 DIEs to represent the *types* of those members. However the `type'
18969 function (above) will specifically avoid generating type DIEs for member
18970 types *within* the list of member DIEs for this (containing) type except
18971 for those types (of members) which are explicitly marked as also being
18972 members of this (containing) type themselves. The g++ front- end can
18973 force any given type to be treated as a member of some other (containing)
18974 type by setting the TYPE_CONTEXT of the given (member) type to point to
18975 the TREE node representing the appropriate (containing) type. */
18977 /* First output info about the base classes. */
18980 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
18984 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18985 gen_inheritance_die (base
,
18986 (accesses
? (*accesses
)[i
] : access_public_node
),
18990 /* Now output info about the data members and type members. */
18991 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
18993 /* If we thought we were generating minimal debug info for TYPE
18994 and then changed our minds, some of the member declarations
18995 may have already been defined. Don't define them again, but
18996 do put them in the right order. */
18998 child
= lookup_decl_die (member
);
19000 splice_child_die (context_die
, child
);
19002 gen_decl_die (member
, NULL
, context_die
);
19005 /* Now output info about the function members (if any). */
19006 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19008 /* Don't include clones in the member list. */
19009 if (DECL_ABSTRACT_ORIGIN (member
))
19012 child
= lookup_decl_die (member
);
19014 splice_child_die (context_die
, child
);
19016 gen_decl_die (member
, NULL
, context_die
);
19020 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19021 is set, we pretend that the type was never defined, so we only get the
19022 member DIEs needed by later specification DIEs. */
19025 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19026 enum debug_info_usage usage
)
19028 dw_die_ref type_die
= lookup_type_die (type
);
19029 dw_die_ref scope_die
= 0;
19031 int complete
= (TYPE_SIZE (type
)
19032 && (! TYPE_STUB_DECL (type
)
19033 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19034 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19035 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19037 if (type_die
&& ! complete
)
19040 if (TYPE_CONTEXT (type
) != NULL_TREE
19041 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19042 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19045 scope_die
= scope_die_for (type
, context_die
);
19047 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19048 /* First occurrence of type or toplevel definition of nested class. */
19050 dw_die_ref old_die
= type_die
;
19052 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19053 ? record_type_tag (type
) : DW_TAG_union_type
,
19055 equate_type_number_to_die (type
, type_die
);
19057 add_AT_specification (type_die
, old_die
);
19059 add_name_attribute (type_die
, type_tag (type
));
19062 remove_AT (type_die
, DW_AT_declaration
);
19064 /* Generate child dies for template paramaters. */
19065 if (debug_info_level
> DINFO_LEVEL_TERSE
19066 && COMPLETE_TYPE_P (type
))
19067 schedule_generic_params_dies_gen (type
);
19069 /* If this type has been completed, then give it a byte_size attribute and
19070 then give a list of members. */
19071 if (complete
&& !ns_decl
)
19073 /* Prevent infinite recursion in cases where the type of some member of
19074 this type is expressed in terms of this type itself. */
19075 TREE_ASM_WRITTEN (type
) = 1;
19076 add_byte_size_attribute (type_die
, type
);
19077 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19079 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19080 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19083 /* If the first reference to this type was as the return type of an
19084 inline function, then it may not have a parent. Fix this now. */
19085 if (type_die
->die_parent
== NULL
)
19086 add_child_die (scope_die
, type_die
);
19088 push_decl_scope (type
);
19089 gen_member_die (type
, type_die
);
19092 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19093 if (TYPE_ARTIFICIAL (type
))
19094 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19096 /* GNU extension: Record what type our vtable lives in. */
19097 if (TYPE_VFIELD (type
))
19099 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19101 gen_type_die (vtype
, context_die
);
19102 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19103 lookup_type_die (vtype
));
19108 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19110 /* We don't need to do this for function-local types. */
19111 if (TYPE_STUB_DECL (type
)
19112 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19113 vec_safe_push (incomplete_types
, type
);
19116 if (get_AT (type_die
, DW_AT_name
))
19117 add_pubtype (type
, type_die
);
19120 /* Generate a DIE for a subroutine _type_. */
19123 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19125 tree return_type
= TREE_TYPE (type
);
19126 dw_die_ref subr_die
19127 = new_die (DW_TAG_subroutine_type
,
19128 scope_die_for (type
, context_die
), type
);
19130 equate_type_number_to_die (type
, subr_die
);
19131 add_prototyped_attribute (subr_die
, type
);
19132 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19133 gen_formal_types_die (type
, subr_die
);
19135 if (get_AT (subr_die
, DW_AT_name
))
19136 add_pubtype (type
, subr_die
);
19139 /* Generate a DIE for a type definition. */
19142 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19144 dw_die_ref type_die
;
19147 if (TREE_ASM_WRITTEN (decl
))
19150 TREE_ASM_WRITTEN (decl
) = 1;
19151 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19152 origin
= decl_ultimate_origin (decl
);
19153 if (origin
!= NULL
)
19154 add_abstract_origin_attribute (type_die
, origin
);
19159 add_name_and_src_coords_attributes (type_die
, decl
);
19160 if (DECL_ORIGINAL_TYPE (decl
))
19162 type
= DECL_ORIGINAL_TYPE (decl
);
19164 gcc_assert (type
!= TREE_TYPE (decl
));
19165 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19169 type
= TREE_TYPE (decl
);
19171 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19173 /* Here, we are in the case of decl being a typedef naming
19174 an anonymous type, e.g:
19175 typedef struct {...} foo;
19176 In that case TREE_TYPE (decl) is not a typedef variant
19177 type and TYPE_NAME of the anonymous type is set to the
19178 TYPE_DECL of the typedef. This construct is emitted by
19181 TYPE is the anonymous struct named by the typedef
19182 DECL. As we need the DW_AT_type attribute of the
19183 DW_TAG_typedef to point to the DIE of TYPE, let's
19184 generate that DIE right away. add_type_attribute
19185 called below will then pick (via lookup_type_die) that
19186 anonymous struct DIE. */
19187 if (!TREE_ASM_WRITTEN (type
))
19188 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19190 /* This is a GNU Extension. We are adding a
19191 DW_AT_linkage_name attribute to the DIE of the
19192 anonymous struct TYPE. The value of that attribute
19193 is the name of the typedef decl naming the anonymous
19194 struct. This greatly eases the work of consumers of
19195 this debug info. */
19196 add_linkage_attr (lookup_type_die (type
), decl
);
19200 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19201 TREE_THIS_VOLATILE (decl
), context_die
);
19203 if (is_naming_typedef_decl (decl
))
19204 /* We want that all subsequent calls to lookup_type_die with
19205 TYPE in argument yield the DW_TAG_typedef we have just
19207 equate_type_number_to_die (type
, type_die
);
19209 add_accessibility_attribute (type_die
, decl
);
19212 if (DECL_ABSTRACT (decl
))
19213 equate_decl_number_to_die (decl
, type_die
);
19215 if (get_AT (type_die
, DW_AT_name
))
19216 add_pubtype (decl
, type_die
);
19219 /* Generate a DIE for a struct, class, enum or union type. */
19222 gen_tagged_type_die (tree type
,
19223 dw_die_ref context_die
,
19224 enum debug_info_usage usage
)
19228 if (type
== NULL_TREE
19229 || !is_tagged_type (type
))
19232 /* If this is a nested type whose containing class hasn't been written
19233 out yet, writing it out will cover this one, too. This does not apply
19234 to instantiations of member class templates; they need to be added to
19235 the containing class as they are generated. FIXME: This hurts the
19236 idea of combining type decls from multiple TUs, since we can't predict
19237 what set of template instantiations we'll get. */
19238 if (TYPE_CONTEXT (type
)
19239 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19240 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19242 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19244 if (TREE_ASM_WRITTEN (type
))
19247 /* If that failed, attach ourselves to the stub. */
19248 push_decl_scope (TYPE_CONTEXT (type
));
19249 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19252 else if (TYPE_CONTEXT (type
) != NULL_TREE
19253 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19255 /* If this type is local to a function that hasn't been written
19256 out yet, use a NULL context for now; it will be fixed up in
19257 decls_for_scope. */
19258 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19259 /* A declaration DIE doesn't count; nested types need to go in the
19261 if (context_die
&& is_declaration_die (context_die
))
19262 context_die
= NULL
;
19267 context_die
= declare_in_namespace (type
, context_die
);
19271 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19273 /* This might have been written out by the call to
19274 declare_in_namespace. */
19275 if (!TREE_ASM_WRITTEN (type
))
19276 gen_enumeration_type_die (type
, context_die
);
19279 gen_struct_or_union_type_die (type
, context_die
, usage
);
19284 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19285 it up if it is ever completed. gen_*_type_die will set it for us
19286 when appropriate. */
19289 /* Generate a type description DIE. */
19292 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19293 enum debug_info_usage usage
)
19295 struct array_descr_info info
;
19297 if (type
== NULL_TREE
|| type
== error_mark_node
)
19300 if (TYPE_NAME (type
) != NULL_TREE
19301 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19302 && is_redundant_typedef (TYPE_NAME (type
))
19303 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19304 /* The DECL of this type is a typedef we don't want to emit debug
19305 info for but we want debug info for its underlying typedef.
19306 This can happen for e.g, the injected-class-name of a C++
19308 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19310 /* If TYPE is a typedef type variant, let's generate debug info
19311 for the parent typedef which TYPE is a type of. */
19312 if (typedef_variant_p (type
))
19314 if (TREE_ASM_WRITTEN (type
))
19317 /* Prevent broken recursion; we can't hand off to the same type. */
19318 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19320 /* Give typedefs the right scope. */
19321 context_die
= scope_die_for (type
, context_die
);
19323 TREE_ASM_WRITTEN (type
) = 1;
19325 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19329 /* If type is an anonymous tagged type named by a typedef, let's
19330 generate debug info for the typedef. */
19331 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19333 /* Use the DIE of the containing namespace as the parent DIE of
19334 the type description DIE we want to generate. */
19335 if (DECL_CONTEXT (TYPE_NAME (type
))
19336 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19337 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19339 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19343 /* If this is an array type with hidden descriptor, handle it first. */
19344 if (!TREE_ASM_WRITTEN (type
)
19345 && lang_hooks
.types
.get_array_descr_info
19346 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19347 && (dwarf_version
>= 3 || !dwarf_strict
))
19349 gen_descr_array_type_die (type
, &info
, context_die
);
19350 TREE_ASM_WRITTEN (type
) = 1;
19354 /* We are going to output a DIE to represent the unqualified version
19355 of this type (i.e. without any const or volatile qualifiers) so
19356 get the main variant (i.e. the unqualified version) of this type
19357 now. (Vectors are special because the debugging info is in the
19358 cloned type itself). */
19359 if (TREE_CODE (type
) != VECTOR_TYPE
)
19360 type
= type_main_variant (type
);
19362 if (TREE_ASM_WRITTEN (type
))
19365 switch (TREE_CODE (type
))
19371 case REFERENCE_TYPE
:
19372 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19373 ensures that the gen_type_die recursion will terminate even if the
19374 type is recursive. Recursive types are possible in Ada. */
19375 /* ??? We could perhaps do this for all types before the switch
19377 TREE_ASM_WRITTEN (type
) = 1;
19379 /* For these types, all that is required is that we output a DIE (or a
19380 set of DIEs) to represent the "basis" type. */
19381 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19382 DINFO_USAGE_IND_USE
);
19386 /* This code is used for C++ pointer-to-data-member types.
19387 Output a description of the relevant class type. */
19388 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19389 DINFO_USAGE_IND_USE
);
19391 /* Output a description of the type of the object pointed to. */
19392 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19393 DINFO_USAGE_IND_USE
);
19395 /* Now output a DIE to represent this pointer-to-data-member type
19397 gen_ptr_to_mbr_type_die (type
, context_die
);
19400 case FUNCTION_TYPE
:
19401 /* Force out return type (in case it wasn't forced out already). */
19402 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19403 DINFO_USAGE_DIR_USE
);
19404 gen_subroutine_type_die (type
, context_die
);
19408 /* Force out return type (in case it wasn't forced out already). */
19409 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19410 DINFO_USAGE_DIR_USE
);
19411 gen_subroutine_type_die (type
, context_die
);
19415 gen_array_type_die (type
, context_die
);
19419 gen_array_type_die (type
, context_die
);
19422 case ENUMERAL_TYPE
:
19425 case QUAL_UNION_TYPE
:
19426 gen_tagged_type_die (type
, context_die
, usage
);
19432 case FIXED_POINT_TYPE
:
19435 /* No DIEs needed for fundamental types. */
19440 /* Just use DW_TAG_unspecified_type. */
19442 dw_die_ref type_die
= lookup_type_die (type
);
19443 if (type_die
== NULL
)
19445 tree name
= TYPE_NAME (type
);
19446 if (TREE_CODE (name
) == TYPE_DECL
)
19447 name
= DECL_NAME (name
);
19448 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19449 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19450 equate_type_number_to_die (type
, type_die
);
19456 gcc_unreachable ();
19459 TREE_ASM_WRITTEN (type
) = 1;
19463 gen_type_die (tree type
, dw_die_ref context_die
)
19465 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19468 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19469 things which are local to the given block. */
19472 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19474 int must_output_die
= 0;
19477 /* Ignore blocks that are NULL. */
19478 if (stmt
== NULL_TREE
)
19481 inlined_func
= inlined_function_outer_scope_p (stmt
);
19483 /* If the block is one fragment of a non-contiguous block, do not
19484 process the variables, since they will have been done by the
19485 origin block. Do process subblocks. */
19486 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19490 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19491 gen_block_die (sub
, context_die
, depth
+ 1);
19496 /* Determine if we need to output any Dwarf DIEs at all to represent this
19499 /* The outer scopes for inlinings *must* always be represented. We
19500 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19501 must_output_die
= 1;
19504 /* Determine if this block directly contains any "significant"
19505 local declarations which we will need to output DIEs for. */
19506 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19507 /* We are not in terse mode so *any* local declaration counts
19508 as being a "significant" one. */
19509 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19510 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19511 && (TREE_USED (stmt
)
19512 || TREE_ASM_WRITTEN (stmt
)
19513 || BLOCK_ABSTRACT (stmt
)));
19514 else if ((TREE_USED (stmt
)
19515 || TREE_ASM_WRITTEN (stmt
)
19516 || BLOCK_ABSTRACT (stmt
))
19517 && !dwarf2out_ignore_block (stmt
))
19518 must_output_die
= 1;
19521 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19522 DIE for any block which contains no significant local declarations at
19523 all. Rather, in such cases we just call `decls_for_scope' so that any
19524 needed Dwarf info for any sub-blocks will get properly generated. Note
19525 that in terse mode, our definition of what constitutes a "significant"
19526 local declaration gets restricted to include only inlined function
19527 instances and local (nested) function definitions. */
19528 if (must_output_die
)
19532 /* If STMT block is abstract, that means we have been called
19533 indirectly from dwarf2out_abstract_function.
19534 That function rightfully marks the descendent blocks (of
19535 the abstract function it is dealing with) as being abstract,
19536 precisely to prevent us from emitting any
19537 DW_TAG_inlined_subroutine DIE as a descendent
19538 of an abstract function instance. So in that case, we should
19539 not call gen_inlined_subroutine_die.
19541 Later though, when cgraph asks dwarf2out to emit info
19542 for the concrete instance of the function decl into which
19543 the concrete instance of STMT got inlined, the later will lead
19544 to the generation of a DW_TAG_inlined_subroutine DIE. */
19545 if (! BLOCK_ABSTRACT (stmt
))
19546 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19549 gen_lexical_block_die (stmt
, context_die
, depth
);
19552 decls_for_scope (stmt
, context_die
, depth
);
19555 /* Process variable DECL (or variable with origin ORIGIN) within
19556 block STMT and add it to CONTEXT_DIE. */
19558 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19561 tree decl_or_origin
= decl
? decl
: origin
;
19563 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19564 die
= lookup_decl_die (decl_or_origin
);
19565 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19566 && TYPE_DECL_IS_STUB (decl_or_origin
))
19567 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19571 if (die
!= NULL
&& die
->die_parent
== NULL
)
19572 add_child_die (context_die
, die
);
19573 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19574 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19575 stmt
, context_die
);
19577 gen_decl_die (decl
, origin
, context_die
);
19580 /* Generate all of the decls declared within a given scope and (recursively)
19581 all of its sub-blocks. */
19584 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19590 /* Ignore NULL blocks. */
19591 if (stmt
== NULL_TREE
)
19594 /* Output the DIEs to represent all of the data objects and typedefs
19595 declared directly within this block but not within any nested
19596 sub-blocks. Also, nested function and tag DIEs have been
19597 generated with a parent of NULL; fix that up now. */
19598 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19599 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19600 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19601 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19604 /* If we're at -g1, we're not interested in subblocks. */
19605 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19608 /* Output the DIEs to represent all sub-blocks (and the items declared
19609 therein) of this block. */
19610 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19612 subblocks
= BLOCK_CHAIN (subblocks
))
19613 gen_block_die (subblocks
, context_die
, depth
+ 1);
19616 /* Is this a typedef we can avoid emitting? */
19619 is_redundant_typedef (const_tree decl
)
19621 if (TYPE_DECL_IS_STUB (decl
))
19624 if (DECL_ARTIFICIAL (decl
)
19625 && DECL_CONTEXT (decl
)
19626 && is_tagged_type (DECL_CONTEXT (decl
))
19627 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19628 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19629 /* Also ignore the artificial member typedef for the class name. */
19635 /* Return TRUE if TYPE is a typedef that names a type for linkage
19636 purposes. This kind of typedefs is produced by the C++ FE for
19639 typedef struct {...} foo;
19641 In that case, there is no typedef variant type produced for foo.
19642 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19646 is_naming_typedef_decl (const_tree decl
)
19648 if (decl
== NULL_TREE
19649 || TREE_CODE (decl
) != TYPE_DECL
19650 || !is_tagged_type (TREE_TYPE (decl
))
19651 || DECL_IS_BUILTIN (decl
)
19652 || is_redundant_typedef (decl
)
19653 /* It looks like Ada produces TYPE_DECLs that are very similar
19654 to C++ naming typedefs but that have different
19655 semantics. Let's be specific to c++ for now. */
19659 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19660 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19661 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19662 != TYPE_NAME (TREE_TYPE (decl
))));
19665 /* Returns the DIE for a context. */
19667 static inline dw_die_ref
19668 get_context_die (tree context
)
19672 /* Find die that represents this context. */
19673 if (TYPE_P (context
))
19675 context
= TYPE_MAIN_VARIANT (context
);
19676 return strip_naming_typedef (context
, force_type_die (context
));
19679 return force_decl_die (context
);
19681 return comp_unit_die ();
19684 /* Returns the DIE for decl. A DIE will always be returned. */
19687 force_decl_die (tree decl
)
19689 dw_die_ref decl_die
;
19690 unsigned saved_external_flag
;
19691 tree save_fn
= NULL_TREE
;
19692 decl_die
= lookup_decl_die (decl
);
19695 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19697 decl_die
= lookup_decl_die (decl
);
19701 switch (TREE_CODE (decl
))
19703 case FUNCTION_DECL
:
19704 /* Clear current_function_decl, so that gen_subprogram_die thinks
19705 that this is a declaration. At this point, we just want to force
19706 declaration die. */
19707 save_fn
= current_function_decl
;
19708 current_function_decl
= NULL_TREE
;
19709 gen_subprogram_die (decl
, context_die
);
19710 current_function_decl
= save_fn
;
19714 /* Set external flag to force declaration die. Restore it after
19715 gen_decl_die() call. */
19716 saved_external_flag
= DECL_EXTERNAL (decl
);
19717 DECL_EXTERNAL (decl
) = 1;
19718 gen_decl_die (decl
, NULL
, context_die
);
19719 DECL_EXTERNAL (decl
) = saved_external_flag
;
19722 case NAMESPACE_DECL
:
19723 if (dwarf_version
>= 3 || !dwarf_strict
)
19724 dwarf2out_decl (decl
);
19726 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19727 decl_die
= comp_unit_die ();
19730 case TRANSLATION_UNIT_DECL
:
19731 decl_die
= comp_unit_die ();
19735 gcc_unreachable ();
19738 /* We should be able to find the DIE now. */
19740 decl_die
= lookup_decl_die (decl
);
19741 gcc_assert (decl_die
);
19747 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19748 always returned. */
19751 force_type_die (tree type
)
19753 dw_die_ref type_die
;
19755 type_die
= lookup_type_die (type
);
19758 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19760 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19761 TYPE_VOLATILE (type
), context_die
);
19762 gcc_assert (type_die
);
19767 /* Force out any required namespaces to be able to output DECL,
19768 and return the new context_die for it, if it's changed. */
19771 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19773 tree context
= (DECL_P (thing
)
19774 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19775 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19776 /* Force out the namespace. */
19777 context_die
= force_decl_die (context
);
19779 return context_die
;
19782 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19783 type) within its namespace, if appropriate.
19785 For compatibility with older debuggers, namespace DIEs only contain
19786 declarations; all definitions are emitted at CU scope. */
19789 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19791 dw_die_ref ns_context
;
19793 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19794 return context_die
;
19796 /* If this decl is from an inlined function, then don't try to emit it in its
19797 namespace, as we will get confused. It would have already been emitted
19798 when the abstract instance of the inline function was emitted anyways. */
19799 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19800 return context_die
;
19802 ns_context
= setup_namespace_context (thing
, context_die
);
19804 if (ns_context
!= context_die
)
19808 if (DECL_P (thing
))
19809 gen_decl_die (thing
, NULL
, ns_context
);
19811 gen_type_die (thing
, ns_context
);
19813 return context_die
;
19816 /* Generate a DIE for a namespace or namespace alias. */
19819 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19821 dw_die_ref namespace_die
;
19823 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19824 they are an alias of. */
19825 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19827 /* Output a real namespace or module. */
19828 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19829 namespace_die
= new_die (is_fortran ()
19830 ? DW_TAG_module
: DW_TAG_namespace
,
19831 context_die
, decl
);
19832 /* For Fortran modules defined in different CU don't add src coords. */
19833 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19835 const char *name
= dwarf2_name (decl
, 0);
19837 add_name_attribute (namespace_die
, name
);
19840 add_name_and_src_coords_attributes (namespace_die
, decl
);
19841 if (DECL_EXTERNAL (decl
))
19842 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19843 equate_decl_number_to_die (decl
, namespace_die
);
19847 /* Output a namespace alias. */
19849 /* Force out the namespace we are an alias of, if necessary. */
19850 dw_die_ref origin_die
19851 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19853 if (DECL_FILE_SCOPE_P (decl
)
19854 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19855 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19856 /* Now create the namespace alias DIE. */
19857 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19858 add_name_and_src_coords_attributes (namespace_die
, decl
);
19859 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19860 equate_decl_number_to_die (decl
, namespace_die
);
19862 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19863 if (want_pubnames ())
19864 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19867 /* Generate Dwarf debug information for a decl described by DECL.
19868 The return value is currently only meaningful for PARM_DECLs,
19869 for all other decls it returns NULL. */
19872 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19874 tree decl_or_origin
= decl
? decl
: origin
;
19875 tree class_origin
= NULL
, ultimate_origin
;
19877 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19880 switch (TREE_CODE (decl_or_origin
))
19886 if (!is_fortran () && !is_ada ())
19888 /* The individual enumerators of an enum type get output when we output
19889 the Dwarf representation of the relevant enum type itself. */
19893 /* Emit its type. */
19894 gen_type_die (TREE_TYPE (decl
), context_die
);
19896 /* And its containing namespace. */
19897 context_die
= declare_in_namespace (decl
, context_die
);
19899 gen_const_die (decl
, context_die
);
19902 case FUNCTION_DECL
:
19903 /* Don't output any DIEs to represent mere function declarations,
19904 unless they are class members or explicit block externs. */
19905 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19906 && DECL_FILE_SCOPE_P (decl_or_origin
)
19907 && (current_function_decl
== NULL_TREE
19908 || DECL_ARTIFICIAL (decl_or_origin
)))
19913 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19914 on local redeclarations of global functions. That seems broken. */
19915 if (current_function_decl
!= decl
)
19916 /* This is only a declaration. */;
19919 /* If we're emitting a clone, emit info for the abstract instance. */
19920 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19921 dwarf2out_abstract_function (origin
19922 ? DECL_ORIGIN (origin
)
19923 : DECL_ABSTRACT_ORIGIN (decl
));
19925 /* If we're emitting an out-of-line copy of an inline function,
19926 emit info for the abstract instance and set up to refer to it. */
19927 else if (cgraph_function_possibly_inlined_p (decl
)
19928 && ! DECL_ABSTRACT (decl
)
19929 && ! class_or_namespace_scope_p (context_die
)
19930 /* dwarf2out_abstract_function won't emit a die if this is just
19931 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19932 that case, because that works only if we have a die. */
19933 && DECL_INITIAL (decl
) != NULL_TREE
)
19935 dwarf2out_abstract_function (decl
);
19936 set_decl_origin_self (decl
);
19939 /* Otherwise we're emitting the primary DIE for this decl. */
19940 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19942 /* Before we describe the FUNCTION_DECL itself, make sure that we
19943 have its containing type. */
19945 origin
= decl_class_context (decl
);
19946 if (origin
!= NULL_TREE
)
19947 gen_type_die (origin
, context_die
);
19949 /* And its return type. */
19950 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19952 /* And its virtual context. */
19953 if (DECL_VINDEX (decl
) != NULL_TREE
)
19954 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19956 /* Make sure we have a member DIE for decl. */
19957 if (origin
!= NULL_TREE
)
19958 gen_type_die_for_member (origin
, decl
, context_die
);
19960 /* And its containing namespace. */
19961 context_die
= declare_in_namespace (decl
, context_die
);
19964 /* Now output a DIE to represent the function itself. */
19966 gen_subprogram_die (decl
, context_die
);
19970 /* If we are in terse mode, don't generate any DIEs to represent any
19971 actual typedefs. */
19972 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19975 /* In the special case of a TYPE_DECL node representing the declaration
19976 of some type tag, if the given TYPE_DECL is marked as having been
19977 instantiated from some other (original) TYPE_DECL node (e.g. one which
19978 was generated within the original definition of an inline function) we
19979 used to generate a special (abbreviated) DW_TAG_structure_type,
19980 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19981 should be actually referencing those DIEs, as variable DIEs with that
19982 type would be emitted already in the abstract origin, so it was always
19983 removed during unused type prunning. Don't add anything in this
19985 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
19988 if (is_redundant_typedef (decl
))
19989 gen_type_die (TREE_TYPE (decl
), context_die
);
19991 /* Output a DIE to represent the typedef itself. */
19992 gen_typedef_die (decl
, context_die
);
19996 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
19997 gen_label_die (decl
, context_die
);
20002 /* If we are in terse mode, don't generate any DIEs to represent any
20003 variable declarations or definitions. */
20004 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20007 /* Output any DIEs that are needed to specify the type of this data
20009 if (decl_by_reference_p (decl_or_origin
))
20010 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20012 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20014 /* And its containing type. */
20015 class_origin
= decl_class_context (decl_or_origin
);
20016 if (class_origin
!= NULL_TREE
)
20017 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20019 /* And its containing namespace. */
20020 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20022 /* Now output the DIE to represent the data object itself. This gets
20023 complicated because of the possibility that the VAR_DECL really
20024 represents an inlined instance of a formal parameter for an inline
20026 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20027 if (ultimate_origin
!= NULL_TREE
20028 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20029 gen_formal_parameter_die (decl
, origin
,
20030 true /* Emit name attribute. */,
20033 gen_variable_die (decl
, origin
, context_die
);
20037 /* Ignore the nameless fields that are used to skip bits but handle C++
20038 anonymous unions and structs. */
20039 if (DECL_NAME (decl
) != NULL_TREE
20040 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20041 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20043 gen_type_die (member_declared_type (decl
), context_die
);
20044 gen_field_die (decl
, context_die
);
20049 if (DECL_BY_REFERENCE (decl_or_origin
))
20050 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20052 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20053 return gen_formal_parameter_die (decl
, origin
,
20054 true /* Emit name attribute. */,
20057 case NAMESPACE_DECL
:
20058 case IMPORTED_DECL
:
20059 if (dwarf_version
>= 3 || !dwarf_strict
)
20060 gen_namespace_die (decl
, context_die
);
20064 /* Probably some frontend-internal decl. Assume we don't care. */
20065 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20072 /* Output debug information for global decl DECL. Called from toplev.c after
20073 compilation proper has finished. */
20076 dwarf2out_global_decl (tree decl
)
20078 /* Output DWARF2 information for file-scope tentative data object
20079 declarations, file-scope (extern) function declarations (which
20080 had no corresponding body) and file-scope tagged type declarations
20081 and definitions which have not yet been forced out. */
20082 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20083 dwarf2out_decl (decl
);
20086 /* Output debug information for type decl DECL. Called from toplev.c
20087 and from language front ends (to record built-in types). */
20089 dwarf2out_type_decl (tree decl
, int local
)
20092 dwarf2out_decl (decl
);
20095 /* Output debug information for imported module or decl DECL.
20096 NAME is non-NULL name in the lexical block if the decl has been renamed.
20097 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20098 that DECL belongs to.
20099 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20101 dwarf2out_imported_module_or_decl_1 (tree decl
,
20103 tree lexical_block
,
20104 dw_die_ref lexical_block_die
)
20106 expanded_location xloc
;
20107 dw_die_ref imported_die
= NULL
;
20108 dw_die_ref at_import_die
;
20110 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20112 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20113 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20117 xloc
= expand_location (input_location
);
20119 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20121 at_import_die
= force_type_die (TREE_TYPE (decl
));
20122 /* For namespace N { typedef void T; } using N::T; base_type_die
20123 returns NULL, but DW_TAG_imported_declaration requires
20124 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20125 if (!at_import_die
)
20127 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20128 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20129 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20130 gcc_assert (at_import_die
);
20135 at_import_die
= lookup_decl_die (decl
);
20136 if (!at_import_die
)
20138 /* If we're trying to avoid duplicate debug info, we may not have
20139 emitted the member decl for this field. Emit it now. */
20140 if (TREE_CODE (decl
) == FIELD_DECL
)
20142 tree type
= DECL_CONTEXT (decl
);
20144 if (TYPE_CONTEXT (type
)
20145 && TYPE_P (TYPE_CONTEXT (type
))
20146 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20147 DINFO_USAGE_DIR_USE
))
20149 gen_type_die_for_member (type
, decl
,
20150 get_context_die (TYPE_CONTEXT (type
)));
20152 at_import_die
= force_decl_die (decl
);
20156 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20158 if (dwarf_version
>= 3 || !dwarf_strict
)
20159 imported_die
= new_die (DW_TAG_imported_module
,
20166 imported_die
= new_die (DW_TAG_imported_declaration
,
20170 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20171 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20173 add_AT_string (imported_die
, DW_AT_name
,
20174 IDENTIFIER_POINTER (name
));
20175 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20178 /* Output debug information for imported module or decl DECL.
20179 NAME is non-NULL name in context if the decl has been renamed.
20180 CHILD is true if decl is one of the renamed decls as part of
20181 importing whole module. */
20184 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20187 /* dw_die_ref at_import_die; */
20188 dw_die_ref scope_die
;
20190 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20195 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20196 We need decl DIE for reference and scope die. First, get DIE for the decl
20199 /* Get the scope die for decl context. Use comp_unit_die for global module
20200 or decl. If die is not found for non globals, force new die. */
20202 && TYPE_P (context
)
20203 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20206 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20209 scope_die
= get_context_die (context
);
20213 gcc_assert (scope_die
->die_child
);
20214 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20215 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20216 scope_die
= scope_die
->die_child
;
20219 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20220 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20224 /* Write the debugging output for DECL. */
20227 dwarf2out_decl (tree decl
)
20229 dw_die_ref context_die
= comp_unit_die ();
20231 switch (TREE_CODE (decl
))
20236 case FUNCTION_DECL
:
20237 /* What we would really like to do here is to filter out all mere
20238 file-scope declarations of file-scope functions which are never
20239 referenced later within this translation unit (and keep all of ones
20240 that *are* referenced later on) but we aren't clairvoyant, so we have
20241 no idea which functions will be referenced in the future (i.e. later
20242 on within the current translation unit). So here we just ignore all
20243 file-scope function declarations which are not also definitions. If
20244 and when the debugger needs to know something about these functions,
20245 it will have to hunt around and find the DWARF information associated
20246 with the definition of the function.
20248 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20249 nodes represent definitions and which ones represent mere
20250 declarations. We have to check DECL_INITIAL instead. That's because
20251 the C front-end supports some weird semantics for "extern inline"
20252 function definitions. These can get inlined within the current
20253 translation unit (and thus, we need to generate Dwarf info for their
20254 abstract instances so that the Dwarf info for the concrete inlined
20255 instances can have something to refer to) but the compiler never
20256 generates any out-of-lines instances of such things (despite the fact
20257 that they *are* definitions).
20259 The important point is that the C front-end marks these "extern
20260 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20261 them anyway. Note that the C++ front-end also plays some similar games
20262 for inline function definitions appearing within include files which
20263 also contain `#pragma interface' pragmas.
20265 If we are called from dwarf2out_abstract_function output a DIE
20266 anyway. We can end up here this way with early inlining and LTO
20267 where the inlined function is output in a different LTRANS unit
20269 if (DECL_INITIAL (decl
) == NULL_TREE
20270 && ! DECL_ABSTRACT (decl
))
20273 /* If we're a nested function, initially use a parent of NULL; if we're
20274 a plain function, this will be fixed up in decls_for_scope. If
20275 we're a method, it will be ignored, since we already have a DIE. */
20276 if (decl_function_context (decl
)
20277 /* But if we're in terse mode, we don't care about scope. */
20278 && debug_info_level
> DINFO_LEVEL_TERSE
)
20279 context_die
= NULL
;
20283 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20284 declaration and if the declaration was never even referenced from
20285 within this entire compilation unit. We suppress these DIEs in
20286 order to save space in the .debug section (by eliminating entries
20287 which are probably useless). Note that we must not suppress
20288 block-local extern declarations (whether used or not) because that
20289 would screw-up the debugger's name lookup mechanism and cause it to
20290 miss things which really ought to be in scope at a given point. */
20291 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20294 /* For local statics lookup proper context die. */
20295 if (TREE_STATIC (decl
)
20296 && DECL_CONTEXT (decl
)
20297 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20298 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20300 /* If we are in terse mode, don't generate any DIEs to represent any
20301 variable declarations or definitions. */
20302 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20307 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20309 if (!is_fortran () && !is_ada ())
20311 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20312 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20315 case NAMESPACE_DECL
:
20316 case IMPORTED_DECL
:
20317 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20319 if (lookup_decl_die (decl
) != NULL
)
20324 /* Don't emit stubs for types unless they are needed by other DIEs. */
20325 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20328 /* Don't bother trying to generate any DIEs to represent any of the
20329 normal built-in types for the language we are compiling. */
20330 if (DECL_IS_BUILTIN (decl
))
20333 /* If we are in terse mode, don't generate any DIEs for types. */
20334 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20337 /* If we're a function-scope tag, initially use a parent of NULL;
20338 this will be fixed up in decls_for_scope. */
20339 if (decl_function_context (decl
))
20340 context_die
= NULL
;
20348 gen_decl_die (decl
, NULL
, context_die
);
20351 /* Write the debugging output for DECL. */
20354 dwarf2out_function_decl (tree decl
)
20356 dwarf2out_decl (decl
);
20357 call_arg_locations
= NULL
;
20358 call_arg_loc_last
= NULL
;
20359 call_site_count
= -1;
20360 tail_call_site_count
= -1;
20361 block_map
.release ();
20362 htab_empty (decl_loc_table
);
20363 htab_empty (cached_dw_loc_list_table
);
20366 /* Output a marker (i.e. a label) for the beginning of the generated code for
20367 a lexical block. */
20370 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20371 unsigned int blocknum
)
20373 switch_to_section (current_function_section ());
20374 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20377 /* Output a marker (i.e. a label) for the end of the generated code for a
20381 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20383 switch_to_section (current_function_section ());
20384 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20387 /* Returns nonzero if it is appropriate not to emit any debugging
20388 information for BLOCK, because it doesn't contain any instructions.
20390 Don't allow this for blocks with nested functions or local classes
20391 as we would end up with orphans, and in the presence of scheduling
20392 we may end up calling them anyway. */
20395 dwarf2out_ignore_block (const_tree block
)
20400 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20401 if (TREE_CODE (decl
) == FUNCTION_DECL
20402 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20404 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20406 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20407 if (TREE_CODE (decl
) == FUNCTION_DECL
20408 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20415 /* Hash table routines for file_hash. */
20418 file_table_eq (const void *p1_p
, const void *p2_p
)
20420 const struct dwarf_file_data
*const p1
=
20421 (const struct dwarf_file_data
*) p1_p
;
20422 const char *const p2
= (const char *) p2_p
;
20423 return filename_cmp (p1
->filename
, p2
) == 0;
20427 file_table_hash (const void *p_p
)
20429 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20430 return htab_hash_string (p
->filename
);
20433 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20434 dwarf2out.c) and return its "index". The index of each (known) filename is
20435 just a unique number which is associated with only that one filename. We
20436 need such numbers for the sake of generating labels (in the .debug_sfnames
20437 section) and references to those files numbers (in the .debug_srcinfo
20438 and.debug_macinfo sections). If the filename given as an argument is not
20439 found in our current list, add it to the list and assign it the next
20440 available unique index number. In order to speed up searches, we remember
20441 the index of the filename was looked up last. This handles the majority of
20444 static struct dwarf_file_data
*
20445 lookup_filename (const char *file_name
)
20448 struct dwarf_file_data
* created
;
20450 /* Check to see if the file name that was searched on the previous
20451 call matches this file name. If so, return the index. */
20452 if (file_table_last_lookup
20453 && (file_name
== file_table_last_lookup
->filename
20454 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20455 return file_table_last_lookup
;
20457 /* Didn't match the previous lookup, search the table. */
20458 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20459 htab_hash_string (file_name
), INSERT
);
20461 return (struct dwarf_file_data
*) *slot
;
20463 created
= ggc_alloc_dwarf_file_data ();
20464 created
->filename
= file_name
;
20465 created
->emitted_number
= 0;
20470 /* If the assembler will construct the file table, then translate the compiler
20471 internal file table number into the assembler file table number, and emit
20472 a .file directive if we haven't already emitted one yet. The file table
20473 numbers are different because we prune debug info for unused variables and
20474 types, which may include filenames. */
20477 maybe_emit_file (struct dwarf_file_data
* fd
)
20479 if (! fd
->emitted_number
)
20481 if (last_emitted_file
)
20482 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20484 fd
->emitted_number
= 1;
20485 last_emitted_file
= fd
;
20487 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20489 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20490 output_quoted_string (asm_out_file
,
20491 remap_debug_filename (fd
->filename
));
20492 fputc ('\n', asm_out_file
);
20496 return fd
->emitted_number
;
20499 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20500 That generation should happen after function debug info has been
20501 generated. The value of the attribute is the constant value of ARG. */
20504 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20506 die_arg_entry entry
;
20511 if (!tmpl_value_parm_die_table
)
20512 vec_alloc (tmpl_value_parm_die_table
, 32);
20516 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20519 /* Return TRUE if T is an instance of generic type, FALSE
20523 generic_type_p (tree t
)
20525 if (t
== NULL_TREE
|| !TYPE_P (t
))
20527 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20530 /* Schedule the generation of the generic parameter dies for the
20531 instance of generic type T. The proper generation itself is later
20532 done by gen_scheduled_generic_parms_dies. */
20535 schedule_generic_params_dies_gen (tree t
)
20537 if (!generic_type_p (t
))
20540 if (!generic_type_instances
)
20541 vec_alloc (generic_type_instances
, 256);
20543 vec_safe_push (generic_type_instances
, t
);
20546 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20547 by append_entry_to_tmpl_value_parm_die_table. This function must
20548 be called after function DIEs have been generated. */
20551 gen_remaining_tmpl_value_param_die_attribute (void)
20553 if (tmpl_value_parm_die_table
)
20558 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20559 tree_add_const_value_attribute (e
->die
, e
->arg
);
20563 /* Generate generic parameters DIEs for instances of generic types
20564 that have been previously scheduled by
20565 schedule_generic_params_dies_gen. This function must be called
20566 after all the types of the CU have been laid out. */
20569 gen_scheduled_generic_parms_dies (void)
20574 if (!generic_type_instances
)
20577 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20578 gen_generic_params_dies (t
);
20582 /* Replace DW_AT_name for the decl with name. */
20585 dwarf2out_set_name (tree decl
, tree name
)
20591 die
= TYPE_SYMTAB_DIE (decl
);
20595 dname
= dwarf2_name (name
, 0);
20599 attr
= get_AT (die
, DW_AT_name
);
20602 struct indirect_string_node
*node
;
20604 node
= find_AT_string (dname
);
20605 /* replace the string. */
20606 attr
->dw_attr_val
.v
.val_str
= node
;
20610 add_name_attribute (die
, dname
);
20613 /* Called by the final INSN scan whenever we see a var location. We
20614 use it to drop labels in the right places, and throw the location in
20615 our lookup table. */
20618 dwarf2out_var_location (rtx loc_note
)
20620 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20621 struct var_loc_node
*newloc
;
20622 rtx next_real
, next_note
;
20623 static const char *last_label
;
20624 static const char *last_postcall_label
;
20625 static bool last_in_cold_section_p
;
20626 static rtx expected_next_loc_note
;
20630 if (!NOTE_P (loc_note
))
20632 if (CALL_P (loc_note
))
20635 if (SIBLING_CALL_P (loc_note
))
20636 tail_call_site_count
++;
20641 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20642 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20645 /* Optimize processing a large consecutive sequence of location
20646 notes so we don't spend too much time in next_real_insn. If the
20647 next insn is another location note, remember the next_real_insn
20648 calculation for next time. */
20649 next_real
= cached_next_real_insn
;
20652 if (expected_next_loc_note
!= loc_note
)
20653 next_real
= NULL_RTX
;
20656 next_note
= NEXT_INSN (loc_note
);
20658 || INSN_DELETED_P (next_note
)
20659 || GET_CODE (next_note
) != NOTE
20660 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20661 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20662 next_note
= NULL_RTX
;
20665 next_real
= next_real_insn (loc_note
);
20669 expected_next_loc_note
= next_note
;
20670 cached_next_real_insn
= next_real
;
20673 cached_next_real_insn
= NULL_RTX
;
20675 /* If there are no instructions which would be affected by this note,
20676 don't do anything. */
20678 && next_real
== NULL_RTX
20679 && !NOTE_DURING_CALL_P (loc_note
))
20682 if (next_real
== NULL_RTX
)
20683 next_real
= get_last_insn ();
20685 /* If there were any real insns between note we processed last time
20686 and this note (or if it is the first note), clear
20687 last_{,postcall_}label so that they are not reused this time. */
20688 if (last_var_location_insn
== NULL_RTX
20689 || last_var_location_insn
!= next_real
20690 || last_in_cold_section_p
!= in_cold_section_p
)
20693 last_postcall_label
= NULL
;
20698 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20699 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20700 NOTE_DURING_CALL_P (loc_note
)
20701 ? last_postcall_label
: last_label
);
20702 if (newloc
== NULL
)
20711 /* If there were no real insns between note we processed last time
20712 and this note, use the label we emitted last time. Otherwise
20713 create a new label and emit it. */
20714 if (last_label
== NULL
)
20716 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20717 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20719 last_label
= ggc_strdup (loclabel
);
20724 struct call_arg_loc_node
*ca_loc
20725 = ggc_alloc_cleared_call_arg_loc_node ();
20726 rtx prev
= prev_real_insn (loc_note
), x
;
20727 ca_loc
->call_arg_loc_note
= loc_note
;
20728 ca_loc
->next
= NULL
;
20729 ca_loc
->label
= last_label
;
20732 || (NONJUMP_INSN_P (prev
)
20733 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20734 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20735 if (!CALL_P (prev
))
20736 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20737 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20738 x
= get_call_rtx_from (PATTERN (prev
));
20741 x
= XEXP (XEXP (x
, 0), 0);
20742 if (GET_CODE (x
) == SYMBOL_REF
20743 && SYMBOL_REF_DECL (x
)
20744 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20745 ca_loc
->symbol_ref
= x
;
20747 ca_loc
->block
= insn_scope (prev
);
20748 if (call_arg_locations
)
20749 call_arg_loc_last
->next
= ca_loc
;
20751 call_arg_locations
= ca_loc
;
20752 call_arg_loc_last
= ca_loc
;
20754 else if (!NOTE_DURING_CALL_P (loc_note
))
20755 newloc
->label
= last_label
;
20758 if (!last_postcall_label
)
20760 sprintf (loclabel
, "%s-1", last_label
);
20761 last_postcall_label
= ggc_strdup (loclabel
);
20763 newloc
->label
= last_postcall_label
;
20766 last_var_location_insn
= next_real
;
20767 last_in_cold_section_p
= in_cold_section_p
;
20770 /* Note in one location list that text section has changed. */
20773 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20775 var_loc_list
*list
= (var_loc_list
*) *slot
;
20777 list
->last_before_switch
20778 = list
->last
->next
? list
->last
->next
: list
->last
;
20782 /* Note in all location lists that text section has changed. */
20785 var_location_switch_text_section (void)
20787 if (decl_loc_table
== NULL
)
20790 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20793 /* Create a new line number table. */
20795 static dw_line_info_table
*
20796 new_line_info_table (void)
20798 dw_line_info_table
*table
;
20800 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20801 table
->file_num
= 1;
20802 table
->line_num
= 1;
20803 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20808 /* Lookup the "current" table into which we emit line info, so
20809 that we don't have to do it for every source line. */
20812 set_cur_line_info_table (section
*sec
)
20814 dw_line_info_table
*table
;
20816 if (sec
== text_section
)
20817 table
= text_section_line_info
;
20818 else if (sec
== cold_text_section
)
20820 table
= cold_text_section_line_info
;
20823 cold_text_section_line_info
= table
= new_line_info_table ();
20824 table
->end_label
= cold_end_label
;
20829 const char *end_label
;
20831 if (flag_reorder_blocks_and_partition
)
20833 if (in_cold_section_p
)
20834 end_label
= crtl
->subsections
.cold_section_end_label
;
20836 end_label
= crtl
->subsections
.hot_section_end_label
;
20840 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20841 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20842 current_function_funcdef_no
);
20843 end_label
= ggc_strdup (label
);
20846 table
= new_line_info_table ();
20847 table
->end_label
= end_label
;
20849 vec_safe_push (separate_line_info
, table
);
20852 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20853 table
->is_stmt
= (cur_line_info_table
20854 ? cur_line_info_table
->is_stmt
20855 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20856 cur_line_info_table
= table
;
20860 /* We need to reset the locations at the beginning of each
20861 function. We can't do this in the end_function hook, because the
20862 declarations that use the locations won't have been output when
20863 that hook is called. Also compute have_multiple_function_sections here. */
20866 dwarf2out_begin_function (tree fun
)
20868 section
*sec
= function_section (fun
);
20870 if (sec
!= text_section
)
20871 have_multiple_function_sections
= true;
20873 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20875 gcc_assert (current_function_decl
== fun
);
20876 cold_text_section
= unlikely_text_section ();
20877 switch_to_section (cold_text_section
);
20878 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20879 switch_to_section (sec
);
20882 dwarf2out_note_section_used ();
20883 call_site_count
= 0;
20884 tail_call_site_count
= 0;
20886 set_cur_line_info_table (sec
);
20889 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20892 push_dw_line_info_entry (dw_line_info_table
*table
,
20893 enum dw_line_info_opcode opcode
, unsigned int val
)
20895 dw_line_info_entry e
;
20898 vec_safe_push (table
->entries
, e
);
20901 /* Output a label to mark the beginning of a source code line entry
20902 and record information relating to this source line, in
20903 'line_info_table' for later output of the .debug_line section. */
20904 /* ??? The discriminator parameter ought to be unsigned. */
20907 dwarf2out_source_line (unsigned int line
, const char *filename
,
20908 int discriminator
, bool is_stmt
)
20910 unsigned int file_num
;
20911 dw_line_info_table
*table
;
20913 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20916 /* The discriminator column was added in dwarf4. Simplify the below
20917 by simply removing it if we're not supposed to output it. */
20918 if (dwarf_version
< 4 && dwarf_strict
)
20921 table
= cur_line_info_table
;
20922 file_num
= maybe_emit_file (lookup_filename (filename
));
20924 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20925 the debugger has used the second (possibly duplicate) line number
20926 at the beginning of the function to mark the end of the prologue.
20927 We could eliminate any other duplicates within the function. For
20928 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20929 that second line number entry. */
20930 /* Recall that this end-of-prologue indication is *not* the same thing
20931 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20932 to which the hook corresponds, follows the last insn that was
20933 emitted by gen_prologue. What we need is to precede the first insn
20934 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20935 insn that corresponds to something the user wrote. These may be
20936 very different locations once scheduling is enabled. */
20938 if (0 && file_num
== table
->file_num
20939 && line
== table
->line_num
20940 && discriminator
== table
->discrim_num
20941 && is_stmt
== table
->is_stmt
)
20944 switch_to_section (current_function_section ());
20946 /* If requested, emit something human-readable. */
20947 if (flag_debug_asm
)
20948 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20950 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20952 /* Emit the .loc directive understood by GNU as. */
20953 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20954 file_num, line, is_stmt, discriminator */
20955 fputs ("\t.loc ", asm_out_file
);
20956 fprint_ul (asm_out_file
, file_num
);
20957 putc (' ', asm_out_file
);
20958 fprint_ul (asm_out_file
, line
);
20959 putc (' ', asm_out_file
);
20960 putc ('0', asm_out_file
);
20962 if (is_stmt
!= table
->is_stmt
)
20964 fputs (" is_stmt ", asm_out_file
);
20965 putc (is_stmt
? '1' : '0', asm_out_file
);
20967 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20969 gcc_assert (discriminator
> 0);
20970 fputs (" discriminator ", asm_out_file
);
20971 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20973 putc ('\n', asm_out_file
);
20977 unsigned int label_num
= ++line_info_label_num
;
20979 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20981 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20982 if (file_num
!= table
->file_num
)
20983 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20984 if (discriminator
!= table
->discrim_num
)
20985 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
20986 if (is_stmt
!= table
->is_stmt
)
20987 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
20988 push_dw_line_info_entry (table
, LI_set_line
, line
);
20991 table
->file_num
= file_num
;
20992 table
->line_num
= line
;
20993 table
->discrim_num
= discriminator
;
20994 table
->is_stmt
= is_stmt
;
20995 table
->in_use
= true;
20998 /* Record the beginning of a new source file. */
21001 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21003 if (flag_eliminate_dwarf2_dups
)
21005 /* Record the beginning of the file for break_out_includes. */
21006 dw_die_ref bincl_die
;
21008 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21009 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21012 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21015 e
.code
= DW_MACINFO_start_file
;
21017 e
.info
= ggc_strdup (filename
);
21018 vec_safe_push (macinfo_table
, e
);
21022 /* Record the end of a source file. */
21025 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21027 if (flag_eliminate_dwarf2_dups
)
21028 /* Record the end of the file for break_out_includes. */
21029 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21031 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21034 e
.code
= DW_MACINFO_end_file
;
21037 vec_safe_push (macinfo_table
, e
);
21041 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21042 the tail part of the directive line, i.e. the part which is past the
21043 initial whitespace, #, whitespace, directive-name, whitespace part. */
21046 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21047 const char *buffer ATTRIBUTE_UNUSED
)
21049 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21052 /* Insert a dummy first entry to be able to optimize the whole
21053 predefined macro block using DW_MACRO_GNU_transparent_include. */
21054 if (macinfo_table
->is_empty () && lineno
<= 1)
21059 vec_safe_push (macinfo_table
, e
);
21061 e
.code
= DW_MACINFO_define
;
21063 e
.info
= ggc_strdup (buffer
);
21064 vec_safe_push (macinfo_table
, e
);
21068 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21069 the tail part of the directive line, i.e. the part which is past the
21070 initial whitespace, #, whitespace, directive-name, whitespace part. */
21073 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21074 const char *buffer ATTRIBUTE_UNUSED
)
21076 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21079 /* Insert a dummy first entry to be able to optimize the whole
21080 predefined macro block using DW_MACRO_GNU_transparent_include. */
21081 if (macinfo_table
->is_empty () && lineno
<= 1)
21086 vec_safe_push (macinfo_table
, e
);
21088 e
.code
= DW_MACINFO_undef
;
21090 e
.info
= ggc_strdup (buffer
);
21091 vec_safe_push (macinfo_table
, e
);
21095 /* Routines to manipulate hash table of CUs. */
21098 htab_macinfo_hash (const void *of
)
21100 const macinfo_entry
*const entry
=
21101 (const macinfo_entry
*) of
;
21103 return htab_hash_string (entry
->info
);
21107 htab_macinfo_eq (const void *of1
, const void *of2
)
21109 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21110 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21112 return !strcmp (entry1
->info
, entry2
->info
);
21115 /* Output a single .debug_macinfo entry. */
21118 output_macinfo_op (macinfo_entry
*ref
)
21122 struct indirect_string_node
*node
;
21123 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21124 struct dwarf_file_data
*fd
;
21128 case DW_MACINFO_start_file
:
21129 fd
= lookup_filename (ref
->info
);
21130 file_num
= maybe_emit_file (fd
);
21131 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21132 dw2_asm_output_data_uleb128 (ref
->lineno
,
21133 "Included from line number %lu",
21134 (unsigned long) ref
->lineno
);
21135 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21137 case DW_MACINFO_end_file
:
21138 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21140 case DW_MACINFO_define
:
21141 case DW_MACINFO_undef
:
21142 len
= strlen (ref
->info
) + 1;
21144 && len
> DWARF_OFFSET_SIZE
21145 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21146 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21148 ref
->code
= ref
->code
== DW_MACINFO_define
21149 ? DW_MACRO_GNU_define_indirect
21150 : DW_MACRO_GNU_undef_indirect
;
21151 output_macinfo_op (ref
);
21154 dw2_asm_output_data (1, ref
->code
,
21155 ref
->code
== DW_MACINFO_define
21156 ? "Define macro" : "Undefine macro");
21157 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21158 (unsigned long) ref
->lineno
);
21159 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21161 case DW_MACRO_GNU_define_indirect
:
21162 case DW_MACRO_GNU_undef_indirect
:
21163 node
= find_AT_string (ref
->info
);
21165 && ((node
->form
== DW_FORM_strp
)
21166 || (node
->form
== DW_FORM_GNU_str_index
)));
21167 dw2_asm_output_data (1, ref
->code
,
21168 ref
->code
== DW_MACRO_GNU_define_indirect
21169 ? "Define macro indirect"
21170 : "Undefine macro indirect");
21171 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21172 (unsigned long) ref
->lineno
);
21173 if (node
->form
== DW_FORM_strp
)
21174 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21175 debug_str_section
, "The macro: \"%s\"",
21178 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21181 case DW_MACRO_GNU_transparent_include
:
21182 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21183 ASM_GENERATE_INTERNAL_LABEL (label
,
21184 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21185 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21188 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21189 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21194 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21195 other compilation unit .debug_macinfo sections. IDX is the first
21196 index of a define/undef, return the number of ops that should be
21197 emitted in a comdat .debug_macinfo section and emit
21198 a DW_MACRO_GNU_transparent_include entry referencing it.
21199 If the define/undef entry should be emitted normally, return 0. */
21202 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21203 htab_t
*macinfo_htab
)
21205 macinfo_entry
*first
, *second
, *cur
, *inc
;
21206 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21207 unsigned char checksum
[16];
21208 struct md5_ctx ctx
;
21209 char *grp_name
, *tail
;
21211 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21214 first
= &(*macinfo_table
)[idx
];
21215 second
= &(*macinfo_table
)[idx
+ 1];
21217 /* Optimize only if there are at least two consecutive define/undef ops,
21218 and either all of them are before first DW_MACINFO_start_file
21219 with lineno {0,1} (i.e. predefined macro block), or all of them are
21220 in some included header file. */
21221 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21223 if (vec_safe_is_empty (files
))
21225 if (first
->lineno
> 1 || second
->lineno
> 1)
21228 else if (first
->lineno
== 0)
21231 /* Find the last define/undef entry that can be grouped together
21232 with first and at the same time compute md5 checksum of their
21233 codes, linenumbers and strings. */
21234 md5_init_ctx (&ctx
);
21235 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21236 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21238 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21242 unsigned char code
= cur
->code
;
21243 md5_process_bytes (&code
, 1, &ctx
);
21244 checksum_uleb128 (cur
->lineno
, &ctx
);
21245 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21247 md5_finish_ctx (&ctx
, checksum
);
21250 /* From the containing include filename (if any) pick up just
21251 usable characters from its basename. */
21252 if (vec_safe_is_empty (files
))
21255 base
= lbasename (files
->last ().info
);
21256 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21257 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21258 encoded_filename_len
++;
21259 /* Count . at the end. */
21260 if (encoded_filename_len
)
21261 encoded_filename_len
++;
21263 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21264 linebuf_len
= strlen (linebuf
);
21266 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21267 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21269 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21270 tail
= grp_name
+ 4;
21271 if (encoded_filename_len
)
21273 for (i
= 0; base
[i
]; i
++)
21274 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21278 memcpy (tail
, linebuf
, linebuf_len
);
21279 tail
+= linebuf_len
;
21281 for (i
= 0; i
< 16; i
++)
21282 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21284 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21285 in the empty vector entry before the first define/undef. */
21286 inc
= &(*macinfo_table
)[idx
- 1];
21287 inc
->code
= DW_MACRO_GNU_transparent_include
;
21289 inc
->info
= ggc_strdup (grp_name
);
21290 if (*macinfo_htab
== NULL
)
21291 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21292 /* Avoid emitting duplicates. */
21293 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21298 /* If such an entry has been used before, just emit
21299 a DW_MACRO_GNU_transparent_include op. */
21300 inc
= (macinfo_entry
*) *slot
;
21301 output_macinfo_op (inc
);
21302 /* And clear all macinfo_entry in the range to avoid emitting them
21303 in the second pass. */
21304 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21313 inc
->lineno
= htab_elements (*macinfo_htab
);
21314 output_macinfo_op (inc
);
21319 /* Save any strings needed by the macinfo table in the debug str
21320 table. All strings must be collected into the table by the time
21321 index_string is called. */
21324 save_macinfo_strings (void)
21328 macinfo_entry
*ref
;
21330 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21334 /* Match the logic in output_macinfo_op to decide on
21335 indirect strings. */
21336 case DW_MACINFO_define
:
21337 case DW_MACINFO_undef
:
21338 len
= strlen (ref
->info
) + 1;
21340 && len
> DWARF_OFFSET_SIZE
21341 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21342 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21343 set_indirect_string (find_AT_string (ref
->info
));
21345 case DW_MACRO_GNU_define_indirect
:
21346 case DW_MACRO_GNU_undef_indirect
:
21347 set_indirect_string (find_AT_string (ref
->info
));
21355 /* Output macinfo section(s). */
21358 output_macinfo (void)
21361 unsigned long length
= vec_safe_length (macinfo_table
);
21362 macinfo_entry
*ref
;
21363 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21364 htab_t macinfo_htab
= NULL
;
21369 /* output_macinfo* uses these interchangeably. */
21370 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21371 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21372 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21373 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21375 /* For .debug_macro emit the section header. */
21378 dw2_asm_output_data (2, 4, "DWARF macro version number");
21379 if (DWARF_OFFSET_SIZE
== 8)
21380 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21382 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21383 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21384 (!dwarf_split_debug_info
? debug_line_section_label
21385 : debug_skeleton_line_section_label
),
21386 debug_line_section
, NULL
);
21389 /* In the first loop, it emits the primary .debug_macinfo section
21390 and after each emitted op the macinfo_entry is cleared.
21391 If a longer range of define/undef ops can be optimized using
21392 DW_MACRO_GNU_transparent_include, the
21393 DW_MACRO_GNU_transparent_include op is emitted and kept in
21394 the vector before the first define/undef in the range and the
21395 whole range of define/undef ops is not emitted and kept. */
21396 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21400 case DW_MACINFO_start_file
:
21401 vec_safe_push (files
, *ref
);
21403 case DW_MACINFO_end_file
:
21404 if (!vec_safe_is_empty (files
))
21407 case DW_MACINFO_define
:
21408 case DW_MACINFO_undef
:
21410 && HAVE_COMDAT_GROUP
21411 && vec_safe_length (files
) != 1
21414 && (*macinfo_table
)[i
- 1].code
== 0)
21416 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21425 /* A dummy entry may be inserted at the beginning to be able
21426 to optimize the whole block of predefined macros. */
21432 output_macinfo_op (ref
);
21437 if (macinfo_htab
== NULL
)
21440 htab_delete (macinfo_htab
);
21442 /* If any DW_MACRO_GNU_transparent_include were used, on those
21443 DW_MACRO_GNU_transparent_include entries terminate the
21444 current chain and switch to a new comdat .debug_macinfo
21445 section and emit the define/undef entries within it. */
21446 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21451 case DW_MACRO_GNU_transparent_include
:
21453 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21454 tree comdat_key
= get_identifier (ref
->info
);
21455 /* Terminate the previous .debug_macinfo section. */
21456 dw2_asm_output_data (1, 0, "End compilation unit");
21457 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21459 | SECTION_LINKONCE
,
21461 ASM_GENERATE_INTERNAL_LABEL (label
,
21462 DEBUG_MACRO_SECTION_LABEL
,
21464 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21467 dw2_asm_output_data (2, 4, "DWARF macro version number");
21468 if (DWARF_OFFSET_SIZE
== 8)
21469 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21471 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21474 case DW_MACINFO_define
:
21475 case DW_MACINFO_undef
:
21476 output_macinfo_op (ref
);
21481 gcc_unreachable ();
21485 /* Set up for Dwarf output at the start of compilation. */
21488 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21490 /* Allocate the file_table. */
21491 file_table
= htab_create_ggc (50, file_table_hash
,
21492 file_table_eq
, NULL
);
21494 /* Allocate the decl_die_table. */
21495 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21496 decl_die_table_eq
, NULL
);
21498 /* Allocate the decl_loc_table. */
21499 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21500 decl_loc_table_eq
, NULL
);
21502 /* Allocate the cached_dw_loc_list_table. */
21503 cached_dw_loc_list_table
21504 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21505 cached_dw_loc_list_table_eq
, NULL
);
21507 /* Allocate the initial hunk of the decl_scope_table. */
21508 vec_alloc (decl_scope_table
, 256);
21510 /* Allocate the initial hunk of the abbrev_die_table. */
21511 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21512 (ABBREV_DIE_TABLE_INCREMENT
);
21513 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21514 /* Zero-th entry is allocated, but unused. */
21515 abbrev_die_table_in_use
= 1;
21517 /* Allocate the pubtypes and pubnames vectors. */
21518 vec_alloc (pubname_table
, 32);
21519 vec_alloc (pubtype_table
, 32);
21521 vec_alloc (incomplete_types
, 64);
21523 vec_alloc (used_rtx_array
, 32);
21525 if (!dwarf_split_debug_info
)
21527 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21528 SECTION_DEBUG
, NULL
);
21529 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21530 SECTION_DEBUG
, NULL
);
21531 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21532 SECTION_DEBUG
, NULL
);
21536 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21537 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21538 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21539 SECTION_DEBUG
| SECTION_EXCLUDE
,
21541 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21542 SECTION_DEBUG
, NULL
);
21543 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21544 SECTION_DEBUG
, NULL
);
21545 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21546 SECTION_DEBUG
, NULL
);
21547 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21548 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21550 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21551 the main .o, but the skeleton_line goes into the split off dwo. */
21552 debug_skeleton_line_section
21553 = get_section (DEBUG_DWO_LINE_SECTION
,
21554 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21555 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21556 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21557 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21558 SECTION_DEBUG
| SECTION_EXCLUDE
,
21560 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21561 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21562 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21563 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21565 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21566 SECTION_DEBUG
, NULL
);
21567 debug_macinfo_section
= get_section (dwarf_strict
21568 ? DEBUG_MACINFO_SECTION
21569 : DEBUG_MACRO_SECTION
,
21570 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21571 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21572 SECTION_DEBUG
, NULL
);
21573 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21574 SECTION_DEBUG
, NULL
);
21575 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21576 SECTION_DEBUG
, NULL
);
21577 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21578 DEBUG_STR_SECTION_FLAGS
, NULL
);
21579 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21580 SECTION_DEBUG
, NULL
);
21581 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21582 SECTION_DEBUG
, NULL
);
21584 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21585 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21586 DEBUG_ABBREV_SECTION_LABEL
, 0);
21587 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21588 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21589 COLD_TEXT_SECTION_LABEL
, 0);
21590 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21592 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21593 DEBUG_INFO_SECTION_LABEL
, 0);
21594 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21595 DEBUG_LINE_SECTION_LABEL
, 0);
21596 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21597 DEBUG_RANGES_SECTION_LABEL
, 0);
21598 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21599 DEBUG_ADDR_SECTION_LABEL
, 0);
21600 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21602 ? DEBUG_MACINFO_SECTION_LABEL
21603 : DEBUG_MACRO_SECTION_LABEL
, 0);
21604 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21606 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21607 vec_alloc (macinfo_table
, 64);
21609 switch_to_section (text_section
);
21610 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21612 /* Make sure the line number table for .text always exists. */
21613 text_section_line_info
= new_line_info_table ();
21614 text_section_line_info
->end_label
= text_end_label
;
21617 /* Called before compile () starts outputtting functions, variables
21618 and toplevel asms into assembly. */
21621 dwarf2out_assembly_start (void)
21623 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21624 && dwarf2out_do_cfi_asm ()
21625 && (!(flag_unwind_tables
|| flag_exceptions
)
21626 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21627 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21630 /* A helper function for dwarf2out_finish called through
21631 htab_traverse. Assign a string its index. All strings must be
21632 collected into the table by the time index_string is called,
21633 because the indexing code relies on htab_traverse to traverse nodes
21634 in the same order for each run. */
21637 index_string (void **h
, void *v
)
21639 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21640 unsigned int *index
= (unsigned int *) v
;
21642 find_string_form (node
);
21643 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21645 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21646 node
->index
= *index
;
21652 /* A helper function for output_indirect_strings called through
21653 htab_traverse. Output the offset to a string and update the
21657 output_index_string_offset (void **h
, void *v
)
21659 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21660 unsigned int *offset
= (unsigned int *) v
;
21662 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21664 /* Assert that this node has been assigned an index. */
21665 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21666 && node
->index
!= NOT_INDEXED
);
21667 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21668 "indexed string 0x%x: %s", node
->index
, node
->str
);
21669 *offset
+= strlen (node
->str
) + 1;
21674 /* A helper function for dwarf2out_finish called through
21675 htab_traverse. Output the indexed string. */
21678 output_index_string (void **h
, void *v
)
21680 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21681 unsigned int *cur_idx
= (unsigned int *) v
;
21683 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21685 /* Assert that the strings are output in the same order as their
21686 indexes were assigned. */
21687 gcc_assert (*cur_idx
== node
->index
);
21688 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21689 assemble_string (node
->str
, strlen (node
->str
) + 1);
21695 /* A helper function for dwarf2out_finish called through
21696 htab_traverse. Emit one queued .debug_str string. */
21699 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21701 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21703 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
21705 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21706 assemble_string (node
->str
, strlen (node
->str
) + 1);
21712 /* Output the indexed string table. */
21715 output_indirect_strings (void)
21717 if (!dwarf_split_debug_info
)
21719 switch_to_section (debug_str_section
);
21720 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
21724 unsigned int offset
= 0;
21725 unsigned int cur_idx
= 0;
21727 switch_to_section (debug_str_offsets_section
);
21728 htab_traverse_noresize (debug_str_hash
,
21729 output_index_string_offset
,
21731 switch_to_section (debug_str_section
);
21732 htab_traverse_noresize (debug_str_hash
,
21733 output_index_string
,
21738 /* Callback for htab_traverse to assign an index to an entry in the
21739 table, and to write that entry to the .debug_addr section. */
21742 output_addr_table_entry (void **slot
, void *data
)
21744 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
21745 unsigned int *cur_index
= (unsigned int *)data
;
21747 if (entry
->refcount
== 0)
21749 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
21750 || entry
->index
== NOT_INDEXED
);
21754 gcc_assert (entry
->index
== *cur_index
);
21757 switch (entry
->kind
)
21760 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
21761 "0x%x", entry
->index
);
21763 case ate_kind_rtx_dtprel
:
21764 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
21765 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
21768 fputc ('\n', asm_out_file
);
21770 case ate_kind_label
:
21771 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
21772 "0x%x", entry
->index
);
21775 gcc_unreachable ();
21780 /* Produce the .debug_addr section. */
21783 output_addr_table (void)
21785 unsigned int index
= 0;
21786 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
21789 switch_to_section (debug_addr_section
);
21790 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
21793 #if ENABLE_ASSERT_CHECKING
21794 /* Verify that all marks are clear. */
21797 verify_marks_clear (dw_die_ref die
)
21801 gcc_assert (! die
->die_mark
);
21802 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21804 #endif /* ENABLE_ASSERT_CHECKING */
21806 /* Clear the marks for a die and its children.
21807 Be cool if the mark isn't set. */
21810 prune_unmark_dies (dw_die_ref die
)
21816 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21819 /* Given DIE that we're marking as used, find any other dies
21820 it references as attributes and mark them as used. */
21823 prune_unused_types_walk_attribs (dw_die_ref die
)
21828 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
21830 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21832 /* A reference to another DIE.
21833 Make sure that it will get emitted.
21834 If it was broken out into a comdat group, don't follow it. */
21835 if (! AT_ref (a
)->comdat_type_p
21836 || a
->dw_attr
== DW_AT_specification
)
21837 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21839 /* Set the string's refcount to 0 so that prune_unused_types_mark
21840 accounts properly for it. */
21841 if (AT_class (a
) == dw_val_class_str
)
21842 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21846 /* Mark the generic parameters and arguments children DIEs of DIE. */
21849 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21853 if (die
== NULL
|| die
->die_child
== NULL
)
21855 c
= die
->die_child
;
21858 switch (c
->die_tag
)
21860 case DW_TAG_template_type_param
:
21861 case DW_TAG_template_value_param
:
21862 case DW_TAG_GNU_template_template_param
:
21863 case DW_TAG_GNU_template_parameter_pack
:
21864 prune_unused_types_mark (c
, 1);
21870 } while (c
&& c
!= die
->die_child
);
21873 /* Mark DIE as being used. If DOKIDS is true, then walk down
21874 to DIE's children. */
21877 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21881 if (die
->die_mark
== 0)
21883 /* We haven't done this node yet. Mark it as used. */
21885 /* If this is the DIE of a generic type instantiation,
21886 mark the children DIEs that describe its generic parms and
21888 prune_unused_types_mark_generic_parms_dies (die
);
21890 /* We also have to mark its parents as used.
21891 (But we don't want to mark our parents' kids due to this.) */
21892 if (die
->die_parent
)
21893 prune_unused_types_mark (die
->die_parent
, 0);
21895 /* Mark any referenced nodes. */
21896 prune_unused_types_walk_attribs (die
);
21898 /* If this node is a specification,
21899 also mark the definition, if it exists. */
21900 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21901 prune_unused_types_mark (die
->die_definition
, 1);
21904 if (dokids
&& die
->die_mark
!= 2)
21906 /* We need to walk the children, but haven't done so yet.
21907 Remember that we've walked the kids. */
21910 /* If this is an array type, we need to make sure our
21911 kids get marked, even if they're types. If we're
21912 breaking out types into comdat sections, do this
21913 for all type definitions. */
21914 if (die
->die_tag
== DW_TAG_array_type
21915 || (use_debug_types
21916 && is_type_die (die
) && ! is_declaration_die (die
)))
21917 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21919 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21923 /* For local classes, look if any static member functions were emitted
21924 and if so, mark them. */
21927 prune_unused_types_walk_local_classes (dw_die_ref die
)
21931 if (die
->die_mark
== 2)
21934 switch (die
->die_tag
)
21936 case DW_TAG_structure_type
:
21937 case DW_TAG_union_type
:
21938 case DW_TAG_class_type
:
21941 case DW_TAG_subprogram
:
21942 if (!get_AT_flag (die
, DW_AT_declaration
)
21943 || die
->die_definition
!= NULL
)
21944 prune_unused_types_mark (die
, 1);
21951 /* Mark children. */
21952 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21955 /* Walk the tree DIE and mark types that we actually use. */
21958 prune_unused_types_walk (dw_die_ref die
)
21962 /* Don't do anything if this node is already marked and
21963 children have been marked as well. */
21964 if (die
->die_mark
== 2)
21967 switch (die
->die_tag
)
21969 case DW_TAG_structure_type
:
21970 case DW_TAG_union_type
:
21971 case DW_TAG_class_type
:
21972 if (die
->die_perennial_p
)
21975 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21976 if (c
->die_tag
== DW_TAG_subprogram
)
21979 /* Finding used static member functions inside of classes
21980 is needed just for local classes, because for other classes
21981 static member function DIEs with DW_AT_specification
21982 are emitted outside of the DW_TAG_*_type. If we ever change
21983 it, we'd need to call this even for non-local classes. */
21985 prune_unused_types_walk_local_classes (die
);
21987 /* It's a type node --- don't mark it. */
21990 case DW_TAG_const_type
:
21991 case DW_TAG_packed_type
:
21992 case DW_TAG_pointer_type
:
21993 case DW_TAG_reference_type
:
21994 case DW_TAG_rvalue_reference_type
:
21995 case DW_TAG_volatile_type
:
21996 case DW_TAG_typedef
:
21997 case DW_TAG_array_type
:
21998 case DW_TAG_interface_type
:
21999 case DW_TAG_friend
:
22000 case DW_TAG_variant_part
:
22001 case DW_TAG_enumeration_type
:
22002 case DW_TAG_subroutine_type
:
22003 case DW_TAG_string_type
:
22004 case DW_TAG_set_type
:
22005 case DW_TAG_subrange_type
:
22006 case DW_TAG_ptr_to_member_type
:
22007 case DW_TAG_file_type
:
22008 if (die
->die_perennial_p
)
22011 /* It's a type node --- don't mark it. */
22015 /* Mark everything else. */
22019 if (die
->die_mark
== 0)
22023 /* Now, mark any dies referenced from here. */
22024 prune_unused_types_walk_attribs (die
);
22029 /* Mark children. */
22030 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22033 /* Increment the string counts on strings referred to from DIE's
22037 prune_unused_types_update_strings (dw_die_ref die
)
22042 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22043 if (AT_class (a
) == dw_val_class_str
)
22045 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22047 /* Avoid unnecessarily putting strings that are used less than
22048 twice in the hash table. */
22050 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22053 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22054 htab_hash_string (s
->str
),
22056 gcc_assert (*slot
== NULL
);
22062 /* Remove from the tree DIE any dies that aren't marked. */
22065 prune_unused_types_prune (dw_die_ref die
)
22070 gcc_assert (die
->die_mark
);
22071 prune_unused_types_update_strings (die
);
22073 if (! die
->die_child
)
22076 c
= die
->die_child
;
22078 dw_die_ref prev
= c
;
22079 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22080 if (c
== die
->die_child
)
22082 /* No marked children between 'prev' and the end of the list. */
22084 /* No marked children at all. */
22085 die
->die_child
= NULL
;
22088 prev
->die_sib
= c
->die_sib
;
22089 die
->die_child
= prev
;
22095 if (c
!= prev
->die_sib
)
22100 prune_unused_types_prune (c
);
22101 } while (c
!= die
->die_child
);
22104 /* If we pruned children, and this is a class, mark it as a
22105 declaration to inform debuggers that this is not a complete
22106 class definition. */
22107 if (pruned
&& die
->die_mark
== 1 && class_scope_p (die
)
22108 && ! is_declaration_die (die
))
22109 add_AT_flag (die
, DW_AT_declaration
, 1);
22112 /* Remove dies representing declarations that we never use. */
22115 prune_unused_types (void)
22118 limbo_die_node
*node
;
22119 comdat_type_node
*ctnode
;
22121 dw_die_ref base_type
;
22123 #if ENABLE_ASSERT_CHECKING
22124 /* All the marks should already be clear. */
22125 verify_marks_clear (comp_unit_die ());
22126 for (node
= limbo_die_list
; node
; node
= node
->next
)
22127 verify_marks_clear (node
->die
);
22128 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22129 verify_marks_clear (ctnode
->root_die
);
22130 #endif /* ENABLE_ASSERT_CHECKING */
22132 /* Mark types that are used in global variables. */
22133 premark_types_used_by_global_vars ();
22135 /* Set the mark on nodes that are actually used. */
22136 prune_unused_types_walk (comp_unit_die ());
22137 for (node
= limbo_die_list
; node
; node
= node
->next
)
22138 prune_unused_types_walk (node
->die
);
22139 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22141 prune_unused_types_walk (ctnode
->root_die
);
22142 prune_unused_types_mark (ctnode
->type_die
, 1);
22145 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22146 are unusual in that they are pubnames that are the children of pubtypes.
22147 They should only be marked via their parent DW_TAG_enumeration_type die,
22148 not as roots in themselves. */
22149 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22150 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22151 prune_unused_types_mark (pub
->die
, 1);
22152 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22153 prune_unused_types_mark (base_type
, 1);
22155 if (debug_str_hash
)
22156 htab_empty (debug_str_hash
);
22157 prune_unused_types_prune (comp_unit_die ());
22158 for (node
= limbo_die_list
; node
; node
= node
->next
)
22159 prune_unused_types_prune (node
->die
);
22160 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22161 prune_unused_types_prune (ctnode
->root_die
);
22163 /* Leave the marks clear. */
22164 prune_unmark_dies (comp_unit_die ());
22165 for (node
= limbo_die_list
; node
; node
= node
->next
)
22166 prune_unmark_dies (node
->die
);
22167 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22168 prune_unmark_dies (ctnode
->root_die
);
22171 /* Set the parameter to true if there are any relative pathnames in
22174 file_table_relative_p (void ** slot
, void *param
)
22176 bool *p
= (bool *) param
;
22177 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22178 if (!IS_ABSOLUTE_PATH (d
->filename
))
22186 /* Routines to manipulate hash table of comdat type units. */
22189 htab_ct_hash (const void *of
)
22192 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22194 memcpy (&h
, type_node
->signature
, sizeof (h
));
22199 htab_ct_eq (const void *of1
, const void *of2
)
22201 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22202 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22204 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22205 DWARF_TYPE_SIGNATURE_SIZE
));
22208 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22209 to the location it would have been added, should we know its
22210 DECL_ASSEMBLER_NAME when we added other attributes. This will
22211 probably improve compactness of debug info, removing equivalent
22212 abbrevs, and hide any differences caused by deferring the
22213 computation of the assembler name, triggered by e.g. PCH. */
22216 move_linkage_attr (dw_die_ref die
)
22218 unsigned ix
= vec_safe_length (die
->die_attr
);
22219 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22221 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22222 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22226 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22228 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22232 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22234 die
->die_attr
->pop ();
22235 die
->die_attr
->quick_insert (ix
, linkage
);
22239 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22240 referenced from typed stack ops and count how often they are used. */
22243 mark_base_types (dw_loc_descr_ref loc
)
22245 dw_die_ref base_type
= NULL
;
22247 for (; loc
; loc
= loc
->dw_loc_next
)
22249 switch (loc
->dw_loc_opc
)
22251 case DW_OP_GNU_regval_type
:
22252 case DW_OP_GNU_deref_type
:
22253 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22255 case DW_OP_GNU_convert
:
22256 case DW_OP_GNU_reinterpret
:
22257 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22260 case DW_OP_GNU_const_type
:
22261 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22263 case DW_OP_GNU_entry_value
:
22264 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22269 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22270 if (base_type
->die_mark
)
22271 base_type
->die_mark
++;
22274 base_types
.safe_push (base_type
);
22275 base_type
->die_mark
= 1;
22280 /* Comparison function for sorting marked base types. */
22283 base_type_cmp (const void *x
, const void *y
)
22285 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22286 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22287 unsigned int byte_size1
, byte_size2
;
22288 unsigned int encoding1
, encoding2
;
22289 if (dx
->die_mark
> dy
->die_mark
)
22291 if (dx
->die_mark
< dy
->die_mark
)
22293 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22294 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22295 if (byte_size1
< byte_size2
)
22297 if (byte_size1
> byte_size2
)
22299 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22300 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22301 if (encoding1
< encoding2
)
22303 if (encoding1
> encoding2
)
22308 /* Move base types marked by mark_base_types as early as possible
22309 in the CU, sorted by decreasing usage count both to make the
22310 uleb128 references as small as possible and to make sure they
22311 will have die_offset already computed by calc_die_sizes when
22312 sizes of typed stack loc ops is computed. */
22315 move_marked_base_types (void)
22318 dw_die_ref base_type
, die
, c
;
22320 if (base_types
.is_empty ())
22323 /* Sort by decreasing usage count, they will be added again in that
22325 base_types
.qsort (base_type_cmp
);
22326 die
= comp_unit_die ();
22327 c
= die
->die_child
;
22330 dw_die_ref prev
= c
;
22332 while (c
->die_mark
)
22334 remove_child_with_prev (c
, prev
);
22335 /* As base types got marked, there must be at least
22336 one node other than DW_TAG_base_type. */
22337 gcc_assert (c
!= c
->die_sib
);
22341 while (c
!= die
->die_child
);
22342 gcc_assert (die
->die_child
);
22343 c
= die
->die_child
;
22344 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22346 base_type
->die_mark
= 0;
22347 base_type
->die_sib
= c
->die_sib
;
22348 c
->die_sib
= base_type
;
22353 /* Helper function for resolve_addr, attempt to resolve
22354 one CONST_STRING, return non-zero if not successful. Similarly verify that
22355 SYMBOL_REFs refer to variables emitted in the current CU. */
22358 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22362 if (GET_CODE (rtl
) == CONST_STRING
)
22364 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22365 tree t
= build_string (len
, XSTR (rtl
, 0));
22366 tree tlen
= size_int (len
- 1);
22368 = build_array_type (char_type_node
, build_index_type (tlen
));
22369 rtl
= lookup_constant_def (t
);
22370 if (!rtl
|| !MEM_P (rtl
))
22372 rtl
= XEXP (rtl
, 0);
22373 vec_safe_push (used_rtx_array
, rtl
);
22378 if (GET_CODE (rtl
) == SYMBOL_REF
22379 && SYMBOL_REF_DECL (rtl
))
22381 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22383 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22386 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22390 if (GET_CODE (rtl
) == CONST
22391 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22397 /* Helper function for resolve_addr, handle one location
22398 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22399 the location list couldn't be resolved. */
22402 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22404 dw_loc_descr_ref keep
= NULL
;
22405 for (; loc
; loc
= loc
->dw_loc_next
)
22406 switch (loc
->dw_loc_opc
)
22409 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22412 case DW_OP_GNU_addr_index
:
22413 case DW_OP_GNU_const_index
:
22415 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22416 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22417 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22422 case DW_OP_const4u
:
22423 case DW_OP_const8u
:
22425 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22428 case DW_OP_plus_uconst
:
22429 if (size_of_loc_descr (loc
)
22430 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22432 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22434 dw_loc_descr_ref repl
22435 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22436 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22437 add_loc_descr (&repl
, loc
->dw_loc_next
);
22441 case DW_OP_implicit_value
:
22442 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22443 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22446 case DW_OP_GNU_implicit_pointer
:
22447 case DW_OP_GNU_parameter_ref
:
22448 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22451 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22454 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22455 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22456 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22459 case DW_OP_GNU_const_type
:
22460 case DW_OP_GNU_regval_type
:
22461 case DW_OP_GNU_deref_type
:
22462 case DW_OP_GNU_convert
:
22463 case DW_OP_GNU_reinterpret
:
22464 while (loc
->dw_loc_next
22465 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22467 dw_die_ref base1
, base2
;
22468 unsigned enc1
, enc2
, size1
, size2
;
22469 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22470 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22471 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22472 else if (loc
->dw_loc_oprnd1
.val_class
22473 == dw_val_class_unsigned_const
)
22476 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22477 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22478 == dw_val_class_unsigned_const
)
22480 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22481 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22482 && base2
->die_tag
== DW_TAG_base_type
);
22483 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22484 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22485 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22486 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22488 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22489 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22493 /* Optimize away next DW_OP_GNU_convert after
22494 adjusting LOC's base type die reference. */
22495 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22496 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22497 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22499 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22500 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22503 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22504 point typed stack entry. */
22505 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22506 keep
= loc
->dw_loc_next
;
22516 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22517 an address in .rodata section if the string literal is emitted there,
22518 or remove the containing location list or replace DW_AT_const_value
22519 with DW_AT_location and empty location expression, if it isn't found
22520 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22521 to something that has been emitted in the current CU. */
22524 resolve_addr (dw_die_ref die
)
22528 dw_loc_list_ref
*curr
, *start
, loc
;
22531 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22532 switch (AT_class (a
))
22534 case dw_val_class_loc_list
:
22535 start
= curr
= AT_loc_list_ptr (a
);
22538 /* The same list can be referenced more than once. See if we have
22539 already recorded the result from a previous pass. */
22541 *curr
= loc
->dw_loc_next
;
22542 else if (!loc
->resolved_addr
)
22544 /* As things stand, we do not expect or allow one die to
22545 reference a suffix of another die's location list chain.
22546 References must be identical or completely separate.
22547 There is therefore no need to cache the result of this
22548 pass on any list other than the first; doing so
22549 would lead to unnecessary writes. */
22552 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22553 if (!resolve_addr_in_expr ((*curr
)->expr
))
22555 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22556 dw_loc_descr_ref l
= (*curr
)->expr
;
22558 if (next
&& (*curr
)->ll_symbol
)
22560 gcc_assert (!next
->ll_symbol
);
22561 next
->ll_symbol
= (*curr
)->ll_symbol
;
22563 if (dwarf_split_debug_info
)
22564 remove_loc_list_addr_table_entries (l
);
22569 mark_base_types ((*curr
)->expr
);
22570 curr
= &(*curr
)->dw_loc_next
;
22574 loc
->resolved_addr
= 1;
22578 if (dwarf_split_debug_info
)
22579 remove_loc_list_addr_table_entries (loc
->expr
);
22580 loc
->dw_loc_next
= *start
;
22585 remove_AT (die
, a
->dw_attr
);
22589 case dw_val_class_loc
:
22591 dw_loc_descr_ref l
= AT_loc (a
);
22592 /* For -gdwarf-2 don't attempt to optimize
22593 DW_AT_data_member_location containing
22594 DW_OP_plus_uconst - older consumers might
22595 rely on it being that op instead of a more complex,
22596 but shorter, location description. */
22597 if ((dwarf_version
> 2
22598 || a
->dw_attr
!= DW_AT_data_member_location
22600 || l
->dw_loc_opc
!= DW_OP_plus_uconst
22601 || l
->dw_loc_next
!= NULL
)
22602 && !resolve_addr_in_expr (l
))
22604 if (dwarf_split_debug_info
)
22605 remove_loc_list_addr_table_entries (l
);
22606 remove_AT (die
, a
->dw_attr
);
22610 mark_base_types (l
);
22613 case dw_val_class_addr
:
22614 if (a
->dw_attr
== DW_AT_const_value
22615 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22617 if (AT_index (a
) != NOT_INDEXED
)
22618 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22619 remove_AT (die
, a
->dw_attr
);
22622 if (die
->die_tag
== DW_TAG_GNU_call_site
22623 && a
->dw_attr
== DW_AT_abstract_origin
)
22625 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
22626 dw_die_ref tdie
= lookup_decl_die (tdecl
);
22628 && DECL_EXTERNAL (tdecl
)
22629 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
22631 force_decl_die (tdecl
);
22632 tdie
= lookup_decl_die (tdecl
);
22636 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
22637 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
22638 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
22642 if (AT_index (a
) != NOT_INDEXED
)
22643 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22644 remove_AT (die
, a
->dw_attr
);
22653 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22656 /* Helper routines for optimize_location_lists.
22657 This pass tries to share identical local lists in .debug_loc
22660 /* Iteratively hash operands of LOC opcode. */
22662 static inline hashval_t
22663 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
22665 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
22666 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
22668 switch (loc
->dw_loc_opc
)
22670 case DW_OP_const4u
:
22671 case DW_OP_const8u
:
22675 case DW_OP_const1u
:
22676 case DW_OP_const1s
:
22677 case DW_OP_const2u
:
22678 case DW_OP_const2s
:
22679 case DW_OP_const4s
:
22680 case DW_OP_const8s
:
22684 case DW_OP_plus_uconst
:
22720 case DW_OP_deref_size
:
22721 case DW_OP_xderef_size
:
22722 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22729 gcc_assert (val1
->val_class
== dw_val_class_loc
);
22730 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
22731 hash
= iterative_hash_object (offset
, hash
);
22734 case DW_OP_implicit_value
:
22735 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22736 switch (val2
->val_class
)
22738 case dw_val_class_const
:
22739 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22741 case dw_val_class_vec
:
22743 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22744 unsigned int len
= val2
->v
.val_vec
.length
;
22746 hash
= iterative_hash_object (elt_size
, hash
);
22747 hash
= iterative_hash_object (len
, hash
);
22748 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22749 len
* elt_size
, hash
);
22752 case dw_val_class_const_double
:
22753 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22754 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22756 case dw_val_class_addr
:
22757 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
22760 gcc_unreachable ();
22764 case DW_OP_bit_piece
:
22765 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22766 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22772 unsigned char dtprel
= 0xd1;
22773 hash
= iterative_hash_object (dtprel
, hash
);
22775 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
22777 case DW_OP_GNU_addr_index
:
22778 case DW_OP_GNU_const_index
:
22782 unsigned char dtprel
= 0xd1;
22783 hash
= iterative_hash_object (dtprel
, hash
);
22785 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
22788 case DW_OP_GNU_implicit_pointer
:
22789 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22791 case DW_OP_GNU_entry_value
:
22792 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
22794 case DW_OP_GNU_regval_type
:
22795 case DW_OP_GNU_deref_type
:
22797 unsigned int byte_size
22798 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22799 unsigned int encoding
22800 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
22801 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22802 hash
= iterative_hash_object (byte_size
, hash
);
22803 hash
= iterative_hash_object (encoding
, hash
);
22806 case DW_OP_GNU_convert
:
22807 case DW_OP_GNU_reinterpret
:
22808 if (val1
->val_class
== dw_val_class_unsigned_const
)
22810 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22814 case DW_OP_GNU_const_type
:
22816 unsigned int byte_size
22817 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22818 unsigned int encoding
22819 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
22820 hash
= iterative_hash_object (byte_size
, hash
);
22821 hash
= iterative_hash_object (encoding
, hash
);
22822 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
22824 hash
= iterative_hash_object (val2
->val_class
, hash
);
22825 switch (val2
->val_class
)
22827 case dw_val_class_const
:
22828 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22830 case dw_val_class_vec
:
22832 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22833 unsigned int len
= val2
->v
.val_vec
.length
;
22835 hash
= iterative_hash_object (elt_size
, hash
);
22836 hash
= iterative_hash_object (len
, hash
);
22837 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22838 len
* elt_size
, hash
);
22841 case dw_val_class_const_double
:
22842 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22843 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22846 gcc_unreachable ();
22852 /* Other codes have no operands. */
22858 /* Iteratively hash the whole DWARF location expression LOC. */
22860 static inline hashval_t
22861 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
22863 dw_loc_descr_ref l
;
22864 bool sizes_computed
= false;
22865 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22866 size_of_locs (loc
);
22868 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
22870 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
22871 hash
= iterative_hash_object (opc
, hash
);
22872 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
22874 size_of_locs (loc
);
22875 sizes_computed
= true;
22877 hash
= hash_loc_operands (l
, hash
);
22882 /* Compute hash of the whole location list LIST_HEAD. */
22885 hash_loc_list (dw_loc_list_ref list_head
)
22887 dw_loc_list_ref curr
= list_head
;
22888 hashval_t hash
= 0;
22890 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
22892 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
22893 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
22895 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22897 hash
= hash_locs (curr
->expr
, hash
);
22899 list_head
->hash
= hash
;
22902 /* Return true if X and Y opcodes have the same operands. */
22905 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22907 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22908 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22909 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22910 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22912 switch (x
->dw_loc_opc
)
22914 case DW_OP_const4u
:
22915 case DW_OP_const8u
:
22919 case DW_OP_const1u
:
22920 case DW_OP_const1s
:
22921 case DW_OP_const2u
:
22922 case DW_OP_const2s
:
22923 case DW_OP_const4s
:
22924 case DW_OP_const8s
:
22928 case DW_OP_plus_uconst
:
22964 case DW_OP_deref_size
:
22965 case DW_OP_xderef_size
:
22966 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22969 /* If splitting debug info, the use of DW_OP_GNU_addr_index
22970 can cause irrelevant differences in dw_loc_addr. */
22971 gcc_assert (valx1
->val_class
== dw_val_class_loc
22972 && valy1
->val_class
== dw_val_class_loc
22973 && (dwarf_split_debug_info
22974 || x
->dw_loc_addr
== y
->dw_loc_addr
));
22975 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22976 case DW_OP_implicit_value
:
22977 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22978 || valx2
->val_class
!= valy2
->val_class
)
22980 switch (valx2
->val_class
)
22982 case dw_val_class_const
:
22983 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22984 case dw_val_class_vec
:
22985 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
22986 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
22987 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
22988 valx2
->v
.val_vec
.elt_size
22989 * valx2
->v
.val_vec
.length
) == 0;
22990 case dw_val_class_const_double
:
22991 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
22992 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
22993 case dw_val_class_addr
:
22994 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
22996 gcc_unreachable ();
22999 case DW_OP_bit_piece
:
23000 return valx1
->v
.val_int
== valy1
->v
.val_int
23001 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23004 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23005 case DW_OP_GNU_addr_index
:
23006 case DW_OP_GNU_const_index
:
23008 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23009 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23010 return rtx_equal_p (ax1
, ay1
);
23012 case DW_OP_GNU_implicit_pointer
:
23013 return valx1
->val_class
== dw_val_class_die_ref
23014 && valx1
->val_class
== valy1
->val_class
23015 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23016 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23017 case DW_OP_GNU_entry_value
:
23018 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23019 case DW_OP_GNU_const_type
:
23020 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23021 || valx2
->val_class
!= valy2
->val_class
)
23023 switch (valx2
->val_class
)
23025 case dw_val_class_const
:
23026 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23027 case dw_val_class_vec
:
23028 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23029 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23030 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23031 valx2
->v
.val_vec
.elt_size
23032 * valx2
->v
.val_vec
.length
) == 0;
23033 case dw_val_class_const_double
:
23034 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23035 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23037 gcc_unreachable ();
23039 case DW_OP_GNU_regval_type
:
23040 case DW_OP_GNU_deref_type
:
23041 return valx1
->v
.val_int
== valy1
->v
.val_int
23042 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23043 case DW_OP_GNU_convert
:
23044 case DW_OP_GNU_reinterpret
:
23045 if (valx1
->val_class
!= valy1
->val_class
)
23047 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23048 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23049 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23050 case DW_OP_GNU_parameter_ref
:
23051 return valx1
->val_class
== dw_val_class_die_ref
23052 && valx1
->val_class
== valy1
->val_class
23053 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23055 /* Other codes have no operands. */
23060 /* Return true if DWARF location expressions X and Y are the same. */
23063 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23065 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23066 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23067 || x
->dtprel
!= y
->dtprel
23068 || !compare_loc_operands (x
, y
))
23070 return x
== NULL
&& y
== NULL
;
23073 /* Return precomputed hash of location list X. */
23076 loc_list_hash (const void *x
)
23078 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23081 /* Return 1 if location lists X and Y are the same. */
23084 loc_list_eq (const void *x
, const void *y
)
23086 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23087 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23090 if (a
->hash
!= b
->hash
)
23092 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23093 if (strcmp (a
->begin
, b
->begin
) != 0
23094 || strcmp (a
->end
, b
->end
) != 0
23095 || (a
->section
== NULL
) != (b
->section
== NULL
)
23096 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23097 || !compare_locs (a
->expr
, b
->expr
))
23099 return a
== NULL
&& b
== NULL
;
23102 /* Recursively optimize location lists referenced from DIE
23103 children and share them whenever possible. */
23106 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23113 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23114 if (AT_class (a
) == dw_val_class_loc_list
)
23116 dw_loc_list_ref list
= AT_loc_list (a
);
23117 /* TODO: perform some optimizations here, before hashing
23118 it and storing into the hash table. */
23119 hash_loc_list (list
);
23120 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23123 *slot
= (void *) list
;
23125 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23128 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23132 /* Recursively assign each location list a unique index into the debug_addr
23136 index_location_lists (dw_die_ref die
)
23142 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23143 if (AT_class (a
) == dw_val_class_loc_list
)
23145 dw_loc_list_ref list
= AT_loc_list (a
);
23146 dw_loc_list_ref curr
;
23147 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23149 /* Don't index an entry that has already been indexed
23150 or won't be output. */
23151 if (curr
->begin_entry
!= NULL
23152 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23156 = add_addr_table_entry (xstrdup (curr
->begin
),
23161 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23164 /* Optimize location lists referenced from DIE
23165 children and share them whenever possible. */
23168 optimize_location_lists (dw_die_ref die
)
23170 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23171 optimize_location_lists_1 (die
, htab
);
23172 htab_delete (htab
);
23175 /* Output stuff that dwarf requires at the end of every file,
23176 and generate the DWARF-2 debugging info. */
23179 dwarf2out_finish (const char *filename
)
23181 limbo_die_node
*node
, *next_node
;
23182 comdat_type_node
*ctnode
;
23183 htab_t comdat_type_table
;
23185 dw_die_ref main_comp_unit_die
;
23187 /* PCH might result in DW_AT_producer string being restored from the
23188 header compilation, so always fill it with empty string initially
23189 and overwrite only here. */
23190 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23191 producer_string
= gen_producer_string ();
23192 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23193 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23195 gen_scheduled_generic_parms_dies ();
23196 gen_remaining_tmpl_value_param_die_attribute ();
23198 /* Add the name for the main input file now. We delayed this from
23199 dwarf2out_init to avoid complications with PCH. */
23200 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23201 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23202 add_comp_dir_attribute (comp_unit_die ());
23203 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23206 htab_traverse (file_table
, file_table_relative_p
, &p
);
23208 add_comp_dir_attribute (comp_unit_die ());
23211 if (deferred_locations_list
)
23212 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23214 add_location_or_const_value_attribute (
23215 (*deferred_locations_list
)[i
].die
,
23216 (*deferred_locations_list
)[i
].variable
,
23221 /* Traverse the limbo die list, and add parent/child links. The only
23222 dies without parents that should be here are concrete instances of
23223 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23224 For concrete instances, we can get the parent die from the abstract
23226 for (node
= limbo_die_list
; node
; node
= next_node
)
23228 dw_die_ref die
= node
->die
;
23229 next_node
= node
->next
;
23231 if (die
->die_parent
== NULL
)
23233 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23235 if (origin
&& origin
->die_parent
)
23236 add_child_die (origin
->die_parent
, die
);
23237 else if (is_cu_die (die
))
23239 else if (seen_error ())
23240 /* It's OK to be confused by errors in the input. */
23241 add_child_die (comp_unit_die (), die
);
23244 /* In certain situations, the lexical block containing a
23245 nested function can be optimized away, which results
23246 in the nested function die being orphaned. Likewise
23247 with the return type of that nested function. Force
23248 this to be a child of the containing function.
23250 It may happen that even the containing function got fully
23251 inlined and optimized out. In that case we are lost and
23252 assign the empty child. This should not be big issue as
23253 the function is likely unreachable too. */
23254 gcc_assert (node
->created_for
);
23256 if (DECL_P (node
->created_for
))
23257 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23258 else if (TYPE_P (node
->created_for
))
23259 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23261 origin
= comp_unit_die ();
23263 add_child_die (origin
, die
);
23268 limbo_die_list
= NULL
;
23270 #if ENABLE_ASSERT_CHECKING
23272 dw_die_ref die
= comp_unit_die (), c
;
23273 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23276 resolve_addr (comp_unit_die ());
23277 move_marked_base_types ();
23279 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23281 tree decl
= node
->created_for
;
23282 /* When generating LTO bytecode we can not generate new assembler
23283 names at this point and all important decls got theirs via
23285 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23286 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23288 add_linkage_attr (node
->die
, decl
);
23289 move_linkage_attr (node
->die
);
23293 deferred_asm_name
= NULL
;
23295 /* Walk through the list of incomplete types again, trying once more to
23296 emit full debugging info for them. */
23297 retry_incomplete_types ();
23299 if (flag_eliminate_unused_debug_types
)
23300 prune_unused_types ();
23302 /* Generate separate COMDAT sections for type DIEs. */
23303 if (use_debug_types
)
23305 break_out_comdat_types (comp_unit_die ());
23307 /* Each new type_unit DIE was added to the limbo die list when created.
23308 Since these have all been added to comdat_type_list, clear the
23310 limbo_die_list
= NULL
;
23312 /* For each new comdat type unit, copy declarations for incomplete
23313 types to make the new unit self-contained (i.e., no direct
23314 references to the main compile unit). */
23315 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23316 copy_decls_for_unworthy_types (ctnode
->root_die
);
23317 copy_decls_for_unworthy_types (comp_unit_die ());
23319 /* In the process of copying declarations from one unit to another,
23320 we may have left some declarations behind that are no longer
23321 referenced. Prune them. */
23322 prune_unused_types ();
23325 /* Generate separate CUs for each of the include files we've seen.
23326 They will go into limbo_die_list. */
23327 if (flag_eliminate_dwarf2_dups
)
23328 break_out_includes (comp_unit_die ());
23330 /* Traverse the DIE's and add add sibling attributes to those DIE's
23331 that have children. */
23332 add_sibling_attributes (comp_unit_die ());
23333 for (node
= limbo_die_list
; node
; node
= node
->next
)
23334 add_sibling_attributes (node
->die
);
23335 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23336 add_sibling_attributes (ctnode
->root_die
);
23338 /* When splitting DWARF info, we put some attributes in the
23339 skeleton compile_unit DIE that remains in the .o, while
23340 most attributes go in the DWO compile_unit_die. */
23341 if (dwarf_split_debug_info
)
23342 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23344 main_comp_unit_die
= comp_unit_die ();
23346 /* Output a terminator label for the .text section. */
23347 switch_to_section (text_section
);
23348 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23349 if (cold_text_section
)
23351 switch_to_section (cold_text_section
);
23352 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23355 /* We can only use the low/high_pc attributes if all of the code was
23357 if (!have_multiple_function_sections
23358 || (dwarf_version
< 3 && dwarf_strict
))
23360 /* Don't add if the CU has no associated code. */
23361 if (text_section_used
)
23362 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23363 text_end_label
, true);
23369 bool range_list_added
= false;
23371 if (text_section_used
)
23372 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23373 text_end_label
, &range_list_added
, true);
23374 if (cold_text_section_used
)
23375 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23376 cold_end_label
, &range_list_added
, true);
23378 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23380 if (DECL_IGNORED_P (fde
->decl
))
23382 if (!fde
->in_std_section
)
23383 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23384 fde
->dw_fde_end
, &range_list_added
,
23386 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23387 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23388 fde
->dw_fde_second_end
, &range_list_added
,
23392 if (range_list_added
)
23394 /* We need to give .debug_loc and .debug_ranges an appropriate
23395 "base address". Use zero so that these addresses become
23396 absolute. Historically, we've emitted the unexpected
23397 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23398 Emit both to give time for other tools to adapt. */
23399 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23400 if (! dwarf_strict
&& dwarf_version
< 4)
23401 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23407 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23408 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23409 debug_line_section_label
);
23412 add_AT_macptr (comp_unit_die (),
23413 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23414 macinfo_section_label
);
23416 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23418 /* optimize_location_lists calculates the size of the lists,
23419 so index them first, and assign indices to the entries.
23420 Although optimize_location_lists will remove entries from
23421 the table, it only does so for duplicates, and therefore
23422 only reduces ref_counts to 1. */
23423 unsigned int index
= 0;
23424 index_location_lists (comp_unit_die ());
23425 htab_traverse_noresize (addr_index_table
,
23426 index_addr_table_entry
, &index
);
23428 if (have_location_lists
)
23429 optimize_location_lists (comp_unit_die ());
23431 save_macinfo_strings ();
23432 if (dwarf_split_debug_info
)
23434 unsigned int index
= 0;
23435 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23438 /* Output all of the compilation units. We put the main one last so that
23439 the offsets are available to output_pubnames. */
23440 for (node
= limbo_die_list
; node
; node
= node
->next
)
23441 output_comp_unit (node
->die
, 0);
23443 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23444 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23446 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23448 /* Don't output duplicate types. */
23449 if (*slot
!= HTAB_EMPTY_ENTRY
)
23452 /* Add a pointer to the line table for the main compilation unit
23453 so that the debugger can make sense of DW_AT_decl_file
23455 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23456 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23457 (!dwarf_split_debug_info
23458 ? debug_line_section_label
23459 : debug_skeleton_line_section_label
));
23461 output_comdat_type_unit (ctnode
);
23464 htab_delete (comdat_type_table
);
23466 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23467 both the main_cu and all skeleton TUs. Making this call unconditional
23468 would end up either adding a second copy of the AT_pubnames attribute, or
23469 requiring a special case in add_top_level_skeleton_die_attrs. */
23470 if (!dwarf_split_debug_info
)
23471 add_AT_pubnames (comp_unit_die ());
23473 if (dwarf_split_debug_info
)
23476 unsigned char checksum
[16];
23477 struct md5_ctx ctx
;
23479 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23480 md5_init_ctx (&ctx
);
23482 die_checksum (comp_unit_die (), &ctx
, &mark
);
23483 unmark_all_dies (comp_unit_die ());
23484 md5_finish_ctx (&ctx
, checksum
);
23486 /* Use the first 8 bytes of the checksum as the dwo_id,
23487 and add it to both comp-unit DIEs. */
23488 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23489 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23491 /* Add the base offset of the ranges table to the skeleton
23493 if (ranges_table_in_use
)
23494 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23495 ranges_section_label
);
23497 switch_to_section (debug_addr_section
);
23498 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23499 output_addr_table ();
23502 /* Output the main compilation unit if non-empty or if .debug_macinfo
23503 or .debug_macro will be emitted. */
23504 output_comp_unit (comp_unit_die (), have_macinfo
);
23506 if (dwarf_split_debug_info
&& info_section_emitted
)
23507 output_skeleton_debug_sections (main_comp_unit_die
);
23509 /* Output the abbreviation table. */
23510 if (abbrev_die_table_in_use
!= 1)
23512 switch_to_section (debug_abbrev_section
);
23513 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23514 output_abbrev_section ();
23517 /* Output location list section if necessary. */
23518 if (have_location_lists
)
23520 /* Output the location lists info. */
23521 switch_to_section (debug_loc_section
);
23522 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23523 output_location_lists (comp_unit_die ());
23526 /* Output public names and types tables if necessary. */
23527 output_pubnames (pubname_table
);
23528 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23529 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23530 simply won't look for the section. */
23531 output_pubnames (pubtype_table
);
23533 /* Output the address range information if a CU (.debug_info section)
23534 was emitted. We output an empty table even if we had no functions
23535 to put in it. This because the consumer has no way to tell the
23536 difference between an empty table that we omitted and failure to
23537 generate a table that would have contained data. */
23538 if (info_section_emitted
)
23540 unsigned long aranges_length
= size_of_aranges ();
23542 switch_to_section (debug_aranges_section
);
23543 output_aranges (aranges_length
);
23546 /* Output ranges section if necessary. */
23547 if (ranges_table_in_use
)
23549 switch_to_section (debug_ranges_section
);
23550 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23554 /* Have to end the macro section. */
23557 switch_to_section (debug_macinfo_section
);
23558 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23560 dw2_asm_output_data (1, 0, "End compilation unit");
23563 /* Output the source line correspondence table. We must do this
23564 even if there is no line information. Otherwise, on an empty
23565 translation unit, we will generate a present, but empty,
23566 .debug_info section. IRIX 6.5 `nm' will then complain when
23567 examining the file. This is done late so that any filenames
23568 used by the debug_info section are marked as 'used'. */
23569 switch_to_section (debug_line_section
);
23570 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23571 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23572 output_line_info (false);
23574 if (dwarf_split_debug_info
&& info_section_emitted
)
23576 switch_to_section (debug_skeleton_line_section
);
23577 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
23578 output_line_info (true);
23581 /* If we emitted any indirect strings, output the string table too. */
23582 if (debug_str_hash
)
23583 output_indirect_strings ();
23586 #include "gt-dwarf2out.h"