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
);
10503 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10504 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10506 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10510 /* Return a location descriptor that designates a machine register for
10511 a given hard register number. */
10513 static dw_loc_descr_ref
10514 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10516 dw_loc_descr_ref reg_loc_descr
;
10520 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10522 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10524 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10525 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10527 return reg_loc_descr
;
10530 /* Given an RTL of a register, return a location descriptor that
10531 designates a value that spans more than one register. */
10533 static dw_loc_descr_ref
10534 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10535 enum var_init_status initialized
)
10537 int nregs
, size
, i
;
10539 dw_loc_descr_ref loc_result
= NULL
;
10542 #ifdef LEAF_REG_REMAP
10543 if (crtl
->uses_only_leaf_regs
)
10545 int leaf_reg
= LEAF_REG_REMAP (reg
);
10546 if (leaf_reg
!= -1)
10547 reg
= (unsigned) leaf_reg
;
10550 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10551 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10553 /* Simple, contiguous registers. */
10554 if (regs
== NULL_RTX
)
10556 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10561 dw_loc_descr_ref t
;
10563 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10564 VAR_INIT_STATUS_INITIALIZED
);
10565 add_loc_descr (&loc_result
, t
);
10566 add_loc_descr_op_piece (&loc_result
, size
);
10572 /* Now onto stupid register sets in non contiguous locations. */
10574 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10576 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10579 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10581 dw_loc_descr_ref t
;
10583 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10584 VAR_INIT_STATUS_INITIALIZED
);
10585 add_loc_descr (&loc_result
, t
);
10586 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10587 add_loc_descr_op_piece (&loc_result
, size
);
10590 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10591 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10595 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10597 /* Return a location descriptor that designates a constant i,
10598 as a compound operation from constant (i >> shift), constant shift
10601 static dw_loc_descr_ref
10602 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10604 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10605 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10606 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10610 /* Return a location descriptor that designates a constant. */
10612 static dw_loc_descr_ref
10613 int_loc_descriptor (HOST_WIDE_INT i
)
10615 enum dwarf_location_atom op
;
10617 /* Pick the smallest representation of a constant, rather than just
10618 defaulting to the LEB encoding. */
10621 int clz
= clz_hwi (i
);
10622 int ctz
= ctz_hwi (i
);
10624 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10625 else if (i
<= 0xff)
10626 op
= DW_OP_const1u
;
10627 else if (i
<= 0xffff)
10628 op
= DW_OP_const2u
;
10629 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10630 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10631 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10632 DW_OP_litX DW_OP_const1u Y 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
- 5);
10635 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10636 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10637 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10638 while DW_OP_const4u is 5 bytes. */
10639 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10640 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10641 op
= DW_OP_const4u
;
10642 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10643 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10644 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10645 while DW_OP_constu of constant >= 0x100000000 takes at least
10647 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10648 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10649 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10650 >= HOST_BITS_PER_WIDE_INT
)
10651 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10652 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10653 while DW_OP_constu takes in this case at least 6 bytes. */
10654 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10655 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10656 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10657 && size_of_uleb128 (i
) > 6)
10658 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10659 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10666 op
= DW_OP_const1s
;
10667 else if (i
>= -0x8000)
10668 op
= DW_OP_const2s
;
10669 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10671 if (size_of_int_loc_descriptor (i
) < 5)
10673 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10674 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10677 op
= DW_OP_const4s
;
10681 if (size_of_int_loc_descriptor (i
)
10682 < (unsigned long) 1 + size_of_sleb128 (i
))
10684 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10685 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10692 return new_loc_descr (op
, i
, 0);
10695 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10696 without actually allocating it. */
10698 static unsigned long
10699 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10701 return size_of_int_loc_descriptor (i
>> shift
)
10702 + size_of_int_loc_descriptor (shift
)
10706 /* Return size_of_locs (int_loc_descriptor (i)) without
10707 actually allocating it. */
10709 static unsigned long
10710 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10719 else if (i
<= 0xff)
10721 else if (i
<= 0xffff)
10725 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10726 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10727 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10729 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10730 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10731 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10733 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10735 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10736 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10737 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10738 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10740 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10741 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10742 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10744 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10745 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10747 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10756 else if (i
>= -0x8000)
10758 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10760 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10762 s
= size_of_int_loc_descriptor (-i
) + 1;
10770 unsigned long r
= 1 + size_of_sleb128 (i
);
10771 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10773 s
= size_of_int_loc_descriptor (-i
) + 1;
10782 /* Return loc description representing "address" of integer value.
10783 This can appear only as toplevel expression. */
10785 static dw_loc_descr_ref
10786 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10789 dw_loc_descr_ref loc_result
= NULL
;
10791 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10794 litsize
= size_of_int_loc_descriptor (i
);
10795 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10796 is more compact. For DW_OP_stack_value we need:
10797 litsize + 1 (DW_OP_stack_value)
10798 and for DW_OP_implicit_value:
10799 1 (DW_OP_implicit_value) + 1 (length) + size. */
10800 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10802 loc_result
= int_loc_descriptor (i
);
10803 add_loc_descr (&loc_result
,
10804 new_loc_descr (DW_OP_stack_value
, 0, 0));
10808 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10810 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10811 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10815 /* Return a location descriptor that designates a base+offset location. */
10817 static dw_loc_descr_ref
10818 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10819 enum var_init_status initialized
)
10821 unsigned int regno
;
10822 dw_loc_descr_ref result
;
10823 dw_fde_ref fde
= cfun
->fde
;
10825 /* We only use "frame base" when we're sure we're talking about the
10826 post-prologue local stack frame. We do this by *not* running
10827 register elimination until this point, and recognizing the special
10828 argument pointer and soft frame pointer rtx's. */
10829 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10831 rtx elim
= (ira_use_lra_p
10832 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10833 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10837 if (GET_CODE (elim
) == PLUS
)
10839 offset
+= INTVAL (XEXP (elim
, 1));
10840 elim
= XEXP (elim
, 0);
10842 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10843 && (elim
== hard_frame_pointer_rtx
10844 || elim
== stack_pointer_rtx
))
10845 || elim
== (frame_pointer_needed
10846 ? hard_frame_pointer_rtx
10847 : stack_pointer_rtx
));
10849 /* If drap register is used to align stack, use frame
10850 pointer + offset to access stack variables. If stack
10851 is aligned without drap, use stack pointer + offset to
10852 access stack variables. */
10853 if (crtl
->stack_realign_tried
10854 && reg
== frame_pointer_rtx
)
10857 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10858 ? HARD_FRAME_POINTER_REGNUM
10860 return new_reg_loc_descr (base_reg
, offset
);
10863 gcc_assert (frame_pointer_fb_offset_valid
);
10864 offset
+= frame_pointer_fb_offset
;
10865 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10869 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10871 if (!optimize
&& fde
10872 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10874 /* Use cfa+offset to represent the location of arguments passed
10875 on the stack when drap is used to align stack.
10876 Only do this when not optimizing, for optimized code var-tracking
10877 is supposed to track where the arguments live and the register
10878 used as vdrap or drap in some spot might be used for something
10879 else in other part of the routine. */
10880 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10884 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10887 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10889 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10890 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10895 /* Return true if this RTL expression describes a base+offset calculation. */
10898 is_based_loc (const_rtx rtl
)
10900 return (GET_CODE (rtl
) == PLUS
10901 && ((REG_P (XEXP (rtl
, 0))
10902 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10903 && CONST_INT_P (XEXP (rtl
, 1)))));
10906 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10909 static dw_loc_descr_ref
10910 tls_mem_loc_descriptor (rtx mem
)
10913 dw_loc_descr_ref loc_result
;
10915 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10918 base
= get_base_address (MEM_EXPR (mem
));
10920 || TREE_CODE (base
) != VAR_DECL
10921 || !DECL_THREAD_LOCAL_P (base
))
10924 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10925 if (loc_result
== NULL
)
10928 if (MEM_OFFSET (mem
))
10929 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10934 /* Output debug info about reason why we failed to expand expression as dwarf
10938 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10940 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10942 fprintf (dump_file
, "Failed to expand as dwarf: ");
10944 print_generic_expr (dump_file
, expr
, dump_flags
);
10947 fprintf (dump_file
, "\n");
10948 print_rtl (dump_file
, rtl
);
10950 fprintf (dump_file
, "\nReason: %s\n", reason
);
10954 /* Helper function for const_ok_for_output, called either directly
10955 or via for_each_rtx. */
10958 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10962 if (GET_CODE (rtl
) == UNSPEC
)
10964 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10965 we can't express it in the debug info. */
10966 #ifdef ENABLE_CHECKING
10967 /* Don't complain about TLS UNSPECs, those are just too hard to
10968 delegitimize. Note this could be a non-decl SYMBOL_REF such as
10969 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
10970 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
10971 if (XVECLEN (rtl
, 0) == 0
10972 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10973 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
10974 inform (current_function_decl
10975 ? DECL_SOURCE_LOCATION (current_function_decl
)
10976 : UNKNOWN_LOCATION
,
10977 #if NUM_UNSPEC_VALUES > 0
10978 "non-delegitimized UNSPEC %s (%d) found in variable location",
10979 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10980 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10983 "non-delegitimized UNSPEC %d found in variable location",
10987 expansion_failed (NULL_TREE
, rtl
,
10988 "UNSPEC hasn't been delegitimized.\n");
10992 if (targetm
.const_not_ok_for_debug_p (rtl
))
10994 expansion_failed (NULL_TREE
, rtl
,
10995 "Expression rejected for debug by the backend.\n");
10999 if (GET_CODE (rtl
) != SYMBOL_REF
)
11002 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11005 get_pool_constant_mark (rtl
, &marked
);
11006 /* If all references to this pool constant were optimized away,
11007 it was not output and thus we can't represent it. */
11010 expansion_failed (NULL_TREE
, rtl
,
11011 "Constant was removed from constant pool.\n");
11016 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11019 /* Avoid references to external symbols in debug info, on several targets
11020 the linker might even refuse to link when linking a shared library,
11021 and in many other cases the relocations for .debug_info/.debug_loc are
11022 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11023 to be defined within the same shared library or executable are fine. */
11024 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11026 tree decl
= SYMBOL_REF_DECL (rtl
);
11028 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11030 expansion_failed (NULL_TREE
, rtl
,
11031 "Symbol not defined in current TU.\n");
11039 /* Return true if constant RTL can be emitted in DW_OP_addr or
11040 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11041 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11044 const_ok_for_output (rtx rtl
)
11046 if (GET_CODE (rtl
) == SYMBOL_REF
)
11047 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11049 if (GET_CODE (rtl
) == CONST
)
11050 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11055 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11056 if possible, NULL otherwise. */
11059 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11061 dw_die_ref type_die
;
11062 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11066 switch (TREE_CODE (type
))
11074 type_die
= lookup_type_die (type
);
11076 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11077 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11082 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11083 type matching MODE, or, if MODE is narrower than or as wide as
11084 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11087 static dw_loc_descr_ref
11088 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11090 enum machine_mode outer_mode
= mode
;
11091 dw_die_ref type_die
;
11092 dw_loc_descr_ref cvt
;
11094 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11096 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11099 type_die
= base_type_for_mode (outer_mode
, 1);
11100 if (type_die
== NULL
)
11102 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11103 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11104 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11105 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11106 add_loc_descr (&op
, cvt
);
11110 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11112 static dw_loc_descr_ref
11113 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11114 dw_loc_descr_ref op1
)
11116 dw_loc_descr_ref ret
= op0
;
11117 add_loc_descr (&ret
, op1
);
11118 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11119 if (STORE_FLAG_VALUE
!= 1)
11121 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11122 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11127 /* Return location descriptor for signed comparison OP RTL. */
11129 static dw_loc_descr_ref
11130 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11131 enum machine_mode mem_mode
)
11133 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11134 dw_loc_descr_ref op0
, op1
;
11137 if (op_mode
== VOIDmode
)
11138 op_mode
= GET_MODE (XEXP (rtl
, 1));
11139 if (op_mode
== VOIDmode
)
11143 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11144 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11147 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11148 VAR_INIT_STATUS_INITIALIZED
);
11149 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11150 VAR_INIT_STATUS_INITIALIZED
);
11152 if (op0
== NULL
|| op1
== NULL
)
11155 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11156 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11157 return compare_loc_descriptor (op
, op0
, op1
);
11159 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11161 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11162 dw_loc_descr_ref cvt
;
11164 if (type_die
== NULL
)
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 (&op0
, cvt
);
11171 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11172 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11173 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11174 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11175 add_loc_descr (&op1
, cvt
);
11176 return compare_loc_descriptor (op
, op0
, op1
);
11179 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11180 /* For eq/ne, if the operands are known to be zero-extended,
11181 there is no need to do the fancy shifting up. */
11182 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11184 dw_loc_descr_ref last0
, last1
;
11185 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11187 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11189 /* deref_size zero extends, and for constants we can check
11190 whether they are zero extended or not. */
11191 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11192 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11193 || (CONST_INT_P (XEXP (rtl
, 0))
11194 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11195 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11196 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11197 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11198 || (CONST_INT_P (XEXP (rtl
, 1))
11199 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11200 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11201 return compare_loc_descriptor (op
, op0
, op1
);
11203 /* EQ/NE comparison against constant in narrower type than
11204 DWARF2_ADDR_SIZE can be performed either as
11205 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11208 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11209 DW_OP_{eq,ne}. Pick whatever is shorter. */
11210 if (CONST_INT_P (XEXP (rtl
, 1))
11211 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11212 && (size_of_int_loc_descriptor (shift
) + 1
11213 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11214 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11215 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11216 & GET_MODE_MASK (op_mode
))))
11218 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11219 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11220 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11221 & GET_MODE_MASK (op_mode
));
11222 return compare_loc_descriptor (op
, op0
, op1
);
11225 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11226 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11227 if (CONST_INT_P (XEXP (rtl
, 1)))
11228 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11231 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11232 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11234 return compare_loc_descriptor (op
, op0
, op1
);
11237 /* Return location descriptor for unsigned comparison OP RTL. */
11239 static dw_loc_descr_ref
11240 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11241 enum machine_mode mem_mode
)
11243 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11244 dw_loc_descr_ref op0
, op1
;
11246 if (op_mode
== VOIDmode
)
11247 op_mode
= GET_MODE (XEXP (rtl
, 1));
11248 if (op_mode
== VOIDmode
)
11250 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11253 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11256 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11257 VAR_INIT_STATUS_INITIALIZED
);
11258 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11259 VAR_INIT_STATUS_INITIALIZED
);
11261 if (op0
== NULL
|| op1
== NULL
)
11264 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11266 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11267 dw_loc_descr_ref last0
, last1
;
11268 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11270 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11272 if (CONST_INT_P (XEXP (rtl
, 0)))
11273 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11274 /* deref_size zero extends, so no need to mask it again. */
11275 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11276 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11278 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11279 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11281 if (CONST_INT_P (XEXP (rtl
, 1)))
11282 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11283 /* deref_size zero extends, so no need to mask it again. */
11284 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11285 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11287 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11288 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11291 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11293 HOST_WIDE_INT bias
= 1;
11294 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11295 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11296 if (CONST_INT_P (XEXP (rtl
, 1)))
11297 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11298 + INTVAL (XEXP (rtl
, 1)));
11300 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11303 return compare_loc_descriptor (op
, op0
, op1
);
11306 /* Return location descriptor for {U,S}{MIN,MAX}. */
11308 static dw_loc_descr_ref
11309 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11310 enum machine_mode mem_mode
)
11312 enum dwarf_location_atom op
;
11313 dw_loc_descr_ref op0
, op1
, ret
;
11314 dw_loc_descr_ref bra_node
, drop_node
;
11317 && (GET_MODE_CLASS (mode
) != MODE_INT
11318 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11321 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11322 VAR_INIT_STATUS_INITIALIZED
);
11323 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11324 VAR_INIT_STATUS_INITIALIZED
);
11326 if (op0
== NULL
|| op1
== NULL
)
11329 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11330 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11331 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11332 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11334 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11336 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11337 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11338 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11339 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11340 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11342 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11344 HOST_WIDE_INT bias
= 1;
11345 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11346 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11347 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11350 else if (GET_MODE_CLASS (mode
) == MODE_INT
11351 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11353 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11354 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11355 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11356 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11357 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11359 else if (GET_MODE_CLASS (mode
) == MODE_INT
11360 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11362 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11363 dw_loc_descr_ref cvt
;
11364 if (type_die
== NULL
)
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 (&op0
, cvt
);
11371 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11372 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11373 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11374 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11375 add_loc_descr (&op1
, cvt
);
11378 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11383 add_loc_descr (&ret
, op1
);
11384 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11385 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11386 add_loc_descr (&ret
, bra_node
);
11387 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11388 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11389 add_loc_descr (&ret
, drop_node
);
11390 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11391 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11392 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11393 && GET_MODE_CLASS (mode
) == MODE_INT
11394 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11395 ret
= convert_descriptor_to_mode (mode
, ret
);
11399 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11400 but after converting arguments to type_die, afterwards
11401 convert back to unsigned. */
11403 static dw_loc_descr_ref
11404 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11405 enum machine_mode mode
, enum machine_mode mem_mode
)
11407 dw_loc_descr_ref cvt
, op0
, op1
;
11409 if (type_die
== NULL
)
11411 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11412 VAR_INIT_STATUS_INITIALIZED
);
11413 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11414 VAR_INIT_STATUS_INITIALIZED
);
11415 if (op0
== NULL
|| op1
== NULL
)
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 (&op0
, cvt
);
11422 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11423 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11424 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11425 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11426 add_loc_descr (&op1
, cvt
);
11427 add_loc_descr (&op0
, op1
);
11428 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11429 return convert_descriptor_to_mode (mode
, op0
);
11432 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11433 const0 is DW_OP_lit0 or corresponding typed constant,
11434 const1 is DW_OP_lit1 or corresponding typed constant
11435 and constMSB is constant with just the MSB bit set
11437 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11438 L1: const0 DW_OP_swap
11439 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11440 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11445 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11446 L1: const0 DW_OP_swap
11447 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11448 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11453 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11454 L1: const1 DW_OP_swap
11455 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11456 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11460 static dw_loc_descr_ref
11461 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11462 enum machine_mode mem_mode
)
11464 dw_loc_descr_ref op0
, ret
, tmp
;
11465 HOST_WIDE_INT valv
;
11466 dw_loc_descr_ref l1jump
, l1label
;
11467 dw_loc_descr_ref l2jump
, l2label
;
11468 dw_loc_descr_ref l3jump
, l3label
;
11469 dw_loc_descr_ref l4jump
, l4label
;
11472 if (GET_MODE_CLASS (mode
) != MODE_INT
11473 || GET_MODE (XEXP (rtl
, 0)) != mode
11474 || (GET_CODE (rtl
) == CLZ
11475 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11478 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11479 VAR_INIT_STATUS_INITIALIZED
);
11483 if (GET_CODE (rtl
) == CLZ
)
11485 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11486 valv
= GET_MODE_BITSIZE (mode
);
11488 else if (GET_CODE (rtl
) == FFS
)
11490 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11491 valv
= GET_MODE_BITSIZE (mode
);
11492 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11493 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11494 add_loc_descr (&ret
, l1jump
);
11495 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11496 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11497 VAR_INIT_STATUS_INITIALIZED
);
11500 add_loc_descr (&ret
, tmp
);
11501 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11502 add_loc_descr (&ret
, l4jump
);
11503 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11504 ? const1_rtx
: const0_rtx
,
11506 VAR_INIT_STATUS_INITIALIZED
);
11507 if (l1label
== NULL
)
11509 add_loc_descr (&ret
, l1label
);
11510 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11511 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11512 add_loc_descr (&ret
, l2label
);
11513 if (GET_CODE (rtl
) != CLZ
)
11515 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11516 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11517 << (GET_MODE_BITSIZE (mode
) - 1));
11519 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11520 << (GET_MODE_BITSIZE (mode
)
11521 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11522 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11523 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11524 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11525 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11527 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11528 VAR_INIT_STATUS_INITIALIZED
);
11531 add_loc_descr (&ret
, tmp
);
11532 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11533 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11534 add_loc_descr (&ret
, l3jump
);
11535 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11536 VAR_INIT_STATUS_INITIALIZED
);
11539 add_loc_descr (&ret
, tmp
);
11540 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11541 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11542 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11543 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11544 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11545 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11546 add_loc_descr (&ret
, l2jump
);
11547 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11548 add_loc_descr (&ret
, l3label
);
11549 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11550 add_loc_descr (&ret
, l4label
);
11551 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11552 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11553 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11554 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11555 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11556 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11557 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11558 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11562 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11563 const1 is DW_OP_lit1 or corresponding typed constant):
11565 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11566 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11570 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11571 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11574 static dw_loc_descr_ref
11575 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11576 enum machine_mode mem_mode
)
11578 dw_loc_descr_ref op0
, ret
, tmp
;
11579 dw_loc_descr_ref l1jump
, l1label
;
11580 dw_loc_descr_ref l2jump
, l2label
;
11582 if (GET_MODE_CLASS (mode
) != MODE_INT
11583 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11586 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11587 VAR_INIT_STATUS_INITIALIZED
);
11591 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11592 VAR_INIT_STATUS_INITIALIZED
);
11595 add_loc_descr (&ret
, tmp
);
11596 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11597 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11598 add_loc_descr (&ret
, l1label
);
11599 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11600 add_loc_descr (&ret
, l2jump
);
11601 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11602 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11603 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11604 VAR_INIT_STATUS_INITIALIZED
);
11607 add_loc_descr (&ret
, tmp
);
11608 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11609 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11610 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11611 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11612 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11613 VAR_INIT_STATUS_INITIALIZED
);
11614 add_loc_descr (&ret
, tmp
);
11615 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11616 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11617 add_loc_descr (&ret
, l1jump
);
11618 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11619 add_loc_descr (&ret
, l2label
);
11620 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11621 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11622 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11623 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11627 /* BSWAP (constS is initial shift count, either 56 or 24):
11629 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11630 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11631 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11632 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11633 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11635 static dw_loc_descr_ref
11636 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11637 enum machine_mode mem_mode
)
11639 dw_loc_descr_ref op0
, ret
, tmp
;
11640 dw_loc_descr_ref l1jump
, l1label
;
11641 dw_loc_descr_ref l2jump
, l2label
;
11643 if (GET_MODE_CLASS (mode
) != MODE_INT
11644 || BITS_PER_UNIT
!= 8
11645 || (GET_MODE_BITSIZE (mode
) != 32
11646 && GET_MODE_BITSIZE (mode
) != 64))
11649 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11650 VAR_INIT_STATUS_INITIALIZED
);
11655 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11657 VAR_INIT_STATUS_INITIALIZED
);
11660 add_loc_descr (&ret
, tmp
);
11661 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11662 VAR_INIT_STATUS_INITIALIZED
);
11665 add_loc_descr (&ret
, tmp
);
11666 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11667 add_loc_descr (&ret
, l1label
);
11668 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11670 VAR_INIT_STATUS_INITIALIZED
);
11671 add_loc_descr (&ret
, tmp
);
11672 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11673 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11674 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11675 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11676 VAR_INIT_STATUS_INITIALIZED
);
11679 add_loc_descr (&ret
, tmp
);
11680 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11681 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11682 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11683 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11684 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11685 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11686 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11687 VAR_INIT_STATUS_INITIALIZED
);
11688 add_loc_descr (&ret
, tmp
);
11689 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11690 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11691 add_loc_descr (&ret
, l2jump
);
11692 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11693 VAR_INIT_STATUS_INITIALIZED
);
11694 add_loc_descr (&ret
, tmp
);
11695 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11696 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11697 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11698 add_loc_descr (&ret
, l1jump
);
11699 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11700 add_loc_descr (&ret
, l2label
);
11701 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11702 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11703 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11704 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11705 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11706 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11710 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11711 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11712 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11713 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11715 ROTATERT is similar:
11716 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11717 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11718 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11720 static dw_loc_descr_ref
11721 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11722 enum machine_mode mem_mode
)
11724 rtx rtlop1
= XEXP (rtl
, 1);
11725 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11728 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11731 if (GET_MODE (rtlop1
) != VOIDmode
11732 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11733 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11734 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11735 VAR_INIT_STATUS_INITIALIZED
);
11736 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11737 VAR_INIT_STATUS_INITIALIZED
);
11738 if (op0
== NULL
|| op1
== NULL
)
11740 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11741 for (i
= 0; i
< 2; i
++)
11743 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11744 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11746 VAR_INIT_STATUS_INITIALIZED
);
11747 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11748 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11750 : HOST_BITS_PER_WIDE_INT
== 64
11751 ? DW_OP_const8u
: DW_OP_constu
,
11752 GET_MODE_MASK (mode
), 0);
11755 if (mask
[i
] == NULL
)
11757 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11760 add_loc_descr (&ret
, op1
);
11761 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11762 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11763 if (GET_CODE (rtl
) == ROTATERT
)
11765 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11766 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11767 GET_MODE_BITSIZE (mode
), 0));
11769 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11770 if (mask
[0] != NULL
)
11771 add_loc_descr (&ret
, mask
[0]);
11772 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11773 if (mask
[1] != NULL
)
11775 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11776 add_loc_descr (&ret
, mask
[1]);
11777 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11779 if (GET_CODE (rtl
) == ROTATE
)
11781 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11782 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11783 GET_MODE_BITSIZE (mode
), 0));
11785 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11786 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11790 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11791 for DEBUG_PARAMETER_REF RTL. */
11793 static dw_loc_descr_ref
11794 parameter_ref_descriptor (rtx rtl
)
11796 dw_loc_descr_ref ret
;
11801 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11802 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11803 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11806 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11807 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11808 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11812 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11813 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11818 /* The following routine converts the RTL for a variable or parameter
11819 (resident in memory) into an equivalent Dwarf representation of a
11820 mechanism for getting the address of that same variable onto the top of a
11821 hypothetical "address evaluation" stack.
11823 When creating memory location descriptors, we are effectively transforming
11824 the RTL for a memory-resident object into its Dwarf postfix expression
11825 equivalent. This routine recursively descends an RTL tree, turning
11826 it into Dwarf postfix code as it goes.
11828 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11830 MEM_MODE is the mode of the memory reference, needed to handle some
11831 autoincrement addressing modes.
11833 Return 0 if we can't represent the location. */
11836 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11837 enum machine_mode mem_mode
,
11838 enum var_init_status initialized
)
11840 dw_loc_descr_ref mem_loc_result
= NULL
;
11841 enum dwarf_location_atom op
;
11842 dw_loc_descr_ref op0
, op1
;
11844 if (mode
== VOIDmode
)
11845 mode
= GET_MODE (rtl
);
11847 /* Note that for a dynamically sized array, the location we will generate a
11848 description of here will be the lowest numbered location which is
11849 actually within the array. That's *not* necessarily the same as the
11850 zeroth element of the array. */
11852 rtl
= targetm
.delegitimize_address (rtl
);
11854 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11857 switch (GET_CODE (rtl
))
11862 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11865 /* The case of a subreg may arise when we have a local (register)
11866 variable or a formal (register) parameter which doesn't quite fill
11867 up an entire register. For now, just assume that it is
11868 legitimate to make the Dwarf info refer to the whole register which
11869 contains the given subreg. */
11870 if (!subreg_lowpart_p (rtl
))
11872 if (GET_MODE_CLASS (mode
) == MODE_INT
11873 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) == MODE_INT
11874 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11875 #ifdef POINTERS_EXTEND_UNSIGNED
11876 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11879 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))) <= DWARF2_ADDR_SIZE
)
11881 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11882 GET_MODE (SUBREG_REG (rtl
)),
11883 mem_mode
, initialized
);
11888 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11890 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
)))
11891 && (GET_MODE_CLASS (mode
) != MODE_INT
11892 || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl
))) != MODE_INT
))
11896 dw_die_ref type_die
;
11897 dw_loc_descr_ref cvt
;
11899 mem_loc_result
= mem_loc_descriptor (SUBREG_REG (rtl
),
11900 GET_MODE (SUBREG_REG (rtl
)),
11901 mem_mode
, initialized
);
11902 if (mem_loc_result
== NULL
)
11904 type_die
= base_type_for_mode (mode
,
11905 GET_MODE_CLASS (mode
) == MODE_INT
);
11906 if (type_die
== NULL
)
11908 mem_loc_result
= NULL
;
11911 if (GET_MODE_SIZE (mode
)
11912 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl
))))
11913 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11915 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11916 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11917 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11918 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11919 add_loc_descr (&mem_loc_result
, cvt
);
11924 if (GET_MODE_CLASS (mode
) != MODE_INT
11925 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11926 && rtl
!= arg_pointer_rtx
11927 && rtl
!= frame_pointer_rtx
11928 #ifdef POINTERS_EXTEND_UNSIGNED
11929 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11933 dw_die_ref type_die
;
11934 unsigned int dbx_regnum
;
11938 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11940 type_die
= base_type_for_mode (mode
,
11941 GET_MODE_CLASS (mode
) == MODE_INT
);
11942 if (type_die
== NULL
)
11945 dbx_regnum
= dbx_reg_number (rtl
);
11946 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11948 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11950 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11951 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11952 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11955 /* Whenever a register number forms a part of the description of the
11956 method for calculating the (dynamic) address of a memory resident
11957 object, DWARF rules require the register number be referred to as
11958 a "base register". This distinction is not based in any way upon
11959 what category of register the hardware believes the given register
11960 belongs to. This is strictly DWARF terminology we're dealing with
11961 here. Note that in cases where the location of a memory-resident
11962 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11963 OP_CONST (0)) the actual DWARF location descriptor that we generate
11964 may just be OP_BASEREG (basereg). This may look deceptively like
11965 the object in question was allocated to a register (rather than in
11966 memory) so DWARF consumers need to be aware of the subtle
11967 distinction between OP_REG and OP_BASEREG. */
11968 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11969 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11970 else if (stack_realign_drap
11972 && crtl
->args
.internal_arg_pointer
== rtl
11973 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11975 /* If RTL is internal_arg_pointer, which has been optimized
11976 out, use DRAP instead. */
11977 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11978 VAR_INIT_STATUS_INITIALIZED
);
11984 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11986 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
11987 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
11990 else if (GET_CODE (rtl
) == ZERO_EXTEND
11991 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11992 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
11993 < HOST_BITS_PER_WIDE_INT
11994 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
11995 to expand zero extend as two shifts instead of
11997 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
11999 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12000 mem_loc_result
= op0
;
12001 add_loc_descr (&mem_loc_result
,
12002 int_loc_descriptor (GET_MODE_MASK (imode
)));
12003 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12005 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12007 int shift
= DWARF2_ADDR_SIZE
12008 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12009 shift
*= BITS_PER_UNIT
;
12010 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12014 mem_loc_result
= op0
;
12015 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12016 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12017 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12018 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12020 else if (!dwarf_strict
)
12022 dw_die_ref type_die1
, type_die2
;
12023 dw_loc_descr_ref cvt
;
12025 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12026 GET_CODE (rtl
) == ZERO_EXTEND
);
12027 if (type_die1
== NULL
)
12029 type_die2
= base_type_for_mode (mode
, 1);
12030 if (type_die2
== NULL
)
12032 mem_loc_result
= op0
;
12033 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12034 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12035 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12036 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12037 add_loc_descr (&mem_loc_result
, cvt
);
12038 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12039 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12040 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12041 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12042 add_loc_descr (&mem_loc_result
, cvt
);
12048 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12049 if (new_rtl
!= rtl
)
12051 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12053 if (mem_loc_result
!= NULL
)
12054 return mem_loc_result
;
12057 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12058 get_address_mode (rtl
), mode
,
12059 VAR_INIT_STATUS_INITIALIZED
);
12060 if (mem_loc_result
== NULL
)
12061 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12062 if (mem_loc_result
!= NULL
)
12064 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12065 || GET_MODE_CLASS (mode
) != MODE_INT
)
12067 dw_die_ref type_die
;
12068 dw_loc_descr_ref deref
;
12073 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12074 if (type_die
== NULL
)
12076 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12077 GET_MODE_SIZE (mode
), 0);
12078 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12079 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12080 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12081 add_loc_descr (&mem_loc_result
, deref
);
12083 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12084 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12086 add_loc_descr (&mem_loc_result
,
12087 new_loc_descr (DW_OP_deref_size
,
12088 GET_MODE_SIZE (mode
), 0));
12093 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12096 /* Some ports can transform a symbol ref into a label ref, because
12097 the symbol ref is too far away and has to be dumped into a constant
12101 if (GET_MODE_CLASS (mode
) != MODE_INT
12102 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12103 #ifdef POINTERS_EXTEND_UNSIGNED
12104 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12108 if (GET_CODE (rtl
) == SYMBOL_REF
12109 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12111 dw_loc_descr_ref temp
;
12113 /* If this is not defined, we have no way to emit the data. */
12114 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12117 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12119 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12120 add_loc_descr (&mem_loc_result
, temp
);
12125 if (!const_ok_for_output (rtl
))
12129 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12130 vec_safe_push (used_rtx_array
, rtl
);
12136 case DEBUG_IMPLICIT_PTR
:
12137 expansion_failed (NULL_TREE
, rtl
,
12138 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12144 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12146 if (GET_MODE_CLASS (mode
) != MODE_INT
12147 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12148 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12149 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12152 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12153 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12155 op0
= one_reg_loc_descriptor (dbx_regnum
,
12156 VAR_INIT_STATUS_INITIALIZED
);
12159 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12160 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12162 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12163 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12164 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12168 gcc_unreachable ();
12171 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12172 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12173 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12176 case DEBUG_PARAMETER_REF
:
12177 mem_loc_result
= parameter_ref_descriptor (rtl
);
12181 /* Extract the PLUS expression nested inside and fall into
12182 PLUS code below. */
12183 rtl
= XEXP (rtl
, 1);
12188 /* Turn these into a PLUS expression and fall into the PLUS code
12190 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12191 GEN_INT (GET_CODE (rtl
) == PRE_INC
12192 ? GET_MODE_UNIT_SIZE (mem_mode
)
12193 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12195 /* ... fall through ... */
12199 if (is_based_loc (rtl
)
12200 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12201 || XEXP (rtl
, 0) == arg_pointer_rtx
12202 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12203 && GET_MODE_CLASS (mode
) == MODE_INT
)
12204 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12205 INTVAL (XEXP (rtl
, 1)),
12206 VAR_INIT_STATUS_INITIALIZED
);
12209 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12210 VAR_INIT_STATUS_INITIALIZED
);
12211 if (mem_loc_result
== 0)
12214 if (CONST_INT_P (XEXP (rtl
, 1))
12215 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12216 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12219 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12220 VAR_INIT_STATUS_INITIALIZED
);
12223 add_loc_descr (&mem_loc_result
, op1
);
12224 add_loc_descr (&mem_loc_result
,
12225 new_loc_descr (DW_OP_plus
, 0, 0));
12230 /* If a pseudo-reg is optimized away, it is possible for it to
12231 be replaced with a MEM containing a multiply or shift. */
12242 && GET_MODE_CLASS (mode
) == MODE_INT
12243 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12245 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12246 base_type_for_mode (mode
, 0),
12270 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12272 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12273 VAR_INIT_STATUS_INITIALIZED
);
12275 rtx rtlop1
= XEXP (rtl
, 1);
12276 if (GET_MODE (rtlop1
) != VOIDmode
12277 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12278 < GET_MODE_BITSIZE (mode
))
12279 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12280 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12281 VAR_INIT_STATUS_INITIALIZED
);
12284 if (op0
== 0 || op1
== 0)
12287 mem_loc_result
= op0
;
12288 add_loc_descr (&mem_loc_result
, op1
);
12289 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12305 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12306 VAR_INIT_STATUS_INITIALIZED
);
12307 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12308 VAR_INIT_STATUS_INITIALIZED
);
12310 if (op0
== 0 || op1
== 0)
12313 mem_loc_result
= op0
;
12314 add_loc_descr (&mem_loc_result
, op1
);
12315 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12319 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12321 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12322 base_type_for_mode (mode
, 0),
12327 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12328 VAR_INIT_STATUS_INITIALIZED
);
12329 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12330 VAR_INIT_STATUS_INITIALIZED
);
12332 if (op0
== 0 || op1
== 0)
12335 mem_loc_result
= op0
;
12336 add_loc_descr (&mem_loc_result
, op1
);
12337 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12338 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12339 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12340 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12341 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12345 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12347 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12352 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12353 base_type_for_mode (mode
, 1),
12371 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12372 VAR_INIT_STATUS_INITIALIZED
);
12377 mem_loc_result
= op0
;
12378 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12382 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12383 #ifdef POINTERS_EXTEND_UNSIGNED
12385 && mem_mode
!= VOIDmode
12386 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12390 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12394 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12395 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12397 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12398 enum machine_mode amode
;
12399 if (type_die
== NULL
)
12401 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12403 if (INTVAL (rtl
) >= 0
12404 && amode
!= BLKmode
12405 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12406 /* const DW_OP_GNU_convert <XXX> vs.
12407 DW_OP_GNU_const_type <XXX, 1, const>. */
12408 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12409 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12411 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12412 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12413 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12414 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12415 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12416 add_loc_descr (&mem_loc_result
, op0
);
12417 return mem_loc_result
;
12419 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12421 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12422 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12423 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12424 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12425 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12428 mem_loc_result
->dw_loc_oprnd2
.val_class
12429 = dw_val_class_const_double
;
12430 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12431 = double_int::from_shwi (INTVAL (rtl
));
12439 dw_die_ref type_die
;
12441 /* Note that a CONST_DOUBLE rtx could represent either an integer
12442 or a floating-point constant. A CONST_DOUBLE is used whenever
12443 the constant requires more than one word in order to be
12444 adequately represented. We output CONST_DOUBLEs as blocks. */
12445 if (mode
== VOIDmode
12446 || (GET_MODE (rtl
) == VOIDmode
12447 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12449 type_die
= base_type_for_mode (mode
,
12450 GET_MODE_CLASS (mode
) == MODE_INT
);
12451 if (type_die
== NULL
)
12453 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12454 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12455 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12456 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12457 if (SCALAR_FLOAT_MODE_P (mode
))
12459 unsigned int length
= GET_MODE_SIZE (mode
);
12460 unsigned char *array
12461 = (unsigned char*) ggc_alloc_atomic (length
);
12463 insert_float (rtl
, array
);
12464 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12465 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12466 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12467 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12471 mem_loc_result
->dw_loc_oprnd2
.val_class
12472 = dw_val_class_const_double
;
12473 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12474 = rtx_to_double_int (rtl
);
12480 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12484 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12488 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12492 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12496 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12500 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12504 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12508 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12512 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12516 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12521 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12526 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12531 if (CONST_INT_P (XEXP (rtl
, 1))
12532 && CONST_INT_P (XEXP (rtl
, 2))
12533 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12534 + (unsigned) INTVAL (XEXP (rtl
, 2))
12535 <= GET_MODE_BITSIZE (mode
))
12536 && GET_MODE_CLASS (mode
) == MODE_INT
12537 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12538 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12541 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12542 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12545 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12549 mem_loc_result
= op0
;
12550 size
= INTVAL (XEXP (rtl
, 1));
12551 shift
= INTVAL (XEXP (rtl
, 2));
12552 if (BITS_BIG_ENDIAN
)
12553 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12555 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12557 add_loc_descr (&mem_loc_result
,
12558 int_loc_descriptor (DWARF2_ADDR_SIZE
12560 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12562 if (size
!= (int) DWARF2_ADDR_SIZE
)
12564 add_loc_descr (&mem_loc_result
,
12565 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12566 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12573 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12574 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12575 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12576 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12577 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12578 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12579 VAR_INIT_STATUS_INITIALIZED
);
12580 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12581 VAR_INIT_STATUS_INITIALIZED
);
12582 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12585 mem_loc_result
= op1
;
12586 add_loc_descr (&mem_loc_result
, op2
);
12587 add_loc_descr (&mem_loc_result
, op0
);
12588 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12589 add_loc_descr (&mem_loc_result
, bra_node
);
12590 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12591 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12592 add_loc_descr (&mem_loc_result
, drop_node
);
12593 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12594 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12599 case FLOAT_TRUNCATE
:
12601 case UNSIGNED_FLOAT
:
12606 dw_die_ref type_die
;
12607 dw_loc_descr_ref cvt
;
12609 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12610 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12613 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12614 && (GET_CODE (rtl
) == FLOAT
12615 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12616 <= DWARF2_ADDR_SIZE
))
12618 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12619 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12620 if (type_die
== NULL
)
12622 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12623 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12624 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12625 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12626 add_loc_descr (&op0
, cvt
);
12628 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12629 if (type_die
== NULL
)
12631 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12632 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12633 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12634 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12635 add_loc_descr (&op0
, cvt
);
12636 if (GET_MODE_CLASS (mode
) == MODE_INT
12637 && (GET_CODE (rtl
) == FIX
12638 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12640 op0
= convert_descriptor_to_mode (mode
, op0
);
12644 mem_loc_result
= op0
;
12651 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12656 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12660 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12665 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12670 /* In theory, we could implement the above. */
12671 /* DWARF cannot represent the unsigned compare operations
12696 case FRACT_CONVERT
:
12697 case UNSIGNED_FRACT_CONVERT
:
12699 case UNSIGNED_SAT_FRACT
:
12705 case VEC_DUPLICATE
:
12709 case STRICT_LOW_PART
:
12713 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12714 can't express it in the debug info. This can happen e.g. with some
12719 resolve_one_addr (&rtl
, NULL
);
12723 #ifdef ENABLE_CHECKING
12724 print_rtl (stderr
, rtl
);
12725 gcc_unreachable ();
12731 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12732 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12734 return mem_loc_result
;
12737 /* Return a descriptor that describes the concatenation of two locations.
12738 This is typically a complex variable. */
12740 static dw_loc_descr_ref
12741 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12743 dw_loc_descr_ref cc_loc_result
= NULL
;
12744 dw_loc_descr_ref x0_ref
12745 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12746 dw_loc_descr_ref x1_ref
12747 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12749 if (x0_ref
== 0 || x1_ref
== 0)
12752 cc_loc_result
= x0_ref
;
12753 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12755 add_loc_descr (&cc_loc_result
, x1_ref
);
12756 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12758 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12759 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12761 return cc_loc_result
;
12764 /* Return a descriptor that describes the concatenation of N
12767 static dw_loc_descr_ref
12768 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12771 dw_loc_descr_ref cc_loc_result
= NULL
;
12772 unsigned int n
= XVECLEN (concatn
, 0);
12774 for (i
= 0; i
< n
; ++i
)
12776 dw_loc_descr_ref ref
;
12777 rtx x
= XVECEXP (concatn
, 0, i
);
12779 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12783 add_loc_descr (&cc_loc_result
, ref
);
12784 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12787 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12788 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12790 return cc_loc_result
;
12793 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12794 for DEBUG_IMPLICIT_PTR RTL. */
12796 static dw_loc_descr_ref
12797 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12799 dw_loc_descr_ref ret
;
12804 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12805 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12806 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12807 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12808 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12809 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12812 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12813 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12814 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12818 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12819 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12824 /* Output a proper Dwarf location descriptor for a variable or parameter
12825 which is either allocated in a register or in a memory location. For a
12826 register, we just generate an OP_REG and the register number. For a
12827 memory location we provide a Dwarf postfix expression describing how to
12828 generate the (dynamic) address of the object onto the address stack.
12830 MODE is mode of the decl if this loc_descriptor is going to be used in
12831 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12832 allowed, VOIDmode otherwise.
12834 If we don't know how to describe it, return 0. */
12836 static dw_loc_descr_ref
12837 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12838 enum var_init_status initialized
)
12840 dw_loc_descr_ref loc_result
= NULL
;
12842 switch (GET_CODE (rtl
))
12845 /* The case of a subreg may arise when we have a local (register)
12846 variable or a formal (register) parameter which doesn't quite fill
12847 up an entire register. For now, just assume that it is
12848 legitimate to make the Dwarf info refer to the whole register which
12849 contains the given subreg. */
12850 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12851 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12852 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12858 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12862 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12863 GET_MODE (rtl
), initialized
);
12864 if (loc_result
== NULL
)
12865 loc_result
= tls_mem_loc_descriptor (rtl
);
12866 if (loc_result
== NULL
)
12868 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12869 if (new_rtl
!= rtl
)
12870 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12875 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12880 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12885 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12887 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12888 if (GET_CODE (loc
) == EXPR_LIST
)
12889 loc
= XEXP (loc
, 0);
12890 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12894 rtl
= XEXP (rtl
, 1);
12899 rtvec par_elems
= XVEC (rtl
, 0);
12900 int num_elem
= GET_NUM_ELEM (par_elems
);
12901 enum machine_mode mode
;
12904 /* Create the first one, so we have something to add to. */
12905 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12906 VOIDmode
, initialized
);
12907 if (loc_result
== NULL
)
12909 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12910 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12911 for (i
= 1; i
< num_elem
; i
++)
12913 dw_loc_descr_ref temp
;
12915 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12916 VOIDmode
, initialized
);
12919 add_loc_descr (&loc_result
, temp
);
12920 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12921 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12927 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12928 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12933 if (mode
== VOIDmode
)
12934 mode
= GET_MODE (rtl
);
12936 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12938 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12940 /* Note that a CONST_DOUBLE rtx could represent either an integer
12941 or a floating-point constant. A CONST_DOUBLE is used whenever
12942 the constant requires more than one word in order to be
12943 adequately represented. We output CONST_DOUBLEs as blocks. */
12944 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12945 GET_MODE_SIZE (mode
), 0);
12946 if (SCALAR_FLOAT_MODE_P (mode
))
12948 unsigned int length
= GET_MODE_SIZE (mode
);
12949 unsigned char *array
12950 = (unsigned char*) ggc_alloc_atomic (length
);
12952 insert_float (rtl
, array
);
12953 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12954 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12955 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12956 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12960 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12961 loc_result
->dw_loc_oprnd2
.v
.val_double
12962 = rtx_to_double_int (rtl
);
12968 if (mode
== VOIDmode
)
12969 mode
= GET_MODE (rtl
);
12971 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12973 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12974 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12975 unsigned char *array
= (unsigned char *)
12976 ggc_alloc_atomic (length
* elt_size
);
12980 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12981 switch (GET_MODE_CLASS (mode
))
12983 case MODE_VECTOR_INT
:
12984 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12986 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
12987 double_int val
= rtx_to_double_int (elt
);
12989 if (elt_size
<= sizeof (HOST_WIDE_INT
))
12990 insert_int (val
.to_shwi (), elt_size
, p
);
12993 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
12994 insert_double (val
, p
);
12999 case MODE_VECTOR_FLOAT
:
13000 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13002 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13003 insert_float (elt
, p
);
13008 gcc_unreachable ();
13011 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13012 length
* elt_size
, 0);
13013 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13014 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13015 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13016 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13021 if (mode
== VOIDmode
13022 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13023 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13024 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13026 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13031 if (!const_ok_for_output (rtl
))
13034 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13035 && (dwarf_version
>= 4 || !dwarf_strict
))
13037 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13038 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13039 vec_safe_push (used_rtx_array
, rtl
);
13043 case DEBUG_IMPLICIT_PTR
:
13044 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13048 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13049 && CONST_INT_P (XEXP (rtl
, 1)))
13052 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13058 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13059 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13060 && dwarf_version
>= 4)
13061 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13063 /* Value expression. */
13064 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13066 add_loc_descr (&loc_result
,
13067 new_loc_descr (DW_OP_stack_value
, 0, 0));
13075 /* We need to figure out what section we should use as the base for the
13076 address ranges where a given location is valid.
13077 1. If this particular DECL has a section associated with it, use that.
13078 2. If this function has a section associated with it, use that.
13079 3. Otherwise, use the text section.
13080 XXX: If you split a variable across multiple sections, we won't notice. */
13082 static const char *
13083 secname_for_decl (const_tree decl
)
13085 const char *secname
;
13087 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13089 tree sectree
= DECL_SECTION_NAME (decl
);
13090 secname
= TREE_STRING_POINTER (sectree
);
13092 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13094 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13095 secname
= TREE_STRING_POINTER (sectree
);
13097 else if (cfun
&& in_cold_section_p
)
13098 secname
= crtl
->subsections
.cold_section_label
;
13100 secname
= text_section_label
;
13105 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13108 decl_by_reference_p (tree decl
)
13110 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13111 || TREE_CODE (decl
) == VAR_DECL
)
13112 && DECL_BY_REFERENCE (decl
));
13115 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13118 static dw_loc_descr_ref
13119 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13120 enum var_init_status initialized
)
13122 int have_address
= 0;
13123 dw_loc_descr_ref descr
;
13124 enum machine_mode mode
;
13126 if (want_address
!= 2)
13128 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13130 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13132 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13133 if (GET_CODE (varloc
) == EXPR_LIST
)
13134 varloc
= XEXP (varloc
, 0);
13135 mode
= GET_MODE (varloc
);
13136 if (MEM_P (varloc
))
13138 rtx addr
= XEXP (varloc
, 0);
13139 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13140 mode
, initialized
);
13145 rtx x
= avoid_constant_pool_reference (varloc
);
13147 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13152 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13159 if (GET_CODE (varloc
) == VAR_LOCATION
)
13160 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13162 mode
= DECL_MODE (loc
);
13163 descr
= loc_descriptor (varloc
, mode
, initialized
);
13170 if (want_address
== 2 && !have_address
13171 && (dwarf_version
>= 4 || !dwarf_strict
))
13173 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13175 expansion_failed (loc
, NULL_RTX
,
13176 "DWARF address size mismatch");
13179 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13182 /* Show if we can't fill the request for an address. */
13183 if (want_address
&& !have_address
)
13185 expansion_failed (loc
, NULL_RTX
,
13186 "Want address and only have value");
13190 /* If we've got an address and don't want one, dereference. */
13191 if (!want_address
&& have_address
)
13193 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13194 enum dwarf_location_atom op
;
13196 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13198 expansion_failed (loc
, NULL_RTX
,
13199 "DWARF address size mismatch");
13202 else if (size
== DWARF2_ADDR_SIZE
)
13205 op
= DW_OP_deref_size
;
13207 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13213 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13214 if it is not possible. */
13216 static dw_loc_descr_ref
13217 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13219 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13220 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13221 else if (dwarf_version
>= 3 || !dwarf_strict
)
13222 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13227 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13228 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13230 static dw_loc_descr_ref
13231 dw_sra_loc_expr (tree decl
, rtx loc
)
13234 unsigned int padsize
= 0;
13235 dw_loc_descr_ref descr
, *descr_tail
;
13236 unsigned HOST_WIDE_INT decl_size
;
13238 enum var_init_status initialized
;
13240 if (DECL_SIZE (decl
) == NULL
13241 || !host_integerp (DECL_SIZE (decl
), 1))
13244 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13246 descr_tail
= &descr
;
13248 for (p
= loc
; p
; p
= XEXP (p
, 1))
13250 unsigned int bitsize
= decl_piece_bitsize (p
);
13251 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13252 dw_loc_descr_ref cur_descr
;
13253 dw_loc_descr_ref
*tail
, last
= NULL
;
13254 unsigned int opsize
= 0;
13256 if (loc_note
== NULL_RTX
13257 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13259 padsize
+= bitsize
;
13262 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13263 varloc
= NOTE_VAR_LOCATION (loc_note
);
13264 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13265 if (cur_descr
== NULL
)
13267 padsize
+= bitsize
;
13271 /* Check that cur_descr either doesn't use
13272 DW_OP_*piece operations, or their sum is equal
13273 to bitsize. Otherwise we can't embed it. */
13274 for (tail
= &cur_descr
; *tail
!= NULL
;
13275 tail
= &(*tail
)->dw_loc_next
)
13276 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13278 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13282 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13284 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13288 if (last
!= NULL
&& opsize
!= bitsize
)
13290 padsize
+= bitsize
;
13294 /* If there is a hole, add DW_OP_*piece after empty DWARF
13295 expression, which means that those bits are optimized out. */
13298 if (padsize
> decl_size
)
13300 decl_size
-= padsize
;
13301 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13302 if (*descr_tail
== NULL
)
13304 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13307 *descr_tail
= cur_descr
;
13309 if (bitsize
> decl_size
)
13311 decl_size
-= bitsize
;
13314 HOST_WIDE_INT offset
= 0;
13315 if (GET_CODE (varloc
) == VAR_LOCATION
13316 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13318 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13319 if (GET_CODE (varloc
) == EXPR_LIST
)
13320 varloc
= XEXP (varloc
, 0);
13324 if (GET_CODE (varloc
) == CONST
13325 || GET_CODE (varloc
) == SIGN_EXTEND
13326 || GET_CODE (varloc
) == ZERO_EXTEND
)
13327 varloc
= XEXP (varloc
, 0);
13328 else if (GET_CODE (varloc
) == SUBREG
)
13329 varloc
= SUBREG_REG (varloc
);
13334 /* DW_OP_bit_size offset should be zero for register
13335 or implicit location descriptions and empty location
13336 descriptions, but for memory addresses needs big endian
13338 if (MEM_P (varloc
))
13340 unsigned HOST_WIDE_INT memsize
13341 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13342 if (memsize
!= bitsize
)
13344 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13345 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13347 if (memsize
< bitsize
)
13349 if (BITS_BIG_ENDIAN
)
13350 offset
= memsize
- bitsize
;
13354 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13355 if (*descr_tail
== NULL
)
13357 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13361 /* If there were any non-empty expressions, add padding till the end of
13363 if (descr
!= NULL
&& decl_size
!= 0)
13365 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13366 if (*descr_tail
== NULL
)
13372 /* Return the dwarf representation of the location list LOC_LIST of
13373 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13376 static dw_loc_list_ref
13377 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13379 const char *endname
, *secname
;
13381 enum var_init_status initialized
;
13382 struct var_loc_node
*node
;
13383 dw_loc_descr_ref descr
;
13384 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13385 dw_loc_list_ref list
= NULL
;
13386 dw_loc_list_ref
*listp
= &list
;
13388 /* Now that we know what section we are using for a base,
13389 actually construct the list of locations.
13390 The first location information is what is passed to the
13391 function that creates the location list, and the remaining
13392 locations just get added on to that list.
13393 Note that we only know the start address for a location
13394 (IE location changes), so to build the range, we use
13395 the range [current location start, next location start].
13396 This means we have to special case the last node, and generate
13397 a range of [last location start, end of function label]. */
13399 secname
= secname_for_decl (decl
);
13401 for (node
= loc_list
->first
; node
; node
= node
->next
)
13402 if (GET_CODE (node
->loc
) == EXPR_LIST
13403 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13405 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13407 /* This requires DW_OP_{,bit_}piece, which is not usable
13408 inside DWARF expressions. */
13409 if (want_address
!= 2)
13411 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13417 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13418 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13419 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13423 bool range_across_switch
= false;
13424 /* If section switch happens in between node->label
13425 and node->next->label (or end of function) and
13426 we can't emit it as a single entry list,
13427 emit two ranges, first one ending at the end
13428 of first partition and second one starting at the
13429 beginning of second partition. */
13430 if (node
== loc_list
->last_before_switch
13431 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13432 && current_function_decl
)
13434 endname
= cfun
->fde
->dw_fde_end
;
13435 range_across_switch
= true;
13437 /* The variable has a location between NODE->LABEL and
13438 NODE->NEXT->LABEL. */
13439 else if (node
->next
)
13440 endname
= node
->next
->label
;
13441 /* If the variable has a location at the last label
13442 it keeps its location until the end of function. */
13443 else if (!current_function_decl
)
13444 endname
= text_end_label
;
13447 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13448 current_function_funcdef_no
);
13449 endname
= ggc_strdup (label_id
);
13452 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13453 if (TREE_CODE (decl
) == PARM_DECL
13454 && node
== loc_list
->first
13455 && GET_CODE (node
->loc
) == NOTE
13456 && strcmp (node
->label
, endname
) == 0)
13457 (*listp
)->force
= true;
13458 listp
= &(*listp
)->dw_loc_next
;
13460 if (range_across_switch
)
13462 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13463 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13466 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13467 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13468 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13471 gcc_assert (descr
);
13472 /* The variable has a location between NODE->LABEL and
13473 NODE->NEXT->LABEL. */
13475 endname
= node
->next
->label
;
13477 endname
= cfun
->fde
->dw_fde_second_end
;
13478 *listp
= new_loc_list (descr
,
13479 cfun
->fde
->dw_fde_second_begin
,
13481 listp
= &(*listp
)->dw_loc_next
;
13486 /* Try to avoid the overhead of a location list emitting a location
13487 expression instead, but only if we didn't have more than one
13488 location entry in the first place. If some entries were not
13489 representable, we don't want to pretend a single entry that was
13490 applies to the entire scope in which the variable is
13492 if (list
&& loc_list
->first
->next
)
13498 /* Return if the loc_list has only single element and thus can be represented
13499 as location description. */
13502 single_element_loc_list_p (dw_loc_list_ref list
)
13504 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13505 return !list
->ll_symbol
;
13508 /* To each location in list LIST add loc descr REF. */
13511 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13513 dw_loc_descr_ref copy
;
13514 add_loc_descr (&list
->expr
, ref
);
13515 list
= list
->dw_loc_next
;
13518 copy
= ggc_alloc_dw_loc_descr_node ();
13519 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13520 add_loc_descr (&list
->expr
, copy
);
13521 while (copy
->dw_loc_next
)
13523 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13524 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13525 copy
->dw_loc_next
= new_copy
;
13528 list
= list
->dw_loc_next
;
13532 /* Given two lists RET and LIST
13533 produce location list that is result of adding expression in LIST
13534 to expression in RET on each position in program.
13535 Might be destructive on both RET and LIST.
13537 TODO: We handle only simple cases of RET or LIST having at most one
13538 element. General case would inolve sorting the lists in program order
13539 and merging them that will need some additional work.
13540 Adding that will improve quality of debug info especially for SRA-ed
13544 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13553 if (!list
->dw_loc_next
)
13555 add_loc_descr_to_each (*ret
, list
->expr
);
13558 if (!(*ret
)->dw_loc_next
)
13560 add_loc_descr_to_each (list
, (*ret
)->expr
);
13564 expansion_failed (NULL_TREE
, NULL_RTX
,
13565 "Don't know how to merge two non-trivial"
13566 " location lists.\n");
13571 /* LOC is constant expression. Try a luck, look it up in constant
13572 pool and return its loc_descr of its address. */
13574 static dw_loc_descr_ref
13575 cst_pool_loc_descr (tree loc
)
13577 /* Get an RTL for this, if something has been emitted. */
13578 rtx rtl
= lookup_constant_def (loc
);
13580 if (!rtl
|| !MEM_P (rtl
))
13585 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13587 /* TODO: We might get more coverage if we was actually delaying expansion
13588 of all expressions till end of compilation when constant pools are fully
13590 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13592 expansion_failed (loc
, NULL_RTX
,
13593 "CST value in contant pool but not marked.");
13596 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13597 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13600 /* Return dw_loc_list representing address of addr_expr LOC
13601 by looking for inner INDIRECT_REF expression and turning
13602 it into simple arithmetics. */
13604 static dw_loc_list_ref
13605 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13608 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13609 enum machine_mode mode
;
13610 int unsignedp
, volatilep
= 0;
13611 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13613 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13614 &bitsize
, &bitpos
, &offset
, &mode
,
13615 &unsignedp
, &volatilep
, false);
13617 if (bitpos
% BITS_PER_UNIT
)
13619 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13622 if (!INDIRECT_REF_P (obj
))
13624 expansion_failed (obj
,
13625 NULL_RTX
, "no indirect ref in inner refrence");
13628 if (!offset
&& !bitpos
)
13629 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13631 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13632 && (dwarf_version
>= 4 || !dwarf_strict
))
13634 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13639 /* Variable offset. */
13640 list_ret1
= loc_list_from_tree (offset
, 0);
13641 if (list_ret1
== 0)
13643 add_loc_list (&list_ret
, list_ret1
);
13646 add_loc_descr_to_each (list_ret
,
13647 new_loc_descr (DW_OP_plus
, 0, 0));
13649 bytepos
= bitpos
/ BITS_PER_UNIT
;
13651 add_loc_descr_to_each (list_ret
,
13652 new_loc_descr (DW_OP_plus_uconst
,
13654 else if (bytepos
< 0)
13655 loc_list_plus_const (list_ret
, bytepos
);
13656 add_loc_descr_to_each (list_ret
,
13657 new_loc_descr (DW_OP_stack_value
, 0, 0));
13663 /* Generate Dwarf location list representing LOC.
13664 If WANT_ADDRESS is false, expression computing LOC will be computed
13665 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13666 if WANT_ADDRESS is 2, expression computing address useable in location
13667 will be returned (i.e. DW_OP_reg can be used
13668 to refer to register values). */
13670 static dw_loc_list_ref
13671 loc_list_from_tree (tree loc
, int want_address
)
13673 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13674 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13675 int have_address
= 0;
13676 enum dwarf_location_atom op
;
13678 /* ??? Most of the time we do not take proper care for sign/zero
13679 extending the values properly. Hopefully this won't be a real
13682 switch (TREE_CODE (loc
))
13685 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13688 case PLACEHOLDER_EXPR
:
13689 /* This case involves extracting fields from an object to determine the
13690 position of other fields. We don't try to encode this here. The
13691 only user of this is Ada, which encodes the needed information using
13692 the names of types. */
13693 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13697 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13698 /* There are no opcodes for these operations. */
13701 case PREINCREMENT_EXPR
:
13702 case PREDECREMENT_EXPR
:
13703 case POSTINCREMENT_EXPR
:
13704 case POSTDECREMENT_EXPR
:
13705 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13706 /* There are no opcodes for these operations. */
13710 /* If we already want an address, see if there is INDIRECT_REF inside
13711 e.g. for &this->field. */
13714 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13715 (loc
, want_address
== 2);
13718 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13719 && (ret
= cst_pool_loc_descr (loc
)))
13722 /* Otherwise, process the argument and look for the address. */
13723 if (!list_ret
&& !ret
)
13724 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13728 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13734 if (DECL_THREAD_LOCAL_P (loc
))
13737 enum dwarf_location_atom tls_op
;
13738 enum dtprel_bool dtprel
= dtprel_false
;
13740 if (targetm
.have_tls
)
13742 /* If this is not defined, we have no way to emit the
13744 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13747 /* The way DW_OP_GNU_push_tls_address is specified, we
13748 can only look up addresses of objects in the current
13749 module. We used DW_OP_addr as first op, but that's
13750 wrong, because DW_OP_addr is relocated by the debug
13751 info consumer, while DW_OP_GNU_push_tls_address
13752 operand shouldn't be. */
13753 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13755 dtprel
= dtprel_true
;
13756 tls_op
= DW_OP_GNU_push_tls_address
;
13760 if (!targetm
.emutls
.debug_form_tls_address
13761 || !(dwarf_version
>= 3 || !dwarf_strict
))
13763 /* We stuffed the control variable into the DECL_VALUE_EXPR
13764 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13765 no longer appear in gimple code. We used the control
13766 variable in specific so that we could pick it up here. */
13767 loc
= DECL_VALUE_EXPR (loc
);
13768 tls_op
= DW_OP_form_tls_address
;
13771 rtl
= rtl_for_decl_location (loc
);
13772 if (rtl
== NULL_RTX
)
13777 rtl
= XEXP (rtl
, 0);
13778 if (! CONSTANT_P (rtl
))
13781 ret
= new_addr_loc_descr (rtl
, dtprel
);
13782 ret1
= new_loc_descr (tls_op
, 0, 0);
13783 add_loc_descr (&ret
, ret1
);
13792 if (DECL_HAS_VALUE_EXPR_P (loc
))
13793 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13797 case FUNCTION_DECL
:
13800 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13802 if (loc_list
&& loc_list
->first
)
13804 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13805 have_address
= want_address
!= 0;
13808 rtl
= rtl_for_decl_location (loc
);
13809 if (rtl
== NULL_RTX
)
13811 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13814 else if (CONST_INT_P (rtl
))
13816 HOST_WIDE_INT val
= INTVAL (rtl
);
13817 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13818 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13819 ret
= int_loc_descriptor (val
);
13821 else if (GET_CODE (rtl
) == CONST_STRING
)
13823 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13826 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13827 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13830 enum machine_mode mode
, mem_mode
;
13832 /* Certain constructs can only be represented at top-level. */
13833 if (want_address
== 2)
13835 ret
= loc_descriptor (rtl
, VOIDmode
,
13836 VAR_INIT_STATUS_INITIALIZED
);
13841 mode
= GET_MODE (rtl
);
13842 mem_mode
= VOIDmode
;
13846 mode
= get_address_mode (rtl
);
13847 rtl
= XEXP (rtl
, 0);
13850 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13851 VAR_INIT_STATUS_INITIALIZED
);
13854 expansion_failed (loc
, rtl
,
13855 "failed to produce loc descriptor for rtl");
13862 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13866 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13870 case COMPOUND_EXPR
:
13871 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13874 case VIEW_CONVERT_EXPR
:
13877 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13879 case COMPONENT_REF
:
13880 case BIT_FIELD_REF
:
13882 case ARRAY_RANGE_REF
:
13883 case REALPART_EXPR
:
13884 case IMAGPART_EXPR
:
13887 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13888 enum machine_mode mode
;
13889 int unsignedp
, volatilep
= 0;
13891 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13892 &unsignedp
, &volatilep
, false);
13894 gcc_assert (obj
!= loc
);
13896 list_ret
= loc_list_from_tree (obj
,
13898 && !bitpos
&& !offset
? 2 : 1);
13899 /* TODO: We can extract value of the small expression via shifting even
13900 for nonzero bitpos. */
13903 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13905 expansion_failed (loc
, NULL_RTX
,
13906 "bitfield access");
13910 if (offset
!= NULL_TREE
)
13912 /* Variable offset. */
13913 list_ret1
= loc_list_from_tree (offset
, 0);
13914 if (list_ret1
== 0)
13916 add_loc_list (&list_ret
, list_ret1
);
13919 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13922 bytepos
= bitpos
/ BITS_PER_UNIT
;
13924 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13925 else if (bytepos
< 0)
13926 loc_list_plus_const (list_ret
, bytepos
);
13933 if ((want_address
|| !host_integerp (loc
, 0))
13934 && (ret
= cst_pool_loc_descr (loc
)))
13936 else if (want_address
== 2
13937 && host_integerp (loc
, 0)
13938 && (ret
= address_of_int_loc_descriptor
13939 (int_size_in_bytes (TREE_TYPE (loc
)),
13940 tree_low_cst (loc
, 0))))
13942 else if (host_integerp (loc
, 0))
13943 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13946 expansion_failed (loc
, NULL_RTX
,
13947 "Integer operand is not host integer");
13956 if ((ret
= cst_pool_loc_descr (loc
)))
13959 /* We can construct small constants here using int_loc_descriptor. */
13960 expansion_failed (loc
, NULL_RTX
,
13961 "constructor or constant not in constant pool");
13964 case TRUTH_AND_EXPR
:
13965 case TRUTH_ANDIF_EXPR
:
13970 case TRUTH_XOR_EXPR
:
13975 case TRUTH_OR_EXPR
:
13976 case TRUTH_ORIF_EXPR
:
13981 case FLOOR_DIV_EXPR
:
13982 case CEIL_DIV_EXPR
:
13983 case ROUND_DIV_EXPR
:
13984 case TRUNC_DIV_EXPR
:
13985 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13994 case FLOOR_MOD_EXPR
:
13995 case CEIL_MOD_EXPR
:
13996 case ROUND_MOD_EXPR
:
13997 case TRUNC_MOD_EXPR
:
13998 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14003 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14004 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14005 if (list_ret
== 0 || list_ret1
== 0)
14008 add_loc_list (&list_ret
, list_ret1
);
14011 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14012 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14013 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14014 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14015 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14027 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14030 case POINTER_PLUS_EXPR
:
14032 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14034 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14038 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14046 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14053 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14060 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14067 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14082 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14083 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14084 if (list_ret
== 0 || list_ret1
== 0)
14087 add_loc_list (&list_ret
, list_ret1
);
14090 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14093 case TRUTH_NOT_EXPR
:
14107 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14111 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14117 const enum tree_code code
=
14118 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14120 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14121 build2 (code
, integer_type_node
,
14122 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14123 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14126 /* ... fall through ... */
14130 dw_loc_descr_ref lhs
14131 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14132 dw_loc_list_ref rhs
14133 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14134 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14136 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14137 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14140 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14141 add_loc_descr_to_each (list_ret
, bra_node
);
14143 add_loc_list (&list_ret
, rhs
);
14144 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14145 add_loc_descr_to_each (list_ret
, jump_node
);
14147 add_loc_descr_to_each (list_ret
, lhs
);
14148 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14149 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14151 /* ??? Need a node to point the skip at. Use a nop. */
14152 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14153 add_loc_descr_to_each (list_ret
, tmp
);
14154 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14155 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14159 case FIX_TRUNC_EXPR
:
14163 /* Leave front-end specific codes as simply unknown. This comes
14164 up, for instance, with the C STMT_EXPR. */
14165 if ((unsigned int) TREE_CODE (loc
)
14166 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14168 expansion_failed (loc
, NULL_RTX
,
14169 "language specific tree node");
14173 #ifdef ENABLE_CHECKING
14174 /* Otherwise this is a generic code; we should just lists all of
14175 these explicitly. We forgot one. */
14176 gcc_unreachable ();
14178 /* In a release build, we want to degrade gracefully: better to
14179 generate incomplete debugging information than to crash. */
14184 if (!ret
&& !list_ret
)
14187 if (want_address
== 2 && !have_address
14188 && (dwarf_version
>= 4 || !dwarf_strict
))
14190 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14192 expansion_failed (loc
, NULL_RTX
,
14193 "DWARF address size mismatch");
14197 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14199 add_loc_descr_to_each (list_ret
,
14200 new_loc_descr (DW_OP_stack_value
, 0, 0));
14203 /* Show if we can't fill the request for an address. */
14204 if (want_address
&& !have_address
)
14206 expansion_failed (loc
, NULL_RTX
,
14207 "Want address and only have value");
14211 gcc_assert (!ret
|| !list_ret
);
14213 /* If we've got an address and don't want one, dereference. */
14214 if (!want_address
&& have_address
)
14216 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14218 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14220 expansion_failed (loc
, NULL_RTX
,
14221 "DWARF address size mismatch");
14224 else if (size
== DWARF2_ADDR_SIZE
)
14227 op
= DW_OP_deref_size
;
14230 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14232 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14235 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14240 /* Same as above but return only single location expression. */
14241 static dw_loc_descr_ref
14242 loc_descriptor_from_tree (tree loc
, int want_address
)
14244 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14247 if (ret
->dw_loc_next
)
14249 expansion_failed (loc
, NULL_RTX
,
14250 "Location list where only loc descriptor needed");
14256 /* Given a value, round it up to the lowest multiple of `boundary'
14257 which is not less than the value itself. */
14259 static inline HOST_WIDE_INT
14260 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14262 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14265 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14266 pointer to the declared type for the relevant field variable, or return
14267 `integer_type_node' if the given node turns out to be an
14268 ERROR_MARK node. */
14271 field_type (const_tree decl
)
14275 if (TREE_CODE (decl
) == ERROR_MARK
)
14276 return integer_type_node
;
14278 type
= DECL_BIT_FIELD_TYPE (decl
);
14279 if (type
== NULL_TREE
)
14280 type
= TREE_TYPE (decl
);
14285 /* Given a pointer to a tree node, return the alignment in bits for
14286 it, or else return BITS_PER_WORD if the node actually turns out to
14287 be an ERROR_MARK node. */
14289 static inline unsigned
14290 simple_type_align_in_bits (const_tree type
)
14292 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14295 static inline unsigned
14296 simple_decl_align_in_bits (const_tree decl
)
14298 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14301 /* Return the result of rounding T up to ALIGN. */
14303 static inline double_int
14304 round_up_to_align (double_int t
, unsigned int align
)
14306 double_int alignd
= double_int::from_uhwi (align
);
14308 t
+= double_int_minus_one
;
14309 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14314 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14315 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14316 or return 0 if we are unable to determine what that offset is, either
14317 because the argument turns out to be a pointer to an ERROR_MARK node, or
14318 because the offset is actually variable. (We can't handle the latter case
14321 static HOST_WIDE_INT
14322 field_byte_offset (const_tree decl
)
14324 double_int object_offset_in_bits
;
14325 double_int object_offset_in_bytes
;
14326 double_int bitpos_int
;
14328 if (TREE_CODE (decl
) == ERROR_MARK
)
14331 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14333 /* We cannot yet cope with fields whose positions are variable, so
14334 for now, when we see such things, we simply return 0. Someday, we may
14335 be able to handle such cases, but it will be damn difficult. */
14336 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14339 bitpos_int
= tree_to_double_int (bit_position (decl
));
14341 #ifdef PCC_BITFIELD_TYPE_MATTERS
14342 if (PCC_BITFIELD_TYPE_MATTERS
)
14345 tree field_size_tree
;
14346 double_int deepest_bitpos
;
14347 double_int field_size_in_bits
;
14348 unsigned int type_align_in_bits
;
14349 unsigned int decl_align_in_bits
;
14350 double_int type_size_in_bits
;
14352 type
= field_type (decl
);
14353 type_size_in_bits
= double_int_type_size_in_bits (type
);
14354 type_align_in_bits
= simple_type_align_in_bits (type
);
14356 field_size_tree
= DECL_SIZE (decl
);
14358 /* The size could be unspecified if there was an error, or for
14359 a flexible array member. */
14360 if (!field_size_tree
)
14361 field_size_tree
= bitsize_zero_node
;
14363 /* If the size of the field is not constant, use the type size. */
14364 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14365 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14367 field_size_in_bits
= type_size_in_bits
;
14369 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14371 /* The GCC front-end doesn't make any attempt to keep track of the
14372 starting bit offset (relative to the start of the containing
14373 structure type) of the hypothetical "containing object" for a
14374 bit-field. Thus, when computing the byte offset value for the
14375 start of the "containing object" of a bit-field, we must deduce
14376 this information on our own. This can be rather tricky to do in
14377 some cases. For example, handling the following structure type
14378 definition when compiling for an i386/i486 target (which only
14379 aligns long long's to 32-bit boundaries) can be very tricky:
14381 struct S { int field1; long long field2:31; };
14383 Fortunately, there is a simple rule-of-thumb which can be used
14384 in such cases. When compiling for an i386/i486, GCC will
14385 allocate 8 bytes for the structure shown above. It decides to
14386 do this based upon one simple rule for bit-field allocation.
14387 GCC allocates each "containing object" for each bit-field at
14388 the first (i.e. lowest addressed) legitimate alignment boundary
14389 (based upon the required minimum alignment for the declared
14390 type of the field) which it can possibly use, subject to the
14391 condition that there is still enough available space remaining
14392 in the containing object (when allocated at the selected point)
14393 to fully accommodate all of the bits of the bit-field itself.
14395 This simple rule makes it obvious why GCC allocates 8 bytes for
14396 each object of the structure type shown above. When looking
14397 for a place to allocate the "containing object" for `field2',
14398 the compiler simply tries to allocate a 64-bit "containing
14399 object" at each successive 32-bit boundary (starting at zero)
14400 until it finds a place to allocate that 64- bit field such that
14401 at least 31 contiguous (and previously unallocated) bits remain
14402 within that selected 64 bit field. (As it turns out, for the
14403 example above, the compiler finds it is OK to allocate the
14404 "containing object" 64-bit field at bit-offset zero within the
14407 Here we attempt to work backwards from the limited set of facts
14408 we're given, and we try to deduce from those facts, where GCC
14409 must have believed that the containing object started (within
14410 the structure type). The value we deduce is then used (by the
14411 callers of this routine) to generate DW_AT_location and
14412 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14413 the case of DW_AT_location, regular fields as well). */
14415 /* Figure out the bit-distance from the start of the structure to
14416 the "deepest" bit of the bit-field. */
14417 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14419 /* This is the tricky part. Use some fancy footwork to deduce
14420 where the lowest addressed bit of the containing object must
14422 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14424 /* Round up to type_align by default. This works best for
14426 object_offset_in_bits
14427 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14429 if (object_offset_in_bits
.ugt (bitpos_int
))
14431 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14433 /* Round up to decl_align instead. */
14434 object_offset_in_bits
14435 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14439 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14440 object_offset_in_bits
= bitpos_int
;
14442 object_offset_in_bytes
14443 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14444 true, TRUNC_DIV_EXPR
);
14445 return object_offset_in_bytes
.to_shwi ();
14448 /* The following routines define various Dwarf attributes and any data
14449 associated with them. */
14451 /* Add a location description attribute value to a DIE.
14453 This emits location attributes suitable for whole variables and
14454 whole parameters. Note that the location attributes for struct fields are
14455 generated by the routine `data_member_location_attribute' below. */
14458 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14459 dw_loc_list_ref descr
)
14463 if (single_element_loc_list_p (descr
))
14464 add_AT_loc (die
, attr_kind
, descr
->expr
);
14466 add_AT_loc_list (die
, attr_kind
, descr
);
14469 /* Add DW_AT_accessibility attribute to DIE if needed. */
14472 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14474 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14475 children, otherwise the default is DW_ACCESS_public. In DWARF2
14476 the default has always been DW_ACCESS_public. */
14477 if (TREE_PROTECTED (decl
))
14478 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14479 else if (TREE_PRIVATE (decl
))
14481 if (dwarf_version
== 2
14482 || die
->die_parent
== NULL
14483 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14484 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14486 else if (dwarf_version
> 2
14488 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14489 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14492 /* Attach the specialized form of location attribute used for data members of
14493 struct and union types. In the special case of a FIELD_DECL node which
14494 represents a bit-field, the "offset" part of this special location
14495 descriptor must indicate the distance in bytes from the lowest-addressed
14496 byte of the containing struct or union type to the lowest-addressed byte of
14497 the "containing object" for the bit-field. (See the `field_byte_offset'
14500 For any given bit-field, the "containing object" is a hypothetical object
14501 (of some integral or enum type) within which the given bit-field lives. The
14502 type of this hypothetical "containing object" is always the same as the
14503 declared type of the individual bit-field itself (for GCC anyway... the
14504 DWARF spec doesn't actually mandate this). Note that it is the size (in
14505 bytes) of the hypothetical "containing object" which will be given in the
14506 DW_AT_byte_size attribute for this bit-field. (See the
14507 `byte_size_attribute' function below.) It is also used when calculating the
14508 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14509 function below.) */
14512 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14514 HOST_WIDE_INT offset
;
14515 dw_loc_descr_ref loc_descr
= 0;
14517 if (TREE_CODE (decl
) == TREE_BINFO
)
14519 /* We're working on the TAG_inheritance for a base class. */
14520 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14522 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14523 aren't at a fixed offset from all (sub)objects of the same
14524 type. We need to extract the appropriate offset from our
14525 vtable. The following dwarf expression means
14527 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14529 This is specific to the V3 ABI, of course. */
14531 dw_loc_descr_ref tmp
;
14533 /* Make a copy of the object address. */
14534 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14535 add_loc_descr (&loc_descr
, tmp
);
14537 /* Extract the vtable address. */
14538 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14539 add_loc_descr (&loc_descr
, tmp
);
14541 /* Calculate the address of the offset. */
14542 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14543 gcc_assert (offset
< 0);
14545 tmp
= int_loc_descriptor (-offset
);
14546 add_loc_descr (&loc_descr
, tmp
);
14547 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14548 add_loc_descr (&loc_descr
, tmp
);
14550 /* Extract the offset. */
14551 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14552 add_loc_descr (&loc_descr
, tmp
);
14554 /* Add it to the object address. */
14555 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14556 add_loc_descr (&loc_descr
, tmp
);
14559 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14562 offset
= field_byte_offset (decl
);
14566 if (dwarf_version
> 2)
14568 /* Don't need to output a location expression, just the constant. */
14570 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14572 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14577 enum dwarf_location_atom op
;
14579 /* The DWARF2 standard says that we should assume that the structure
14580 address is already on the stack, so we can specify a structure
14581 field address by using DW_OP_plus_uconst. */
14582 op
= DW_OP_plus_uconst
;
14583 loc_descr
= new_loc_descr (op
, offset
, 0);
14587 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14590 /* Writes integer values to dw_vec_const array. */
14593 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14597 *dest
++ = val
& 0xff;
14603 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14605 static HOST_WIDE_INT
14606 extract_int (const unsigned char *src
, unsigned int size
)
14608 HOST_WIDE_INT val
= 0;
14614 val
|= *--src
& 0xff;
14620 /* Writes double_int values to dw_vec_const array. */
14623 insert_double (double_int val
, unsigned char *dest
)
14625 unsigned char *p0
= dest
;
14626 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14628 if (WORDS_BIG_ENDIAN
)
14634 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14635 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14638 /* Writes floating point values to dw_vec_const array. */
14641 insert_float (const_rtx rtl
, unsigned char *array
)
14643 REAL_VALUE_TYPE rv
;
14647 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14648 real_to_target (val
, &rv
, GET_MODE (rtl
));
14650 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14651 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14653 insert_int (val
[i
], 4, array
);
14658 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14659 does not have a "location" either in memory or in a register. These
14660 things can arise in GNU C when a constant is passed as an actual parameter
14661 to an inlined function. They can also arise in C++ where declared
14662 constants do not necessarily get memory "homes". */
14665 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14667 switch (GET_CODE (rtl
))
14671 HOST_WIDE_INT val
= INTVAL (rtl
);
14674 add_AT_int (die
, DW_AT_const_value
, val
);
14676 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14681 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14682 floating-point constant. A CONST_DOUBLE is used whenever the
14683 constant requires more than one word in order to be adequately
14686 enum machine_mode mode
= GET_MODE (rtl
);
14688 if (SCALAR_FLOAT_MODE_P (mode
))
14690 unsigned int length
= GET_MODE_SIZE (mode
);
14691 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14693 insert_float (rtl
, array
);
14694 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14697 add_AT_double (die
, DW_AT_const_value
,
14698 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14704 enum machine_mode mode
= GET_MODE (rtl
);
14705 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14706 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14707 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14708 (length
* elt_size
);
14712 switch (GET_MODE_CLASS (mode
))
14714 case MODE_VECTOR_INT
:
14715 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14717 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14718 double_int val
= rtx_to_double_int (elt
);
14720 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14721 insert_int (val
.to_shwi (), elt_size
, p
);
14724 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14725 insert_double (val
, p
);
14730 case MODE_VECTOR_FLOAT
:
14731 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14733 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14734 insert_float (elt
, p
);
14739 gcc_unreachable ();
14742 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14747 if (dwarf_version
>= 4 || !dwarf_strict
)
14749 dw_loc_descr_ref loc_result
;
14750 resolve_one_addr (&rtl
, NULL
);
14752 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14753 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14754 add_AT_loc (die
, DW_AT_location
, loc_result
);
14755 vec_safe_push (used_rtx_array
, rtl
);
14761 if (CONSTANT_P (XEXP (rtl
, 0)))
14762 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14765 if (!const_ok_for_output (rtl
))
14768 if (dwarf_version
>= 4 || !dwarf_strict
)
14773 /* In cases where an inlined instance of an inline function is passed
14774 the address of an `auto' variable (which is local to the caller) we
14775 can get a situation where the DECL_RTL of the artificial local
14776 variable (for the inlining) which acts as a stand-in for the
14777 corresponding formal parameter (of the inline function) will look
14778 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14779 exactly a compile-time constant expression, but it isn't the address
14780 of the (artificial) local variable either. Rather, it represents the
14781 *value* which the artificial local variable always has during its
14782 lifetime. We currently have no way to represent such quasi-constant
14783 values in Dwarf, so for now we just punt and generate nothing. */
14791 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14792 && MEM_READONLY_P (rtl
)
14793 && GET_MODE (rtl
) == BLKmode
)
14795 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14801 /* No other kinds of rtx should be possible here. */
14802 gcc_unreachable ();
14807 /* Determine whether the evaluation of EXPR references any variables
14808 or functions which aren't otherwise used (and therefore may not be
14811 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14812 void * data ATTRIBUTE_UNUSED
)
14814 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14815 *walk_subtrees
= 0;
14817 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14818 && ! TREE_ASM_WRITTEN (*tp
))
14820 /* ??? The C++ FE emits debug information for using decls, so
14821 putting gcc_unreachable here falls over. See PR31899. For now
14822 be conservative. */
14823 else if (!cgraph_global_info_ready
14824 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14826 else if (TREE_CODE (*tp
) == VAR_DECL
)
14828 struct varpool_node
*node
= varpool_get_node (*tp
);
14829 if (!node
|| !node
->analyzed
)
14832 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14833 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14835 /* The call graph machinery must have finished analyzing,
14836 optimizing and gimplifying the CU by now.
14837 So if *TP has no call graph node associated
14838 to it, it means *TP will not be emitted. */
14839 if (!cgraph_get_node (*tp
))
14842 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14848 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14849 for use in a later add_const_value_attribute call. */
14852 rtl_for_decl_init (tree init
, tree type
)
14854 rtx rtl
= NULL_RTX
;
14858 /* If a variable is initialized with a string constant without embedded
14859 zeros, build CONST_STRING. */
14860 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14862 tree enttype
= TREE_TYPE (type
);
14863 tree domain
= TYPE_DOMAIN (type
);
14864 enum machine_mode mode
= TYPE_MODE (enttype
);
14866 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14868 && integer_zerop (TYPE_MIN_VALUE (domain
))
14869 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14870 TREE_STRING_LENGTH (init
) - 1) == 0
14871 && ((size_t) TREE_STRING_LENGTH (init
)
14872 == strlen (TREE_STRING_POINTER (init
)) + 1))
14874 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14875 ggc_strdup (TREE_STRING_POINTER (init
)));
14876 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14877 MEM_READONLY_P (rtl
) = 1;
14880 /* Other aggregates, and complex values, could be represented using
14882 else if (AGGREGATE_TYPE_P (type
)
14883 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14884 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14885 || TREE_CODE (type
) == COMPLEX_TYPE
)
14887 /* Vectors only work if their mode is supported by the target.
14888 FIXME: generic vectors ought to work too. */
14889 else if (TREE_CODE (type
) == VECTOR_TYPE
14890 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14892 /* If the initializer is something that we know will expand into an
14893 immediate RTL constant, expand it now. We must be careful not to
14894 reference variables which won't be output. */
14895 else if (initializer_constant_valid_p (init
, type
)
14896 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14898 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14900 if (TREE_CODE (type
) == VECTOR_TYPE
)
14901 switch (TREE_CODE (init
))
14906 if (TREE_CONSTANT (init
))
14908 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
14909 bool constant_p
= true;
14911 unsigned HOST_WIDE_INT ix
;
14913 /* Even when ctor is constant, it might contain non-*_CST
14914 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14915 belong into VECTOR_CST nodes. */
14916 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14917 if (!CONSTANT_CLASS_P (value
))
14919 constant_p
= false;
14925 init
= build_vector_from_ctor (type
, elts
);
14935 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14937 /* If expand_expr returns a MEM, it wasn't immediate. */
14938 gcc_assert (!rtl
|| !MEM_P (rtl
));
14944 /* Generate RTL for the variable DECL to represent its location. */
14947 rtl_for_decl_location (tree decl
)
14951 /* Here we have to decide where we are going to say the parameter "lives"
14952 (as far as the debugger is concerned). We only have a couple of
14953 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14955 DECL_RTL normally indicates where the parameter lives during most of the
14956 activation of the function. If optimization is enabled however, this
14957 could be either NULL or else a pseudo-reg. Both of those cases indicate
14958 that the parameter doesn't really live anywhere (as far as the code
14959 generation parts of GCC are concerned) during most of the function's
14960 activation. That will happen (for example) if the parameter is never
14961 referenced within the function.
14963 We could just generate a location descriptor here for all non-NULL
14964 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14965 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14966 where DECL_RTL is NULL or is a pseudo-reg.
14968 Note however that we can only get away with using DECL_INCOMING_RTL as
14969 a backup substitute for DECL_RTL in certain limited cases. In cases
14970 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14971 we can be sure that the parameter was passed using the same type as it is
14972 declared to have within the function, and that its DECL_INCOMING_RTL
14973 points us to a place where a value of that type is passed.
14975 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14976 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14977 because in these cases DECL_INCOMING_RTL points us to a value of some
14978 type which is *different* from the type of the parameter itself. Thus,
14979 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14980 such cases, the debugger would end up (for example) trying to fetch a
14981 `float' from a place which actually contains the first part of a
14982 `double'. That would lead to really incorrect and confusing
14983 output at debug-time.
14985 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14986 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
14987 are a couple of exceptions however. On little-endian machines we can
14988 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
14989 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
14990 an integral type that is smaller than TREE_TYPE (decl). These cases arise
14991 when (on a little-endian machine) a non-prototyped function has a
14992 parameter declared to be of type `short' or `char'. In such cases,
14993 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
14994 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
14995 passed `int' value. If the debugger then uses that address to fetch
14996 a `short' or a `char' (on a little-endian machine) the result will be
14997 the correct data, so we allow for such exceptional cases below.
14999 Note that our goal here is to describe the place where the given formal
15000 parameter lives during most of the function's activation (i.e. between the
15001 end of the prologue and the start of the epilogue). We'll do that as best
15002 as we can. Note however that if the given formal parameter is modified
15003 sometime during the execution of the function, then a stack backtrace (at
15004 debug-time) will show the function as having been called with the *new*
15005 value rather than the value which was originally passed in. This happens
15006 rarely enough that it is not a major problem, but it *is* a problem, and
15007 I'd like to fix it.
15009 A future version of dwarf2out.c may generate two additional attributes for
15010 any given DW_TAG_formal_parameter DIE which will describe the "passed
15011 type" and the "passed location" for the given formal parameter in addition
15012 to the attributes we now generate to indicate the "declared type" and the
15013 "active location" for each parameter. This additional set of attributes
15014 could be used by debuggers for stack backtraces. Separately, note that
15015 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15016 This happens (for example) for inlined-instances of inline function formal
15017 parameters which are never referenced. This really shouldn't be
15018 happening. All PARM_DECL nodes should get valid non-NULL
15019 DECL_INCOMING_RTL values. FIXME. */
15021 /* Use DECL_RTL as the "location" unless we find something better. */
15022 rtl
= DECL_RTL_IF_SET (decl
);
15024 /* When generating abstract instances, ignore everything except
15025 constants, symbols living in memory, and symbols living in
15026 fixed registers. */
15027 if (! reload_completed
)
15030 && (CONSTANT_P (rtl
)
15032 && CONSTANT_P (XEXP (rtl
, 0)))
15034 && TREE_CODE (decl
) == VAR_DECL
15035 && TREE_STATIC (decl
))))
15037 rtl
= targetm
.delegitimize_address (rtl
);
15042 else if (TREE_CODE (decl
) == PARM_DECL
)
15044 if (rtl
== NULL_RTX
15045 || is_pseudo_reg (rtl
)
15047 && is_pseudo_reg (XEXP (rtl
, 0))
15048 && DECL_INCOMING_RTL (decl
)
15049 && MEM_P (DECL_INCOMING_RTL (decl
))
15050 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15052 tree declared_type
= TREE_TYPE (decl
);
15053 tree passed_type
= DECL_ARG_TYPE (decl
);
15054 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15055 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15057 /* This decl represents a formal parameter which was optimized out.
15058 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15059 all cases where (rtl == NULL_RTX) just below. */
15060 if (dmode
== pmode
)
15061 rtl
= DECL_INCOMING_RTL (decl
);
15062 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15063 && SCALAR_INT_MODE_P (dmode
)
15064 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15065 && DECL_INCOMING_RTL (decl
))
15067 rtx inc
= DECL_INCOMING_RTL (decl
);
15070 else if (MEM_P (inc
))
15072 if (BYTES_BIG_ENDIAN
)
15073 rtl
= adjust_address_nv (inc
, dmode
,
15074 GET_MODE_SIZE (pmode
)
15075 - GET_MODE_SIZE (dmode
));
15082 /* If the parm was passed in registers, but lives on the stack, then
15083 make a big endian correction if the mode of the type of the
15084 parameter is not the same as the mode of the rtl. */
15085 /* ??? This is the same series of checks that are made in dbxout.c before
15086 we reach the big endian correction code there. It isn't clear if all
15087 of these checks are necessary here, but keeping them all is the safe
15089 else if (MEM_P (rtl
)
15090 && XEXP (rtl
, 0) != const0_rtx
15091 && ! CONSTANT_P (XEXP (rtl
, 0))
15092 /* Not passed in memory. */
15093 && !MEM_P (DECL_INCOMING_RTL (decl
))
15094 /* Not passed by invisible reference. */
15095 && (!REG_P (XEXP (rtl
, 0))
15096 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15097 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15098 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15099 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15102 /* Big endian correction check. */
15103 && BYTES_BIG_ENDIAN
15104 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15105 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15108 enum machine_mode addr_mode
= get_address_mode (rtl
);
15109 int offset
= (UNITS_PER_WORD
15110 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15112 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15113 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15116 else if (TREE_CODE (decl
) == VAR_DECL
15119 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15120 && BYTES_BIG_ENDIAN
)
15122 enum machine_mode addr_mode
= get_address_mode (rtl
);
15123 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15124 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15126 /* If a variable is declared "register" yet is smaller than
15127 a register, then if we store the variable to memory, it
15128 looks like we're storing a register-sized value, when in
15129 fact we are not. We need to adjust the offset of the
15130 storage location to reflect the actual value's bytes,
15131 else gdb will not be able to display it. */
15133 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15134 plus_constant (addr_mode
, XEXP (rtl
, 0),
15138 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15139 and will have been substituted directly into all expressions that use it.
15140 C does not have such a concept, but C++ and other languages do. */
15141 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15142 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15145 rtl
= targetm
.delegitimize_address (rtl
);
15147 /* If we don't look past the constant pool, we risk emitting a
15148 reference to a constant pool entry that isn't referenced from
15149 code, and thus is not emitted. */
15151 rtl
= avoid_constant_pool_reference (rtl
);
15153 /* Try harder to get a rtl. If this symbol ends up not being emitted
15154 in the current CU, resolve_addr will remove the expression referencing
15156 if (rtl
== NULL_RTX
15157 && TREE_CODE (decl
) == VAR_DECL
15158 && !DECL_EXTERNAL (decl
)
15159 && TREE_STATIC (decl
)
15160 && DECL_NAME (decl
)
15161 && !DECL_HARD_REGISTER (decl
)
15162 && DECL_MODE (decl
) != VOIDmode
)
15164 rtl
= make_decl_rtl_for_debug (decl
);
15166 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15167 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15174 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15175 returned. If so, the decl for the COMMON block is returned, and the
15176 value is the offset into the common block for the symbol. */
15179 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15181 tree val_expr
, cvar
;
15182 enum machine_mode mode
;
15183 HOST_WIDE_INT bitsize
, bitpos
;
15185 int unsignedp
, volatilep
= 0;
15187 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15188 it does not have a value (the offset into the common area), or if it
15189 is thread local (as opposed to global) then it isn't common, and shouldn't
15190 be handled as such. */
15191 if (TREE_CODE (decl
) != VAR_DECL
15192 || !TREE_STATIC (decl
)
15193 || !DECL_HAS_VALUE_EXPR_P (decl
)
15197 val_expr
= DECL_VALUE_EXPR (decl
);
15198 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15201 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15202 &mode
, &unsignedp
, &volatilep
, true);
15204 if (cvar
== NULL_TREE
15205 || TREE_CODE (cvar
) != VAR_DECL
15206 || DECL_ARTIFICIAL (cvar
)
15207 || !TREE_PUBLIC (cvar
))
15211 if (offset
!= NULL
)
15213 if (!host_integerp (offset
, 0))
15215 *value
= tree_low_cst (offset
, 0);
15218 *value
+= bitpos
/ BITS_PER_UNIT
;
15223 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15224 data attribute for a variable or a parameter. We generate the
15225 DW_AT_const_value attribute only in those cases where the given variable
15226 or parameter does not have a true "location" either in memory or in a
15227 register. This can happen (for example) when a constant is passed as an
15228 actual argument in a call to an inline function. (It's possible that
15229 these things can crop up in other ways also.) Note that one type of
15230 constant value which can be passed into an inlined function is a constant
15231 pointer. This can happen for example if an actual argument in an inlined
15232 function call evaluates to a compile-time constant address.
15234 CACHE_P is true if it is worth caching the location list for DECL,
15235 so that future calls can reuse it rather than regenerate it from scratch.
15236 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15237 since we will need to refer to them each time the function is inlined. */
15240 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15241 enum dwarf_attribute attr
)
15244 dw_loc_list_ref list
;
15245 var_loc_list
*loc_list
;
15246 cached_dw_loc_list
*cache
;
15249 if (TREE_CODE (decl
) == ERROR_MARK
)
15252 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15253 || TREE_CODE (decl
) == RESULT_DECL
);
15255 /* Try to get some constant RTL for this decl, and use that as the value of
15258 rtl
= rtl_for_decl_location (decl
);
15259 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15260 && add_const_value_attribute (die
, rtl
))
15263 /* See if we have single element location list that is equivalent to
15264 a constant value. That way we are better to use add_const_value_attribute
15265 rather than expanding constant value equivalent. */
15266 loc_list
= lookup_decl_loc (decl
);
15269 && loc_list
->first
->next
== NULL
15270 && NOTE_P (loc_list
->first
->loc
)
15271 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15272 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15274 struct var_loc_node
*node
;
15276 node
= loc_list
->first
;
15277 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15278 if (GET_CODE (rtl
) == EXPR_LIST
)
15279 rtl
= XEXP (rtl
, 0);
15280 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15281 && add_const_value_attribute (die
, rtl
))
15284 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15285 list several times. See if we've already cached the contents. */
15287 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15291 cache
= (cached_dw_loc_list
*)
15292 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15294 list
= cache
->loc_list
;
15298 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15299 /* It is usually worth caching this result if the decl is from
15300 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15301 if (cache_p
&& list
&& list
->dw_loc_next
)
15303 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15304 DECL_UID (decl
), INSERT
);
15305 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15306 cache
->decl_id
= DECL_UID (decl
);
15307 cache
->loc_list
= list
;
15313 add_AT_location_description (die
, attr
, list
);
15316 /* None of that worked, so it must not really have a location;
15317 try adding a constant value attribute from the DECL_INITIAL. */
15318 return tree_add_const_value_attribute_for_decl (die
, decl
);
15321 /* Add VARIABLE and DIE into deferred locations list. */
15324 defer_location (tree variable
, dw_die_ref die
)
15326 deferred_locations entry
;
15327 entry
.variable
= variable
;
15329 vec_safe_push (deferred_locations_list
, entry
);
15332 /* Helper function for tree_add_const_value_attribute. Natively encode
15333 initializer INIT into an array. Return true if successful. */
15336 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15340 if (init
== NULL_TREE
)
15344 switch (TREE_CODE (init
))
15347 type
= TREE_TYPE (init
);
15348 if (TREE_CODE (type
) == ARRAY_TYPE
)
15350 tree enttype
= TREE_TYPE (type
);
15351 enum machine_mode mode
= TYPE_MODE (enttype
);
15353 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15355 if (int_size_in_bytes (type
) != size
)
15357 if (size
> TREE_STRING_LENGTH (init
))
15359 memcpy (array
, TREE_STRING_POINTER (init
),
15360 TREE_STRING_LENGTH (init
));
15361 memset (array
+ TREE_STRING_LENGTH (init
),
15362 '\0', size
- TREE_STRING_LENGTH (init
));
15365 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15370 type
= TREE_TYPE (init
);
15371 if (int_size_in_bytes (type
) != size
)
15373 if (TREE_CODE (type
) == ARRAY_TYPE
)
15375 HOST_WIDE_INT min_index
;
15376 unsigned HOST_WIDE_INT cnt
;
15377 int curpos
= 0, fieldsize
;
15378 constructor_elt
*ce
;
15380 if (TYPE_DOMAIN (type
) == NULL_TREE
15381 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15384 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15385 if (fieldsize
<= 0)
15388 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15389 memset (array
, '\0', size
);
15390 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15392 tree val
= ce
->value
;
15393 tree index
= ce
->index
;
15395 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15396 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15399 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15404 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15407 curpos
= pos
+ fieldsize
;
15408 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15410 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15411 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15412 while (count
-- > 0)
15415 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15416 curpos
+= fieldsize
;
15419 gcc_assert (curpos
<= size
);
15423 else if (TREE_CODE (type
) == RECORD_TYPE
15424 || TREE_CODE (type
) == UNION_TYPE
)
15426 tree field
= NULL_TREE
;
15427 unsigned HOST_WIDE_INT cnt
;
15428 constructor_elt
*ce
;
15430 if (int_size_in_bytes (type
) != size
)
15433 if (TREE_CODE (type
) == RECORD_TYPE
)
15434 field
= TYPE_FIELDS (type
);
15436 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15438 tree val
= ce
->value
;
15439 int pos
, fieldsize
;
15441 if (ce
->index
!= 0)
15447 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15450 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15451 && TYPE_DOMAIN (TREE_TYPE (field
))
15452 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15454 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15455 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15457 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15458 pos
= int_byte_position (field
);
15459 gcc_assert (pos
+ fieldsize
<= size
);
15461 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15467 case VIEW_CONVERT_EXPR
:
15468 case NON_LVALUE_EXPR
:
15469 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15471 return native_encode_expr (init
, array
, size
) == size
;
15475 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15476 attribute is the const value T. */
15479 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15482 tree type
= TREE_TYPE (t
);
15485 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15489 gcc_assert (!DECL_P (init
));
15491 rtl
= rtl_for_decl_init (init
, type
);
15493 return add_const_value_attribute (die
, rtl
);
15494 /* If the host and target are sane, try harder. */
15495 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15496 && initializer_constant_valid_p (init
, type
))
15498 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15499 if (size
> 0 && (int) size
== size
)
15501 unsigned char *array
= (unsigned char *)
15502 ggc_alloc_cleared_atomic (size
);
15504 if (native_encode_initializer (init
, array
, size
))
15506 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15514 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15515 attribute is the const value of T, where T is an integral constant
15516 variable with static storage duration
15517 (so it can't be a PARM_DECL or a RESULT_DECL). */
15520 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15524 || (TREE_CODE (decl
) != VAR_DECL
15525 && TREE_CODE (decl
) != CONST_DECL
)
15526 || (TREE_CODE (decl
) == VAR_DECL
15527 && !TREE_STATIC (decl
)))
15530 if (TREE_READONLY (decl
)
15531 && ! TREE_THIS_VOLATILE (decl
)
15532 && DECL_INITIAL (decl
))
15537 /* Don't add DW_AT_const_value if abstract origin already has one. */
15538 if (get_AT (var_die
, DW_AT_const_value
))
15541 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15544 /* Convert the CFI instructions for the current function into a
15545 location list. This is used for DW_AT_frame_base when we targeting
15546 a dwarf2 consumer that does not support the dwarf3
15547 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15550 static dw_loc_list_ref
15551 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15555 dw_loc_list_ref list
, *list_tail
;
15557 dw_cfa_location last_cfa
, next_cfa
;
15558 const char *start_label
, *last_label
, *section
;
15559 dw_cfa_location remember
;
15562 gcc_assert (fde
!= NULL
);
15564 section
= secname_for_decl (current_function_decl
);
15568 memset (&next_cfa
, 0, sizeof (next_cfa
));
15569 next_cfa
.reg
= INVALID_REGNUM
;
15570 remember
= next_cfa
;
15572 start_label
= fde
->dw_fde_begin
;
15574 /* ??? Bald assumption that the CIE opcode list does not contain
15575 advance opcodes. */
15576 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15577 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15579 last_cfa
= next_cfa
;
15580 last_label
= start_label
;
15582 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15584 /* If the first partition contained no CFI adjustments, the
15585 CIE opcodes apply to the whole first partition. */
15586 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15587 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15588 list_tail
=&(*list_tail
)->dw_loc_next
;
15589 start_label
= last_label
= fde
->dw_fde_second_begin
;
15592 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15594 switch (cfi
->dw_cfi_opc
)
15596 case DW_CFA_set_loc
:
15597 case DW_CFA_advance_loc1
:
15598 case DW_CFA_advance_loc2
:
15599 case DW_CFA_advance_loc4
:
15600 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15602 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15603 start_label
, last_label
, section
);
15605 list_tail
= &(*list_tail
)->dw_loc_next
;
15606 last_cfa
= next_cfa
;
15607 start_label
= last_label
;
15609 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15612 case DW_CFA_advance_loc
:
15613 /* The encoding is complex enough that we should never emit this. */
15614 gcc_unreachable ();
15617 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15620 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15622 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15624 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15625 start_label
, last_label
, section
);
15627 list_tail
= &(*list_tail
)->dw_loc_next
;
15628 last_cfa
= next_cfa
;
15629 start_label
= last_label
;
15631 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15632 start_label
, fde
->dw_fde_end
, section
);
15633 list_tail
= &(*list_tail
)->dw_loc_next
;
15634 start_label
= last_label
= fde
->dw_fde_second_begin
;
15638 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15640 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15641 start_label
, last_label
, section
);
15642 list_tail
= &(*list_tail
)->dw_loc_next
;
15643 start_label
= last_label
;
15646 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15648 fde
->dw_fde_second_begin
15649 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15652 if (list
&& list
->dw_loc_next
)
15658 /* Compute a displacement from the "steady-state frame pointer" to the
15659 frame base (often the same as the CFA), and store it in
15660 frame_pointer_fb_offset. OFFSET is added to the displacement
15661 before the latter is negated. */
15664 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15668 #ifdef FRAME_POINTER_CFA_OFFSET
15669 reg
= frame_pointer_rtx
;
15670 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15672 reg
= arg_pointer_rtx
;
15673 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15676 elim
= (ira_use_lra_p
15677 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15678 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15679 if (GET_CODE (elim
) == PLUS
)
15681 offset
+= INTVAL (XEXP (elim
, 1));
15682 elim
= XEXP (elim
, 0);
15685 frame_pointer_fb_offset
= -offset
;
15687 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15688 in which to eliminate. This is because it's stack pointer isn't
15689 directly accessible as a register within the ISA. To work around
15690 this, assume that while we cannot provide a proper value for
15691 frame_pointer_fb_offset, we won't need one either. */
15692 frame_pointer_fb_offset_valid
15693 = ((SUPPORTS_STACK_ALIGNMENT
15694 && (elim
== hard_frame_pointer_rtx
15695 || elim
== stack_pointer_rtx
))
15696 || elim
== (frame_pointer_needed
15697 ? hard_frame_pointer_rtx
15698 : stack_pointer_rtx
));
15701 /* Generate a DW_AT_name attribute given some string value to be included as
15702 the value of the attribute. */
15705 add_name_attribute (dw_die_ref die
, const char *name_string
)
15707 if (name_string
!= NULL
&& *name_string
!= 0)
15709 if (demangle_name_func
)
15710 name_string
= (*demangle_name_func
) (name_string
);
15712 add_AT_string (die
, DW_AT_name
, name_string
);
15716 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15717 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15718 of TYPE accordingly.
15720 ??? This is a temporary measure until after we're able to generate
15721 regular DWARF for the complex Ada type system. */
15724 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15725 dw_die_ref context_die
)
15728 dw_die_ref dtype_die
;
15730 if (!lang_hooks
.types
.descriptive_type
)
15733 dtype
= lang_hooks
.types
.descriptive_type (type
);
15737 dtype_die
= lookup_type_die (dtype
);
15740 gen_type_die (dtype
, context_die
);
15741 dtype_die
= lookup_type_die (dtype
);
15742 gcc_assert (dtype_die
);
15745 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15748 /* Generate a DW_AT_comp_dir attribute for DIE. */
15751 add_comp_dir_attribute (dw_die_ref die
)
15753 const char *wd
= get_src_pwd ();
15759 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15763 wdlen
= strlen (wd
);
15764 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15766 wd1
[wdlen
] = DIR_SEPARATOR
;
15767 wd1
[wdlen
+ 1] = 0;
15771 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15774 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15778 lower_bound_default (void)
15780 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15785 case DW_LANG_C_plus_plus
:
15787 case DW_LANG_ObjC_plus_plus
:
15790 case DW_LANG_Fortran77
:
15791 case DW_LANG_Fortran90
:
15792 case DW_LANG_Fortran95
:
15796 case DW_LANG_Python
:
15797 return dwarf_version
>= 4 ? 0 : -1;
15798 case DW_LANG_Ada95
:
15799 case DW_LANG_Ada83
:
15800 case DW_LANG_Cobol74
:
15801 case DW_LANG_Cobol85
:
15802 case DW_LANG_Pascal83
:
15803 case DW_LANG_Modula2
:
15805 return dwarf_version
>= 4 ? 1 : -1;
15811 /* Given a tree node describing an array bound (either lower or upper) output
15812 a representation for that bound. */
15815 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15817 switch (TREE_CODE (bound
))
15822 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15825 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15828 /* Use the default if possible. */
15829 if (bound_attr
== DW_AT_lower_bound
15830 && host_integerp (bound
, 0)
15831 && (dflt
= lower_bound_default ()) != -1
15832 && tree_low_cst (bound
, 0) == dflt
)
15835 /* Otherwise represent the bound as an unsigned value with the
15836 precision of its type. The precision and signedness of the
15837 type will be necessary to re-interpret it unambiguously. */
15838 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15840 unsigned HOST_WIDE_INT mask
15841 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15842 add_AT_unsigned (subrange_die
, bound_attr
,
15843 TREE_INT_CST_LOW (bound
) & mask
);
15845 else if (prec
== HOST_BITS_PER_WIDE_INT
15846 || TREE_INT_CST_HIGH (bound
) == 0)
15847 add_AT_unsigned (subrange_die
, bound_attr
,
15848 TREE_INT_CST_LOW (bound
));
15850 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15851 TREE_INT_CST_LOW (bound
));
15856 case VIEW_CONVERT_EXPR
:
15857 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15867 dw_die_ref decl_die
= lookup_decl_die (bound
);
15869 /* ??? Can this happen, or should the variable have been bound
15870 first? Probably it can, since I imagine that we try to create
15871 the types of parameters in the order in which they exist in
15872 the list, and won't have created a forward reference to a
15873 later parameter. */
15874 if (decl_die
!= NULL
)
15876 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15884 /* Otherwise try to create a stack operation procedure to
15885 evaluate the value of the array bound. */
15887 dw_die_ref ctx
, decl_die
;
15888 dw_loc_list_ref list
;
15890 list
= loc_list_from_tree (bound
, 2);
15891 if (list
== NULL
|| single_element_loc_list_p (list
))
15893 /* If DW_AT_*bound is not a reference nor constant, it is
15894 a DWARF expression rather than location description.
15895 For that loc_list_from_tree (bound, 0) is needed.
15896 If that fails to give a single element list,
15897 fall back to outputting this as a reference anyway. */
15898 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15899 if (list2
&& single_element_loc_list_p (list2
))
15901 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15908 if (current_function_decl
== 0)
15909 ctx
= comp_unit_die ();
15911 ctx
= lookup_decl_die (current_function_decl
);
15913 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15914 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15915 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15916 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15917 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15923 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15924 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15925 Note that the block of subscript information for an array type also
15926 includes information about the element type of the given array type. */
15929 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15931 unsigned dimension_number
;
15933 dw_die_ref subrange_die
;
15935 for (dimension_number
= 0;
15936 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15937 type
= TREE_TYPE (type
), dimension_number
++)
15939 tree domain
= TYPE_DOMAIN (type
);
15941 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15944 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15945 and (in GNU C only) variable bounds. Handle all three forms
15947 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15950 /* We have an array type with specified bounds. */
15951 lower
= TYPE_MIN_VALUE (domain
);
15952 upper
= TYPE_MAX_VALUE (domain
);
15954 /* Define the index type. */
15955 if (TREE_TYPE (domain
))
15957 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15958 TREE_TYPE field. We can't emit debug info for this
15959 because it is an unnamed integral type. */
15960 if (TREE_CODE (domain
) == INTEGER_TYPE
15961 && TYPE_NAME (domain
) == NULL_TREE
15962 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15963 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15966 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15970 /* ??? If upper is NULL, the array has unspecified length,
15971 but it does have a lower bound. This happens with Fortran
15973 Since the debugger is definitely going to need to know N
15974 to produce useful results, go ahead and output the lower
15975 bound solo, and hope the debugger can cope. */
15977 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15979 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15982 /* Otherwise we have an array type with an unspecified length. The
15983 DWARF-2 spec does not say how to handle this; let's just leave out the
15989 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
15991 dw_die_ref decl_die
;
15994 switch (TREE_CODE (tree_node
))
15999 case ENUMERAL_TYPE
:
16002 case QUAL_UNION_TYPE
:
16003 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16004 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16006 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16009 size
= int_size_in_bytes (tree_node
);
16012 /* For a data member of a struct or union, the DW_AT_byte_size is
16013 generally given as the number of bytes normally allocated for an
16014 object of the *declared* type of the member itself. This is true
16015 even for bit-fields. */
16016 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16019 gcc_unreachable ();
16022 /* Note that `size' might be -1 when we get to this point. If it is, that
16023 indicates that the byte size of the entity in question is variable. We
16024 have no good way of expressing this fact in Dwarf at the present time,
16025 so just let the -1 pass on through. */
16026 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16029 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16030 which specifies the distance in bits from the highest order bit of the
16031 "containing object" for the bit-field to the highest order bit of the
16034 For any given bit-field, the "containing object" is a hypothetical object
16035 (of some integral or enum type) within which the given bit-field lives. The
16036 type of this hypothetical "containing object" is always the same as the
16037 declared type of the individual bit-field itself. The determination of the
16038 exact location of the "containing object" for a bit-field is rather
16039 complicated. It's handled by the `field_byte_offset' function (above).
16041 Note that it is the size (in bytes) of the hypothetical "containing object"
16042 which will be given in the DW_AT_byte_size attribute for this bit-field.
16043 (See `byte_size_attribute' above). */
16046 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16048 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16049 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16050 HOST_WIDE_INT bitpos_int
;
16051 HOST_WIDE_INT highest_order_object_bit_offset
;
16052 HOST_WIDE_INT highest_order_field_bit_offset
;
16053 HOST_WIDE_INT bit_offset
;
16055 /* Must be a field and a bit field. */
16056 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16058 /* We can't yet handle bit-fields whose offsets are variable, so if we
16059 encounter such things, just return without generating any attribute
16060 whatsoever. Likewise for variable or too large size. */
16061 if (! host_integerp (bit_position (decl
), 0)
16062 || ! host_integerp (DECL_SIZE (decl
), 1))
16065 bitpos_int
= int_bit_position (decl
);
16067 /* Note that the bit offset is always the distance (in bits) from the
16068 highest-order bit of the "containing object" to the highest-order bit of
16069 the bit-field itself. Since the "high-order end" of any object or field
16070 is different on big-endian and little-endian machines, the computation
16071 below must take account of these differences. */
16072 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16073 highest_order_field_bit_offset
= bitpos_int
;
16075 if (! BYTES_BIG_ENDIAN
)
16077 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16078 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16082 = (! BYTES_BIG_ENDIAN
16083 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16084 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16086 if (bit_offset
< 0)
16087 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16089 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16092 /* For a FIELD_DECL node which represents a bit field, output an attribute
16093 which specifies the length in bits of the given field. */
16096 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16098 /* Must be a field and a bit field. */
16099 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16100 && DECL_BIT_FIELD_TYPE (decl
));
16102 if (host_integerp (DECL_SIZE (decl
), 1))
16103 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16106 /* If the compiled language is ANSI C, then add a 'prototyped'
16107 attribute, if arg types are given for the parameters of a function. */
16110 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16112 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16113 && prototype_p (func_type
))
16114 add_AT_flag (die
, DW_AT_prototyped
, 1);
16117 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16118 by looking in either the type declaration or object declaration
16121 static inline dw_die_ref
16122 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16124 dw_die_ref origin_die
= NULL
;
16126 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16128 /* We may have gotten separated from the block for the inlined
16129 function, if we're in an exception handler or some such; make
16130 sure that the abstract function has been written out.
16132 Doing this for nested functions is wrong, however; functions are
16133 distinct units, and our context might not even be inline. */
16137 fn
= TYPE_STUB_DECL (fn
);
16139 fn
= decl_function_context (fn
);
16141 dwarf2out_abstract_function (fn
);
16144 if (DECL_P (origin
))
16145 origin_die
= lookup_decl_die (origin
);
16146 else if (TYPE_P (origin
))
16147 origin_die
= lookup_type_die (origin
);
16149 /* XXX: Functions that are never lowered don't always have correct block
16150 trees (in the case of java, they simply have no block tree, in some other
16151 languages). For these functions, there is nothing we can really do to
16152 output correct debug info for inlined functions in all cases. Rather
16153 than die, we'll just produce deficient debug info now, in that we will
16154 have variables without a proper abstract origin. In the future, when all
16155 functions are lowered, we should re-add a gcc_assert (origin_die)
16159 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16163 /* We do not currently support the pure_virtual attribute. */
16166 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16168 if (DECL_VINDEX (func_decl
))
16170 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16172 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16173 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16174 new_loc_descr (DW_OP_constu
,
16175 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16178 /* GNU extension: Record what type this method came from originally. */
16179 if (debug_info_level
> DINFO_LEVEL_TERSE
16180 && DECL_CONTEXT (func_decl
))
16181 add_AT_die_ref (die
, DW_AT_containing_type
,
16182 lookup_type_die (DECL_CONTEXT (func_decl
)));
16186 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16187 given decl. This used to be a vendor extension until after DWARF 4
16188 standardized it. */
16191 add_linkage_attr (dw_die_ref die
, tree decl
)
16193 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16195 /* Mimic what assemble_name_raw does with a leading '*'. */
16196 if (name
[0] == '*')
16199 if (dwarf_version
>= 4)
16200 add_AT_string (die
, DW_AT_linkage_name
, name
);
16202 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16205 /* Add source coordinate attributes for the given decl. */
16208 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16210 expanded_location s
;
16212 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16214 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16215 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16216 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16219 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16222 add_linkage_name (dw_die_ref die
, tree decl
)
16224 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16225 && TREE_PUBLIC (decl
)
16226 && !DECL_ABSTRACT (decl
)
16227 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16228 && die
->die_tag
!= DW_TAG_member
)
16230 /* Defer until we have an assembler name set. */
16231 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16233 limbo_die_node
*asm_name
;
16235 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16236 asm_name
->die
= die
;
16237 asm_name
->created_for
= decl
;
16238 asm_name
->next
= deferred_asm_name
;
16239 deferred_asm_name
= asm_name
;
16241 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16242 add_linkage_attr (die
, decl
);
16246 /* Add a DW_AT_name attribute and source coordinate attribute for the
16247 given decl, but only if it actually has a name. */
16250 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16254 decl_name
= DECL_NAME (decl
);
16255 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16257 const char *name
= dwarf2_name (decl
, 0);
16259 add_name_attribute (die
, name
);
16260 if (! DECL_ARTIFICIAL (decl
))
16261 add_src_coords_attributes (die
, decl
);
16263 add_linkage_name (die
, decl
);
16266 #ifdef VMS_DEBUGGING_INFO
16267 /* Get the function's name, as described by its RTL. This may be different
16268 from the DECL_NAME name used in the source file. */
16269 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16271 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16272 XEXP (DECL_RTL (decl
), 0), false);
16273 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16275 #endif /* VMS_DEBUGGING_INFO */
16278 #ifdef VMS_DEBUGGING_INFO
16279 /* Output the debug main pointer die for VMS */
16282 dwarf2out_vms_debug_main_pointer (void)
16284 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16287 /* Allocate the VMS debug main subprogram die. */
16288 die
= ggc_alloc_cleared_die_node ();
16289 die
->die_tag
= DW_TAG_subprogram
;
16290 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16291 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16292 current_function_funcdef_no
);
16293 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16295 /* Make it the first child of comp_unit_die (). */
16296 die
->die_parent
= comp_unit_die ();
16297 if (comp_unit_die ()->die_child
)
16299 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16300 comp_unit_die ()->die_child
->die_sib
= die
;
16304 die
->die_sib
= die
;
16305 comp_unit_die ()->die_child
= die
;
16308 #endif /* VMS_DEBUGGING_INFO */
16310 /* Push a new declaration scope. */
16313 push_decl_scope (tree scope
)
16315 vec_safe_push (decl_scope_table
, scope
);
16318 /* Pop a declaration scope. */
16321 pop_decl_scope (void)
16323 decl_scope_table
->pop ();
16326 /* walk_tree helper function for uses_local_type, below. */
16329 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16332 *walk_subtrees
= 0;
16335 tree name
= TYPE_NAME (*tp
);
16336 if (name
&& DECL_P (name
) && decl_function_context (name
))
16342 /* If TYPE involves a function-local type (including a local typedef to a
16343 non-local type), returns that type; otherwise returns NULL_TREE. */
16346 uses_local_type (tree type
)
16348 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16352 /* Return the DIE for the scope that immediately contains this type.
16353 Non-named types that do not involve a function-local type get global
16354 scope. Named types nested in namespaces or other types get their
16355 containing scope. All other types (i.e. function-local named types) get
16356 the current active scope. */
16359 scope_die_for (tree t
, dw_die_ref context_die
)
16361 dw_die_ref scope_die
= NULL
;
16362 tree containing_scope
;
16364 /* Non-types always go in the current scope. */
16365 gcc_assert (TYPE_P (t
));
16367 /* Use the scope of the typedef, rather than the scope of the type
16369 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16370 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16372 containing_scope
= TYPE_CONTEXT (t
);
16374 /* Use the containing namespace if there is one. */
16375 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16377 if (context_die
== lookup_decl_die (containing_scope
))
16379 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16380 context_die
= get_context_die (containing_scope
);
16382 containing_scope
= NULL_TREE
;
16385 /* Ignore function type "scopes" from the C frontend. They mean that
16386 a tagged type is local to a parmlist of a function declarator, but
16387 that isn't useful to DWARF. */
16388 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16389 containing_scope
= NULL_TREE
;
16391 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16393 /* If T uses a local type keep it local as well, to avoid references
16394 to function-local DIEs from outside the function. */
16395 if (current_function_decl
&& uses_local_type (t
))
16396 scope_die
= context_die
;
16398 scope_die
= comp_unit_die ();
16400 else if (TYPE_P (containing_scope
))
16402 /* For types, we can just look up the appropriate DIE. */
16403 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16404 scope_die
= get_context_die (containing_scope
);
16407 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16408 if (scope_die
== NULL
)
16409 scope_die
= comp_unit_die ();
16413 scope_die
= context_die
;
16418 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16421 local_scope_p (dw_die_ref context_die
)
16423 for (; context_die
; context_die
= context_die
->die_parent
)
16424 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16425 || context_die
->die_tag
== DW_TAG_subprogram
)
16431 /* Returns nonzero if CONTEXT_DIE is a class. */
16434 class_scope_p (dw_die_ref context_die
)
16436 return (context_die
16437 && (context_die
->die_tag
== DW_TAG_structure_type
16438 || context_die
->die_tag
== DW_TAG_class_type
16439 || context_die
->die_tag
== DW_TAG_interface_type
16440 || context_die
->die_tag
== DW_TAG_union_type
));
16443 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16444 whether or not to treat a DIE in this context as a declaration. */
16447 class_or_namespace_scope_p (dw_die_ref context_die
)
16449 return (class_scope_p (context_die
)
16450 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16453 /* Many forms of DIEs require a "type description" attribute. This
16454 routine locates the proper "type descriptor" die for the type given
16455 by 'type', and adds a DW_AT_type attribute below the given die. */
16458 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16459 int decl_volatile
, dw_die_ref context_die
)
16461 enum tree_code code
= TREE_CODE (type
);
16462 dw_die_ref type_die
= NULL
;
16464 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16465 or fixed-point type, use the inner type. This is because we have no
16466 support for unnamed types in base_type_die. This can happen if this is
16467 an Ada subrange type. Correct solution is emit a subrange type die. */
16468 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16469 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16470 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16472 if (code
== ERROR_MARK
16473 /* Handle a special case. For functions whose return type is void, we
16474 generate *no* type attribute. (Note that no object may have type
16475 `void', so this only applies to function return types). */
16476 || code
== VOID_TYPE
)
16479 type_die
= modified_type_die (type
,
16480 decl_const
|| TYPE_READONLY (type
),
16481 decl_volatile
|| TYPE_VOLATILE (type
),
16484 if (type_die
!= NULL
)
16485 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16488 /* Given an object die, add the calling convention attribute for the
16489 function call type. */
16491 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16493 enum dwarf_calling_convention value
= DW_CC_normal
;
16495 value
= ((enum dwarf_calling_convention
)
16496 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16499 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16501 /* DWARF 2 doesn't provide a way to identify a program's source-level
16502 entry point. DW_AT_calling_convention attributes are only meant
16503 to describe functions' calling conventions. However, lacking a
16504 better way to signal the Fortran main program, we used this for
16505 a long time, following existing custom. Now, DWARF 4 has
16506 DW_AT_main_subprogram, which we add below, but some tools still
16507 rely on the old way, which we thus keep. */
16508 value
= DW_CC_program
;
16510 if (dwarf_version
>= 4 || !dwarf_strict
)
16511 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16514 /* Only add the attribute if the backend requests it, and
16515 is not DW_CC_normal. */
16516 if (value
&& (value
!= DW_CC_normal
))
16517 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16520 /* Given a tree pointer to a struct, class, union, or enum type node, return
16521 a pointer to the (string) tag name for the given type, or zero if the type
16522 was declared without a tag. */
16524 static const char *
16525 type_tag (const_tree type
)
16527 const char *name
= 0;
16529 if (TYPE_NAME (type
) != 0)
16533 /* Find the IDENTIFIER_NODE for the type name. */
16534 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16535 && !TYPE_NAMELESS (type
))
16536 t
= TYPE_NAME (type
);
16538 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16539 a TYPE_DECL node, regardless of whether or not a `typedef' was
16541 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16542 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16544 /* We want to be extra verbose. Don't call dwarf_name if
16545 DECL_NAME isn't set. The default hook for decl_printable_name
16546 doesn't like that, and in this context it's correct to return
16547 0, instead of "<anonymous>" or the like. */
16548 if (DECL_NAME (TYPE_NAME (type
))
16549 && !DECL_NAMELESS (TYPE_NAME (type
)))
16550 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16553 /* Now get the name as a string, or invent one. */
16554 if (!name
&& t
!= 0)
16555 name
= IDENTIFIER_POINTER (t
);
16558 return (name
== 0 || *name
== '\0') ? 0 : name
;
16561 /* Return the type associated with a data member, make a special check
16562 for bit field types. */
16565 member_declared_type (const_tree member
)
16567 return (DECL_BIT_FIELD_TYPE (member
)
16568 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16571 /* Get the decl's label, as described by its RTL. This may be different
16572 from the DECL_NAME name used in the source file. */
16575 static const char *
16576 decl_start_label (tree decl
)
16579 const char *fnname
;
16581 x
= DECL_RTL (decl
);
16582 gcc_assert (MEM_P (x
));
16585 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16587 fnname
= XSTR (x
, 0);
16592 /* These routines generate the internal representation of the DIE's for
16593 the compilation unit. Debugging information is collected by walking
16594 the declaration trees passed in from dwarf2out_decl(). */
16597 gen_array_type_die (tree type
, dw_die_ref context_die
)
16599 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16600 dw_die_ref array_die
;
16602 /* GNU compilers represent multidimensional array types as sequences of one
16603 dimensional array types whose element types are themselves array types.
16604 We sometimes squish that down to a single array_type DIE with multiple
16605 subscripts in the Dwarf debugging info. The draft Dwarf specification
16606 say that we are allowed to do this kind of compression in C, because
16607 there is no difference between an array of arrays and a multidimensional
16608 array. We don't do this for Ada to remain as close as possible to the
16609 actual representation, which is especially important against the language
16610 flexibilty wrt arrays of variable size. */
16612 bool collapse_nested_arrays
= !is_ada ();
16615 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16616 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16617 if (TYPE_STRING_FLAG (type
)
16618 && TREE_CODE (type
) == ARRAY_TYPE
16620 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16622 HOST_WIDE_INT size
;
16624 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16625 add_name_attribute (array_die
, type_tag (type
));
16626 equate_type_number_to_die (type
, array_die
);
16627 size
= int_size_in_bytes (type
);
16629 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16630 else if (TYPE_DOMAIN (type
) != NULL_TREE
16631 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16632 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16634 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16635 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16637 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16638 if (loc
&& size
> 0)
16640 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16641 if (size
!= DWARF2_ADDR_SIZE
)
16642 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16648 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16649 add_name_attribute (array_die
, type_tag (type
));
16650 equate_type_number_to_die (type
, array_die
);
16652 if (TREE_CODE (type
) == VECTOR_TYPE
)
16653 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16655 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16657 && TREE_CODE (type
) == ARRAY_TYPE
16658 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16659 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16660 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16663 /* We default the array ordering. SDB will probably do
16664 the right things even if DW_AT_ordering is not present. It's not even
16665 an issue until we start to get into multidimensional arrays anyway. If
16666 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16667 then we'll have to put the DW_AT_ordering attribute back in. (But if
16668 and when we find out that we need to put these in, we will only do so
16669 for multidimensional arrays. */
16670 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16673 if (TREE_CODE (type
) == VECTOR_TYPE
)
16675 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16676 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16677 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16678 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16679 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16682 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16684 /* Add representation of the type of the elements of this array type and
16685 emit the corresponding DIE if we haven't done it already. */
16686 element_type
= TREE_TYPE (type
);
16687 if (collapse_nested_arrays
)
16688 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16690 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16692 element_type
= TREE_TYPE (element_type
);
16695 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16697 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16698 if (TYPE_ARTIFICIAL (type
))
16699 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16701 if (get_AT (array_die
, DW_AT_name
))
16702 add_pubtype (type
, array_die
);
16705 static dw_loc_descr_ref
16706 descr_info_loc (tree val
, tree base_decl
)
16708 HOST_WIDE_INT size
;
16709 dw_loc_descr_ref loc
, loc2
;
16710 enum dwarf_location_atom op
;
16712 if (val
== base_decl
)
16713 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16715 switch (TREE_CODE (val
))
16718 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16720 return loc_descriptor_from_tree (val
, 0);
16722 if (host_integerp (val
, 0))
16723 return int_loc_descriptor (tree_low_cst (val
, 0));
16726 size
= int_size_in_bytes (TREE_TYPE (val
));
16729 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16732 if (size
== DWARF2_ADDR_SIZE
)
16733 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16735 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16737 case POINTER_PLUS_EXPR
:
16739 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16740 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16743 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16746 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16752 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16755 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16758 add_loc_descr (&loc
, loc2
);
16759 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16781 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16782 tree val
, tree base_decl
)
16784 dw_loc_descr_ref loc
;
16786 if (host_integerp (val
, 0))
16788 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16792 loc
= descr_info_loc (val
, base_decl
);
16796 add_AT_loc (die
, attr
, loc
);
16799 /* This routine generates DIE for array with hidden descriptor, details
16800 are filled into *info by a langhook. */
16803 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16804 dw_die_ref context_die
)
16806 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16807 dw_die_ref array_die
;
16810 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16811 add_name_attribute (array_die
, type_tag (type
));
16812 equate_type_number_to_die (type
, array_die
);
16814 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16816 && info
->ndimensions
>= 2)
16817 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16819 if (info
->data_location
)
16820 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16822 if (info
->associated
)
16823 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16825 if (info
->allocated
)
16826 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16829 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16831 dw_die_ref subrange_die
16832 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16834 if (info
->dimen
[dim
].lower_bound
)
16836 /* If it is the default value, omit it. */
16839 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16840 && (dflt
= lower_bound_default ()) != -1
16841 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16844 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16845 info
->dimen
[dim
].lower_bound
,
16848 if (info
->dimen
[dim
].upper_bound
)
16849 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16850 info
->dimen
[dim
].upper_bound
,
16852 if (info
->dimen
[dim
].stride
)
16853 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16854 info
->dimen
[dim
].stride
,
16858 gen_type_die (info
->element_type
, context_die
);
16859 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16861 if (get_AT (array_die
, DW_AT_name
))
16862 add_pubtype (type
, array_die
);
16867 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16869 tree origin
= decl_ultimate_origin (decl
);
16870 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16872 if (origin
!= NULL
)
16873 add_abstract_origin_attribute (decl_die
, origin
);
16876 add_name_and_src_coords_attributes (decl_die
, decl
);
16877 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16878 0, 0, context_die
);
16881 if (DECL_ABSTRACT (decl
))
16882 equate_decl_number_to_die (decl
, decl_die
);
16884 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16888 /* Walk through the list of incomplete types again, trying once more to
16889 emit full debugging info for them. */
16892 retry_incomplete_types (void)
16896 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
16897 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
16898 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
16901 /* Determine what tag to use for a record type. */
16903 static enum dwarf_tag
16904 record_type_tag (tree type
)
16906 if (! lang_hooks
.types
.classify_record
)
16907 return DW_TAG_structure_type
;
16909 switch (lang_hooks
.types
.classify_record (type
))
16911 case RECORD_IS_STRUCT
:
16912 return DW_TAG_structure_type
;
16914 case RECORD_IS_CLASS
:
16915 return DW_TAG_class_type
;
16917 case RECORD_IS_INTERFACE
:
16918 if (dwarf_version
>= 3 || !dwarf_strict
)
16919 return DW_TAG_interface_type
;
16920 return DW_TAG_structure_type
;
16923 gcc_unreachable ();
16927 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16928 include all of the information about the enumeration values also. Each
16929 enumerated type name/value is listed as a child of the enumerated type
16933 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16935 dw_die_ref type_die
= lookup_type_die (type
);
16937 if (type_die
== NULL
)
16939 type_die
= new_die (DW_TAG_enumeration_type
,
16940 scope_die_for (type
, context_die
), type
);
16941 equate_type_number_to_die (type
, type_die
);
16942 add_name_attribute (type_die
, type_tag (type
));
16943 if (dwarf_version
>= 4 || !dwarf_strict
)
16945 if (ENUM_IS_SCOPED (type
))
16946 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16947 if (ENUM_IS_OPAQUE (type
))
16948 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16951 else if (! TYPE_SIZE (type
))
16954 remove_AT (type_die
, DW_AT_declaration
);
16956 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16957 given enum type is incomplete, do not generate the DW_AT_byte_size
16958 attribute or the DW_AT_element_list attribute. */
16959 if (TYPE_SIZE (type
))
16963 TREE_ASM_WRITTEN (type
) = 1;
16964 add_byte_size_attribute (type_die
, type
);
16965 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16967 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16968 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16971 /* If the first reference to this type was as the return type of an
16972 inline function, then it may not have a parent. Fix this now. */
16973 if (type_die
->die_parent
== NULL
)
16974 add_child_die (scope_die_for (type
, context_die
), type_die
);
16976 for (link
= TYPE_VALUES (type
);
16977 link
!= NULL
; link
= TREE_CHAIN (link
))
16979 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16980 tree value
= TREE_VALUE (link
);
16982 add_name_attribute (enum_die
,
16983 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16985 if (TREE_CODE (value
) == CONST_DECL
)
16986 value
= DECL_INITIAL (value
);
16988 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
16989 /* DWARF2 does not provide a way of indicating whether or
16990 not enumeration constants are signed or unsigned. GDB
16991 always assumes the values are signed, so we output all
16992 values as if they were signed. That means that
16993 enumeration constants with very large unsigned values
16994 will appear to have negative values in the debugger. */
16995 add_AT_int (enum_die
, DW_AT_const_value
,
16996 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
16999 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17000 if (TYPE_ARTIFICIAL (type
))
17001 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17004 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17006 add_pubtype (type
, type_die
);
17011 /* Generate a DIE to represent either a real live formal parameter decl or to
17012 represent just the type of some formal parameter position in some function
17015 Note that this routine is a bit unusual because its argument may be a
17016 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17017 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17018 node. If it's the former then this function is being called to output a
17019 DIE to represent a formal parameter object (or some inlining thereof). If
17020 it's the latter, then this function is only being called to output a
17021 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17022 argument type of some subprogram type.
17023 If EMIT_NAME_P is true, name and source coordinate attributes
17027 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17028 dw_die_ref context_die
)
17030 tree node_or_origin
= node
? node
: origin
;
17031 tree ultimate_origin
;
17032 dw_die_ref parm_die
17033 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17035 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17037 case tcc_declaration
:
17038 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17039 if (node
|| ultimate_origin
)
17040 origin
= ultimate_origin
;
17041 if (origin
!= NULL
)
17042 add_abstract_origin_attribute (parm_die
, origin
);
17043 else if (emit_name_p
)
17044 add_name_and_src_coords_attributes (parm_die
, node
);
17046 || (! DECL_ABSTRACT (node_or_origin
)
17047 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17048 decl_function_context
17049 (node_or_origin
))))
17051 tree type
= TREE_TYPE (node_or_origin
);
17052 if (decl_by_reference_p (node_or_origin
))
17053 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17056 add_type_attribute (parm_die
, type
,
17057 TREE_READONLY (node_or_origin
),
17058 TREE_THIS_VOLATILE (node_or_origin
),
17061 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17062 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17064 if (node
&& node
!= origin
)
17065 equate_decl_number_to_die (node
, parm_die
);
17066 if (! DECL_ABSTRACT (node_or_origin
))
17067 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17068 node
== NULL
, DW_AT_location
);
17073 /* We were called with some kind of a ..._TYPE node. */
17074 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17078 gcc_unreachable ();
17084 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17085 children DW_TAG_formal_parameter DIEs representing the arguments of the
17088 PARM_PACK must be a function parameter pack.
17089 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17090 must point to the subsequent arguments of the function PACK_ARG belongs to.
17091 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17092 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17093 following the last one for which a DIE was generated. */
17096 gen_formal_parameter_pack_die (tree parm_pack
,
17098 dw_die_ref subr_die
,
17102 dw_die_ref parm_pack_die
;
17104 gcc_assert (parm_pack
17105 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17108 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17109 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17111 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17113 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17116 gen_formal_parameter_die (arg
, NULL
,
17117 false /* Don't emit name attribute. */,
17122 return parm_pack_die
;
17125 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17126 at the end of an (ANSI prototyped) formal parameters list. */
17129 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17131 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17134 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17135 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17136 parameters as specified in some function type specification (except for
17137 those which appear as part of a function *definition*). */
17140 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17143 tree formal_type
= NULL
;
17144 tree first_parm_type
;
17147 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17149 arg
= DECL_ARGUMENTS (function_or_method_type
);
17150 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17155 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17157 /* Make our first pass over the list of formal parameter types and output a
17158 DW_TAG_formal_parameter DIE for each one. */
17159 for (link
= first_parm_type
; link
; )
17161 dw_die_ref parm_die
;
17163 formal_type
= TREE_VALUE (link
);
17164 if (formal_type
== void_type_node
)
17167 /* Output a (nameless) DIE to represent the formal parameter itself. */
17168 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17169 true /* Emit name attribute. */,
17171 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17172 && link
== first_parm_type
)
17174 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17175 if (dwarf_version
>= 3 || !dwarf_strict
)
17176 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17178 else if (arg
&& DECL_ARTIFICIAL (arg
))
17179 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17181 link
= TREE_CHAIN (link
);
17183 arg
= DECL_CHAIN (arg
);
17186 /* If this function type has an ellipsis, add a
17187 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17188 if (formal_type
!= void_type_node
)
17189 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17191 /* Make our second (and final) pass over the list of formal parameter types
17192 and output DIEs to represent those types (as necessary). */
17193 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17194 link
&& TREE_VALUE (link
);
17195 link
= TREE_CHAIN (link
))
17196 gen_type_die (TREE_VALUE (link
), context_die
);
17199 /* We want to generate the DIE for TYPE so that we can generate the
17200 die for MEMBER, which has been defined; we will need to refer back
17201 to the member declaration nested within TYPE. If we're trying to
17202 generate minimal debug info for TYPE, processing TYPE won't do the
17203 trick; we need to attach the member declaration by hand. */
17206 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17208 gen_type_die (type
, context_die
);
17210 /* If we're trying to avoid duplicate debug info, we may not have
17211 emitted the member decl for this function. Emit it now. */
17212 if (TYPE_STUB_DECL (type
)
17213 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17214 && ! lookup_decl_die (member
))
17216 dw_die_ref type_die
;
17217 gcc_assert (!decl_ultimate_origin (member
));
17219 push_decl_scope (type
);
17220 type_die
= lookup_type_die_strip_naming_typedef (type
);
17221 if (TREE_CODE (member
) == FUNCTION_DECL
)
17222 gen_subprogram_die (member
, type_die
);
17223 else if (TREE_CODE (member
) == FIELD_DECL
)
17225 /* Ignore the nameless fields that are used to skip bits but handle
17226 C++ anonymous unions and structs. */
17227 if (DECL_NAME (member
) != NULL_TREE
17228 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17229 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17231 gen_type_die (member_declared_type (member
), type_die
);
17232 gen_field_die (member
, type_die
);
17236 gen_variable_die (member
, NULL_TREE
, type_die
);
17242 /* Forward declare these functions, because they are mutually recursive
17243 with their set_block_* pairing functions. */
17244 static void set_decl_origin_self (tree
);
17245 static void set_decl_abstract_flags (tree
, int);
17247 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17248 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17249 that it points to the node itself, thus indicating that the node is its
17250 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17251 the given node is NULL, recursively descend the decl/block tree which
17252 it is the root of, and for each other ..._DECL or BLOCK node contained
17253 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17254 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17255 values to point to themselves. */
17258 set_block_origin_self (tree stmt
)
17260 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17262 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17267 for (local_decl
= BLOCK_VARS (stmt
);
17268 local_decl
!= NULL_TREE
;
17269 local_decl
= DECL_CHAIN (local_decl
))
17270 if (! DECL_EXTERNAL (local_decl
))
17271 set_decl_origin_self (local_decl
); /* Potential recursion. */
17277 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17278 subblock
!= NULL_TREE
;
17279 subblock
= BLOCK_CHAIN (subblock
))
17280 set_block_origin_self (subblock
); /* Recurse. */
17285 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17286 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17287 node to so that it points to the node itself, thus indicating that the
17288 node represents its own (abstract) origin. Additionally, if the
17289 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17290 the decl/block tree of which the given node is the root of, and for
17291 each other ..._DECL or BLOCK node contained therein whose
17292 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17293 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17294 point to themselves. */
17297 set_decl_origin_self (tree decl
)
17299 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17301 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17302 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17306 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17307 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17308 if (DECL_INITIAL (decl
) != NULL_TREE
17309 && DECL_INITIAL (decl
) != error_mark_node
)
17310 set_block_origin_self (DECL_INITIAL (decl
));
17315 /* Given a pointer to some BLOCK node, and a boolean value to set the
17316 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17317 the given block, and for all local decls and all local sub-blocks
17318 (recursively) which are contained therein. */
17321 set_block_abstract_flags (tree stmt
, int setting
)
17327 BLOCK_ABSTRACT (stmt
) = setting
;
17329 for (local_decl
= BLOCK_VARS (stmt
);
17330 local_decl
!= NULL_TREE
;
17331 local_decl
= DECL_CHAIN (local_decl
))
17332 if (! DECL_EXTERNAL (local_decl
))
17333 set_decl_abstract_flags (local_decl
, setting
);
17335 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17337 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17338 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17339 || TREE_CODE (local_decl
) == PARM_DECL
)
17340 set_decl_abstract_flags (local_decl
, setting
);
17343 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17344 subblock
!= NULL_TREE
;
17345 subblock
= BLOCK_CHAIN (subblock
))
17346 set_block_abstract_flags (subblock
, setting
);
17349 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17350 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17351 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17352 set the abstract flags for all of the parameters, local vars, local
17353 blocks and sub-blocks (recursively) to the same setting. */
17356 set_decl_abstract_flags (tree decl
, int setting
)
17358 DECL_ABSTRACT (decl
) = setting
;
17359 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17363 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17364 DECL_ABSTRACT (arg
) = setting
;
17365 if (DECL_INITIAL (decl
) != NULL_TREE
17366 && DECL_INITIAL (decl
) != error_mark_node
)
17367 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17371 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17372 may later generate inlined and/or out-of-line instances of. */
17375 dwarf2out_abstract_function (tree decl
)
17377 dw_die_ref old_die
;
17381 htab_t old_decl_loc_table
;
17382 htab_t old_cached_dw_loc_list_table
;
17383 int old_call_site_count
, old_tail_call_site_count
;
17384 struct call_arg_loc_node
*old_call_arg_locations
;
17386 /* Make sure we have the actual abstract inline, not a clone. */
17387 decl
= DECL_ORIGIN (decl
);
17389 old_die
= lookup_decl_die (decl
);
17390 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17391 /* We've already generated the abstract instance. */
17394 /* We can be called while recursively when seeing block defining inlined subroutine
17395 DIE. Be sure to not clobber the outer location table nor use it or we would
17396 get locations in abstract instantces. */
17397 old_decl_loc_table
= decl_loc_table
;
17398 decl_loc_table
= NULL
;
17399 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17400 cached_dw_loc_list_table
= NULL
;
17401 old_call_arg_locations
= call_arg_locations
;
17402 call_arg_locations
= NULL
;
17403 old_call_site_count
= call_site_count
;
17404 call_site_count
= -1;
17405 old_tail_call_site_count
= tail_call_site_count
;
17406 tail_call_site_count
= -1;
17408 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17409 we don't get confused by DECL_ABSTRACT. */
17410 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17412 context
= decl_class_context (decl
);
17414 gen_type_die_for_member
17415 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17418 /* Pretend we've just finished compiling this function. */
17419 save_fn
= current_function_decl
;
17420 current_function_decl
= decl
;
17422 was_abstract
= DECL_ABSTRACT (decl
);
17423 set_decl_abstract_flags (decl
, 1);
17424 dwarf2out_decl (decl
);
17425 if (! was_abstract
)
17426 set_decl_abstract_flags (decl
, 0);
17428 current_function_decl
= save_fn
;
17429 decl_loc_table
= old_decl_loc_table
;
17430 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17431 call_arg_locations
= old_call_arg_locations
;
17432 call_site_count
= old_call_site_count
;
17433 tail_call_site_count
= old_tail_call_site_count
;
17436 /* Helper function of premark_used_types() which gets called through
17439 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17440 marked as unused by prune_unused_types. */
17443 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17448 type
= (tree
) *slot
;
17449 die
= lookup_type_die (type
);
17451 die
->die_perennial_p
= 1;
17455 /* Helper function of premark_types_used_by_global_vars which gets called
17456 through htab_traverse.
17458 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17459 marked as unused by prune_unused_types. The DIE of the type is marked
17460 only if the global variable using the type will actually be emitted. */
17463 premark_types_used_by_global_vars_helper (void **slot
,
17464 void *data ATTRIBUTE_UNUSED
)
17466 struct types_used_by_vars_entry
*entry
;
17469 entry
= (struct types_used_by_vars_entry
*) *slot
;
17470 gcc_assert (entry
->type
!= NULL
17471 && entry
->var_decl
!= NULL
);
17472 die
= lookup_type_die (entry
->type
);
17475 /* Ask cgraph if the global variable really is to be emitted.
17476 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17477 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17478 if (node
&& node
->analyzed
)
17480 die
->die_perennial_p
= 1;
17481 /* Keep the parent DIEs as well. */
17482 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17483 die
->die_perennial_p
= 1;
17489 /* Mark all members of used_types_hash as perennial. */
17492 premark_used_types (struct function
*fun
)
17494 if (fun
&& fun
->used_types_hash
)
17495 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17498 /* Mark all members of types_used_by_vars_entry as perennial. */
17501 premark_types_used_by_global_vars (void)
17503 if (types_used_by_vars_hash
)
17504 htab_traverse (types_used_by_vars_hash
,
17505 premark_types_used_by_global_vars_helper
, NULL
);
17508 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17509 for CA_LOC call arg loc node. */
17512 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17513 struct call_arg_loc_node
*ca_loc
)
17515 dw_die_ref stmt_die
= NULL
, die
;
17516 tree block
= ca_loc
->block
;
17519 && block
!= DECL_INITIAL (decl
)
17520 && TREE_CODE (block
) == BLOCK
)
17522 if (block_map
.length () > BLOCK_NUMBER (block
))
17523 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17526 block
= BLOCK_SUPERCONTEXT (block
);
17528 if (stmt_die
== NULL
)
17529 stmt_die
= subr_die
;
17530 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17531 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17532 if (ca_loc
->tail_call_p
)
17533 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17534 if (ca_loc
->symbol_ref
)
17536 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17538 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17540 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17545 /* Generate a DIE to represent a declared function (either file-scope or
17549 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17551 tree origin
= decl_ultimate_origin (decl
);
17552 dw_die_ref subr_die
;
17554 dw_die_ref old_die
= lookup_decl_die (decl
);
17555 int declaration
= (current_function_decl
!= decl
17556 || class_or_namespace_scope_p (context_die
));
17558 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17560 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17561 started to generate the abstract instance of an inline, decided to output
17562 its containing class, and proceeded to emit the declaration of the inline
17563 from the member list for the class. If so, DECLARATION takes priority;
17564 we'll get back to the abstract instance when done with the class. */
17566 /* The class-scope declaration DIE must be the primary DIE. */
17567 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17570 gcc_assert (!old_die
);
17573 /* Now that the C++ front end lazily declares artificial member fns, we
17574 might need to retrofit the declaration into its class. */
17575 if (!declaration
&& !origin
&& !old_die
17576 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17577 && !class_or_namespace_scope_p (context_die
)
17578 && debug_info_level
> DINFO_LEVEL_TERSE
)
17579 old_die
= force_decl_die (decl
);
17581 if (origin
!= NULL
)
17583 gcc_assert (!declaration
|| local_scope_p (context_die
));
17585 /* Fixup die_parent for the abstract instance of a nested
17586 inline function. */
17587 if (old_die
&& old_die
->die_parent
== NULL
)
17588 add_child_die (context_die
, old_die
);
17590 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17591 add_abstract_origin_attribute (subr_die
, origin
);
17592 /* This is where the actual code for a cloned function is.
17593 Let's emit linkage name attribute for it. This helps
17594 debuggers to e.g, set breakpoints into
17595 constructors/destructors when the user asks "break
17597 add_linkage_name (subr_die
, decl
);
17601 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17602 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17604 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17605 /* We can have a normal definition following an inline one in the
17606 case of redefinition of GNU C extern inlines.
17607 It seems reasonable to use AT_specification in this case. */
17608 && !get_AT (old_die
, DW_AT_inline
))
17610 /* Detect and ignore this case, where we are trying to output
17611 something we have already output. */
17615 /* If the definition comes from the same place as the declaration,
17616 maybe use the old DIE. We always want the DIE for this function
17617 that has the *_pc attributes to be under comp_unit_die so the
17618 debugger can find it. We also need to do this for abstract
17619 instances of inlines, since the spec requires the out-of-line copy
17620 to have the same parent. For local class methods, this doesn't
17621 apply; we just use the old DIE. */
17622 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17623 && (DECL_ARTIFICIAL (decl
)
17624 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17625 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17626 == (unsigned) s
.line
))))
17628 subr_die
= old_die
;
17630 /* Clear out the declaration attribute and the formal parameters.
17631 Do not remove all children, because it is possible that this
17632 declaration die was forced using force_decl_die(). In such
17633 cases die that forced declaration die (e.g. TAG_imported_module)
17634 is one of the children that we do not want to remove. */
17635 remove_AT (subr_die
, DW_AT_declaration
);
17636 remove_AT (subr_die
, DW_AT_object_pointer
);
17637 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17641 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17642 add_AT_specification (subr_die
, old_die
);
17643 add_pubname (decl
, subr_die
);
17644 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17645 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17646 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17647 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17652 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17654 if (TREE_PUBLIC (decl
))
17655 add_AT_flag (subr_die
, DW_AT_external
, 1);
17657 add_name_and_src_coords_attributes (subr_die
, decl
);
17658 add_pubname (decl
, subr_die
);
17659 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17661 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17662 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17663 0, 0, context_die
);
17666 add_pure_or_virtual_attribute (subr_die
, decl
);
17667 if (DECL_ARTIFICIAL (decl
))
17668 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17670 add_accessibility_attribute (subr_die
, decl
);
17675 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17677 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17679 /* If this is an explicit function declaration then generate
17680 a DW_AT_explicit attribute. */
17681 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17682 && (dwarf_version
>= 3 || !dwarf_strict
))
17683 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17685 /* The first time we see a member function, it is in the context of
17686 the class to which it belongs. We make sure of this by emitting
17687 the class first. The next time is the definition, which is
17688 handled above. The two may come from the same source text.
17690 Note that force_decl_die() forces function declaration die. It is
17691 later reused to represent definition. */
17692 equate_decl_number_to_die (decl
, subr_die
);
17695 else if (DECL_ABSTRACT (decl
))
17697 if (DECL_DECLARED_INLINE_P (decl
))
17699 if (cgraph_function_possibly_inlined_p (decl
))
17700 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17702 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17706 if (cgraph_function_possibly_inlined_p (decl
))
17707 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17709 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17712 if (DECL_DECLARED_INLINE_P (decl
)
17713 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17714 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17716 equate_decl_number_to_die (decl
, subr_die
);
17718 else if (!DECL_EXTERNAL (decl
))
17720 HOST_WIDE_INT cfa_fb_offset
;
17721 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17723 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17724 equate_decl_number_to_die (decl
, subr_die
);
17726 gcc_checking_assert (fun
);
17727 if (!flag_reorder_blocks_and_partition
)
17729 dw_fde_ref fde
= fun
->fde
;
17730 if (fde
->dw_fde_begin
)
17732 /* We have already generated the labels. */
17733 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17734 fde
->dw_fde_end
, false);
17738 /* Create start/end labels and add the range. */
17739 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17740 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17741 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17742 current_function_funcdef_no
);
17743 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17744 current_function_funcdef_no
);
17745 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17749 #if VMS_DEBUGGING_INFO
17750 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17751 Section 2.3 Prologue and Epilogue Attributes:
17752 When a breakpoint is set on entry to a function, it is generally
17753 desirable for execution to be suspended, not on the very first
17754 instruction of the function, but rather at a point after the
17755 function's frame has been set up, after any language defined local
17756 declaration processing has been completed, and before execution of
17757 the first statement of the function begins. Debuggers generally
17758 cannot properly determine where this point is. Similarly for a
17759 breakpoint set on exit from a function. The prologue and epilogue
17760 attributes allow a compiler to communicate the location(s) to use. */
17763 if (fde
->dw_fde_vms_end_prologue
)
17764 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17765 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17767 if (fde
->dw_fde_vms_begin_epilogue
)
17768 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17769 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17776 /* Generate pubnames entries for the split function code ranges. */
17777 dw_fde_ref fde
= fun
->fde
;
17779 if (fde
->dw_fde_second_begin
)
17781 if (dwarf_version
>= 3 || !dwarf_strict
)
17783 /* We should use ranges for non-contiguous code section
17784 addresses. Use the actual code range for the initial
17785 section, since the HOT/COLD labels might precede an
17786 alignment offset. */
17787 bool range_list_added
= false;
17788 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17789 fde
->dw_fde_end
, &range_list_added
,
17791 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17792 fde
->dw_fde_second_end
,
17793 &range_list_added
, false);
17794 if (range_list_added
)
17799 /* There is no real support in DW2 for this .. so we make
17800 a work-around. First, emit the pub name for the segment
17801 containing the function label. Then make and emit a
17802 simplified subprogram DIE for the second segment with the
17803 name pre-fixed by __hot/cold_sect_of_. We use the same
17804 linkage name for the second die so that gdb will find both
17805 sections when given "b foo". */
17806 const char *name
= NULL
;
17807 tree decl_name
= DECL_NAME (decl
);
17808 dw_die_ref seg_die
;
17810 /* Do the 'primary' section. */
17811 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17812 fde
->dw_fde_end
, false);
17814 /* Build a minimal DIE for the secondary section. */
17815 seg_die
= new_die (DW_TAG_subprogram
,
17816 subr_die
->die_parent
, decl
);
17818 if (TREE_PUBLIC (decl
))
17819 add_AT_flag (seg_die
, DW_AT_external
, 1);
17821 if (decl_name
!= NULL
17822 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17824 name
= dwarf2_name (decl
, 1);
17825 if (! DECL_ARTIFICIAL (decl
))
17826 add_src_coords_attributes (seg_die
, decl
);
17828 add_linkage_name (seg_die
, decl
);
17830 gcc_assert (name
!= NULL
);
17831 add_pure_or_virtual_attribute (seg_die
, decl
);
17832 if (DECL_ARTIFICIAL (decl
))
17833 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17835 name
= concat ("__second_sect_of_", name
, NULL
);
17836 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17837 fde
->dw_fde_second_end
, false);
17838 add_name_attribute (seg_die
, name
);
17839 if (want_pubnames ())
17840 add_pubname_string (name
, seg_die
);
17844 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17848 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17850 /* We define the "frame base" as the function's CFA. This is more
17851 convenient for several reasons: (1) It's stable across the prologue
17852 and epilogue, which makes it better than just a frame pointer,
17853 (2) With dwarf3, there exists a one-byte encoding that allows us
17854 to reference the .debug_frame data by proxy, but failing that,
17855 (3) We can at least reuse the code inspection and interpretation
17856 code that determines the CFA position at various points in the
17858 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17860 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17861 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17865 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17866 if (list
->dw_loc_next
)
17867 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17869 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17872 /* Compute a displacement from the "steady-state frame pointer" to
17873 the CFA. The former is what all stack slots and argument slots
17874 will reference in the rtl; the later is what we've told the
17875 debugger about. We'll need to adjust all frame_base references
17876 by this displacement. */
17877 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17879 if (fun
->static_chain_decl
)
17880 add_AT_location_description (subr_die
, DW_AT_static_link
,
17881 loc_list_from_tree (fun
->static_chain_decl
, 2));
17884 /* Generate child dies for template paramaters. */
17885 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17886 gen_generic_params_dies (decl
);
17888 /* Now output descriptions of the arguments for this function. This gets
17889 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17890 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17891 `...' at the end of the formal parameter list. In order to find out if
17892 there was a trailing ellipsis or not, we must instead look at the type
17893 associated with the FUNCTION_DECL. This will be a node of type
17894 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17895 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17896 an ellipsis at the end. */
17898 /* In the case where we are describing a mere function declaration, all we
17899 need to do here (and all we *can* do here) is to describe the *types* of
17900 its formal parameters. */
17901 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17903 else if (declaration
)
17904 gen_formal_types_die (decl
, subr_die
);
17907 /* Generate DIEs to represent all known formal parameters. */
17908 tree parm
= DECL_ARGUMENTS (decl
);
17909 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17910 tree generic_decl_parm
= generic_decl
17911 ? DECL_ARGUMENTS (generic_decl
)
17914 /* Now we want to walk the list of parameters of the function and
17915 emit their relevant DIEs.
17917 We consider the case of DECL being an instance of a generic function
17918 as well as it being a normal function.
17920 If DECL is an instance of a generic function we walk the
17921 parameters of the generic function declaration _and_ the parameters of
17922 DECL itself. This is useful because we want to emit specific DIEs for
17923 function parameter packs and those are declared as part of the
17924 generic function declaration. In that particular case,
17925 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17926 That DIE has children DIEs representing the set of arguments
17927 of the pack. Note that the set of pack arguments can be empty.
17928 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17931 Otherwise, we just consider the parameters of DECL. */
17932 while (generic_decl_parm
|| parm
)
17934 if (generic_decl_parm
17935 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17936 gen_formal_parameter_pack_die (generic_decl_parm
,
17941 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17943 if (parm
== DECL_ARGUMENTS (decl
)
17944 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17946 && (dwarf_version
>= 3 || !dwarf_strict
))
17947 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17949 parm
= DECL_CHAIN (parm
);
17952 if (generic_decl_parm
)
17953 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17956 /* Decide whether we need an unspecified_parameters DIE at the end.
17957 There are 2 more cases to do this for: 1) the ansi ... declaration -
17958 this is detectable when the end of the arg list is not a
17959 void_type_node 2) an unprototyped function declaration (not a
17960 definition). This just means that we have no info about the
17961 parameters at all. */
17962 if (prototype_p (TREE_TYPE (decl
)))
17964 /* This is the prototyped case, check for.... */
17965 if (stdarg_p (TREE_TYPE (decl
)))
17966 gen_unspecified_parameters_die (decl
, subr_die
);
17968 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17969 gen_unspecified_parameters_die (decl
, subr_die
);
17972 /* Output Dwarf info for all of the stuff within the body of the function
17973 (if it has one - it may be just a declaration). */
17974 outer_scope
= DECL_INITIAL (decl
);
17976 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17977 a function. This BLOCK actually represents the outermost binding contour
17978 for the function, i.e. the contour in which the function's formal
17979 parameters and labels get declared. Curiously, it appears that the front
17980 end doesn't actually put the PARM_DECL nodes for the current function onto
17981 the BLOCK_VARS list for this outer scope, but are strung off of the
17982 DECL_ARGUMENTS list for the function instead.
17984 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17985 the LABEL_DECL nodes for the function however, and we output DWARF info
17986 for those in decls_for_scope. Just within the `outer_scope' there will be
17987 a BLOCK node representing the function's outermost pair of curly braces,
17988 and any blocks used for the base and member initializers of a C++
17989 constructor function. */
17990 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
17992 int call_site_note_count
= 0;
17993 int tail_call_site_note_count
= 0;
17995 /* Emit a DW_TAG_variable DIE for a named return value. */
17996 if (DECL_NAME (DECL_RESULT (decl
)))
17997 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
17999 current_function_has_inlines
= 0;
18000 decls_for_scope (outer_scope
, subr_die
, 0);
18002 if (call_arg_locations
&& !dwarf_strict
)
18004 struct call_arg_loc_node
*ca_loc
;
18005 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18007 dw_die_ref die
= NULL
;
18008 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18011 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18012 arg
; arg
= next_arg
)
18014 dw_loc_descr_ref reg
, val
;
18015 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18016 dw_die_ref cdie
, tdie
= NULL
;
18018 next_arg
= XEXP (arg
, 1);
18019 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18021 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18022 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18023 && REGNO (XEXP (XEXP (arg
, 0), 0))
18024 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18025 next_arg
= XEXP (next_arg
, 1);
18026 if (mode
== VOIDmode
)
18028 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18029 if (mode
== VOIDmode
)
18030 mode
= GET_MODE (XEXP (arg
, 0));
18032 if (mode
== VOIDmode
|| mode
== BLKmode
)
18034 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18036 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18037 tloc
= XEXP (XEXP (arg
, 0), 1);
18040 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18041 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18043 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18044 tlocc
= XEXP (XEXP (arg
, 0), 1);
18048 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18049 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18050 VAR_INIT_STATUS_INITIALIZED
);
18051 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18053 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18054 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18055 get_address_mode (mem
),
18057 VAR_INIT_STATUS_INITIALIZED
);
18059 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18060 == DEBUG_PARAMETER_REF
)
18063 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18064 tdie
= lookup_decl_die (tdecl
);
18071 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18072 != DEBUG_PARAMETER_REF
)
18074 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18076 VAR_INIT_STATUS_INITIALIZED
);
18080 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18081 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18084 add_AT_loc (cdie
, DW_AT_location
, reg
);
18085 else if (tdie
!= NULL
)
18086 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18087 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18088 if (next_arg
!= XEXP (arg
, 1))
18090 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18091 if (mode
== VOIDmode
)
18092 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18093 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18096 VAR_INIT_STATUS_INITIALIZED
);
18098 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18102 && (ca_loc
->symbol_ref
|| tloc
))
18103 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18104 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18106 dw_loc_descr_ref tval
= NULL
;
18108 if (tloc
!= NULL_RTX
)
18109 tval
= mem_loc_descriptor (tloc
,
18110 GET_MODE (tloc
) == VOIDmode
18111 ? Pmode
: GET_MODE (tloc
),
18113 VAR_INIT_STATUS_INITIALIZED
);
18115 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18116 else if (tlocc
!= NULL_RTX
)
18118 tval
= mem_loc_descriptor (tlocc
,
18119 GET_MODE (tlocc
) == VOIDmode
18120 ? Pmode
: GET_MODE (tlocc
),
18122 VAR_INIT_STATUS_INITIALIZED
);
18124 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18130 call_site_note_count
++;
18131 if (ca_loc
->tail_call_p
)
18132 tail_call_site_note_count
++;
18136 call_arg_locations
= NULL
;
18137 call_arg_loc_last
= NULL
;
18138 if (tail_call_site_count
>= 0
18139 && tail_call_site_count
== tail_call_site_note_count
18142 if (call_site_count
>= 0
18143 && call_site_count
== call_site_note_count
)
18144 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18146 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18148 call_site_count
= -1;
18149 tail_call_site_count
= -1;
18151 /* Add the calling convention attribute if requested. */
18152 add_calling_convention_attribute (subr_die
, decl
);
18156 /* Returns a hash value for X (which really is a die_struct). */
18159 common_block_die_table_hash (const void *x
)
18161 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18162 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18165 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18166 as decl_id and die_parent of die_struct Y. */
18169 common_block_die_table_eq (const void *x
, const void *y
)
18171 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18172 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18173 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18176 /* Generate a DIE to represent a declared data object.
18177 Either DECL or ORIGIN must be non-null. */
18180 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18182 HOST_WIDE_INT off
= 0;
18184 tree decl_or_origin
= decl
? decl
: origin
;
18185 tree ultimate_origin
;
18186 dw_die_ref var_die
;
18187 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18188 dw_die_ref origin_die
;
18189 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18190 || class_or_namespace_scope_p (context_die
));
18191 bool specialization_p
= false;
18193 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18194 if (decl
|| ultimate_origin
)
18195 origin
= ultimate_origin
;
18196 com_decl
= fortran_common (decl_or_origin
, &off
);
18198 /* Symbol in common gets emitted as a child of the common block, in the form
18199 of a data member. */
18202 dw_die_ref com_die
;
18203 dw_loc_list_ref loc
;
18204 die_node com_die_arg
;
18206 var_die
= lookup_decl_die (decl_or_origin
);
18209 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18211 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18216 /* Optimize the common case. */
18217 if (single_element_loc_list_p (loc
)
18218 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18219 && loc
->expr
->dw_loc_next
== NULL
18220 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18223 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18224 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18225 = plus_constant (GET_MODE (x
), x
, off
);
18228 loc_list_plus_const (loc
, off
);
18230 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18231 remove_AT (var_die
, DW_AT_declaration
);
18237 if (common_block_die_table
== NULL
)
18238 common_block_die_table
18239 = htab_create_ggc (10, common_block_die_table_hash
,
18240 common_block_die_table_eq
, NULL
);
18242 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18243 com_die_arg
.die_parent
= context_die
;
18244 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18245 loc
= loc_list_from_tree (com_decl
, 2);
18246 if (com_die
== NULL
)
18249 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18252 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18253 add_name_and_src_coords_attributes (com_die
, com_decl
);
18256 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18257 /* Avoid sharing the same loc descriptor between
18258 DW_TAG_common_block and DW_TAG_variable. */
18259 loc
= loc_list_from_tree (com_decl
, 2);
18261 else if (DECL_EXTERNAL (decl
))
18262 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18263 if (want_pubnames ())
18264 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18265 com_die
->decl_id
= DECL_UID (com_decl
);
18266 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18267 *slot
= (void *) com_die
;
18269 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18271 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18272 loc
= loc_list_from_tree (com_decl
, 2);
18273 remove_AT (com_die
, DW_AT_declaration
);
18275 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18276 add_name_and_src_coords_attributes (var_die
, decl
);
18277 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18278 TREE_THIS_VOLATILE (decl
), context_die
);
18279 add_AT_flag (var_die
, DW_AT_external
, 1);
18284 /* Optimize the common case. */
18285 if (single_element_loc_list_p (loc
)
18286 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18287 && loc
->expr
->dw_loc_next
== NULL
18288 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18290 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18291 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18292 = plus_constant (GET_MODE (x
), x
, off
);
18295 loc_list_plus_const (loc
, off
);
18297 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18299 else if (DECL_EXTERNAL (decl
))
18300 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18301 equate_decl_number_to_die (decl
, var_die
);
18305 /* If the compiler emitted a definition for the DECL declaration
18306 and if we already emitted a DIE for it, don't emit a second
18307 DIE for it again. Allow re-declarations of DECLs that are
18308 inside functions, though. */
18309 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18312 /* For static data members, the declaration in the class is supposed
18313 to have DW_TAG_member tag; the specification should still be
18314 DW_TAG_variable referencing the DW_TAG_member DIE. */
18315 if (declaration
&& class_scope_p (context_die
))
18316 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18318 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18321 if (origin
!= NULL
)
18322 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18324 /* Loop unrolling can create multiple blocks that refer to the same
18325 static variable, so we must test for the DW_AT_declaration flag.
18327 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18328 copy decls and set the DECL_ABSTRACT flag on them instead of
18331 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18333 ??? The declare_in_namespace support causes us to get two DIEs for one
18334 variable, both of which are declarations. We want to avoid considering
18335 one to be a specification, so we must test that this DIE is not a
18337 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18338 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18340 /* This is a definition of a C++ class level static. */
18341 add_AT_specification (var_die
, old_die
);
18342 specialization_p
= true;
18343 if (DECL_NAME (decl
))
18345 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18346 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18348 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18349 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18351 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18352 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18354 if (old_die
->die_tag
== DW_TAG_member
)
18355 add_linkage_name (var_die
, decl
);
18359 add_name_and_src_coords_attributes (var_die
, decl
);
18361 if ((origin
== NULL
&& !specialization_p
)
18363 && !DECL_ABSTRACT (decl_or_origin
)
18364 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18365 decl_function_context
18366 (decl_or_origin
))))
18368 tree type
= TREE_TYPE (decl_or_origin
);
18370 if (decl_by_reference_p (decl_or_origin
))
18371 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18373 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18374 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18377 if (origin
== NULL
&& !specialization_p
)
18379 if (TREE_PUBLIC (decl
))
18380 add_AT_flag (var_die
, DW_AT_external
, 1);
18382 if (DECL_ARTIFICIAL (decl
))
18383 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18385 add_accessibility_attribute (var_die
, decl
);
18389 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18391 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18392 equate_decl_number_to_die (decl
, var_die
);
18395 && (! DECL_ABSTRACT (decl_or_origin
)
18396 /* Local static vars are shared between all clones/inlines,
18397 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18399 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18400 && TREE_STATIC (decl_or_origin
)
18401 && DECL_RTL_SET_P (decl_or_origin
)))
18402 /* When abstract origin already has DW_AT_location attribute, no need
18403 to add it again. */
18404 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18406 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18407 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18408 defer_location (decl_or_origin
, var_die
);
18410 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18411 decl
== NULL
, DW_AT_location
);
18412 add_pubname (decl_or_origin
, var_die
);
18415 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18418 /* Generate a DIE to represent a named constant. */
18421 gen_const_die (tree decl
, dw_die_ref context_die
)
18423 dw_die_ref const_die
;
18424 tree type
= TREE_TYPE (decl
);
18426 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18427 add_name_and_src_coords_attributes (const_die
, decl
);
18428 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18429 if (TREE_PUBLIC (decl
))
18430 add_AT_flag (const_die
, DW_AT_external
, 1);
18431 if (DECL_ARTIFICIAL (decl
))
18432 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18433 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18436 /* Generate a DIE to represent a label identifier. */
18439 gen_label_die (tree decl
, dw_die_ref context_die
)
18441 tree origin
= decl_ultimate_origin (decl
);
18442 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18444 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18446 if (origin
!= NULL
)
18447 add_abstract_origin_attribute (lbl_die
, origin
);
18449 add_name_and_src_coords_attributes (lbl_die
, decl
);
18451 if (DECL_ABSTRACT (decl
))
18452 equate_decl_number_to_die (decl
, lbl_die
);
18455 insn
= DECL_RTL_IF_SET (decl
);
18457 /* Deleted labels are programmer specified labels which have been
18458 eliminated because of various optimizations. We still emit them
18459 here so that it is possible to put breakpoints on them. */
18463 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18465 /* When optimization is enabled (via -O) some parts of the compiler
18466 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18467 represent source-level labels which were explicitly declared by
18468 the user. This really shouldn't be happening though, so catch
18469 it if it ever does happen. */
18470 gcc_assert (!INSN_DELETED_P (insn
));
18472 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18473 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18477 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18478 && CODE_LABEL_NUMBER (insn
) != -1)
18480 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18481 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18486 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18487 attributes to the DIE for a block STMT, to describe where the inlined
18488 function was called from. This is similar to add_src_coords_attributes. */
18491 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18493 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18495 if (dwarf_version
>= 3 || !dwarf_strict
)
18497 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18498 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18503 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18504 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18507 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18509 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18511 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18512 && (dwarf_version
>= 3 || !dwarf_strict
))
18514 tree chain
, superblock
= NULL_TREE
;
18516 dw_attr_ref attr
= NULL
;
18518 if (inlined_function_outer_scope_p (stmt
))
18520 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18521 BLOCK_NUMBER (stmt
));
18522 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18525 /* Optimize duplicate .debug_ranges lists or even tails of
18526 lists. If this BLOCK has same ranges as its supercontext,
18527 lookup DW_AT_ranges attribute in the supercontext (and
18528 recursively so), verify that the ranges_table contains the
18529 right values and use it instead of adding a new .debug_range. */
18530 for (chain
= stmt
, pdie
= die
;
18531 BLOCK_SAME_RANGE (chain
);
18532 chain
= BLOCK_SUPERCONTEXT (chain
))
18534 dw_attr_ref new_attr
;
18536 pdie
= pdie
->die_parent
;
18539 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18541 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18542 if (new_attr
== NULL
18543 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18546 superblock
= BLOCK_SUPERCONTEXT (chain
);
18549 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18550 / 2 / DWARF2_ADDR_SIZE
].num
18551 == BLOCK_NUMBER (superblock
))
18552 && BLOCK_FRAGMENT_CHAIN (superblock
))
18554 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18555 / 2 / DWARF2_ADDR_SIZE
;
18556 unsigned long supercnt
= 0, thiscnt
= 0;
18557 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18558 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18561 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18562 == BLOCK_NUMBER (chain
));
18564 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18565 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18566 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18568 gcc_assert (supercnt
>= thiscnt
);
18569 add_AT_range_list (die
, DW_AT_ranges
,
18570 ((off
+ supercnt
- thiscnt
)
18571 * 2 * DWARF2_ADDR_SIZE
),
18576 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18578 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18581 add_ranges (chain
);
18582 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18589 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18590 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18591 BLOCK_NUMBER (stmt
));
18592 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18593 BLOCK_NUMBER (stmt
));
18594 add_AT_low_high_pc (die
, label
, label_high
, false);
18598 /* Generate a DIE for a lexical block. */
18601 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18603 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18605 if (call_arg_locations
)
18607 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18608 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18609 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18612 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18613 add_high_low_attributes (stmt
, stmt_die
);
18615 decls_for_scope (stmt
, stmt_die
, depth
);
18618 /* Generate a DIE for an inlined subprogram. */
18621 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18625 /* The instance of function that is effectively being inlined shall not
18627 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18629 decl
= block_ultimate_origin (stmt
);
18631 /* Emit info for the abstract instance first, if we haven't yet. We
18632 must emit this even if the block is abstract, otherwise when we
18633 emit the block below (or elsewhere), we may end up trying to emit
18634 a die whose origin die hasn't been emitted, and crashing. */
18635 dwarf2out_abstract_function (decl
);
18637 if (! BLOCK_ABSTRACT (stmt
))
18639 dw_die_ref subr_die
18640 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18642 if (call_arg_locations
)
18644 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18645 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18646 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18648 add_abstract_origin_attribute (subr_die
, decl
);
18649 if (TREE_ASM_WRITTEN (stmt
))
18650 add_high_low_attributes (stmt
, subr_die
);
18651 add_call_src_coords_attributes (stmt
, subr_die
);
18653 decls_for_scope (stmt
, subr_die
, depth
);
18654 current_function_has_inlines
= 1;
18658 /* Generate a DIE for a field in a record, or structure. */
18661 gen_field_die (tree decl
, dw_die_ref context_die
)
18663 dw_die_ref decl_die
;
18665 if (TREE_TYPE (decl
) == error_mark_node
)
18668 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18669 add_name_and_src_coords_attributes (decl_die
, decl
);
18670 add_type_attribute (decl_die
, member_declared_type (decl
),
18671 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18674 if (DECL_BIT_FIELD_TYPE (decl
))
18676 add_byte_size_attribute (decl_die
, decl
);
18677 add_bit_size_attribute (decl_die
, decl
);
18678 add_bit_offset_attribute (decl_die
, decl
);
18681 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18682 add_data_member_location_attribute (decl_die
, decl
);
18684 if (DECL_ARTIFICIAL (decl
))
18685 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18687 add_accessibility_attribute (decl_die
, decl
);
18689 /* Equate decl number to die, so that we can look up this decl later on. */
18690 equate_decl_number_to_die (decl
, decl_die
);
18694 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18695 Use modified_type_die instead.
18696 We keep this code here just in case these types of DIEs may be needed to
18697 represent certain things in other languages (e.g. Pascal) someday. */
18700 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18703 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18705 equate_type_number_to_die (type
, ptr_die
);
18706 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18707 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18710 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18711 Use modified_type_die instead.
18712 We keep this code here just in case these types of DIEs may be needed to
18713 represent certain things in other languages (e.g. Pascal) someday. */
18716 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18718 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18720 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18721 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18723 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18725 equate_type_number_to_die (type
, ref_die
);
18726 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18727 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18731 /* Generate a DIE for a pointer to a member type. */
18734 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18737 = new_die (DW_TAG_ptr_to_member_type
,
18738 scope_die_for (type
, context_die
), type
);
18740 equate_type_number_to_die (type
, ptr_die
);
18741 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18742 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18743 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18746 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18748 static char *producer_string
;
18750 /* Return a heap allocated producer string including command line options
18751 if -grecord-gcc-switches. */
18754 gen_producer_string (void)
18757 vec
<dchar_p
> switches
= vNULL
;
18758 const char *language_string
= lang_hooks
.name
;
18759 char *producer
, *tail
;
18761 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18762 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18764 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18765 switch (save_decoded_options
[j
].opt_index
)
18772 case OPT_auxbase_strip
:
18781 case OPT_SPECIAL_unknown
:
18782 case OPT_SPECIAL_ignore
:
18783 case OPT_SPECIAL_program_name
:
18784 case OPT_SPECIAL_input_file
:
18785 case OPT_grecord_gcc_switches
:
18786 case OPT_gno_record_gcc_switches
:
18787 case OPT__output_pch_
:
18788 case OPT_fdiagnostics_show_location_
:
18789 case OPT_fdiagnostics_show_option
:
18790 case OPT_fdiagnostics_show_caret
:
18791 case OPT_fverbose_asm
:
18793 case OPT__sysroot_
:
18795 case OPT_nostdinc__
:
18796 /* Ignore these. */
18799 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18800 & CL_NO_DWARF_RECORD
)
18802 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18804 switch (save_decoded_options
[j
].canonical_option
[0][1])
18811 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18818 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18819 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18823 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18825 sprintf (tail
, "%s %s", language_string
, version_string
);
18828 FOR_EACH_VEC_ELT (switches
, j
, p
)
18832 memcpy (tail
+ 1, p
, len
);
18837 switches
.release ();
18841 /* Generate the DIE for the compilation unit. */
18844 gen_compile_unit_die (const char *filename
)
18847 const char *language_string
= lang_hooks
.name
;
18850 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18854 add_name_attribute (die
, filename
);
18855 /* Don't add cwd for <built-in>. */
18856 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18857 add_comp_dir_attribute (die
);
18860 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
18862 /* If our producer is LTO try to figure out a common language to use
18863 from the global list of translation units. */
18864 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18868 const char *common_lang
= NULL
;
18870 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
18872 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18875 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18876 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18878 else if (strncmp (common_lang
, "GNU C", 5) == 0
18879 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18880 /* Mixing C and C++ is ok, use C++ in that case. */
18881 common_lang
= "GNU C++";
18884 /* Fall back to C. */
18885 common_lang
= NULL
;
18891 language_string
= common_lang
;
18894 language
= DW_LANG_C89
;
18895 if (strcmp (language_string
, "GNU C++") == 0)
18896 language
= DW_LANG_C_plus_plus
;
18897 else if (strcmp (language_string
, "GNU F77") == 0)
18898 language
= DW_LANG_Fortran77
;
18899 else if (strcmp (language_string
, "GNU Pascal") == 0)
18900 language
= DW_LANG_Pascal83
;
18901 else if (dwarf_version
>= 3 || !dwarf_strict
)
18903 if (strcmp (language_string
, "GNU Ada") == 0)
18904 language
= DW_LANG_Ada95
;
18905 else if (strcmp (language_string
, "GNU Fortran") == 0)
18906 language
= DW_LANG_Fortran95
;
18907 else if (strcmp (language_string
, "GNU Java") == 0)
18908 language
= DW_LANG_Java
;
18909 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18910 language
= DW_LANG_ObjC
;
18911 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18912 language
= DW_LANG_ObjC_plus_plus
;
18913 else if (dwarf_version
>= 5 || !dwarf_strict
)
18915 if (strcmp (language_string
, "GNU Go") == 0)
18916 language
= DW_LANG_Go
;
18919 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18920 else if (strcmp (language_string
, "GNU Fortran") == 0)
18921 language
= DW_LANG_Fortran90
;
18923 add_AT_unsigned (die
, DW_AT_language
, language
);
18927 case DW_LANG_Fortran77
:
18928 case DW_LANG_Fortran90
:
18929 case DW_LANG_Fortran95
:
18930 /* Fortran has case insensitive identifiers and the front-end
18931 lowercases everything. */
18932 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18935 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18941 /* Generate the DIE for a base class. */
18944 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18946 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18948 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18949 add_data_member_location_attribute (die
, binfo
);
18951 if (BINFO_VIRTUAL_P (binfo
))
18952 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18954 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18955 children, otherwise the default is DW_ACCESS_public. In DWARF2
18956 the default has always been DW_ACCESS_private. */
18957 if (access
== access_public_node
)
18959 if (dwarf_version
== 2
18960 || context_die
->die_tag
== DW_TAG_class_type
)
18961 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18963 else if (access
== access_protected_node
)
18964 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18965 else if (dwarf_version
> 2
18966 && context_die
->die_tag
!= DW_TAG_class_type
)
18967 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18970 /* Generate a DIE for a class member. */
18973 gen_member_die (tree type
, dw_die_ref context_die
)
18976 tree binfo
= TYPE_BINFO (type
);
18979 /* If this is not an incomplete type, output descriptions of each of its
18980 members. Note that as we output the DIEs necessary to represent the
18981 members of this record or union type, we will also be trying to output
18982 DIEs to represent the *types* of those members. However the `type'
18983 function (above) will specifically avoid generating type DIEs for member
18984 types *within* the list of member DIEs for this (containing) type except
18985 for those types (of members) which are explicitly marked as also being
18986 members of this (containing) type themselves. The g++ front- end can
18987 force any given type to be treated as a member of some other (containing)
18988 type by setting the TYPE_CONTEXT of the given (member) type to point to
18989 the TREE node representing the appropriate (containing) type. */
18991 /* First output info about the base classes. */
18994 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
18998 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
18999 gen_inheritance_die (base
,
19000 (accesses
? (*accesses
)[i
] : access_public_node
),
19004 /* Now output info about the data members and type members. */
19005 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19007 /* If we thought we were generating minimal debug info for TYPE
19008 and then changed our minds, some of the member declarations
19009 may have already been defined. Don't define them again, but
19010 do put them in the right order. */
19012 child
= lookup_decl_die (member
);
19014 splice_child_die (context_die
, child
);
19016 gen_decl_die (member
, NULL
, context_die
);
19019 /* Now output info about the function members (if any). */
19020 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19022 /* Don't include clones in the member list. */
19023 if (DECL_ABSTRACT_ORIGIN (member
))
19026 child
= lookup_decl_die (member
);
19028 splice_child_die (context_die
, child
);
19030 gen_decl_die (member
, NULL
, context_die
);
19034 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19035 is set, we pretend that the type was never defined, so we only get the
19036 member DIEs needed by later specification DIEs. */
19039 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19040 enum debug_info_usage usage
)
19042 dw_die_ref type_die
= lookup_type_die (type
);
19043 dw_die_ref scope_die
= 0;
19045 int complete
= (TYPE_SIZE (type
)
19046 && (! TYPE_STUB_DECL (type
)
19047 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19048 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19049 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19051 if (type_die
&& ! complete
)
19054 if (TYPE_CONTEXT (type
) != NULL_TREE
19055 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19056 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19059 scope_die
= scope_die_for (type
, context_die
);
19061 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19062 /* First occurrence of type or toplevel definition of nested class. */
19064 dw_die_ref old_die
= type_die
;
19066 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19067 ? record_type_tag (type
) : DW_TAG_union_type
,
19069 equate_type_number_to_die (type
, type_die
);
19071 add_AT_specification (type_die
, old_die
);
19073 add_name_attribute (type_die
, type_tag (type
));
19076 remove_AT (type_die
, DW_AT_declaration
);
19078 /* Generate child dies for template paramaters. */
19079 if (debug_info_level
> DINFO_LEVEL_TERSE
19080 && COMPLETE_TYPE_P (type
))
19081 schedule_generic_params_dies_gen (type
);
19083 /* If this type has been completed, then give it a byte_size attribute and
19084 then give a list of members. */
19085 if (complete
&& !ns_decl
)
19087 /* Prevent infinite recursion in cases where the type of some member of
19088 this type is expressed in terms of this type itself. */
19089 TREE_ASM_WRITTEN (type
) = 1;
19090 add_byte_size_attribute (type_die
, type
);
19091 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19093 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19094 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19097 /* If the first reference to this type was as the return type of an
19098 inline function, then it may not have a parent. Fix this now. */
19099 if (type_die
->die_parent
== NULL
)
19100 add_child_die (scope_die
, type_die
);
19102 push_decl_scope (type
);
19103 gen_member_die (type
, type_die
);
19106 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19107 if (TYPE_ARTIFICIAL (type
))
19108 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19110 /* GNU extension: Record what type our vtable lives in. */
19111 if (TYPE_VFIELD (type
))
19113 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19115 gen_type_die (vtype
, context_die
);
19116 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19117 lookup_type_die (vtype
));
19122 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19124 /* We don't need to do this for function-local types. */
19125 if (TYPE_STUB_DECL (type
)
19126 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19127 vec_safe_push (incomplete_types
, type
);
19130 if (get_AT (type_die
, DW_AT_name
))
19131 add_pubtype (type
, type_die
);
19134 /* Generate a DIE for a subroutine _type_. */
19137 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19139 tree return_type
= TREE_TYPE (type
);
19140 dw_die_ref subr_die
19141 = new_die (DW_TAG_subroutine_type
,
19142 scope_die_for (type
, context_die
), type
);
19144 equate_type_number_to_die (type
, subr_die
);
19145 add_prototyped_attribute (subr_die
, type
);
19146 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19147 gen_formal_types_die (type
, subr_die
);
19149 if (get_AT (subr_die
, DW_AT_name
))
19150 add_pubtype (type
, subr_die
);
19153 /* Generate a DIE for a type definition. */
19156 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19158 dw_die_ref type_die
;
19161 if (TREE_ASM_WRITTEN (decl
))
19164 TREE_ASM_WRITTEN (decl
) = 1;
19165 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19166 origin
= decl_ultimate_origin (decl
);
19167 if (origin
!= NULL
)
19168 add_abstract_origin_attribute (type_die
, origin
);
19173 add_name_and_src_coords_attributes (type_die
, decl
);
19174 if (DECL_ORIGINAL_TYPE (decl
))
19176 type
= DECL_ORIGINAL_TYPE (decl
);
19178 gcc_assert (type
!= TREE_TYPE (decl
));
19179 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19183 type
= TREE_TYPE (decl
);
19185 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19187 /* Here, we are in the case of decl being a typedef naming
19188 an anonymous type, e.g:
19189 typedef struct {...} foo;
19190 In that case TREE_TYPE (decl) is not a typedef variant
19191 type and TYPE_NAME of the anonymous type is set to the
19192 TYPE_DECL of the typedef. This construct is emitted by
19195 TYPE is the anonymous struct named by the typedef
19196 DECL. As we need the DW_AT_type attribute of the
19197 DW_TAG_typedef to point to the DIE of TYPE, let's
19198 generate that DIE right away. add_type_attribute
19199 called below will then pick (via lookup_type_die) that
19200 anonymous struct DIE. */
19201 if (!TREE_ASM_WRITTEN (type
))
19202 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19204 /* This is a GNU Extension. We are adding a
19205 DW_AT_linkage_name attribute to the DIE of the
19206 anonymous struct TYPE. The value of that attribute
19207 is the name of the typedef decl naming the anonymous
19208 struct. This greatly eases the work of consumers of
19209 this debug info. */
19210 add_linkage_attr (lookup_type_die (type
), decl
);
19214 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19215 TREE_THIS_VOLATILE (decl
), context_die
);
19217 if (is_naming_typedef_decl (decl
))
19218 /* We want that all subsequent calls to lookup_type_die with
19219 TYPE in argument yield the DW_TAG_typedef we have just
19221 equate_type_number_to_die (type
, type_die
);
19223 add_accessibility_attribute (type_die
, decl
);
19226 if (DECL_ABSTRACT (decl
))
19227 equate_decl_number_to_die (decl
, type_die
);
19229 if (get_AT (type_die
, DW_AT_name
))
19230 add_pubtype (decl
, type_die
);
19233 /* Generate a DIE for a struct, class, enum or union type. */
19236 gen_tagged_type_die (tree type
,
19237 dw_die_ref context_die
,
19238 enum debug_info_usage usage
)
19242 if (type
== NULL_TREE
19243 || !is_tagged_type (type
))
19246 /* If this is a nested type whose containing class hasn't been written
19247 out yet, writing it out will cover this one, too. This does not apply
19248 to instantiations of member class templates; they need to be added to
19249 the containing class as they are generated. FIXME: This hurts the
19250 idea of combining type decls from multiple TUs, since we can't predict
19251 what set of template instantiations we'll get. */
19252 if (TYPE_CONTEXT (type
)
19253 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19254 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19256 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19258 if (TREE_ASM_WRITTEN (type
))
19261 /* If that failed, attach ourselves to the stub. */
19262 push_decl_scope (TYPE_CONTEXT (type
));
19263 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19266 else if (TYPE_CONTEXT (type
) != NULL_TREE
19267 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19269 /* If this type is local to a function that hasn't been written
19270 out yet, use a NULL context for now; it will be fixed up in
19271 decls_for_scope. */
19272 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19273 /* A declaration DIE doesn't count; nested types need to go in the
19275 if (context_die
&& is_declaration_die (context_die
))
19276 context_die
= NULL
;
19281 context_die
= declare_in_namespace (type
, context_die
);
19285 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19287 /* This might have been written out by the call to
19288 declare_in_namespace. */
19289 if (!TREE_ASM_WRITTEN (type
))
19290 gen_enumeration_type_die (type
, context_die
);
19293 gen_struct_or_union_type_die (type
, context_die
, usage
);
19298 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19299 it up if it is ever completed. gen_*_type_die will set it for us
19300 when appropriate. */
19303 /* Generate a type description DIE. */
19306 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19307 enum debug_info_usage usage
)
19309 struct array_descr_info info
;
19311 if (type
== NULL_TREE
|| type
== error_mark_node
)
19314 if (TYPE_NAME (type
) != NULL_TREE
19315 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19316 && is_redundant_typedef (TYPE_NAME (type
))
19317 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19318 /* The DECL of this type is a typedef we don't want to emit debug
19319 info for but we want debug info for its underlying typedef.
19320 This can happen for e.g, the injected-class-name of a C++
19322 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19324 /* If TYPE is a typedef type variant, let's generate debug info
19325 for the parent typedef which TYPE is a type of. */
19326 if (typedef_variant_p (type
))
19328 if (TREE_ASM_WRITTEN (type
))
19331 /* Prevent broken recursion; we can't hand off to the same type. */
19332 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19334 /* Give typedefs the right scope. */
19335 context_die
= scope_die_for (type
, context_die
);
19337 TREE_ASM_WRITTEN (type
) = 1;
19339 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19343 /* If type is an anonymous tagged type named by a typedef, let's
19344 generate debug info for the typedef. */
19345 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19347 /* Use the DIE of the containing namespace as the parent DIE of
19348 the type description DIE we want to generate. */
19349 if (DECL_CONTEXT (TYPE_NAME (type
))
19350 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19351 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19353 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19357 /* If this is an array type with hidden descriptor, handle it first. */
19358 if (!TREE_ASM_WRITTEN (type
)
19359 && lang_hooks
.types
.get_array_descr_info
19360 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19361 && (dwarf_version
>= 3 || !dwarf_strict
))
19363 gen_descr_array_type_die (type
, &info
, context_die
);
19364 TREE_ASM_WRITTEN (type
) = 1;
19368 /* We are going to output a DIE to represent the unqualified version
19369 of this type (i.e. without any const or volatile qualifiers) so
19370 get the main variant (i.e. the unqualified version) of this type
19371 now. (Vectors are special because the debugging info is in the
19372 cloned type itself). */
19373 if (TREE_CODE (type
) != VECTOR_TYPE
)
19374 type
= type_main_variant (type
);
19376 if (TREE_ASM_WRITTEN (type
))
19379 switch (TREE_CODE (type
))
19385 case REFERENCE_TYPE
:
19386 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19387 ensures that the gen_type_die recursion will terminate even if the
19388 type is recursive. Recursive types are possible in Ada. */
19389 /* ??? We could perhaps do this for all types before the switch
19391 TREE_ASM_WRITTEN (type
) = 1;
19393 /* For these types, all that is required is that we output a DIE (or a
19394 set of DIEs) to represent the "basis" type. */
19395 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19396 DINFO_USAGE_IND_USE
);
19400 /* This code is used for C++ pointer-to-data-member types.
19401 Output a description of the relevant class type. */
19402 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19403 DINFO_USAGE_IND_USE
);
19405 /* Output a description of the type of the object pointed to. */
19406 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19407 DINFO_USAGE_IND_USE
);
19409 /* Now output a DIE to represent this pointer-to-data-member type
19411 gen_ptr_to_mbr_type_die (type
, context_die
);
19414 case FUNCTION_TYPE
:
19415 /* Force out return type (in case it wasn't forced out already). */
19416 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19417 DINFO_USAGE_DIR_USE
);
19418 gen_subroutine_type_die (type
, context_die
);
19422 /* Force out return type (in case it wasn't forced out already). */
19423 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19424 DINFO_USAGE_DIR_USE
);
19425 gen_subroutine_type_die (type
, context_die
);
19429 gen_array_type_die (type
, context_die
);
19433 gen_array_type_die (type
, context_die
);
19436 case ENUMERAL_TYPE
:
19439 case QUAL_UNION_TYPE
:
19440 gen_tagged_type_die (type
, context_die
, usage
);
19446 case FIXED_POINT_TYPE
:
19449 /* No DIEs needed for fundamental types. */
19454 /* Just use DW_TAG_unspecified_type. */
19456 dw_die_ref type_die
= lookup_type_die (type
);
19457 if (type_die
== NULL
)
19459 tree name
= TYPE_NAME (type
);
19460 if (TREE_CODE (name
) == TYPE_DECL
)
19461 name
= DECL_NAME (name
);
19462 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19463 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19464 equate_type_number_to_die (type
, type_die
);
19470 gcc_unreachable ();
19473 TREE_ASM_WRITTEN (type
) = 1;
19477 gen_type_die (tree type
, dw_die_ref context_die
)
19479 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19482 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19483 things which are local to the given block. */
19486 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19488 int must_output_die
= 0;
19491 /* Ignore blocks that are NULL. */
19492 if (stmt
== NULL_TREE
)
19495 inlined_func
= inlined_function_outer_scope_p (stmt
);
19497 /* If the block is one fragment of a non-contiguous block, do not
19498 process the variables, since they will have been done by the
19499 origin block. Do process subblocks. */
19500 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19504 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19505 gen_block_die (sub
, context_die
, depth
+ 1);
19510 /* Determine if we need to output any Dwarf DIEs at all to represent this
19513 /* The outer scopes for inlinings *must* always be represented. We
19514 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19515 must_output_die
= 1;
19518 /* Determine if this block directly contains any "significant"
19519 local declarations which we will need to output DIEs for. */
19520 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19521 /* We are not in terse mode so *any* local declaration counts
19522 as being a "significant" one. */
19523 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19524 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19525 && (TREE_USED (stmt
)
19526 || TREE_ASM_WRITTEN (stmt
)
19527 || BLOCK_ABSTRACT (stmt
)));
19528 else if ((TREE_USED (stmt
)
19529 || TREE_ASM_WRITTEN (stmt
)
19530 || BLOCK_ABSTRACT (stmt
))
19531 && !dwarf2out_ignore_block (stmt
))
19532 must_output_die
= 1;
19535 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19536 DIE for any block which contains no significant local declarations at
19537 all. Rather, in such cases we just call `decls_for_scope' so that any
19538 needed Dwarf info for any sub-blocks will get properly generated. Note
19539 that in terse mode, our definition of what constitutes a "significant"
19540 local declaration gets restricted to include only inlined function
19541 instances and local (nested) function definitions. */
19542 if (must_output_die
)
19546 /* If STMT block is abstract, that means we have been called
19547 indirectly from dwarf2out_abstract_function.
19548 That function rightfully marks the descendent blocks (of
19549 the abstract function it is dealing with) as being abstract,
19550 precisely to prevent us from emitting any
19551 DW_TAG_inlined_subroutine DIE as a descendent
19552 of an abstract function instance. So in that case, we should
19553 not call gen_inlined_subroutine_die.
19555 Later though, when cgraph asks dwarf2out to emit info
19556 for the concrete instance of the function decl into which
19557 the concrete instance of STMT got inlined, the later will lead
19558 to the generation of a DW_TAG_inlined_subroutine DIE. */
19559 if (! BLOCK_ABSTRACT (stmt
))
19560 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19563 gen_lexical_block_die (stmt
, context_die
, depth
);
19566 decls_for_scope (stmt
, context_die
, depth
);
19569 /* Process variable DECL (or variable with origin ORIGIN) within
19570 block STMT and add it to CONTEXT_DIE. */
19572 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19575 tree decl_or_origin
= decl
? decl
: origin
;
19577 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19578 die
= lookup_decl_die (decl_or_origin
);
19579 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19580 && TYPE_DECL_IS_STUB (decl_or_origin
))
19581 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19585 if (die
!= NULL
&& die
->die_parent
== NULL
)
19586 add_child_die (context_die
, die
);
19587 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19588 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19589 stmt
, context_die
);
19591 gen_decl_die (decl
, origin
, context_die
);
19594 /* Generate all of the decls declared within a given scope and (recursively)
19595 all of its sub-blocks. */
19598 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19604 /* Ignore NULL blocks. */
19605 if (stmt
== NULL_TREE
)
19608 /* Output the DIEs to represent all of the data objects and typedefs
19609 declared directly within this block but not within any nested
19610 sub-blocks. Also, nested function and tag DIEs have been
19611 generated with a parent of NULL; fix that up now. */
19612 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19613 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19614 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19615 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19618 /* If we're at -g1, we're not interested in subblocks. */
19619 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19622 /* Output the DIEs to represent all sub-blocks (and the items declared
19623 therein) of this block. */
19624 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19626 subblocks
= BLOCK_CHAIN (subblocks
))
19627 gen_block_die (subblocks
, context_die
, depth
+ 1);
19630 /* Is this a typedef we can avoid emitting? */
19633 is_redundant_typedef (const_tree decl
)
19635 if (TYPE_DECL_IS_STUB (decl
))
19638 if (DECL_ARTIFICIAL (decl
)
19639 && DECL_CONTEXT (decl
)
19640 && is_tagged_type (DECL_CONTEXT (decl
))
19641 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19642 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19643 /* Also ignore the artificial member typedef for the class name. */
19649 /* Return TRUE if TYPE is a typedef that names a type for linkage
19650 purposes. This kind of typedefs is produced by the C++ FE for
19653 typedef struct {...} foo;
19655 In that case, there is no typedef variant type produced for foo.
19656 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19660 is_naming_typedef_decl (const_tree decl
)
19662 if (decl
== NULL_TREE
19663 || TREE_CODE (decl
) != TYPE_DECL
19664 || !is_tagged_type (TREE_TYPE (decl
))
19665 || DECL_IS_BUILTIN (decl
)
19666 || is_redundant_typedef (decl
)
19667 /* It looks like Ada produces TYPE_DECLs that are very similar
19668 to C++ naming typedefs but that have different
19669 semantics. Let's be specific to c++ for now. */
19673 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19674 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19675 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19676 != TYPE_NAME (TREE_TYPE (decl
))));
19679 /* Returns the DIE for a context. */
19681 static inline dw_die_ref
19682 get_context_die (tree context
)
19686 /* Find die that represents this context. */
19687 if (TYPE_P (context
))
19689 context
= TYPE_MAIN_VARIANT (context
);
19690 return strip_naming_typedef (context
, force_type_die (context
));
19693 return force_decl_die (context
);
19695 return comp_unit_die ();
19698 /* Returns the DIE for decl. A DIE will always be returned. */
19701 force_decl_die (tree decl
)
19703 dw_die_ref decl_die
;
19704 unsigned saved_external_flag
;
19705 tree save_fn
= NULL_TREE
;
19706 decl_die
= lookup_decl_die (decl
);
19709 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19711 decl_die
= lookup_decl_die (decl
);
19715 switch (TREE_CODE (decl
))
19717 case FUNCTION_DECL
:
19718 /* Clear current_function_decl, so that gen_subprogram_die thinks
19719 that this is a declaration. At this point, we just want to force
19720 declaration die. */
19721 save_fn
= current_function_decl
;
19722 current_function_decl
= NULL_TREE
;
19723 gen_subprogram_die (decl
, context_die
);
19724 current_function_decl
= save_fn
;
19728 /* Set external flag to force declaration die. Restore it after
19729 gen_decl_die() call. */
19730 saved_external_flag
= DECL_EXTERNAL (decl
);
19731 DECL_EXTERNAL (decl
) = 1;
19732 gen_decl_die (decl
, NULL
, context_die
);
19733 DECL_EXTERNAL (decl
) = saved_external_flag
;
19736 case NAMESPACE_DECL
:
19737 if (dwarf_version
>= 3 || !dwarf_strict
)
19738 dwarf2out_decl (decl
);
19740 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19741 decl_die
= comp_unit_die ();
19744 case TRANSLATION_UNIT_DECL
:
19745 decl_die
= comp_unit_die ();
19749 gcc_unreachable ();
19752 /* We should be able to find the DIE now. */
19754 decl_die
= lookup_decl_die (decl
);
19755 gcc_assert (decl_die
);
19761 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19762 always returned. */
19765 force_type_die (tree type
)
19767 dw_die_ref type_die
;
19769 type_die
= lookup_type_die (type
);
19772 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19774 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19775 TYPE_VOLATILE (type
), context_die
);
19776 gcc_assert (type_die
);
19781 /* Force out any required namespaces to be able to output DECL,
19782 and return the new context_die for it, if it's changed. */
19785 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19787 tree context
= (DECL_P (thing
)
19788 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19789 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19790 /* Force out the namespace. */
19791 context_die
= force_decl_die (context
);
19793 return context_die
;
19796 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19797 type) within its namespace, if appropriate.
19799 For compatibility with older debuggers, namespace DIEs only contain
19800 declarations; all definitions are emitted at CU scope. */
19803 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19805 dw_die_ref ns_context
;
19807 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19808 return context_die
;
19810 /* If this decl is from an inlined function, then don't try to emit it in its
19811 namespace, as we will get confused. It would have already been emitted
19812 when the abstract instance of the inline function was emitted anyways. */
19813 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19814 return context_die
;
19816 ns_context
= setup_namespace_context (thing
, context_die
);
19818 if (ns_context
!= context_die
)
19822 if (DECL_P (thing
))
19823 gen_decl_die (thing
, NULL
, ns_context
);
19825 gen_type_die (thing
, ns_context
);
19827 return context_die
;
19830 /* Generate a DIE for a namespace or namespace alias. */
19833 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19835 dw_die_ref namespace_die
;
19837 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19838 they are an alias of. */
19839 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19841 /* Output a real namespace or module. */
19842 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19843 namespace_die
= new_die (is_fortran ()
19844 ? DW_TAG_module
: DW_TAG_namespace
,
19845 context_die
, decl
);
19846 /* For Fortran modules defined in different CU don't add src coords. */
19847 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19849 const char *name
= dwarf2_name (decl
, 0);
19851 add_name_attribute (namespace_die
, name
);
19854 add_name_and_src_coords_attributes (namespace_die
, decl
);
19855 if (DECL_EXTERNAL (decl
))
19856 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19857 equate_decl_number_to_die (decl
, namespace_die
);
19861 /* Output a namespace alias. */
19863 /* Force out the namespace we are an alias of, if necessary. */
19864 dw_die_ref origin_die
19865 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19867 if (DECL_FILE_SCOPE_P (decl
)
19868 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19869 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19870 /* Now create the namespace alias DIE. */
19871 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19872 add_name_and_src_coords_attributes (namespace_die
, decl
);
19873 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19874 equate_decl_number_to_die (decl
, namespace_die
);
19876 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19877 if (want_pubnames ())
19878 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19881 /* Generate Dwarf debug information for a decl described by DECL.
19882 The return value is currently only meaningful for PARM_DECLs,
19883 for all other decls it returns NULL. */
19886 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19888 tree decl_or_origin
= decl
? decl
: origin
;
19889 tree class_origin
= NULL
, ultimate_origin
;
19891 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19894 switch (TREE_CODE (decl_or_origin
))
19900 if (!is_fortran () && !is_ada ())
19902 /* The individual enumerators of an enum type get output when we output
19903 the Dwarf representation of the relevant enum type itself. */
19907 /* Emit its type. */
19908 gen_type_die (TREE_TYPE (decl
), context_die
);
19910 /* And its containing namespace. */
19911 context_die
= declare_in_namespace (decl
, context_die
);
19913 gen_const_die (decl
, context_die
);
19916 case FUNCTION_DECL
:
19917 /* Don't output any DIEs to represent mere function declarations,
19918 unless they are class members or explicit block externs. */
19919 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19920 && DECL_FILE_SCOPE_P (decl_or_origin
)
19921 && (current_function_decl
== NULL_TREE
19922 || DECL_ARTIFICIAL (decl_or_origin
)))
19927 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19928 on local redeclarations of global functions. That seems broken. */
19929 if (current_function_decl
!= decl
)
19930 /* This is only a declaration. */;
19933 /* If we're emitting a clone, emit info for the abstract instance. */
19934 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19935 dwarf2out_abstract_function (origin
19936 ? DECL_ORIGIN (origin
)
19937 : DECL_ABSTRACT_ORIGIN (decl
));
19939 /* If we're emitting an out-of-line copy of an inline function,
19940 emit info for the abstract instance and set up to refer to it. */
19941 else if (cgraph_function_possibly_inlined_p (decl
)
19942 && ! DECL_ABSTRACT (decl
)
19943 && ! class_or_namespace_scope_p (context_die
)
19944 /* dwarf2out_abstract_function won't emit a die if this is just
19945 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19946 that case, because that works only if we have a die. */
19947 && DECL_INITIAL (decl
) != NULL_TREE
)
19949 dwarf2out_abstract_function (decl
);
19950 set_decl_origin_self (decl
);
19953 /* Otherwise we're emitting the primary DIE for this decl. */
19954 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19956 /* Before we describe the FUNCTION_DECL itself, make sure that we
19957 have its containing type. */
19959 origin
= decl_class_context (decl
);
19960 if (origin
!= NULL_TREE
)
19961 gen_type_die (origin
, context_die
);
19963 /* And its return type. */
19964 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19966 /* And its virtual context. */
19967 if (DECL_VINDEX (decl
) != NULL_TREE
)
19968 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19970 /* Make sure we have a member DIE for decl. */
19971 if (origin
!= NULL_TREE
)
19972 gen_type_die_for_member (origin
, decl
, context_die
);
19974 /* And its containing namespace. */
19975 context_die
= declare_in_namespace (decl
, context_die
);
19978 /* Now output a DIE to represent the function itself. */
19980 gen_subprogram_die (decl
, context_die
);
19984 /* If we are in terse mode, don't generate any DIEs to represent any
19985 actual typedefs. */
19986 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19989 /* In the special case of a TYPE_DECL node representing the declaration
19990 of some type tag, if the given TYPE_DECL is marked as having been
19991 instantiated from some other (original) TYPE_DECL node (e.g. one which
19992 was generated within the original definition of an inline function) we
19993 used to generate a special (abbreviated) DW_TAG_structure_type,
19994 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
19995 should be actually referencing those DIEs, as variable DIEs with that
19996 type would be emitted already in the abstract origin, so it was always
19997 removed during unused type prunning. Don't add anything in this
19999 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20002 if (is_redundant_typedef (decl
))
20003 gen_type_die (TREE_TYPE (decl
), context_die
);
20005 /* Output a DIE to represent the typedef itself. */
20006 gen_typedef_die (decl
, context_die
);
20010 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20011 gen_label_die (decl
, context_die
);
20016 /* If we are in terse mode, don't generate any DIEs to represent any
20017 variable declarations or definitions. */
20018 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20021 /* Output any DIEs that are needed to specify the type of this data
20023 if (decl_by_reference_p (decl_or_origin
))
20024 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20026 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20028 /* And its containing type. */
20029 class_origin
= decl_class_context (decl_or_origin
);
20030 if (class_origin
!= NULL_TREE
)
20031 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20033 /* And its containing namespace. */
20034 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20036 /* Now output the DIE to represent the data object itself. This gets
20037 complicated because of the possibility that the VAR_DECL really
20038 represents an inlined instance of a formal parameter for an inline
20040 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20041 if (ultimate_origin
!= NULL_TREE
20042 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20043 gen_formal_parameter_die (decl
, origin
,
20044 true /* Emit name attribute. */,
20047 gen_variable_die (decl
, origin
, context_die
);
20051 /* Ignore the nameless fields that are used to skip bits but handle C++
20052 anonymous unions and structs. */
20053 if (DECL_NAME (decl
) != NULL_TREE
20054 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20055 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20057 gen_type_die (member_declared_type (decl
), context_die
);
20058 gen_field_die (decl
, context_die
);
20063 if (DECL_BY_REFERENCE (decl_or_origin
))
20064 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20066 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20067 return gen_formal_parameter_die (decl
, origin
,
20068 true /* Emit name attribute. */,
20071 case NAMESPACE_DECL
:
20072 case IMPORTED_DECL
:
20073 if (dwarf_version
>= 3 || !dwarf_strict
)
20074 gen_namespace_die (decl
, context_die
);
20078 /* Probably some frontend-internal decl. Assume we don't care. */
20079 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20086 /* Output debug information for global decl DECL. Called from toplev.c after
20087 compilation proper has finished. */
20090 dwarf2out_global_decl (tree decl
)
20092 /* Output DWARF2 information for file-scope tentative data object
20093 declarations, file-scope (extern) function declarations (which
20094 had no corresponding body) and file-scope tagged type declarations
20095 and definitions which have not yet been forced out. */
20096 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20097 dwarf2out_decl (decl
);
20100 /* Output debug information for type decl DECL. Called from toplev.c
20101 and from language front ends (to record built-in types). */
20103 dwarf2out_type_decl (tree decl
, int local
)
20106 dwarf2out_decl (decl
);
20109 /* Output debug information for imported module or decl DECL.
20110 NAME is non-NULL name in the lexical block if the decl has been renamed.
20111 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20112 that DECL belongs to.
20113 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20115 dwarf2out_imported_module_or_decl_1 (tree decl
,
20117 tree lexical_block
,
20118 dw_die_ref lexical_block_die
)
20120 expanded_location xloc
;
20121 dw_die_ref imported_die
= NULL
;
20122 dw_die_ref at_import_die
;
20124 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20126 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20127 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20131 xloc
= expand_location (input_location
);
20133 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20135 at_import_die
= force_type_die (TREE_TYPE (decl
));
20136 /* For namespace N { typedef void T; } using N::T; base_type_die
20137 returns NULL, but DW_TAG_imported_declaration requires
20138 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20139 if (!at_import_die
)
20141 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20142 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20143 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20144 gcc_assert (at_import_die
);
20149 at_import_die
= lookup_decl_die (decl
);
20150 if (!at_import_die
)
20152 /* If we're trying to avoid duplicate debug info, we may not have
20153 emitted the member decl for this field. Emit it now. */
20154 if (TREE_CODE (decl
) == FIELD_DECL
)
20156 tree type
= DECL_CONTEXT (decl
);
20158 if (TYPE_CONTEXT (type
)
20159 && TYPE_P (TYPE_CONTEXT (type
))
20160 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20161 DINFO_USAGE_DIR_USE
))
20163 gen_type_die_for_member (type
, decl
,
20164 get_context_die (TYPE_CONTEXT (type
)));
20166 at_import_die
= force_decl_die (decl
);
20170 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20172 if (dwarf_version
>= 3 || !dwarf_strict
)
20173 imported_die
= new_die (DW_TAG_imported_module
,
20180 imported_die
= new_die (DW_TAG_imported_declaration
,
20184 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20185 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20187 add_AT_string (imported_die
, DW_AT_name
,
20188 IDENTIFIER_POINTER (name
));
20189 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20192 /* Output debug information for imported module or decl DECL.
20193 NAME is non-NULL name in context if the decl has been renamed.
20194 CHILD is true if decl is one of the renamed decls as part of
20195 importing whole module. */
20198 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20201 /* dw_die_ref at_import_die; */
20202 dw_die_ref scope_die
;
20204 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20209 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20210 We need decl DIE for reference and scope die. First, get DIE for the decl
20213 /* Get the scope die for decl context. Use comp_unit_die for global module
20214 or decl. If die is not found for non globals, force new die. */
20216 && TYPE_P (context
)
20217 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20220 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20223 scope_die
= get_context_die (context
);
20227 gcc_assert (scope_die
->die_child
);
20228 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20229 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20230 scope_die
= scope_die
->die_child
;
20233 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20234 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20238 /* Write the debugging output for DECL. */
20241 dwarf2out_decl (tree decl
)
20243 dw_die_ref context_die
= comp_unit_die ();
20245 switch (TREE_CODE (decl
))
20250 case FUNCTION_DECL
:
20251 /* What we would really like to do here is to filter out all mere
20252 file-scope declarations of file-scope functions which are never
20253 referenced later within this translation unit (and keep all of ones
20254 that *are* referenced later on) but we aren't clairvoyant, so we have
20255 no idea which functions will be referenced in the future (i.e. later
20256 on within the current translation unit). So here we just ignore all
20257 file-scope function declarations which are not also definitions. If
20258 and when the debugger needs to know something about these functions,
20259 it will have to hunt around and find the DWARF information associated
20260 with the definition of the function.
20262 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20263 nodes represent definitions and which ones represent mere
20264 declarations. We have to check DECL_INITIAL instead. That's because
20265 the C front-end supports some weird semantics for "extern inline"
20266 function definitions. These can get inlined within the current
20267 translation unit (and thus, we need to generate Dwarf info for their
20268 abstract instances so that the Dwarf info for the concrete inlined
20269 instances can have something to refer to) but the compiler never
20270 generates any out-of-lines instances of such things (despite the fact
20271 that they *are* definitions).
20273 The important point is that the C front-end marks these "extern
20274 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20275 them anyway. Note that the C++ front-end also plays some similar games
20276 for inline function definitions appearing within include files which
20277 also contain `#pragma interface' pragmas.
20279 If we are called from dwarf2out_abstract_function output a DIE
20280 anyway. We can end up here this way with early inlining and LTO
20281 where the inlined function is output in a different LTRANS unit
20283 if (DECL_INITIAL (decl
) == NULL_TREE
20284 && ! DECL_ABSTRACT (decl
))
20287 /* If we're a nested function, initially use a parent of NULL; if we're
20288 a plain function, this will be fixed up in decls_for_scope. If
20289 we're a method, it will be ignored, since we already have a DIE. */
20290 if (decl_function_context (decl
)
20291 /* But if we're in terse mode, we don't care about scope. */
20292 && debug_info_level
> DINFO_LEVEL_TERSE
)
20293 context_die
= NULL
;
20297 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20298 declaration and if the declaration was never even referenced from
20299 within this entire compilation unit. We suppress these DIEs in
20300 order to save space in the .debug section (by eliminating entries
20301 which are probably useless). Note that we must not suppress
20302 block-local extern declarations (whether used or not) because that
20303 would screw-up the debugger's name lookup mechanism and cause it to
20304 miss things which really ought to be in scope at a given point. */
20305 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20308 /* For local statics lookup proper context die. */
20309 if (TREE_STATIC (decl
)
20310 && DECL_CONTEXT (decl
)
20311 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20312 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20314 /* If we are in terse mode, don't generate any DIEs to represent any
20315 variable declarations or definitions. */
20316 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20321 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20323 if (!is_fortran () && !is_ada ())
20325 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20326 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20329 case NAMESPACE_DECL
:
20330 case IMPORTED_DECL
:
20331 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20333 if (lookup_decl_die (decl
) != NULL
)
20338 /* Don't emit stubs for types unless they are needed by other DIEs. */
20339 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20342 /* Don't bother trying to generate any DIEs to represent any of the
20343 normal built-in types for the language we are compiling. */
20344 if (DECL_IS_BUILTIN (decl
))
20347 /* If we are in terse mode, don't generate any DIEs for types. */
20348 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20351 /* If we're a function-scope tag, initially use a parent of NULL;
20352 this will be fixed up in decls_for_scope. */
20353 if (decl_function_context (decl
))
20354 context_die
= NULL
;
20362 gen_decl_die (decl
, NULL
, context_die
);
20365 /* Write the debugging output for DECL. */
20368 dwarf2out_function_decl (tree decl
)
20370 dwarf2out_decl (decl
);
20371 call_arg_locations
= NULL
;
20372 call_arg_loc_last
= NULL
;
20373 call_site_count
= -1;
20374 tail_call_site_count
= -1;
20375 block_map
.release ();
20376 htab_empty (decl_loc_table
);
20377 htab_empty (cached_dw_loc_list_table
);
20380 /* Output a marker (i.e. a label) for the beginning of the generated code for
20381 a lexical block. */
20384 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20385 unsigned int blocknum
)
20387 switch_to_section (current_function_section ());
20388 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20391 /* Output a marker (i.e. a label) for the end of the generated code for a
20395 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20397 switch_to_section (current_function_section ());
20398 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20401 /* Returns nonzero if it is appropriate not to emit any debugging
20402 information for BLOCK, because it doesn't contain any instructions.
20404 Don't allow this for blocks with nested functions or local classes
20405 as we would end up with orphans, and in the presence of scheduling
20406 we may end up calling them anyway. */
20409 dwarf2out_ignore_block (const_tree block
)
20414 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20415 if (TREE_CODE (decl
) == FUNCTION_DECL
20416 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20418 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20420 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20421 if (TREE_CODE (decl
) == FUNCTION_DECL
20422 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20429 /* Hash table routines for file_hash. */
20432 file_table_eq (const void *p1_p
, const void *p2_p
)
20434 const struct dwarf_file_data
*const p1
=
20435 (const struct dwarf_file_data
*) p1_p
;
20436 const char *const p2
= (const char *) p2_p
;
20437 return filename_cmp (p1
->filename
, p2
) == 0;
20441 file_table_hash (const void *p_p
)
20443 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20444 return htab_hash_string (p
->filename
);
20447 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20448 dwarf2out.c) and return its "index". The index of each (known) filename is
20449 just a unique number which is associated with only that one filename. We
20450 need such numbers for the sake of generating labels (in the .debug_sfnames
20451 section) and references to those files numbers (in the .debug_srcinfo
20452 and.debug_macinfo sections). If the filename given as an argument is not
20453 found in our current list, add it to the list and assign it the next
20454 available unique index number. In order to speed up searches, we remember
20455 the index of the filename was looked up last. This handles the majority of
20458 static struct dwarf_file_data
*
20459 lookup_filename (const char *file_name
)
20462 struct dwarf_file_data
* created
;
20464 /* Check to see if the file name that was searched on the previous
20465 call matches this file name. If so, return the index. */
20466 if (file_table_last_lookup
20467 && (file_name
== file_table_last_lookup
->filename
20468 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20469 return file_table_last_lookup
;
20471 /* Didn't match the previous lookup, search the table. */
20472 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20473 htab_hash_string (file_name
), INSERT
);
20475 return (struct dwarf_file_data
*) *slot
;
20477 created
= ggc_alloc_dwarf_file_data ();
20478 created
->filename
= file_name
;
20479 created
->emitted_number
= 0;
20484 /* If the assembler will construct the file table, then translate the compiler
20485 internal file table number into the assembler file table number, and emit
20486 a .file directive if we haven't already emitted one yet. The file table
20487 numbers are different because we prune debug info for unused variables and
20488 types, which may include filenames. */
20491 maybe_emit_file (struct dwarf_file_data
* fd
)
20493 if (! fd
->emitted_number
)
20495 if (last_emitted_file
)
20496 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20498 fd
->emitted_number
= 1;
20499 last_emitted_file
= fd
;
20501 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20503 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20504 output_quoted_string (asm_out_file
,
20505 remap_debug_filename (fd
->filename
));
20506 fputc ('\n', asm_out_file
);
20510 return fd
->emitted_number
;
20513 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20514 That generation should happen after function debug info has been
20515 generated. The value of the attribute is the constant value of ARG. */
20518 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20520 die_arg_entry entry
;
20525 if (!tmpl_value_parm_die_table
)
20526 vec_alloc (tmpl_value_parm_die_table
, 32);
20530 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20533 /* Return TRUE if T is an instance of generic type, FALSE
20537 generic_type_p (tree t
)
20539 if (t
== NULL_TREE
|| !TYPE_P (t
))
20541 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20544 /* Schedule the generation of the generic parameter dies for the
20545 instance of generic type T. The proper generation itself is later
20546 done by gen_scheduled_generic_parms_dies. */
20549 schedule_generic_params_dies_gen (tree t
)
20551 if (!generic_type_p (t
))
20554 if (!generic_type_instances
)
20555 vec_alloc (generic_type_instances
, 256);
20557 vec_safe_push (generic_type_instances
, t
);
20560 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20561 by append_entry_to_tmpl_value_parm_die_table. This function must
20562 be called after function DIEs have been generated. */
20565 gen_remaining_tmpl_value_param_die_attribute (void)
20567 if (tmpl_value_parm_die_table
)
20572 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20573 tree_add_const_value_attribute (e
->die
, e
->arg
);
20577 /* Generate generic parameters DIEs for instances of generic types
20578 that have been previously scheduled by
20579 schedule_generic_params_dies_gen. This function must be called
20580 after all the types of the CU have been laid out. */
20583 gen_scheduled_generic_parms_dies (void)
20588 if (!generic_type_instances
)
20591 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20592 gen_generic_params_dies (t
);
20596 /* Replace DW_AT_name for the decl with name. */
20599 dwarf2out_set_name (tree decl
, tree name
)
20605 die
= TYPE_SYMTAB_DIE (decl
);
20609 dname
= dwarf2_name (name
, 0);
20613 attr
= get_AT (die
, DW_AT_name
);
20616 struct indirect_string_node
*node
;
20618 node
= find_AT_string (dname
);
20619 /* replace the string. */
20620 attr
->dw_attr_val
.v
.val_str
= node
;
20624 add_name_attribute (die
, dname
);
20627 /* Called by the final INSN scan whenever we see a var location. We
20628 use it to drop labels in the right places, and throw the location in
20629 our lookup table. */
20632 dwarf2out_var_location (rtx loc_note
)
20634 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20635 struct var_loc_node
*newloc
;
20636 rtx next_real
, next_note
;
20637 static const char *last_label
;
20638 static const char *last_postcall_label
;
20639 static bool last_in_cold_section_p
;
20640 static rtx expected_next_loc_note
;
20644 if (!NOTE_P (loc_note
))
20646 if (CALL_P (loc_note
))
20649 if (SIBLING_CALL_P (loc_note
))
20650 tail_call_site_count
++;
20655 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20656 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20659 /* Optimize processing a large consecutive sequence of location
20660 notes so we don't spend too much time in next_real_insn. If the
20661 next insn is another location note, remember the next_real_insn
20662 calculation for next time. */
20663 next_real
= cached_next_real_insn
;
20666 if (expected_next_loc_note
!= loc_note
)
20667 next_real
= NULL_RTX
;
20670 next_note
= NEXT_INSN (loc_note
);
20672 || INSN_DELETED_P (next_note
)
20673 || GET_CODE (next_note
) != NOTE
20674 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20675 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20676 next_note
= NULL_RTX
;
20679 next_real
= next_real_insn (loc_note
);
20683 expected_next_loc_note
= next_note
;
20684 cached_next_real_insn
= next_real
;
20687 cached_next_real_insn
= NULL_RTX
;
20689 /* If there are no instructions which would be affected by this note,
20690 don't do anything. */
20692 && next_real
== NULL_RTX
20693 && !NOTE_DURING_CALL_P (loc_note
))
20696 if (next_real
== NULL_RTX
)
20697 next_real
= get_last_insn ();
20699 /* If there were any real insns between note we processed last time
20700 and this note (or if it is the first note), clear
20701 last_{,postcall_}label so that they are not reused this time. */
20702 if (last_var_location_insn
== NULL_RTX
20703 || last_var_location_insn
!= next_real
20704 || last_in_cold_section_p
!= in_cold_section_p
)
20707 last_postcall_label
= NULL
;
20712 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20713 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20714 NOTE_DURING_CALL_P (loc_note
)
20715 ? last_postcall_label
: last_label
);
20716 if (newloc
== NULL
)
20725 /* If there were no real insns between note we processed last time
20726 and this note, use the label we emitted last time. Otherwise
20727 create a new label and emit it. */
20728 if (last_label
== NULL
)
20730 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20731 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20733 last_label
= ggc_strdup (loclabel
);
20738 struct call_arg_loc_node
*ca_loc
20739 = ggc_alloc_cleared_call_arg_loc_node ();
20740 rtx prev
= prev_real_insn (loc_note
), x
;
20741 ca_loc
->call_arg_loc_note
= loc_note
;
20742 ca_loc
->next
= NULL
;
20743 ca_loc
->label
= last_label
;
20746 || (NONJUMP_INSN_P (prev
)
20747 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20748 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20749 if (!CALL_P (prev
))
20750 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20751 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20752 x
= get_call_rtx_from (PATTERN (prev
));
20755 x
= XEXP (XEXP (x
, 0), 0);
20756 if (GET_CODE (x
) == SYMBOL_REF
20757 && SYMBOL_REF_DECL (x
)
20758 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20759 ca_loc
->symbol_ref
= x
;
20761 ca_loc
->block
= insn_scope (prev
);
20762 if (call_arg_locations
)
20763 call_arg_loc_last
->next
= ca_loc
;
20765 call_arg_locations
= ca_loc
;
20766 call_arg_loc_last
= ca_loc
;
20768 else if (!NOTE_DURING_CALL_P (loc_note
))
20769 newloc
->label
= last_label
;
20772 if (!last_postcall_label
)
20774 sprintf (loclabel
, "%s-1", last_label
);
20775 last_postcall_label
= ggc_strdup (loclabel
);
20777 newloc
->label
= last_postcall_label
;
20780 last_var_location_insn
= next_real
;
20781 last_in_cold_section_p
= in_cold_section_p
;
20784 /* Note in one location list that text section has changed. */
20787 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20789 var_loc_list
*list
= (var_loc_list
*) *slot
;
20791 list
->last_before_switch
20792 = list
->last
->next
? list
->last
->next
: list
->last
;
20796 /* Note in all location lists that text section has changed. */
20799 var_location_switch_text_section (void)
20801 if (decl_loc_table
== NULL
)
20804 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20807 /* Create a new line number table. */
20809 static dw_line_info_table
*
20810 new_line_info_table (void)
20812 dw_line_info_table
*table
;
20814 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20815 table
->file_num
= 1;
20816 table
->line_num
= 1;
20817 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20822 /* Lookup the "current" table into which we emit line info, so
20823 that we don't have to do it for every source line. */
20826 set_cur_line_info_table (section
*sec
)
20828 dw_line_info_table
*table
;
20830 if (sec
== text_section
)
20831 table
= text_section_line_info
;
20832 else if (sec
== cold_text_section
)
20834 table
= cold_text_section_line_info
;
20837 cold_text_section_line_info
= table
= new_line_info_table ();
20838 table
->end_label
= cold_end_label
;
20843 const char *end_label
;
20845 if (flag_reorder_blocks_and_partition
)
20847 if (in_cold_section_p
)
20848 end_label
= crtl
->subsections
.cold_section_end_label
;
20850 end_label
= crtl
->subsections
.hot_section_end_label
;
20854 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20855 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20856 current_function_funcdef_no
);
20857 end_label
= ggc_strdup (label
);
20860 table
= new_line_info_table ();
20861 table
->end_label
= end_label
;
20863 vec_safe_push (separate_line_info
, table
);
20866 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20867 table
->is_stmt
= (cur_line_info_table
20868 ? cur_line_info_table
->is_stmt
20869 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20870 cur_line_info_table
= table
;
20874 /* We need to reset the locations at the beginning of each
20875 function. We can't do this in the end_function hook, because the
20876 declarations that use the locations won't have been output when
20877 that hook is called. Also compute have_multiple_function_sections here. */
20880 dwarf2out_begin_function (tree fun
)
20882 section
*sec
= function_section (fun
);
20884 if (sec
!= text_section
)
20885 have_multiple_function_sections
= true;
20887 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20889 gcc_assert (current_function_decl
== fun
);
20890 cold_text_section
= unlikely_text_section ();
20891 switch_to_section (cold_text_section
);
20892 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20893 switch_to_section (sec
);
20896 dwarf2out_note_section_used ();
20897 call_site_count
= 0;
20898 tail_call_site_count
= 0;
20900 set_cur_line_info_table (sec
);
20903 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20906 push_dw_line_info_entry (dw_line_info_table
*table
,
20907 enum dw_line_info_opcode opcode
, unsigned int val
)
20909 dw_line_info_entry e
;
20912 vec_safe_push (table
->entries
, e
);
20915 /* Output a label to mark the beginning of a source code line entry
20916 and record information relating to this source line, in
20917 'line_info_table' for later output of the .debug_line section. */
20918 /* ??? The discriminator parameter ought to be unsigned. */
20921 dwarf2out_source_line (unsigned int line
, const char *filename
,
20922 int discriminator
, bool is_stmt
)
20924 unsigned int file_num
;
20925 dw_line_info_table
*table
;
20927 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20930 /* The discriminator column was added in dwarf4. Simplify the below
20931 by simply removing it if we're not supposed to output it. */
20932 if (dwarf_version
< 4 && dwarf_strict
)
20935 table
= cur_line_info_table
;
20936 file_num
= maybe_emit_file (lookup_filename (filename
));
20938 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20939 the debugger has used the second (possibly duplicate) line number
20940 at the beginning of the function to mark the end of the prologue.
20941 We could eliminate any other duplicates within the function. For
20942 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20943 that second line number entry. */
20944 /* Recall that this end-of-prologue indication is *not* the same thing
20945 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20946 to which the hook corresponds, follows the last insn that was
20947 emitted by gen_prologue. What we need is to precede the first insn
20948 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20949 insn that corresponds to something the user wrote. These may be
20950 very different locations once scheduling is enabled. */
20952 if (0 && file_num
== table
->file_num
20953 && line
== table
->line_num
20954 && discriminator
== table
->discrim_num
20955 && is_stmt
== table
->is_stmt
)
20958 switch_to_section (current_function_section ());
20960 /* If requested, emit something human-readable. */
20961 if (flag_debug_asm
)
20962 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
20964 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20966 /* Emit the .loc directive understood by GNU as. */
20967 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
20968 file_num, line, is_stmt, discriminator */
20969 fputs ("\t.loc ", asm_out_file
);
20970 fprint_ul (asm_out_file
, file_num
);
20971 putc (' ', asm_out_file
);
20972 fprint_ul (asm_out_file
, line
);
20973 putc (' ', asm_out_file
);
20974 putc ('0', asm_out_file
);
20976 if (is_stmt
!= table
->is_stmt
)
20978 fputs (" is_stmt ", asm_out_file
);
20979 putc (is_stmt
? '1' : '0', asm_out_file
);
20981 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
20983 gcc_assert (discriminator
> 0);
20984 fputs (" discriminator ", asm_out_file
);
20985 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
20987 putc ('\n', asm_out_file
);
20991 unsigned int label_num
= ++line_info_label_num
;
20993 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
20995 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
20996 if (file_num
!= table
->file_num
)
20997 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
20998 if (discriminator
!= table
->discrim_num
)
20999 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21000 if (is_stmt
!= table
->is_stmt
)
21001 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21002 push_dw_line_info_entry (table
, LI_set_line
, line
);
21005 table
->file_num
= file_num
;
21006 table
->line_num
= line
;
21007 table
->discrim_num
= discriminator
;
21008 table
->is_stmt
= is_stmt
;
21009 table
->in_use
= true;
21012 /* Record the beginning of a new source file. */
21015 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21017 if (flag_eliminate_dwarf2_dups
)
21019 /* Record the beginning of the file for break_out_includes. */
21020 dw_die_ref bincl_die
;
21022 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21023 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21026 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21029 e
.code
= DW_MACINFO_start_file
;
21031 e
.info
= ggc_strdup (filename
);
21032 vec_safe_push (macinfo_table
, e
);
21036 /* Record the end of a source file. */
21039 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21041 if (flag_eliminate_dwarf2_dups
)
21042 /* Record the end of the file for break_out_includes. */
21043 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21045 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21048 e
.code
= DW_MACINFO_end_file
;
21051 vec_safe_push (macinfo_table
, e
);
21055 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21056 the tail part of the directive line, i.e. the part which is past the
21057 initial whitespace, #, whitespace, directive-name, whitespace part. */
21060 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21061 const char *buffer ATTRIBUTE_UNUSED
)
21063 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21066 /* Insert a dummy first entry to be able to optimize the whole
21067 predefined macro block using DW_MACRO_GNU_transparent_include. */
21068 if (macinfo_table
->is_empty () && lineno
<= 1)
21073 vec_safe_push (macinfo_table
, e
);
21075 e
.code
= DW_MACINFO_define
;
21077 e
.info
= ggc_strdup (buffer
);
21078 vec_safe_push (macinfo_table
, e
);
21082 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21083 the tail part of the directive line, i.e. the part which is past the
21084 initial whitespace, #, whitespace, directive-name, whitespace part. */
21087 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21088 const char *buffer ATTRIBUTE_UNUSED
)
21090 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21093 /* Insert a dummy first entry to be able to optimize the whole
21094 predefined macro block using DW_MACRO_GNU_transparent_include. */
21095 if (macinfo_table
->is_empty () && lineno
<= 1)
21100 vec_safe_push (macinfo_table
, e
);
21102 e
.code
= DW_MACINFO_undef
;
21104 e
.info
= ggc_strdup (buffer
);
21105 vec_safe_push (macinfo_table
, e
);
21109 /* Routines to manipulate hash table of CUs. */
21112 htab_macinfo_hash (const void *of
)
21114 const macinfo_entry
*const entry
=
21115 (const macinfo_entry
*) of
;
21117 return htab_hash_string (entry
->info
);
21121 htab_macinfo_eq (const void *of1
, const void *of2
)
21123 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21124 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21126 return !strcmp (entry1
->info
, entry2
->info
);
21129 /* Output a single .debug_macinfo entry. */
21132 output_macinfo_op (macinfo_entry
*ref
)
21136 struct indirect_string_node
*node
;
21137 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21138 struct dwarf_file_data
*fd
;
21142 case DW_MACINFO_start_file
:
21143 fd
= lookup_filename (ref
->info
);
21144 file_num
= maybe_emit_file (fd
);
21145 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21146 dw2_asm_output_data_uleb128 (ref
->lineno
,
21147 "Included from line number %lu",
21148 (unsigned long) ref
->lineno
);
21149 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21151 case DW_MACINFO_end_file
:
21152 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21154 case DW_MACINFO_define
:
21155 case DW_MACINFO_undef
:
21156 len
= strlen (ref
->info
) + 1;
21158 && len
> DWARF_OFFSET_SIZE
21159 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21160 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21162 ref
->code
= ref
->code
== DW_MACINFO_define
21163 ? DW_MACRO_GNU_define_indirect
21164 : DW_MACRO_GNU_undef_indirect
;
21165 output_macinfo_op (ref
);
21168 dw2_asm_output_data (1, ref
->code
,
21169 ref
->code
== DW_MACINFO_define
21170 ? "Define macro" : "Undefine macro");
21171 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21172 (unsigned long) ref
->lineno
);
21173 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21175 case DW_MACRO_GNU_define_indirect
:
21176 case DW_MACRO_GNU_undef_indirect
:
21177 node
= find_AT_string (ref
->info
);
21179 && ((node
->form
== DW_FORM_strp
)
21180 || (node
->form
== DW_FORM_GNU_str_index
)));
21181 dw2_asm_output_data (1, ref
->code
,
21182 ref
->code
== DW_MACRO_GNU_define_indirect
21183 ? "Define macro indirect"
21184 : "Undefine macro indirect");
21185 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21186 (unsigned long) ref
->lineno
);
21187 if (node
->form
== DW_FORM_strp
)
21188 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21189 debug_str_section
, "The macro: \"%s\"",
21192 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21195 case DW_MACRO_GNU_transparent_include
:
21196 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21197 ASM_GENERATE_INTERNAL_LABEL (label
,
21198 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21199 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21202 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21203 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21208 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21209 other compilation unit .debug_macinfo sections. IDX is the first
21210 index of a define/undef, return the number of ops that should be
21211 emitted in a comdat .debug_macinfo section and emit
21212 a DW_MACRO_GNU_transparent_include entry referencing it.
21213 If the define/undef entry should be emitted normally, return 0. */
21216 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21217 htab_t
*macinfo_htab
)
21219 macinfo_entry
*first
, *second
, *cur
, *inc
;
21220 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21221 unsigned char checksum
[16];
21222 struct md5_ctx ctx
;
21223 char *grp_name
, *tail
;
21225 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21228 first
= &(*macinfo_table
)[idx
];
21229 second
= &(*macinfo_table
)[idx
+ 1];
21231 /* Optimize only if there are at least two consecutive define/undef ops,
21232 and either all of them are before first DW_MACINFO_start_file
21233 with lineno {0,1} (i.e. predefined macro block), or all of them are
21234 in some included header file. */
21235 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21237 if (vec_safe_is_empty (files
))
21239 if (first
->lineno
> 1 || second
->lineno
> 1)
21242 else if (first
->lineno
== 0)
21245 /* Find the last define/undef entry that can be grouped together
21246 with first and at the same time compute md5 checksum of their
21247 codes, linenumbers and strings. */
21248 md5_init_ctx (&ctx
);
21249 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21250 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21252 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21256 unsigned char code
= cur
->code
;
21257 md5_process_bytes (&code
, 1, &ctx
);
21258 checksum_uleb128 (cur
->lineno
, &ctx
);
21259 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21261 md5_finish_ctx (&ctx
, checksum
);
21264 /* From the containing include filename (if any) pick up just
21265 usable characters from its basename. */
21266 if (vec_safe_is_empty (files
))
21269 base
= lbasename (files
->last ().info
);
21270 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21271 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21272 encoded_filename_len
++;
21273 /* Count . at the end. */
21274 if (encoded_filename_len
)
21275 encoded_filename_len
++;
21277 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21278 linebuf_len
= strlen (linebuf
);
21280 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21281 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21283 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21284 tail
= grp_name
+ 4;
21285 if (encoded_filename_len
)
21287 for (i
= 0; base
[i
]; i
++)
21288 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21292 memcpy (tail
, linebuf
, linebuf_len
);
21293 tail
+= linebuf_len
;
21295 for (i
= 0; i
< 16; i
++)
21296 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21298 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21299 in the empty vector entry before the first define/undef. */
21300 inc
= &(*macinfo_table
)[idx
- 1];
21301 inc
->code
= DW_MACRO_GNU_transparent_include
;
21303 inc
->info
= ggc_strdup (grp_name
);
21304 if (*macinfo_htab
== NULL
)
21305 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21306 /* Avoid emitting duplicates. */
21307 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21312 /* If such an entry has been used before, just emit
21313 a DW_MACRO_GNU_transparent_include op. */
21314 inc
= (macinfo_entry
*) *slot
;
21315 output_macinfo_op (inc
);
21316 /* And clear all macinfo_entry in the range to avoid emitting them
21317 in the second pass. */
21318 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21327 inc
->lineno
= htab_elements (*macinfo_htab
);
21328 output_macinfo_op (inc
);
21333 /* Save any strings needed by the macinfo table in the debug str
21334 table. All strings must be collected into the table by the time
21335 index_string is called. */
21338 save_macinfo_strings (void)
21342 macinfo_entry
*ref
;
21344 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21348 /* Match the logic in output_macinfo_op to decide on
21349 indirect strings. */
21350 case DW_MACINFO_define
:
21351 case DW_MACINFO_undef
:
21352 len
= strlen (ref
->info
) + 1;
21354 && len
> DWARF_OFFSET_SIZE
21355 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21356 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21357 set_indirect_string (find_AT_string (ref
->info
));
21359 case DW_MACRO_GNU_define_indirect
:
21360 case DW_MACRO_GNU_undef_indirect
:
21361 set_indirect_string (find_AT_string (ref
->info
));
21369 /* Output macinfo section(s). */
21372 output_macinfo (void)
21375 unsigned long length
= vec_safe_length (macinfo_table
);
21376 macinfo_entry
*ref
;
21377 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21378 htab_t macinfo_htab
= NULL
;
21383 /* output_macinfo* uses these interchangeably. */
21384 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21385 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21386 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21387 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21389 /* For .debug_macro emit the section header. */
21392 dw2_asm_output_data (2, 4, "DWARF macro version number");
21393 if (DWARF_OFFSET_SIZE
== 8)
21394 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21396 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21397 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21398 (!dwarf_split_debug_info
? debug_line_section_label
21399 : debug_skeleton_line_section_label
),
21400 debug_line_section
, NULL
);
21403 /* In the first loop, it emits the primary .debug_macinfo section
21404 and after each emitted op the macinfo_entry is cleared.
21405 If a longer range of define/undef ops can be optimized using
21406 DW_MACRO_GNU_transparent_include, the
21407 DW_MACRO_GNU_transparent_include op is emitted and kept in
21408 the vector before the first define/undef in the range and the
21409 whole range of define/undef ops is not emitted and kept. */
21410 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21414 case DW_MACINFO_start_file
:
21415 vec_safe_push (files
, *ref
);
21417 case DW_MACINFO_end_file
:
21418 if (!vec_safe_is_empty (files
))
21421 case DW_MACINFO_define
:
21422 case DW_MACINFO_undef
:
21424 && HAVE_COMDAT_GROUP
21425 && vec_safe_length (files
) != 1
21428 && (*macinfo_table
)[i
- 1].code
== 0)
21430 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21439 /* A dummy entry may be inserted at the beginning to be able
21440 to optimize the whole block of predefined macros. */
21446 output_macinfo_op (ref
);
21451 if (macinfo_htab
== NULL
)
21454 htab_delete (macinfo_htab
);
21456 /* If any DW_MACRO_GNU_transparent_include were used, on those
21457 DW_MACRO_GNU_transparent_include entries terminate the
21458 current chain and switch to a new comdat .debug_macinfo
21459 section and emit the define/undef entries within it. */
21460 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21465 case DW_MACRO_GNU_transparent_include
:
21467 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21468 tree comdat_key
= get_identifier (ref
->info
);
21469 /* Terminate the previous .debug_macinfo section. */
21470 dw2_asm_output_data (1, 0, "End compilation unit");
21471 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21473 | SECTION_LINKONCE
,
21475 ASM_GENERATE_INTERNAL_LABEL (label
,
21476 DEBUG_MACRO_SECTION_LABEL
,
21478 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21481 dw2_asm_output_data (2, 4, "DWARF macro version number");
21482 if (DWARF_OFFSET_SIZE
== 8)
21483 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21485 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21488 case DW_MACINFO_define
:
21489 case DW_MACINFO_undef
:
21490 output_macinfo_op (ref
);
21495 gcc_unreachable ();
21499 /* Set up for Dwarf output at the start of compilation. */
21502 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21504 /* Allocate the file_table. */
21505 file_table
= htab_create_ggc (50, file_table_hash
,
21506 file_table_eq
, NULL
);
21508 /* Allocate the decl_die_table. */
21509 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21510 decl_die_table_eq
, NULL
);
21512 /* Allocate the decl_loc_table. */
21513 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21514 decl_loc_table_eq
, NULL
);
21516 /* Allocate the cached_dw_loc_list_table. */
21517 cached_dw_loc_list_table
21518 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21519 cached_dw_loc_list_table_eq
, NULL
);
21521 /* Allocate the initial hunk of the decl_scope_table. */
21522 vec_alloc (decl_scope_table
, 256);
21524 /* Allocate the initial hunk of the abbrev_die_table. */
21525 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21526 (ABBREV_DIE_TABLE_INCREMENT
);
21527 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21528 /* Zero-th entry is allocated, but unused. */
21529 abbrev_die_table_in_use
= 1;
21531 /* Allocate the pubtypes and pubnames vectors. */
21532 vec_alloc (pubname_table
, 32);
21533 vec_alloc (pubtype_table
, 32);
21535 vec_alloc (incomplete_types
, 64);
21537 vec_alloc (used_rtx_array
, 32);
21539 if (!dwarf_split_debug_info
)
21541 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21542 SECTION_DEBUG
, NULL
);
21543 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21544 SECTION_DEBUG
, NULL
);
21545 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21546 SECTION_DEBUG
, NULL
);
21550 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21551 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21552 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21553 SECTION_DEBUG
| SECTION_EXCLUDE
,
21555 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21556 SECTION_DEBUG
, NULL
);
21557 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21558 SECTION_DEBUG
, NULL
);
21559 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21560 SECTION_DEBUG
, NULL
);
21561 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21562 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21564 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21565 the main .o, but the skeleton_line goes into the split off dwo. */
21566 debug_skeleton_line_section
21567 = get_section (DEBUG_DWO_LINE_SECTION
,
21568 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21569 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21570 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21571 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21572 SECTION_DEBUG
| SECTION_EXCLUDE
,
21574 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21575 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21576 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21577 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21579 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21580 SECTION_DEBUG
, NULL
);
21581 debug_macinfo_section
= get_section (dwarf_strict
21582 ? DEBUG_MACINFO_SECTION
21583 : DEBUG_MACRO_SECTION
,
21584 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21585 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21586 SECTION_DEBUG
, NULL
);
21587 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21588 SECTION_DEBUG
, NULL
);
21589 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21590 SECTION_DEBUG
, NULL
);
21591 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21592 DEBUG_STR_SECTION_FLAGS
, NULL
);
21593 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21594 SECTION_DEBUG
, NULL
);
21595 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21596 SECTION_DEBUG
, NULL
);
21598 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21599 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21600 DEBUG_ABBREV_SECTION_LABEL
, 0);
21601 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21602 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21603 COLD_TEXT_SECTION_LABEL
, 0);
21604 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21606 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21607 DEBUG_INFO_SECTION_LABEL
, 0);
21608 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21609 DEBUG_LINE_SECTION_LABEL
, 0);
21610 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21611 DEBUG_RANGES_SECTION_LABEL
, 0);
21612 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21613 DEBUG_ADDR_SECTION_LABEL
, 0);
21614 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21616 ? DEBUG_MACINFO_SECTION_LABEL
21617 : DEBUG_MACRO_SECTION_LABEL
, 0);
21618 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21620 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21621 vec_alloc (macinfo_table
, 64);
21623 switch_to_section (text_section
);
21624 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21626 /* Make sure the line number table for .text always exists. */
21627 text_section_line_info
= new_line_info_table ();
21628 text_section_line_info
->end_label
= text_end_label
;
21631 /* Called before compile () starts outputtting functions, variables
21632 and toplevel asms into assembly. */
21635 dwarf2out_assembly_start (void)
21637 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21638 && dwarf2out_do_cfi_asm ()
21639 && (!(flag_unwind_tables
|| flag_exceptions
)
21640 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21641 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21644 /* A helper function for dwarf2out_finish called through
21645 htab_traverse. Assign a string its index. All strings must be
21646 collected into the table by the time index_string is called,
21647 because the indexing code relies on htab_traverse to traverse nodes
21648 in the same order for each run. */
21651 index_string (void **h
, void *v
)
21653 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21654 unsigned int *index
= (unsigned int *) v
;
21656 find_string_form (node
);
21657 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21659 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21660 node
->index
= *index
;
21666 /* A helper function for output_indirect_strings called through
21667 htab_traverse. Output the offset to a string and update the
21671 output_index_string_offset (void **h
, void *v
)
21673 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21674 unsigned int *offset
= (unsigned int *) v
;
21676 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21678 /* Assert that this node has been assigned an index. */
21679 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21680 && node
->index
!= NOT_INDEXED
);
21681 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21682 "indexed string 0x%x: %s", node
->index
, node
->str
);
21683 *offset
+= strlen (node
->str
) + 1;
21688 /* A helper function for dwarf2out_finish called through
21689 htab_traverse. Output the indexed string. */
21692 output_index_string (void **h
, void *v
)
21694 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21695 unsigned int *cur_idx
= (unsigned int *) v
;
21697 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21699 /* Assert that the strings are output in the same order as their
21700 indexes were assigned. */
21701 gcc_assert (*cur_idx
== node
->index
);
21702 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21703 assemble_string (node
->str
, strlen (node
->str
) + 1);
21709 /* A helper function for dwarf2out_finish called through
21710 htab_traverse. Emit one queued .debug_str string. */
21713 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21715 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21717 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
21719 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21720 assemble_string (node
->str
, strlen (node
->str
) + 1);
21726 /* Output the indexed string table. */
21729 output_indirect_strings (void)
21731 if (!dwarf_split_debug_info
)
21733 switch_to_section (debug_str_section
);
21734 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
21738 unsigned int offset
= 0;
21739 unsigned int cur_idx
= 0;
21741 switch_to_section (debug_str_offsets_section
);
21742 htab_traverse_noresize (debug_str_hash
,
21743 output_index_string_offset
,
21745 switch_to_section (debug_str_section
);
21746 htab_traverse_noresize (debug_str_hash
,
21747 output_index_string
,
21752 /* Callback for htab_traverse to assign an index to an entry in the
21753 table, and to write that entry to the .debug_addr section. */
21756 output_addr_table_entry (void **slot
, void *data
)
21758 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
21759 unsigned int *cur_index
= (unsigned int *)data
;
21761 if (entry
->refcount
== 0)
21763 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
21764 || entry
->index
== NOT_INDEXED
);
21768 gcc_assert (entry
->index
== *cur_index
);
21771 switch (entry
->kind
)
21774 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
21775 "0x%x", entry
->index
);
21777 case ate_kind_rtx_dtprel
:
21778 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
21779 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
21782 fputc ('\n', asm_out_file
);
21784 case ate_kind_label
:
21785 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
21786 "0x%x", entry
->index
);
21789 gcc_unreachable ();
21794 /* Produce the .debug_addr section. */
21797 output_addr_table (void)
21799 unsigned int index
= 0;
21800 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
21803 switch_to_section (debug_addr_section
);
21804 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
21807 #if ENABLE_ASSERT_CHECKING
21808 /* Verify that all marks are clear. */
21811 verify_marks_clear (dw_die_ref die
)
21815 gcc_assert (! die
->die_mark
);
21816 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21818 #endif /* ENABLE_ASSERT_CHECKING */
21820 /* Clear the marks for a die and its children.
21821 Be cool if the mark isn't set. */
21824 prune_unmark_dies (dw_die_ref die
)
21830 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21833 /* Given DIE that we're marking as used, find any other dies
21834 it references as attributes and mark them as used. */
21837 prune_unused_types_walk_attribs (dw_die_ref die
)
21842 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
21844 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21846 /* A reference to another DIE.
21847 Make sure that it will get emitted.
21848 If it was broken out into a comdat group, don't follow it. */
21849 if (! AT_ref (a
)->comdat_type_p
21850 || a
->dw_attr
== DW_AT_specification
)
21851 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21853 /* Set the string's refcount to 0 so that prune_unused_types_mark
21854 accounts properly for it. */
21855 if (AT_class (a
) == dw_val_class_str
)
21856 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21860 /* Mark the generic parameters and arguments children DIEs of DIE. */
21863 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21867 if (die
== NULL
|| die
->die_child
== NULL
)
21869 c
= die
->die_child
;
21872 switch (c
->die_tag
)
21874 case DW_TAG_template_type_param
:
21875 case DW_TAG_template_value_param
:
21876 case DW_TAG_GNU_template_template_param
:
21877 case DW_TAG_GNU_template_parameter_pack
:
21878 prune_unused_types_mark (c
, 1);
21884 } while (c
&& c
!= die
->die_child
);
21887 /* Mark DIE as being used. If DOKIDS is true, then walk down
21888 to DIE's children. */
21891 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21895 if (die
->die_mark
== 0)
21897 /* We haven't done this node yet. Mark it as used. */
21899 /* If this is the DIE of a generic type instantiation,
21900 mark the children DIEs that describe its generic parms and
21902 prune_unused_types_mark_generic_parms_dies (die
);
21904 /* We also have to mark its parents as used.
21905 (But we don't want to mark our parents' kids due to this.) */
21906 if (die
->die_parent
)
21907 prune_unused_types_mark (die
->die_parent
, 0);
21909 /* Mark any referenced nodes. */
21910 prune_unused_types_walk_attribs (die
);
21912 /* If this node is a specification,
21913 also mark the definition, if it exists. */
21914 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21915 prune_unused_types_mark (die
->die_definition
, 1);
21918 if (dokids
&& die
->die_mark
!= 2)
21920 /* We need to walk the children, but haven't done so yet.
21921 Remember that we've walked the kids. */
21924 /* If this is an array type, we need to make sure our
21925 kids get marked, even if they're types. If we're
21926 breaking out types into comdat sections, do this
21927 for all type definitions. */
21928 if (die
->die_tag
== DW_TAG_array_type
21929 || (use_debug_types
21930 && is_type_die (die
) && ! is_declaration_die (die
)))
21931 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21933 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21937 /* For local classes, look if any static member functions were emitted
21938 and if so, mark them. */
21941 prune_unused_types_walk_local_classes (dw_die_ref die
)
21945 if (die
->die_mark
== 2)
21948 switch (die
->die_tag
)
21950 case DW_TAG_structure_type
:
21951 case DW_TAG_union_type
:
21952 case DW_TAG_class_type
:
21955 case DW_TAG_subprogram
:
21956 if (!get_AT_flag (die
, DW_AT_declaration
)
21957 || die
->die_definition
!= NULL
)
21958 prune_unused_types_mark (die
, 1);
21965 /* Mark children. */
21966 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
21969 /* Walk the tree DIE and mark types that we actually use. */
21972 prune_unused_types_walk (dw_die_ref die
)
21976 /* Don't do anything if this node is already marked and
21977 children have been marked as well. */
21978 if (die
->die_mark
== 2)
21981 switch (die
->die_tag
)
21983 case DW_TAG_structure_type
:
21984 case DW_TAG_union_type
:
21985 case DW_TAG_class_type
:
21986 if (die
->die_perennial_p
)
21989 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
21990 if (c
->die_tag
== DW_TAG_subprogram
)
21993 /* Finding used static member functions inside of classes
21994 is needed just for local classes, because for other classes
21995 static member function DIEs with DW_AT_specification
21996 are emitted outside of the DW_TAG_*_type. If we ever change
21997 it, we'd need to call this even for non-local classes. */
21999 prune_unused_types_walk_local_classes (die
);
22001 /* It's a type node --- don't mark it. */
22004 case DW_TAG_const_type
:
22005 case DW_TAG_packed_type
:
22006 case DW_TAG_pointer_type
:
22007 case DW_TAG_reference_type
:
22008 case DW_TAG_rvalue_reference_type
:
22009 case DW_TAG_volatile_type
:
22010 case DW_TAG_typedef
:
22011 case DW_TAG_array_type
:
22012 case DW_TAG_interface_type
:
22013 case DW_TAG_friend
:
22014 case DW_TAG_variant_part
:
22015 case DW_TAG_enumeration_type
:
22016 case DW_TAG_subroutine_type
:
22017 case DW_TAG_string_type
:
22018 case DW_TAG_set_type
:
22019 case DW_TAG_subrange_type
:
22020 case DW_TAG_ptr_to_member_type
:
22021 case DW_TAG_file_type
:
22022 if (die
->die_perennial_p
)
22025 /* It's a type node --- don't mark it. */
22029 /* Mark everything else. */
22033 if (die
->die_mark
== 0)
22037 /* Now, mark any dies referenced from here. */
22038 prune_unused_types_walk_attribs (die
);
22043 /* Mark children. */
22044 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22047 /* Increment the string counts on strings referred to from DIE's
22051 prune_unused_types_update_strings (dw_die_ref die
)
22056 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22057 if (AT_class (a
) == dw_val_class_str
)
22059 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22061 /* Avoid unnecessarily putting strings that are used less than
22062 twice in the hash table. */
22064 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22067 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22068 htab_hash_string (s
->str
),
22070 gcc_assert (*slot
== NULL
);
22076 /* Remove from the tree DIE any dies that aren't marked. */
22079 prune_unused_types_prune (dw_die_ref die
)
22084 gcc_assert (die
->die_mark
);
22085 prune_unused_types_update_strings (die
);
22087 if (! die
->die_child
)
22090 c
= die
->die_child
;
22092 dw_die_ref prev
= c
;
22093 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22094 if (c
== die
->die_child
)
22096 /* No marked children between 'prev' and the end of the list. */
22098 /* No marked children at all. */
22099 die
->die_child
= NULL
;
22102 prev
->die_sib
= c
->die_sib
;
22103 die
->die_child
= prev
;
22109 if (c
!= prev
->die_sib
)
22114 prune_unused_types_prune (c
);
22115 } while (c
!= die
->die_child
);
22118 /* If we pruned children, and this is a class, mark it as a
22119 declaration to inform debuggers that this is not a complete
22120 class definition. */
22121 if (pruned
&& die
->die_mark
== 1 && class_scope_p (die
)
22122 && ! is_declaration_die (die
))
22123 add_AT_flag (die
, DW_AT_declaration
, 1);
22126 /* Remove dies representing declarations that we never use. */
22129 prune_unused_types (void)
22132 limbo_die_node
*node
;
22133 comdat_type_node
*ctnode
;
22135 dw_die_ref base_type
;
22137 #if ENABLE_ASSERT_CHECKING
22138 /* All the marks should already be clear. */
22139 verify_marks_clear (comp_unit_die ());
22140 for (node
= limbo_die_list
; node
; node
= node
->next
)
22141 verify_marks_clear (node
->die
);
22142 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22143 verify_marks_clear (ctnode
->root_die
);
22144 #endif /* ENABLE_ASSERT_CHECKING */
22146 /* Mark types that are used in global variables. */
22147 premark_types_used_by_global_vars ();
22149 /* Set the mark on nodes that are actually used. */
22150 prune_unused_types_walk (comp_unit_die ());
22151 for (node
= limbo_die_list
; node
; node
= node
->next
)
22152 prune_unused_types_walk (node
->die
);
22153 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22155 prune_unused_types_walk (ctnode
->root_die
);
22156 prune_unused_types_mark (ctnode
->type_die
, 1);
22159 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22160 are unusual in that they are pubnames that are the children of pubtypes.
22161 They should only be marked via their parent DW_TAG_enumeration_type die,
22162 not as roots in themselves. */
22163 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22164 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22165 prune_unused_types_mark (pub
->die
, 1);
22166 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22167 prune_unused_types_mark (base_type
, 1);
22169 if (debug_str_hash
)
22170 htab_empty (debug_str_hash
);
22171 prune_unused_types_prune (comp_unit_die ());
22172 for (node
= limbo_die_list
; node
; node
= node
->next
)
22173 prune_unused_types_prune (node
->die
);
22174 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22175 prune_unused_types_prune (ctnode
->root_die
);
22177 /* Leave the marks clear. */
22178 prune_unmark_dies (comp_unit_die ());
22179 for (node
= limbo_die_list
; node
; node
= node
->next
)
22180 prune_unmark_dies (node
->die
);
22181 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22182 prune_unmark_dies (ctnode
->root_die
);
22185 /* Set the parameter to true if there are any relative pathnames in
22188 file_table_relative_p (void ** slot
, void *param
)
22190 bool *p
= (bool *) param
;
22191 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22192 if (!IS_ABSOLUTE_PATH (d
->filename
))
22200 /* Routines to manipulate hash table of comdat type units. */
22203 htab_ct_hash (const void *of
)
22206 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22208 memcpy (&h
, type_node
->signature
, sizeof (h
));
22213 htab_ct_eq (const void *of1
, const void *of2
)
22215 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22216 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22218 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22219 DWARF_TYPE_SIGNATURE_SIZE
));
22222 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22223 to the location it would have been added, should we know its
22224 DECL_ASSEMBLER_NAME when we added other attributes. This will
22225 probably improve compactness of debug info, removing equivalent
22226 abbrevs, and hide any differences caused by deferring the
22227 computation of the assembler name, triggered by e.g. PCH. */
22230 move_linkage_attr (dw_die_ref die
)
22232 unsigned ix
= vec_safe_length (die
->die_attr
);
22233 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22235 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22236 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22240 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22242 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22246 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22248 die
->die_attr
->pop ();
22249 die
->die_attr
->quick_insert (ix
, linkage
);
22253 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22254 referenced from typed stack ops and count how often they are used. */
22257 mark_base_types (dw_loc_descr_ref loc
)
22259 dw_die_ref base_type
= NULL
;
22261 for (; loc
; loc
= loc
->dw_loc_next
)
22263 switch (loc
->dw_loc_opc
)
22265 case DW_OP_GNU_regval_type
:
22266 case DW_OP_GNU_deref_type
:
22267 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22269 case DW_OP_GNU_convert
:
22270 case DW_OP_GNU_reinterpret
:
22271 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22274 case DW_OP_GNU_const_type
:
22275 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22277 case DW_OP_GNU_entry_value
:
22278 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22283 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22284 if (base_type
->die_mark
)
22285 base_type
->die_mark
++;
22288 base_types
.safe_push (base_type
);
22289 base_type
->die_mark
= 1;
22294 /* Comparison function for sorting marked base types. */
22297 base_type_cmp (const void *x
, const void *y
)
22299 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22300 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22301 unsigned int byte_size1
, byte_size2
;
22302 unsigned int encoding1
, encoding2
;
22303 if (dx
->die_mark
> dy
->die_mark
)
22305 if (dx
->die_mark
< dy
->die_mark
)
22307 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22308 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22309 if (byte_size1
< byte_size2
)
22311 if (byte_size1
> byte_size2
)
22313 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22314 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22315 if (encoding1
< encoding2
)
22317 if (encoding1
> encoding2
)
22322 /* Move base types marked by mark_base_types as early as possible
22323 in the CU, sorted by decreasing usage count both to make the
22324 uleb128 references as small as possible and to make sure they
22325 will have die_offset already computed by calc_die_sizes when
22326 sizes of typed stack loc ops is computed. */
22329 move_marked_base_types (void)
22332 dw_die_ref base_type
, die
, c
;
22334 if (base_types
.is_empty ())
22337 /* Sort by decreasing usage count, they will be added again in that
22339 base_types
.qsort (base_type_cmp
);
22340 die
= comp_unit_die ();
22341 c
= die
->die_child
;
22344 dw_die_ref prev
= c
;
22346 while (c
->die_mark
)
22348 remove_child_with_prev (c
, prev
);
22349 /* As base types got marked, there must be at least
22350 one node other than DW_TAG_base_type. */
22351 gcc_assert (c
!= c
->die_sib
);
22355 while (c
!= die
->die_child
);
22356 gcc_assert (die
->die_child
);
22357 c
= die
->die_child
;
22358 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22360 base_type
->die_mark
= 0;
22361 base_type
->die_sib
= c
->die_sib
;
22362 c
->die_sib
= base_type
;
22367 /* Helper function for resolve_addr, attempt to resolve
22368 one CONST_STRING, return non-zero if not successful. Similarly verify that
22369 SYMBOL_REFs refer to variables emitted in the current CU. */
22372 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22376 if (GET_CODE (rtl
) == CONST_STRING
)
22378 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22379 tree t
= build_string (len
, XSTR (rtl
, 0));
22380 tree tlen
= size_int (len
- 1);
22382 = build_array_type (char_type_node
, build_index_type (tlen
));
22383 rtl
= lookup_constant_def (t
);
22384 if (!rtl
|| !MEM_P (rtl
))
22386 rtl
= XEXP (rtl
, 0);
22387 vec_safe_push (used_rtx_array
, rtl
);
22392 if (GET_CODE (rtl
) == SYMBOL_REF
22393 && SYMBOL_REF_DECL (rtl
))
22395 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22397 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22400 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22404 if (GET_CODE (rtl
) == CONST
22405 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22411 /* Helper function for resolve_addr, handle one location
22412 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22413 the location list couldn't be resolved. */
22416 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22418 dw_loc_descr_ref keep
= NULL
;
22419 for (; loc
; loc
= loc
->dw_loc_next
)
22420 switch (loc
->dw_loc_opc
)
22423 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22426 case DW_OP_GNU_addr_index
:
22427 case DW_OP_GNU_const_index
:
22429 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22430 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22431 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22436 case DW_OP_const4u
:
22437 case DW_OP_const8u
:
22439 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22442 case DW_OP_plus_uconst
:
22443 if (size_of_loc_descr (loc
)
22444 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22446 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22448 dw_loc_descr_ref repl
22449 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22450 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22451 add_loc_descr (&repl
, loc
->dw_loc_next
);
22455 case DW_OP_implicit_value
:
22456 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22457 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22460 case DW_OP_GNU_implicit_pointer
:
22461 case DW_OP_GNU_parameter_ref
:
22462 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22465 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22468 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22469 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22470 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22473 case DW_OP_GNU_const_type
:
22474 case DW_OP_GNU_regval_type
:
22475 case DW_OP_GNU_deref_type
:
22476 case DW_OP_GNU_convert
:
22477 case DW_OP_GNU_reinterpret
:
22478 while (loc
->dw_loc_next
22479 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22481 dw_die_ref base1
, base2
;
22482 unsigned enc1
, enc2
, size1
, size2
;
22483 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22484 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22485 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22486 else if (loc
->dw_loc_oprnd1
.val_class
22487 == dw_val_class_unsigned_const
)
22490 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22491 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22492 == dw_val_class_unsigned_const
)
22494 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22495 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22496 && base2
->die_tag
== DW_TAG_base_type
);
22497 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22498 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22499 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22500 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22502 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22503 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22507 /* Optimize away next DW_OP_GNU_convert after
22508 adjusting LOC's base type die reference. */
22509 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22510 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22511 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22513 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22514 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22517 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22518 point typed stack entry. */
22519 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22520 keep
= loc
->dw_loc_next
;
22530 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22531 an address in .rodata section if the string literal is emitted there,
22532 or remove the containing location list or replace DW_AT_const_value
22533 with DW_AT_location and empty location expression, if it isn't found
22534 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22535 to something that has been emitted in the current CU. */
22538 resolve_addr (dw_die_ref die
)
22542 dw_loc_list_ref
*curr
, *start
, loc
;
22545 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22546 switch (AT_class (a
))
22548 case dw_val_class_loc_list
:
22549 start
= curr
= AT_loc_list_ptr (a
);
22552 /* The same list can be referenced more than once. See if we have
22553 already recorded the result from a previous pass. */
22555 *curr
= loc
->dw_loc_next
;
22556 else if (!loc
->resolved_addr
)
22558 /* As things stand, we do not expect or allow one die to
22559 reference a suffix of another die's location list chain.
22560 References must be identical or completely separate.
22561 There is therefore no need to cache the result of this
22562 pass on any list other than the first; doing so
22563 would lead to unnecessary writes. */
22566 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22567 if (!resolve_addr_in_expr ((*curr
)->expr
))
22569 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22570 dw_loc_descr_ref l
= (*curr
)->expr
;
22572 if (next
&& (*curr
)->ll_symbol
)
22574 gcc_assert (!next
->ll_symbol
);
22575 next
->ll_symbol
= (*curr
)->ll_symbol
;
22577 if (dwarf_split_debug_info
)
22578 remove_loc_list_addr_table_entries (l
);
22583 mark_base_types ((*curr
)->expr
);
22584 curr
= &(*curr
)->dw_loc_next
;
22588 loc
->resolved_addr
= 1;
22592 if (dwarf_split_debug_info
)
22593 remove_loc_list_addr_table_entries (loc
->expr
);
22594 loc
->dw_loc_next
= *start
;
22599 remove_AT (die
, a
->dw_attr
);
22603 case dw_val_class_loc
:
22605 dw_loc_descr_ref l
= AT_loc (a
);
22606 /* For -gdwarf-2 don't attempt to optimize
22607 DW_AT_data_member_location containing
22608 DW_OP_plus_uconst - older consumers might
22609 rely on it being that op instead of a more complex,
22610 but shorter, location description. */
22611 if ((dwarf_version
> 2
22612 || a
->dw_attr
!= DW_AT_data_member_location
22614 || l
->dw_loc_opc
!= DW_OP_plus_uconst
22615 || l
->dw_loc_next
!= NULL
)
22616 && !resolve_addr_in_expr (l
))
22618 if (dwarf_split_debug_info
)
22619 remove_loc_list_addr_table_entries (l
);
22620 remove_AT (die
, a
->dw_attr
);
22624 mark_base_types (l
);
22627 case dw_val_class_addr
:
22628 if (a
->dw_attr
== DW_AT_const_value
22629 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22631 if (AT_index (a
) != NOT_INDEXED
)
22632 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22633 remove_AT (die
, a
->dw_attr
);
22636 if (die
->die_tag
== DW_TAG_GNU_call_site
22637 && a
->dw_attr
== DW_AT_abstract_origin
)
22639 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
22640 dw_die_ref tdie
= lookup_decl_die (tdecl
);
22642 && DECL_EXTERNAL (tdecl
)
22643 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
22645 force_decl_die (tdecl
);
22646 tdie
= lookup_decl_die (tdecl
);
22650 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
22651 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
22652 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
22656 if (AT_index (a
) != NOT_INDEXED
)
22657 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22658 remove_AT (die
, a
->dw_attr
);
22667 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22670 /* Helper routines for optimize_location_lists.
22671 This pass tries to share identical local lists in .debug_loc
22674 /* Iteratively hash operands of LOC opcode. */
22676 static inline hashval_t
22677 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
22679 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
22680 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
22682 switch (loc
->dw_loc_opc
)
22684 case DW_OP_const4u
:
22685 case DW_OP_const8u
:
22689 case DW_OP_const1u
:
22690 case DW_OP_const1s
:
22691 case DW_OP_const2u
:
22692 case DW_OP_const2s
:
22693 case DW_OP_const4s
:
22694 case DW_OP_const8s
:
22698 case DW_OP_plus_uconst
:
22734 case DW_OP_deref_size
:
22735 case DW_OP_xderef_size
:
22736 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22743 gcc_assert (val1
->val_class
== dw_val_class_loc
);
22744 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
22745 hash
= iterative_hash_object (offset
, hash
);
22748 case DW_OP_implicit_value
:
22749 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22750 switch (val2
->val_class
)
22752 case dw_val_class_const
:
22753 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22755 case dw_val_class_vec
:
22757 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22758 unsigned int len
= val2
->v
.val_vec
.length
;
22760 hash
= iterative_hash_object (elt_size
, hash
);
22761 hash
= iterative_hash_object (len
, hash
);
22762 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22763 len
* elt_size
, hash
);
22766 case dw_val_class_const_double
:
22767 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22768 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22770 case dw_val_class_addr
:
22771 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
22774 gcc_unreachable ();
22778 case DW_OP_bit_piece
:
22779 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22780 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22786 unsigned char dtprel
= 0xd1;
22787 hash
= iterative_hash_object (dtprel
, hash
);
22789 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
22791 case DW_OP_GNU_addr_index
:
22792 case DW_OP_GNU_const_index
:
22796 unsigned char dtprel
= 0xd1;
22797 hash
= iterative_hash_object (dtprel
, hash
);
22799 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
22802 case DW_OP_GNU_implicit_pointer
:
22803 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22805 case DW_OP_GNU_entry_value
:
22806 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
22808 case DW_OP_GNU_regval_type
:
22809 case DW_OP_GNU_deref_type
:
22811 unsigned int byte_size
22812 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22813 unsigned int encoding
22814 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
22815 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22816 hash
= iterative_hash_object (byte_size
, hash
);
22817 hash
= iterative_hash_object (encoding
, hash
);
22820 case DW_OP_GNU_convert
:
22821 case DW_OP_GNU_reinterpret
:
22822 if (val1
->val_class
== dw_val_class_unsigned_const
)
22824 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22828 case DW_OP_GNU_const_type
:
22830 unsigned int byte_size
22831 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22832 unsigned int encoding
22833 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
22834 hash
= iterative_hash_object (byte_size
, hash
);
22835 hash
= iterative_hash_object (encoding
, hash
);
22836 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
22838 hash
= iterative_hash_object (val2
->val_class
, hash
);
22839 switch (val2
->val_class
)
22841 case dw_val_class_const
:
22842 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22844 case dw_val_class_vec
:
22846 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22847 unsigned int len
= val2
->v
.val_vec
.length
;
22849 hash
= iterative_hash_object (elt_size
, hash
);
22850 hash
= iterative_hash_object (len
, hash
);
22851 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22852 len
* elt_size
, hash
);
22855 case dw_val_class_const_double
:
22856 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22857 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22860 gcc_unreachable ();
22866 /* Other codes have no operands. */
22872 /* Iteratively hash the whole DWARF location expression LOC. */
22874 static inline hashval_t
22875 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
22877 dw_loc_descr_ref l
;
22878 bool sizes_computed
= false;
22879 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22880 size_of_locs (loc
);
22882 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
22884 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
22885 hash
= iterative_hash_object (opc
, hash
);
22886 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
22888 size_of_locs (loc
);
22889 sizes_computed
= true;
22891 hash
= hash_loc_operands (l
, hash
);
22896 /* Compute hash of the whole location list LIST_HEAD. */
22899 hash_loc_list (dw_loc_list_ref list_head
)
22901 dw_loc_list_ref curr
= list_head
;
22902 hashval_t hash
= 0;
22904 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
22906 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
22907 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
22909 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22911 hash
= hash_locs (curr
->expr
, hash
);
22913 list_head
->hash
= hash
;
22916 /* Return true if X and Y opcodes have the same operands. */
22919 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22921 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22922 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22923 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22924 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22926 switch (x
->dw_loc_opc
)
22928 case DW_OP_const4u
:
22929 case DW_OP_const8u
:
22933 case DW_OP_const1u
:
22934 case DW_OP_const1s
:
22935 case DW_OP_const2u
:
22936 case DW_OP_const2s
:
22937 case DW_OP_const4s
:
22938 case DW_OP_const8s
:
22942 case DW_OP_plus_uconst
:
22978 case DW_OP_deref_size
:
22979 case DW_OP_xderef_size
:
22980 return valx1
->v
.val_int
== valy1
->v
.val_int
;
22983 /* If splitting debug info, the use of DW_OP_GNU_addr_index
22984 can cause irrelevant differences in dw_loc_addr. */
22985 gcc_assert (valx1
->val_class
== dw_val_class_loc
22986 && valy1
->val_class
== dw_val_class_loc
22987 && (dwarf_split_debug_info
22988 || x
->dw_loc_addr
== y
->dw_loc_addr
));
22989 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
22990 case DW_OP_implicit_value
:
22991 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
22992 || valx2
->val_class
!= valy2
->val_class
)
22994 switch (valx2
->val_class
)
22996 case dw_val_class_const
:
22997 return valx2
->v
.val_int
== valy2
->v
.val_int
;
22998 case dw_val_class_vec
:
22999 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23000 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23001 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23002 valx2
->v
.val_vec
.elt_size
23003 * valx2
->v
.val_vec
.length
) == 0;
23004 case dw_val_class_const_double
:
23005 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23006 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23007 case dw_val_class_addr
:
23008 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23010 gcc_unreachable ();
23013 case DW_OP_bit_piece
:
23014 return valx1
->v
.val_int
== valy1
->v
.val_int
23015 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23018 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23019 case DW_OP_GNU_addr_index
:
23020 case DW_OP_GNU_const_index
:
23022 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23023 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23024 return rtx_equal_p (ax1
, ay1
);
23026 case DW_OP_GNU_implicit_pointer
:
23027 return valx1
->val_class
== dw_val_class_die_ref
23028 && valx1
->val_class
== valy1
->val_class
23029 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23030 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23031 case DW_OP_GNU_entry_value
:
23032 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23033 case DW_OP_GNU_const_type
:
23034 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23035 || valx2
->val_class
!= valy2
->val_class
)
23037 switch (valx2
->val_class
)
23039 case dw_val_class_const
:
23040 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23041 case dw_val_class_vec
:
23042 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23043 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23044 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23045 valx2
->v
.val_vec
.elt_size
23046 * valx2
->v
.val_vec
.length
) == 0;
23047 case dw_val_class_const_double
:
23048 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23049 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23051 gcc_unreachable ();
23053 case DW_OP_GNU_regval_type
:
23054 case DW_OP_GNU_deref_type
:
23055 return valx1
->v
.val_int
== valy1
->v
.val_int
23056 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23057 case DW_OP_GNU_convert
:
23058 case DW_OP_GNU_reinterpret
:
23059 if (valx1
->val_class
!= valy1
->val_class
)
23061 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23062 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23063 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23064 case DW_OP_GNU_parameter_ref
:
23065 return valx1
->val_class
== dw_val_class_die_ref
23066 && valx1
->val_class
== valy1
->val_class
23067 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23069 /* Other codes have no operands. */
23074 /* Return true if DWARF location expressions X and Y are the same. */
23077 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23079 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23080 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23081 || x
->dtprel
!= y
->dtprel
23082 || !compare_loc_operands (x
, y
))
23084 return x
== NULL
&& y
== NULL
;
23087 /* Return precomputed hash of location list X. */
23090 loc_list_hash (const void *x
)
23092 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23095 /* Return 1 if location lists X and Y are the same. */
23098 loc_list_eq (const void *x
, const void *y
)
23100 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23101 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23104 if (a
->hash
!= b
->hash
)
23106 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23107 if (strcmp (a
->begin
, b
->begin
) != 0
23108 || strcmp (a
->end
, b
->end
) != 0
23109 || (a
->section
== NULL
) != (b
->section
== NULL
)
23110 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23111 || !compare_locs (a
->expr
, b
->expr
))
23113 return a
== NULL
&& b
== NULL
;
23116 /* Recursively optimize location lists referenced from DIE
23117 children and share them whenever possible. */
23120 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23127 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23128 if (AT_class (a
) == dw_val_class_loc_list
)
23130 dw_loc_list_ref list
= AT_loc_list (a
);
23131 /* TODO: perform some optimizations here, before hashing
23132 it and storing into the hash table. */
23133 hash_loc_list (list
);
23134 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23137 *slot
= (void *) list
;
23139 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23142 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23146 /* Recursively assign each location list a unique index into the debug_addr
23150 index_location_lists (dw_die_ref die
)
23156 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23157 if (AT_class (a
) == dw_val_class_loc_list
)
23159 dw_loc_list_ref list
= AT_loc_list (a
);
23160 dw_loc_list_ref curr
;
23161 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23163 /* Don't index an entry that has already been indexed
23164 or won't be output. */
23165 if (curr
->begin_entry
!= NULL
23166 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23170 = add_addr_table_entry (xstrdup (curr
->begin
),
23175 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23178 /* Optimize location lists referenced from DIE
23179 children and share them whenever possible. */
23182 optimize_location_lists (dw_die_ref die
)
23184 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23185 optimize_location_lists_1 (die
, htab
);
23186 htab_delete (htab
);
23189 /* Output stuff that dwarf requires at the end of every file,
23190 and generate the DWARF-2 debugging info. */
23193 dwarf2out_finish (const char *filename
)
23195 limbo_die_node
*node
, *next_node
;
23196 comdat_type_node
*ctnode
;
23197 htab_t comdat_type_table
;
23199 dw_die_ref main_comp_unit_die
;
23201 /* PCH might result in DW_AT_producer string being restored from the
23202 header compilation, so always fill it with empty string initially
23203 and overwrite only here. */
23204 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23205 producer_string
= gen_producer_string ();
23206 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23207 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23209 gen_scheduled_generic_parms_dies ();
23210 gen_remaining_tmpl_value_param_die_attribute ();
23212 /* Add the name for the main input file now. We delayed this from
23213 dwarf2out_init to avoid complications with PCH. */
23214 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23215 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23216 add_comp_dir_attribute (comp_unit_die ());
23217 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23220 htab_traverse (file_table
, file_table_relative_p
, &p
);
23222 add_comp_dir_attribute (comp_unit_die ());
23225 if (deferred_locations_list
)
23226 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23228 add_location_or_const_value_attribute (
23229 (*deferred_locations_list
)[i
].die
,
23230 (*deferred_locations_list
)[i
].variable
,
23235 /* Traverse the limbo die list, and add parent/child links. The only
23236 dies without parents that should be here are concrete instances of
23237 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23238 For concrete instances, we can get the parent die from the abstract
23240 for (node
= limbo_die_list
; node
; node
= next_node
)
23242 dw_die_ref die
= node
->die
;
23243 next_node
= node
->next
;
23245 if (die
->die_parent
== NULL
)
23247 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23249 if (origin
&& origin
->die_parent
)
23250 add_child_die (origin
->die_parent
, die
);
23251 else if (is_cu_die (die
))
23253 else if (seen_error ())
23254 /* It's OK to be confused by errors in the input. */
23255 add_child_die (comp_unit_die (), die
);
23258 /* In certain situations, the lexical block containing a
23259 nested function can be optimized away, which results
23260 in the nested function die being orphaned. Likewise
23261 with the return type of that nested function. Force
23262 this to be a child of the containing function.
23264 It may happen that even the containing function got fully
23265 inlined and optimized out. In that case we are lost and
23266 assign the empty child. This should not be big issue as
23267 the function is likely unreachable too. */
23268 gcc_assert (node
->created_for
);
23270 if (DECL_P (node
->created_for
))
23271 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23272 else if (TYPE_P (node
->created_for
))
23273 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23275 origin
= comp_unit_die ();
23277 add_child_die (origin
, die
);
23282 limbo_die_list
= NULL
;
23284 #if ENABLE_ASSERT_CHECKING
23286 dw_die_ref die
= comp_unit_die (), c
;
23287 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23290 resolve_addr (comp_unit_die ());
23291 move_marked_base_types ();
23293 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23295 tree decl
= node
->created_for
;
23296 /* When generating LTO bytecode we can not generate new assembler
23297 names at this point and all important decls got theirs via
23299 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23300 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23302 add_linkage_attr (node
->die
, decl
);
23303 move_linkage_attr (node
->die
);
23307 deferred_asm_name
= NULL
;
23309 /* Walk through the list of incomplete types again, trying once more to
23310 emit full debugging info for them. */
23311 retry_incomplete_types ();
23313 if (flag_eliminate_unused_debug_types
)
23314 prune_unused_types ();
23316 /* Generate separate COMDAT sections for type DIEs. */
23317 if (use_debug_types
)
23319 break_out_comdat_types (comp_unit_die ());
23321 /* Each new type_unit DIE was added to the limbo die list when created.
23322 Since these have all been added to comdat_type_list, clear the
23324 limbo_die_list
= NULL
;
23326 /* For each new comdat type unit, copy declarations for incomplete
23327 types to make the new unit self-contained (i.e., no direct
23328 references to the main compile unit). */
23329 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23330 copy_decls_for_unworthy_types (ctnode
->root_die
);
23331 copy_decls_for_unworthy_types (comp_unit_die ());
23333 /* In the process of copying declarations from one unit to another,
23334 we may have left some declarations behind that are no longer
23335 referenced. Prune them. */
23336 prune_unused_types ();
23339 /* Generate separate CUs for each of the include files we've seen.
23340 They will go into limbo_die_list. */
23341 if (flag_eliminate_dwarf2_dups
)
23342 break_out_includes (comp_unit_die ());
23344 /* Traverse the DIE's and add add sibling attributes to those DIE's
23345 that have children. */
23346 add_sibling_attributes (comp_unit_die ());
23347 for (node
= limbo_die_list
; node
; node
= node
->next
)
23348 add_sibling_attributes (node
->die
);
23349 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23350 add_sibling_attributes (ctnode
->root_die
);
23352 /* When splitting DWARF info, we put some attributes in the
23353 skeleton compile_unit DIE that remains in the .o, while
23354 most attributes go in the DWO compile_unit_die. */
23355 if (dwarf_split_debug_info
)
23356 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23358 main_comp_unit_die
= comp_unit_die ();
23360 /* Output a terminator label for the .text section. */
23361 switch_to_section (text_section
);
23362 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23363 if (cold_text_section
)
23365 switch_to_section (cold_text_section
);
23366 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23369 /* We can only use the low/high_pc attributes if all of the code was
23371 if (!have_multiple_function_sections
23372 || (dwarf_version
< 3 && dwarf_strict
))
23374 /* Don't add if the CU has no associated code. */
23375 if (text_section_used
)
23376 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23377 text_end_label
, true);
23383 bool range_list_added
= false;
23385 if (text_section_used
)
23386 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23387 text_end_label
, &range_list_added
, true);
23388 if (cold_text_section_used
)
23389 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23390 cold_end_label
, &range_list_added
, true);
23392 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23394 if (DECL_IGNORED_P (fde
->decl
))
23396 if (!fde
->in_std_section
)
23397 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23398 fde
->dw_fde_end
, &range_list_added
,
23400 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23401 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23402 fde
->dw_fde_second_end
, &range_list_added
,
23406 if (range_list_added
)
23408 /* We need to give .debug_loc and .debug_ranges an appropriate
23409 "base address". Use zero so that these addresses become
23410 absolute. Historically, we've emitted the unexpected
23411 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23412 Emit both to give time for other tools to adapt. */
23413 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23414 if (! dwarf_strict
&& dwarf_version
< 4)
23415 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23421 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23422 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23423 debug_line_section_label
);
23426 add_AT_macptr (comp_unit_die (),
23427 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23428 macinfo_section_label
);
23430 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23432 /* optimize_location_lists calculates the size of the lists,
23433 so index them first, and assign indices to the entries.
23434 Although optimize_location_lists will remove entries from
23435 the table, it only does so for duplicates, and therefore
23436 only reduces ref_counts to 1. */
23437 unsigned int index
= 0;
23438 index_location_lists (comp_unit_die ());
23439 htab_traverse_noresize (addr_index_table
,
23440 index_addr_table_entry
, &index
);
23442 if (have_location_lists
)
23443 optimize_location_lists (comp_unit_die ());
23445 save_macinfo_strings ();
23446 if (dwarf_split_debug_info
)
23448 unsigned int index
= 0;
23449 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23452 /* Output all of the compilation units. We put the main one last so that
23453 the offsets are available to output_pubnames. */
23454 for (node
= limbo_die_list
; node
; node
= node
->next
)
23455 output_comp_unit (node
->die
, 0);
23457 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23458 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23460 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23462 /* Don't output duplicate types. */
23463 if (*slot
!= HTAB_EMPTY_ENTRY
)
23466 /* Add a pointer to the line table for the main compilation unit
23467 so that the debugger can make sense of DW_AT_decl_file
23469 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23470 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23471 (!dwarf_split_debug_info
23472 ? debug_line_section_label
23473 : debug_skeleton_line_section_label
));
23475 output_comdat_type_unit (ctnode
);
23478 htab_delete (comdat_type_table
);
23480 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23481 both the main_cu and all skeleton TUs. Making this call unconditional
23482 would end up either adding a second copy of the AT_pubnames attribute, or
23483 requiring a special case in add_top_level_skeleton_die_attrs. */
23484 if (!dwarf_split_debug_info
)
23485 add_AT_pubnames (comp_unit_die ());
23487 if (dwarf_split_debug_info
)
23490 unsigned char checksum
[16];
23491 struct md5_ctx ctx
;
23493 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23494 md5_init_ctx (&ctx
);
23496 die_checksum (comp_unit_die (), &ctx
, &mark
);
23497 unmark_all_dies (comp_unit_die ());
23498 md5_finish_ctx (&ctx
, checksum
);
23500 /* Use the first 8 bytes of the checksum as the dwo_id,
23501 and add it to both comp-unit DIEs. */
23502 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23503 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23505 /* Add the base offset of the ranges table to the skeleton
23507 if (ranges_table_in_use
)
23508 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23509 ranges_section_label
);
23511 switch_to_section (debug_addr_section
);
23512 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23513 output_addr_table ();
23516 /* Output the main compilation unit if non-empty or if .debug_macinfo
23517 or .debug_macro will be emitted. */
23518 output_comp_unit (comp_unit_die (), have_macinfo
);
23520 if (dwarf_split_debug_info
&& info_section_emitted
)
23521 output_skeleton_debug_sections (main_comp_unit_die
);
23523 /* Output the abbreviation table. */
23524 if (abbrev_die_table_in_use
!= 1)
23526 switch_to_section (debug_abbrev_section
);
23527 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23528 output_abbrev_section ();
23531 /* Output location list section if necessary. */
23532 if (have_location_lists
)
23534 /* Output the location lists info. */
23535 switch_to_section (debug_loc_section
);
23536 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23537 output_location_lists (comp_unit_die ());
23540 /* Output public names and types tables if necessary. */
23541 output_pubnames (pubname_table
);
23542 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23543 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23544 simply won't look for the section. */
23545 output_pubnames (pubtype_table
);
23547 /* Output the address range information if a CU (.debug_info section)
23548 was emitted. We output an empty table even if we had no functions
23549 to put in it. This because the consumer has no way to tell the
23550 difference between an empty table that we omitted and failure to
23551 generate a table that would have contained data. */
23552 if (info_section_emitted
)
23554 unsigned long aranges_length
= size_of_aranges ();
23556 switch_to_section (debug_aranges_section
);
23557 output_aranges (aranges_length
);
23560 /* Output ranges section if necessary. */
23561 if (ranges_table_in_use
)
23563 switch_to_section (debug_ranges_section
);
23564 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23568 /* Have to end the macro section. */
23571 switch_to_section (debug_macinfo_section
);
23572 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23574 dw2_asm_output_data (1, 0, "End compilation unit");
23577 /* Output the source line correspondence table. We must do this
23578 even if there is no line information. Otherwise, on an empty
23579 translation unit, we will generate a present, but empty,
23580 .debug_info section. IRIX 6.5 `nm' will then complain when
23581 examining the file. This is done late so that any filenames
23582 used by the debug_info section are marked as 'used'. */
23583 switch_to_section (debug_line_section
);
23584 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23585 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23586 output_line_info (false);
23588 if (dwarf_split_debug_info
&& info_section_emitted
)
23590 switch_to_section (debug_skeleton_line_section
);
23591 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
23592 output_line_info (true);
23595 /* If we emitted any indirect strings, output the string table too. */
23596 if (debug_str_hash
)
23597 output_indirect_strings ();
23600 #include "gt-dwarf2out.h"