1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2013 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
66 #include "hard-reg-set.h"
68 #include "insn-config.h"
75 #include "dwarf2out.h"
76 #include "dwarf2asm.h"
81 #include "diagnostic.h"
82 #include "tree-pretty-print.h"
85 #include "common/common-target.h"
86 #include "langhooks.h"
87 #include "hash-table.h"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn
;
98 static rtx cached_next_real_insn
;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 /* The size of the target's pointer type. */
126 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
129 /* Array of RTXes referenced by the debugging information, which therefore
130 must be kept around forever. */
131 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
133 /* A pointer to the base of a list of incomplete types which might be
134 completed at some later time. incomplete_types_list needs to be a
135 vec<tree, va_gc> *because we want to tell the garbage collector about
137 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
146 /* Pointers to various DWARF2 sections. */
147 static GTY(()) section
*debug_info_section
;
148 static GTY(()) section
*debug_skeleton_info_section
;
149 static GTY(()) section
*debug_abbrev_section
;
150 static GTY(()) section
*debug_skeleton_abbrev_section
;
151 static GTY(()) section
*debug_aranges_section
;
152 static GTY(()) section
*debug_addr_section
;
153 static GTY(()) section
*debug_macinfo_section
;
154 static GTY(()) section
*debug_line_section
;
155 static GTY(()) section
*debug_skeleton_line_section
;
156 static GTY(()) section
*debug_loc_section
;
157 static GTY(()) section
*debug_pubnames_section
;
158 static GTY(()) section
*debug_pubtypes_section
;
159 static GTY(()) section
*debug_str_section
;
160 static GTY(()) section
*debug_str_dwo_section
;
161 static GTY(()) section
*debug_str_offsets_section
;
162 static GTY(()) section
*debug_ranges_section
;
163 static GTY(()) section
*debug_frame_section
;
165 /* Maximum size (in bytes) of an artificially generated label. */
166 #define MAX_ARTIFICIAL_LABEL_BYTES 30
168 /* According to the (draft) DWARF 3 specification, the initial length
169 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
170 bytes are 0xffffffff, followed by the length stored in the next 8
173 However, the SGI/MIPS ABI uses an initial length which is equal to
174 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
176 #ifndef DWARF_INITIAL_LENGTH_SIZE
177 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
180 /* Round SIZE up to the nearest BOUNDARY. */
181 #define DWARF_ROUND(SIZE,BOUNDARY) \
182 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
184 /* CIE identifier. */
185 #if HOST_BITS_PER_WIDE_INT >= 64
186 #define DWARF_CIE_ID \
187 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
189 #define DWARF_CIE_ID DW_CIE_ID
193 /* A vector for a table that contains frame description
194 information for each routine. */
195 #define NOT_INDEXED (-1U)
196 #define NO_INDEX_ASSIGNED (-2U)
198 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
200 struct GTY(()) indirect_string_node
{
202 unsigned int refcount
;
203 enum dwarf_form form
;
208 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
210 /* With split_debug_info, both the comp_dir and dwo_name go in the
211 main object file, rather than the dwo, similar to the force_direct
212 parameter elsewhere but with additional complications:
214 1) The string is needed in both the main object file and the dwo.
215 That is, the comp_dir and dwo_name will appear in both places.
217 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
218 DW_FORM_GNU_str_index.
220 3) GCC chooses the form to use late, depending on the size and
223 Rather than forcing the all debug string handling functions and
224 callers to deal with these complications, simply use a separate,
225 special-cased string table for any attribute that should go in the
226 main object file. This limits the complexity to just the places
229 static GTY ((param_is (struct indirect_string_node
)))
230 htab_t skeleton_debug_str_hash
;
232 static GTY(()) int dw2_string_counter
;
234 /* True if the compilation unit places functions in more than one section. */
235 static GTY(()) bool have_multiple_function_sections
= false;
237 /* Whether the default text and cold text sections have been used at all. */
239 static GTY(()) bool text_section_used
= false;
240 static GTY(()) bool cold_text_section_used
= false;
242 /* The default cold text section. */
243 static GTY(()) section
*cold_text_section
;
245 /* Forward declarations for functions defined in this file. */
247 static char *stripattributes (const char *);
248 static void output_call_frame_info (int);
249 static void dwarf2out_note_section_used (void);
251 /* Personality decl of current unit. Used only when assembler does not support
253 static GTY(()) rtx current_unit_personality
;
255 /* Data and reference forms for relocatable data. */
256 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
257 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
259 #ifndef DEBUG_FRAME_SECTION
260 #define DEBUG_FRAME_SECTION ".debug_frame"
263 #ifndef FUNC_BEGIN_LABEL
264 #define FUNC_BEGIN_LABEL "LFB"
267 #ifndef FUNC_END_LABEL
268 #define FUNC_END_LABEL "LFE"
271 #ifndef PROLOGUE_END_LABEL
272 #define PROLOGUE_END_LABEL "LPE"
275 #ifndef EPILOGUE_BEGIN_LABEL
276 #define EPILOGUE_BEGIN_LABEL "LEB"
279 #ifndef FRAME_BEGIN_LABEL
280 #define FRAME_BEGIN_LABEL "Lframe"
282 #define CIE_AFTER_SIZE_LABEL "LSCIE"
283 #define CIE_END_LABEL "LECIE"
284 #define FDE_LABEL "LSFDE"
285 #define FDE_AFTER_SIZE_LABEL "LASFDE"
286 #define FDE_END_LABEL "LEFDE"
287 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
288 #define LINE_NUMBER_END_LABEL "LELT"
289 #define LN_PROLOG_AS_LABEL "LASLTP"
290 #define LN_PROLOG_END_LABEL "LELTP"
291 #define DIE_LABEL_PREFIX "DW"
293 /* Match the base name of a file to the base name of a compilation unit. */
296 matches_main_base (const char *path
)
298 /* Cache the last query. */
299 static const char *last_path
= NULL
;
300 static int last_match
= 0;
301 if (path
!= last_path
)
304 int length
= base_of_path (path
, &base
);
306 last_match
= (length
== main_input_baselength
307 && memcmp (base
, main_input_basename
, length
) == 0);
312 #ifdef DEBUG_DEBUG_STRUCT
315 dump_struct_debug (tree type
, enum debug_info_usage usage
,
316 enum debug_struct_file criterion
, int generic
,
317 int matches
, int result
)
319 /* Find the type name. */
320 tree type_decl
= TYPE_STUB_DECL (type
);
322 const char *name
= 0;
323 if (TREE_CODE (t
) == TYPE_DECL
)
326 name
= IDENTIFIER_POINTER (t
);
328 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
330 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
331 matches
? "bas" : "hdr",
332 generic
? "gen" : "ord",
333 usage
== DINFO_USAGE_DFN
? ";" :
334 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
336 (void*) type_decl
, name
);
339 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
340 dump_struct_debug (type, usage, criterion, generic, matches, result)
344 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
350 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
352 enum debug_struct_file criterion
;
354 bool generic
= lang_hooks
.types
.generic_p (type
);
357 criterion
= debug_struct_generic
[usage
];
359 criterion
= debug_struct_ordinary
[usage
];
361 if (criterion
== DINFO_STRUCT_FILE_NONE
)
362 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
363 if (criterion
== DINFO_STRUCT_FILE_ANY
)
364 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
366 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
368 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
369 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
371 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
372 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
373 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
376 /* Return a pointer to a copy of the section string name S with all
377 attributes stripped off, and an asterisk prepended (for assemble_name). */
380 stripattributes (const char *s
)
382 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
387 while (*s
&& *s
!= ',')
394 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
395 switch to the data section instead, and write out a synthetic start label
396 for collect2 the first time around. */
399 switch_to_eh_frame_section (bool back
)
403 #ifdef EH_FRAME_SECTION_NAME
404 if (eh_frame_section
== 0)
408 if (EH_TABLES_CAN_BE_READ_ONLY
)
414 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
416 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
418 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
421 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
422 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
423 && (per_encoding
& 0x70) != DW_EH_PE_absptr
424 && (per_encoding
& 0x70) != DW_EH_PE_aligned
425 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
426 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
427 ? 0 : SECTION_WRITE
);
430 flags
= SECTION_WRITE
;
431 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
433 #endif /* EH_FRAME_SECTION_NAME */
435 if (eh_frame_section
)
436 switch_to_section (eh_frame_section
);
439 /* We have no special eh_frame section. Put the information in
440 the data section and emit special labels to guide collect2. */
441 switch_to_section (data_section
);
445 label
= get_file_function_name ("F");
446 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
447 targetm
.asm_out
.globalize_label (asm_out_file
,
448 IDENTIFIER_POINTER (label
));
449 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
454 /* Switch [BACK] to the eh or debug frame table section, depending on
458 switch_to_frame_table_section (int for_eh
, bool back
)
461 switch_to_eh_frame_section (back
);
464 if (!debug_frame_section
)
465 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
466 SECTION_DEBUG
, NULL
);
467 switch_to_section (debug_frame_section
);
471 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
473 enum dw_cfi_oprnd_type
474 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
479 case DW_CFA_GNU_window_save
:
480 case DW_CFA_remember_state
:
481 case DW_CFA_restore_state
:
482 return dw_cfi_oprnd_unused
;
485 case DW_CFA_advance_loc1
:
486 case DW_CFA_advance_loc2
:
487 case DW_CFA_advance_loc4
:
488 case DW_CFA_MIPS_advance_loc8
:
489 return dw_cfi_oprnd_addr
;
492 case DW_CFA_offset_extended
:
494 case DW_CFA_offset_extended_sf
:
495 case DW_CFA_def_cfa_sf
:
497 case DW_CFA_restore_extended
:
498 case DW_CFA_undefined
:
499 case DW_CFA_same_value
:
500 case DW_CFA_def_cfa_register
:
501 case DW_CFA_register
:
502 case DW_CFA_expression
:
503 return dw_cfi_oprnd_reg_num
;
505 case DW_CFA_def_cfa_offset
:
506 case DW_CFA_GNU_args_size
:
507 case DW_CFA_def_cfa_offset_sf
:
508 return dw_cfi_oprnd_offset
;
510 case DW_CFA_def_cfa_expression
:
511 return dw_cfi_oprnd_loc
;
518 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
520 enum dw_cfi_oprnd_type
521 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
526 case DW_CFA_def_cfa_sf
:
528 case DW_CFA_offset_extended_sf
:
529 case DW_CFA_offset_extended
:
530 return dw_cfi_oprnd_offset
;
532 case DW_CFA_register
:
533 return dw_cfi_oprnd_reg_num
;
535 case DW_CFA_expression
:
536 return dw_cfi_oprnd_loc
;
539 return dw_cfi_oprnd_unused
;
543 /* Output one FDE. */
546 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
547 char *section_start_label
, int fde_encoding
, char *augmentation
,
548 bool any_lsda_needed
, int lsda_encoding
)
550 const char *begin
, *end
;
551 static unsigned int j
;
554 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
556 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
558 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
559 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
560 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
561 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
562 " indicating 64-bit DWARF extension");
563 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
565 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
568 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
570 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
571 debug_frame_section
, "FDE CIE offset");
573 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
574 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
578 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
579 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
580 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
581 "FDE initial location");
582 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
583 end
, begin
, "FDE address range");
587 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
588 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
595 int size
= size_of_encoded_value (lsda_encoding
);
597 if (lsda_encoding
== DW_EH_PE_aligned
)
599 int offset
= ( 4 /* Length */
601 + 2 * size_of_encoded_value (fde_encoding
)
602 + 1 /* Augmentation size */ );
603 int pad
= -offset
& (PTR_SIZE
- 1);
606 gcc_assert (size_of_uleb128 (size
) == 1);
609 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
611 if (fde
->uses_eh_lsda
)
613 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
614 fde
->funcdef_number
);
615 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
616 gen_rtx_SYMBOL_REF (Pmode
, l1
),
618 "Language Specific Data Area");
622 if (lsda_encoding
== DW_EH_PE_aligned
)
623 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
624 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
625 "Language Specific Data Area (none)");
629 dw2_asm_output_data_uleb128 (0, "Augmentation size");
632 /* Loop through the Call Frame Instructions associated with this FDE. */
633 fde
->dw_fde_current_label
= begin
;
635 size_t from
, until
, i
;
638 until
= vec_safe_length (fde
->dw_fde_cfi
);
640 if (fde
->dw_fde_second_begin
== NULL
)
643 until
= fde
->dw_fde_switch_cfi_index
;
645 from
= fde
->dw_fde_switch_cfi_index
;
647 for (i
= from
; i
< until
; i
++)
648 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
651 /* If we are to emit a ref/link from function bodies to their frame tables,
652 do it now. This is typically performed to make sure that tables
653 associated with functions are dragged with them and not discarded in
654 garbage collecting links. We need to do this on a per function basis to
655 cope with -ffunction-sections. */
657 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
658 /* Switch to the function section, emit the ref to the tables, and
659 switch *back* into the table section. */
660 switch_to_section (function_section (fde
->decl
));
661 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
662 switch_to_frame_table_section (for_eh
, true);
665 /* Pad the FDE out to an address sized boundary. */
666 ASM_OUTPUT_ALIGN (asm_out_file
,
667 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
668 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
673 /* Return true if frame description entry FDE is needed for EH. */
676 fde_needed_for_eh_p (dw_fde_ref fde
)
678 if (flag_asynchronous_unwind_tables
)
681 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
684 if (fde
->uses_eh_lsda
)
687 /* If exceptions are enabled, we have collected nothrow info. */
688 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
694 /* Output the call frame information used to record information
695 that relates to calculating the frame pointer, and records the
696 location of saved registers. */
699 output_call_frame_info (int for_eh
)
704 char l1
[20], l2
[20], section_start_label
[20];
705 bool any_lsda_needed
= false;
706 char augmentation
[6];
707 int augmentation_size
;
708 int fde_encoding
= DW_EH_PE_absptr
;
709 int per_encoding
= DW_EH_PE_absptr
;
710 int lsda_encoding
= DW_EH_PE_absptr
;
712 rtx personality
= NULL
;
715 /* Don't emit a CIE if there won't be any FDEs. */
719 /* Nothing to do if the assembler's doing it all. */
720 if (dwarf2out_do_cfi_asm ())
723 /* If we don't have any functions we'll want to unwind out of, don't emit
724 any EH unwind information. If we make FDEs linkonce, we may have to
725 emit an empty label for an FDE that wouldn't otherwise be emitted. We
726 want to avoid having an FDE kept around when the function it refers to
727 is discarded. Example where this matters: a primary function template
728 in C++ requires EH information, an explicit specialization doesn't. */
731 bool any_eh_needed
= false;
733 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
735 if (fde
->uses_eh_lsda
)
736 any_eh_needed
= any_lsda_needed
= true;
737 else if (fde_needed_for_eh_p (fde
))
738 any_eh_needed
= true;
739 else if (TARGET_USES_WEAK_UNWIND_INFO
)
740 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
747 /* We're going to be generating comments, so turn on app. */
751 /* Switch to the proper frame section, first time. */
752 switch_to_frame_table_section (for_eh
, false);
754 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
755 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
757 /* Output the CIE. */
758 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
759 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
760 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
761 dw2_asm_output_data (4, 0xffffffff,
762 "Initial length escape value indicating 64-bit DWARF extension");
763 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
764 "Length of Common Information Entry");
765 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
767 /* Now that the CIE pointer is PC-relative for EH,
768 use 0 to identify the CIE. */
769 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
770 (for_eh
? 0 : DWARF_CIE_ID
),
771 "CIE Identifier Tag");
773 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
774 use CIE version 1, unless that would produce incorrect results
775 due to overflowing the return register column. */
776 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
778 if (return_reg
>= 256 || dwarf_version
> 2)
780 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
783 augmentation_size
= 0;
785 personality
= current_unit_personality
;
791 z Indicates that a uleb128 is present to size the
792 augmentation section.
793 L Indicates the encoding (and thus presence) of
794 an LSDA pointer in the FDE augmentation.
795 R Indicates a non-default pointer encoding for
797 P Indicates the presence of an encoding + language
798 personality routine in the CIE augmentation. */
800 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
801 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
802 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
804 p
= augmentation
+ 1;
808 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
809 assemble_external_libcall (personality
);
814 augmentation_size
+= 1;
816 if (fde_encoding
!= DW_EH_PE_absptr
)
819 augmentation_size
+= 1;
821 if (p
> augmentation
+ 1)
823 augmentation
[0] = 'z';
827 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
828 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
830 int offset
= ( 4 /* Length */
832 + 1 /* CIE version */
833 + strlen (augmentation
) + 1 /* Augmentation */
834 + size_of_uleb128 (1) /* Code alignment */
835 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
837 + 1 /* Augmentation size */
838 + 1 /* Personality encoding */ );
839 int pad
= -offset
& (PTR_SIZE
- 1);
841 augmentation_size
+= pad
;
843 /* Augmentations should be small, so there's scarce need to
844 iterate for a solution. Die if we exceed one uleb128 byte. */
845 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
849 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
850 if (dw_cie_version
>= 4)
852 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
853 dw2_asm_output_data (1, 0, "CIE Segment Size");
855 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
856 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
857 "CIE Data Alignment Factor");
859 if (dw_cie_version
== 1)
860 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
862 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
866 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
869 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
870 eh_data_format_name (per_encoding
));
871 dw2_asm_output_encoded_addr_rtx (per_encoding
,
877 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
878 eh_data_format_name (lsda_encoding
));
880 if (fde_encoding
!= DW_EH_PE_absptr
)
881 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
882 eh_data_format_name (fde_encoding
));
885 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
886 output_cfi (cfi
, NULL
, for_eh
);
888 /* Pad the CIE out to an address sized boundary. */
889 ASM_OUTPUT_ALIGN (asm_out_file
,
890 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
891 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
893 /* Loop through all of the FDE's. */
894 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
898 /* Don't emit EH unwind info for leaf functions that don't need it. */
899 if (for_eh
&& !fde_needed_for_eh_p (fde
))
902 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
903 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
904 augmentation
, any_lsda_needed
, lsda_encoding
);
907 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
908 dw2_asm_output_data (4, 0, "End of Table");
910 /* Turn off app to make assembly quicker. */
915 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
918 dwarf2out_do_cfi_startproc (bool second
)
922 rtx personality
= get_personality_function (current_function_decl
);
924 fprintf (asm_out_file
, "\t.cfi_startproc\n");
928 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
931 /* ??? The GAS support isn't entirely consistent. We have to
932 handle indirect support ourselves, but PC-relative is done
933 in the assembler. Further, the assembler can't handle any
934 of the weirder relocation types. */
935 if (enc
& DW_EH_PE_indirect
)
936 ref
= dw2_force_const_mem (ref
, true);
938 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
939 output_addr_const (asm_out_file
, ref
);
940 fputc ('\n', asm_out_file
);
943 if (crtl
->uses_eh_lsda
)
947 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
948 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
949 current_function_funcdef_no
);
950 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
951 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
953 if (enc
& DW_EH_PE_indirect
)
954 ref
= dw2_force_const_mem (ref
, true);
956 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
957 output_addr_const (asm_out_file
, ref
);
958 fputc ('\n', asm_out_file
);
962 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
963 this allocation may be done before pass_final. */
966 dwarf2out_alloc_current_fde (void)
970 fde
= ggc_alloc_cleared_dw_fde_node ();
971 fde
->decl
= current_function_decl
;
972 fde
->funcdef_number
= current_function_funcdef_no
;
973 fde
->fde_index
= vec_safe_length (fde_vec
);
974 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
975 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
976 fde
->nothrow
= crtl
->nothrow
;
977 fde
->drap_reg
= INVALID_REGNUM
;
978 fde
->vdrap_reg
= INVALID_REGNUM
;
980 /* Record the FDE associated with this function. */
982 vec_safe_push (fde_vec
, fde
);
987 /* Output a marker (i.e. a label) for the beginning of a function, before
991 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
992 const char *file ATTRIBUTE_UNUSED
)
994 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1000 current_function_func_begin_label
= NULL
;
1002 do_frame
= dwarf2out_do_frame ();
1004 /* ??? current_function_func_begin_label is also used by except.c for
1005 call-site information. We must emit this label if it might be used. */
1007 && (!flag_exceptions
1008 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1011 fnsec
= function_section (current_function_decl
);
1012 switch_to_section (fnsec
);
1013 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1014 current_function_funcdef_no
);
1015 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1016 current_function_funcdef_no
);
1017 dup_label
= xstrdup (label
);
1018 current_function_func_begin_label
= dup_label
;
1020 /* We can elide the fde allocation if we're not emitting debug info. */
1024 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1025 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1026 would include pass_dwarf2_frame. If we've not created the FDE yet,
1030 fde
= dwarf2out_alloc_current_fde ();
1032 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1033 fde
->dw_fde_begin
= dup_label
;
1034 fde
->dw_fde_current_label
= dup_label
;
1035 fde
->in_std_section
= (fnsec
== text_section
1036 || (cold_text_section
&& fnsec
== cold_text_section
));
1038 /* We only want to output line number information for the genuine dwarf2
1039 prologue case, not the eh frame case. */
1040 #ifdef DWARF2_DEBUGGING_INFO
1042 dwarf2out_source_line (line
, file
, 0, true);
1045 if (dwarf2out_do_cfi_asm ())
1046 dwarf2out_do_cfi_startproc (false);
1049 rtx personality
= get_personality_function (current_function_decl
);
1050 if (!current_unit_personality
)
1051 current_unit_personality
= personality
;
1053 /* We cannot keep a current personality per function as without CFI
1054 asm, at the point where we emit the CFI data, there is no current
1055 function anymore. */
1056 if (personality
&& current_unit_personality
!= personality
)
1057 sorry ("multiple EH personalities are supported only with assemblers "
1058 "supporting .cfi_personality directive");
1062 /* Output a marker (i.e. a label) for the end of the generated code
1063 for a function prologue. This gets called *after* the prologue code has
1067 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1068 const char *file ATTRIBUTE_UNUSED
)
1070 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1072 /* Output a label to mark the endpoint of the code generated for this
1074 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1075 current_function_funcdef_no
);
1076 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1077 current_function_funcdef_no
);
1078 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1081 /* Output a marker (i.e. a label) for the beginning of the generated code
1082 for a function epilogue. This gets called *before* the prologue code has
1086 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1087 const char *file ATTRIBUTE_UNUSED
)
1089 dw_fde_ref fde
= cfun
->fde
;
1090 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1092 if (fde
->dw_fde_vms_begin_epilogue
)
1095 /* Output a label to mark the endpoint of the code generated for this
1097 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1098 current_function_funcdef_no
);
1099 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1100 current_function_funcdef_no
);
1101 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1104 /* Output a marker (i.e. a label) for the absolute end of the generated code
1105 for a function definition. This gets called *after* the epilogue code has
1109 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1110 const char *file ATTRIBUTE_UNUSED
)
1113 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1115 last_var_location_insn
= NULL_RTX
;
1116 cached_next_real_insn
= NULL_RTX
;
1118 if (dwarf2out_do_cfi_asm ())
1119 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1121 /* Output a label to mark the endpoint of the code generated for this
1123 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1124 current_function_funcdef_no
);
1125 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1127 gcc_assert (fde
!= NULL
);
1128 if (fde
->dw_fde_second_begin
== NULL
)
1129 fde
->dw_fde_end
= xstrdup (label
);
1133 dwarf2out_frame_finish (void)
1135 /* Output call frame information. */
1136 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1137 output_call_frame_info (0);
1139 /* Output another copy for the unwinder. */
1140 if ((flag_unwind_tables
|| flag_exceptions
)
1141 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1142 output_call_frame_info (1);
1145 /* Note that the current function section is being used for code. */
1148 dwarf2out_note_section_used (void)
1150 section
*sec
= current_function_section ();
1151 if (sec
== text_section
)
1152 text_section_used
= true;
1153 else if (sec
== cold_text_section
)
1154 cold_text_section_used
= true;
1157 static void var_location_switch_text_section (void);
1158 static void set_cur_line_info_table (section
*);
1161 dwarf2out_switch_text_section (void)
1164 dw_fde_ref fde
= cfun
->fde
;
1166 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1168 if (!in_cold_section_p
)
1170 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1171 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1172 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1176 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1177 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1178 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1180 have_multiple_function_sections
= true;
1182 /* There is no need to mark used sections when not debugging. */
1183 if (cold_text_section
!= NULL
)
1184 dwarf2out_note_section_used ();
1186 if (dwarf2out_do_cfi_asm ())
1187 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1189 /* Now do the real section switch. */
1190 sect
= current_function_section ();
1191 switch_to_section (sect
);
1193 fde
->second_in_std_section
1194 = (sect
== text_section
1195 || (cold_text_section
&& sect
== cold_text_section
));
1197 if (dwarf2out_do_cfi_asm ())
1198 dwarf2out_do_cfi_startproc (true);
1200 var_location_switch_text_section ();
1202 if (cold_text_section
!= NULL
)
1203 set_cur_line_info_table (sect
);
1206 /* And now, the subset of the debugging information support code necessary
1207 for emitting location expressions. */
1209 /* Data about a single source file. */
1210 struct GTY(()) dwarf_file_data
{
1211 const char * filename
;
1215 typedef struct GTY(()) deferred_locations_struct
1219 } deferred_locations
;
1222 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1225 /* Describe an entry into the .debug_addr section. */
1229 ate_kind_rtx_dtprel
,
1233 typedef struct GTY(()) addr_table_entry_struct
{
1235 unsigned int refcount
;
1237 union addr_table_entry_struct_union
1239 rtx
GTY ((tag ("0"))) rtl
;
1240 char * GTY ((tag ("1"))) label
;
1242 GTY ((desc ("%1.kind"))) addr
;
1246 /* Location lists are ranges + location descriptions for that range,
1247 so you can track variables that are in different places over
1248 their entire life. */
1249 typedef struct GTY(()) dw_loc_list_struct
{
1250 dw_loc_list_ref dw_loc_next
;
1251 const char *begin
; /* Label and addr_entry for start of range */
1252 addr_table_entry
*begin_entry
;
1253 const char *end
; /* Label for end of range */
1254 char *ll_symbol
; /* Label for beginning of location list.
1255 Only on head of list */
1256 const char *section
; /* Section this loclist is relative to */
1257 dw_loc_descr_ref expr
;
1259 /* True if all addresses in this and subsequent lists are known to be
1262 /* True if this list has been replaced by dw_loc_next. */
1265 /* True if the range should be emitted even if begin and end
1270 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1272 /* Convert a DWARF stack opcode into its string name. */
1275 dwarf_stack_op_name (unsigned int op
)
1277 const char *name
= get_DW_OP_name (op
);
1282 return "OP_<unknown>";
1285 /* Return a pointer to a newly allocated location description. Location
1286 descriptions are simple expression terms that can be strung
1287 together to form more complicated location (address) descriptions. */
1289 static inline dw_loc_descr_ref
1290 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1291 unsigned HOST_WIDE_INT oprnd2
)
1293 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1295 descr
->dw_loc_opc
= op
;
1296 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1297 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1298 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1299 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1300 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1301 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1306 /* Return a pointer to a newly allocated location description for
1309 static inline dw_loc_descr_ref
1310 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1313 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1316 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1319 /* Add a location description term to a location description expression. */
1322 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1324 dw_loc_descr_ref
*d
;
1326 /* Find the end of the chain. */
1327 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1333 /* Compare two location operands for exact equality. */
1336 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1338 if (a
->val_class
!= b
->val_class
)
1340 switch (a
->val_class
)
1342 case dw_val_class_none
:
1344 case dw_val_class_addr
:
1345 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1347 case dw_val_class_offset
:
1348 case dw_val_class_unsigned_const
:
1349 case dw_val_class_const
:
1350 case dw_val_class_range_list
:
1351 case dw_val_class_lineptr
:
1352 case dw_val_class_macptr
:
1353 /* These are all HOST_WIDE_INT, signed or unsigned. */
1354 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1356 case dw_val_class_loc
:
1357 return a
->v
.val_loc
== b
->v
.val_loc
;
1358 case dw_val_class_loc_list
:
1359 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1360 case dw_val_class_die_ref
:
1361 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1362 case dw_val_class_fde_ref
:
1363 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1364 case dw_val_class_lbl_id
:
1365 case dw_val_class_high_pc
:
1366 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1367 case dw_val_class_str
:
1368 return a
->v
.val_str
== b
->v
.val_str
;
1369 case dw_val_class_flag
:
1370 return a
->v
.val_flag
== b
->v
.val_flag
;
1371 case dw_val_class_file
:
1372 return a
->v
.val_file
== b
->v
.val_file
;
1373 case dw_val_class_decl_ref
:
1374 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1376 case dw_val_class_const_double
:
1377 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1378 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1380 case dw_val_class_vec
:
1382 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1383 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1385 return (a_len
== b_len
1386 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1389 case dw_val_class_data8
:
1390 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1392 case dw_val_class_vms_delta
:
1393 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1394 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1399 /* Compare two location atoms for exact equality. */
1402 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1404 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1407 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1408 address size, but since we always allocate cleared storage it
1409 should be zero for other types of locations. */
1410 if (a
->dtprel
!= b
->dtprel
)
1413 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1414 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1417 /* Compare two complete location expressions for exact equality. */
1420 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1426 if (a
== NULL
|| b
== NULL
)
1428 if (!loc_descr_equal_p_1 (a
, b
))
1437 /* Add a constant OFFSET to a location expression. */
1440 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1442 dw_loc_descr_ref loc
;
1445 gcc_assert (*list_head
!= NULL
);
1450 /* Find the end of the chain. */
1451 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1455 if (loc
->dw_loc_opc
== DW_OP_fbreg
1456 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1457 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1458 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1459 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1461 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1462 offset. Don't optimize if an signed integer overflow would happen. */
1464 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1465 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1468 else if (offset
> 0)
1469 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1473 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1474 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1478 /* Add a constant OFFSET to a location list. */
1481 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1484 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1485 loc_descr_plus_const (&d
->expr
, offset
);
1488 #define DWARF_REF_SIZE \
1489 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1491 static unsigned long int get_base_type_offset (dw_die_ref
);
1493 /* Return the size of a location descriptor. */
1495 static unsigned long
1496 size_of_loc_descr (dw_loc_descr_ref loc
)
1498 unsigned long size
= 1;
1500 switch (loc
->dw_loc_opc
)
1503 size
+= DWARF2_ADDR_SIZE
;
1505 case DW_OP_GNU_addr_index
:
1506 case DW_OP_GNU_const_index
:
1507 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1508 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1527 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1530 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1535 case DW_OP_plus_uconst
:
1536 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1574 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1577 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1580 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1583 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1584 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1587 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1589 case DW_OP_bit_piece
:
1590 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1591 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1593 case DW_OP_deref_size
:
1594 case DW_OP_xderef_size
:
1603 case DW_OP_call_ref
:
1604 size
+= DWARF_REF_SIZE
;
1606 case DW_OP_implicit_value
:
1607 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1608 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1610 case DW_OP_GNU_implicit_pointer
:
1611 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1613 case DW_OP_GNU_entry_value
:
1615 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1616 size
+= size_of_uleb128 (op_size
) + op_size
;
1619 case DW_OP_GNU_const_type
:
1622 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1623 size
+= size_of_uleb128 (o
) + 1;
1624 switch (loc
->dw_loc_oprnd2
.val_class
)
1626 case dw_val_class_vec
:
1627 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1628 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1630 case dw_val_class_const
:
1631 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1633 case dw_val_class_const_double
:
1634 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1641 case DW_OP_GNU_regval_type
:
1644 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1645 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1646 + size_of_uleb128 (o
);
1649 case DW_OP_GNU_deref_type
:
1652 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1653 size
+= 1 + size_of_uleb128 (o
);
1656 case DW_OP_GNU_convert
:
1657 case DW_OP_GNU_reinterpret
:
1658 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1659 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1663 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1664 size
+= size_of_uleb128 (o
);
1667 case DW_OP_GNU_parameter_ref
:
1677 /* Return the size of a series of location descriptors. */
1680 size_of_locs (dw_loc_descr_ref loc
)
1685 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1686 field, to avoid writing to a PCH file. */
1687 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1689 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1691 size
+= size_of_loc_descr (l
);
1696 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1698 l
->dw_loc_addr
= size
;
1699 size
+= size_of_loc_descr (l
);
1705 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1706 static void get_ref_die_offset_label (char *, dw_die_ref
);
1707 static unsigned long int get_ref_die_offset (dw_die_ref
);
1709 /* Output location description stack opcode's operands (if any).
1710 The for_eh_or_skip parameter controls whether register numbers are
1711 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1712 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1713 info). This should be suppressed for the cases that have not been converted
1714 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1717 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1719 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1720 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1722 switch (loc
->dw_loc_opc
)
1724 #ifdef DWARF2_DEBUGGING_INFO
1727 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1732 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1733 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1735 fputc ('\n', asm_out_file
);
1740 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1745 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1746 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1748 fputc ('\n', asm_out_file
);
1753 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1754 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1761 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1762 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1764 dw2_asm_output_data (2, offset
, NULL
);
1767 case DW_OP_implicit_value
:
1768 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1769 switch (val2
->val_class
)
1771 case dw_val_class_const
:
1772 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1774 case dw_val_class_vec
:
1776 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1777 unsigned int len
= val2
->v
.val_vec
.length
;
1781 if (elt_size
> sizeof (HOST_WIDE_INT
))
1786 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1789 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1790 "fp or vector constant word %u", i
);
1793 case dw_val_class_const_double
:
1795 unsigned HOST_WIDE_INT first
, second
;
1797 if (WORDS_BIG_ENDIAN
)
1799 first
= val2
->v
.val_double
.high
;
1800 second
= val2
->v
.val_double
.low
;
1804 first
= val2
->v
.val_double
.low
;
1805 second
= val2
->v
.val_double
.high
;
1807 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1809 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1813 case dw_val_class_addr
:
1814 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1815 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1830 case DW_OP_implicit_value
:
1831 /* We currently don't make any attempt to make sure these are
1832 aligned properly like we do for the main unwind info, so
1833 don't support emitting things larger than a byte if we're
1834 only doing unwinding. */
1839 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1842 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1845 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1848 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1850 case DW_OP_plus_uconst
:
1851 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1885 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1889 unsigned r
= val1
->v
.val_unsigned
;
1890 if (for_eh_or_skip
>= 0)
1891 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1892 gcc_assert (size_of_uleb128 (r
)
1893 == size_of_uleb128 (val1
->v
.val_unsigned
));
1894 dw2_asm_output_data_uleb128 (r
, NULL
);
1898 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1902 unsigned r
= val1
->v
.val_unsigned
;
1903 if (for_eh_or_skip
>= 0)
1904 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1905 gcc_assert (size_of_uleb128 (r
)
1906 == size_of_uleb128 (val1
->v
.val_unsigned
));
1907 dw2_asm_output_data_uleb128 (r
, NULL
);
1908 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1912 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1914 case DW_OP_bit_piece
:
1915 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1916 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1918 case DW_OP_deref_size
:
1919 case DW_OP_xderef_size
:
1920 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1926 if (targetm
.asm_out
.output_dwarf_dtprel
)
1928 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1931 fputc ('\n', asm_out_file
);
1938 #ifdef DWARF2_DEBUGGING_INFO
1939 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1946 case DW_OP_GNU_addr_index
:
1947 case DW_OP_GNU_const_index
:
1948 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1949 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1950 "(index into .debug_addr)");
1953 case DW_OP_GNU_implicit_pointer
:
1955 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1956 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1957 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1958 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1959 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1960 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1964 case DW_OP_GNU_entry_value
:
1965 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1966 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1969 case DW_OP_GNU_const_type
:
1971 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1973 dw2_asm_output_data_uleb128 (o
, NULL
);
1974 switch (val2
->val_class
)
1976 case dw_val_class_const
:
1977 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1978 dw2_asm_output_data (1, l
, NULL
);
1979 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1981 case dw_val_class_vec
:
1983 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1984 unsigned int len
= val2
->v
.val_vec
.length
;
1989 dw2_asm_output_data (1, l
, NULL
);
1990 if (elt_size
> sizeof (HOST_WIDE_INT
))
1995 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1998 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1999 "fp or vector constant word %u", i
);
2002 case dw_val_class_const_double
:
2004 unsigned HOST_WIDE_INT first
, second
;
2005 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2007 dw2_asm_output_data (1, 2 * l
, NULL
);
2008 if (WORDS_BIG_ENDIAN
)
2010 first
= val2
->v
.val_double
.high
;
2011 second
= val2
->v
.val_double
.low
;
2015 first
= val2
->v
.val_double
.low
;
2016 second
= val2
->v
.val_double
.high
;
2018 dw2_asm_output_data (l
, first
, NULL
);
2019 dw2_asm_output_data (l
, second
, NULL
);
2027 case DW_OP_GNU_regval_type
:
2029 unsigned r
= val1
->v
.val_unsigned
;
2030 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2032 if (for_eh_or_skip
>= 0)
2034 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2035 gcc_assert (size_of_uleb128 (r
)
2036 == size_of_uleb128 (val1
->v
.val_unsigned
));
2038 dw2_asm_output_data_uleb128 (r
, NULL
);
2039 dw2_asm_output_data_uleb128 (o
, NULL
);
2042 case DW_OP_GNU_deref_type
:
2044 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2046 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2047 dw2_asm_output_data_uleb128 (o
, NULL
);
2050 case DW_OP_GNU_convert
:
2051 case DW_OP_GNU_reinterpret
:
2052 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2053 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2056 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2058 dw2_asm_output_data_uleb128 (o
, NULL
);
2062 case DW_OP_GNU_parameter_ref
:
2065 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2066 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2067 dw2_asm_output_data (4, o
, NULL
);
2072 /* Other codes have no operands. */
2077 /* Output a sequence of location operations.
2078 The for_eh_or_skip parameter controls whether register numbers are
2079 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2080 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2081 info). This should be suppressed for the cases that have not been converted
2082 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2085 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2087 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2089 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2090 /* Output the opcode. */
2091 if (for_eh_or_skip
>= 0
2092 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2094 unsigned r
= (opc
- DW_OP_breg0
);
2095 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2096 gcc_assert (r
<= 31);
2097 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2099 else if (for_eh_or_skip
>= 0
2100 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2102 unsigned r
= (opc
- DW_OP_reg0
);
2103 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2104 gcc_assert (r
<= 31);
2105 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2108 dw2_asm_output_data (1, opc
,
2109 "%s", dwarf_stack_op_name (opc
));
2111 /* Output the operand(s) (if any). */
2112 output_loc_operands (loc
, for_eh_or_skip
);
2116 /* Output location description stack opcode's operands (if any).
2117 The output is single bytes on a line, suitable for .cfi_escape. */
2120 output_loc_operands_raw (dw_loc_descr_ref loc
)
2122 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2123 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2125 switch (loc
->dw_loc_opc
)
2128 case DW_OP_GNU_addr_index
:
2129 case DW_OP_GNU_const_index
:
2130 case DW_OP_implicit_value
:
2131 /* We cannot output addresses in .cfi_escape, only bytes. */
2137 case DW_OP_deref_size
:
2138 case DW_OP_xderef_size
:
2139 fputc (',', asm_out_file
);
2140 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2145 fputc (',', asm_out_file
);
2146 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2151 fputc (',', asm_out_file
);
2152 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2157 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2158 fputc (',', asm_out_file
);
2159 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2167 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2168 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2170 fputc (',', asm_out_file
);
2171 dw2_asm_output_data_raw (2, offset
);
2177 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2178 gcc_assert (size_of_uleb128 (r
)
2179 == size_of_uleb128 (val1
->v
.val_unsigned
));
2180 fputc (',', asm_out_file
);
2181 dw2_asm_output_data_uleb128_raw (r
);
2186 case DW_OP_plus_uconst
:
2188 fputc (',', asm_out_file
);
2189 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2192 case DW_OP_bit_piece
:
2193 fputc (',', asm_out_file
);
2194 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2195 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2232 fputc (',', asm_out_file
);
2233 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2238 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2239 gcc_assert (size_of_uleb128 (r
)
2240 == size_of_uleb128 (val1
->v
.val_unsigned
));
2241 fputc (',', asm_out_file
);
2242 dw2_asm_output_data_uleb128_raw (r
);
2243 fputc (',', asm_out_file
);
2244 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2248 case DW_OP_GNU_implicit_pointer
:
2249 case DW_OP_GNU_entry_value
:
2250 case DW_OP_GNU_const_type
:
2251 case DW_OP_GNU_regval_type
:
2252 case DW_OP_GNU_deref_type
:
2253 case DW_OP_GNU_convert
:
2254 case DW_OP_GNU_reinterpret
:
2255 case DW_OP_GNU_parameter_ref
:
2260 /* Other codes have no operands. */
2266 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2270 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2271 /* Output the opcode. */
2272 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2274 unsigned r
= (opc
- DW_OP_breg0
);
2275 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2276 gcc_assert (r
<= 31);
2277 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2279 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2281 unsigned r
= (opc
- DW_OP_reg0
);
2282 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2283 gcc_assert (r
<= 31);
2284 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2286 /* Output the opcode. */
2287 fprintf (asm_out_file
, "%#x", opc
);
2288 output_loc_operands_raw (loc
);
2290 if (!loc
->dw_loc_next
)
2292 loc
= loc
->dw_loc_next
;
2294 fputc (',', asm_out_file
);
2298 /* This function builds a dwarf location descriptor sequence from a
2299 dw_cfa_location, adding the given OFFSET to the result of the
2302 struct dw_loc_descr_struct
*
2303 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2305 struct dw_loc_descr_struct
*head
, *tmp
;
2307 offset
+= cfa
->offset
;
2311 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2312 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2313 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2314 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2315 add_loc_descr (&head
, tmp
);
2318 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2319 add_loc_descr (&head
, tmp
);
2323 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2328 /* This function builds a dwarf location descriptor sequence for
2329 the address at OFFSET from the CFA when stack is aligned to
2332 struct dw_loc_descr_struct
*
2333 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2334 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2336 struct dw_loc_descr_struct
*head
;
2337 unsigned int dwarf_fp
2338 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2340 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2341 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2343 head
= new_reg_loc_descr (dwarf_fp
, 0);
2344 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2345 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2346 loc_descr_plus_const (&head
, offset
);
2349 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2353 /* And now, the support for symbolic debugging information. */
2355 /* .debug_str support. */
2356 static int output_indirect_string (void **, void *);
2358 static void dwarf2out_init (const char *);
2359 static void dwarf2out_finish (const char *);
2360 static void dwarf2out_assembly_start (void);
2361 static void dwarf2out_define (unsigned int, const char *);
2362 static void dwarf2out_undef (unsigned int, const char *);
2363 static void dwarf2out_start_source_file (unsigned, const char *);
2364 static void dwarf2out_end_source_file (unsigned);
2365 static void dwarf2out_function_decl (tree
);
2366 static void dwarf2out_begin_block (unsigned, unsigned);
2367 static void dwarf2out_end_block (unsigned, unsigned);
2368 static bool dwarf2out_ignore_block (const_tree
);
2369 static void dwarf2out_global_decl (tree
);
2370 static void dwarf2out_type_decl (tree
, int);
2371 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2372 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2374 static void dwarf2out_abstract_function (tree
);
2375 static void dwarf2out_var_location (rtx
);
2376 static void dwarf2out_begin_function (tree
);
2377 static void dwarf2out_end_function (unsigned int);
2378 static void dwarf2out_set_name (tree
, tree
);
2380 /* The debug hooks structure. */
2382 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2386 dwarf2out_assembly_start
,
2389 dwarf2out_start_source_file
,
2390 dwarf2out_end_source_file
,
2391 dwarf2out_begin_block
,
2392 dwarf2out_end_block
,
2393 dwarf2out_ignore_block
,
2394 dwarf2out_source_line
,
2395 dwarf2out_begin_prologue
,
2396 #if VMS_DEBUGGING_INFO
2397 dwarf2out_vms_end_prologue
,
2398 dwarf2out_vms_begin_epilogue
,
2400 debug_nothing_int_charstar
,
2401 debug_nothing_int_charstar
,
2403 dwarf2out_end_epilogue
,
2404 dwarf2out_begin_function
,
2405 dwarf2out_end_function
, /* end_function */
2406 dwarf2out_function_decl
, /* function_decl */
2407 dwarf2out_global_decl
,
2408 dwarf2out_type_decl
, /* type_decl */
2409 dwarf2out_imported_module_or_decl
,
2410 debug_nothing_tree
, /* deferred_inline_function */
2411 /* The DWARF 2 backend tries to reduce debugging bloat by not
2412 emitting the abstract description of inline functions until
2413 something tries to reference them. */
2414 dwarf2out_abstract_function
, /* outlining_inline_function */
2415 debug_nothing_rtx
, /* label */
2416 debug_nothing_int
, /* handle_pch */
2417 dwarf2out_var_location
,
2418 dwarf2out_switch_text_section
,
2420 1, /* start_end_main_source_file */
2421 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2424 /* NOTE: In the comments in this file, many references are made to
2425 "Debugging Information Entries". This term is abbreviated as `DIE'
2426 throughout the remainder of this file. */
2428 /* An internal representation of the DWARF output is built, and then
2429 walked to generate the DWARF debugging info. The walk of the internal
2430 representation is done after the entire program has been compiled.
2431 The types below are used to describe the internal representation. */
2433 /* Whether to put type DIEs into their own section .debug_types instead
2434 of making them part of the .debug_info section. Only supported for
2435 Dwarf V4 or higher and the user didn't disable them through
2436 -fno-debug-types-section. It is more efficient to put them in a
2437 separate comdat sections since the linker will then be able to
2438 remove duplicates. But not all tools support .debug_types sections
2441 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2443 /* Various DIE's use offsets relative to the beginning of the
2444 .debug_info section to refer to each other. */
2446 typedef long int dw_offset
;
2448 /* Define typedefs here to avoid circular dependencies. */
2450 typedef struct dw_attr_struct
*dw_attr_ref
;
2451 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2452 typedef struct pubname_struct
*pubname_ref
;
2453 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2454 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2455 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2457 /* The entries in the line_info table more-or-less mirror the opcodes
2458 that are used in the real dwarf line table. Arrays of these entries
2459 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2462 enum dw_line_info_opcode
{
2463 /* Emit DW_LNE_set_address; the operand is the label index. */
2466 /* Emit a row to the matrix with the given line. This may be done
2467 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2471 /* Emit a DW_LNS_set_file. */
2474 /* Emit a DW_LNS_set_column. */
2477 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2480 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2481 LI_set_prologue_end
,
2482 LI_set_epilogue_begin
,
2484 /* Emit a DW_LNE_set_discriminator. */
2485 LI_set_discriminator
2488 typedef struct GTY(()) dw_line_info_struct
{
2489 enum dw_line_info_opcode opcode
;
2491 } dw_line_info_entry
;
2494 typedef struct GTY(()) dw_line_info_table_struct
{
2495 /* The label that marks the end of this section. */
2496 const char *end_label
;
2498 /* The values for the last row of the matrix, as collected in the table.
2499 These are used to minimize the changes to the next row. */
2500 unsigned int file_num
;
2501 unsigned int line_num
;
2502 unsigned int column_num
;
2507 vec
<dw_line_info_entry
, va_gc
> *entries
;
2508 } dw_line_info_table
;
2510 typedef dw_line_info_table
*dw_line_info_table_p
;
2513 /* Each DIE attribute has a field specifying the attribute kind,
2514 a link to the next attribute in the chain, and an attribute value.
2515 Attributes are typically linked below the DIE they modify. */
2517 typedef struct GTY(()) dw_attr_struct
{
2518 enum dwarf_attribute dw_attr
;
2519 dw_val_node dw_attr_val
;
2524 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2525 The children of each node form a circular list linked by
2526 die_sib. die_child points to the node *before* the "first" child node. */
2528 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2529 union die_symbol_or_type_node
2531 const char * GTY ((tag ("0"))) die_symbol
;
2532 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2534 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2535 vec
<dw_attr_node
, va_gc
> *die_attr
;
2536 dw_die_ref die_parent
;
2537 dw_die_ref die_child
;
2539 dw_die_ref die_definition
; /* ref from a specification to its definition */
2540 dw_offset die_offset
;
2541 unsigned long die_abbrev
;
2543 unsigned int decl_id
;
2544 enum dwarf_tag die_tag
;
2545 /* Die is used and must not be pruned as unused. */
2546 BOOL_BITFIELD die_perennial_p
: 1;
2547 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2548 /* Lots of spare bits. */
2552 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2553 #define FOR_EACH_CHILD(die, c, expr) do { \
2554 c = die->die_child; \
2558 } while (c != die->die_child); \
2561 /* The pubname structure */
2563 typedef struct GTY(()) pubname_struct
{
2570 struct GTY(()) dw_ranges_struct
{
2571 /* If this is positive, it's a block number, otherwise it's a
2572 bitwise-negated index into dw_ranges_by_label. */
2576 /* A structure to hold a macinfo entry. */
2578 typedef struct GTY(()) macinfo_struct
{
2580 unsigned HOST_WIDE_INT lineno
;
2586 struct GTY(()) dw_ranges_by_label_struct
{
2591 /* The comdat type node structure. */
2592 typedef struct GTY(()) comdat_type_struct
2594 dw_die_ref root_die
;
2595 dw_die_ref type_die
;
2596 dw_die_ref skeleton_die
;
2597 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2598 struct comdat_type_struct
*next
;
2602 /* The limbo die list structure. */
2603 typedef struct GTY(()) limbo_die_struct
{
2606 struct limbo_die_struct
*next
;
2610 typedef struct skeleton_chain_struct
2614 struct skeleton_chain_struct
*parent
;
2616 skeleton_chain_node
;
2618 /* Define a macro which returns nonzero for a TYPE_DECL which was
2619 implicitly generated for a type.
2621 Note that, unlike the C front-end (which generates a NULL named
2622 TYPE_DECL node for each complete tagged type, each array type,
2623 and each function type node created) the C++ front-end generates
2624 a _named_ TYPE_DECL node for each tagged type node created.
2625 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2626 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2627 front-end, but for each type, tagged or not. */
2629 #define TYPE_DECL_IS_STUB(decl) \
2630 (DECL_NAME (decl) == NULL_TREE \
2631 || (DECL_ARTIFICIAL (decl) \
2632 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2633 /* This is necessary for stub decls that \
2634 appear in nested inline functions. */ \
2635 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2636 && (decl_ultimate_origin (decl) \
2637 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2639 /* Information concerning the compilation unit's programming
2640 language, and compiler version. */
2642 /* Fixed size portion of the DWARF compilation unit header. */
2643 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2644 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2646 /* Fixed size portion of the DWARF comdat type unit header. */
2647 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2648 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2649 + DWARF_OFFSET_SIZE)
2651 /* Fixed size portion of public names info. */
2652 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2654 /* Fixed size portion of the address range info. */
2655 #define DWARF_ARANGES_HEADER_SIZE \
2656 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2657 DWARF2_ADDR_SIZE * 2) \
2658 - DWARF_INITIAL_LENGTH_SIZE)
2660 /* Size of padding portion in the address range info. It must be
2661 aligned to twice the pointer size. */
2662 #define DWARF_ARANGES_PAD_SIZE \
2663 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2664 DWARF2_ADDR_SIZE * 2) \
2665 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2667 /* Use assembler line directives if available. */
2668 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2669 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2670 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2672 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2676 /* Minimum line offset in a special line info. opcode.
2677 This value was chosen to give a reasonable range of values. */
2678 #define DWARF_LINE_BASE -10
2680 /* First special line opcode - leave room for the standard opcodes. */
2681 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2683 /* Range of line offsets in a special line info. opcode. */
2684 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2686 /* Flag that indicates the initial value of the is_stmt_start flag.
2687 In the present implementation, we do not mark any lines as
2688 the beginning of a source statement, because that information
2689 is not made available by the GCC front-end. */
2690 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2692 /* Maximum number of operations per instruction bundle. */
2693 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2694 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2697 /* This location is used by calc_die_sizes() to keep track
2698 the offset of each DIE within the .debug_info section. */
2699 static unsigned long next_die_offset
;
2701 /* Record the root of the DIE's built for the current compilation unit. */
2702 static GTY(()) dw_die_ref single_comp_unit_die
;
2704 /* A list of type DIEs that have been separated into comdat sections. */
2705 static GTY(()) comdat_type_node
*comdat_type_list
;
2707 /* A list of DIEs with a NULL parent waiting to be relocated. */
2708 static GTY(()) limbo_die_node
*limbo_die_list
;
2710 /* A list of DIEs for which we may have to generate
2711 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2712 static GTY(()) limbo_die_node
*deferred_asm_name
;
2714 /* Filenames referenced by this compilation unit. */
2715 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2717 /* A hash table of references to DIE's that describe declarations.
2718 The key is a DECL_UID() which is a unique number identifying each decl. */
2719 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2721 /* A hash table of references to DIE's that describe COMMON blocks.
2722 The key is DECL_UID() ^ die_parent. */
2723 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2725 typedef struct GTY(()) die_arg_entry_struct
{
2731 /* Node of the variable location list. */
2732 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2733 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2734 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2735 in mode of the EXPR_LIST node and first EXPR_LIST operand
2736 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2737 location or NULL for padding. For larger bitsizes,
2738 mode is 0 and first operand is a CONCAT with bitsize
2739 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2740 NULL as second operand. */
2742 const char * GTY (()) label
;
2743 struct var_loc_node
* GTY (()) next
;
2746 /* Variable location list. */
2747 struct GTY (()) var_loc_list_def
{
2748 struct var_loc_node
* GTY (()) first
;
2750 /* Pointer to the last but one or last element of the
2751 chained list. If the list is empty, both first and
2752 last are NULL, if the list contains just one node
2753 or the last node certainly is not redundant, it points
2754 to the last node, otherwise points to the last but one.
2755 Do not mark it for GC because it is marked through the chain. */
2756 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2758 /* Pointer to the last element before section switch,
2759 if NULL, either sections weren't switched or first
2760 is after section switch. */
2761 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2763 /* DECL_UID of the variable decl. */
2764 unsigned int decl_id
;
2766 typedef struct var_loc_list_def var_loc_list
;
2768 /* Call argument location list. */
2769 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2770 rtx
GTY (()) call_arg_loc_note
;
2771 const char * GTY (()) label
;
2772 tree
GTY (()) block
;
2774 rtx
GTY (()) symbol_ref
;
2775 struct call_arg_loc_node
* GTY (()) next
;
2779 /* Table of decl location linked lists. */
2780 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2782 /* Head and tail of call_arg_loc chain. */
2783 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2784 static struct call_arg_loc_node
*call_arg_loc_last
;
2786 /* Number of call sites in the current function. */
2787 static int call_site_count
= -1;
2788 /* Number of tail call sites in the current function. */
2789 static int tail_call_site_count
= -1;
2791 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2793 static vec
<dw_die_ref
> block_map
;
2795 /* A cached location list. */
2796 struct GTY (()) cached_dw_loc_list_def
{
2797 /* The DECL_UID of the decl that this entry describes. */
2798 unsigned int decl_id
;
2800 /* The cached location list. */
2801 dw_loc_list_ref loc_list
;
2803 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2805 /* Table of cached location lists. */
2806 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2808 /* A pointer to the base of a list of references to DIE's that
2809 are uniquely identified by their tag, presence/absence of
2810 children DIE's, and list of attribute/value pairs. */
2811 static GTY((length ("abbrev_die_table_allocated")))
2812 dw_die_ref
*abbrev_die_table
;
2814 /* Number of elements currently allocated for abbrev_die_table. */
2815 static GTY(()) unsigned abbrev_die_table_allocated
;
2817 /* Number of elements in type_die_table currently in use. */
2818 static GTY(()) unsigned abbrev_die_table_in_use
;
2820 /* Size (in elements) of increments by which we may expand the
2821 abbrev_die_table. */
2822 #define ABBREV_DIE_TABLE_INCREMENT 256
2824 /* A global counter for generating labels for line number data. */
2825 static unsigned int line_info_label_num
;
2827 /* The current table to which we should emit line number information
2828 for the current function. This will be set up at the beginning of
2829 assembly for the function. */
2830 static dw_line_info_table
*cur_line_info_table
;
2832 /* The two default tables of line number info. */
2833 static GTY(()) dw_line_info_table
*text_section_line_info
;
2834 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2836 /* The set of all non-default tables of line number info. */
2837 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2839 /* A flag to tell pubnames/types export if there is an info section to
2841 static bool info_section_emitted
;
2843 /* A pointer to the base of a table that contains a list of publicly
2844 accessible names. */
2845 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2847 /* A pointer to the base of a table that contains a list of publicly
2848 accessible types. */
2849 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2851 /* A pointer to the base of a table that contains a list of macro
2852 defines/undefines (and file start/end markers). */
2853 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2855 /* True if .debug_macinfo or .debug_macros section is going to be
2857 #define have_macinfo \
2858 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2859 && !macinfo_table->is_empty ())
2861 /* Array of dies for which we should generate .debug_ranges info. */
2862 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2864 /* Number of elements currently allocated for ranges_table. */
2865 static GTY(()) unsigned ranges_table_allocated
;
2867 /* Number of elements in ranges_table currently in use. */
2868 static GTY(()) unsigned ranges_table_in_use
;
2870 /* Array of pairs of labels referenced in ranges_table. */
2871 static GTY ((length ("ranges_by_label_allocated")))
2872 dw_ranges_by_label_ref ranges_by_label
;
2874 /* Number of elements currently allocated for ranges_by_label. */
2875 static GTY(()) unsigned ranges_by_label_allocated
;
2877 /* Number of elements in ranges_by_label currently in use. */
2878 static GTY(()) unsigned ranges_by_label_in_use
;
2880 /* Size (in elements) of increments by which we may expand the
2882 #define RANGES_TABLE_INCREMENT 64
2884 /* Whether we have location lists that need outputting */
2885 static GTY(()) bool have_location_lists
;
2887 /* Unique label counter. */
2888 static GTY(()) unsigned int loclabel_num
;
2890 /* Unique label counter for point-of-call tables. */
2891 static GTY(()) unsigned int poc_label_num
;
2893 /* Record whether the function being analyzed contains inlined functions. */
2894 static int current_function_has_inlines
;
2896 /* The last file entry emitted by maybe_emit_file(). */
2897 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2899 /* Number of internal labels generated by gen_internal_sym(). */
2900 static GTY(()) int label_num
;
2902 /* Cached result of previous call to lookup_filename. */
2903 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2905 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2907 /* Instances of generic types for which we need to generate debug
2908 info that describe their generic parameters and arguments. That
2909 generation needs to happen once all types are properly laid out so
2910 we do it at the end of compilation. */
2911 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2913 /* Offset from the "steady-state frame pointer" to the frame base,
2914 within the current function. */
2915 static HOST_WIDE_INT frame_pointer_fb_offset
;
2916 static bool frame_pointer_fb_offset_valid
;
2918 static vec
<dw_die_ref
> base_types
;
2920 /* Forward declarations for functions defined in this file. */
2922 static int is_pseudo_reg (const_rtx
);
2923 static tree
type_main_variant (tree
);
2924 static int is_tagged_type (const_tree
);
2925 static const char *dwarf_tag_name (unsigned);
2926 static const char *dwarf_attr_name (unsigned);
2927 static const char *dwarf_form_name (unsigned);
2928 static tree
decl_ultimate_origin (const_tree
);
2929 static tree
decl_class_context (tree
);
2930 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2931 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2932 static inline unsigned int AT_index (dw_attr_ref
);
2933 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2934 static inline unsigned AT_flag (dw_attr_ref
);
2935 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2936 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2937 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2938 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2939 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2940 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2941 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2942 unsigned int, unsigned char *);
2943 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2944 static hashval_t
debug_str_do_hash (const void *);
2945 static int debug_str_eq (const void *, const void *);
2946 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2947 static inline const char *AT_string (dw_attr_ref
);
2948 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2949 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2950 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2951 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2952 static inline int AT_ref_external (dw_attr_ref
);
2953 static inline void set_AT_ref_external (dw_attr_ref
, int);
2954 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2955 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2956 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2957 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2959 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2960 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2961 static void remove_addr_table_entry (addr_table_entry
*);
2962 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2963 static inline rtx
AT_addr (dw_attr_ref
);
2964 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2965 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2966 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2967 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2968 unsigned HOST_WIDE_INT
);
2969 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2970 unsigned long, bool);
2971 static inline const char *AT_lbl (dw_attr_ref
);
2972 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2973 static const char *get_AT_low_pc (dw_die_ref
);
2974 static const char *get_AT_hi_pc (dw_die_ref
);
2975 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2976 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2977 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2978 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2979 static bool is_cxx (void);
2980 static bool is_fortran (void);
2981 static bool is_ada (void);
2982 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2983 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2984 static void add_child_die (dw_die_ref
, dw_die_ref
);
2985 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2986 static dw_die_ref
lookup_type_die (tree
);
2987 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2988 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2989 static void equate_type_number_to_die (tree
, dw_die_ref
);
2990 static hashval_t
decl_die_table_hash (const void *);
2991 static int decl_die_table_eq (const void *, const void *);
2992 static dw_die_ref
lookup_decl_die (tree
);
2993 static hashval_t
common_block_die_table_hash (const void *);
2994 static int common_block_die_table_eq (const void *, const void *);
2995 static hashval_t
decl_loc_table_hash (const void *);
2996 static int decl_loc_table_eq (const void *, const void *);
2997 static var_loc_list
*lookup_decl_loc (const_tree
);
2998 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2999 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3000 static void print_spaces (FILE *);
3001 static void print_die (dw_die_ref
, FILE *);
3002 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3003 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3004 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3005 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3006 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3007 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3008 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3009 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3010 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3011 struct md5_ctx
*, int *);
3012 struct checksum_attributes
;
3013 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3014 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3015 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3016 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3017 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3018 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3019 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3020 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3021 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3022 static void compute_section_prefix (dw_die_ref
);
3023 static int is_type_die (dw_die_ref
);
3024 static int is_comdat_die (dw_die_ref
);
3025 static int is_symbol_die (dw_die_ref
);
3026 static void assign_symbol_names (dw_die_ref
);
3027 static void break_out_includes (dw_die_ref
);
3028 static int is_declaration_die (dw_die_ref
);
3029 static int should_move_die_to_comdat (dw_die_ref
);
3030 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3031 static dw_die_ref
clone_die (dw_die_ref
);
3032 static dw_die_ref
clone_tree (dw_die_ref
);
3033 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3034 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3035 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3036 static dw_die_ref
generate_skeleton (dw_die_ref
);
3037 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3040 static void break_out_comdat_types (dw_die_ref
);
3041 static void copy_decls_for_unworthy_types (dw_die_ref
);
3043 static void add_sibling_attributes (dw_die_ref
);
3044 static void output_location_lists (dw_die_ref
);
3045 static int constant_size (unsigned HOST_WIDE_INT
);
3046 static unsigned long size_of_die (dw_die_ref
);
3047 static void calc_die_sizes (dw_die_ref
);
3048 static void calc_base_type_die_sizes (void);
3049 static void mark_dies (dw_die_ref
);
3050 static void unmark_dies (dw_die_ref
);
3051 static void unmark_all_dies (dw_die_ref
);
3052 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3053 static unsigned long size_of_aranges (void);
3054 static enum dwarf_form
value_format (dw_attr_ref
);
3055 static void output_value_format (dw_attr_ref
);
3056 static void output_abbrev_section (void);
3057 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3058 static void output_die_symbol (dw_die_ref
);
3059 static void output_die (dw_die_ref
);
3060 static void output_compilation_unit_header (void);
3061 static void output_comp_unit (dw_die_ref
, int);
3062 static void output_comdat_type_unit (comdat_type_node
*);
3063 static const char *dwarf2_name (tree
, int);
3064 static void add_pubname (tree
, dw_die_ref
);
3065 static void add_enumerator_pubname (const char *, dw_die_ref
);
3066 static void add_pubname_string (const char *, dw_die_ref
);
3067 static void add_pubtype (tree
, dw_die_ref
);
3068 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3069 static void output_aranges (unsigned long);
3070 static unsigned int add_ranges_num (int);
3071 static unsigned int add_ranges (const_tree
);
3072 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3074 static void output_ranges (void);
3075 static dw_line_info_table
*new_line_info_table (void);
3076 static void output_line_info (bool);
3077 static void output_file_names (void);
3078 static dw_die_ref
base_type_die (tree
);
3079 static int is_base_type (tree
);
3080 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3081 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3082 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3083 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3084 static int type_is_enum (const_tree
);
3085 static unsigned int dbx_reg_number (const_rtx
);
3086 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3087 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3088 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3089 enum var_init_status
);
3090 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3091 enum var_init_status
);
3092 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3093 enum var_init_status
);
3094 static int is_based_loc (const_rtx
);
3095 static int resolve_one_addr (rtx
*, void *);
3096 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3097 enum var_init_status
);
3098 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3099 enum var_init_status
);
3100 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3101 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3102 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3103 static tree
field_type (const_tree
);
3104 static unsigned int simple_type_align_in_bits (const_tree
);
3105 static unsigned int simple_decl_align_in_bits (const_tree
);
3106 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3107 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3108 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3110 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3111 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3112 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3113 static void insert_double (double_int
, unsigned char *);
3114 static void insert_float (const_rtx
, unsigned char *);
3115 static rtx
rtl_for_decl_location (tree
);
3116 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3117 enum dwarf_attribute
);
3118 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3119 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3120 static void add_name_attribute (dw_die_ref
, const char *);
3121 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3122 static void add_comp_dir_attribute (dw_die_ref
);
3123 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3124 static void add_subscript_info (dw_die_ref
, tree
, bool);
3125 static void add_byte_size_attribute (dw_die_ref
, tree
);
3126 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3127 static void add_bit_size_attribute (dw_die_ref
, tree
);
3128 static void add_prototyped_attribute (dw_die_ref
, tree
);
3129 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3130 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3131 static void add_src_coords_attributes (dw_die_ref
, tree
);
3132 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3133 static void push_decl_scope (tree
);
3134 static void pop_decl_scope (void);
3135 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3136 static inline int local_scope_p (dw_die_ref
);
3137 static inline int class_scope_p (dw_die_ref
);
3138 static inline int class_or_namespace_scope_p (dw_die_ref
);
3139 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3140 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3141 static const char *type_tag (const_tree
);
3142 static tree
member_declared_type (const_tree
);
3144 static const char *decl_start_label (tree
);
3146 static void gen_array_type_die (tree
, dw_die_ref
);
3147 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3149 static void gen_entry_point_die (tree
, dw_die_ref
);
3151 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3152 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3153 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3154 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3155 static void gen_formal_types_die (tree
, dw_die_ref
);
3156 static void gen_subprogram_die (tree
, dw_die_ref
);
3157 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3158 static void gen_const_die (tree
, dw_die_ref
);
3159 static void gen_label_die (tree
, dw_die_ref
);
3160 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3161 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3162 static void gen_field_die (tree
, dw_die_ref
);
3163 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3164 static dw_die_ref
gen_compile_unit_die (const char *);
3165 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3166 static void gen_member_die (tree
, dw_die_ref
);
3167 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3168 enum debug_info_usage
);
3169 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3170 static void gen_typedef_die (tree
, dw_die_ref
);
3171 static void gen_type_die (tree
, dw_die_ref
);
3172 static void gen_block_die (tree
, dw_die_ref
, int);
3173 static void decls_for_scope (tree
, dw_die_ref
, int);
3174 static inline int is_redundant_typedef (const_tree
);
3175 static bool is_naming_typedef_decl (const_tree
);
3176 static inline dw_die_ref
get_context_die (tree
);
3177 static void gen_namespace_die (tree
, dw_die_ref
);
3178 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3179 static dw_die_ref
force_decl_die (tree
);
3180 static dw_die_ref
force_type_die (tree
);
3181 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3182 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3183 static struct dwarf_file_data
* lookup_filename (const char *);
3184 static void retry_incomplete_types (void);
3185 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3186 static void gen_generic_params_dies (tree
);
3187 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3188 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3189 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3190 static int file_info_cmp (const void *, const void *);
3191 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3192 const char *, const char *);
3193 static void output_loc_list (dw_loc_list_ref
);
3194 static char *gen_internal_sym (const char *);
3195 static bool want_pubnames (void);
3197 static void prune_unmark_dies (dw_die_ref
);
3198 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3199 static void prune_unused_types_mark (dw_die_ref
, int);
3200 static void prune_unused_types_walk (dw_die_ref
);
3201 static void prune_unused_types_walk_attribs (dw_die_ref
);
3202 static void prune_unused_types_prune (dw_die_ref
);
3203 static void prune_unused_types (void);
3204 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3205 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3206 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3207 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3208 const char *, const char *);
3209 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3210 static void gen_remaining_tmpl_value_param_die_attribute (void);
3211 static bool generic_type_p (tree
);
3212 static void schedule_generic_params_dies_gen (tree t
);
3213 static void gen_scheduled_generic_parms_dies (void);
3215 static const char *comp_dir_string (void);
3217 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3219 /* enum for tracking thread-local variables whose address is really an offset
3220 relative to the TLS pointer, which will need link-time relocation, but will
3221 not need relocation by the DWARF consumer. */
3229 /* Return the operator to use for an address of a variable. For dtprel_true, we
3230 use DW_OP_const*. For regular variables, which need both link-time
3231 relocation and consumer-level relocation (e.g., to account for shared objects
3232 loaded at a random address), we use DW_OP_addr*. */
3234 static inline enum dwarf_location_atom
3235 dw_addr_op (enum dtprel_bool dtprel
)
3237 if (dtprel
== dtprel_true
)
3238 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3239 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3241 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3244 /* Return a pointer to a newly allocated address location description. If
3245 dwarf_split_debug_info is true, then record the address with the appropriate
3247 static inline dw_loc_descr_ref
3248 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3250 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3252 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3253 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3254 ref
->dtprel
= dtprel
;
3255 if (dwarf_split_debug_info
)
3256 ref
->dw_loc_oprnd1
.val_entry
3257 = add_addr_table_entry (addr
,
3258 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3260 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3265 /* Section names used to hold DWARF debugging information. */
3267 #ifndef DEBUG_INFO_SECTION
3268 #define DEBUG_INFO_SECTION ".debug_info"
3270 #ifndef DEBUG_DWO_INFO_SECTION
3271 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3273 #ifndef DEBUG_ABBREV_SECTION
3274 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3276 #ifndef DEBUG_DWO_ABBREV_SECTION
3277 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3279 #ifndef DEBUG_ARANGES_SECTION
3280 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3282 #ifndef DEBUG_ADDR_SECTION
3283 #define DEBUG_ADDR_SECTION ".debug_addr"
3285 #ifndef DEBUG_NORM_MACINFO_SECTION
3286 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3288 #ifndef DEBUG_DWO_MACINFO_SECTION
3289 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3291 #ifndef DEBUG_MACINFO_SECTION
3292 #define DEBUG_MACINFO_SECTION \
3293 (!dwarf_split_debug_info \
3294 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3296 #ifndef DEBUG_NORM_MACRO_SECTION
3297 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3299 #ifndef DEBUG_DWO_MACRO_SECTION
3300 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3302 #ifndef DEBUG_MACRO_SECTION
3303 #define DEBUG_MACRO_SECTION \
3304 (!dwarf_split_debug_info \
3305 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3307 #ifndef DEBUG_LINE_SECTION
3308 #define DEBUG_LINE_SECTION ".debug_line"
3310 #ifndef DEBUG_DWO_LINE_SECTION
3311 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3313 #ifndef DEBUG_LOC_SECTION
3314 #define DEBUG_LOC_SECTION ".debug_loc"
3316 #ifndef DEBUG_DWO_LOC_SECTION
3317 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3319 #ifndef DEBUG_PUBNAMES_SECTION
3320 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3322 #ifndef DEBUG_PUBTYPES_SECTION
3323 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3325 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3326 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3327 #ifndef DEBUG_STR_OFFSETS_SECTION
3328 #define DEBUG_STR_OFFSETS_SECTION \
3329 (!dwarf_split_debug_info \
3330 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3332 #ifndef DEBUG_STR_DWO_SECTION
3333 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3335 #ifndef DEBUG_STR_SECTION
3336 #define DEBUG_STR_SECTION ".debug_str"
3338 #ifndef DEBUG_RANGES_SECTION
3339 #define DEBUG_RANGES_SECTION ".debug_ranges"
3342 /* Standard ELF section names for compiled code and data. */
3343 #ifndef TEXT_SECTION_NAME
3344 #define TEXT_SECTION_NAME ".text"
3347 /* Section flags for .debug_macinfo/.debug_macro section. */
3348 #define DEBUG_MACRO_SECTION_FLAGS \
3349 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3351 /* Section flags for .debug_str section. */
3352 #define DEBUG_STR_SECTION_FLAGS \
3353 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3354 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3357 /* Section flags for .debug_str.dwo section. */
3358 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3360 /* Labels we insert at beginning sections we can reference instead of
3361 the section names themselves. */
3363 #ifndef TEXT_SECTION_LABEL
3364 #define TEXT_SECTION_LABEL "Ltext"
3366 #ifndef COLD_TEXT_SECTION_LABEL
3367 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3369 #ifndef DEBUG_LINE_SECTION_LABEL
3370 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3372 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3373 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3375 #ifndef DEBUG_INFO_SECTION_LABEL
3376 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3378 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3379 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3381 #ifndef DEBUG_ABBREV_SECTION_LABEL
3382 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3384 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3385 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3387 #ifndef DEBUG_ADDR_SECTION_LABEL
3388 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3390 #ifndef DEBUG_LOC_SECTION_LABEL
3391 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3393 #ifndef DEBUG_RANGES_SECTION_LABEL
3394 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3396 #ifndef DEBUG_MACINFO_SECTION_LABEL
3397 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3399 #ifndef DEBUG_MACRO_SECTION_LABEL
3400 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3402 #define SKELETON_COMP_DIE_ABBREV 1
3403 #define SKELETON_TYPE_DIE_ABBREV 2
3405 /* Definitions of defaults for formats and names of various special
3406 (artificial) labels which may be generated within this file (when the -g
3407 options is used and DWARF2_DEBUGGING_INFO is in effect.
3408 If necessary, these may be overridden from within the tm.h file, but
3409 typically, overriding these defaults is unnecessary. */
3411 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3412 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3413 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3414 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3415 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3416 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3417 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3418 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3419 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3420 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3421 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3422 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3423 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3424 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3426 #ifndef TEXT_END_LABEL
3427 #define TEXT_END_LABEL "Letext"
3429 #ifndef COLD_END_LABEL
3430 #define COLD_END_LABEL "Letext_cold"
3432 #ifndef BLOCK_BEGIN_LABEL
3433 #define BLOCK_BEGIN_LABEL "LBB"
3435 #ifndef BLOCK_END_LABEL
3436 #define BLOCK_END_LABEL "LBE"
3438 #ifndef LINE_CODE_LABEL
3439 #define LINE_CODE_LABEL "LM"
3443 /* Return the root of the DIE's built for the current compilation unit. */
3445 comp_unit_die (void)
3447 if (!single_comp_unit_die
)
3448 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3449 return single_comp_unit_die
;
3452 /* We allow a language front-end to designate a function that is to be
3453 called to "demangle" any name before it is put into a DIE. */
3455 static const char *(*demangle_name_func
) (const char *);
3458 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3460 demangle_name_func
= func
;
3463 /* Test if rtl node points to a pseudo register. */
3466 is_pseudo_reg (const_rtx rtl
)
3468 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3469 || (GET_CODE (rtl
) == SUBREG
3470 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3473 /* Return a reference to a type, with its const and volatile qualifiers
3477 type_main_variant (tree type
)
3479 type
= TYPE_MAIN_VARIANT (type
);
3481 /* ??? There really should be only one main variant among any group of
3482 variants of a given type (and all of the MAIN_VARIANT values for all
3483 members of the group should point to that one type) but sometimes the C
3484 front-end messes this up for array types, so we work around that bug
3486 if (TREE_CODE (type
) == ARRAY_TYPE
)
3487 while (type
!= TYPE_MAIN_VARIANT (type
))
3488 type
= TYPE_MAIN_VARIANT (type
);
3493 /* Return nonzero if the given type node represents a tagged type. */
3496 is_tagged_type (const_tree type
)
3498 enum tree_code code
= TREE_CODE (type
);
3500 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3501 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3504 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3507 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3509 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3512 /* Return die_offset of a DIE reference to a base type. */
3514 static unsigned long int
3515 get_base_type_offset (dw_die_ref ref
)
3517 if (ref
->die_offset
)
3518 return ref
->die_offset
;
3519 if (comp_unit_die ()->die_abbrev
)
3521 calc_base_type_die_sizes ();
3522 gcc_assert (ref
->die_offset
);
3524 return ref
->die_offset
;
3527 /* Return die_offset of a DIE reference other than base type. */
3529 static unsigned long int
3530 get_ref_die_offset (dw_die_ref ref
)
3532 gcc_assert (ref
->die_offset
);
3533 return ref
->die_offset
;
3536 /* Convert a DIE tag into its string name. */
3539 dwarf_tag_name (unsigned int tag
)
3541 const char *name
= get_DW_TAG_name (tag
);
3546 return "DW_TAG_<unknown>";
3549 /* Convert a DWARF attribute code into its string name. */
3552 dwarf_attr_name (unsigned int attr
)
3558 #if VMS_DEBUGGING_INFO
3559 case DW_AT_HP_prologue
:
3560 return "DW_AT_HP_prologue";
3562 case DW_AT_MIPS_loop_unroll_factor
:
3563 return "DW_AT_MIPS_loop_unroll_factor";
3566 #if VMS_DEBUGGING_INFO
3567 case DW_AT_HP_epilogue
:
3568 return "DW_AT_HP_epilogue";
3570 case DW_AT_MIPS_stride
:
3571 return "DW_AT_MIPS_stride";
3575 name
= get_DW_AT_name (attr
);
3580 return "DW_AT_<unknown>";
3583 /* Convert a DWARF value form code into its string name. */
3586 dwarf_form_name (unsigned int form
)
3588 const char *name
= get_DW_FORM_name (form
);
3593 return "DW_FORM_<unknown>";
3596 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3597 instance of an inlined instance of a decl which is local to an inline
3598 function, so we have to trace all of the way back through the origin chain
3599 to find out what sort of node actually served as the original seed for the
3603 decl_ultimate_origin (const_tree decl
)
3605 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3608 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3609 nodes in the function to point to themselves; ignore that if
3610 we're trying to output the abstract instance of this function. */
3611 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3614 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3615 most distant ancestor, this should never happen. */
3616 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3618 return DECL_ABSTRACT_ORIGIN (decl
);
3621 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3622 of a virtual function may refer to a base class, so we check the 'this'
3626 decl_class_context (tree decl
)
3628 tree context
= NULL_TREE
;
3630 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3631 context
= DECL_CONTEXT (decl
);
3633 context
= TYPE_MAIN_VARIANT
3634 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3636 if (context
&& !TYPE_P (context
))
3637 context
= NULL_TREE
;
3642 /* Add an attribute/value pair to a DIE. */
3645 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3647 /* Maybe this should be an assert? */
3651 vec_safe_reserve (die
->die_attr
, 1);
3652 vec_safe_push (die
->die_attr
, *attr
);
3655 static inline enum dw_val_class
3656 AT_class (dw_attr_ref a
)
3658 return a
->dw_attr_val
.val_class
;
3661 /* Return the index for any attribute that will be referenced with a
3662 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3663 are stored in dw_attr_val.v.val_str for reference counting
3666 static inline unsigned int
3667 AT_index (dw_attr_ref a
)
3669 if (AT_class (a
) == dw_val_class_str
)
3670 return a
->dw_attr_val
.v
.val_str
->index
;
3671 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3672 return a
->dw_attr_val
.val_entry
->index
;
3676 /* Add a flag value attribute to a DIE. */
3679 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3683 attr
.dw_attr
= attr_kind
;
3684 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3685 attr
.dw_attr_val
.val_entry
= NULL
;
3686 attr
.dw_attr_val
.v
.val_flag
= flag
;
3687 add_dwarf_attr (die
, &attr
);
3690 static inline unsigned
3691 AT_flag (dw_attr_ref a
)
3693 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3694 return a
->dw_attr_val
.v
.val_flag
;
3697 /* Add a signed integer attribute value to a DIE. */
3700 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3704 attr
.dw_attr
= attr_kind
;
3705 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3706 attr
.dw_attr_val
.val_entry
= NULL
;
3707 attr
.dw_attr_val
.v
.val_int
= int_val
;
3708 add_dwarf_attr (die
, &attr
);
3711 static inline HOST_WIDE_INT
3712 AT_int (dw_attr_ref a
)
3714 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3715 return a
->dw_attr_val
.v
.val_int
;
3718 /* Add an unsigned integer attribute value to a DIE. */
3721 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3722 unsigned HOST_WIDE_INT unsigned_val
)
3726 attr
.dw_attr
= attr_kind
;
3727 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3728 attr
.dw_attr_val
.val_entry
= NULL
;
3729 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3730 add_dwarf_attr (die
, &attr
);
3733 static inline unsigned HOST_WIDE_INT
3734 AT_unsigned (dw_attr_ref a
)
3736 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3737 return a
->dw_attr_val
.v
.val_unsigned
;
3740 /* Add an unsigned double integer attribute value to a DIE. */
3743 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3744 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3748 attr
.dw_attr
= attr_kind
;
3749 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3750 attr
.dw_attr_val
.val_entry
= NULL
;
3751 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3752 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3753 add_dwarf_attr (die
, &attr
);
3756 /* Add a floating point attribute value to a DIE and return it. */
3759 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3760 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3764 attr
.dw_attr
= attr_kind
;
3765 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3766 attr
.dw_attr_val
.val_entry
= NULL
;
3767 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3768 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3769 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3770 add_dwarf_attr (die
, &attr
);
3773 /* Add an 8-byte data attribute value to a DIE. */
3776 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3777 unsigned char data8
[8])
3781 attr
.dw_attr
= attr_kind
;
3782 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3783 attr
.dw_attr_val
.val_entry
= NULL
;
3784 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3785 add_dwarf_attr (die
, &attr
);
3788 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3789 dwarf_split_debug_info, address attributes in dies destined for the
3790 final executable have force_direct set to avoid using indexed
3794 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3800 lbl_id
= xstrdup (lbl_low
);
3801 attr
.dw_attr
= DW_AT_low_pc
;
3802 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3803 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3804 if (dwarf_split_debug_info
&& !force_direct
)
3805 attr
.dw_attr_val
.val_entry
3806 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3808 attr
.dw_attr_val
.val_entry
= NULL
;
3809 add_dwarf_attr (die
, &attr
);
3811 attr
.dw_attr
= DW_AT_high_pc
;
3812 if (dwarf_version
< 4)
3813 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3815 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3816 lbl_id
= xstrdup (lbl_high
);
3817 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3818 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3819 && dwarf_split_debug_info
&& !force_direct
)
3820 attr
.dw_attr_val
.val_entry
3821 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3823 attr
.dw_attr_val
.val_entry
= NULL
;
3824 add_dwarf_attr (die
, &attr
);
3827 /* Hash and equality functions for debug_str_hash. */
3830 debug_str_do_hash (const void *x
)
3832 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3836 debug_str_eq (const void *x1
, const void *x2
)
3838 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3839 (const char *)x2
) == 0;
3842 /* Add STR to the given string hash table. */
3844 static struct indirect_string_node
*
3845 find_AT_string_in_table (const char *str
, htab_t table
)
3847 struct indirect_string_node
*node
;
3850 slot
= htab_find_slot_with_hash (table
, str
,
3851 htab_hash_string (str
), INSERT
);
3854 node
= ggc_alloc_cleared_indirect_string_node ();
3855 node
->str
= ggc_strdup (str
);
3859 node
= (struct indirect_string_node
*) *slot
;
3865 /* Add STR to the indirect string hash table. */
3867 static struct indirect_string_node
*
3868 find_AT_string (const char *str
)
3870 if (! debug_str_hash
)
3871 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3872 debug_str_eq
, NULL
);
3874 return find_AT_string_in_table (str
, debug_str_hash
);
3877 /* Add a string attribute value to a DIE. */
3880 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3883 struct indirect_string_node
*node
;
3885 node
= find_AT_string (str
);
3887 attr
.dw_attr
= attr_kind
;
3888 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3889 attr
.dw_attr_val
.val_entry
= NULL
;
3890 attr
.dw_attr_val
.v
.val_str
= node
;
3891 add_dwarf_attr (die
, &attr
);
3894 static inline const char *
3895 AT_string (dw_attr_ref a
)
3897 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3898 return a
->dw_attr_val
.v
.val_str
->str
;
3901 /* Call this function directly to bypass AT_string_form's logic to put
3902 the string inline in the die. */
3905 set_indirect_string (struct indirect_string_node
*node
)
3908 /* Already indirect is a no op. */
3909 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3911 gcc_assert (node
->label
);
3914 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3915 ++dw2_string_counter
;
3916 node
->label
= xstrdup (label
);
3918 if (!dwarf_split_debug_info
)
3920 node
->form
= DW_FORM_strp
;
3921 node
->index
= NOT_INDEXED
;
3925 node
->form
= DW_FORM_GNU_str_index
;
3926 node
->index
= NO_INDEX_ASSIGNED
;
3930 /* Find out whether a string should be output inline in DIE
3931 or out-of-line in .debug_str section. */
3933 static enum dwarf_form
3934 find_string_form (struct indirect_string_node
*node
)
3941 len
= strlen (node
->str
) + 1;
3943 /* If the string is shorter or equal to the size of the reference, it is
3944 always better to put it inline. */
3945 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3946 return node
->form
= DW_FORM_string
;
3948 /* If we cannot expect the linker to merge strings in .debug_str
3949 section, only put it into .debug_str if it is worth even in this
3951 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3952 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3953 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3954 return node
->form
= DW_FORM_string
;
3956 set_indirect_string (node
);
3961 /* Find out whether the string referenced from the attribute should be
3962 output inline in DIE or out-of-line in .debug_str section. */
3964 static enum dwarf_form
3965 AT_string_form (dw_attr_ref a
)
3967 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3968 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3971 /* Add a DIE reference attribute value to a DIE. */
3974 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3978 #ifdef ENABLE_CHECKING
3979 gcc_assert (targ_die
!= NULL
);
3981 /* With LTO we can end up trying to reference something we didn't create
3982 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3983 if (targ_die
== NULL
)
3987 attr
.dw_attr
= attr_kind
;
3988 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3989 attr
.dw_attr_val
.val_entry
= NULL
;
3990 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3991 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3992 add_dwarf_attr (die
, &attr
);
3995 /* Change DIE reference REF to point to NEW_DIE instead. */
3998 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4000 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4001 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4002 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4005 /* Add an AT_specification attribute to a DIE, and also make the back
4006 pointer from the specification to the definition. */
4009 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4011 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4012 gcc_assert (!targ_die
->die_definition
);
4013 targ_die
->die_definition
= die
;
4016 static inline dw_die_ref
4017 AT_ref (dw_attr_ref a
)
4019 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4020 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4024 AT_ref_external (dw_attr_ref a
)
4026 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4027 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4033 set_AT_ref_external (dw_attr_ref a
, int i
)
4035 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4036 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4039 /* Add an FDE reference attribute value to a DIE. */
4042 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4046 attr
.dw_attr
= attr_kind
;
4047 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4048 attr
.dw_attr_val
.val_entry
= NULL
;
4049 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4050 add_dwarf_attr (die
, &attr
);
4053 /* Add a location description attribute value to a DIE. */
4056 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4060 attr
.dw_attr
= attr_kind
;
4061 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4062 attr
.dw_attr_val
.val_entry
= NULL
;
4063 attr
.dw_attr_val
.v
.val_loc
= loc
;
4064 add_dwarf_attr (die
, &attr
);
4067 static inline dw_loc_descr_ref
4068 AT_loc (dw_attr_ref a
)
4070 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4071 return a
->dw_attr_val
.v
.val_loc
;
4075 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4079 attr
.dw_attr
= attr_kind
;
4080 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4081 attr
.dw_attr_val
.val_entry
= NULL
;
4082 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4083 add_dwarf_attr (die
, &attr
);
4084 have_location_lists
= true;
4087 static inline dw_loc_list_ref
4088 AT_loc_list (dw_attr_ref a
)
4090 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4091 return a
->dw_attr_val
.v
.val_loc_list
;
4094 static inline dw_loc_list_ref
*
4095 AT_loc_list_ptr (dw_attr_ref a
)
4097 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4098 return &a
->dw_attr_val
.v
.val_loc_list
;
4101 /* Table of entries into the .debug_addr section. */
4103 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4105 /* Hash an address_table_entry. */
4108 addr_table_entry_do_hash (const void *x
)
4110 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4114 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4115 case ate_kind_rtx_dtprel
:
4116 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4117 case ate_kind_label
:
4118 return htab_hash_string (a
->addr
.label
);
4124 /* Determine equality for two address_table_entries. */
4127 addr_table_entry_eq (const void *x1
, const void *x2
)
4129 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4130 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4132 if (a1
->kind
!= a2
->kind
)
4137 case ate_kind_rtx_dtprel
:
4138 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4139 case ate_kind_label
:
4140 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4146 /* Initialize an addr_table_entry. */
4149 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4155 case ate_kind_rtx_dtprel
:
4156 e
->addr
.rtl
= (rtx
) addr
;
4158 case ate_kind_label
:
4159 e
->addr
.label
= (char *) addr
;
4163 e
->index
= NO_INDEX_ASSIGNED
;
4166 /* Add attr to the address table entry to the table. Defer setting an
4167 index until output time. */
4169 static addr_table_entry
*
4170 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4172 addr_table_entry
*node
;
4173 addr_table_entry finder
;
4176 gcc_assert (dwarf_split_debug_info
);
4177 if (! addr_index_table
)
4178 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4179 addr_table_entry_eq
, NULL
);
4180 init_addr_table_entry (&finder
, kind
, addr
);
4181 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4183 if (*slot
== HTAB_EMPTY_ENTRY
)
4185 node
= ggc_alloc_cleared_addr_table_entry ();
4186 init_addr_table_entry (node
, kind
, addr
);
4190 node
= (addr_table_entry
*) *slot
;
4196 /* Remove an entry from the addr table by decrementing its refcount.
4197 Strictly, decrementing the refcount would be enough, but the
4198 assertion that the entry is actually in the table has found
4202 remove_addr_table_entry (addr_table_entry
*entry
)
4204 addr_table_entry
*node
;
4206 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4207 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4208 /* After an index is assigned, the table is frozen. */
4209 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4213 /* Given a location list, remove all addresses it refers to from the
4217 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4219 for (; descr
; descr
= descr
->dw_loc_next
)
4220 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4222 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4223 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4227 /* A helper function for dwarf2out_finish called through
4228 htab_traverse. Assign an addr_table_entry its index. All entries
4229 must be collected into the table when this function is called,
4230 because the indexing code relies on htab_traverse to traverse nodes
4231 in the same order for each run. */
4234 index_addr_table_entry (void **h
, void *v
)
4236 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4237 unsigned int *index
= (unsigned int *) v
;
4239 /* Don't index unreferenced nodes. */
4240 if (node
->refcount
== 0)
4243 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4244 node
->index
= *index
;
4250 /* Add an address constant attribute value to a DIE. When using
4251 dwarf_split_debug_info, address attributes in dies destined for the
4252 final executable should be direct references--setting the parameter
4253 force_direct ensures this behavior. */
4256 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4261 attr
.dw_attr
= attr_kind
;
4262 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4263 attr
.dw_attr_val
.v
.val_addr
= addr
;
4264 if (dwarf_split_debug_info
&& !force_direct
)
4265 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4267 attr
.dw_attr_val
.val_entry
= NULL
;
4268 add_dwarf_attr (die
, &attr
);
4271 /* Get the RTX from to an address DIE attribute. */
4274 AT_addr (dw_attr_ref a
)
4276 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4277 return a
->dw_attr_val
.v
.val_addr
;
4280 /* Add a file attribute value to a DIE. */
4283 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4284 struct dwarf_file_data
*fd
)
4288 attr
.dw_attr
= attr_kind
;
4289 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4290 attr
.dw_attr_val
.val_entry
= NULL
;
4291 attr
.dw_attr_val
.v
.val_file
= fd
;
4292 add_dwarf_attr (die
, &attr
);
4295 /* Get the dwarf_file_data from a file DIE attribute. */
4297 static inline struct dwarf_file_data
*
4298 AT_file (dw_attr_ref a
)
4300 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4301 return a
->dw_attr_val
.v
.val_file
;
4304 /* Add a vms delta attribute value to a DIE. */
4307 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4308 const char *lbl1
, const char *lbl2
)
4312 attr
.dw_attr
= attr_kind
;
4313 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4314 attr
.dw_attr_val
.val_entry
= NULL
;
4315 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4316 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4317 add_dwarf_attr (die
, &attr
);
4320 /* Add a label identifier attribute value to a DIE. */
4323 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4328 attr
.dw_attr
= attr_kind
;
4329 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4330 attr
.dw_attr_val
.val_entry
= NULL
;
4331 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4332 if (dwarf_split_debug_info
)
4333 attr
.dw_attr_val
.val_entry
4334 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4336 add_dwarf_attr (die
, &attr
);
4339 /* Add a section offset attribute value to a DIE, an offset into the
4340 debug_line section. */
4343 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4348 attr
.dw_attr
= attr_kind
;
4349 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4350 attr
.dw_attr_val
.val_entry
= NULL
;
4351 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4352 add_dwarf_attr (die
, &attr
);
4355 /* Add a section offset attribute value to a DIE, an offset into the
4356 debug_macinfo section. */
4359 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4364 attr
.dw_attr
= attr_kind
;
4365 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4366 attr
.dw_attr_val
.val_entry
= NULL
;
4367 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4368 add_dwarf_attr (die
, &attr
);
4371 /* Add an offset attribute value to a DIE. */
4374 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4375 unsigned HOST_WIDE_INT offset
)
4379 attr
.dw_attr
= attr_kind
;
4380 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4381 attr
.dw_attr_val
.val_entry
= NULL
;
4382 attr
.dw_attr_val
.v
.val_offset
= offset
;
4383 add_dwarf_attr (die
, &attr
);
4386 /* Add a range_list attribute value to a DIE. When using
4387 dwarf_split_debug_info, address attributes in dies destined for the
4388 final executable should be direct references--setting the parameter
4389 force_direct ensures this behavior. */
4391 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4392 #define RELOCATED_OFFSET (NULL)
4395 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4396 long unsigned int offset
, bool force_direct
)
4400 attr
.dw_attr
= attr_kind
;
4401 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4402 /* For the range_list attribute, use val_entry to store whether the
4403 offset should follow split-debug-info or normal semantics. This
4404 value is read in output_range_list_offset. */
4405 if (dwarf_split_debug_info
&& !force_direct
)
4406 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4408 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4409 attr
.dw_attr_val
.v
.val_offset
= offset
;
4410 add_dwarf_attr (die
, &attr
);
4413 /* Return the start label of a delta attribute. */
4415 static inline const char *
4416 AT_vms_delta1 (dw_attr_ref a
)
4418 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4419 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4422 /* Return the end label of a delta attribute. */
4424 static inline const char *
4425 AT_vms_delta2 (dw_attr_ref a
)
4427 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4428 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4431 static inline const char *
4432 AT_lbl (dw_attr_ref a
)
4434 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4435 || AT_class (a
) == dw_val_class_lineptr
4436 || AT_class (a
) == dw_val_class_macptr
4437 || AT_class (a
) == dw_val_class_high_pc
));
4438 return a
->dw_attr_val
.v
.val_lbl_id
;
4441 /* Get the attribute of type attr_kind. */
4444 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4448 dw_die_ref spec
= NULL
;
4453 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4454 if (a
->dw_attr
== attr_kind
)
4456 else if (a
->dw_attr
== DW_AT_specification
4457 || a
->dw_attr
== DW_AT_abstract_origin
)
4461 return get_AT (spec
, attr_kind
);
4466 /* Returns the parent of the declaration of DIE. */
4469 get_die_parent (dw_die_ref die
)
4476 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4477 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4480 return die
->die_parent
;
4483 /* Return the "low pc" attribute value, typically associated with a subprogram
4484 DIE. Return null if the "low pc" attribute is either not present, or if it
4485 cannot be represented as an assembler label identifier. */
4487 static inline const char *
4488 get_AT_low_pc (dw_die_ref die
)
4490 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4492 return a
? AT_lbl (a
) : NULL
;
4495 /* Return the "high pc" attribute value, typically associated with a subprogram
4496 DIE. Return null if the "high pc" attribute is either not present, or if it
4497 cannot be represented as an assembler label identifier. */
4499 static inline const char *
4500 get_AT_hi_pc (dw_die_ref die
)
4502 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4504 return a
? AT_lbl (a
) : NULL
;
4507 /* Return the value of the string attribute designated by ATTR_KIND, or
4508 NULL if it is not present. */
4510 static inline const char *
4511 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4513 dw_attr_ref a
= get_AT (die
, attr_kind
);
4515 return a
? AT_string (a
) : NULL
;
4518 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4519 if it is not present. */
4522 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4524 dw_attr_ref a
= get_AT (die
, attr_kind
);
4526 return a
? AT_flag (a
) : 0;
4529 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4530 if it is not present. */
4532 static inline unsigned
4533 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4535 dw_attr_ref a
= get_AT (die
, attr_kind
);
4537 return a
? AT_unsigned (a
) : 0;
4540 static inline dw_die_ref
4541 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4543 dw_attr_ref a
= get_AT (die
, attr_kind
);
4545 return a
? AT_ref (a
) : NULL
;
4548 static inline struct dwarf_file_data
*
4549 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4551 dw_attr_ref a
= get_AT (die
, attr_kind
);
4553 return a
? AT_file (a
) : NULL
;
4556 /* Return TRUE if the language is C++. */
4561 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4563 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4566 /* Return TRUE if the language is Fortran. */
4571 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4573 return (lang
== DW_LANG_Fortran77
4574 || lang
== DW_LANG_Fortran90
4575 || lang
== DW_LANG_Fortran95
);
4578 /* Return TRUE if the language is Ada. */
4583 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4585 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4588 /* Remove the specified attribute if present. */
4591 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4599 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4600 if (a
->dw_attr
== attr_kind
)
4602 if (AT_class (a
) == dw_val_class_str
)
4603 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4604 a
->dw_attr_val
.v
.val_str
->refcount
--;
4606 /* vec::ordered_remove should help reduce the number of abbrevs
4608 die
->die_attr
->ordered_remove (ix
);
4613 /* Remove CHILD from its parent. PREV must have the property that
4614 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4617 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4619 gcc_assert (child
->die_parent
== prev
->die_parent
);
4620 gcc_assert (prev
->die_sib
== child
);
4623 gcc_assert (child
->die_parent
->die_child
== child
);
4627 prev
->die_sib
= child
->die_sib
;
4628 if (child
->die_parent
->die_child
== child
)
4629 child
->die_parent
->die_child
= prev
;
4632 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4633 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4636 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4638 dw_die_ref parent
= old_child
->die_parent
;
4640 gcc_assert (parent
== prev
->die_parent
);
4641 gcc_assert (prev
->die_sib
== old_child
);
4643 new_child
->die_parent
= parent
;
4644 if (prev
== old_child
)
4646 gcc_assert (parent
->die_child
== old_child
);
4647 new_child
->die_sib
= new_child
;
4651 prev
->die_sib
= new_child
;
4652 new_child
->die_sib
= old_child
->die_sib
;
4654 if (old_child
->die_parent
->die_child
== old_child
)
4655 old_child
->die_parent
->die_child
= new_child
;
4658 /* Move all children from OLD_PARENT to NEW_PARENT. */
4661 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4664 new_parent
->die_child
= old_parent
->die_child
;
4665 old_parent
->die_child
= NULL
;
4666 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4669 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4673 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4679 dw_die_ref prev
= c
;
4681 while (c
->die_tag
== tag
)
4683 remove_child_with_prev (c
, prev
);
4684 /* Might have removed every child. */
4685 if (c
== c
->die_sib
)
4689 } while (c
!= die
->die_child
);
4692 /* Add a CHILD_DIE as the last child of DIE. */
4695 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4697 /* FIXME this should probably be an assert. */
4698 if (! die
|| ! child_die
)
4700 gcc_assert (die
!= child_die
);
4702 child_die
->die_parent
= die
;
4705 child_die
->die_sib
= die
->die_child
->die_sib
;
4706 die
->die_child
->die_sib
= child_die
;
4709 child_die
->die_sib
= child_die
;
4710 die
->die_child
= child_die
;
4713 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4714 is the specification, to the end of PARENT's list of children.
4715 This is done by removing and re-adding it. */
4718 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4722 /* We want the declaration DIE from inside the class, not the
4723 specification DIE at toplevel. */
4724 if (child
->die_parent
!= parent
)
4726 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4732 gcc_assert (child
->die_parent
== parent
4733 || (child
->die_parent
4734 == get_AT_ref (parent
, DW_AT_specification
)));
4736 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4737 if (p
->die_sib
== child
)
4739 remove_child_with_prev (child
, p
);
4743 add_child_die (parent
, child
);
4746 /* Return a pointer to a newly created DIE node. */
4748 static inline dw_die_ref
4749 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4751 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4753 die
->die_tag
= tag_value
;
4755 if (parent_die
!= NULL
)
4756 add_child_die (parent_die
, die
);
4759 limbo_die_node
*limbo_node
;
4761 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4762 limbo_node
->die
= die
;
4763 limbo_node
->created_for
= t
;
4764 limbo_node
->next
= limbo_die_list
;
4765 limbo_die_list
= limbo_node
;
4771 /* Return the DIE associated with the given type specifier. */
4773 static inline dw_die_ref
4774 lookup_type_die (tree type
)
4776 return TYPE_SYMTAB_DIE (type
);
4779 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4780 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4781 anonymous type instead the one of the naming typedef. */
4783 static inline dw_die_ref
4784 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4787 && TREE_CODE (type
) == RECORD_TYPE
4789 && type_die
->die_tag
== DW_TAG_typedef
4790 && is_naming_typedef_decl (TYPE_NAME (type
)))
4791 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4795 /* Like lookup_type_die, but if type is an anonymous type named by a
4796 typedef[1], return the DIE of the anonymous type instead the one of
4797 the naming typedef. This is because in gen_typedef_die, we did
4798 equate the anonymous struct named by the typedef with the DIE of
4799 the naming typedef. So by default, lookup_type_die on an anonymous
4800 struct yields the DIE of the naming typedef.
4802 [1]: Read the comment of is_naming_typedef_decl to learn about what
4803 a naming typedef is. */
4805 static inline dw_die_ref
4806 lookup_type_die_strip_naming_typedef (tree type
)
4808 dw_die_ref die
= lookup_type_die (type
);
4809 return strip_naming_typedef (type
, die
);
4812 /* Equate a DIE to a given type specifier. */
4815 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4817 TYPE_SYMTAB_DIE (type
) = type_die
;
4820 /* Returns a hash value for X (which really is a die_struct). */
4823 decl_die_table_hash (const void *x
)
4825 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4828 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4831 decl_die_table_eq (const void *x
, const void *y
)
4833 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4836 /* Return the DIE associated with a given declaration. */
4838 static inline dw_die_ref
4839 lookup_decl_die (tree decl
)
4841 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4844 /* Returns a hash value for X (which really is a var_loc_list). */
4847 decl_loc_table_hash (const void *x
)
4849 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4852 /* Return nonzero if decl_id of var_loc_list X is the same as
4856 decl_loc_table_eq (const void *x
, const void *y
)
4858 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4861 /* Return the var_loc list associated with a given declaration. */
4863 static inline var_loc_list
*
4864 lookup_decl_loc (const_tree decl
)
4866 if (!decl_loc_table
)
4868 return (var_loc_list
*)
4869 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4872 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4875 cached_dw_loc_list_table_hash (const void *x
)
4877 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4880 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4884 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4886 return (((const cached_dw_loc_list
*) x
)->decl_id
4887 == DECL_UID ((const_tree
) y
));
4890 /* Equate a DIE to a particular declaration. */
4893 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4895 unsigned int decl_id
= DECL_UID (decl
);
4898 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4900 decl_die
->decl_id
= decl_id
;
4903 /* Return how many bits covers PIECE EXPR_LIST. */
4906 decl_piece_bitsize (rtx piece
)
4908 int ret
= (int) GET_MODE (piece
);
4911 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4912 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4913 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4916 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4919 decl_piece_varloc_ptr (rtx piece
)
4921 if ((int) GET_MODE (piece
))
4922 return &XEXP (piece
, 0);
4924 return &XEXP (XEXP (piece
, 0), 1);
4927 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4928 Next is the chain of following piece nodes. */
4931 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4933 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4934 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4936 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4941 /* Return rtx that should be stored into loc field for
4942 LOC_NOTE and BITPOS/BITSIZE. */
4945 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4946 HOST_WIDE_INT bitsize
)
4950 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4952 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4957 /* This function either modifies location piece list *DEST in
4958 place (if SRC and INNER is NULL), or copies location piece list
4959 *SRC to *DEST while modifying it. Location BITPOS is modified
4960 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4961 not copied and if needed some padding around it is added.
4962 When modifying in place, DEST should point to EXPR_LIST where
4963 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4964 to the start of the whole list and INNER points to the EXPR_LIST
4965 where earlier pieces cover PIECE_BITPOS bits. */
4968 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4969 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4970 HOST_WIDE_INT bitsize
, rtx loc_note
)
4973 bool copy
= inner
!= NULL
;
4977 /* First copy all nodes preceding the current bitpos. */
4978 while (src
!= inner
)
4980 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4981 decl_piece_bitsize (*src
), NULL_RTX
);
4982 dest
= &XEXP (*dest
, 1);
4983 src
= &XEXP (*src
, 1);
4986 /* Add padding if needed. */
4987 if (bitpos
!= piece_bitpos
)
4989 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4990 copy
? NULL_RTX
: *dest
);
4991 dest
= &XEXP (*dest
, 1);
4993 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4996 /* A piece with correct bitpos and bitsize already exist,
4997 just update the location for it and return. */
4998 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5001 /* Add the piece that changed. */
5002 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5003 dest
= &XEXP (*dest
, 1);
5004 /* Skip over pieces that overlap it. */
5005 diff
= bitpos
- piece_bitpos
+ bitsize
;
5008 while (diff
> 0 && *src
)
5011 diff
-= decl_piece_bitsize (piece
);
5013 src
= &XEXP (piece
, 1);
5016 *src
= XEXP (piece
, 1);
5017 free_EXPR_LIST_node (piece
);
5020 /* Add padding if needed. */
5021 if (diff
< 0 && *src
)
5025 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5026 dest
= &XEXP (*dest
, 1);
5030 /* Finally copy all nodes following it. */
5033 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5034 decl_piece_bitsize (*src
), NULL_RTX
);
5035 dest
= &XEXP (*dest
, 1);
5036 src
= &XEXP (*src
, 1);
5040 /* Add a variable location node to the linked list for DECL. */
5042 static struct var_loc_node
*
5043 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5045 unsigned int decl_id
;
5048 struct var_loc_node
*loc
= NULL
;
5049 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5051 if (TREE_CODE (decl
) == VAR_DECL
5052 && DECL_HAS_DEBUG_EXPR_P (decl
))
5054 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5055 if (handled_component_p (realdecl
)
5056 || (TREE_CODE (realdecl
) == MEM_REF
5057 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5059 HOST_WIDE_INT maxsize
;
5062 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5063 if (!DECL_P (innerdecl
)
5064 || DECL_IGNORED_P (innerdecl
)
5065 || TREE_STATIC (innerdecl
)
5067 || bitpos
+ bitsize
> 256
5068 || bitsize
!= maxsize
)
5074 decl_id
= DECL_UID (decl
);
5075 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5078 temp
= ggc_alloc_cleared_var_loc_list ();
5079 temp
->decl_id
= decl_id
;
5083 temp
= (var_loc_list
*) *slot
;
5085 /* For PARM_DECLs try to keep around the original incoming value,
5086 even if that means we'll emit a zero-range .debug_loc entry. */
5088 && temp
->first
== temp
->last
5089 && TREE_CODE (decl
) == PARM_DECL
5090 && NOTE_P (temp
->first
->loc
)
5091 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5092 && DECL_INCOMING_RTL (decl
)
5093 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5094 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5095 == GET_CODE (DECL_INCOMING_RTL (decl
))
5096 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5098 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5099 NOTE_VAR_LOCATION_LOC (loc_note
))
5100 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5101 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5103 loc
= ggc_alloc_cleared_var_loc_node ();
5104 temp
->first
->next
= loc
;
5106 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5108 else if (temp
->last
)
5110 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5111 rtx
*piece_loc
= NULL
, last_loc_note
;
5112 int piece_bitpos
= 0;
5116 gcc_assert (last
->next
== NULL
);
5118 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5120 piece_loc
= &last
->loc
;
5123 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5124 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5126 piece_bitpos
+= cur_bitsize
;
5127 piece_loc
= &XEXP (*piece_loc
, 1);
5131 /* TEMP->LAST here is either pointer to the last but one or
5132 last element in the chained list, LAST is pointer to the
5134 if (label
&& strcmp (last
->label
, label
) == 0)
5136 /* For SRA optimized variables if there weren't any real
5137 insns since last note, just modify the last node. */
5138 if (piece_loc
!= NULL
)
5140 adjust_piece_list (piece_loc
, NULL
, NULL
,
5141 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5144 /* If the last note doesn't cover any instructions, remove it. */
5145 if (temp
->last
!= last
)
5147 temp
->last
->next
= NULL
;
5150 gcc_assert (strcmp (last
->label
, label
) != 0);
5154 gcc_assert (temp
->first
== temp
->last
5155 || (temp
->first
->next
== temp
->last
5156 && TREE_CODE (decl
) == PARM_DECL
));
5157 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5158 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5162 if (bitsize
== -1 && NOTE_P (last
->loc
))
5163 last_loc_note
= last
->loc
;
5164 else if (piece_loc
!= NULL
5165 && *piece_loc
!= NULL_RTX
5166 && piece_bitpos
== bitpos
5167 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5168 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5170 last_loc_note
= NULL_RTX
;
5171 /* If the current location is the same as the end of the list,
5172 and either both or neither of the locations is uninitialized,
5173 we have nothing to do. */
5174 if (last_loc_note
== NULL_RTX
5175 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5176 NOTE_VAR_LOCATION_LOC (loc_note
)))
5177 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5178 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5179 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5180 == VAR_INIT_STATUS_UNINITIALIZED
)
5181 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5182 == VAR_INIT_STATUS_UNINITIALIZED
))))
5184 /* Add LOC to the end of list and update LAST. If the last
5185 element of the list has been removed above, reuse its
5186 memory for the new node, otherwise allocate a new one. */
5190 memset (loc
, '\0', sizeof (*loc
));
5193 loc
= ggc_alloc_cleared_var_loc_node ();
5194 if (bitsize
== -1 || piece_loc
== NULL
)
5195 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5197 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5198 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5200 /* Ensure TEMP->LAST will point either to the new last but one
5201 element of the chain, or to the last element in it. */
5202 if (last
!= temp
->last
)
5210 loc
= ggc_alloc_cleared_var_loc_node ();
5213 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5218 /* Keep track of the number of spaces used to indent the
5219 output of the debugging routines that print the structure of
5220 the DIE internal representation. */
5221 static int print_indent
;
5223 /* Indent the line the number of spaces given by print_indent. */
5226 print_spaces (FILE *outfile
)
5228 fprintf (outfile
, "%*s", print_indent
, "");
5231 /* Print a type signature in hex. */
5234 print_signature (FILE *outfile
, char *sig
)
5238 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5239 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5242 /* Print the information associated with a given DIE, and its children.
5243 This routine is a debugging aid only. */
5246 print_die (dw_die_ref die
, FILE *outfile
)
5252 print_spaces (outfile
);
5253 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5254 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5256 print_spaces (outfile
);
5257 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5258 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5259 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5261 if (die
->comdat_type_p
)
5263 print_spaces (outfile
);
5264 fprintf (outfile
, " signature: ");
5265 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5266 fprintf (outfile
, "\n");
5269 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5271 print_spaces (outfile
);
5272 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5274 switch (AT_class (a
))
5276 case dw_val_class_addr
:
5277 fprintf (outfile
, "address");
5279 case dw_val_class_offset
:
5280 fprintf (outfile
, "offset");
5282 case dw_val_class_loc
:
5283 fprintf (outfile
, "location descriptor");
5285 case dw_val_class_loc_list
:
5286 fprintf (outfile
, "location list -> label:%s",
5287 AT_loc_list (a
)->ll_symbol
);
5289 case dw_val_class_range_list
:
5290 fprintf (outfile
, "range list");
5292 case dw_val_class_const
:
5293 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5295 case dw_val_class_unsigned_const
:
5296 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5298 case dw_val_class_const_double
:
5299 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5300 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5301 a
->dw_attr_val
.v
.val_double
.high
,
5302 a
->dw_attr_val
.v
.val_double
.low
);
5304 case dw_val_class_vec
:
5305 fprintf (outfile
, "floating-point or vector constant");
5307 case dw_val_class_flag
:
5308 fprintf (outfile
, "%u", AT_flag (a
));
5310 case dw_val_class_die_ref
:
5311 if (AT_ref (a
) != NULL
)
5313 if (AT_ref (a
)->comdat_type_p
)
5315 fprintf (outfile
, "die -> signature: ");
5316 print_signature (outfile
,
5317 AT_ref (a
)->die_id
.die_type_node
->signature
);
5319 else if (AT_ref (a
)->die_id
.die_symbol
)
5320 fprintf (outfile
, "die -> label: %s",
5321 AT_ref (a
)->die_id
.die_symbol
);
5323 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5324 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5327 fprintf (outfile
, "die -> <null>");
5329 case dw_val_class_vms_delta
:
5330 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5331 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5333 case dw_val_class_lbl_id
:
5334 case dw_val_class_lineptr
:
5335 case dw_val_class_macptr
:
5336 case dw_val_class_high_pc
:
5337 fprintf (outfile
, "label: %s", AT_lbl (a
));
5339 case dw_val_class_str
:
5340 if (AT_string (a
) != NULL
)
5341 fprintf (outfile
, "\"%s\"", AT_string (a
));
5343 fprintf (outfile
, "<null>");
5345 case dw_val_class_file
:
5346 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5347 AT_file (a
)->emitted_number
);
5349 case dw_val_class_data8
:
5353 for (i
= 0; i
< 8; i
++)
5354 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5361 fprintf (outfile
, "\n");
5364 if (die
->die_child
!= NULL
)
5367 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5370 if (print_indent
== 0)
5371 fprintf (outfile
, "\n");
5374 /* Print the information collected for a given DIE. */
5377 debug_dwarf_die (dw_die_ref die
)
5379 print_die (die
, stderr
);
5383 debug (die_struct
&ref
)
5385 print_die (&ref
, stderr
);
5389 debug (die_struct
*ptr
)
5394 fprintf (stderr
, "<nil>\n");
5398 /* Print all DWARF information collected for the compilation unit.
5399 This routine is a debugging aid only. */
5405 print_die (comp_unit_die (), stderr
);
5408 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5409 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5410 DIE that marks the start of the DIEs for this include file. */
5413 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5415 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5416 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5418 new_unit
->die_sib
= old_unit
;
5422 /* Close an include-file CU and reopen the enclosing one. */
5425 pop_compile_unit (dw_die_ref old_unit
)
5427 dw_die_ref new_unit
= old_unit
->die_sib
;
5429 old_unit
->die_sib
= NULL
;
5433 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5434 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5436 /* Calculate the checksum of a location expression. */
5439 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5444 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5446 hash
= hash_loc_operands (loc
, hash
);
5450 /* Calculate the checksum of an attribute. */
5453 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5455 dw_loc_descr_ref loc
;
5458 CHECKSUM (at
->dw_attr
);
5460 /* We don't care that this was compiled with a different compiler
5461 snapshot; if the output is the same, that's what matters. */
5462 if (at
->dw_attr
== DW_AT_producer
)
5465 switch (AT_class (at
))
5467 case dw_val_class_const
:
5468 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5470 case dw_val_class_unsigned_const
:
5471 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5473 case dw_val_class_const_double
:
5474 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5476 case dw_val_class_vec
:
5477 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5479 case dw_val_class_flag
:
5480 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5482 case dw_val_class_str
:
5483 CHECKSUM_STRING (AT_string (at
));
5486 case dw_val_class_addr
:
5488 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5489 CHECKSUM_STRING (XSTR (r
, 0));
5492 case dw_val_class_offset
:
5493 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5496 case dw_val_class_loc
:
5497 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5498 loc_checksum (loc
, ctx
);
5501 case dw_val_class_die_ref
:
5502 die_checksum (AT_ref (at
), ctx
, mark
);
5505 case dw_val_class_fde_ref
:
5506 case dw_val_class_vms_delta
:
5507 case dw_val_class_lbl_id
:
5508 case dw_val_class_lineptr
:
5509 case dw_val_class_macptr
:
5510 case dw_val_class_high_pc
:
5513 case dw_val_class_file
:
5514 CHECKSUM_STRING (AT_file (at
)->filename
);
5517 case dw_val_class_data8
:
5518 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5526 /* Calculate the checksum of a DIE. */
5529 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5535 /* To avoid infinite recursion. */
5538 CHECKSUM (die
->die_mark
);
5541 die
->die_mark
= ++(*mark
);
5543 CHECKSUM (die
->die_tag
);
5545 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5546 attr_checksum (a
, ctx
, mark
);
5548 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5552 #undef CHECKSUM_STRING
5554 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5555 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5556 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5557 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5558 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5559 #define CHECKSUM_ATTR(FOO) \
5560 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5562 /* Calculate the checksum of a number in signed LEB128 format. */
5565 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5572 byte
= (value
& 0x7f);
5574 more
= !((value
== 0 && (byte
& 0x40) == 0)
5575 || (value
== -1 && (byte
& 0x40) != 0));
5584 /* Calculate the checksum of a number in unsigned LEB128 format. */
5587 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5591 unsigned char byte
= (value
& 0x7f);
5594 /* More bytes to follow. */
5602 /* Checksum the context of the DIE. This adds the names of any
5603 surrounding namespaces or structures to the checksum. */
5606 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5610 int tag
= die
->die_tag
;
5612 if (tag
!= DW_TAG_namespace
5613 && tag
!= DW_TAG_structure_type
5614 && tag
!= DW_TAG_class_type
)
5617 name
= get_AT_string (die
, DW_AT_name
);
5619 spec
= get_AT_ref (die
, DW_AT_specification
);
5623 if (die
->die_parent
!= NULL
)
5624 checksum_die_context (die
->die_parent
, ctx
);
5626 CHECKSUM_ULEB128 ('C');
5627 CHECKSUM_ULEB128 (tag
);
5629 CHECKSUM_STRING (name
);
5632 /* Calculate the checksum of a location expression. */
5635 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5637 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5638 were emitted as a DW_FORM_sdata instead of a location expression. */
5639 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5641 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5642 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5646 /* Otherwise, just checksum the raw location expression. */
5651 CHECKSUM_ULEB128 (loc
->dtprel
);
5652 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5653 hash
= hash_loc_operands (loc
, hash
);
5655 loc
= loc
->dw_loc_next
;
5659 /* Calculate the checksum of an attribute. */
5662 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5663 struct md5_ctx
*ctx
, int *mark
)
5665 dw_loc_descr_ref loc
;
5668 if (AT_class (at
) == dw_val_class_die_ref
)
5670 dw_die_ref target_die
= AT_ref (at
);
5672 /* For pointer and reference types, we checksum only the (qualified)
5673 name of the target type (if there is a name). For friend entries,
5674 we checksum only the (qualified) name of the target type or function.
5675 This allows the checksum to remain the same whether the target type
5676 is complete or not. */
5677 if ((at
->dw_attr
== DW_AT_type
5678 && (tag
== DW_TAG_pointer_type
5679 || tag
== DW_TAG_reference_type
5680 || tag
== DW_TAG_rvalue_reference_type
5681 || tag
== DW_TAG_ptr_to_member_type
))
5682 || (at
->dw_attr
== DW_AT_friend
5683 && tag
== DW_TAG_friend
))
5685 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5687 if (name_attr
!= NULL
)
5689 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5693 CHECKSUM_ULEB128 ('N');
5694 CHECKSUM_ULEB128 (at
->dw_attr
);
5695 if (decl
->die_parent
!= NULL
)
5696 checksum_die_context (decl
->die_parent
, ctx
);
5697 CHECKSUM_ULEB128 ('E');
5698 CHECKSUM_STRING (AT_string (name_attr
));
5703 /* For all other references to another DIE, we check to see if the
5704 target DIE has already been visited. If it has, we emit a
5705 backward reference; if not, we descend recursively. */
5706 if (target_die
->die_mark
> 0)
5708 CHECKSUM_ULEB128 ('R');
5709 CHECKSUM_ULEB128 (at
->dw_attr
);
5710 CHECKSUM_ULEB128 (target_die
->die_mark
);
5714 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5718 target_die
->die_mark
= ++(*mark
);
5719 CHECKSUM_ULEB128 ('T');
5720 CHECKSUM_ULEB128 (at
->dw_attr
);
5721 if (decl
->die_parent
!= NULL
)
5722 checksum_die_context (decl
->die_parent
, ctx
);
5723 die_checksum_ordered (target_die
, ctx
, mark
);
5728 CHECKSUM_ULEB128 ('A');
5729 CHECKSUM_ULEB128 (at
->dw_attr
);
5731 switch (AT_class (at
))
5733 case dw_val_class_const
:
5734 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5735 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5738 case dw_val_class_unsigned_const
:
5739 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5740 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5743 case dw_val_class_const_double
:
5744 CHECKSUM_ULEB128 (DW_FORM_block
);
5745 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5746 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5749 case dw_val_class_vec
:
5750 CHECKSUM_ULEB128 (DW_FORM_block
);
5751 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5752 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5755 case dw_val_class_flag
:
5756 CHECKSUM_ULEB128 (DW_FORM_flag
);
5757 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5760 case dw_val_class_str
:
5761 CHECKSUM_ULEB128 (DW_FORM_string
);
5762 CHECKSUM_STRING (AT_string (at
));
5765 case dw_val_class_addr
:
5767 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5768 CHECKSUM_ULEB128 (DW_FORM_string
);
5769 CHECKSUM_STRING (XSTR (r
, 0));
5772 case dw_val_class_offset
:
5773 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5774 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5777 case dw_val_class_loc
:
5778 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5779 loc_checksum_ordered (loc
, ctx
);
5782 case dw_val_class_fde_ref
:
5783 case dw_val_class_lbl_id
:
5784 case dw_val_class_lineptr
:
5785 case dw_val_class_macptr
:
5786 case dw_val_class_high_pc
:
5789 case dw_val_class_file
:
5790 CHECKSUM_ULEB128 (DW_FORM_string
);
5791 CHECKSUM_STRING (AT_file (at
)->filename
);
5794 case dw_val_class_data8
:
5795 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5803 struct checksum_attributes
5805 dw_attr_ref at_name
;
5806 dw_attr_ref at_type
;
5807 dw_attr_ref at_friend
;
5808 dw_attr_ref at_accessibility
;
5809 dw_attr_ref at_address_class
;
5810 dw_attr_ref at_allocated
;
5811 dw_attr_ref at_artificial
;
5812 dw_attr_ref at_associated
;
5813 dw_attr_ref at_binary_scale
;
5814 dw_attr_ref at_bit_offset
;
5815 dw_attr_ref at_bit_size
;
5816 dw_attr_ref at_bit_stride
;
5817 dw_attr_ref at_byte_size
;
5818 dw_attr_ref at_byte_stride
;
5819 dw_attr_ref at_const_value
;
5820 dw_attr_ref at_containing_type
;
5821 dw_attr_ref at_count
;
5822 dw_attr_ref at_data_location
;
5823 dw_attr_ref at_data_member_location
;
5824 dw_attr_ref at_decimal_scale
;
5825 dw_attr_ref at_decimal_sign
;
5826 dw_attr_ref at_default_value
;
5827 dw_attr_ref at_digit_count
;
5828 dw_attr_ref at_discr
;
5829 dw_attr_ref at_discr_list
;
5830 dw_attr_ref at_discr_value
;
5831 dw_attr_ref at_encoding
;
5832 dw_attr_ref at_endianity
;
5833 dw_attr_ref at_explicit
;
5834 dw_attr_ref at_is_optional
;
5835 dw_attr_ref at_location
;
5836 dw_attr_ref at_lower_bound
;
5837 dw_attr_ref at_mutable
;
5838 dw_attr_ref at_ordering
;
5839 dw_attr_ref at_picture_string
;
5840 dw_attr_ref at_prototyped
;
5841 dw_attr_ref at_small
;
5842 dw_attr_ref at_segment
;
5843 dw_attr_ref at_string_length
;
5844 dw_attr_ref at_threads_scaled
;
5845 dw_attr_ref at_upper_bound
;
5846 dw_attr_ref at_use_location
;
5847 dw_attr_ref at_use_UTF8
;
5848 dw_attr_ref at_variable_parameter
;
5849 dw_attr_ref at_virtuality
;
5850 dw_attr_ref at_visibility
;
5851 dw_attr_ref at_vtable_elem_location
;
5854 /* Collect the attributes that we will want to use for the checksum. */
5857 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5862 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5873 attrs
->at_friend
= a
;
5875 case DW_AT_accessibility
:
5876 attrs
->at_accessibility
= a
;
5878 case DW_AT_address_class
:
5879 attrs
->at_address_class
= a
;
5881 case DW_AT_allocated
:
5882 attrs
->at_allocated
= a
;
5884 case DW_AT_artificial
:
5885 attrs
->at_artificial
= a
;
5887 case DW_AT_associated
:
5888 attrs
->at_associated
= a
;
5890 case DW_AT_binary_scale
:
5891 attrs
->at_binary_scale
= a
;
5893 case DW_AT_bit_offset
:
5894 attrs
->at_bit_offset
= a
;
5896 case DW_AT_bit_size
:
5897 attrs
->at_bit_size
= a
;
5899 case DW_AT_bit_stride
:
5900 attrs
->at_bit_stride
= a
;
5902 case DW_AT_byte_size
:
5903 attrs
->at_byte_size
= a
;
5905 case DW_AT_byte_stride
:
5906 attrs
->at_byte_stride
= a
;
5908 case DW_AT_const_value
:
5909 attrs
->at_const_value
= a
;
5911 case DW_AT_containing_type
:
5912 attrs
->at_containing_type
= a
;
5915 attrs
->at_count
= a
;
5917 case DW_AT_data_location
:
5918 attrs
->at_data_location
= a
;
5920 case DW_AT_data_member_location
:
5921 attrs
->at_data_member_location
= a
;
5923 case DW_AT_decimal_scale
:
5924 attrs
->at_decimal_scale
= a
;
5926 case DW_AT_decimal_sign
:
5927 attrs
->at_decimal_sign
= a
;
5929 case DW_AT_default_value
:
5930 attrs
->at_default_value
= a
;
5932 case DW_AT_digit_count
:
5933 attrs
->at_digit_count
= a
;
5936 attrs
->at_discr
= a
;
5938 case DW_AT_discr_list
:
5939 attrs
->at_discr_list
= a
;
5941 case DW_AT_discr_value
:
5942 attrs
->at_discr_value
= a
;
5944 case DW_AT_encoding
:
5945 attrs
->at_encoding
= a
;
5947 case DW_AT_endianity
:
5948 attrs
->at_endianity
= a
;
5950 case DW_AT_explicit
:
5951 attrs
->at_explicit
= a
;
5953 case DW_AT_is_optional
:
5954 attrs
->at_is_optional
= a
;
5956 case DW_AT_location
:
5957 attrs
->at_location
= a
;
5959 case DW_AT_lower_bound
:
5960 attrs
->at_lower_bound
= a
;
5963 attrs
->at_mutable
= a
;
5965 case DW_AT_ordering
:
5966 attrs
->at_ordering
= a
;
5968 case DW_AT_picture_string
:
5969 attrs
->at_picture_string
= a
;
5971 case DW_AT_prototyped
:
5972 attrs
->at_prototyped
= a
;
5975 attrs
->at_small
= a
;
5978 attrs
->at_segment
= a
;
5980 case DW_AT_string_length
:
5981 attrs
->at_string_length
= a
;
5983 case DW_AT_threads_scaled
:
5984 attrs
->at_threads_scaled
= a
;
5986 case DW_AT_upper_bound
:
5987 attrs
->at_upper_bound
= a
;
5989 case DW_AT_use_location
:
5990 attrs
->at_use_location
= a
;
5992 case DW_AT_use_UTF8
:
5993 attrs
->at_use_UTF8
= a
;
5995 case DW_AT_variable_parameter
:
5996 attrs
->at_variable_parameter
= a
;
5998 case DW_AT_virtuality
:
5999 attrs
->at_virtuality
= a
;
6001 case DW_AT_visibility
:
6002 attrs
->at_visibility
= a
;
6004 case DW_AT_vtable_elem_location
:
6005 attrs
->at_vtable_elem_location
= a
;
6013 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6016 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6020 struct checksum_attributes attrs
;
6022 CHECKSUM_ULEB128 ('D');
6023 CHECKSUM_ULEB128 (die
->die_tag
);
6025 memset (&attrs
, 0, sizeof (attrs
));
6027 decl
= get_AT_ref (die
, DW_AT_specification
);
6029 collect_checksum_attributes (&attrs
, decl
);
6030 collect_checksum_attributes (&attrs
, die
);
6032 CHECKSUM_ATTR (attrs
.at_name
);
6033 CHECKSUM_ATTR (attrs
.at_accessibility
);
6034 CHECKSUM_ATTR (attrs
.at_address_class
);
6035 CHECKSUM_ATTR (attrs
.at_allocated
);
6036 CHECKSUM_ATTR (attrs
.at_artificial
);
6037 CHECKSUM_ATTR (attrs
.at_associated
);
6038 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6039 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6040 CHECKSUM_ATTR (attrs
.at_bit_size
);
6041 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6042 CHECKSUM_ATTR (attrs
.at_byte_size
);
6043 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6044 CHECKSUM_ATTR (attrs
.at_const_value
);
6045 CHECKSUM_ATTR (attrs
.at_containing_type
);
6046 CHECKSUM_ATTR (attrs
.at_count
);
6047 CHECKSUM_ATTR (attrs
.at_data_location
);
6048 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6049 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6050 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6051 CHECKSUM_ATTR (attrs
.at_default_value
);
6052 CHECKSUM_ATTR (attrs
.at_digit_count
);
6053 CHECKSUM_ATTR (attrs
.at_discr
);
6054 CHECKSUM_ATTR (attrs
.at_discr_list
);
6055 CHECKSUM_ATTR (attrs
.at_discr_value
);
6056 CHECKSUM_ATTR (attrs
.at_encoding
);
6057 CHECKSUM_ATTR (attrs
.at_endianity
);
6058 CHECKSUM_ATTR (attrs
.at_explicit
);
6059 CHECKSUM_ATTR (attrs
.at_is_optional
);
6060 CHECKSUM_ATTR (attrs
.at_location
);
6061 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6062 CHECKSUM_ATTR (attrs
.at_mutable
);
6063 CHECKSUM_ATTR (attrs
.at_ordering
);
6064 CHECKSUM_ATTR (attrs
.at_picture_string
);
6065 CHECKSUM_ATTR (attrs
.at_prototyped
);
6066 CHECKSUM_ATTR (attrs
.at_small
);
6067 CHECKSUM_ATTR (attrs
.at_segment
);
6068 CHECKSUM_ATTR (attrs
.at_string_length
);
6069 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6070 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6071 CHECKSUM_ATTR (attrs
.at_use_location
);
6072 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6073 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6074 CHECKSUM_ATTR (attrs
.at_virtuality
);
6075 CHECKSUM_ATTR (attrs
.at_visibility
);
6076 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6077 CHECKSUM_ATTR (attrs
.at_type
);
6078 CHECKSUM_ATTR (attrs
.at_friend
);
6080 /* Checksum the child DIEs, except for nested types and member functions. */
6083 dw_attr_ref name_attr
;
6086 name_attr
= get_AT (c
, DW_AT_name
);
6087 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6088 && name_attr
!= NULL
)
6090 CHECKSUM_ULEB128 ('S');
6091 CHECKSUM_ULEB128 (c
->die_tag
);
6092 CHECKSUM_STRING (AT_string (name_attr
));
6096 /* Mark this DIE so it gets processed when unmarking. */
6097 if (c
->die_mark
== 0)
6099 die_checksum_ordered (c
, ctx
, mark
);
6101 } while (c
!= die
->die_child
);
6103 CHECKSUM_ULEB128 (0);
6107 #undef CHECKSUM_STRING
6108 #undef CHECKSUM_ATTR
6109 #undef CHECKSUM_LEB128
6110 #undef CHECKSUM_ULEB128
6112 /* Generate the type signature for DIE. This is computed by generating an
6113 MD5 checksum over the DIE's tag, its relevant attributes, and its
6114 children. Attributes that are references to other DIEs are processed
6115 by recursion, using the MARK field to prevent infinite recursion.
6116 If the DIE is nested inside a namespace or another type, we also
6117 need to include that context in the signature. The lower 64 bits
6118 of the resulting MD5 checksum comprise the signature. */
6121 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6125 unsigned char checksum
[16];
6130 name
= get_AT_string (die
, DW_AT_name
);
6131 decl
= get_AT_ref (die
, DW_AT_specification
);
6132 parent
= get_die_parent (die
);
6134 /* First, compute a signature for just the type name (and its surrounding
6135 context, if any. This is stored in the type unit DIE for link-time
6136 ODR (one-definition rule) checking. */
6138 if (is_cxx() && name
!= NULL
)
6140 md5_init_ctx (&ctx
);
6142 /* Checksum the names of surrounding namespaces and structures. */
6144 checksum_die_context (parent
, &ctx
);
6146 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6147 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6148 md5_finish_ctx (&ctx
, checksum
);
6150 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6153 /* Next, compute the complete type signature. */
6155 md5_init_ctx (&ctx
);
6157 die
->die_mark
= mark
;
6159 /* Checksum the names of surrounding namespaces and structures. */
6161 checksum_die_context (parent
, &ctx
);
6163 /* Checksum the DIE and its children. */
6164 die_checksum_ordered (die
, &ctx
, &mark
);
6165 unmark_all_dies (die
);
6166 md5_finish_ctx (&ctx
, checksum
);
6168 /* Store the signature in the type node and link the type DIE and the
6169 type node together. */
6170 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6171 DWARF_TYPE_SIGNATURE_SIZE
);
6172 die
->comdat_type_p
= true;
6173 die
->die_id
.die_type_node
= type_node
;
6174 type_node
->type_die
= die
;
6176 /* If the DIE is a specification, link its declaration to the type node
6180 decl
->comdat_type_p
= true;
6181 decl
->die_id
.die_type_node
= type_node
;
6185 /* Do the location expressions look same? */
6187 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6189 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6190 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6191 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6194 /* Do the values look the same? */
6196 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6198 dw_loc_descr_ref loc1
, loc2
;
6201 if (v1
->val_class
!= v2
->val_class
)
6204 switch (v1
->val_class
)
6206 case dw_val_class_const
:
6207 return v1
->v
.val_int
== v2
->v
.val_int
;
6208 case dw_val_class_unsigned_const
:
6209 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6210 case dw_val_class_const_double
:
6211 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6212 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6213 case dw_val_class_vec
:
6214 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6215 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6217 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6218 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6221 case dw_val_class_flag
:
6222 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6223 case dw_val_class_str
:
6224 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6226 case dw_val_class_addr
:
6227 r1
= v1
->v
.val_addr
;
6228 r2
= v2
->v
.val_addr
;
6229 if (GET_CODE (r1
) != GET_CODE (r2
))
6231 return !rtx_equal_p (r1
, r2
);
6233 case dw_val_class_offset
:
6234 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6236 case dw_val_class_loc
:
6237 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6239 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6240 if (!same_loc_p (loc1
, loc2
, mark
))
6242 return !loc1
&& !loc2
;
6244 case dw_val_class_die_ref
:
6245 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6247 case dw_val_class_fde_ref
:
6248 case dw_val_class_vms_delta
:
6249 case dw_val_class_lbl_id
:
6250 case dw_val_class_lineptr
:
6251 case dw_val_class_macptr
:
6252 case dw_val_class_high_pc
:
6255 case dw_val_class_file
:
6256 return v1
->v
.val_file
== v2
->v
.val_file
;
6258 case dw_val_class_data8
:
6259 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6266 /* Do the attributes look the same? */
6269 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6271 if (at1
->dw_attr
!= at2
->dw_attr
)
6274 /* We don't care that this was compiled with a different compiler
6275 snapshot; if the output is the same, that's what matters. */
6276 if (at1
->dw_attr
== DW_AT_producer
)
6279 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6282 /* Do the dies look the same? */
6285 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6291 /* To avoid infinite recursion. */
6293 return die1
->die_mark
== die2
->die_mark
;
6294 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6296 if (die1
->die_tag
!= die2
->die_tag
)
6299 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6302 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6303 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6306 c1
= die1
->die_child
;
6307 c2
= die2
->die_child
;
6316 if (!same_die_p (c1
, c2
, mark
))
6320 if (c1
== die1
->die_child
)
6322 if (c2
== die2
->die_child
)
6332 /* Do the dies look the same? Wrapper around same_die_p. */
6335 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6338 int ret
= same_die_p (die1
, die2
, &mark
);
6340 unmark_all_dies (die1
);
6341 unmark_all_dies (die2
);
6346 /* The prefix to attach to symbols on DIEs in the current comdat debug
6348 static const char *comdat_symbol_id
;
6350 /* The index of the current symbol within the current comdat CU. */
6351 static unsigned int comdat_symbol_number
;
6353 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6354 children, and set comdat_symbol_id accordingly. */
6357 compute_section_prefix (dw_die_ref unit_die
)
6359 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6360 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6361 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6364 unsigned char checksum
[16];
6367 /* Compute the checksum of the DIE, then append part of it as hex digits to
6368 the name filename of the unit. */
6370 md5_init_ctx (&ctx
);
6372 die_checksum (unit_die
, &ctx
, &mark
);
6373 unmark_all_dies (unit_die
);
6374 md5_finish_ctx (&ctx
, checksum
);
6376 sprintf (name
, "%s.", base
);
6377 clean_symbol_name (name
);
6379 p
= name
+ strlen (name
);
6380 for (i
= 0; i
< 4; i
++)
6382 sprintf (p
, "%.2x", checksum
[i
]);
6386 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6387 comdat_symbol_number
= 0;
6390 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6393 is_type_die (dw_die_ref die
)
6395 switch (die
->die_tag
)
6397 case DW_TAG_array_type
:
6398 case DW_TAG_class_type
:
6399 case DW_TAG_interface_type
:
6400 case DW_TAG_enumeration_type
:
6401 case DW_TAG_pointer_type
:
6402 case DW_TAG_reference_type
:
6403 case DW_TAG_rvalue_reference_type
:
6404 case DW_TAG_string_type
:
6405 case DW_TAG_structure_type
:
6406 case DW_TAG_subroutine_type
:
6407 case DW_TAG_union_type
:
6408 case DW_TAG_ptr_to_member_type
:
6409 case DW_TAG_set_type
:
6410 case DW_TAG_subrange_type
:
6411 case DW_TAG_base_type
:
6412 case DW_TAG_const_type
:
6413 case DW_TAG_file_type
:
6414 case DW_TAG_packed_type
:
6415 case DW_TAG_volatile_type
:
6416 case DW_TAG_typedef
:
6423 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6424 Basically, we want to choose the bits that are likely to be shared between
6425 compilations (types) and leave out the bits that are specific to individual
6426 compilations (functions). */
6429 is_comdat_die (dw_die_ref c
)
6431 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6432 we do for stabs. The advantage is a greater likelihood of sharing between
6433 objects that don't include headers in the same order (and therefore would
6434 put the base types in a different comdat). jason 8/28/00 */
6436 if (c
->die_tag
== DW_TAG_base_type
)
6439 if (c
->die_tag
== DW_TAG_pointer_type
6440 || c
->die_tag
== DW_TAG_reference_type
6441 || c
->die_tag
== DW_TAG_rvalue_reference_type
6442 || c
->die_tag
== DW_TAG_const_type
6443 || c
->die_tag
== DW_TAG_volatile_type
)
6445 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6447 return t
? is_comdat_die (t
) : 0;
6450 return is_type_die (c
);
6453 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6454 compilation unit. */
6457 is_symbol_die (dw_die_ref c
)
6459 return (is_type_die (c
)
6460 || is_declaration_die (c
)
6461 || c
->die_tag
== DW_TAG_namespace
6462 || c
->die_tag
== DW_TAG_module
);
6465 /* Returns true iff C is a compile-unit DIE. */
6468 is_cu_die (dw_die_ref c
)
6470 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6473 /* Returns true iff C is a unit DIE of some sort. */
6476 is_unit_die (dw_die_ref c
)
6478 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6479 || c
->die_tag
== DW_TAG_partial_unit
6480 || c
->die_tag
== DW_TAG_type_unit
);
6483 /* Returns true iff C is a namespace DIE. */
6486 is_namespace_die (dw_die_ref c
)
6488 return c
&& c
->die_tag
== DW_TAG_namespace
;
6491 /* Returns true iff C is a class or structure DIE. */
6494 is_class_die (dw_die_ref c
)
6496 return c
&& (c
->die_tag
== DW_TAG_class_type
6497 || c
->die_tag
== DW_TAG_structure_type
);
6501 gen_internal_sym (const char *prefix
)
6505 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6506 return xstrdup (buf
);
6509 /* Assign symbols to all worthy DIEs under DIE. */
6512 assign_symbol_names (dw_die_ref die
)
6516 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6518 if (comdat_symbol_id
)
6520 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6522 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6523 comdat_symbol_id
, comdat_symbol_number
++);
6524 die
->die_id
.die_symbol
= xstrdup (p
);
6527 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6530 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6533 struct cu_hash_table_entry
6536 unsigned min_comdat_num
, max_comdat_num
;
6537 struct cu_hash_table_entry
*next
;
6540 /* Helpers to manipulate hash table of CUs. */
6542 struct cu_hash_table_entry_hasher
6544 typedef cu_hash_table_entry value_type
;
6545 typedef die_struct compare_type
;
6546 static inline hashval_t
hash (const value_type
*);
6547 static inline bool equal (const value_type
*, const compare_type
*);
6548 static inline void remove (value_type
*);
6552 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6554 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6558 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6559 const compare_type
*entry2
)
6561 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6565 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6567 struct cu_hash_table_entry
*next
;
6577 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6579 /* Check whether we have already seen this CU and set up SYM_NUM
6582 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6584 struct cu_hash_table_entry dummy
;
6585 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6587 dummy
.max_comdat_num
= 0;
6589 slot
= htable
.find_slot_with_hash (cu
,
6590 htab_hash_string (cu
->die_id
.die_symbol
),
6594 for (; entry
; last
= entry
, entry
= entry
->next
)
6596 if (same_die_p_wrap (cu
, entry
->cu
))
6602 *sym_num
= entry
->min_comdat_num
;
6606 entry
= XCNEW (struct cu_hash_table_entry
);
6608 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6609 entry
->next
= *slot
;
6615 /* Record SYM_NUM to record of CU in HTABLE. */
6617 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6618 unsigned int sym_num
)
6620 struct cu_hash_table_entry
**slot
, *entry
;
6622 slot
= htable
.find_slot_with_hash (cu
,
6623 htab_hash_string (cu
->die_id
.die_symbol
),
6627 entry
->max_comdat_num
= sym_num
;
6630 /* Traverse the DIE (which is always comp_unit_die), and set up
6631 additional compilation units for each of the include files we see
6632 bracketed by BINCL/EINCL. */
6635 break_out_includes (dw_die_ref die
)
6638 dw_die_ref unit
= NULL
;
6639 limbo_die_node
*node
, **pnode
;
6640 cu_hash_type cu_hash_table
;
6644 dw_die_ref prev
= c
;
6646 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6647 || (unit
&& is_comdat_die (c
)))
6649 dw_die_ref next
= c
->die_sib
;
6651 /* This DIE is for a secondary CU; remove it from the main one. */
6652 remove_child_with_prev (c
, prev
);
6654 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6655 unit
= push_new_compile_unit (unit
, c
);
6656 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6657 unit
= pop_compile_unit (unit
);
6659 add_child_die (unit
, c
);
6661 if (c
== die
->die_child
)
6664 } while (c
!= die
->die_child
);
6667 /* We can only use this in debugging, since the frontend doesn't check
6668 to make sure that we leave every include file we enter. */
6672 assign_symbol_names (die
);
6673 cu_hash_table
.create (10);
6674 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6680 compute_section_prefix (node
->die
);
6681 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6682 &comdat_symbol_number
);
6683 assign_symbol_names (node
->die
);
6685 *pnode
= node
->next
;
6688 pnode
= &node
->next
;
6689 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6690 comdat_symbol_number
);
6693 cu_hash_table
.dispose ();
6696 /* Return non-zero if this DIE is a declaration. */
6699 is_declaration_die (dw_die_ref die
)
6704 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6705 if (a
->dw_attr
== DW_AT_declaration
)
6711 /* Return non-zero if this DIE is nested inside a subprogram. */
6714 is_nested_in_subprogram (dw_die_ref die
)
6716 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6720 return local_scope_p (decl
);
6723 /* Return non-zero if this DIE contains a defining declaration of a
6727 contains_subprogram_definition (dw_die_ref die
)
6731 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6733 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6737 /* Return non-zero if this is a type DIE that should be moved to a
6738 COMDAT .debug_types section. */
6741 should_move_die_to_comdat (dw_die_ref die
)
6743 switch (die
->die_tag
)
6745 case DW_TAG_class_type
:
6746 case DW_TAG_structure_type
:
6747 case DW_TAG_enumeration_type
:
6748 case DW_TAG_union_type
:
6749 /* Don't move declarations, inlined instances, or types nested in a
6751 if (is_declaration_die (die
)
6752 || get_AT (die
, DW_AT_abstract_origin
)
6753 || is_nested_in_subprogram (die
))
6755 /* A type definition should never contain a subprogram definition. */
6756 gcc_assert (!contains_subprogram_definition (die
));
6758 case DW_TAG_array_type
:
6759 case DW_TAG_interface_type
:
6760 case DW_TAG_pointer_type
:
6761 case DW_TAG_reference_type
:
6762 case DW_TAG_rvalue_reference_type
:
6763 case DW_TAG_string_type
:
6764 case DW_TAG_subroutine_type
:
6765 case DW_TAG_ptr_to_member_type
:
6766 case DW_TAG_set_type
:
6767 case DW_TAG_subrange_type
:
6768 case DW_TAG_base_type
:
6769 case DW_TAG_const_type
:
6770 case DW_TAG_file_type
:
6771 case DW_TAG_packed_type
:
6772 case DW_TAG_volatile_type
:
6773 case DW_TAG_typedef
:
6779 /* Make a clone of DIE. */
6782 clone_die (dw_die_ref die
)
6788 clone
= ggc_alloc_cleared_die_node ();
6789 clone
->die_tag
= die
->die_tag
;
6791 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6792 add_dwarf_attr (clone
, a
);
6797 /* Make a clone of the tree rooted at DIE. */
6800 clone_tree (dw_die_ref die
)
6803 dw_die_ref clone
= clone_die (die
);
6805 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6810 /* Make a clone of DIE as a declaration. */
6813 clone_as_declaration (dw_die_ref die
)
6820 /* If the DIE is already a declaration, just clone it. */
6821 if (is_declaration_die (die
))
6822 return clone_die (die
);
6824 /* If the DIE is a specification, just clone its declaration DIE. */
6825 decl
= get_AT_ref (die
, DW_AT_specification
);
6828 clone
= clone_die (decl
);
6829 if (die
->comdat_type_p
)
6830 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6834 clone
= ggc_alloc_cleared_die_node ();
6835 clone
->die_tag
= die
->die_tag
;
6837 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6839 /* We don't want to copy over all attributes.
6840 For example we don't want DW_AT_byte_size because otherwise we will no
6841 longer have a declaration and GDB will treat it as a definition. */
6845 case DW_AT_artificial
:
6846 case DW_AT_containing_type
:
6847 case DW_AT_external
:
6850 case DW_AT_virtuality
:
6851 case DW_AT_linkage_name
:
6852 case DW_AT_MIPS_linkage_name
:
6853 add_dwarf_attr (clone
, a
);
6855 case DW_AT_byte_size
:
6861 if (die
->comdat_type_p
)
6862 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6864 add_AT_flag (clone
, DW_AT_declaration
, 1);
6869 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6871 struct decl_table_entry
6877 /* Helpers to manipulate hash table of copied declarations. */
6879 /* Hashtable helpers. */
6881 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6883 typedef decl_table_entry value_type
;
6884 typedef die_struct compare_type
;
6885 static inline hashval_t
hash (const value_type
*);
6886 static inline bool equal (const value_type
*, const compare_type
*);
6890 decl_table_entry_hasher::hash (const value_type
*entry
)
6892 return htab_hash_pointer (entry
->orig
);
6896 decl_table_entry_hasher::equal (const value_type
*entry1
,
6897 const compare_type
*entry2
)
6899 return entry1
->orig
== entry2
;
6902 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6904 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6905 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6906 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6907 to check if the ancestor has already been copied into UNIT. */
6910 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6912 dw_die_ref parent
= die
->die_parent
;
6913 dw_die_ref new_parent
= unit
;
6915 decl_table_entry
**slot
= NULL
;
6916 struct decl_table_entry
*entry
= NULL
;
6918 if (decl_table
.is_created ())
6920 /* Check if the entry has already been copied to UNIT. */
6921 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
6923 if (*slot
!= HTAB_EMPTY_ENTRY
)
6929 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
6930 entry
= XCNEW (struct decl_table_entry
);
6938 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
6941 if (!is_unit_die (parent
))
6942 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
6945 copy
= clone_as_declaration (die
);
6946 add_child_die (new_parent
, copy
);
6948 if (decl_table
.is_created ())
6950 /* Record the pointer to the copy. */
6956 /* Copy the declaration context to the new type unit DIE. This includes
6957 any surrounding namespace or type declarations. If the DIE has an
6958 AT_specification attribute, it also includes attributes and children
6959 attached to the specification, and returns a pointer to the original
6960 parent of the declaration DIE. Returns NULL otherwise. */
6963 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6966 dw_die_ref new_decl
;
6967 dw_die_ref orig_parent
= NULL
;
6969 decl
= get_AT_ref (die
, DW_AT_specification
);
6978 /* The original DIE will be changed to a declaration, and must
6979 be moved to be a child of the original declaration DIE. */
6980 orig_parent
= decl
->die_parent
;
6982 /* Copy the type node pointer from the new DIE to the original
6983 declaration DIE so we can forward references later. */
6984 decl
->comdat_type_p
= true;
6985 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6987 remove_AT (die
, DW_AT_specification
);
6989 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6991 if (a
->dw_attr
!= DW_AT_name
6992 && a
->dw_attr
!= DW_AT_declaration
6993 && a
->dw_attr
!= DW_AT_external
)
6994 add_dwarf_attr (die
, a
);
6997 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
7000 if (decl
->die_parent
!= NULL
7001 && !is_unit_die (decl
->die_parent
))
7003 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7004 if (new_decl
!= NULL
)
7006 remove_AT (new_decl
, DW_AT_signature
);
7007 add_AT_specification (die
, new_decl
);
7014 /* Generate the skeleton ancestor tree for the given NODE, then clone
7015 the DIE and add the clone into the tree. */
7018 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7020 if (node
->new_die
!= NULL
)
7023 node
->new_die
= clone_as_declaration (node
->old_die
);
7025 if (node
->parent
!= NULL
)
7027 generate_skeleton_ancestor_tree (node
->parent
);
7028 add_child_die (node
->parent
->new_die
, node
->new_die
);
7032 /* Generate a skeleton tree of DIEs containing any declarations that are
7033 found in the original tree. We traverse the tree looking for declaration
7034 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7037 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7039 skeleton_chain_node node
;
7042 dw_die_ref prev
= NULL
;
7043 dw_die_ref next
= NULL
;
7045 node
.parent
= parent
;
7047 first
= c
= parent
->old_die
->die_child
;
7051 if (prev
== NULL
|| prev
->die_sib
== c
)
7054 next
= (c
== first
? NULL
: c
->die_sib
);
7056 node
.new_die
= NULL
;
7057 if (is_declaration_die (c
))
7059 /* Clone the existing DIE, move the original to the skeleton
7060 tree (which is in the main CU), and put the clone, with
7061 all the original's children, where the original came from. */
7062 dw_die_ref clone
= clone_die (c
);
7063 move_all_children (c
, clone
);
7065 replace_child (c
, clone
, prev
);
7066 generate_skeleton_ancestor_tree (parent
);
7067 add_child_die (parent
->new_die
, c
);
7071 generate_skeleton_bottom_up (&node
);
7072 } while (next
!= NULL
);
7075 /* Wrapper function for generate_skeleton_bottom_up. */
7078 generate_skeleton (dw_die_ref die
)
7080 skeleton_chain_node node
;
7083 node
.new_die
= NULL
;
7086 /* If this type definition is nested inside another type,
7087 always leave at least a declaration in its place. */
7088 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
7089 node
.new_die
= clone_as_declaration (die
);
7091 generate_skeleton_bottom_up (&node
);
7092 return node
.new_die
;
7095 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7096 declaration. The original DIE is moved to a new compile unit so that
7097 existing references to it follow it to the new location. If any of the
7098 original DIE's descendants is a declaration, we need to replace the
7099 original DIE with a skeleton tree and move the declarations back into the
7103 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7106 dw_die_ref skeleton
, orig_parent
;
7108 /* Copy the declaration context to the type unit DIE. If the returned
7109 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7111 orig_parent
= copy_declaration_context (unit
, child
);
7113 skeleton
= generate_skeleton (child
);
7114 if (skeleton
== NULL
)
7115 remove_child_with_prev (child
, prev
);
7118 skeleton
->comdat_type_p
= true;
7119 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7121 /* If the original DIE was a specification, we need to put
7122 the skeleton under the parent DIE of the declaration.
7123 This leaves the original declaration in the tree, but
7124 it will be pruned later since there are no longer any
7125 references to it. */
7126 if (orig_parent
!= NULL
)
7128 remove_child_with_prev (child
, prev
);
7129 add_child_die (orig_parent
, skeleton
);
7132 replace_child (child
, skeleton
, prev
);
7138 /* Traverse the DIE and set up additional .debug_types sections for each
7139 type worthy of being placed in a COMDAT section. */
7142 break_out_comdat_types (dw_die_ref die
)
7146 dw_die_ref prev
= NULL
;
7147 dw_die_ref next
= NULL
;
7148 dw_die_ref unit
= NULL
;
7150 first
= c
= die
->die_child
;
7154 if (prev
== NULL
|| prev
->die_sib
== c
)
7157 next
= (c
== first
? NULL
: c
->die_sib
);
7158 if (should_move_die_to_comdat (c
))
7160 dw_die_ref replacement
;
7161 comdat_type_node_ref type_node
;
7163 /* Create a new type unit DIE as the root for the new tree, and
7164 add it to the list of comdat types. */
7165 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7166 add_AT_unsigned (unit
, DW_AT_language
,
7167 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7168 type_node
= ggc_alloc_cleared_comdat_type_node ();
7169 type_node
->root_die
= unit
;
7170 type_node
->next
= comdat_type_list
;
7171 comdat_type_list
= type_node
;
7173 /* Generate the type signature. */
7174 generate_type_signature (c
, type_node
);
7176 /* Copy the declaration context, attributes, and children of the
7177 declaration into the new type unit DIE, then remove this DIE
7178 from the main CU (or replace it with a skeleton if necessary). */
7179 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7180 type_node
->skeleton_die
= replacement
;
7182 /* Break out nested types into their own type units. */
7183 break_out_comdat_types (c
);
7185 /* Add the DIE to the new compunit. */
7186 add_child_die (unit
, c
);
7188 if (replacement
!= NULL
)
7191 else if (c
->die_tag
== DW_TAG_namespace
7192 || c
->die_tag
== DW_TAG_class_type
7193 || c
->die_tag
== DW_TAG_structure_type
7194 || c
->die_tag
== DW_TAG_union_type
)
7196 /* Look for nested types that can be broken out. */
7197 break_out_comdat_types (c
);
7199 } while (next
!= NULL
);
7202 /* Like clone_tree, but additionally enter all the children into
7203 the hash table decl_table. */
7206 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7209 dw_die_ref clone
= clone_die (die
);
7210 struct decl_table_entry
*entry
;
7211 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7212 htab_hash_pointer (die
), INSERT
);
7213 /* Assert that DIE isn't in the hash table yet. If it would be there
7214 before, the ancestors would be necessarily there as well, therefore
7215 clone_tree_hash wouldn't be called. */
7216 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7217 entry
= XCNEW (struct decl_table_entry
);
7219 entry
->copy
= clone
;
7222 FOR_EACH_CHILD (die
, c
,
7223 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7228 /* Walk the DIE and its children, looking for references to incomplete
7229 or trivial types that are unmarked (i.e., that are not in the current
7233 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7239 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7241 if (AT_class (a
) == dw_val_class_die_ref
)
7243 dw_die_ref targ
= AT_ref (a
);
7244 decl_table_entry
**slot
;
7245 struct decl_table_entry
*entry
;
7247 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7250 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7253 if (*slot
!= HTAB_EMPTY_ENTRY
)
7255 /* TARG has already been copied, so we just need to
7256 modify the reference to point to the copy. */
7258 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7262 dw_die_ref parent
= unit
;
7263 dw_die_ref copy
= clone_die (targ
);
7265 /* Record in DECL_TABLE that TARG has been copied.
7266 Need to do this now, before the recursive call,
7267 because DECL_TABLE may be expanded and SLOT
7268 would no longer be a valid pointer. */
7269 entry
= XCNEW (struct decl_table_entry
);
7274 FOR_EACH_CHILD (targ
, c
,
7275 add_child_die (copy
,
7276 clone_tree_hash (c
, decl_table
)));
7278 /* Make sure the cloned tree is marked as part of the
7282 /* If TARG has surrounding context, copy its ancestor tree
7283 into the new type unit. */
7284 if (targ
->die_parent
!= NULL
7285 && !is_unit_die (targ
->die_parent
))
7286 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7289 add_child_die (parent
, copy
);
7290 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7292 /* Make sure the newly-copied DIE is walked. If it was
7293 installed in a previously-added context, it won't
7294 get visited otherwise. */
7297 /* Find the highest point of the newly-added tree,
7298 mark each node along the way, and walk from there. */
7299 parent
->die_mark
= 1;
7300 while (parent
->die_parent
7301 && parent
->die_parent
->die_mark
== 0)
7303 parent
= parent
->die_parent
;
7304 parent
->die_mark
= 1;
7306 copy_decls_walk (unit
, parent
, decl_table
);
7312 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7315 /* Copy declarations for "unworthy" types into the new comdat section.
7316 Incomplete types, modified types, and certain other types aren't broken
7317 out into comdat sections of their own, so they don't have a signature,
7318 and we need to copy the declaration into the same section so that we
7319 don't have an external reference. */
7322 copy_decls_for_unworthy_types (dw_die_ref unit
)
7324 decl_hash_type decl_table
;
7327 decl_table
.create (10);
7328 copy_decls_walk (unit
, unit
, decl_table
);
7329 decl_table
.dispose ();
7333 /* Traverse the DIE and add a sibling attribute if it may have the
7334 effect of speeding up access to siblings. To save some space,
7335 avoid generating sibling attributes for DIE's without children. */
7338 add_sibling_attributes (dw_die_ref die
)
7342 if (! die
->die_child
)
7345 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7346 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7348 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7351 /* Output all location lists for the DIE and its children. */
7354 output_location_lists (dw_die_ref die
)
7360 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7361 if (AT_class (a
) == dw_val_class_loc_list
)
7362 output_loc_list (AT_loc_list (a
));
7364 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7367 /* We want to limit the number of external references, because they are
7368 larger than local references: a relocation takes multiple words, and
7369 even a sig8 reference is always eight bytes, whereas a local reference
7370 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7371 So if we encounter multiple external references to the same type DIE, we
7372 make a local typedef stub for it and redirect all references there.
7374 This is the element of the hash table for keeping track of these
7384 /* Hashtable helpers. */
7386 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7388 typedef external_ref value_type
;
7389 typedef external_ref compare_type
;
7390 static inline hashval_t
hash (const value_type
*);
7391 static inline bool equal (const value_type
*, const compare_type
*);
7395 external_ref_hasher::hash (const value_type
*r
)
7397 dw_die_ref die
= r
->type
;
7400 /* We can't use the address of the DIE for hashing, because
7401 that will make the order of the stub DIEs non-deterministic. */
7402 if (! die
->comdat_type_p
)
7403 /* We have a symbol; use it to compute a hash. */
7404 h
= htab_hash_string (die
->die_id
.die_symbol
);
7407 /* We have a type signature; use a subset of the bits as the hash.
7408 The 8-byte signature is at least as large as hashval_t. */
7409 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7410 memcpy (&h
, type_node
->signature
, sizeof (h
));
7416 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7418 return r1
->type
== r2
->type
;
7421 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7423 /* Return a pointer to the external_ref for references to DIE. */
7425 static struct external_ref
*
7426 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7428 struct external_ref ref
, *ref_p
;
7429 external_ref
**slot
;
7432 slot
= map
.find_slot (&ref
, INSERT
);
7433 if (*slot
!= HTAB_EMPTY_ENTRY
)
7436 ref_p
= XCNEW (struct external_ref
);
7442 /* Subroutine of optimize_external_refs, below.
7444 If we see a type skeleton, record it as our stub. If we see external
7445 references, remember how many we've seen. */
7448 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7453 struct external_ref
*ref_p
;
7455 if (is_type_die (die
)
7456 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7458 /* This is a local skeleton; use it for local references. */
7459 ref_p
= lookup_external_ref (map
, c
);
7463 /* Scan the DIE references, and remember any that refer to DIEs from
7464 other CUs (i.e. those which are not marked). */
7465 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7466 if (AT_class (a
) == dw_val_class_die_ref
7467 && (c
= AT_ref (a
))->die_mark
== 0
7470 ref_p
= lookup_external_ref (map
, c
);
7474 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7477 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7478 points to an external_ref, DATA is the CU we're processing. If we don't
7479 already have a local stub, and we have multiple refs, build a stub. */
7482 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7484 struct external_ref
*ref_p
= *slot
;
7486 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7488 /* We have multiple references to this type, so build a small stub.
7489 Both of these forms are a bit dodgy from the perspective of the
7490 DWARF standard, since technically they should have names. */
7491 dw_die_ref cu
= data
;
7492 dw_die_ref type
= ref_p
->type
;
7493 dw_die_ref stub
= NULL
;
7495 if (type
->comdat_type_p
)
7497 /* If we refer to this type via sig8, use AT_signature. */
7498 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7499 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7503 /* Otherwise, use a typedef with no name. */
7504 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7505 add_AT_die_ref (stub
, DW_AT_type
, type
);
7514 /* DIE is a unit; look through all the DIE references to see if there are
7515 any external references to types, and if so, create local stubs for
7516 them which will be applied in build_abbrev_table. This is useful because
7517 references to local DIEs are smaller. */
7519 static external_ref_hash_type
7520 optimize_external_refs (dw_die_ref die
)
7522 external_ref_hash_type map
;
7524 optimize_external_refs_1 (die
, map
);
7525 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7529 /* The format of each DIE (and its attribute value pairs) is encoded in an
7530 abbreviation table. This routine builds the abbreviation table and assigns
7531 a unique abbreviation id for each abbreviation entry. The children of each
7532 die are visited recursively. */
7535 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7537 unsigned long abbrev_id
;
7538 unsigned int n_alloc
;
7543 /* Scan the DIE references, and replace any that refer to
7544 DIEs from other CUs (i.e. those which are not marked) with
7545 the local stubs we built in optimize_external_refs. */
7546 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7547 if (AT_class (a
) == dw_val_class_die_ref
7548 && (c
= AT_ref (a
))->die_mark
== 0)
7550 struct external_ref
*ref_p
;
7551 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7553 ref_p
= lookup_external_ref (extern_map
, c
);
7554 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7555 change_AT_die_ref (a
, ref_p
->stub
);
7557 /* We aren't changing this reference, so mark it external. */
7558 set_AT_ref_external (a
, 1);
7561 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7563 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7564 dw_attr_ref die_a
, abbrev_a
;
7568 if (abbrev
->die_tag
!= die
->die_tag
)
7570 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7573 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7576 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7578 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7579 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7580 || (value_format (abbrev_a
) != value_format (die_a
)))
7590 if (abbrev_id
>= abbrev_die_table_in_use
)
7592 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7594 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7595 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7598 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7599 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7600 abbrev_die_table_allocated
= n_alloc
;
7603 ++abbrev_die_table_in_use
;
7604 abbrev_die_table
[abbrev_id
] = die
;
7607 die
->die_abbrev
= abbrev_id
;
7608 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7611 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7614 constant_size (unsigned HOST_WIDE_INT value
)
7621 log
= floor_log2 (value
);
7624 log
= 1 << (floor_log2 (log
) + 1);
7629 /* Return the size of a DIE as it is represented in the
7630 .debug_info section. */
7632 static unsigned long
7633 size_of_die (dw_die_ref die
)
7635 unsigned long size
= 0;
7638 enum dwarf_form form
;
7640 size
+= size_of_uleb128 (die
->die_abbrev
);
7641 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7643 switch (AT_class (a
))
7645 case dw_val_class_addr
:
7646 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7648 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7649 size
+= size_of_uleb128 (AT_index (a
));
7652 size
+= DWARF2_ADDR_SIZE
;
7654 case dw_val_class_offset
:
7655 size
+= DWARF_OFFSET_SIZE
;
7657 case dw_val_class_loc
:
7659 unsigned long lsize
= size_of_locs (AT_loc (a
));
7662 if (dwarf_version
>= 4)
7663 size
+= size_of_uleb128 (lsize
);
7665 size
+= constant_size (lsize
);
7669 case dw_val_class_loc_list
:
7670 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7672 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7673 size
+= size_of_uleb128 (AT_index (a
));
7676 size
+= DWARF_OFFSET_SIZE
;
7678 case dw_val_class_range_list
:
7679 size
+= DWARF_OFFSET_SIZE
;
7681 case dw_val_class_const
:
7682 size
+= size_of_sleb128 (AT_int (a
));
7684 case dw_val_class_unsigned_const
:
7686 int csize
= constant_size (AT_unsigned (a
));
7687 if (dwarf_version
== 3
7688 && a
->dw_attr
== DW_AT_data_member_location
7690 size
+= size_of_uleb128 (AT_unsigned (a
));
7695 case dw_val_class_const_double
:
7696 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7697 if (HOST_BITS_PER_WIDE_INT
>= 64)
7700 case dw_val_class_vec
:
7701 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7702 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7703 + a
->dw_attr_val
.v
.val_vec
.length
7704 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7706 case dw_val_class_flag
:
7707 if (dwarf_version
>= 4)
7708 /* Currently all add_AT_flag calls pass in 1 as last argument,
7709 so DW_FORM_flag_present can be used. If that ever changes,
7710 we'll need to use DW_FORM_flag and have some optimization
7711 in build_abbrev_table that will change those to
7712 DW_FORM_flag_present if it is set to 1 in all DIEs using
7713 the same abbrev entry. */
7714 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7718 case dw_val_class_die_ref
:
7719 if (AT_ref_external (a
))
7721 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7722 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7723 is sized by target address length, whereas in DWARF3
7724 it's always sized as an offset. */
7725 if (use_debug_types
)
7726 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7727 else if (dwarf_version
== 2)
7728 size
+= DWARF2_ADDR_SIZE
;
7730 size
+= DWARF_OFFSET_SIZE
;
7733 size
+= DWARF_OFFSET_SIZE
;
7735 case dw_val_class_fde_ref
:
7736 size
+= DWARF_OFFSET_SIZE
;
7738 case dw_val_class_lbl_id
:
7739 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7741 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7742 size
+= size_of_uleb128 (AT_index (a
));
7745 size
+= DWARF2_ADDR_SIZE
;
7747 case dw_val_class_lineptr
:
7748 case dw_val_class_macptr
:
7749 size
+= DWARF_OFFSET_SIZE
;
7751 case dw_val_class_str
:
7752 form
= AT_string_form (a
);
7753 if (form
== DW_FORM_strp
)
7754 size
+= DWARF_OFFSET_SIZE
;
7755 else if (form
== DW_FORM_GNU_str_index
)
7756 size
+= size_of_uleb128 (AT_index (a
));
7758 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7760 case dw_val_class_file
:
7761 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7763 case dw_val_class_data8
:
7766 case dw_val_class_vms_delta
:
7767 size
+= DWARF_OFFSET_SIZE
;
7769 case dw_val_class_high_pc
:
7770 size
+= DWARF2_ADDR_SIZE
;
7780 /* Size the debugging information associated with a given DIE. Visits the
7781 DIE's children recursively. Updates the global variable next_die_offset, on
7782 each time through. Uses the current value of next_die_offset to update the
7783 die_offset field in each DIE. */
7786 calc_die_sizes (dw_die_ref die
)
7790 gcc_assert (die
->die_offset
== 0
7791 || (unsigned long int) die
->die_offset
== next_die_offset
);
7792 die
->die_offset
= next_die_offset
;
7793 next_die_offset
+= size_of_die (die
);
7795 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7797 if (die
->die_child
!= NULL
)
7798 /* Count the null byte used to terminate sibling lists. */
7799 next_die_offset
+= 1;
7802 /* Size just the base type children at the start of the CU.
7803 This is needed because build_abbrev needs to size locs
7804 and sizing of type based stack ops needs to know die_offset
7805 values for the base types. */
7808 calc_base_type_die_sizes (void)
7810 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7812 dw_die_ref base_type
;
7813 #if ENABLE_ASSERT_CHECKING
7814 dw_die_ref prev
= comp_unit_die ()->die_child
;
7817 die_offset
+= size_of_die (comp_unit_die ());
7818 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7820 #if ENABLE_ASSERT_CHECKING
7821 gcc_assert (base_type
->die_offset
== 0
7822 && prev
->die_sib
== base_type
7823 && base_type
->die_child
== NULL
7824 && base_type
->die_abbrev
);
7827 base_type
->die_offset
= die_offset
;
7828 die_offset
+= size_of_die (base_type
);
7832 /* Set the marks for a die and its children. We do this so
7833 that we know whether or not a reference needs to use FORM_ref_addr; only
7834 DIEs in the same CU will be marked. We used to clear out the offset
7835 and use that as the flag, but ran into ordering problems. */
7838 mark_dies (dw_die_ref die
)
7842 gcc_assert (!die
->die_mark
);
7845 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7848 /* Clear the marks for a die and its children. */
7851 unmark_dies (dw_die_ref die
)
7855 if (! use_debug_types
)
7856 gcc_assert (die
->die_mark
);
7859 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7862 /* Clear the marks for a die, its children and referred dies. */
7865 unmark_all_dies (dw_die_ref die
)
7875 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7877 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7878 if (AT_class (a
) == dw_val_class_die_ref
)
7879 unmark_all_dies (AT_ref (a
));
7882 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7883 generated for the compilation unit. */
7885 static unsigned long
7886 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7892 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7893 FOR_EACH_VEC_ELT (*names
, i
, p
)
7894 if (names
!= pubtype_table
7895 || p
->die
->die_offset
!= 0
7896 || !flag_eliminate_unused_debug_types
)
7897 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7899 size
+= DWARF_OFFSET_SIZE
;
7903 /* Return the size of the information in the .debug_aranges section. */
7905 static unsigned long
7906 size_of_aranges (void)
7910 size
= DWARF_ARANGES_HEADER_SIZE
;
7912 /* Count the address/length pair for this compilation unit. */
7913 if (text_section_used
)
7914 size
+= 2 * DWARF2_ADDR_SIZE
;
7915 if (cold_text_section_used
)
7916 size
+= 2 * DWARF2_ADDR_SIZE
;
7917 if (have_multiple_function_sections
)
7922 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
7924 if (DECL_IGNORED_P (fde
->decl
))
7926 if (!fde
->in_std_section
)
7927 size
+= 2 * DWARF2_ADDR_SIZE
;
7928 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7929 size
+= 2 * DWARF2_ADDR_SIZE
;
7933 /* Count the two zero words used to terminated the address range table. */
7934 size
+= 2 * DWARF2_ADDR_SIZE
;
7938 /* Select the encoding of an attribute value. */
7940 static enum dwarf_form
7941 value_format (dw_attr_ref a
)
7943 switch (AT_class (a
))
7945 case dw_val_class_addr
:
7946 /* Only very few attributes allow DW_FORM_addr. */
7951 case DW_AT_entry_pc
:
7952 case DW_AT_trampoline
:
7953 return (AT_index (a
) == NOT_INDEXED
7954 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7958 switch (DWARF2_ADDR_SIZE
)
7961 return DW_FORM_data1
;
7963 return DW_FORM_data2
;
7965 return DW_FORM_data4
;
7967 return DW_FORM_data8
;
7971 case dw_val_class_range_list
:
7972 case dw_val_class_loc_list
:
7973 if (dwarf_version
>= 4)
7974 return DW_FORM_sec_offset
;
7976 case dw_val_class_vms_delta
:
7977 case dw_val_class_offset
:
7978 switch (DWARF_OFFSET_SIZE
)
7981 return DW_FORM_data4
;
7983 return DW_FORM_data8
;
7987 case dw_val_class_loc
:
7988 if (dwarf_version
>= 4)
7989 return DW_FORM_exprloc
;
7990 switch (constant_size (size_of_locs (AT_loc (a
))))
7993 return DW_FORM_block1
;
7995 return DW_FORM_block2
;
7997 return DW_FORM_block4
;
8001 case dw_val_class_const
:
8002 return DW_FORM_sdata
;
8003 case dw_val_class_unsigned_const
:
8004 switch (constant_size (AT_unsigned (a
)))
8007 return DW_FORM_data1
;
8009 return DW_FORM_data2
;
8011 /* In DWARF3 DW_AT_data_member_location with
8012 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8013 constant, so we need to use DW_FORM_udata if we need
8014 a large constant. */
8015 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8016 return DW_FORM_udata
;
8017 return DW_FORM_data4
;
8019 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8020 return DW_FORM_udata
;
8021 return DW_FORM_data8
;
8025 case dw_val_class_const_double
:
8026 switch (HOST_BITS_PER_WIDE_INT
)
8029 return DW_FORM_data2
;
8031 return DW_FORM_data4
;
8033 return DW_FORM_data8
;
8036 return DW_FORM_block1
;
8038 case dw_val_class_vec
:
8039 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8040 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8043 return DW_FORM_block1
;
8045 return DW_FORM_block2
;
8047 return DW_FORM_block4
;
8051 case dw_val_class_flag
:
8052 if (dwarf_version
>= 4)
8054 /* Currently all add_AT_flag calls pass in 1 as last argument,
8055 so DW_FORM_flag_present can be used. If that ever changes,
8056 we'll need to use DW_FORM_flag and have some optimization
8057 in build_abbrev_table that will change those to
8058 DW_FORM_flag_present if it is set to 1 in all DIEs using
8059 the same abbrev entry. */
8060 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8061 return DW_FORM_flag_present
;
8063 return DW_FORM_flag
;
8064 case dw_val_class_die_ref
:
8065 if (AT_ref_external (a
))
8066 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8069 case dw_val_class_fde_ref
:
8070 return DW_FORM_data
;
8071 case dw_val_class_lbl_id
:
8072 return (AT_index (a
) == NOT_INDEXED
8073 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8074 case dw_val_class_lineptr
:
8075 case dw_val_class_macptr
:
8076 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8077 case dw_val_class_str
:
8078 return AT_string_form (a
);
8079 case dw_val_class_file
:
8080 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8083 return DW_FORM_data1
;
8085 return DW_FORM_data2
;
8087 return DW_FORM_data4
;
8092 case dw_val_class_data8
:
8093 return DW_FORM_data8
;
8095 case dw_val_class_high_pc
:
8096 switch (DWARF2_ADDR_SIZE
)
8099 return DW_FORM_data1
;
8101 return DW_FORM_data2
;
8103 return DW_FORM_data4
;
8105 return DW_FORM_data8
;
8115 /* Output the encoding of an attribute value. */
8118 output_value_format (dw_attr_ref a
)
8120 enum dwarf_form form
= value_format (a
);
8122 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8125 /* Given a die and id, produce the appropriate abbreviations. */
8128 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8133 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8134 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8135 dwarf_tag_name (abbrev
->die_tag
));
8137 if (abbrev
->die_child
!= NULL
)
8138 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8140 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8142 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8144 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8145 dwarf_attr_name (a_attr
->dw_attr
));
8146 output_value_format (a_attr
);
8149 dw2_asm_output_data (1, 0, NULL
);
8150 dw2_asm_output_data (1, 0, NULL
);
8154 /* Output the .debug_abbrev section which defines the DIE abbreviation
8158 output_abbrev_section (void)
8160 unsigned long abbrev_id
;
8162 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8163 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8165 /* Terminate the table. */
8166 dw2_asm_output_data (1, 0, NULL
);
8169 /* Output a symbol we can use to refer to this DIE from another CU. */
8172 output_die_symbol (dw_die_ref die
)
8174 const char *sym
= die
->die_id
.die_symbol
;
8176 gcc_assert (!die
->comdat_type_p
);
8181 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8182 /* We make these global, not weak; if the target doesn't support
8183 .linkonce, it doesn't support combining the sections, so debugging
8185 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8187 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8190 /* Return a new location list, given the begin and end range, and the
8193 static inline dw_loc_list_ref
8194 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8195 const char *section
)
8197 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8199 retlist
->begin
= begin
;
8200 retlist
->begin_entry
= NULL
;
8202 retlist
->expr
= expr
;
8203 retlist
->section
= section
;
8208 /* Generate a new internal symbol for this location list node, if it
8209 hasn't got one yet. */
8212 gen_llsym (dw_loc_list_ref list
)
8214 gcc_assert (!list
->ll_symbol
);
8215 list
->ll_symbol
= gen_internal_sym ("LLST");
8218 /* Output the location list given to us. */
8221 output_loc_list (dw_loc_list_ref list_head
)
8223 dw_loc_list_ref curr
= list_head
;
8225 if (list_head
->emitted
)
8227 list_head
->emitted
= true;
8229 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8231 /* Walk the location list, and output each range + expression. */
8232 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8235 /* Don't output an entry that starts and ends at the same address. */
8236 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8238 size
= size_of_locs (curr
->expr
);
8239 /* If the expression is too large, drop it on the floor. We could
8240 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8241 in the expression, but >= 64KB expressions for a single value
8242 in a single range are unlikely very useful. */
8245 if (dwarf_split_debug_info
)
8247 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8248 "Location list start/length entry (%s)",
8249 list_head
->ll_symbol
);
8250 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8251 "Location list range start index (%s)",
8253 /* The length field is 4 bytes. If we ever need to support
8254 an 8-byte length, we can add a new DW_LLE code or fall back
8255 to DW_LLE_GNU_start_end_entry. */
8256 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8257 "Location list range length (%s)",
8258 list_head
->ll_symbol
);
8260 else if (!have_multiple_function_sections
)
8262 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8263 "Location list begin address (%s)",
8264 list_head
->ll_symbol
);
8265 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8266 "Location list end address (%s)",
8267 list_head
->ll_symbol
);
8271 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8272 "Location list begin address (%s)",
8273 list_head
->ll_symbol
);
8274 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8275 "Location list end address (%s)",
8276 list_head
->ll_symbol
);
8279 /* Output the block length for this list of location operations. */
8280 gcc_assert (size
<= 0xffff);
8281 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8283 output_loc_sequence (curr
->expr
, -1);
8286 if (dwarf_split_debug_info
)
8287 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8288 "Location list terminator (%s)",
8289 list_head
->ll_symbol
);
8292 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8293 "Location list terminator begin (%s)",
8294 list_head
->ll_symbol
);
8295 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8296 "Location list terminator end (%s)",
8297 list_head
->ll_symbol
);
8301 /* Output a range_list offset into the debug_range section. Emit a
8302 relocated reference if val_entry is NULL, otherwise, emit an
8303 indirect reference. */
8306 output_range_list_offset (dw_attr_ref a
)
8308 const char *name
= dwarf_attr_name (a
->dw_attr
);
8310 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8312 char *p
= strchr (ranges_section_label
, '\0');
8313 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8314 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8315 debug_ranges_section
, "%s", name
);
8319 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8320 "%s (offset from %s)", name
, ranges_section_label
);
8323 /* Output the offset into the debug_loc section. */
8326 output_loc_list_offset (dw_attr_ref a
)
8328 char *sym
= AT_loc_list (a
)->ll_symbol
;
8331 if (dwarf_split_debug_info
)
8332 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8333 "%s", dwarf_attr_name (a
->dw_attr
));
8335 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8336 "%s", dwarf_attr_name (a
->dw_attr
));
8339 /* Output an attribute's index or value appropriately. */
8342 output_attr_index_or_value (dw_attr_ref a
)
8344 const char *name
= dwarf_attr_name (a
->dw_attr
);
8346 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8348 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8351 switch (AT_class (a
))
8353 case dw_val_class_addr
:
8354 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8356 case dw_val_class_high_pc
:
8357 case dw_val_class_lbl_id
:
8358 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8360 case dw_val_class_loc_list
:
8361 output_loc_list_offset (a
);
8368 /* Output a type signature. */
8371 output_signature (const char *sig
, const char *name
)
8375 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8376 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8379 /* Output the DIE and its attributes. Called recursively to generate
8380 the definitions of each child DIE. */
8383 output_die (dw_die_ref die
)
8390 /* If someone in another CU might refer to us, set up a symbol for
8391 them to point to. */
8392 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8393 output_die_symbol (die
);
8395 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8396 (unsigned long)die
->die_offset
,
8397 dwarf_tag_name (die
->die_tag
));
8399 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8401 const char *name
= dwarf_attr_name (a
->dw_attr
);
8403 switch (AT_class (a
))
8405 case dw_val_class_addr
:
8406 output_attr_index_or_value (a
);
8409 case dw_val_class_offset
:
8410 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8414 case dw_val_class_range_list
:
8415 output_range_list_offset (a
);
8418 case dw_val_class_loc
:
8419 size
= size_of_locs (AT_loc (a
));
8421 /* Output the block length for this list of location operations. */
8422 if (dwarf_version
>= 4)
8423 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8425 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8427 output_loc_sequence (AT_loc (a
), -1);
8430 case dw_val_class_const
:
8431 /* ??? It would be slightly more efficient to use a scheme like is
8432 used for unsigned constants below, but gdb 4.x does not sign
8433 extend. Gdb 5.x does sign extend. */
8434 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8437 case dw_val_class_unsigned_const
:
8439 int csize
= constant_size (AT_unsigned (a
));
8440 if (dwarf_version
== 3
8441 && a
->dw_attr
== DW_AT_data_member_location
8443 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8445 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8449 case dw_val_class_const_double
:
8451 unsigned HOST_WIDE_INT first
, second
;
8453 if (HOST_BITS_PER_WIDE_INT
>= 64)
8454 dw2_asm_output_data (1,
8455 HOST_BITS_PER_DOUBLE_INT
8456 / HOST_BITS_PER_CHAR
,
8459 if (WORDS_BIG_ENDIAN
)
8461 first
= a
->dw_attr_val
.v
.val_double
.high
;
8462 second
= a
->dw_attr_val
.v
.val_double
.low
;
8466 first
= a
->dw_attr_val
.v
.val_double
.low
;
8467 second
= a
->dw_attr_val
.v
.val_double
.high
;
8470 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8472 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8477 case dw_val_class_vec
:
8479 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8480 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8484 dw2_asm_output_data (constant_size (len
* elt_size
),
8485 len
* elt_size
, "%s", name
);
8486 if (elt_size
> sizeof (HOST_WIDE_INT
))
8491 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8494 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8495 "fp or vector constant word %u", i
);
8499 case dw_val_class_flag
:
8500 if (dwarf_version
>= 4)
8502 /* Currently all add_AT_flag calls pass in 1 as last argument,
8503 so DW_FORM_flag_present can be used. If that ever changes,
8504 we'll need to use DW_FORM_flag and have some optimization
8505 in build_abbrev_table that will change those to
8506 DW_FORM_flag_present if it is set to 1 in all DIEs using
8507 the same abbrev entry. */
8508 gcc_assert (AT_flag (a
) == 1);
8510 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8511 ASM_COMMENT_START
, name
);
8514 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8517 case dw_val_class_loc_list
:
8518 output_attr_index_or_value (a
);
8521 case dw_val_class_die_ref
:
8522 if (AT_ref_external (a
))
8524 if (AT_ref (a
)->comdat_type_p
)
8526 comdat_type_node_ref type_node
=
8527 AT_ref (a
)->die_id
.die_type_node
;
8529 gcc_assert (type_node
);
8530 output_signature (type_node
->signature
, name
);
8534 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8538 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8539 length, whereas in DWARF3 it's always sized as an
8541 if (dwarf_version
== 2)
8542 size
= DWARF2_ADDR_SIZE
;
8544 size
= DWARF_OFFSET_SIZE
;
8545 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8551 gcc_assert (AT_ref (a
)->die_offset
);
8552 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8557 case dw_val_class_fde_ref
:
8561 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8562 a
->dw_attr_val
.v
.val_fde_index
* 2);
8563 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8568 case dw_val_class_vms_delta
:
8569 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8570 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8574 case dw_val_class_lbl_id
:
8575 output_attr_index_or_value (a
);
8578 case dw_val_class_lineptr
:
8579 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8580 debug_line_section
, "%s", name
);
8583 case dw_val_class_macptr
:
8584 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8585 debug_macinfo_section
, "%s", name
);
8588 case dw_val_class_str
:
8589 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8590 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8591 a
->dw_attr_val
.v
.val_str
->label
,
8593 "%s: \"%s\"", name
, AT_string (a
));
8594 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8595 dw2_asm_output_data_uleb128 (AT_index (a
),
8596 "%s: \"%s\"", name
, AT_string (a
));
8598 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8601 case dw_val_class_file
:
8603 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8605 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8606 a
->dw_attr_val
.v
.val_file
->filename
);
8610 case dw_val_class_data8
:
8614 for (i
= 0; i
< 8; i
++)
8615 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8616 i
== 0 ? "%s" : NULL
, name
);
8620 case dw_val_class_high_pc
:
8621 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8622 get_AT_low_pc (die
), "DW_AT_high_pc");
8630 FOR_EACH_CHILD (die
, c
, output_die (c
));
8632 /* Add null byte to terminate sibling list. */
8633 if (die
->die_child
!= NULL
)
8634 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8635 (unsigned long) die
->die_offset
);
8638 /* Output the compilation unit that appears at the beginning of the
8639 .debug_info section, and precedes the DIE descriptions. */
8642 output_compilation_unit_header (void)
8644 int ver
= dwarf_version
;
8646 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8647 dw2_asm_output_data (4, 0xffffffff,
8648 "Initial length escape value indicating 64-bit DWARF extension");
8649 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8650 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8651 "Length of Compilation Unit Info");
8652 dw2_asm_output_data (2, ver
, "DWARF version number");
8653 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8654 debug_abbrev_section
,
8655 "Offset Into Abbrev. Section");
8656 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8659 /* Output the compilation unit DIE and its children. */
8662 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8664 const char *secname
, *oldsym
;
8666 external_ref_hash_type extern_map
;
8668 /* Unless we are outputting main CU, we may throw away empty ones. */
8669 if (!output_if_empty
&& die
->die_child
== NULL
)
8672 /* Even if there are no children of this DIE, we must output the information
8673 about the compilation unit. Otherwise, on an empty translation unit, we
8674 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8675 will then complain when examining the file. First mark all the DIEs in
8676 this CU so we know which get local refs. */
8679 extern_map
= optimize_external_refs (die
);
8681 build_abbrev_table (die
, extern_map
);
8683 extern_map
.dispose ();
8685 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8686 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8687 calc_die_sizes (die
);
8689 oldsym
= die
->die_id
.die_symbol
;
8692 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8694 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8696 die
->die_id
.die_symbol
= NULL
;
8697 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8701 switch_to_section (debug_info_section
);
8702 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8703 info_section_emitted
= true;
8706 /* Output debugging information. */
8707 output_compilation_unit_header ();
8710 /* Leave the marks on the main CU, so we can check them in
8715 die
->die_id
.die_symbol
= oldsym
;
8719 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8720 and .debug_pubtypes. This is configured per-target, but can be
8721 overridden by the -gpubnames or -gno-pubnames options. */
8724 want_pubnames (void)
8726 return (debug_generate_pub_sections
!= -1
8727 ? debug_generate_pub_sections
8728 : targetm
.want_debug_pub_sections
);
8731 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8734 add_AT_pubnames (dw_die_ref die
)
8736 if (want_pubnames ())
8737 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8740 /* Add a string attribute value to a skeleton DIE. */
8743 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8747 struct indirect_string_node
*node
;
8749 if (! skeleton_debug_str_hash
)
8750 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8751 debug_str_eq
, NULL
);
8753 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8754 find_string_form (node
);
8755 if (node
->form
== DW_FORM_GNU_str_index
)
8756 node
->form
= DW_FORM_strp
;
8758 attr
.dw_attr
= attr_kind
;
8759 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8760 attr
.dw_attr_val
.val_entry
= NULL
;
8761 attr
.dw_attr_val
.v
.val_str
= node
;
8762 add_dwarf_attr (die
, &attr
);
8765 /* Helper function to generate top-level dies for skeleton debug_info and
8769 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8771 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8772 const char *comp_dir
= comp_dir_string ();
8774 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8775 if (comp_dir
!= NULL
)
8776 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8777 add_AT_pubnames (die
);
8778 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8781 /* Return the single type-unit die for skeleton type units. */
8784 get_skeleton_type_unit (void)
8786 /* For dwarf_split_debug_sections with use_type info, all type units in the
8787 skeleton sections have identical dies (but different headers). This
8788 single die will be output many times. */
8790 static dw_die_ref skeleton_type_unit
= NULL
;
8792 if (skeleton_type_unit
== NULL
)
8794 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8795 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8796 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8798 return skeleton_type_unit
;
8801 /* Output skeleton debug sections that point to the dwo file. */
8804 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8806 /* These attributes will be found in the full debug_info section. */
8807 remove_AT (comp_unit
, DW_AT_producer
);
8808 remove_AT (comp_unit
, DW_AT_language
);
8810 switch_to_section (debug_skeleton_info_section
);
8811 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8813 /* Produce the skeleton compilation-unit header. This one differs enough from
8814 a normal CU header that it's better not to call output_compilation_unit
8816 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8817 dw2_asm_output_data (4, 0xffffffff,
8818 "Initial length escape value indicating 64-bit DWARF extension");
8820 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8821 DWARF_COMPILE_UNIT_HEADER_SIZE
8822 - DWARF_INITIAL_LENGTH_SIZE
8823 + size_of_die (comp_unit
),
8824 "Length of Compilation Unit Info");
8825 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8826 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8827 debug_abbrev_section
,
8828 "Offset Into Abbrev. Section");
8829 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8831 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8832 output_die (comp_unit
);
8834 /* Build the skeleton debug_abbrev section. */
8835 switch_to_section (debug_skeleton_abbrev_section
);
8836 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8838 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8839 if (use_debug_types
)
8840 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8842 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8845 /* Output a comdat type unit DIE and its children. */
8848 output_comdat_type_unit (comdat_type_node
*node
)
8850 const char *secname
;
8853 #if defined (OBJECT_FORMAT_ELF)
8856 external_ref_hash_type extern_map
;
8858 /* First mark all the DIEs in this CU so we know which get local refs. */
8859 mark_dies (node
->root_die
);
8861 extern_map
= optimize_external_refs (node
->root_die
);
8863 build_abbrev_table (node
->root_die
, extern_map
);
8865 extern_map
.dispose ();
8867 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8868 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8869 calc_die_sizes (node
->root_die
);
8871 #if defined (OBJECT_FORMAT_ELF)
8872 if (!dwarf_split_debug_info
)
8873 secname
= ".debug_types";
8875 secname
= ".debug_types.dwo";
8877 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8878 sprintf (tmp
, "wt.");
8879 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8880 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8881 comdat_key
= get_identifier (tmp
);
8882 targetm
.asm_out
.named_section (secname
,
8883 SECTION_DEBUG
| SECTION_LINKONCE
,
8886 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8887 sprintf (tmp
, ".gnu.linkonce.wt.");
8888 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8889 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8891 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8894 /* Output debugging information. */
8895 output_compilation_unit_header ();
8896 output_signature (node
->signature
, "Type Signature");
8897 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8898 "Offset to Type DIE");
8899 output_die (node
->root_die
);
8901 unmark_dies (node
->root_die
);
8903 #if defined (OBJECT_FORMAT_ELF)
8904 if (dwarf_split_debug_info
)
8906 /* Produce the skeleton type-unit header. */
8907 const char *secname
= ".debug_types";
8909 targetm
.asm_out
.named_section (secname
,
8910 SECTION_DEBUG
| SECTION_LINKONCE
,
8912 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8913 dw2_asm_output_data (4, 0xffffffff,
8914 "Initial length escape value indicating 64-bit DWARF extension");
8916 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8917 DWARF_COMPILE_UNIT_HEADER_SIZE
8918 - DWARF_INITIAL_LENGTH_SIZE
8919 + size_of_die (get_skeleton_type_unit ())
8920 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
8921 "Length of Type Unit Info");
8922 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8923 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8924 debug_skeleton_abbrev_section_label
,
8925 debug_abbrev_section
,
8926 "Offset Into Abbrev. Section");
8927 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8928 output_signature (node
->signature
, "Type Signature");
8929 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
8931 output_die (get_skeleton_type_unit ());
8936 /* Return the DWARF2/3 pubname associated with a decl. */
8939 dwarf2_name (tree decl
, int scope
)
8941 if (DECL_NAMELESS (decl
))
8943 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8946 /* Add a new entry to .debug_pubnames if appropriate. */
8949 add_pubname_string (const char *str
, dw_die_ref die
)
8954 e
.name
= xstrdup (str
);
8955 vec_safe_push (pubname_table
, e
);
8959 add_pubname (tree decl
, dw_die_ref die
)
8961 if (!want_pubnames ())
8964 /* Don't add items to the table when we expect that the consumer will have
8965 just read the enclosing die. For example, if the consumer is looking at a
8966 class_member, it will either be inside the class already, or will have just
8967 looked up the class to find the member. Either way, searching the class is
8968 faster than searching the index. */
8969 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
8970 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8972 const char *name
= dwarf2_name (decl
, 1);
8975 add_pubname_string (name
, die
);
8979 /* Add an enumerator to the pubnames section. */
8982 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8986 gcc_assert (scope_name
);
8987 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8989 vec_safe_push (pubname_table
, e
);
8992 /* Add a new entry to .debug_pubtypes if appropriate. */
8995 add_pubtype (tree decl
, dw_die_ref die
)
8999 if (!want_pubnames ())
9002 if ((TREE_PUBLIC (decl
)
9003 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9004 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9007 const char *scope_name
= "";
9008 const char *sep
= is_cxx () ? "::" : ".";
9011 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9012 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9014 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9015 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9016 scope_name
= concat (scope_name
, sep
, NULL
);
9022 name
= type_tag (decl
);
9024 name
= lang_hooks
.dwarf_name (decl
, 1);
9026 /* If we don't have a name for the type, there's no point in adding
9028 if (name
!= NULL
&& name
[0] != '\0')
9031 e
.name
= concat (scope_name
, name
, NULL
);
9032 vec_safe_push (pubtype_table
, e
);
9035 /* Although it might be more consistent to add the pubinfo for the
9036 enumerators as their dies are created, they should only be added if the
9037 enum type meets the criteria above. So rather than re-check the parent
9038 enum type whenever an enumerator die is created, just output them all
9039 here. This isn't protected by the name conditional because anonymous
9040 enums don't have names. */
9041 if (die
->die_tag
== DW_TAG_enumeration_type
)
9045 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9050 /* Output the public names table used to speed up access to externally
9051 visible names; or the public types table used to find type definitions. */
9054 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9057 unsigned long pubnames_length
= size_of_pubnames (names
);
9060 if (!want_pubnames () || !info_section_emitted
)
9062 if (names
== pubname_table
)
9063 switch_to_section (debug_pubnames_section
);
9065 switch_to_section (debug_pubtypes_section
);
9066 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9067 dw2_asm_output_data (4, 0xffffffff,
9068 "Initial length escape value indicating 64-bit DWARF extension");
9069 if (names
== pubname_table
)
9070 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9071 "Length of Public Names Info");
9073 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9074 "Length of Public Type Names Info");
9075 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9076 dw2_asm_output_data (2, 2, "DWARF Version");
9077 if (dwarf_split_debug_info
)
9078 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9079 debug_skeleton_info_section
,
9080 "Offset of Compilation Unit Info");
9082 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9084 "Offset of Compilation Unit Info");
9085 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9086 "Compilation Unit Length");
9088 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9090 /* Enumerator names are part of the pubname table, but the parent
9091 DW_TAG_enumeration_type die may have been pruned. Don't output
9092 them if that is the case. */
9093 if (pub
->die
->die_tag
== DW_TAG_enumerator
&&
9094 (pub
->die
->die_parent
== NULL
9095 || !pub
->die
->die_parent
->die_perennial_p
))
9098 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9099 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9100 gcc_assert (pub
->die
->die_mark
);
9102 if (names
!= pubtype_table
9103 || pub
->die
->die_offset
!= 0
9104 || !flag_eliminate_unused_debug_types
)
9106 dw_offset die_offset
= pub
->die
->die_offset
;
9108 /* If we're putting types in their own .debug_types sections,
9109 the .debug_pubtypes table will still point to the compile
9110 unit (not the type unit), so we want to use the offset of
9111 the skeleton DIE (if there is one). */
9112 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9114 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9116 if (type_node
!= NULL
)
9117 die_offset
= (type_node
->skeleton_die
!= NULL
9118 ? type_node
->skeleton_die
->die_offset
9122 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9124 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9128 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9131 /* Output the information that goes into the .debug_aranges table.
9132 Namely, define the beginning and ending address range of the
9133 text section generated for this compilation unit. */
9136 output_aranges (unsigned long aranges_length
)
9140 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9141 dw2_asm_output_data (4, 0xffffffff,
9142 "Initial length escape value indicating 64-bit DWARF extension");
9143 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9144 "Length of Address Ranges Info");
9145 /* Version number for aranges is still 2, even in DWARF3. */
9146 dw2_asm_output_data (2, 2, "DWARF Version");
9147 if (dwarf_split_debug_info
)
9148 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9149 debug_skeleton_info_section
,
9150 "Offset of Compilation Unit Info");
9152 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9154 "Offset of Compilation Unit Info");
9155 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9156 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9158 /* We need to align to twice the pointer size here. */
9159 if (DWARF_ARANGES_PAD_SIZE
)
9161 /* Pad using a 2 byte words so that padding is correct for any
9163 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9164 2 * DWARF2_ADDR_SIZE
);
9165 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9166 dw2_asm_output_data (2, 0, NULL
);
9169 /* It is necessary not to output these entries if the sections were
9170 not used; if the sections were not used, the length will be 0 and
9171 the address may end up as 0 if the section is discarded by ld
9172 --gc-sections, leaving an invalid (0, 0) entry that can be
9173 confused with the terminator. */
9174 if (text_section_used
)
9176 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9177 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9178 text_section_label
, "Length");
9180 if (cold_text_section_used
)
9182 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9184 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9185 cold_text_section_label
, "Length");
9188 if (have_multiple_function_sections
)
9193 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9195 if (DECL_IGNORED_P (fde
->decl
))
9197 if (!fde
->in_std_section
)
9199 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9201 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9202 fde
->dw_fde_begin
, "Length");
9204 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9206 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9208 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9209 fde
->dw_fde_second_begin
, "Length");
9214 /* Output the terminator words. */
9215 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9216 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9219 /* Add a new entry to .debug_ranges. Return the offset at which it
9223 add_ranges_num (int num
)
9225 unsigned int in_use
= ranges_table_in_use
;
9227 if (in_use
== ranges_table_allocated
)
9229 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9230 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9231 ranges_table_allocated
);
9232 memset (ranges_table
+ ranges_table_in_use
, 0,
9233 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9236 ranges_table
[in_use
].num
= num
;
9237 ranges_table_in_use
= in_use
+ 1;
9239 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9242 /* Add a new entry to .debug_ranges corresponding to a block, or a
9243 range terminator if BLOCK is NULL. */
9246 add_ranges (const_tree block
)
9248 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9251 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9252 When using dwarf_split_debug_info, address attributes in dies destined
9253 for the final executable should be direct references--setting the
9254 parameter force_direct ensures this behavior. */
9257 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9258 bool *added
, bool force_direct
)
9260 unsigned int in_use
= ranges_by_label_in_use
;
9261 unsigned int offset
;
9263 if (in_use
== ranges_by_label_allocated
)
9265 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9266 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9268 ranges_by_label_allocated
);
9269 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9270 RANGES_TABLE_INCREMENT
9271 * sizeof (struct dw_ranges_by_label_struct
));
9274 ranges_by_label
[in_use
].begin
= begin
;
9275 ranges_by_label
[in_use
].end
= end
;
9276 ranges_by_label_in_use
= in_use
+ 1;
9278 offset
= add_ranges_num (-(int)in_use
- 1);
9281 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9287 output_ranges (void)
9290 static const char *const start_fmt
= "Offset %#x";
9291 const char *fmt
= start_fmt
;
9293 for (i
= 0; i
< ranges_table_in_use
; i
++)
9295 int block_num
= ranges_table
[i
].num
;
9299 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9300 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9302 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9303 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9305 /* If all code is in the text section, then the compilation
9306 unit base address defaults to DW_AT_low_pc, which is the
9307 base of the text section. */
9308 if (!have_multiple_function_sections
)
9310 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9312 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9313 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9314 text_section_label
, NULL
);
9317 /* Otherwise, the compilation unit base address is zero,
9318 which allows us to use absolute addresses, and not worry
9319 about whether the target supports cross-section
9323 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9324 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9325 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9331 /* Negative block_num stands for an index into ranges_by_label. */
9332 else if (block_num
< 0)
9334 int lab_idx
= - block_num
- 1;
9336 if (!have_multiple_function_sections
)
9340 /* If we ever use add_ranges_by_labels () for a single
9341 function section, all we have to do is to take out
9343 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9344 ranges_by_label
[lab_idx
].begin
,
9346 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9347 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9348 ranges_by_label
[lab_idx
].end
,
9349 text_section_label
, NULL
);
9354 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9355 ranges_by_label
[lab_idx
].begin
,
9356 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9357 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9358 ranges_by_label
[lab_idx
].end
,
9364 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9365 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9371 /* Data structure containing information about input files. */
9374 const char *path
; /* Complete file name. */
9375 const char *fname
; /* File name part. */
9376 int length
; /* Length of entire string. */
9377 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9378 int dir_idx
; /* Index in directory table. */
9381 /* Data structure containing information about directories with source
9385 const char *path
; /* Path including directory name. */
9386 int length
; /* Path length. */
9387 int prefix
; /* Index of directory entry which is a prefix. */
9388 int count
; /* Number of files in this directory. */
9389 int dir_idx
; /* Index of directory used as base. */
9392 /* Callback function for file_info comparison. We sort by looking at
9393 the directories in the path. */
9396 file_info_cmp (const void *p1
, const void *p2
)
9398 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9399 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9400 const unsigned char *cp1
;
9401 const unsigned char *cp2
;
9403 /* Take care of file names without directories. We need to make sure that
9404 we return consistent values to qsort since some will get confused if
9405 we return the same value when identical operands are passed in opposite
9406 orders. So if neither has a directory, return 0 and otherwise return
9407 1 or -1 depending on which one has the directory. */
9408 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9409 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9411 cp1
= (const unsigned char *) s1
->path
;
9412 cp2
= (const unsigned char *) s2
->path
;
9418 /* Reached the end of the first path? If so, handle like above. */
9419 if ((cp1
== (const unsigned char *) s1
->fname
)
9420 || (cp2
== (const unsigned char *) s2
->fname
))
9421 return ((cp2
== (const unsigned char *) s2
->fname
)
9422 - (cp1
== (const unsigned char *) s1
->fname
));
9424 /* Character of current path component the same? */
9425 else if (*cp1
!= *cp2
)
9430 struct file_name_acquire_data
9432 struct file_info
*files
;
9437 /* Traversal function for the hash table. */
9440 file_name_acquire (void ** slot
, void *data
)
9442 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9443 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9444 struct file_info
*fi
;
9447 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9449 if (! d
->emitted_number
)
9452 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9454 fi
= fnad
->files
+ fnad
->used_files
++;
9456 /* Skip all leading "./". */
9458 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9461 /* Create a new array entry. */
9463 fi
->length
= strlen (f
);
9466 /* Search for the file name part. */
9467 f
= strrchr (f
, DIR_SEPARATOR
);
9468 #if defined (DIR_SEPARATOR_2)
9470 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9474 if (f
== NULL
|| f
< g
)
9480 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9484 /* Output the directory table and the file name table. We try to minimize
9485 the total amount of memory needed. A heuristic is used to avoid large
9486 slowdowns with many input files. */
9489 output_file_names (void)
9491 struct file_name_acquire_data fnad
;
9493 struct file_info
*files
;
9494 struct dir_info
*dirs
;
9502 if (!last_emitted_file
)
9504 dw2_asm_output_data (1, 0, "End directory table");
9505 dw2_asm_output_data (1, 0, "End file name table");
9509 numfiles
= last_emitted_file
->emitted_number
;
9511 /* Allocate the various arrays we need. */
9512 files
= XALLOCAVEC (struct file_info
, numfiles
);
9513 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9516 fnad
.used_files
= 0;
9517 fnad
.max_files
= numfiles
;
9518 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9519 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9521 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9523 /* Find all the different directories used. */
9524 dirs
[0].path
= files
[0].path
;
9525 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9526 dirs
[0].prefix
= -1;
9528 dirs
[0].dir_idx
= 0;
9529 files
[0].dir_idx
= 0;
9532 for (i
= 1; i
< numfiles
; i
++)
9533 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9534 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9535 dirs
[ndirs
- 1].length
) == 0)
9537 /* Same directory as last entry. */
9538 files
[i
].dir_idx
= ndirs
- 1;
9539 ++dirs
[ndirs
- 1].count
;
9545 /* This is a new directory. */
9546 dirs
[ndirs
].path
= files
[i
].path
;
9547 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9548 dirs
[ndirs
].count
= 1;
9549 dirs
[ndirs
].dir_idx
= ndirs
;
9550 files
[i
].dir_idx
= ndirs
;
9552 /* Search for a prefix. */
9553 dirs
[ndirs
].prefix
= -1;
9554 for (j
= 0; j
< ndirs
; j
++)
9555 if (dirs
[j
].length
< dirs
[ndirs
].length
9556 && dirs
[j
].length
> 1
9557 && (dirs
[ndirs
].prefix
== -1
9558 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9559 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9560 dirs
[ndirs
].prefix
= j
;
9565 /* Now to the actual work. We have to find a subset of the directories which
9566 allow expressing the file name using references to the directory table
9567 with the least amount of characters. We do not do an exhaustive search
9568 where we would have to check out every combination of every single
9569 possible prefix. Instead we use a heuristic which provides nearly optimal
9570 results in most cases and never is much off. */
9571 saved
= XALLOCAVEC (int, ndirs
);
9572 savehere
= XALLOCAVEC (int, ndirs
);
9574 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9575 for (i
= 0; i
< ndirs
; i
++)
9580 /* We can always save some space for the current directory. But this
9581 does not mean it will be enough to justify adding the directory. */
9582 savehere
[i
] = dirs
[i
].length
;
9583 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9585 for (j
= i
+ 1; j
< ndirs
; j
++)
9588 if (saved
[j
] < dirs
[i
].length
)
9590 /* Determine whether the dirs[i] path is a prefix of the
9595 while (k
!= -1 && k
!= (int) i
)
9600 /* Yes it is. We can possibly save some memory by
9601 writing the filenames in dirs[j] relative to
9603 savehere
[j
] = dirs
[i
].length
;
9604 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9609 /* Check whether we can save enough to justify adding the dirs[i]
9611 if (total
> dirs
[i
].length
+ 1)
9613 /* It's worthwhile adding. */
9614 for (j
= i
; j
< ndirs
; j
++)
9615 if (savehere
[j
] > 0)
9617 /* Remember how much we saved for this directory so far. */
9618 saved
[j
] = savehere
[j
];
9620 /* Remember the prefix directory. */
9621 dirs
[j
].dir_idx
= i
;
9626 /* Emit the directory name table. */
9627 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9628 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9629 dw2_asm_output_nstring (dirs
[i
].path
,
9631 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9632 "Directory Entry: %#x", i
+ idx_offset
);
9634 dw2_asm_output_data (1, 0, "End directory table");
9636 /* We have to emit them in the order of emitted_number since that's
9637 used in the debug info generation. To do this efficiently we
9638 generate a back-mapping of the indices first. */
9639 backmap
= XALLOCAVEC (int, numfiles
);
9640 for (i
= 0; i
< numfiles
; i
++)
9641 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9643 /* Now write all the file names. */
9644 for (i
= 0; i
< numfiles
; i
++)
9646 int file_idx
= backmap
[i
];
9647 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9649 #ifdef VMS_DEBUGGING_INFO
9650 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9652 /* Setting these fields can lead to debugger miscomparisons,
9653 but VMS Debug requires them to be set correctly. */
9658 int maxfilelen
= strlen (files
[file_idx
].path
)
9659 + dirs
[dir_idx
].length
9660 + MAX_VMS_VERSION_LEN
+ 1;
9661 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9663 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9664 snprintf (filebuf
, maxfilelen
, "%s;%d",
9665 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9667 dw2_asm_output_nstring
9668 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9670 /* Include directory index. */
9671 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9673 /* Modification time. */
9674 dw2_asm_output_data_uleb128
9675 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9679 /* File length in bytes. */
9680 dw2_asm_output_data_uleb128
9681 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9685 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9686 "File Entry: %#x", (unsigned) i
+ 1);
9688 /* Include directory index. */
9689 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9691 /* Modification time. */
9692 dw2_asm_output_data_uleb128 (0, NULL
);
9694 /* File length in bytes. */
9695 dw2_asm_output_data_uleb128 (0, NULL
);
9696 #endif /* VMS_DEBUGGING_INFO */
9699 dw2_asm_output_data (1, 0, "End file name table");
9703 /* Output one line number table into the .debug_line section. */
9706 output_one_line_info_table (dw_line_info_table
*table
)
9708 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9709 unsigned int current_line
= 1;
9710 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9711 dw_line_info_entry
*ent
;
9714 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9716 switch (ent
->opcode
)
9718 case LI_set_address
:
9719 /* ??? Unfortunately, we have little choice here currently, and
9720 must always use the most general form. GCC does not know the
9721 address delta itself, so we can't use DW_LNS_advance_pc. Many
9722 ports do have length attributes which will give an upper bound
9723 on the address range. We could perhaps use length attributes
9724 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9725 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9727 /* This can handle any delta. This takes
9728 4+DWARF2_ADDR_SIZE bytes. */
9729 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9730 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9731 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9732 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9736 if (ent
->val
== current_line
)
9738 /* We still need to start a new row, so output a copy insn. */
9739 dw2_asm_output_data (1, DW_LNS_copy
,
9740 "copy line %u", current_line
);
9744 int line_offset
= ent
->val
- current_line
;
9745 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9747 current_line
= ent
->val
;
9748 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9750 /* This can handle deltas from -10 to 234, using the current
9751 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9752 This takes 1 byte. */
9753 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9754 "line %u", current_line
);
9758 /* This can handle any delta. This takes at least 4 bytes,
9759 depending on the value being encoded. */
9760 dw2_asm_output_data (1, DW_LNS_advance_line
,
9761 "advance to line %u", current_line
);
9762 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9763 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9769 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9770 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9774 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9775 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9778 case LI_negate_stmt
:
9779 current_is_stmt
= !current_is_stmt
;
9780 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9781 "is_stmt %d", current_is_stmt
);
9784 case LI_set_prologue_end
:
9785 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9786 "set prologue end");
9789 case LI_set_epilogue_begin
:
9790 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9791 "set epilogue begin");
9794 case LI_set_discriminator
:
9795 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9796 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9797 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9798 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9803 /* Emit debug info for the address of the end of the table. */
9804 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9805 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9806 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9807 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9809 dw2_asm_output_data (1, 0, "end sequence");
9810 dw2_asm_output_data_uleb128 (1, NULL
);
9811 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9814 /* Output the source line number correspondence information. This
9815 information goes into the .debug_line section. */
9818 output_line_info (bool prologue_only
)
9820 char l1
[20], l2
[20], p1
[20], p2
[20];
9821 int ver
= dwarf_version
;
9822 bool saw_one
= false;
9825 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9826 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9827 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9828 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9830 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9831 dw2_asm_output_data (4, 0xffffffff,
9832 "Initial length escape value indicating 64-bit DWARF extension");
9833 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9834 "Length of Source Line Info");
9835 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9837 dw2_asm_output_data (2, ver
, "DWARF Version");
9838 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9839 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9841 /* Define the architecture-dependent minimum instruction length (in bytes).
9842 In this implementation of DWARF, this field is used for information
9843 purposes only. Since GCC generates assembly language, we have no
9844 a priori knowledge of how many instruction bytes are generated for each
9845 source line, and therefore can use only the DW_LNE_set_address and
9846 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9847 this as '1', which is "correct enough" for all architectures,
9848 and don't let the target override. */
9849 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9852 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9853 "Maximum Operations Per Instruction");
9854 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9855 "Default is_stmt_start flag");
9856 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9857 "Line Base Value (Special Opcodes)");
9858 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9859 "Line Range Value (Special Opcodes)");
9860 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9861 "Special Opcode Base");
9863 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9868 case DW_LNS_advance_pc
:
9869 case DW_LNS_advance_line
:
9870 case DW_LNS_set_file
:
9871 case DW_LNS_set_column
:
9872 case DW_LNS_fixed_advance_pc
:
9873 case DW_LNS_set_isa
:
9881 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9885 /* Write out the information about the files we use. */
9886 output_file_names ();
9887 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9890 /* Output the marker for the end of the line number info. */
9891 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9895 if (separate_line_info
)
9897 dw_line_info_table
*table
;
9900 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9903 output_one_line_info_table (table
);
9907 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9909 output_one_line_info_table (cold_text_section_line_info
);
9913 /* ??? Some Darwin linkers crash on a .debug_line section with no
9914 sequences. Further, merely a DW_LNE_end_sequence entry is not
9915 sufficient -- the address column must also be initialized.
9916 Make sure to output at least one set_address/end_sequence pair,
9917 choosing .text since that section is always present. */
9918 if (text_section_line_info
->in_use
|| !saw_one
)
9919 output_one_line_info_table (text_section_line_info
);
9921 /* Output the marker for the end of the line number info. */
9922 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9925 /* Given a pointer to a tree node for some base type, return a pointer to
9926 a DIE that describes the given type.
9928 This routine must only be called for GCC type nodes that correspond to
9929 Dwarf base (fundamental) types. */
9932 base_type_die (tree type
)
9934 dw_die_ref base_type_result
;
9935 enum dwarf_type encoding
;
9937 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9940 /* If this is a subtype that should not be emitted as a subrange type,
9941 use the base type. See subrange_type_for_debug_p. */
9942 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9943 type
= TREE_TYPE (type
);
9945 switch (TREE_CODE (type
))
9948 if ((dwarf_version
>= 4 || !dwarf_strict
)
9950 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9951 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9952 && DECL_NAME (TYPE_NAME (type
)))
9954 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9955 if (strcmp (name
, "char16_t") == 0
9956 || strcmp (name
, "char32_t") == 0)
9958 encoding
= DW_ATE_UTF
;
9962 if (TYPE_STRING_FLAG (type
))
9964 if (TYPE_UNSIGNED (type
))
9965 encoding
= DW_ATE_unsigned_char
;
9967 encoding
= DW_ATE_signed_char
;
9969 else if (TYPE_UNSIGNED (type
))
9970 encoding
= DW_ATE_unsigned
;
9972 encoding
= DW_ATE_signed
;
9976 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9978 if (dwarf_version
>= 3 || !dwarf_strict
)
9979 encoding
= DW_ATE_decimal_float
;
9981 encoding
= DW_ATE_lo_user
;
9984 encoding
= DW_ATE_float
;
9987 case FIXED_POINT_TYPE
:
9988 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9989 encoding
= DW_ATE_lo_user
;
9990 else if (TYPE_UNSIGNED (type
))
9991 encoding
= DW_ATE_unsigned_fixed
;
9993 encoding
= DW_ATE_signed_fixed
;
9996 /* Dwarf2 doesn't know anything about complex ints, so use
9997 a user defined type for it. */
9999 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10000 encoding
= DW_ATE_complex_float
;
10002 encoding
= DW_ATE_lo_user
;
10006 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10007 encoding
= DW_ATE_boolean
;
10011 /* No other TREE_CODEs are Dwarf fundamental types. */
10012 gcc_unreachable ();
10015 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10017 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10018 int_size_in_bytes (type
));
10019 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10020 add_pubtype (type
, base_type_result
);
10022 return base_type_result
;
10025 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10026 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10029 is_base_type (tree type
)
10031 switch (TREE_CODE (type
))
10037 case FIXED_POINT_TYPE
:
10045 case QUAL_UNION_TYPE
:
10046 case ENUMERAL_TYPE
:
10047 case FUNCTION_TYPE
:
10050 case REFERENCE_TYPE
:
10058 gcc_unreachable ();
10064 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10065 node, return the size in bits for the type if it is a constant, or else
10066 return the alignment for the type if the type's size is not constant, or
10067 else return BITS_PER_WORD if the type actually turns out to be an
10068 ERROR_MARK node. */
10070 static inline unsigned HOST_WIDE_INT
10071 simple_type_size_in_bits (const_tree type
)
10073 if (TREE_CODE (type
) == ERROR_MARK
)
10074 return BITS_PER_WORD
;
10075 else if (TYPE_SIZE (type
) == NULL_TREE
)
10077 else if (host_integerp (TYPE_SIZE (type
), 1))
10078 return tree_low_cst (TYPE_SIZE (type
), 1);
10080 return TYPE_ALIGN (type
);
10083 /* Similarly, but return a double_int instead of UHWI. */
10085 static inline double_int
10086 double_int_type_size_in_bits (const_tree type
)
10088 if (TREE_CODE (type
) == ERROR_MARK
)
10089 return double_int::from_uhwi (BITS_PER_WORD
);
10090 else if (TYPE_SIZE (type
) == NULL_TREE
)
10091 return double_int_zero
;
10092 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10093 return tree_to_double_int (TYPE_SIZE (type
));
10095 return double_int::from_uhwi (TYPE_ALIGN (type
));
10098 /* Given a pointer to a tree node for a subrange type, return a pointer
10099 to a DIE that describes the given type. */
10102 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10104 dw_die_ref subrange_die
;
10105 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10107 if (context_die
== NULL
)
10108 context_die
= comp_unit_die ();
10110 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10112 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10114 /* The size of the subrange type and its base type do not match,
10115 so we need to generate a size attribute for the subrange type. */
10116 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10120 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10122 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10124 return subrange_die
;
10127 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10128 entry that chains various modifiers in front of the given type. */
10131 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10132 dw_die_ref context_die
)
10134 enum tree_code code
= TREE_CODE (type
);
10135 dw_die_ref mod_type_die
;
10136 dw_die_ref sub_die
= NULL
;
10137 tree item_type
= NULL
;
10138 tree qualified_type
;
10139 tree name
, low
, high
;
10140 dw_die_ref mod_scope
;
10142 if (code
== ERROR_MARK
)
10145 /* See if we already have the appropriately qualified variant of
10148 = get_qualified_type (type
,
10149 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10150 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10152 if (qualified_type
== sizetype
10153 && TYPE_NAME (qualified_type
)
10154 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10156 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10158 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10159 && TYPE_PRECISION (t
)
10160 == TYPE_PRECISION (qualified_type
)
10161 && TYPE_UNSIGNED (t
)
10162 == TYPE_UNSIGNED (qualified_type
));
10163 qualified_type
= t
;
10166 /* If we do, then we can just use its DIE, if it exists. */
10167 if (qualified_type
)
10169 mod_type_die
= lookup_type_die (qualified_type
);
10171 return mod_type_die
;
10174 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10176 /* Handle C typedef types. */
10177 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10178 && !DECL_ARTIFICIAL (name
))
10180 tree dtype
= TREE_TYPE (name
);
10182 if (qualified_type
== dtype
)
10184 /* For a named type, use the typedef. */
10185 gen_type_die (qualified_type
, context_die
);
10186 return lookup_type_die (qualified_type
);
10188 else if (is_const_type
< TYPE_READONLY (dtype
)
10189 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10190 || (is_const_type
<= TYPE_READONLY (dtype
)
10191 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10192 && DECL_ORIGINAL_TYPE (name
) != type
))
10193 /* cv-unqualified version of named type. Just use the unnamed
10194 type to which it refers. */
10195 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10196 is_const_type
, is_volatile_type
,
10198 /* Else cv-qualified version of named type; fall through. */
10201 mod_scope
= scope_die_for (type
, context_die
);
10204 /* If both is_const_type and is_volatile_type, prefer the path
10205 which leads to a qualified type. */
10206 && (!is_volatile_type
10207 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10208 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10210 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10211 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10213 else if (is_volatile_type
)
10215 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10216 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10218 else if (code
== POINTER_TYPE
)
10220 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10221 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10222 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10223 item_type
= TREE_TYPE (type
);
10224 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10225 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10226 TYPE_ADDR_SPACE (item_type
));
10228 else if (code
== REFERENCE_TYPE
)
10230 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10231 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10234 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10235 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10236 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10237 item_type
= TREE_TYPE (type
);
10238 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10239 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10240 TYPE_ADDR_SPACE (item_type
));
10242 else if (code
== INTEGER_TYPE
10243 && TREE_TYPE (type
) != NULL_TREE
10244 && subrange_type_for_debug_p (type
, &low
, &high
))
10246 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10247 item_type
= TREE_TYPE (type
);
10249 else if (is_base_type (type
))
10250 mod_type_die
= base_type_die (type
);
10253 gen_type_die (type
, context_die
);
10255 /* We have to get the type_main_variant here (and pass that to the
10256 `lookup_type_die' routine) because the ..._TYPE node we have
10257 might simply be a *copy* of some original type node (where the
10258 copy was created to help us keep track of typedef names) and
10259 that copy might have a different TYPE_UID from the original
10261 if (TREE_CODE (type
) != VECTOR_TYPE
)
10262 return lookup_type_die (type_main_variant (type
));
10264 /* Vectors have the debugging information in the type,
10265 not the main variant. */
10266 return lookup_type_die (type
);
10269 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10270 don't output a DW_TAG_typedef, since there isn't one in the
10271 user's program; just attach a DW_AT_name to the type.
10272 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10273 if the base type already has the same name. */
10275 && ((TREE_CODE (name
) != TYPE_DECL
10276 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10277 || (!is_const_type
&& !is_volatile_type
)))
10278 || (TREE_CODE (name
) == TYPE_DECL
10279 && TREE_TYPE (name
) == qualified_type
10280 && DECL_NAME (name
))))
10282 if (TREE_CODE (name
) == TYPE_DECL
)
10283 /* Could just call add_name_and_src_coords_attributes here,
10284 but since this is a builtin type it doesn't have any
10285 useful source coordinates anyway. */
10286 name
= DECL_NAME (name
);
10287 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10289 /* This probably indicates a bug. */
10290 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10292 name
= TYPE_NAME (type
);
10294 && TREE_CODE (name
) == TYPE_DECL
)
10295 name
= DECL_NAME (name
);
10296 add_name_attribute (mod_type_die
,
10297 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10300 if (qualified_type
)
10301 equate_type_number_to_die (qualified_type
, mod_type_die
);
10304 /* We must do this after the equate_type_number_to_die call, in case
10305 this is a recursive type. This ensures that the modified_type_die
10306 recursion will terminate even if the type is recursive. Recursive
10307 types are possible in Ada. */
10308 sub_die
= modified_type_die (item_type
,
10309 TYPE_READONLY (item_type
),
10310 TYPE_VOLATILE (item_type
),
10313 if (sub_die
!= NULL
)
10314 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10316 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10317 if (TYPE_ARTIFICIAL (type
))
10318 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10320 return mod_type_die
;
10323 /* Generate DIEs for the generic parameters of T.
10324 T must be either a generic type or a generic function.
10325 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10328 gen_generic_params_dies (tree t
)
10332 dw_die_ref die
= NULL
;
10335 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10339 die
= lookup_type_die (t
);
10340 else if (DECL_P (t
))
10341 die
= lookup_decl_die (t
);
10345 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10347 /* T has no generic parameter. It means T is neither a generic type
10348 or function. End of story. */
10351 parms_num
= TREE_VEC_LENGTH (parms
);
10352 args
= lang_hooks
.get_innermost_generic_args (t
);
10353 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10354 non_default
= int_cst_value (TREE_CHAIN (args
));
10356 non_default
= TREE_VEC_LENGTH (args
);
10357 for (i
= 0; i
< parms_num
; i
++)
10359 tree parm
, arg
, arg_pack_elems
;
10360 dw_die_ref parm_die
;
10362 parm
= TREE_VEC_ELT (parms
, i
);
10363 arg
= TREE_VEC_ELT (args
, i
);
10364 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10365 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10367 if (parm
&& TREE_VALUE (parm
) && arg
)
10369 /* If PARM represents a template parameter pack,
10370 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10371 by DW_TAG_template_*_parameter DIEs for the argument
10372 pack elements of ARG. Note that ARG would then be
10373 an argument pack. */
10374 if (arg_pack_elems
)
10375 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10379 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10380 true /* emit name */, die
);
10381 if (i
>= non_default
)
10382 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10387 /* Create and return a DIE for PARM which should be
10388 the representation of a generic type parameter.
10389 For instance, in the C++ front end, PARM would be a template parameter.
10390 ARG is the argument to PARM.
10391 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10393 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10394 as a child node. */
10397 generic_parameter_die (tree parm
, tree arg
,
10399 dw_die_ref parent_die
)
10401 dw_die_ref tmpl_die
= NULL
;
10402 const char *name
= NULL
;
10404 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10407 /* We support non-type generic parameters and arguments,
10408 type generic parameters and arguments, as well as
10409 generic generic parameters (a.k.a. template template parameters in C++)
10411 if (TREE_CODE (parm
) == PARM_DECL
)
10412 /* PARM is a nontype generic parameter */
10413 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10414 else if (TREE_CODE (parm
) == TYPE_DECL
)
10415 /* PARM is a type generic parameter. */
10416 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10417 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10418 /* PARM is a generic generic parameter.
10419 Its DIE is a GNU extension. It shall have a
10420 DW_AT_name attribute to represent the name of the template template
10421 parameter, and a DW_AT_GNU_template_name attribute to represent the
10422 name of the template template argument. */
10423 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10426 gcc_unreachable ();
10432 /* If PARM is a generic parameter pack, it means we are
10433 emitting debug info for a template argument pack element.
10434 In other terms, ARG is a template argument pack element.
10435 In that case, we don't emit any DW_AT_name attribute for
10439 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10441 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10444 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10446 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10447 TMPL_DIE should have a child DW_AT_type attribute that is set
10448 to the type of the argument to PARM, which is ARG.
10449 If PARM is a type generic parameter, TMPL_DIE should have a
10450 child DW_AT_type that is set to ARG. */
10451 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10452 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10453 TREE_THIS_VOLATILE (tmpl_type
),
10458 /* So TMPL_DIE is a DIE representing a
10459 a generic generic template parameter, a.k.a template template
10460 parameter in C++ and arg is a template. */
10462 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10463 to the name of the argument. */
10464 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10466 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10469 if (TREE_CODE (parm
) == PARM_DECL
)
10470 /* So PARM is a non-type generic parameter.
10471 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10472 attribute of TMPL_DIE which value represents the value
10474 We must be careful here:
10475 The value of ARG might reference some function decls.
10476 We might currently be emitting debug info for a generic
10477 type and types are emitted before function decls, we don't
10478 know if the function decls referenced by ARG will actually be
10479 emitted after cgraph computations.
10480 So must defer the generation of the DW_AT_const_value to
10481 after cgraph is ready. */
10482 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10488 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10489 PARM_PACK must be a template parameter pack. The returned DIE
10490 will be child DIE of PARENT_DIE. */
10493 template_parameter_pack_die (tree parm_pack
,
10494 tree parm_pack_args
,
10495 dw_die_ref parent_die
)
10500 gcc_assert (parent_die
&& parm_pack
);
10502 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10503 add_name_and_src_coords_attributes (die
, parm_pack
);
10504 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10505 generic_parameter_die (parm_pack
,
10506 TREE_VEC_ELT (parm_pack_args
, j
),
10507 false /* Don't emit DW_AT_name */,
10512 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10513 an enumerated type. */
10516 type_is_enum (const_tree type
)
10518 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10521 /* Return the DBX register number described by a given RTL node. */
10523 static unsigned int
10524 dbx_reg_number (const_rtx rtl
)
10526 unsigned regno
= REGNO (rtl
);
10528 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10530 #ifdef LEAF_REG_REMAP
10531 if (crtl
->uses_only_leaf_regs
)
10533 int leaf_reg
= LEAF_REG_REMAP (regno
);
10534 if (leaf_reg
!= -1)
10535 regno
= (unsigned) leaf_reg
;
10539 regno
= DBX_REGISTER_NUMBER (regno
);
10540 gcc_assert (regno
!= INVALID_REGNUM
);
10544 /* Optionally add a DW_OP_piece term to a location description expression.
10545 DW_OP_piece is only added if the location description expression already
10546 doesn't end with DW_OP_piece. */
10549 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10551 dw_loc_descr_ref loc
;
10553 if (*list_head
!= NULL
)
10555 /* Find the end of the chain. */
10556 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10559 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10560 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10564 /* Return a location descriptor that designates a machine register or
10565 zero if there is none. */
10567 static dw_loc_descr_ref
10568 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10572 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10575 /* We only use "frame base" when we're sure we're talking about the
10576 post-prologue local stack frame. We do this by *not* running
10577 register elimination until this point, and recognizing the special
10578 argument pointer and soft frame pointer rtx's.
10579 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10580 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10581 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10583 dw_loc_descr_ref result
= NULL
;
10585 if (dwarf_version
>= 4 || !dwarf_strict
)
10587 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10590 add_loc_descr (&result
,
10591 new_loc_descr (DW_OP_stack_value
, 0, 0));
10596 regs
= targetm
.dwarf_register_span (rtl
);
10598 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10599 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10602 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10603 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10605 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10609 /* Return a location descriptor that designates a machine register for
10610 a given hard register number. */
10612 static dw_loc_descr_ref
10613 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10615 dw_loc_descr_ref reg_loc_descr
;
10619 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10621 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10623 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10624 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10626 return reg_loc_descr
;
10629 /* Given an RTL of a register, return a location descriptor that
10630 designates a value that spans more than one register. */
10632 static dw_loc_descr_ref
10633 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10634 enum var_init_status initialized
)
10637 dw_loc_descr_ref loc_result
= NULL
;
10639 /* Simple, contiguous registers. */
10640 if (regs
== NULL_RTX
)
10642 unsigned reg
= REGNO (rtl
);
10645 #ifdef LEAF_REG_REMAP
10646 if (crtl
->uses_only_leaf_regs
)
10648 int leaf_reg
= LEAF_REG_REMAP (reg
);
10649 if (leaf_reg
!= -1)
10650 reg
= (unsigned) leaf_reg
;
10654 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10655 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10657 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10662 dw_loc_descr_ref t
;
10664 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10665 VAR_INIT_STATUS_INITIALIZED
);
10666 add_loc_descr (&loc_result
, t
);
10667 add_loc_descr_op_piece (&loc_result
, size
);
10673 /* Now onto stupid register sets in non contiguous locations. */
10675 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10677 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10680 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10682 dw_loc_descr_ref t
;
10684 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
10685 VAR_INIT_STATUS_INITIALIZED
);
10686 add_loc_descr (&loc_result
, t
);
10687 add_loc_descr_op_piece (&loc_result
, size
);
10690 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10691 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10695 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10697 /* Return a location descriptor that designates a constant i,
10698 as a compound operation from constant (i >> shift), constant shift
10701 static dw_loc_descr_ref
10702 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10704 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10705 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10706 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10710 /* Return a location descriptor that designates a constant. */
10712 static dw_loc_descr_ref
10713 int_loc_descriptor (HOST_WIDE_INT i
)
10715 enum dwarf_location_atom op
;
10717 /* Pick the smallest representation of a constant, rather than just
10718 defaulting to the LEB encoding. */
10721 int clz
= clz_hwi (i
);
10722 int ctz
= ctz_hwi (i
);
10724 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10725 else if (i
<= 0xff)
10726 op
= DW_OP_const1u
;
10727 else if (i
<= 0xffff)
10728 op
= DW_OP_const2u
;
10729 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10730 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10731 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10732 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10733 while DW_OP_const4u is 5 bytes. */
10734 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10735 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10736 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10737 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10738 while DW_OP_const4u is 5 bytes. */
10739 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10740 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10741 op
= DW_OP_const4u
;
10742 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10743 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10744 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10745 while DW_OP_constu of constant >= 0x100000000 takes at least
10747 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10748 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10749 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10750 >= HOST_BITS_PER_WIDE_INT
)
10751 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10752 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10753 while DW_OP_constu takes in this case at least 6 bytes. */
10754 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10755 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10756 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10757 && size_of_uleb128 (i
) > 6)
10758 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10759 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10766 op
= DW_OP_const1s
;
10767 else if (i
>= -0x8000)
10768 op
= DW_OP_const2s
;
10769 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10771 if (size_of_int_loc_descriptor (i
) < 5)
10773 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10774 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10777 op
= DW_OP_const4s
;
10781 if (size_of_int_loc_descriptor (i
)
10782 < (unsigned long) 1 + size_of_sleb128 (i
))
10784 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10785 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10792 return new_loc_descr (op
, i
, 0);
10795 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10796 without actually allocating it. */
10798 static unsigned long
10799 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10801 return size_of_int_loc_descriptor (i
>> shift
)
10802 + size_of_int_loc_descriptor (shift
)
10806 /* Return size_of_locs (int_loc_descriptor (i)) without
10807 actually allocating it. */
10809 static unsigned long
10810 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10819 else if (i
<= 0xff)
10821 else if (i
<= 0xffff)
10825 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10826 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10827 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10829 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10830 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10831 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10833 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10835 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10836 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10837 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10838 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10840 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10841 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10842 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10844 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10845 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10847 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10856 else if (i
>= -0x8000)
10858 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10860 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10862 s
= size_of_int_loc_descriptor (-i
) + 1;
10870 unsigned long r
= 1 + size_of_sleb128 (i
);
10871 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10873 s
= size_of_int_loc_descriptor (-i
) + 1;
10882 /* Return loc description representing "address" of integer value.
10883 This can appear only as toplevel expression. */
10885 static dw_loc_descr_ref
10886 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10889 dw_loc_descr_ref loc_result
= NULL
;
10891 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10894 litsize
= size_of_int_loc_descriptor (i
);
10895 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10896 is more compact. For DW_OP_stack_value we need:
10897 litsize + 1 (DW_OP_stack_value)
10898 and for DW_OP_implicit_value:
10899 1 (DW_OP_implicit_value) + 1 (length) + size. */
10900 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10902 loc_result
= int_loc_descriptor (i
);
10903 add_loc_descr (&loc_result
,
10904 new_loc_descr (DW_OP_stack_value
, 0, 0));
10908 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10910 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10911 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10915 /* Return a location descriptor that designates a base+offset location. */
10917 static dw_loc_descr_ref
10918 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10919 enum var_init_status initialized
)
10921 unsigned int regno
;
10922 dw_loc_descr_ref result
;
10923 dw_fde_ref fde
= cfun
->fde
;
10925 /* We only use "frame base" when we're sure we're talking about the
10926 post-prologue local stack frame. We do this by *not* running
10927 register elimination until this point, and recognizing the special
10928 argument pointer and soft frame pointer rtx's. */
10929 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10931 rtx elim
= (ira_use_lra_p
10932 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10933 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10937 if (GET_CODE (elim
) == PLUS
)
10939 offset
+= INTVAL (XEXP (elim
, 1));
10940 elim
= XEXP (elim
, 0);
10942 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10943 && (elim
== hard_frame_pointer_rtx
10944 || elim
== stack_pointer_rtx
))
10945 || elim
== (frame_pointer_needed
10946 ? hard_frame_pointer_rtx
10947 : stack_pointer_rtx
));
10949 /* If drap register is used to align stack, use frame
10950 pointer + offset to access stack variables. If stack
10951 is aligned without drap, use stack pointer + offset to
10952 access stack variables. */
10953 if (crtl
->stack_realign_tried
10954 && reg
== frame_pointer_rtx
)
10957 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10958 ? HARD_FRAME_POINTER_REGNUM
10960 return new_reg_loc_descr (base_reg
, offset
);
10963 gcc_assert (frame_pointer_fb_offset_valid
);
10964 offset
+= frame_pointer_fb_offset
;
10965 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10969 regno
= REGNO (reg
);
10970 #ifdef LEAF_REG_REMAP
10971 if (crtl
->uses_only_leaf_regs
)
10973 int leaf_reg
= LEAF_REG_REMAP (regno
);
10974 if (leaf_reg
!= -1)
10975 regno
= (unsigned) leaf_reg
;
10978 regno
= DWARF_FRAME_REGNUM (regno
);
10980 if (!optimize
&& fde
10981 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10983 /* Use cfa+offset to represent the location of arguments passed
10984 on the stack when drap is used to align stack.
10985 Only do this when not optimizing, for optimized code var-tracking
10986 is supposed to track where the arguments live and the register
10987 used as vdrap or drap in some spot might be used for something
10988 else in other part of the routine. */
10989 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10993 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10996 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10998 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10999 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11004 /* Return true if this RTL expression describes a base+offset calculation. */
11007 is_based_loc (const_rtx rtl
)
11009 return (GET_CODE (rtl
) == PLUS
11010 && ((REG_P (XEXP (rtl
, 0))
11011 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11012 && CONST_INT_P (XEXP (rtl
, 1)))));
11015 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11018 static dw_loc_descr_ref
11019 tls_mem_loc_descriptor (rtx mem
)
11022 dw_loc_descr_ref loc_result
;
11024 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11027 base
= get_base_address (MEM_EXPR (mem
));
11029 || TREE_CODE (base
) != VAR_DECL
11030 || !DECL_THREAD_LOCAL_P (base
))
11033 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11034 if (loc_result
== NULL
)
11037 if (MEM_OFFSET (mem
))
11038 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11043 /* Output debug info about reason why we failed to expand expression as dwarf
11047 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11049 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11051 fprintf (dump_file
, "Failed to expand as dwarf: ");
11053 print_generic_expr (dump_file
, expr
, dump_flags
);
11056 fprintf (dump_file
, "\n");
11057 print_rtl (dump_file
, rtl
);
11059 fprintf (dump_file
, "\nReason: %s\n", reason
);
11063 /* Helper function for const_ok_for_output, called either directly
11064 or via for_each_rtx. */
11067 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11071 if (GET_CODE (rtl
) == UNSPEC
)
11073 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11074 we can't express it in the debug info. */
11075 #ifdef ENABLE_CHECKING
11076 /* Don't complain about TLS UNSPECs, those are just too hard to
11077 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11078 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11079 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11080 if (XVECLEN (rtl
, 0) == 0
11081 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11082 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11083 inform (current_function_decl
11084 ? DECL_SOURCE_LOCATION (current_function_decl
)
11085 : UNKNOWN_LOCATION
,
11086 #if NUM_UNSPEC_VALUES > 0
11087 "non-delegitimized UNSPEC %s (%d) found in variable location",
11088 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11089 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11092 "non-delegitimized UNSPEC %d found in variable location",
11096 expansion_failed (NULL_TREE
, rtl
,
11097 "UNSPEC hasn't been delegitimized.\n");
11101 if (targetm
.const_not_ok_for_debug_p (rtl
))
11103 expansion_failed (NULL_TREE
, rtl
,
11104 "Expression rejected for debug by the backend.\n");
11108 if (GET_CODE (rtl
) != SYMBOL_REF
)
11111 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11114 get_pool_constant_mark (rtl
, &marked
);
11115 /* If all references to this pool constant were optimized away,
11116 it was not output and thus we can't represent it. */
11119 expansion_failed (NULL_TREE
, rtl
,
11120 "Constant was removed from constant pool.\n");
11125 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11128 /* Avoid references to external symbols in debug info, on several targets
11129 the linker might even refuse to link when linking a shared library,
11130 and in many other cases the relocations for .debug_info/.debug_loc are
11131 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11132 to be defined within the same shared library or executable are fine. */
11133 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11135 tree decl
= SYMBOL_REF_DECL (rtl
);
11137 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11139 expansion_failed (NULL_TREE
, rtl
,
11140 "Symbol not defined in current TU.\n");
11148 /* Return true if constant RTL can be emitted in DW_OP_addr or
11149 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11150 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11153 const_ok_for_output (rtx rtl
)
11155 if (GET_CODE (rtl
) == SYMBOL_REF
)
11156 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11158 if (GET_CODE (rtl
) == CONST
)
11159 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11164 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11165 if possible, NULL otherwise. */
11168 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11170 dw_die_ref type_die
;
11171 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11175 switch (TREE_CODE (type
))
11183 type_die
= lookup_type_die (type
);
11185 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11186 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11191 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11192 type matching MODE, or, if MODE is narrower than or as wide as
11193 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11196 static dw_loc_descr_ref
11197 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11199 enum machine_mode outer_mode
= mode
;
11200 dw_die_ref type_die
;
11201 dw_loc_descr_ref cvt
;
11203 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11205 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11208 type_die
= base_type_for_mode (outer_mode
, 1);
11209 if (type_die
== NULL
)
11211 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11212 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11213 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11214 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11215 add_loc_descr (&op
, cvt
);
11219 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11221 static dw_loc_descr_ref
11222 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11223 dw_loc_descr_ref op1
)
11225 dw_loc_descr_ref ret
= op0
;
11226 add_loc_descr (&ret
, op1
);
11227 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11228 if (STORE_FLAG_VALUE
!= 1)
11230 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11231 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11236 /* Return location descriptor for signed comparison OP RTL. */
11238 static dw_loc_descr_ref
11239 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11240 enum machine_mode mem_mode
)
11242 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11243 dw_loc_descr_ref op0
, op1
;
11246 if (op_mode
== VOIDmode
)
11247 op_mode
= GET_MODE (XEXP (rtl
, 1));
11248 if (op_mode
== VOIDmode
)
11252 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11253 || 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_CLASS (op_mode
) != MODE_INT
11265 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11266 return compare_loc_descriptor (op
, op0
, op1
);
11268 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11270 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11271 dw_loc_descr_ref cvt
;
11273 if (type_die
== NULL
)
11275 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11276 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11277 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11278 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11279 add_loc_descr (&op0
, cvt
);
11280 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11281 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11282 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11283 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11284 add_loc_descr (&op1
, cvt
);
11285 return compare_loc_descriptor (op
, op0
, op1
);
11288 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11289 /* For eq/ne, if the operands are known to be zero-extended,
11290 there is no need to do the fancy shifting up. */
11291 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11293 dw_loc_descr_ref last0
, last1
;
11294 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11296 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11298 /* deref_size zero extends, and for constants we can check
11299 whether they are zero extended or not. */
11300 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11301 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11302 || (CONST_INT_P (XEXP (rtl
, 0))
11303 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11304 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11305 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11306 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11307 || (CONST_INT_P (XEXP (rtl
, 1))
11308 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11309 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11310 return compare_loc_descriptor (op
, op0
, op1
);
11312 /* EQ/NE comparison against constant in narrower type than
11313 DWARF2_ADDR_SIZE can be performed either as
11314 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11317 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11318 DW_OP_{eq,ne}. Pick whatever is shorter. */
11319 if (CONST_INT_P (XEXP (rtl
, 1))
11320 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11321 && (size_of_int_loc_descriptor (shift
) + 1
11322 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11323 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11324 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11325 & GET_MODE_MASK (op_mode
))))
11327 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11328 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11329 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11330 & GET_MODE_MASK (op_mode
));
11331 return compare_loc_descriptor (op
, op0
, op1
);
11334 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11335 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11336 if (CONST_INT_P (XEXP (rtl
, 1)))
11337 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11340 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11341 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11343 return compare_loc_descriptor (op
, op0
, op1
);
11346 /* Return location descriptor for unsigned comparison OP RTL. */
11348 static dw_loc_descr_ref
11349 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11350 enum machine_mode mem_mode
)
11352 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11353 dw_loc_descr_ref op0
, op1
;
11355 if (op_mode
== VOIDmode
)
11356 op_mode
= GET_MODE (XEXP (rtl
, 1));
11357 if (op_mode
== VOIDmode
)
11359 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11362 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11365 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11366 VAR_INIT_STATUS_INITIALIZED
);
11367 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11368 VAR_INIT_STATUS_INITIALIZED
);
11370 if (op0
== NULL
|| op1
== NULL
)
11373 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11375 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11376 dw_loc_descr_ref last0
, last1
;
11377 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11379 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11381 if (CONST_INT_P (XEXP (rtl
, 0)))
11382 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11383 /* deref_size zero extends, so no need to mask it again. */
11384 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11385 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11387 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11388 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11390 if (CONST_INT_P (XEXP (rtl
, 1)))
11391 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11392 /* deref_size zero extends, so no need to mask it again. */
11393 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11394 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11396 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11397 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11400 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11402 HOST_WIDE_INT bias
= 1;
11403 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11404 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11405 if (CONST_INT_P (XEXP (rtl
, 1)))
11406 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11407 + INTVAL (XEXP (rtl
, 1)));
11409 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11412 return compare_loc_descriptor (op
, op0
, op1
);
11415 /* Return location descriptor for {U,S}{MIN,MAX}. */
11417 static dw_loc_descr_ref
11418 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11419 enum machine_mode mem_mode
)
11421 enum dwarf_location_atom op
;
11422 dw_loc_descr_ref op0
, op1
, ret
;
11423 dw_loc_descr_ref bra_node
, drop_node
;
11426 && (GET_MODE_CLASS (mode
) != MODE_INT
11427 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11430 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11431 VAR_INIT_STATUS_INITIALIZED
);
11432 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11433 VAR_INIT_STATUS_INITIALIZED
);
11435 if (op0
== NULL
|| op1
== NULL
)
11438 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11439 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11440 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11441 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11443 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11445 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11446 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11447 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11448 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11449 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11451 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11453 HOST_WIDE_INT bias
= 1;
11454 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11455 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11456 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11459 else if (GET_MODE_CLASS (mode
) == MODE_INT
11460 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11462 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11463 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11464 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11465 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11466 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11468 else if (GET_MODE_CLASS (mode
) == MODE_INT
11469 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11471 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11472 dw_loc_descr_ref cvt
;
11473 if (type_die
== NULL
)
11475 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11476 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11477 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11478 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11479 add_loc_descr (&op0
, cvt
);
11480 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11481 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11482 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11483 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11484 add_loc_descr (&op1
, cvt
);
11487 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11492 add_loc_descr (&ret
, op1
);
11493 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11494 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11495 add_loc_descr (&ret
, bra_node
);
11496 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11497 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11498 add_loc_descr (&ret
, drop_node
);
11499 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11500 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11501 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11502 && GET_MODE_CLASS (mode
) == MODE_INT
11503 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11504 ret
= convert_descriptor_to_mode (mode
, ret
);
11508 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11509 but after converting arguments to type_die, afterwards
11510 convert back to unsigned. */
11512 static dw_loc_descr_ref
11513 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11514 enum machine_mode mode
, enum machine_mode mem_mode
)
11516 dw_loc_descr_ref cvt
, op0
, op1
;
11518 if (type_die
== NULL
)
11520 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11521 VAR_INIT_STATUS_INITIALIZED
);
11522 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11523 VAR_INIT_STATUS_INITIALIZED
);
11524 if (op0
== NULL
|| op1
== NULL
)
11526 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11527 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11528 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11529 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11530 add_loc_descr (&op0
, cvt
);
11531 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11532 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11533 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11534 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11535 add_loc_descr (&op1
, cvt
);
11536 add_loc_descr (&op0
, op1
);
11537 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11538 return convert_descriptor_to_mode (mode
, op0
);
11541 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11542 const0 is DW_OP_lit0 or corresponding typed constant,
11543 const1 is DW_OP_lit1 or corresponding typed constant
11544 and constMSB is constant with just the MSB bit set
11546 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11547 L1: const0 DW_OP_swap
11548 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11549 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11554 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11555 L1: const0 DW_OP_swap
11556 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11557 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11562 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11563 L1: const1 DW_OP_swap
11564 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11565 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11569 static dw_loc_descr_ref
11570 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11571 enum machine_mode mem_mode
)
11573 dw_loc_descr_ref op0
, ret
, tmp
;
11574 HOST_WIDE_INT valv
;
11575 dw_loc_descr_ref l1jump
, l1label
;
11576 dw_loc_descr_ref l2jump
, l2label
;
11577 dw_loc_descr_ref l3jump
, l3label
;
11578 dw_loc_descr_ref l4jump
, l4label
;
11581 if (GET_MODE_CLASS (mode
) != MODE_INT
11582 || GET_MODE (XEXP (rtl
, 0)) != mode
11583 || (GET_CODE (rtl
) == CLZ
11584 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11587 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11588 VAR_INIT_STATUS_INITIALIZED
);
11592 if (GET_CODE (rtl
) == CLZ
)
11594 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11595 valv
= GET_MODE_BITSIZE (mode
);
11597 else if (GET_CODE (rtl
) == FFS
)
11599 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11600 valv
= GET_MODE_BITSIZE (mode
);
11601 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11602 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11603 add_loc_descr (&ret
, l1jump
);
11604 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11605 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11606 VAR_INIT_STATUS_INITIALIZED
);
11609 add_loc_descr (&ret
, tmp
);
11610 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11611 add_loc_descr (&ret
, l4jump
);
11612 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11613 ? const1_rtx
: const0_rtx
,
11615 VAR_INIT_STATUS_INITIALIZED
);
11616 if (l1label
== NULL
)
11618 add_loc_descr (&ret
, l1label
);
11619 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11620 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11621 add_loc_descr (&ret
, l2label
);
11622 if (GET_CODE (rtl
) != CLZ
)
11624 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11625 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11626 << (GET_MODE_BITSIZE (mode
) - 1));
11628 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11629 << (GET_MODE_BITSIZE (mode
)
11630 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11631 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11632 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11633 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11634 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11636 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11637 VAR_INIT_STATUS_INITIALIZED
);
11640 add_loc_descr (&ret
, tmp
);
11641 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11642 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11643 add_loc_descr (&ret
, l3jump
);
11644 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11645 VAR_INIT_STATUS_INITIALIZED
);
11648 add_loc_descr (&ret
, tmp
);
11649 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11650 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11651 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11652 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11653 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11654 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11655 add_loc_descr (&ret
, l2jump
);
11656 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11657 add_loc_descr (&ret
, l3label
);
11658 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11659 add_loc_descr (&ret
, l4label
);
11660 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11661 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11662 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11663 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11664 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11665 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11666 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11667 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11671 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11672 const1 is DW_OP_lit1 or corresponding typed constant):
11674 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11675 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11679 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11680 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11683 static dw_loc_descr_ref
11684 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11685 enum machine_mode mem_mode
)
11687 dw_loc_descr_ref op0
, ret
, tmp
;
11688 dw_loc_descr_ref l1jump
, l1label
;
11689 dw_loc_descr_ref l2jump
, l2label
;
11691 if (GET_MODE_CLASS (mode
) != MODE_INT
11692 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11695 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11696 VAR_INIT_STATUS_INITIALIZED
);
11700 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11701 VAR_INIT_STATUS_INITIALIZED
);
11704 add_loc_descr (&ret
, tmp
);
11705 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11706 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11707 add_loc_descr (&ret
, l1label
);
11708 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11709 add_loc_descr (&ret
, l2jump
);
11710 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11711 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11712 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11713 VAR_INIT_STATUS_INITIALIZED
);
11716 add_loc_descr (&ret
, tmp
);
11717 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11718 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11719 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11720 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11721 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11722 VAR_INIT_STATUS_INITIALIZED
);
11723 add_loc_descr (&ret
, tmp
);
11724 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11725 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11726 add_loc_descr (&ret
, l1jump
);
11727 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11728 add_loc_descr (&ret
, l2label
);
11729 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11730 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11731 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11732 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11736 /* BSWAP (constS is initial shift count, either 56 or 24):
11738 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11739 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11740 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11741 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11742 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11744 static dw_loc_descr_ref
11745 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11746 enum machine_mode mem_mode
)
11748 dw_loc_descr_ref op0
, ret
, tmp
;
11749 dw_loc_descr_ref l1jump
, l1label
;
11750 dw_loc_descr_ref l2jump
, l2label
;
11752 if (GET_MODE_CLASS (mode
) != MODE_INT
11753 || BITS_PER_UNIT
!= 8
11754 || (GET_MODE_BITSIZE (mode
) != 32
11755 && GET_MODE_BITSIZE (mode
) != 64))
11758 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11759 VAR_INIT_STATUS_INITIALIZED
);
11764 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11766 VAR_INIT_STATUS_INITIALIZED
);
11769 add_loc_descr (&ret
, tmp
);
11770 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11771 VAR_INIT_STATUS_INITIALIZED
);
11774 add_loc_descr (&ret
, tmp
);
11775 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11776 add_loc_descr (&ret
, l1label
);
11777 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11779 VAR_INIT_STATUS_INITIALIZED
);
11780 add_loc_descr (&ret
, tmp
);
11781 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11782 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11783 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11784 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11785 VAR_INIT_STATUS_INITIALIZED
);
11788 add_loc_descr (&ret
, tmp
);
11789 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11790 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11791 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11792 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11793 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11794 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11795 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11796 VAR_INIT_STATUS_INITIALIZED
);
11797 add_loc_descr (&ret
, tmp
);
11798 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11799 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11800 add_loc_descr (&ret
, l2jump
);
11801 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11802 VAR_INIT_STATUS_INITIALIZED
);
11803 add_loc_descr (&ret
, tmp
);
11804 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11805 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11806 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11807 add_loc_descr (&ret
, l1jump
);
11808 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11809 add_loc_descr (&ret
, l2label
);
11810 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11811 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11812 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11813 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11814 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11815 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11819 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11820 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11821 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11822 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11824 ROTATERT is similar:
11825 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11826 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11827 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11829 static dw_loc_descr_ref
11830 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11831 enum machine_mode mem_mode
)
11833 rtx rtlop1
= XEXP (rtl
, 1);
11834 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11837 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11840 if (GET_MODE (rtlop1
) != VOIDmode
11841 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11842 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11843 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11844 VAR_INIT_STATUS_INITIALIZED
);
11845 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11846 VAR_INIT_STATUS_INITIALIZED
);
11847 if (op0
== NULL
|| op1
== NULL
)
11849 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11850 for (i
= 0; i
< 2; i
++)
11852 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11853 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11855 VAR_INIT_STATUS_INITIALIZED
);
11856 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11857 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11859 : HOST_BITS_PER_WIDE_INT
== 64
11860 ? DW_OP_const8u
: DW_OP_constu
,
11861 GET_MODE_MASK (mode
), 0);
11864 if (mask
[i
] == NULL
)
11866 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11869 add_loc_descr (&ret
, op1
);
11870 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11871 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11872 if (GET_CODE (rtl
) == ROTATERT
)
11874 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11875 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11876 GET_MODE_BITSIZE (mode
), 0));
11878 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11879 if (mask
[0] != NULL
)
11880 add_loc_descr (&ret
, mask
[0]);
11881 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11882 if (mask
[1] != NULL
)
11884 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11885 add_loc_descr (&ret
, mask
[1]);
11886 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11888 if (GET_CODE (rtl
) == ROTATE
)
11890 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11891 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11892 GET_MODE_BITSIZE (mode
), 0));
11894 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11895 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11899 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11900 for DEBUG_PARAMETER_REF RTL. */
11902 static dw_loc_descr_ref
11903 parameter_ref_descriptor (rtx rtl
)
11905 dw_loc_descr_ref ret
;
11910 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11911 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11912 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11915 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11916 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11917 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11921 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11922 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11927 /* The following routine converts the RTL for a variable or parameter
11928 (resident in memory) into an equivalent Dwarf representation of a
11929 mechanism for getting the address of that same variable onto the top of a
11930 hypothetical "address evaluation" stack.
11932 When creating memory location descriptors, we are effectively transforming
11933 the RTL for a memory-resident object into its Dwarf postfix expression
11934 equivalent. This routine recursively descends an RTL tree, turning
11935 it into Dwarf postfix code as it goes.
11937 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11939 MEM_MODE is the mode of the memory reference, needed to handle some
11940 autoincrement addressing modes.
11942 Return 0 if we can't represent the location. */
11945 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11946 enum machine_mode mem_mode
,
11947 enum var_init_status initialized
)
11949 dw_loc_descr_ref mem_loc_result
= NULL
;
11950 enum dwarf_location_atom op
;
11951 dw_loc_descr_ref op0
, op1
;
11952 rtx inner
= NULL_RTX
;
11954 if (mode
== VOIDmode
)
11955 mode
= GET_MODE (rtl
);
11957 /* Note that for a dynamically sized array, the location we will generate a
11958 description of here will be the lowest numbered location which is
11959 actually within the array. That's *not* necessarily the same as the
11960 zeroth element of the array. */
11962 rtl
= targetm
.delegitimize_address (rtl
);
11964 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11967 switch (GET_CODE (rtl
))
11972 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11975 /* The case of a subreg may arise when we have a local (register)
11976 variable or a formal (register) parameter which doesn't quite fill
11977 up an entire register. For now, just assume that it is
11978 legitimate to make the Dwarf info refer to the whole register which
11979 contains the given subreg. */
11980 if (!subreg_lowpart_p (rtl
))
11982 inner
= SUBREG_REG (rtl
);
11984 if (inner
== NULL_RTX
)
11985 inner
= XEXP (rtl
, 0);
11986 if (GET_MODE_CLASS (mode
) == MODE_INT
11987 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
11988 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11989 #ifdef POINTERS_EXTEND_UNSIGNED
11990 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11993 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
11995 mem_loc_result
= mem_loc_descriptor (inner
,
11997 mem_mode
, initialized
);
12002 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12004 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12005 && (GET_MODE_CLASS (mode
) != MODE_INT
12006 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12010 dw_die_ref type_die
;
12011 dw_loc_descr_ref cvt
;
12013 mem_loc_result
= mem_loc_descriptor (inner
,
12015 mem_mode
, initialized
);
12016 if (mem_loc_result
== NULL
)
12018 type_die
= base_type_for_mode (mode
,
12019 GET_MODE_CLASS (mode
) == MODE_INT
);
12020 if (type_die
== NULL
)
12022 mem_loc_result
= NULL
;
12025 if (GET_MODE_SIZE (mode
)
12026 != GET_MODE_SIZE (GET_MODE (inner
)))
12027 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12029 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12030 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12031 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12032 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12033 add_loc_descr (&mem_loc_result
, cvt
);
12038 if (GET_MODE_CLASS (mode
) != MODE_INT
12039 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12040 && rtl
!= arg_pointer_rtx
12041 && rtl
!= frame_pointer_rtx
12042 #ifdef POINTERS_EXTEND_UNSIGNED
12043 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12047 dw_die_ref type_die
;
12048 unsigned int dbx_regnum
;
12052 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12054 type_die
= base_type_for_mode (mode
,
12055 GET_MODE_CLASS (mode
) == MODE_INT
);
12056 if (type_die
== NULL
)
12059 dbx_regnum
= dbx_reg_number (rtl
);
12060 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12062 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12064 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12065 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12066 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12069 /* Whenever a register number forms a part of the description of the
12070 method for calculating the (dynamic) address of a memory resident
12071 object, DWARF rules require the register number be referred to as
12072 a "base register". This distinction is not based in any way upon
12073 what category of register the hardware believes the given register
12074 belongs to. This is strictly DWARF terminology we're dealing with
12075 here. Note that in cases where the location of a memory-resident
12076 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12077 OP_CONST (0)) the actual DWARF location descriptor that we generate
12078 may just be OP_BASEREG (basereg). This may look deceptively like
12079 the object in question was allocated to a register (rather than in
12080 memory) so DWARF consumers need to be aware of the subtle
12081 distinction between OP_REG and OP_BASEREG. */
12082 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12083 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12084 else if (stack_realign_drap
12086 && crtl
->args
.internal_arg_pointer
== rtl
12087 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12089 /* If RTL is internal_arg_pointer, which has been optimized
12090 out, use DRAP instead. */
12091 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12092 VAR_INIT_STATUS_INITIALIZED
);
12098 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12100 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12101 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12104 else if (GET_CODE (rtl
) == ZERO_EXTEND
12105 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12106 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12107 < HOST_BITS_PER_WIDE_INT
12108 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12109 to expand zero extend as two shifts instead of
12111 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12113 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12114 mem_loc_result
= op0
;
12115 add_loc_descr (&mem_loc_result
,
12116 int_loc_descriptor (GET_MODE_MASK (imode
)));
12117 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12119 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12121 int shift
= DWARF2_ADDR_SIZE
12122 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12123 shift
*= BITS_PER_UNIT
;
12124 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12128 mem_loc_result
= op0
;
12129 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12130 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12131 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12132 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12134 else if (!dwarf_strict
)
12136 dw_die_ref type_die1
, type_die2
;
12137 dw_loc_descr_ref cvt
;
12139 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12140 GET_CODE (rtl
) == ZERO_EXTEND
);
12141 if (type_die1
== NULL
)
12143 type_die2
= base_type_for_mode (mode
, 1);
12144 if (type_die2
== NULL
)
12146 mem_loc_result
= op0
;
12147 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12148 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12149 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12150 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12151 add_loc_descr (&mem_loc_result
, cvt
);
12152 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12153 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12154 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12155 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12156 add_loc_descr (&mem_loc_result
, cvt
);
12162 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12163 if (new_rtl
!= rtl
)
12165 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12167 if (mem_loc_result
!= NULL
)
12168 return mem_loc_result
;
12171 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12172 get_address_mode (rtl
), mode
,
12173 VAR_INIT_STATUS_INITIALIZED
);
12174 if (mem_loc_result
== NULL
)
12175 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12176 if (mem_loc_result
!= NULL
)
12178 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12179 || GET_MODE_CLASS (mode
) != MODE_INT
)
12181 dw_die_ref type_die
;
12182 dw_loc_descr_ref deref
;
12187 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12188 if (type_die
== NULL
)
12190 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12191 GET_MODE_SIZE (mode
), 0);
12192 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12193 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12194 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12195 add_loc_descr (&mem_loc_result
, deref
);
12197 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12198 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12200 add_loc_descr (&mem_loc_result
,
12201 new_loc_descr (DW_OP_deref_size
,
12202 GET_MODE_SIZE (mode
), 0));
12207 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12210 /* Some ports can transform a symbol ref into a label ref, because
12211 the symbol ref is too far away and has to be dumped into a constant
12215 if (GET_MODE_CLASS (mode
) != MODE_INT
12216 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12217 #ifdef POINTERS_EXTEND_UNSIGNED
12218 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12222 if (GET_CODE (rtl
) == SYMBOL_REF
12223 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12225 dw_loc_descr_ref temp
;
12227 /* If this is not defined, we have no way to emit the data. */
12228 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12231 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12233 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12234 add_loc_descr (&mem_loc_result
, temp
);
12239 if (!const_ok_for_output (rtl
))
12243 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12244 vec_safe_push (used_rtx_array
, rtl
);
12250 case DEBUG_IMPLICIT_PTR
:
12251 expansion_failed (NULL_TREE
, rtl
,
12252 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12258 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12260 if (GET_MODE_CLASS (mode
) != MODE_INT
12261 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12262 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12263 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12266 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12267 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12269 op0
= one_reg_loc_descriptor (dbx_regnum
,
12270 VAR_INIT_STATUS_INITIALIZED
);
12273 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12274 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12276 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12277 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12278 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12282 gcc_unreachable ();
12285 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12286 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12287 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12290 case DEBUG_PARAMETER_REF
:
12291 mem_loc_result
= parameter_ref_descriptor (rtl
);
12295 /* Extract the PLUS expression nested inside and fall into
12296 PLUS code below. */
12297 rtl
= XEXP (rtl
, 1);
12302 /* Turn these into a PLUS expression and fall into the PLUS code
12304 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12305 GEN_INT (GET_CODE (rtl
) == PRE_INC
12306 ? GET_MODE_UNIT_SIZE (mem_mode
)
12307 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12309 /* ... fall through ... */
12313 if (is_based_loc (rtl
)
12314 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12315 || XEXP (rtl
, 0) == arg_pointer_rtx
12316 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12317 && GET_MODE_CLASS (mode
) == MODE_INT
)
12318 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12319 INTVAL (XEXP (rtl
, 1)),
12320 VAR_INIT_STATUS_INITIALIZED
);
12323 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12324 VAR_INIT_STATUS_INITIALIZED
);
12325 if (mem_loc_result
== 0)
12328 if (CONST_INT_P (XEXP (rtl
, 1))
12329 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12330 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12333 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12334 VAR_INIT_STATUS_INITIALIZED
);
12337 add_loc_descr (&mem_loc_result
, op1
);
12338 add_loc_descr (&mem_loc_result
,
12339 new_loc_descr (DW_OP_plus
, 0, 0));
12344 /* If a pseudo-reg is optimized away, it is possible for it to
12345 be replaced with a MEM containing a multiply or shift. */
12356 && GET_MODE_CLASS (mode
) == MODE_INT
12357 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12359 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12360 base_type_for_mode (mode
, 0),
12384 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12386 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12387 VAR_INIT_STATUS_INITIALIZED
);
12389 rtx rtlop1
= XEXP (rtl
, 1);
12390 if (GET_MODE (rtlop1
) != VOIDmode
12391 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12392 < GET_MODE_BITSIZE (mode
))
12393 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12394 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12395 VAR_INIT_STATUS_INITIALIZED
);
12398 if (op0
== 0 || op1
== 0)
12401 mem_loc_result
= op0
;
12402 add_loc_descr (&mem_loc_result
, op1
);
12403 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12419 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12420 VAR_INIT_STATUS_INITIALIZED
);
12421 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12422 VAR_INIT_STATUS_INITIALIZED
);
12424 if (op0
== 0 || op1
== 0)
12427 mem_loc_result
= op0
;
12428 add_loc_descr (&mem_loc_result
, op1
);
12429 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12433 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12435 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12436 base_type_for_mode (mode
, 0),
12441 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12442 VAR_INIT_STATUS_INITIALIZED
);
12443 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12444 VAR_INIT_STATUS_INITIALIZED
);
12446 if (op0
== 0 || op1
== 0)
12449 mem_loc_result
= op0
;
12450 add_loc_descr (&mem_loc_result
, op1
);
12451 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12452 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12453 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12454 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12455 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12459 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12461 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12466 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12467 base_type_for_mode (mode
, 1),
12485 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12486 VAR_INIT_STATUS_INITIALIZED
);
12491 mem_loc_result
= op0
;
12492 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12496 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12497 #ifdef POINTERS_EXTEND_UNSIGNED
12499 && mem_mode
!= VOIDmode
12500 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12504 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12508 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12509 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12511 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12512 enum machine_mode amode
;
12513 if (type_die
== NULL
)
12515 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12517 if (INTVAL (rtl
) >= 0
12518 && amode
!= BLKmode
12519 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12520 /* const DW_OP_GNU_convert <XXX> vs.
12521 DW_OP_GNU_const_type <XXX, 1, const>. */
12522 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12523 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12525 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12526 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12527 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12528 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12529 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12530 add_loc_descr (&mem_loc_result
, op0
);
12531 return mem_loc_result
;
12533 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12535 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12536 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12537 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12538 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12539 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12542 mem_loc_result
->dw_loc_oprnd2
.val_class
12543 = dw_val_class_const_double
;
12544 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12545 = double_int::from_shwi (INTVAL (rtl
));
12553 dw_die_ref type_die
;
12555 /* Note that a CONST_DOUBLE rtx could represent either an integer
12556 or a floating-point constant. A CONST_DOUBLE is used whenever
12557 the constant requires more than one word in order to be
12558 adequately represented. We output CONST_DOUBLEs as blocks. */
12559 if (mode
== VOIDmode
12560 || (GET_MODE (rtl
) == VOIDmode
12561 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12563 type_die
= base_type_for_mode (mode
,
12564 GET_MODE_CLASS (mode
) == MODE_INT
);
12565 if (type_die
== NULL
)
12567 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12568 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12569 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12570 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12571 if (SCALAR_FLOAT_MODE_P (mode
))
12573 unsigned int length
= GET_MODE_SIZE (mode
);
12574 unsigned char *array
12575 = (unsigned char*) ggc_alloc_atomic (length
);
12577 insert_float (rtl
, array
);
12578 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12579 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12580 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12581 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12585 mem_loc_result
->dw_loc_oprnd2
.val_class
12586 = dw_val_class_const_double
;
12587 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12588 = rtx_to_double_int (rtl
);
12594 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12598 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12602 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12606 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12610 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12614 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12618 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12622 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12626 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12630 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12635 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12640 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12645 if (CONST_INT_P (XEXP (rtl
, 1))
12646 && CONST_INT_P (XEXP (rtl
, 2))
12647 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12648 + (unsigned) INTVAL (XEXP (rtl
, 2))
12649 <= GET_MODE_BITSIZE (mode
))
12650 && GET_MODE_CLASS (mode
) == MODE_INT
12651 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12652 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12655 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12656 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12659 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12663 mem_loc_result
= op0
;
12664 size
= INTVAL (XEXP (rtl
, 1));
12665 shift
= INTVAL (XEXP (rtl
, 2));
12666 if (BITS_BIG_ENDIAN
)
12667 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12669 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12671 add_loc_descr (&mem_loc_result
,
12672 int_loc_descriptor (DWARF2_ADDR_SIZE
12674 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12676 if (size
!= (int) DWARF2_ADDR_SIZE
)
12678 add_loc_descr (&mem_loc_result
,
12679 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12680 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12687 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12688 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12689 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12690 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12691 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12692 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12693 VAR_INIT_STATUS_INITIALIZED
);
12694 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12695 VAR_INIT_STATUS_INITIALIZED
);
12696 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12699 mem_loc_result
= op1
;
12700 add_loc_descr (&mem_loc_result
, op2
);
12701 add_loc_descr (&mem_loc_result
, op0
);
12702 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12703 add_loc_descr (&mem_loc_result
, bra_node
);
12704 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12705 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12706 add_loc_descr (&mem_loc_result
, drop_node
);
12707 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12708 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12713 case FLOAT_TRUNCATE
:
12715 case UNSIGNED_FLOAT
:
12720 dw_die_ref type_die
;
12721 dw_loc_descr_ref cvt
;
12723 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12724 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12727 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12728 && (GET_CODE (rtl
) == FLOAT
12729 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12730 <= DWARF2_ADDR_SIZE
))
12732 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12733 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12734 if (type_die
== NULL
)
12736 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12737 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12738 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12739 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12740 add_loc_descr (&op0
, cvt
);
12742 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12743 if (type_die
== NULL
)
12745 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12746 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12747 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12748 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12749 add_loc_descr (&op0
, cvt
);
12750 if (GET_MODE_CLASS (mode
) == MODE_INT
12751 && (GET_CODE (rtl
) == FIX
12752 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12754 op0
= convert_descriptor_to_mode (mode
, op0
);
12758 mem_loc_result
= op0
;
12765 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12770 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12774 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12779 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12783 /* In theory, we could implement the above. */
12784 /* DWARF cannot represent the unsigned compare operations
12809 case FRACT_CONVERT
:
12810 case UNSIGNED_FRACT_CONVERT
:
12812 case UNSIGNED_SAT_FRACT
:
12818 case VEC_DUPLICATE
:
12822 case STRICT_LOW_PART
:
12827 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12828 can't express it in the debug info. This can happen e.g. with some
12833 resolve_one_addr (&rtl
, NULL
);
12837 #ifdef ENABLE_CHECKING
12838 print_rtl (stderr
, rtl
);
12839 gcc_unreachable ();
12845 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12846 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12848 return mem_loc_result
;
12851 /* Return a descriptor that describes the concatenation of two locations.
12852 This is typically a complex variable. */
12854 static dw_loc_descr_ref
12855 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12857 dw_loc_descr_ref cc_loc_result
= NULL
;
12858 dw_loc_descr_ref x0_ref
12859 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12860 dw_loc_descr_ref x1_ref
12861 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12863 if (x0_ref
== 0 || x1_ref
== 0)
12866 cc_loc_result
= x0_ref
;
12867 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12869 add_loc_descr (&cc_loc_result
, x1_ref
);
12870 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12872 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12873 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12875 return cc_loc_result
;
12878 /* Return a descriptor that describes the concatenation of N
12881 static dw_loc_descr_ref
12882 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12885 dw_loc_descr_ref cc_loc_result
= NULL
;
12886 unsigned int n
= XVECLEN (concatn
, 0);
12888 for (i
= 0; i
< n
; ++i
)
12890 dw_loc_descr_ref ref
;
12891 rtx x
= XVECEXP (concatn
, 0, i
);
12893 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12897 add_loc_descr (&cc_loc_result
, ref
);
12898 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12901 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12902 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12904 return cc_loc_result
;
12907 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12908 for DEBUG_IMPLICIT_PTR RTL. */
12910 static dw_loc_descr_ref
12911 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12913 dw_loc_descr_ref ret
;
12918 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12919 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12920 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12921 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12922 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12923 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12926 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12927 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12928 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12932 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12933 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12938 /* Output a proper Dwarf location descriptor for a variable or parameter
12939 which is either allocated in a register or in a memory location. For a
12940 register, we just generate an OP_REG and the register number. For a
12941 memory location we provide a Dwarf postfix expression describing how to
12942 generate the (dynamic) address of the object onto the address stack.
12944 MODE is mode of the decl if this loc_descriptor is going to be used in
12945 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12946 allowed, VOIDmode otherwise.
12948 If we don't know how to describe it, return 0. */
12950 static dw_loc_descr_ref
12951 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12952 enum var_init_status initialized
)
12954 dw_loc_descr_ref loc_result
= NULL
;
12956 switch (GET_CODE (rtl
))
12959 /* The case of a subreg may arise when we have a local (register)
12960 variable or a formal (register) parameter which doesn't quite fill
12961 up an entire register. For now, just assume that it is
12962 legitimate to make the Dwarf info refer to the whole register which
12963 contains the given subreg. */
12964 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12965 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12966 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12972 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12976 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12977 GET_MODE (rtl
), initialized
);
12978 if (loc_result
== NULL
)
12979 loc_result
= tls_mem_loc_descriptor (rtl
);
12980 if (loc_result
== NULL
)
12982 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12983 if (new_rtl
!= rtl
)
12984 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12989 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12994 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12999 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13001 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13002 if (GET_CODE (loc
) == EXPR_LIST
)
13003 loc
= XEXP (loc
, 0);
13004 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13008 rtl
= XEXP (rtl
, 1);
13013 rtvec par_elems
= XVEC (rtl
, 0);
13014 int num_elem
= GET_NUM_ELEM (par_elems
);
13015 enum machine_mode mode
;
13018 /* Create the first one, so we have something to add to. */
13019 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13020 VOIDmode
, initialized
);
13021 if (loc_result
== NULL
)
13023 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13024 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13025 for (i
= 1; i
< num_elem
; i
++)
13027 dw_loc_descr_ref temp
;
13029 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13030 VOIDmode
, initialized
);
13033 add_loc_descr (&loc_result
, temp
);
13034 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13035 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13041 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13042 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13047 if (mode
== VOIDmode
)
13048 mode
= GET_MODE (rtl
);
13050 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13052 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13054 /* Note that a CONST_DOUBLE rtx could represent either an integer
13055 or a floating-point constant. A CONST_DOUBLE is used whenever
13056 the constant requires more than one word in order to be
13057 adequately represented. We output CONST_DOUBLEs as blocks. */
13058 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13059 GET_MODE_SIZE (mode
), 0);
13060 if (SCALAR_FLOAT_MODE_P (mode
))
13062 unsigned int length
= GET_MODE_SIZE (mode
);
13063 unsigned char *array
13064 = (unsigned char*) ggc_alloc_atomic (length
);
13066 insert_float (rtl
, array
);
13067 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13068 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13069 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13070 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13074 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13075 loc_result
->dw_loc_oprnd2
.v
.val_double
13076 = rtx_to_double_int (rtl
);
13082 if (mode
== VOIDmode
)
13083 mode
= GET_MODE (rtl
);
13085 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13087 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13088 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13089 unsigned char *array
= (unsigned char *)
13090 ggc_alloc_atomic (length
* elt_size
);
13094 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13095 switch (GET_MODE_CLASS (mode
))
13097 case MODE_VECTOR_INT
:
13098 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13100 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13101 double_int val
= rtx_to_double_int (elt
);
13103 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13104 insert_int (val
.to_shwi (), elt_size
, p
);
13107 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13108 insert_double (val
, p
);
13113 case MODE_VECTOR_FLOAT
:
13114 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13116 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13117 insert_float (elt
, p
);
13122 gcc_unreachable ();
13125 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13126 length
* elt_size
, 0);
13127 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13128 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13129 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13130 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13135 if (mode
== VOIDmode
13136 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13137 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13138 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13140 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13145 if (!const_ok_for_output (rtl
))
13148 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13149 && (dwarf_version
>= 4 || !dwarf_strict
))
13151 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13152 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13153 vec_safe_push (used_rtx_array
, rtl
);
13157 case DEBUG_IMPLICIT_PTR
:
13158 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13162 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13163 && CONST_INT_P (XEXP (rtl
, 1)))
13166 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13172 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13173 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13174 && dwarf_version
>= 4)
13175 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13177 /* Value expression. */
13178 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13180 add_loc_descr (&loc_result
,
13181 new_loc_descr (DW_OP_stack_value
, 0, 0));
13189 /* We need to figure out what section we should use as the base for the
13190 address ranges where a given location is valid.
13191 1. If this particular DECL has a section associated with it, use that.
13192 2. If this function has a section associated with it, use that.
13193 3. Otherwise, use the text section.
13194 XXX: If you split a variable across multiple sections, we won't notice. */
13196 static const char *
13197 secname_for_decl (const_tree decl
)
13199 const char *secname
;
13201 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13203 tree sectree
= DECL_SECTION_NAME (decl
);
13204 secname
= TREE_STRING_POINTER (sectree
);
13206 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13208 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13209 secname
= TREE_STRING_POINTER (sectree
);
13211 else if (cfun
&& in_cold_section_p
)
13212 secname
= crtl
->subsections
.cold_section_label
;
13214 secname
= text_section_label
;
13219 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13222 decl_by_reference_p (tree decl
)
13224 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13225 || TREE_CODE (decl
) == VAR_DECL
)
13226 && DECL_BY_REFERENCE (decl
));
13229 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13232 static dw_loc_descr_ref
13233 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13234 enum var_init_status initialized
)
13236 int have_address
= 0;
13237 dw_loc_descr_ref descr
;
13238 enum machine_mode mode
;
13240 if (want_address
!= 2)
13242 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13244 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13246 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13247 if (GET_CODE (varloc
) == EXPR_LIST
)
13248 varloc
= XEXP (varloc
, 0);
13249 mode
= GET_MODE (varloc
);
13250 if (MEM_P (varloc
))
13252 rtx addr
= XEXP (varloc
, 0);
13253 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13254 mode
, initialized
);
13259 rtx x
= avoid_constant_pool_reference (varloc
);
13261 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13266 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13273 if (GET_CODE (varloc
) == VAR_LOCATION
)
13274 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13276 mode
= DECL_MODE (loc
);
13277 descr
= loc_descriptor (varloc
, mode
, initialized
);
13284 if (want_address
== 2 && !have_address
13285 && (dwarf_version
>= 4 || !dwarf_strict
))
13287 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13289 expansion_failed (loc
, NULL_RTX
,
13290 "DWARF address size mismatch");
13293 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13296 /* Show if we can't fill the request for an address. */
13297 if (want_address
&& !have_address
)
13299 expansion_failed (loc
, NULL_RTX
,
13300 "Want address and only have value");
13304 /* If we've got an address and don't want one, dereference. */
13305 if (!want_address
&& have_address
)
13307 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13308 enum dwarf_location_atom op
;
13310 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13312 expansion_failed (loc
, NULL_RTX
,
13313 "DWARF address size mismatch");
13316 else if (size
== DWARF2_ADDR_SIZE
)
13319 op
= DW_OP_deref_size
;
13321 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13327 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13328 if it is not possible. */
13330 static dw_loc_descr_ref
13331 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13333 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13334 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13335 else if (dwarf_version
>= 3 || !dwarf_strict
)
13336 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13341 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13342 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13344 static dw_loc_descr_ref
13345 dw_sra_loc_expr (tree decl
, rtx loc
)
13348 unsigned int padsize
= 0;
13349 dw_loc_descr_ref descr
, *descr_tail
;
13350 unsigned HOST_WIDE_INT decl_size
;
13352 enum var_init_status initialized
;
13354 if (DECL_SIZE (decl
) == NULL
13355 || !host_integerp (DECL_SIZE (decl
), 1))
13358 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13360 descr_tail
= &descr
;
13362 for (p
= loc
; p
; p
= XEXP (p
, 1))
13364 unsigned int bitsize
= decl_piece_bitsize (p
);
13365 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13366 dw_loc_descr_ref cur_descr
;
13367 dw_loc_descr_ref
*tail
, last
= NULL
;
13368 unsigned int opsize
= 0;
13370 if (loc_note
== NULL_RTX
13371 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13373 padsize
+= bitsize
;
13376 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13377 varloc
= NOTE_VAR_LOCATION (loc_note
);
13378 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13379 if (cur_descr
== NULL
)
13381 padsize
+= bitsize
;
13385 /* Check that cur_descr either doesn't use
13386 DW_OP_*piece operations, or their sum is equal
13387 to bitsize. Otherwise we can't embed it. */
13388 for (tail
= &cur_descr
; *tail
!= NULL
;
13389 tail
= &(*tail
)->dw_loc_next
)
13390 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13392 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13396 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13398 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13402 if (last
!= NULL
&& opsize
!= bitsize
)
13404 padsize
+= bitsize
;
13408 /* If there is a hole, add DW_OP_*piece after empty DWARF
13409 expression, which means that those bits are optimized out. */
13412 if (padsize
> decl_size
)
13414 decl_size
-= padsize
;
13415 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13416 if (*descr_tail
== NULL
)
13418 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13421 *descr_tail
= cur_descr
;
13423 if (bitsize
> decl_size
)
13425 decl_size
-= bitsize
;
13428 HOST_WIDE_INT offset
= 0;
13429 if (GET_CODE (varloc
) == VAR_LOCATION
13430 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13432 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13433 if (GET_CODE (varloc
) == EXPR_LIST
)
13434 varloc
= XEXP (varloc
, 0);
13438 if (GET_CODE (varloc
) == CONST
13439 || GET_CODE (varloc
) == SIGN_EXTEND
13440 || GET_CODE (varloc
) == ZERO_EXTEND
)
13441 varloc
= XEXP (varloc
, 0);
13442 else if (GET_CODE (varloc
) == SUBREG
)
13443 varloc
= SUBREG_REG (varloc
);
13448 /* DW_OP_bit_size offset should be zero for register
13449 or implicit location descriptions and empty location
13450 descriptions, but for memory addresses needs big endian
13452 if (MEM_P (varloc
))
13454 unsigned HOST_WIDE_INT memsize
13455 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13456 if (memsize
!= bitsize
)
13458 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13459 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13461 if (memsize
< bitsize
)
13463 if (BITS_BIG_ENDIAN
)
13464 offset
= memsize
- bitsize
;
13468 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13469 if (*descr_tail
== NULL
)
13471 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13475 /* If there were any non-empty expressions, add padding till the end of
13477 if (descr
!= NULL
&& decl_size
!= 0)
13479 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13480 if (*descr_tail
== NULL
)
13486 /* Return the dwarf representation of the location list LOC_LIST of
13487 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13490 static dw_loc_list_ref
13491 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13493 const char *endname
, *secname
;
13495 enum var_init_status initialized
;
13496 struct var_loc_node
*node
;
13497 dw_loc_descr_ref descr
;
13498 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13499 dw_loc_list_ref list
= NULL
;
13500 dw_loc_list_ref
*listp
= &list
;
13502 /* Now that we know what section we are using for a base,
13503 actually construct the list of locations.
13504 The first location information is what is passed to the
13505 function that creates the location list, and the remaining
13506 locations just get added on to that list.
13507 Note that we only know the start address for a location
13508 (IE location changes), so to build the range, we use
13509 the range [current location start, next location start].
13510 This means we have to special case the last node, and generate
13511 a range of [last location start, end of function label]. */
13513 secname
= secname_for_decl (decl
);
13515 for (node
= loc_list
->first
; node
; node
= node
->next
)
13516 if (GET_CODE (node
->loc
) == EXPR_LIST
13517 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13519 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13521 /* This requires DW_OP_{,bit_}piece, which is not usable
13522 inside DWARF expressions. */
13523 if (want_address
!= 2)
13525 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13531 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13532 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13533 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13537 bool range_across_switch
= false;
13538 /* If section switch happens in between node->label
13539 and node->next->label (or end of function) and
13540 we can't emit it as a single entry list,
13541 emit two ranges, first one ending at the end
13542 of first partition and second one starting at the
13543 beginning of second partition. */
13544 if (node
== loc_list
->last_before_switch
13545 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13546 && current_function_decl
)
13548 endname
= cfun
->fde
->dw_fde_end
;
13549 range_across_switch
= true;
13551 /* The variable has a location between NODE->LABEL and
13552 NODE->NEXT->LABEL. */
13553 else if (node
->next
)
13554 endname
= node
->next
->label
;
13555 /* If the variable has a location at the last label
13556 it keeps its location until the end of function. */
13557 else if (!current_function_decl
)
13558 endname
= text_end_label
;
13561 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13562 current_function_funcdef_no
);
13563 endname
= ggc_strdup (label_id
);
13566 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13567 if (TREE_CODE (decl
) == PARM_DECL
13568 && node
== loc_list
->first
13569 && NOTE_P (node
->loc
)
13570 && strcmp (node
->label
, endname
) == 0)
13571 (*listp
)->force
= true;
13572 listp
= &(*listp
)->dw_loc_next
;
13574 if (range_across_switch
)
13576 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13577 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13580 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13581 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13582 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13585 gcc_assert (descr
);
13586 /* The variable has a location between NODE->LABEL and
13587 NODE->NEXT->LABEL. */
13589 endname
= node
->next
->label
;
13591 endname
= cfun
->fde
->dw_fde_second_end
;
13592 *listp
= new_loc_list (descr
,
13593 cfun
->fde
->dw_fde_second_begin
,
13595 listp
= &(*listp
)->dw_loc_next
;
13600 /* Try to avoid the overhead of a location list emitting a location
13601 expression instead, but only if we didn't have more than one
13602 location entry in the first place. If some entries were not
13603 representable, we don't want to pretend a single entry that was
13604 applies to the entire scope in which the variable is
13606 if (list
&& loc_list
->first
->next
)
13612 /* Return if the loc_list has only single element and thus can be represented
13613 as location description. */
13616 single_element_loc_list_p (dw_loc_list_ref list
)
13618 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13619 return !list
->ll_symbol
;
13622 /* To each location in list LIST add loc descr REF. */
13625 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13627 dw_loc_descr_ref copy
;
13628 add_loc_descr (&list
->expr
, ref
);
13629 list
= list
->dw_loc_next
;
13632 copy
= ggc_alloc_dw_loc_descr_node ();
13633 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13634 add_loc_descr (&list
->expr
, copy
);
13635 while (copy
->dw_loc_next
)
13637 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13638 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13639 copy
->dw_loc_next
= new_copy
;
13642 list
= list
->dw_loc_next
;
13646 /* Given two lists RET and LIST
13647 produce location list that is result of adding expression in LIST
13648 to expression in RET on each position in program.
13649 Might be destructive on both RET and LIST.
13651 TODO: We handle only simple cases of RET or LIST having at most one
13652 element. General case would inolve sorting the lists in program order
13653 and merging them that will need some additional work.
13654 Adding that will improve quality of debug info especially for SRA-ed
13658 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13667 if (!list
->dw_loc_next
)
13669 add_loc_descr_to_each (*ret
, list
->expr
);
13672 if (!(*ret
)->dw_loc_next
)
13674 add_loc_descr_to_each (list
, (*ret
)->expr
);
13678 expansion_failed (NULL_TREE
, NULL_RTX
,
13679 "Don't know how to merge two non-trivial"
13680 " location lists.\n");
13685 /* LOC is constant expression. Try a luck, look it up in constant
13686 pool and return its loc_descr of its address. */
13688 static dw_loc_descr_ref
13689 cst_pool_loc_descr (tree loc
)
13691 /* Get an RTL for this, if something has been emitted. */
13692 rtx rtl
= lookup_constant_def (loc
);
13694 if (!rtl
|| !MEM_P (rtl
))
13699 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13701 /* TODO: We might get more coverage if we was actually delaying expansion
13702 of all expressions till end of compilation when constant pools are fully
13704 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13706 expansion_failed (loc
, NULL_RTX
,
13707 "CST value in contant pool but not marked.");
13710 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13711 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13714 /* Return dw_loc_list representing address of addr_expr LOC
13715 by looking for inner INDIRECT_REF expression and turning
13716 it into simple arithmetics. */
13718 static dw_loc_list_ref
13719 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13722 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13723 enum machine_mode mode
;
13724 int unsignedp
, volatilep
= 0;
13725 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13727 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13728 &bitsize
, &bitpos
, &offset
, &mode
,
13729 &unsignedp
, &volatilep
, false);
13731 if (bitpos
% BITS_PER_UNIT
)
13733 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13736 if (!INDIRECT_REF_P (obj
))
13738 expansion_failed (obj
,
13739 NULL_RTX
, "no indirect ref in inner refrence");
13742 if (!offset
&& !bitpos
)
13743 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13745 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13746 && (dwarf_version
>= 4 || !dwarf_strict
))
13748 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13753 /* Variable offset. */
13754 list_ret1
= loc_list_from_tree (offset
, 0);
13755 if (list_ret1
== 0)
13757 add_loc_list (&list_ret
, list_ret1
);
13760 add_loc_descr_to_each (list_ret
,
13761 new_loc_descr (DW_OP_plus
, 0, 0));
13763 bytepos
= bitpos
/ BITS_PER_UNIT
;
13765 add_loc_descr_to_each (list_ret
,
13766 new_loc_descr (DW_OP_plus_uconst
,
13768 else if (bytepos
< 0)
13769 loc_list_plus_const (list_ret
, bytepos
);
13770 add_loc_descr_to_each (list_ret
,
13771 new_loc_descr (DW_OP_stack_value
, 0, 0));
13777 /* Generate Dwarf location list representing LOC.
13778 If WANT_ADDRESS is false, expression computing LOC will be computed
13779 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13780 if WANT_ADDRESS is 2, expression computing address useable in location
13781 will be returned (i.e. DW_OP_reg can be used
13782 to refer to register values). */
13784 static dw_loc_list_ref
13785 loc_list_from_tree (tree loc
, int want_address
)
13787 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13788 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13789 int have_address
= 0;
13790 enum dwarf_location_atom op
;
13792 /* ??? Most of the time we do not take proper care for sign/zero
13793 extending the values properly. Hopefully this won't be a real
13796 switch (TREE_CODE (loc
))
13799 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13802 case PLACEHOLDER_EXPR
:
13803 /* This case involves extracting fields from an object to determine the
13804 position of other fields. We don't try to encode this here. The
13805 only user of this is Ada, which encodes the needed information using
13806 the names of types. */
13807 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13811 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13812 /* There are no opcodes for these operations. */
13815 case PREINCREMENT_EXPR
:
13816 case PREDECREMENT_EXPR
:
13817 case POSTINCREMENT_EXPR
:
13818 case POSTDECREMENT_EXPR
:
13819 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13820 /* There are no opcodes for these operations. */
13824 /* If we already want an address, see if there is INDIRECT_REF inside
13825 e.g. for &this->field. */
13828 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13829 (loc
, want_address
== 2);
13832 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13833 && (ret
= cst_pool_loc_descr (loc
)))
13836 /* Otherwise, process the argument and look for the address. */
13837 if (!list_ret
&& !ret
)
13838 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13842 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13848 if (DECL_THREAD_LOCAL_P (loc
))
13851 enum dwarf_location_atom tls_op
;
13852 enum dtprel_bool dtprel
= dtprel_false
;
13854 if (targetm
.have_tls
)
13856 /* If this is not defined, we have no way to emit the
13858 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13861 /* The way DW_OP_GNU_push_tls_address is specified, we
13862 can only look up addresses of objects in the current
13863 module. We used DW_OP_addr as first op, but that's
13864 wrong, because DW_OP_addr is relocated by the debug
13865 info consumer, while DW_OP_GNU_push_tls_address
13866 operand shouldn't be. */
13867 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13869 dtprel
= dtprel_true
;
13870 tls_op
= DW_OP_GNU_push_tls_address
;
13874 if (!targetm
.emutls
.debug_form_tls_address
13875 || !(dwarf_version
>= 3 || !dwarf_strict
))
13877 /* We stuffed the control variable into the DECL_VALUE_EXPR
13878 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13879 no longer appear in gimple code. We used the control
13880 variable in specific so that we could pick it up here. */
13881 loc
= DECL_VALUE_EXPR (loc
);
13882 tls_op
= DW_OP_form_tls_address
;
13885 rtl
= rtl_for_decl_location (loc
);
13886 if (rtl
== NULL_RTX
)
13891 rtl
= XEXP (rtl
, 0);
13892 if (! CONSTANT_P (rtl
))
13895 ret
= new_addr_loc_descr (rtl
, dtprel
);
13896 ret1
= new_loc_descr (tls_op
, 0, 0);
13897 add_loc_descr (&ret
, ret1
);
13906 if (DECL_HAS_VALUE_EXPR_P (loc
))
13907 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13911 case FUNCTION_DECL
:
13914 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13916 if (loc_list
&& loc_list
->first
)
13918 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13919 have_address
= want_address
!= 0;
13922 rtl
= rtl_for_decl_location (loc
);
13923 if (rtl
== NULL_RTX
)
13925 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13928 else if (CONST_INT_P (rtl
))
13930 HOST_WIDE_INT val
= INTVAL (rtl
);
13931 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13932 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13933 ret
= int_loc_descriptor (val
);
13935 else if (GET_CODE (rtl
) == CONST_STRING
)
13937 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13940 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13941 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13944 enum machine_mode mode
, mem_mode
;
13946 /* Certain constructs can only be represented at top-level. */
13947 if (want_address
== 2)
13949 ret
= loc_descriptor (rtl
, VOIDmode
,
13950 VAR_INIT_STATUS_INITIALIZED
);
13955 mode
= GET_MODE (rtl
);
13956 mem_mode
= VOIDmode
;
13960 mode
= get_address_mode (rtl
);
13961 rtl
= XEXP (rtl
, 0);
13964 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13965 VAR_INIT_STATUS_INITIALIZED
);
13968 expansion_failed (loc
, rtl
,
13969 "failed to produce loc descriptor for rtl");
13976 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13980 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13984 case COMPOUND_EXPR
:
13985 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13988 case VIEW_CONVERT_EXPR
:
13991 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13993 case COMPONENT_REF
:
13994 case BIT_FIELD_REF
:
13996 case ARRAY_RANGE_REF
:
13997 case REALPART_EXPR
:
13998 case IMAGPART_EXPR
:
14001 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14002 enum machine_mode mode
;
14003 int unsignedp
, volatilep
= 0;
14005 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14006 &unsignedp
, &volatilep
, false);
14008 gcc_assert (obj
!= loc
);
14010 list_ret
= loc_list_from_tree (obj
,
14012 && !bitpos
&& !offset
? 2 : 1);
14013 /* TODO: We can extract value of the small expression via shifting even
14014 for nonzero bitpos. */
14017 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14019 expansion_failed (loc
, NULL_RTX
,
14020 "bitfield access");
14024 if (offset
!= NULL_TREE
)
14026 /* Variable offset. */
14027 list_ret1
= loc_list_from_tree (offset
, 0);
14028 if (list_ret1
== 0)
14030 add_loc_list (&list_ret
, list_ret1
);
14033 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14036 bytepos
= bitpos
/ BITS_PER_UNIT
;
14038 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14039 else if (bytepos
< 0)
14040 loc_list_plus_const (list_ret
, bytepos
);
14047 if ((want_address
|| !host_integerp (loc
, 0))
14048 && (ret
= cst_pool_loc_descr (loc
)))
14050 else if (want_address
== 2
14051 && host_integerp (loc
, 0)
14052 && (ret
= address_of_int_loc_descriptor
14053 (int_size_in_bytes (TREE_TYPE (loc
)),
14054 tree_low_cst (loc
, 0))))
14056 else if (host_integerp (loc
, 0))
14057 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14060 expansion_failed (loc
, NULL_RTX
,
14061 "Integer operand is not host integer");
14070 if ((ret
= cst_pool_loc_descr (loc
)))
14073 /* We can construct small constants here using int_loc_descriptor. */
14074 expansion_failed (loc
, NULL_RTX
,
14075 "constructor or constant not in constant pool");
14078 case TRUTH_AND_EXPR
:
14079 case TRUTH_ANDIF_EXPR
:
14084 case TRUTH_XOR_EXPR
:
14089 case TRUTH_OR_EXPR
:
14090 case TRUTH_ORIF_EXPR
:
14095 case FLOOR_DIV_EXPR
:
14096 case CEIL_DIV_EXPR
:
14097 case ROUND_DIV_EXPR
:
14098 case TRUNC_DIV_EXPR
:
14099 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14108 case FLOOR_MOD_EXPR
:
14109 case CEIL_MOD_EXPR
:
14110 case ROUND_MOD_EXPR
:
14111 case TRUNC_MOD_EXPR
:
14112 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14117 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14118 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14119 if (list_ret
== 0 || list_ret1
== 0)
14122 add_loc_list (&list_ret
, list_ret1
);
14125 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14126 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14127 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14128 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14129 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14141 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14144 case POINTER_PLUS_EXPR
:
14146 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14148 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14152 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14160 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14167 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14174 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14181 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14196 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14197 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14198 if (list_ret
== 0 || list_ret1
== 0)
14201 add_loc_list (&list_ret
, list_ret1
);
14204 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14207 case TRUTH_NOT_EXPR
:
14221 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14225 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14231 const enum tree_code code
=
14232 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14234 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14235 build2 (code
, integer_type_node
,
14236 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14237 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14240 /* ... fall through ... */
14244 dw_loc_descr_ref lhs
14245 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14246 dw_loc_list_ref rhs
14247 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14248 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14250 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14251 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14254 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14255 add_loc_descr_to_each (list_ret
, bra_node
);
14257 add_loc_list (&list_ret
, rhs
);
14258 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14259 add_loc_descr_to_each (list_ret
, jump_node
);
14261 add_loc_descr_to_each (list_ret
, lhs
);
14262 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14263 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14265 /* ??? Need a node to point the skip at. Use a nop. */
14266 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14267 add_loc_descr_to_each (list_ret
, tmp
);
14268 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14269 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14273 case FIX_TRUNC_EXPR
:
14277 /* Leave front-end specific codes as simply unknown. This comes
14278 up, for instance, with the C STMT_EXPR. */
14279 if ((unsigned int) TREE_CODE (loc
)
14280 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14282 expansion_failed (loc
, NULL_RTX
,
14283 "language specific tree node");
14287 #ifdef ENABLE_CHECKING
14288 /* Otherwise this is a generic code; we should just lists all of
14289 these explicitly. We forgot one. */
14290 gcc_unreachable ();
14292 /* In a release build, we want to degrade gracefully: better to
14293 generate incomplete debugging information than to crash. */
14298 if (!ret
&& !list_ret
)
14301 if (want_address
== 2 && !have_address
14302 && (dwarf_version
>= 4 || !dwarf_strict
))
14304 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14306 expansion_failed (loc
, NULL_RTX
,
14307 "DWARF address size mismatch");
14311 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14313 add_loc_descr_to_each (list_ret
,
14314 new_loc_descr (DW_OP_stack_value
, 0, 0));
14317 /* Show if we can't fill the request for an address. */
14318 if (want_address
&& !have_address
)
14320 expansion_failed (loc
, NULL_RTX
,
14321 "Want address and only have value");
14325 gcc_assert (!ret
|| !list_ret
);
14327 /* If we've got an address and don't want one, dereference. */
14328 if (!want_address
&& have_address
)
14330 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14332 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14334 expansion_failed (loc
, NULL_RTX
,
14335 "DWARF address size mismatch");
14338 else if (size
== DWARF2_ADDR_SIZE
)
14341 op
= DW_OP_deref_size
;
14344 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14346 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14349 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14354 /* Same as above but return only single location expression. */
14355 static dw_loc_descr_ref
14356 loc_descriptor_from_tree (tree loc
, int want_address
)
14358 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14361 if (ret
->dw_loc_next
)
14363 expansion_failed (loc
, NULL_RTX
,
14364 "Location list where only loc descriptor needed");
14370 /* Given a value, round it up to the lowest multiple of `boundary'
14371 which is not less than the value itself. */
14373 static inline HOST_WIDE_INT
14374 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14376 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14379 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14380 pointer to the declared type for the relevant field variable, or return
14381 `integer_type_node' if the given node turns out to be an
14382 ERROR_MARK node. */
14385 field_type (const_tree decl
)
14389 if (TREE_CODE (decl
) == ERROR_MARK
)
14390 return integer_type_node
;
14392 type
= DECL_BIT_FIELD_TYPE (decl
);
14393 if (type
== NULL_TREE
)
14394 type
= TREE_TYPE (decl
);
14399 /* Given a pointer to a tree node, return the alignment in bits for
14400 it, or else return BITS_PER_WORD if the node actually turns out to
14401 be an ERROR_MARK node. */
14403 static inline unsigned
14404 simple_type_align_in_bits (const_tree type
)
14406 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14409 static inline unsigned
14410 simple_decl_align_in_bits (const_tree decl
)
14412 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14415 /* Return the result of rounding T up to ALIGN. */
14417 static inline double_int
14418 round_up_to_align (double_int t
, unsigned int align
)
14420 double_int alignd
= double_int::from_uhwi (align
);
14422 t
+= double_int_minus_one
;
14423 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14428 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14429 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14430 or return 0 if we are unable to determine what that offset is, either
14431 because the argument turns out to be a pointer to an ERROR_MARK node, or
14432 because the offset is actually variable. (We can't handle the latter case
14435 static HOST_WIDE_INT
14436 field_byte_offset (const_tree decl
)
14438 double_int object_offset_in_bits
;
14439 double_int object_offset_in_bytes
;
14440 double_int bitpos_int
;
14442 if (TREE_CODE (decl
) == ERROR_MARK
)
14445 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14447 /* We cannot yet cope with fields whose positions are variable, so
14448 for now, when we see such things, we simply return 0. Someday, we may
14449 be able to handle such cases, but it will be damn difficult. */
14450 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14453 bitpos_int
= tree_to_double_int (bit_position (decl
));
14455 #ifdef PCC_BITFIELD_TYPE_MATTERS
14456 if (PCC_BITFIELD_TYPE_MATTERS
)
14459 tree field_size_tree
;
14460 double_int deepest_bitpos
;
14461 double_int field_size_in_bits
;
14462 unsigned int type_align_in_bits
;
14463 unsigned int decl_align_in_bits
;
14464 double_int type_size_in_bits
;
14466 type
= field_type (decl
);
14467 type_size_in_bits
= double_int_type_size_in_bits (type
);
14468 type_align_in_bits
= simple_type_align_in_bits (type
);
14470 field_size_tree
= DECL_SIZE (decl
);
14472 /* The size could be unspecified if there was an error, or for
14473 a flexible array member. */
14474 if (!field_size_tree
)
14475 field_size_tree
= bitsize_zero_node
;
14477 /* If the size of the field is not constant, use the type size. */
14478 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14479 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14481 field_size_in_bits
= type_size_in_bits
;
14483 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14485 /* The GCC front-end doesn't make any attempt to keep track of the
14486 starting bit offset (relative to the start of the containing
14487 structure type) of the hypothetical "containing object" for a
14488 bit-field. Thus, when computing the byte offset value for the
14489 start of the "containing object" of a bit-field, we must deduce
14490 this information on our own. This can be rather tricky to do in
14491 some cases. For example, handling the following structure type
14492 definition when compiling for an i386/i486 target (which only
14493 aligns long long's to 32-bit boundaries) can be very tricky:
14495 struct S { int field1; long long field2:31; };
14497 Fortunately, there is a simple rule-of-thumb which can be used
14498 in such cases. When compiling for an i386/i486, GCC will
14499 allocate 8 bytes for the structure shown above. It decides to
14500 do this based upon one simple rule for bit-field allocation.
14501 GCC allocates each "containing object" for each bit-field at
14502 the first (i.e. lowest addressed) legitimate alignment boundary
14503 (based upon the required minimum alignment for the declared
14504 type of the field) which it can possibly use, subject to the
14505 condition that there is still enough available space remaining
14506 in the containing object (when allocated at the selected point)
14507 to fully accommodate all of the bits of the bit-field itself.
14509 This simple rule makes it obvious why GCC allocates 8 bytes for
14510 each object of the structure type shown above. When looking
14511 for a place to allocate the "containing object" for `field2',
14512 the compiler simply tries to allocate a 64-bit "containing
14513 object" at each successive 32-bit boundary (starting at zero)
14514 until it finds a place to allocate that 64- bit field such that
14515 at least 31 contiguous (and previously unallocated) bits remain
14516 within that selected 64 bit field. (As it turns out, for the
14517 example above, the compiler finds it is OK to allocate the
14518 "containing object" 64-bit field at bit-offset zero within the
14521 Here we attempt to work backwards from the limited set of facts
14522 we're given, and we try to deduce from those facts, where GCC
14523 must have believed that the containing object started (within
14524 the structure type). The value we deduce is then used (by the
14525 callers of this routine) to generate DW_AT_location and
14526 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14527 the case of DW_AT_location, regular fields as well). */
14529 /* Figure out the bit-distance from the start of the structure to
14530 the "deepest" bit of the bit-field. */
14531 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14533 /* This is the tricky part. Use some fancy footwork to deduce
14534 where the lowest addressed bit of the containing object must
14536 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14538 /* Round up to type_align by default. This works best for
14540 object_offset_in_bits
14541 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14543 if (object_offset_in_bits
.ugt (bitpos_int
))
14545 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14547 /* Round up to decl_align instead. */
14548 object_offset_in_bits
14549 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14553 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14554 object_offset_in_bits
= bitpos_int
;
14556 object_offset_in_bytes
14557 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14558 true, TRUNC_DIV_EXPR
);
14559 return object_offset_in_bytes
.to_shwi ();
14562 /* The following routines define various Dwarf attributes and any data
14563 associated with them. */
14565 /* Add a location description attribute value to a DIE.
14567 This emits location attributes suitable for whole variables and
14568 whole parameters. Note that the location attributes for struct fields are
14569 generated by the routine `data_member_location_attribute' below. */
14572 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14573 dw_loc_list_ref descr
)
14577 if (single_element_loc_list_p (descr
))
14578 add_AT_loc (die
, attr_kind
, descr
->expr
);
14580 add_AT_loc_list (die
, attr_kind
, descr
);
14583 /* Add DW_AT_accessibility attribute to DIE if needed. */
14586 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14588 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14589 children, otherwise the default is DW_ACCESS_public. In DWARF2
14590 the default has always been DW_ACCESS_public. */
14591 if (TREE_PROTECTED (decl
))
14592 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14593 else if (TREE_PRIVATE (decl
))
14595 if (dwarf_version
== 2
14596 || die
->die_parent
== NULL
14597 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14598 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14600 else if (dwarf_version
> 2
14602 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14603 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14606 /* Attach the specialized form of location attribute used for data members of
14607 struct and union types. In the special case of a FIELD_DECL node which
14608 represents a bit-field, the "offset" part of this special location
14609 descriptor must indicate the distance in bytes from the lowest-addressed
14610 byte of the containing struct or union type to the lowest-addressed byte of
14611 the "containing object" for the bit-field. (See the `field_byte_offset'
14614 For any given bit-field, the "containing object" is a hypothetical object
14615 (of some integral or enum type) within which the given bit-field lives. The
14616 type of this hypothetical "containing object" is always the same as the
14617 declared type of the individual bit-field itself (for GCC anyway... the
14618 DWARF spec doesn't actually mandate this). Note that it is the size (in
14619 bytes) of the hypothetical "containing object" which will be given in the
14620 DW_AT_byte_size attribute for this bit-field. (See the
14621 `byte_size_attribute' function below.) It is also used when calculating the
14622 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14623 function below.) */
14626 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14628 HOST_WIDE_INT offset
;
14629 dw_loc_descr_ref loc_descr
= 0;
14631 if (TREE_CODE (decl
) == TREE_BINFO
)
14633 /* We're working on the TAG_inheritance for a base class. */
14634 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14636 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14637 aren't at a fixed offset from all (sub)objects of the same
14638 type. We need to extract the appropriate offset from our
14639 vtable. The following dwarf expression means
14641 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14643 This is specific to the V3 ABI, of course. */
14645 dw_loc_descr_ref tmp
;
14647 /* Make a copy of the object address. */
14648 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14649 add_loc_descr (&loc_descr
, tmp
);
14651 /* Extract the vtable address. */
14652 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14653 add_loc_descr (&loc_descr
, tmp
);
14655 /* Calculate the address of the offset. */
14656 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14657 gcc_assert (offset
< 0);
14659 tmp
= int_loc_descriptor (-offset
);
14660 add_loc_descr (&loc_descr
, tmp
);
14661 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14662 add_loc_descr (&loc_descr
, tmp
);
14664 /* Extract the offset. */
14665 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14666 add_loc_descr (&loc_descr
, tmp
);
14668 /* Add it to the object address. */
14669 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14670 add_loc_descr (&loc_descr
, tmp
);
14673 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14676 offset
= field_byte_offset (decl
);
14680 if (dwarf_version
> 2)
14682 /* Don't need to output a location expression, just the constant. */
14684 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14686 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14691 enum dwarf_location_atom op
;
14693 /* The DWARF2 standard says that we should assume that the structure
14694 address is already on the stack, so we can specify a structure
14695 field address by using DW_OP_plus_uconst. */
14696 op
= DW_OP_plus_uconst
;
14697 loc_descr
= new_loc_descr (op
, offset
, 0);
14701 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14704 /* Writes integer values to dw_vec_const array. */
14707 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14711 *dest
++ = val
& 0xff;
14717 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14719 static HOST_WIDE_INT
14720 extract_int (const unsigned char *src
, unsigned int size
)
14722 HOST_WIDE_INT val
= 0;
14728 val
|= *--src
& 0xff;
14734 /* Writes double_int values to dw_vec_const array. */
14737 insert_double (double_int val
, unsigned char *dest
)
14739 unsigned char *p0
= dest
;
14740 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14742 if (WORDS_BIG_ENDIAN
)
14748 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14749 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14752 /* Writes floating point values to dw_vec_const array. */
14755 insert_float (const_rtx rtl
, unsigned char *array
)
14757 REAL_VALUE_TYPE rv
;
14761 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14762 real_to_target (val
, &rv
, GET_MODE (rtl
));
14764 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14765 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14767 insert_int (val
[i
], 4, array
);
14772 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14773 does not have a "location" either in memory or in a register. These
14774 things can arise in GNU C when a constant is passed as an actual parameter
14775 to an inlined function. They can also arise in C++ where declared
14776 constants do not necessarily get memory "homes". */
14779 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14781 switch (GET_CODE (rtl
))
14785 HOST_WIDE_INT val
= INTVAL (rtl
);
14788 add_AT_int (die
, DW_AT_const_value
, val
);
14790 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14795 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14796 floating-point constant. A CONST_DOUBLE is used whenever the
14797 constant requires more than one word in order to be adequately
14800 enum machine_mode mode
= GET_MODE (rtl
);
14802 if (SCALAR_FLOAT_MODE_P (mode
))
14804 unsigned int length
= GET_MODE_SIZE (mode
);
14805 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14807 insert_float (rtl
, array
);
14808 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14811 add_AT_double (die
, DW_AT_const_value
,
14812 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14818 enum machine_mode mode
= GET_MODE (rtl
);
14819 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14820 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14821 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14822 (length
* elt_size
);
14826 switch (GET_MODE_CLASS (mode
))
14828 case MODE_VECTOR_INT
:
14829 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14831 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14832 double_int val
= rtx_to_double_int (elt
);
14834 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14835 insert_int (val
.to_shwi (), elt_size
, p
);
14838 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14839 insert_double (val
, p
);
14844 case MODE_VECTOR_FLOAT
:
14845 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14847 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14848 insert_float (elt
, p
);
14853 gcc_unreachable ();
14856 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14861 if (dwarf_version
>= 4 || !dwarf_strict
)
14863 dw_loc_descr_ref loc_result
;
14864 resolve_one_addr (&rtl
, NULL
);
14866 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14867 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14868 add_AT_loc (die
, DW_AT_location
, loc_result
);
14869 vec_safe_push (used_rtx_array
, rtl
);
14875 if (CONSTANT_P (XEXP (rtl
, 0)))
14876 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14879 if (!const_ok_for_output (rtl
))
14882 if (dwarf_version
>= 4 || !dwarf_strict
)
14887 /* In cases where an inlined instance of an inline function is passed
14888 the address of an `auto' variable (which is local to the caller) we
14889 can get a situation where the DECL_RTL of the artificial local
14890 variable (for the inlining) which acts as a stand-in for the
14891 corresponding formal parameter (of the inline function) will look
14892 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14893 exactly a compile-time constant expression, but it isn't the address
14894 of the (artificial) local variable either. Rather, it represents the
14895 *value* which the artificial local variable always has during its
14896 lifetime. We currently have no way to represent such quasi-constant
14897 values in Dwarf, so for now we just punt and generate nothing. */
14905 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14906 && MEM_READONLY_P (rtl
)
14907 && GET_MODE (rtl
) == BLKmode
)
14909 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14915 /* No other kinds of rtx should be possible here. */
14916 gcc_unreachable ();
14921 /* Determine whether the evaluation of EXPR references any variables
14922 or functions which aren't otherwise used (and therefore may not be
14925 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14926 void * data ATTRIBUTE_UNUSED
)
14928 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14929 *walk_subtrees
= 0;
14931 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14932 && ! TREE_ASM_WRITTEN (*tp
))
14934 /* ??? The C++ FE emits debug information for using decls, so
14935 putting gcc_unreachable here falls over. See PR31899. For now
14936 be conservative. */
14937 else if (!cgraph_global_info_ready
14938 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14940 else if (TREE_CODE (*tp
) == VAR_DECL
)
14942 struct varpool_node
*node
= varpool_get_node (*tp
);
14943 if (!node
|| !node
->symbol
.definition
)
14946 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14947 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14949 /* The call graph machinery must have finished analyzing,
14950 optimizing and gimplifying the CU by now.
14951 So if *TP has no call graph node associated
14952 to it, it means *TP will not be emitted. */
14953 if (!cgraph_get_node (*tp
))
14956 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14962 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14963 for use in a later add_const_value_attribute call. */
14966 rtl_for_decl_init (tree init
, tree type
)
14968 rtx rtl
= NULL_RTX
;
14972 /* If a variable is initialized with a string constant without embedded
14973 zeros, build CONST_STRING. */
14974 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14976 tree enttype
= TREE_TYPE (type
);
14977 tree domain
= TYPE_DOMAIN (type
);
14978 enum machine_mode mode
= TYPE_MODE (enttype
);
14980 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14982 && integer_zerop (TYPE_MIN_VALUE (domain
))
14983 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14984 TREE_STRING_LENGTH (init
) - 1) == 0
14985 && ((size_t) TREE_STRING_LENGTH (init
)
14986 == strlen (TREE_STRING_POINTER (init
)) + 1))
14988 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14989 ggc_strdup (TREE_STRING_POINTER (init
)));
14990 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14991 MEM_READONLY_P (rtl
) = 1;
14994 /* Other aggregates, and complex values, could be represented using
14996 else if (AGGREGATE_TYPE_P (type
)
14997 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14998 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14999 || TREE_CODE (type
) == COMPLEX_TYPE
)
15001 /* Vectors only work if their mode is supported by the target.
15002 FIXME: generic vectors ought to work too. */
15003 else if (TREE_CODE (type
) == VECTOR_TYPE
15004 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15006 /* If the initializer is something that we know will expand into an
15007 immediate RTL constant, expand it now. We must be careful not to
15008 reference variables which won't be output. */
15009 else if (initializer_constant_valid_p (init
, type
)
15010 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15012 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15014 if (TREE_CODE (type
) == VECTOR_TYPE
)
15015 switch (TREE_CODE (init
))
15020 if (TREE_CONSTANT (init
))
15022 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15023 bool constant_p
= true;
15025 unsigned HOST_WIDE_INT ix
;
15027 /* Even when ctor is constant, it might contain non-*_CST
15028 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15029 belong into VECTOR_CST nodes. */
15030 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15031 if (!CONSTANT_CLASS_P (value
))
15033 constant_p
= false;
15039 init
= build_vector_from_ctor (type
, elts
);
15049 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15051 /* If expand_expr returns a MEM, it wasn't immediate. */
15052 gcc_assert (!rtl
|| !MEM_P (rtl
));
15058 /* Generate RTL for the variable DECL to represent its location. */
15061 rtl_for_decl_location (tree decl
)
15065 /* Here we have to decide where we are going to say the parameter "lives"
15066 (as far as the debugger is concerned). We only have a couple of
15067 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15069 DECL_RTL normally indicates where the parameter lives during most of the
15070 activation of the function. If optimization is enabled however, this
15071 could be either NULL or else a pseudo-reg. Both of those cases indicate
15072 that the parameter doesn't really live anywhere (as far as the code
15073 generation parts of GCC are concerned) during most of the function's
15074 activation. That will happen (for example) if the parameter is never
15075 referenced within the function.
15077 We could just generate a location descriptor here for all non-NULL
15078 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15079 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15080 where DECL_RTL is NULL or is a pseudo-reg.
15082 Note however that we can only get away with using DECL_INCOMING_RTL as
15083 a backup substitute for DECL_RTL in certain limited cases. In cases
15084 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15085 we can be sure that the parameter was passed using the same type as it is
15086 declared to have within the function, and that its DECL_INCOMING_RTL
15087 points us to a place where a value of that type is passed.
15089 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15090 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15091 because in these cases DECL_INCOMING_RTL points us to a value of some
15092 type which is *different* from the type of the parameter itself. Thus,
15093 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15094 such cases, the debugger would end up (for example) trying to fetch a
15095 `float' from a place which actually contains the first part of a
15096 `double'. That would lead to really incorrect and confusing
15097 output at debug-time.
15099 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15100 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15101 are a couple of exceptions however. On little-endian machines we can
15102 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15103 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15104 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15105 when (on a little-endian machine) a non-prototyped function has a
15106 parameter declared to be of type `short' or `char'. In such cases,
15107 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15108 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15109 passed `int' value. If the debugger then uses that address to fetch
15110 a `short' or a `char' (on a little-endian machine) the result will be
15111 the correct data, so we allow for such exceptional cases below.
15113 Note that our goal here is to describe the place where the given formal
15114 parameter lives during most of the function's activation (i.e. between the
15115 end of the prologue and the start of the epilogue). We'll do that as best
15116 as we can. Note however that if the given formal parameter is modified
15117 sometime during the execution of the function, then a stack backtrace (at
15118 debug-time) will show the function as having been called with the *new*
15119 value rather than the value which was originally passed in. This happens
15120 rarely enough that it is not a major problem, but it *is* a problem, and
15121 I'd like to fix it.
15123 A future version of dwarf2out.c may generate two additional attributes for
15124 any given DW_TAG_formal_parameter DIE which will describe the "passed
15125 type" and the "passed location" for the given formal parameter in addition
15126 to the attributes we now generate to indicate the "declared type" and the
15127 "active location" for each parameter. This additional set of attributes
15128 could be used by debuggers for stack backtraces. Separately, note that
15129 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15130 This happens (for example) for inlined-instances of inline function formal
15131 parameters which are never referenced. This really shouldn't be
15132 happening. All PARM_DECL nodes should get valid non-NULL
15133 DECL_INCOMING_RTL values. FIXME. */
15135 /* Use DECL_RTL as the "location" unless we find something better. */
15136 rtl
= DECL_RTL_IF_SET (decl
);
15138 /* When generating abstract instances, ignore everything except
15139 constants, symbols living in memory, and symbols living in
15140 fixed registers. */
15141 if (! reload_completed
)
15144 && (CONSTANT_P (rtl
)
15146 && CONSTANT_P (XEXP (rtl
, 0)))
15148 && TREE_CODE (decl
) == VAR_DECL
15149 && TREE_STATIC (decl
))))
15151 rtl
= targetm
.delegitimize_address (rtl
);
15156 else if (TREE_CODE (decl
) == PARM_DECL
)
15158 if (rtl
== NULL_RTX
15159 || is_pseudo_reg (rtl
)
15161 && is_pseudo_reg (XEXP (rtl
, 0))
15162 && DECL_INCOMING_RTL (decl
)
15163 && MEM_P (DECL_INCOMING_RTL (decl
))
15164 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15166 tree declared_type
= TREE_TYPE (decl
);
15167 tree passed_type
= DECL_ARG_TYPE (decl
);
15168 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15169 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15171 /* This decl represents a formal parameter which was optimized out.
15172 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15173 all cases where (rtl == NULL_RTX) just below. */
15174 if (dmode
== pmode
)
15175 rtl
= DECL_INCOMING_RTL (decl
);
15176 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15177 && SCALAR_INT_MODE_P (dmode
)
15178 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15179 && DECL_INCOMING_RTL (decl
))
15181 rtx inc
= DECL_INCOMING_RTL (decl
);
15184 else if (MEM_P (inc
))
15186 if (BYTES_BIG_ENDIAN
)
15187 rtl
= adjust_address_nv (inc
, dmode
,
15188 GET_MODE_SIZE (pmode
)
15189 - GET_MODE_SIZE (dmode
));
15196 /* If the parm was passed in registers, but lives on the stack, then
15197 make a big endian correction if the mode of the type of the
15198 parameter is not the same as the mode of the rtl. */
15199 /* ??? This is the same series of checks that are made in dbxout.c before
15200 we reach the big endian correction code there. It isn't clear if all
15201 of these checks are necessary here, but keeping them all is the safe
15203 else if (MEM_P (rtl
)
15204 && XEXP (rtl
, 0) != const0_rtx
15205 && ! CONSTANT_P (XEXP (rtl
, 0))
15206 /* Not passed in memory. */
15207 && !MEM_P (DECL_INCOMING_RTL (decl
))
15208 /* Not passed by invisible reference. */
15209 && (!REG_P (XEXP (rtl
, 0))
15210 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15211 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15212 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15213 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15216 /* Big endian correction check. */
15217 && BYTES_BIG_ENDIAN
15218 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15219 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15222 enum machine_mode addr_mode
= get_address_mode (rtl
);
15223 int offset
= (UNITS_PER_WORD
15224 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15226 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15227 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15230 else if (TREE_CODE (decl
) == VAR_DECL
15233 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15234 && BYTES_BIG_ENDIAN
)
15236 enum machine_mode addr_mode
= get_address_mode (rtl
);
15237 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15238 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15240 /* If a variable is declared "register" yet is smaller than
15241 a register, then if we store the variable to memory, it
15242 looks like we're storing a register-sized value, when in
15243 fact we are not. We need to adjust the offset of the
15244 storage location to reflect the actual value's bytes,
15245 else gdb will not be able to display it. */
15247 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15248 plus_constant (addr_mode
, XEXP (rtl
, 0),
15252 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15253 and will have been substituted directly into all expressions that use it.
15254 C does not have such a concept, but C++ and other languages do. */
15255 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15256 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15259 rtl
= targetm
.delegitimize_address (rtl
);
15261 /* If we don't look past the constant pool, we risk emitting a
15262 reference to a constant pool entry that isn't referenced from
15263 code, and thus is not emitted. */
15265 rtl
= avoid_constant_pool_reference (rtl
);
15267 /* Try harder to get a rtl. If this symbol ends up not being emitted
15268 in the current CU, resolve_addr will remove the expression referencing
15270 if (rtl
== NULL_RTX
15271 && TREE_CODE (decl
) == VAR_DECL
15272 && !DECL_EXTERNAL (decl
)
15273 && TREE_STATIC (decl
)
15274 && DECL_NAME (decl
)
15275 && !DECL_HARD_REGISTER (decl
)
15276 && DECL_MODE (decl
) != VOIDmode
)
15278 rtl
= make_decl_rtl_for_debug (decl
);
15280 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15281 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15288 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15289 returned. If so, the decl for the COMMON block is returned, and the
15290 value is the offset into the common block for the symbol. */
15293 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15295 tree val_expr
, cvar
;
15296 enum machine_mode mode
;
15297 HOST_WIDE_INT bitsize
, bitpos
;
15299 int unsignedp
, volatilep
= 0;
15301 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15302 it does not have a value (the offset into the common area), or if it
15303 is thread local (as opposed to global) then it isn't common, and shouldn't
15304 be handled as such. */
15305 if (TREE_CODE (decl
) != VAR_DECL
15306 || !TREE_STATIC (decl
)
15307 || !DECL_HAS_VALUE_EXPR_P (decl
)
15311 val_expr
= DECL_VALUE_EXPR (decl
);
15312 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15315 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15316 &mode
, &unsignedp
, &volatilep
, true);
15318 if (cvar
== NULL_TREE
15319 || TREE_CODE (cvar
) != VAR_DECL
15320 || DECL_ARTIFICIAL (cvar
)
15321 || !TREE_PUBLIC (cvar
))
15325 if (offset
!= NULL
)
15327 if (!host_integerp (offset
, 0))
15329 *value
= tree_low_cst (offset
, 0);
15332 *value
+= bitpos
/ BITS_PER_UNIT
;
15337 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15338 data attribute for a variable or a parameter. We generate the
15339 DW_AT_const_value attribute only in those cases where the given variable
15340 or parameter does not have a true "location" either in memory or in a
15341 register. This can happen (for example) when a constant is passed as an
15342 actual argument in a call to an inline function. (It's possible that
15343 these things can crop up in other ways also.) Note that one type of
15344 constant value which can be passed into an inlined function is a constant
15345 pointer. This can happen for example if an actual argument in an inlined
15346 function call evaluates to a compile-time constant address.
15348 CACHE_P is true if it is worth caching the location list for DECL,
15349 so that future calls can reuse it rather than regenerate it from scratch.
15350 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15351 since we will need to refer to them each time the function is inlined. */
15354 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15355 enum dwarf_attribute attr
)
15358 dw_loc_list_ref list
;
15359 var_loc_list
*loc_list
;
15360 cached_dw_loc_list
*cache
;
15363 if (TREE_CODE (decl
) == ERROR_MARK
)
15366 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15367 || TREE_CODE (decl
) == RESULT_DECL
);
15369 /* Try to get some constant RTL for this decl, and use that as the value of
15372 rtl
= rtl_for_decl_location (decl
);
15373 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15374 && add_const_value_attribute (die
, rtl
))
15377 /* See if we have single element location list that is equivalent to
15378 a constant value. That way we are better to use add_const_value_attribute
15379 rather than expanding constant value equivalent. */
15380 loc_list
= lookup_decl_loc (decl
);
15383 && loc_list
->first
->next
== NULL
15384 && NOTE_P (loc_list
->first
->loc
)
15385 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15386 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15388 struct var_loc_node
*node
;
15390 node
= loc_list
->first
;
15391 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15392 if (GET_CODE (rtl
) == EXPR_LIST
)
15393 rtl
= XEXP (rtl
, 0);
15394 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15395 && add_const_value_attribute (die
, rtl
))
15398 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15399 list several times. See if we've already cached the contents. */
15401 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15405 cache
= (cached_dw_loc_list
*)
15406 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15408 list
= cache
->loc_list
;
15412 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15413 /* It is usually worth caching this result if the decl is from
15414 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15415 if (cache_p
&& list
&& list
->dw_loc_next
)
15417 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15418 DECL_UID (decl
), INSERT
);
15419 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15420 cache
->decl_id
= DECL_UID (decl
);
15421 cache
->loc_list
= list
;
15427 add_AT_location_description (die
, attr
, list
);
15430 /* None of that worked, so it must not really have a location;
15431 try adding a constant value attribute from the DECL_INITIAL. */
15432 return tree_add_const_value_attribute_for_decl (die
, decl
);
15435 /* Add VARIABLE and DIE into deferred locations list. */
15438 defer_location (tree variable
, dw_die_ref die
)
15440 deferred_locations entry
;
15441 entry
.variable
= variable
;
15443 vec_safe_push (deferred_locations_list
, entry
);
15446 /* Helper function for tree_add_const_value_attribute. Natively encode
15447 initializer INIT into an array. Return true if successful. */
15450 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15454 if (init
== NULL_TREE
)
15458 switch (TREE_CODE (init
))
15461 type
= TREE_TYPE (init
);
15462 if (TREE_CODE (type
) == ARRAY_TYPE
)
15464 tree enttype
= TREE_TYPE (type
);
15465 enum machine_mode mode
= TYPE_MODE (enttype
);
15467 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15469 if (int_size_in_bytes (type
) != size
)
15471 if (size
> TREE_STRING_LENGTH (init
))
15473 memcpy (array
, TREE_STRING_POINTER (init
),
15474 TREE_STRING_LENGTH (init
));
15475 memset (array
+ TREE_STRING_LENGTH (init
),
15476 '\0', size
- TREE_STRING_LENGTH (init
));
15479 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15484 type
= TREE_TYPE (init
);
15485 if (int_size_in_bytes (type
) != size
)
15487 if (TREE_CODE (type
) == ARRAY_TYPE
)
15489 HOST_WIDE_INT min_index
;
15490 unsigned HOST_WIDE_INT cnt
;
15491 int curpos
= 0, fieldsize
;
15492 constructor_elt
*ce
;
15494 if (TYPE_DOMAIN (type
) == NULL_TREE
15495 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15498 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15499 if (fieldsize
<= 0)
15502 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15503 memset (array
, '\0', size
);
15504 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15506 tree val
= ce
->value
;
15507 tree index
= ce
->index
;
15509 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15510 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15513 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15518 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15521 curpos
= pos
+ fieldsize
;
15522 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15524 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15525 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15526 while (count
-- > 0)
15529 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15530 curpos
+= fieldsize
;
15533 gcc_assert (curpos
<= size
);
15537 else if (TREE_CODE (type
) == RECORD_TYPE
15538 || TREE_CODE (type
) == UNION_TYPE
)
15540 tree field
= NULL_TREE
;
15541 unsigned HOST_WIDE_INT cnt
;
15542 constructor_elt
*ce
;
15544 if (int_size_in_bytes (type
) != size
)
15547 if (TREE_CODE (type
) == RECORD_TYPE
)
15548 field
= TYPE_FIELDS (type
);
15550 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15552 tree val
= ce
->value
;
15553 int pos
, fieldsize
;
15555 if (ce
->index
!= 0)
15561 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15564 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15565 && TYPE_DOMAIN (TREE_TYPE (field
))
15566 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15568 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15569 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15571 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15572 pos
= int_byte_position (field
);
15573 gcc_assert (pos
+ fieldsize
<= size
);
15575 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15581 case VIEW_CONVERT_EXPR
:
15582 case NON_LVALUE_EXPR
:
15583 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15585 return native_encode_expr (init
, array
, size
) == size
;
15589 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15590 attribute is the const value T. */
15593 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15596 tree type
= TREE_TYPE (t
);
15599 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15603 gcc_assert (!DECL_P (init
));
15605 rtl
= rtl_for_decl_init (init
, type
);
15607 return add_const_value_attribute (die
, rtl
);
15608 /* If the host and target are sane, try harder. */
15609 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15610 && initializer_constant_valid_p (init
, type
))
15612 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15613 if (size
> 0 && (int) size
== size
)
15615 unsigned char *array
= (unsigned char *)
15616 ggc_alloc_cleared_atomic (size
);
15618 if (native_encode_initializer (init
, array
, size
))
15620 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15629 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15630 attribute is the const value of T, where T is an integral constant
15631 variable with static storage duration
15632 (so it can't be a PARM_DECL or a RESULT_DECL). */
15635 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15639 || (TREE_CODE (decl
) != VAR_DECL
15640 && TREE_CODE (decl
) != CONST_DECL
)
15641 || (TREE_CODE (decl
) == VAR_DECL
15642 && !TREE_STATIC (decl
)))
15645 if (TREE_READONLY (decl
)
15646 && ! TREE_THIS_VOLATILE (decl
)
15647 && DECL_INITIAL (decl
))
15652 /* Don't add DW_AT_const_value if abstract origin already has one. */
15653 if (get_AT (var_die
, DW_AT_const_value
))
15656 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15659 /* Convert the CFI instructions for the current function into a
15660 location list. This is used for DW_AT_frame_base when we targeting
15661 a dwarf2 consumer that does not support the dwarf3
15662 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15665 static dw_loc_list_ref
15666 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15670 dw_loc_list_ref list
, *list_tail
;
15672 dw_cfa_location last_cfa
, next_cfa
;
15673 const char *start_label
, *last_label
, *section
;
15674 dw_cfa_location remember
;
15677 gcc_assert (fde
!= NULL
);
15679 section
= secname_for_decl (current_function_decl
);
15683 memset (&next_cfa
, 0, sizeof (next_cfa
));
15684 next_cfa
.reg
= INVALID_REGNUM
;
15685 remember
= next_cfa
;
15687 start_label
= fde
->dw_fde_begin
;
15689 /* ??? Bald assumption that the CIE opcode list does not contain
15690 advance opcodes. */
15691 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15692 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15694 last_cfa
= next_cfa
;
15695 last_label
= start_label
;
15697 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15699 /* If the first partition contained no CFI adjustments, the
15700 CIE opcodes apply to the whole first partition. */
15701 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15702 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15703 list_tail
=&(*list_tail
)->dw_loc_next
;
15704 start_label
= last_label
= fde
->dw_fde_second_begin
;
15707 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15709 switch (cfi
->dw_cfi_opc
)
15711 case DW_CFA_set_loc
:
15712 case DW_CFA_advance_loc1
:
15713 case DW_CFA_advance_loc2
:
15714 case DW_CFA_advance_loc4
:
15715 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15717 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15718 start_label
, last_label
, section
);
15720 list_tail
= &(*list_tail
)->dw_loc_next
;
15721 last_cfa
= next_cfa
;
15722 start_label
= last_label
;
15724 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15727 case DW_CFA_advance_loc
:
15728 /* The encoding is complex enough that we should never emit this. */
15729 gcc_unreachable ();
15732 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15735 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15737 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15739 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15740 start_label
, last_label
, section
);
15742 list_tail
= &(*list_tail
)->dw_loc_next
;
15743 last_cfa
= next_cfa
;
15744 start_label
= last_label
;
15746 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15747 start_label
, fde
->dw_fde_end
, section
);
15748 list_tail
= &(*list_tail
)->dw_loc_next
;
15749 start_label
= last_label
= fde
->dw_fde_second_begin
;
15753 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15755 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15756 start_label
, last_label
, section
);
15757 list_tail
= &(*list_tail
)->dw_loc_next
;
15758 start_label
= last_label
;
15761 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15763 fde
->dw_fde_second_begin
15764 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15767 if (list
&& list
->dw_loc_next
)
15773 /* Compute a displacement from the "steady-state frame pointer" to the
15774 frame base (often the same as the CFA), and store it in
15775 frame_pointer_fb_offset. OFFSET is added to the displacement
15776 before the latter is negated. */
15779 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15783 #ifdef FRAME_POINTER_CFA_OFFSET
15784 reg
= frame_pointer_rtx
;
15785 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15787 reg
= arg_pointer_rtx
;
15788 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15791 elim
= (ira_use_lra_p
15792 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15793 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15794 if (GET_CODE (elim
) == PLUS
)
15796 offset
+= INTVAL (XEXP (elim
, 1));
15797 elim
= XEXP (elim
, 0);
15800 frame_pointer_fb_offset
= -offset
;
15802 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15803 in which to eliminate. This is because it's stack pointer isn't
15804 directly accessible as a register within the ISA. To work around
15805 this, assume that while we cannot provide a proper value for
15806 frame_pointer_fb_offset, we won't need one either. */
15807 frame_pointer_fb_offset_valid
15808 = ((SUPPORTS_STACK_ALIGNMENT
15809 && (elim
== hard_frame_pointer_rtx
15810 || elim
== stack_pointer_rtx
))
15811 || elim
== (frame_pointer_needed
15812 ? hard_frame_pointer_rtx
15813 : stack_pointer_rtx
));
15816 /* Generate a DW_AT_name attribute given some string value to be included as
15817 the value of the attribute. */
15820 add_name_attribute (dw_die_ref die
, const char *name_string
)
15822 if (name_string
!= NULL
&& *name_string
!= 0)
15824 if (demangle_name_func
)
15825 name_string
= (*demangle_name_func
) (name_string
);
15827 add_AT_string (die
, DW_AT_name
, name_string
);
15831 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15832 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15833 of TYPE accordingly.
15835 ??? This is a temporary measure until after we're able to generate
15836 regular DWARF for the complex Ada type system. */
15839 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15840 dw_die_ref context_die
)
15843 dw_die_ref dtype_die
;
15845 if (!lang_hooks
.types
.descriptive_type
)
15848 dtype
= lang_hooks
.types
.descriptive_type (type
);
15852 dtype_die
= lookup_type_die (dtype
);
15855 gen_type_die (dtype
, context_die
);
15856 dtype_die
= lookup_type_die (dtype
);
15857 gcc_assert (dtype_die
);
15860 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15863 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
15865 static const char *
15866 comp_dir_string (void)
15870 static const char *cached_wd
= NULL
;
15872 if (cached_wd
!= NULL
)
15875 wd
= get_src_pwd ();
15879 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15883 wdlen
= strlen (wd
);
15884 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15886 wd1
[wdlen
] = DIR_SEPARATOR
;
15887 wd1
[wdlen
+ 1] = 0;
15891 cached_wd
= remap_debug_filename (wd
);
15895 /* Generate a DW_AT_comp_dir attribute for DIE. */
15898 add_comp_dir_attribute (dw_die_ref die
)
15900 const char * wd
= comp_dir_string ();
15902 add_AT_string (die
, DW_AT_comp_dir
, wd
);
15905 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15909 lower_bound_default (void)
15911 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15916 case DW_LANG_C_plus_plus
:
15918 case DW_LANG_ObjC_plus_plus
:
15921 case DW_LANG_Fortran77
:
15922 case DW_LANG_Fortran90
:
15923 case DW_LANG_Fortran95
:
15927 case DW_LANG_Python
:
15928 return dwarf_version
>= 4 ? 0 : -1;
15929 case DW_LANG_Ada95
:
15930 case DW_LANG_Ada83
:
15931 case DW_LANG_Cobol74
:
15932 case DW_LANG_Cobol85
:
15933 case DW_LANG_Pascal83
:
15934 case DW_LANG_Modula2
:
15936 return dwarf_version
>= 4 ? 1 : -1;
15942 /* Given a tree node describing an array bound (either lower or upper) output
15943 a representation for that bound. */
15946 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15948 switch (TREE_CODE (bound
))
15953 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15956 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15959 /* Use the default if possible. */
15960 if (bound_attr
== DW_AT_lower_bound
15961 && host_integerp (bound
, 0)
15962 && (dflt
= lower_bound_default ()) != -1
15963 && tree_low_cst (bound
, 0) == dflt
)
15966 /* Otherwise represent the bound as an unsigned value with the
15967 precision of its type. The precision and signedness of the
15968 type will be necessary to re-interpret it unambiguously. */
15969 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15971 unsigned HOST_WIDE_INT mask
15972 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15973 add_AT_unsigned (subrange_die
, bound_attr
,
15974 TREE_INT_CST_LOW (bound
) & mask
);
15976 else if (prec
== HOST_BITS_PER_WIDE_INT
15977 || TREE_INT_CST_HIGH (bound
) == 0)
15978 add_AT_unsigned (subrange_die
, bound_attr
,
15979 TREE_INT_CST_LOW (bound
));
15981 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15982 TREE_INT_CST_LOW (bound
));
15987 case VIEW_CONVERT_EXPR
:
15988 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15998 dw_die_ref decl_die
= lookup_decl_die (bound
);
16000 /* ??? Can this happen, or should the variable have been bound
16001 first? Probably it can, since I imagine that we try to create
16002 the types of parameters in the order in which they exist in
16003 the list, and won't have created a forward reference to a
16004 later parameter. */
16005 if (decl_die
!= NULL
)
16007 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16015 /* Otherwise try to create a stack operation procedure to
16016 evaluate the value of the array bound. */
16018 dw_die_ref ctx
, decl_die
;
16019 dw_loc_list_ref list
;
16021 list
= loc_list_from_tree (bound
, 2);
16022 if (list
== NULL
|| single_element_loc_list_p (list
))
16024 /* If DW_AT_*bound is not a reference nor constant, it is
16025 a DWARF expression rather than location description.
16026 For that loc_list_from_tree (bound, 0) is needed.
16027 If that fails to give a single element list,
16028 fall back to outputting this as a reference anyway. */
16029 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16030 if (list2
&& single_element_loc_list_p (list2
))
16032 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16039 if (current_function_decl
== 0)
16040 ctx
= comp_unit_die ();
16042 ctx
= lookup_decl_die (current_function_decl
);
16044 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16045 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16046 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16047 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16048 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16054 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16055 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16056 Note that the block of subscript information for an array type also
16057 includes information about the element type of the given array type. */
16060 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16062 unsigned dimension_number
;
16064 dw_die_ref subrange_die
;
16066 for (dimension_number
= 0;
16067 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16068 type
= TREE_TYPE (type
), dimension_number
++)
16070 tree domain
= TYPE_DOMAIN (type
);
16072 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16075 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16076 and (in GNU C only) variable bounds. Handle all three forms
16078 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16081 /* We have an array type with specified bounds. */
16082 lower
= TYPE_MIN_VALUE (domain
);
16083 upper
= TYPE_MAX_VALUE (domain
);
16085 /* Define the index type. */
16086 if (TREE_TYPE (domain
))
16088 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16089 TREE_TYPE field. We can't emit debug info for this
16090 because it is an unnamed integral type. */
16091 if (TREE_CODE (domain
) == INTEGER_TYPE
16092 && TYPE_NAME (domain
) == NULL_TREE
16093 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16094 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16097 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16101 /* ??? If upper is NULL, the array has unspecified length,
16102 but it does have a lower bound. This happens with Fortran
16104 Since the debugger is definitely going to need to know N
16105 to produce useful results, go ahead and output the lower
16106 bound solo, and hope the debugger can cope. */
16108 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16110 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16113 /* Otherwise we have an array type with an unspecified length. The
16114 DWARF-2 spec does not say how to handle this; let's just leave out the
16120 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16122 dw_die_ref decl_die
;
16125 switch (TREE_CODE (tree_node
))
16130 case ENUMERAL_TYPE
:
16133 case QUAL_UNION_TYPE
:
16134 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16135 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16137 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16140 size
= int_size_in_bytes (tree_node
);
16143 /* For a data member of a struct or union, the DW_AT_byte_size is
16144 generally given as the number of bytes normally allocated for an
16145 object of the *declared* type of the member itself. This is true
16146 even for bit-fields. */
16147 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16150 gcc_unreachable ();
16153 /* Note that `size' might be -1 when we get to this point. If it is, that
16154 indicates that the byte size of the entity in question is variable. We
16155 have no good way of expressing this fact in Dwarf at the present time,
16156 so just let the -1 pass on through. */
16157 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16160 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16161 which specifies the distance in bits from the highest order bit of the
16162 "containing object" for the bit-field to the highest order bit of the
16165 For any given bit-field, the "containing object" is a hypothetical object
16166 (of some integral or enum type) within which the given bit-field lives. The
16167 type of this hypothetical "containing object" is always the same as the
16168 declared type of the individual bit-field itself. The determination of the
16169 exact location of the "containing object" for a bit-field is rather
16170 complicated. It's handled by the `field_byte_offset' function (above).
16172 Note that it is the size (in bytes) of the hypothetical "containing object"
16173 which will be given in the DW_AT_byte_size attribute for this bit-field.
16174 (See `byte_size_attribute' above). */
16177 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16179 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16180 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16181 HOST_WIDE_INT bitpos_int
;
16182 HOST_WIDE_INT highest_order_object_bit_offset
;
16183 HOST_WIDE_INT highest_order_field_bit_offset
;
16184 HOST_WIDE_INT bit_offset
;
16186 /* Must be a field and a bit field. */
16187 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16189 /* We can't yet handle bit-fields whose offsets are variable, so if we
16190 encounter such things, just return without generating any attribute
16191 whatsoever. Likewise for variable or too large size. */
16192 if (! host_integerp (bit_position (decl
), 0)
16193 || ! host_integerp (DECL_SIZE (decl
), 1))
16196 bitpos_int
= int_bit_position (decl
);
16198 /* Note that the bit offset is always the distance (in bits) from the
16199 highest-order bit of the "containing object" to the highest-order bit of
16200 the bit-field itself. Since the "high-order end" of any object or field
16201 is different on big-endian and little-endian machines, the computation
16202 below must take account of these differences. */
16203 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16204 highest_order_field_bit_offset
= bitpos_int
;
16206 if (! BYTES_BIG_ENDIAN
)
16208 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16209 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16213 = (! BYTES_BIG_ENDIAN
16214 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16215 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16217 if (bit_offset
< 0)
16218 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16220 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16223 /* For a FIELD_DECL node which represents a bit field, output an attribute
16224 which specifies the length in bits of the given field. */
16227 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16229 /* Must be a field and a bit field. */
16230 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16231 && DECL_BIT_FIELD_TYPE (decl
));
16233 if (host_integerp (DECL_SIZE (decl
), 1))
16234 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16237 /* If the compiled language is ANSI C, then add a 'prototyped'
16238 attribute, if arg types are given for the parameters of a function. */
16241 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16243 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16244 && prototype_p (func_type
))
16245 add_AT_flag (die
, DW_AT_prototyped
, 1);
16248 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16249 by looking in either the type declaration or object declaration
16252 static inline dw_die_ref
16253 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16255 dw_die_ref origin_die
= NULL
;
16257 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16259 /* We may have gotten separated from the block for the inlined
16260 function, if we're in an exception handler or some such; make
16261 sure that the abstract function has been written out.
16263 Doing this for nested functions is wrong, however; functions are
16264 distinct units, and our context might not even be inline. */
16268 fn
= TYPE_STUB_DECL (fn
);
16270 fn
= decl_function_context (fn
);
16272 dwarf2out_abstract_function (fn
);
16275 if (DECL_P (origin
))
16276 origin_die
= lookup_decl_die (origin
);
16277 else if (TYPE_P (origin
))
16278 origin_die
= lookup_type_die (origin
);
16280 /* XXX: Functions that are never lowered don't always have correct block
16281 trees (in the case of java, they simply have no block tree, in some other
16282 languages). For these functions, there is nothing we can really do to
16283 output correct debug info for inlined functions in all cases. Rather
16284 than die, we'll just produce deficient debug info now, in that we will
16285 have variables without a proper abstract origin. In the future, when all
16286 functions are lowered, we should re-add a gcc_assert (origin_die)
16290 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16294 /* We do not currently support the pure_virtual attribute. */
16297 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16299 if (DECL_VINDEX (func_decl
))
16301 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16303 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16304 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16305 new_loc_descr (DW_OP_constu
,
16306 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16309 /* GNU extension: Record what type this method came from originally. */
16310 if (debug_info_level
> DINFO_LEVEL_TERSE
16311 && DECL_CONTEXT (func_decl
))
16312 add_AT_die_ref (die
, DW_AT_containing_type
,
16313 lookup_type_die (DECL_CONTEXT (func_decl
)));
16317 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16318 given decl. This used to be a vendor extension until after DWARF 4
16319 standardized it. */
16322 add_linkage_attr (dw_die_ref die
, tree decl
)
16324 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16326 /* Mimic what assemble_name_raw does with a leading '*'. */
16327 if (name
[0] == '*')
16330 if (dwarf_version
>= 4)
16331 add_AT_string (die
, DW_AT_linkage_name
, name
);
16333 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16336 /* Add source coordinate attributes for the given decl. */
16339 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16341 expanded_location s
;
16343 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16345 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16346 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16347 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16350 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16353 add_linkage_name (dw_die_ref die
, tree decl
)
16355 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16356 && TREE_PUBLIC (decl
)
16357 && !DECL_ABSTRACT (decl
)
16358 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16359 && die
->die_tag
!= DW_TAG_member
)
16361 /* Defer until we have an assembler name set. */
16362 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16364 limbo_die_node
*asm_name
;
16366 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16367 asm_name
->die
= die
;
16368 asm_name
->created_for
= decl
;
16369 asm_name
->next
= deferred_asm_name
;
16370 deferred_asm_name
= asm_name
;
16372 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16373 add_linkage_attr (die
, decl
);
16377 /* Add a DW_AT_name attribute and source coordinate attribute for the
16378 given decl, but only if it actually has a name. */
16381 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16385 decl_name
= DECL_NAME (decl
);
16386 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16388 const char *name
= dwarf2_name (decl
, 0);
16390 add_name_attribute (die
, name
);
16391 if (! DECL_ARTIFICIAL (decl
))
16392 add_src_coords_attributes (die
, decl
);
16394 add_linkage_name (die
, decl
);
16397 #ifdef VMS_DEBUGGING_INFO
16398 /* Get the function's name, as described by its RTL. This may be different
16399 from the DECL_NAME name used in the source file. */
16400 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16402 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16403 XEXP (DECL_RTL (decl
), 0), false);
16404 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16406 #endif /* VMS_DEBUGGING_INFO */
16409 #ifdef VMS_DEBUGGING_INFO
16410 /* Output the debug main pointer die for VMS */
16413 dwarf2out_vms_debug_main_pointer (void)
16415 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16418 /* Allocate the VMS debug main subprogram die. */
16419 die
= ggc_alloc_cleared_die_node ();
16420 die
->die_tag
= DW_TAG_subprogram
;
16421 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16422 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16423 current_function_funcdef_no
);
16424 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16426 /* Make it the first child of comp_unit_die (). */
16427 die
->die_parent
= comp_unit_die ();
16428 if (comp_unit_die ()->die_child
)
16430 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16431 comp_unit_die ()->die_child
->die_sib
= die
;
16435 die
->die_sib
= die
;
16436 comp_unit_die ()->die_child
= die
;
16439 #endif /* VMS_DEBUGGING_INFO */
16441 /* Push a new declaration scope. */
16444 push_decl_scope (tree scope
)
16446 vec_safe_push (decl_scope_table
, scope
);
16449 /* Pop a declaration scope. */
16452 pop_decl_scope (void)
16454 decl_scope_table
->pop ();
16457 /* walk_tree helper function for uses_local_type, below. */
16460 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16463 *walk_subtrees
= 0;
16466 tree name
= TYPE_NAME (*tp
);
16467 if (name
&& DECL_P (name
) && decl_function_context (name
))
16473 /* If TYPE involves a function-local type (including a local typedef to a
16474 non-local type), returns that type; otherwise returns NULL_TREE. */
16477 uses_local_type (tree type
)
16479 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16483 /* Return the DIE for the scope that immediately contains this type.
16484 Non-named types that do not involve a function-local type get global
16485 scope. Named types nested in namespaces or other types get their
16486 containing scope. All other types (i.e. function-local named types) get
16487 the current active scope. */
16490 scope_die_for (tree t
, dw_die_ref context_die
)
16492 dw_die_ref scope_die
= NULL
;
16493 tree containing_scope
;
16495 /* Non-types always go in the current scope. */
16496 gcc_assert (TYPE_P (t
));
16498 /* Use the scope of the typedef, rather than the scope of the type
16500 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16501 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16503 containing_scope
= TYPE_CONTEXT (t
);
16505 /* Use the containing namespace if there is one. */
16506 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16508 if (context_die
== lookup_decl_die (containing_scope
))
16510 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16511 context_die
= get_context_die (containing_scope
);
16513 containing_scope
= NULL_TREE
;
16516 /* Ignore function type "scopes" from the C frontend. They mean that
16517 a tagged type is local to a parmlist of a function declarator, but
16518 that isn't useful to DWARF. */
16519 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16520 containing_scope
= NULL_TREE
;
16522 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16524 /* If T uses a local type keep it local as well, to avoid references
16525 to function-local DIEs from outside the function. */
16526 if (current_function_decl
&& uses_local_type (t
))
16527 scope_die
= context_die
;
16529 scope_die
= comp_unit_die ();
16531 else if (TYPE_P (containing_scope
))
16533 /* For types, we can just look up the appropriate DIE. */
16534 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16535 scope_die
= get_context_die (containing_scope
);
16538 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16539 if (scope_die
== NULL
)
16540 scope_die
= comp_unit_die ();
16544 scope_die
= context_die
;
16549 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16552 local_scope_p (dw_die_ref context_die
)
16554 for (; context_die
; context_die
= context_die
->die_parent
)
16555 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16556 || context_die
->die_tag
== DW_TAG_subprogram
)
16562 /* Returns nonzero if CONTEXT_DIE is a class. */
16565 class_scope_p (dw_die_ref context_die
)
16567 return (context_die
16568 && (context_die
->die_tag
== DW_TAG_structure_type
16569 || context_die
->die_tag
== DW_TAG_class_type
16570 || context_die
->die_tag
== DW_TAG_interface_type
16571 || context_die
->die_tag
== DW_TAG_union_type
));
16574 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16575 whether or not to treat a DIE in this context as a declaration. */
16578 class_or_namespace_scope_p (dw_die_ref context_die
)
16580 return (class_scope_p (context_die
)
16581 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16584 /* Many forms of DIEs require a "type description" attribute. This
16585 routine locates the proper "type descriptor" die for the type given
16586 by 'type', and adds a DW_AT_type attribute below the given die. */
16589 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16590 int decl_volatile
, dw_die_ref context_die
)
16592 enum tree_code code
= TREE_CODE (type
);
16593 dw_die_ref type_die
= NULL
;
16595 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16596 or fixed-point type, use the inner type. This is because we have no
16597 support for unnamed types in base_type_die. This can happen if this is
16598 an Ada subrange type. Correct solution is emit a subrange type die. */
16599 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16600 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16601 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16603 if (code
== ERROR_MARK
16604 /* Handle a special case. For functions whose return type is void, we
16605 generate *no* type attribute. (Note that no object may have type
16606 `void', so this only applies to function return types). */
16607 || code
== VOID_TYPE
)
16610 type_die
= modified_type_die (type
,
16611 decl_const
|| TYPE_READONLY (type
),
16612 decl_volatile
|| TYPE_VOLATILE (type
),
16615 if (type_die
!= NULL
)
16616 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16619 /* Given an object die, add the calling convention attribute for the
16620 function call type. */
16622 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16624 enum dwarf_calling_convention value
= DW_CC_normal
;
16626 value
= ((enum dwarf_calling_convention
)
16627 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16630 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16632 /* DWARF 2 doesn't provide a way to identify a program's source-level
16633 entry point. DW_AT_calling_convention attributes are only meant
16634 to describe functions' calling conventions. However, lacking a
16635 better way to signal the Fortran main program, we used this for
16636 a long time, following existing custom. Now, DWARF 4 has
16637 DW_AT_main_subprogram, which we add below, but some tools still
16638 rely on the old way, which we thus keep. */
16639 value
= DW_CC_program
;
16641 if (dwarf_version
>= 4 || !dwarf_strict
)
16642 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16645 /* Only add the attribute if the backend requests it, and
16646 is not DW_CC_normal. */
16647 if (value
&& (value
!= DW_CC_normal
))
16648 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16651 /* Given a tree pointer to a struct, class, union, or enum type node, return
16652 a pointer to the (string) tag name for the given type, or zero if the type
16653 was declared without a tag. */
16655 static const char *
16656 type_tag (const_tree type
)
16658 const char *name
= 0;
16660 if (TYPE_NAME (type
) != 0)
16664 /* Find the IDENTIFIER_NODE for the type name. */
16665 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16666 && !TYPE_NAMELESS (type
))
16667 t
= TYPE_NAME (type
);
16669 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16670 a TYPE_DECL node, regardless of whether or not a `typedef' was
16672 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16673 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16675 /* We want to be extra verbose. Don't call dwarf_name if
16676 DECL_NAME isn't set. The default hook for decl_printable_name
16677 doesn't like that, and in this context it's correct to return
16678 0, instead of "<anonymous>" or the like. */
16679 if (DECL_NAME (TYPE_NAME (type
))
16680 && !DECL_NAMELESS (TYPE_NAME (type
)))
16681 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16684 /* Now get the name as a string, or invent one. */
16685 if (!name
&& t
!= 0)
16686 name
= IDENTIFIER_POINTER (t
);
16689 return (name
== 0 || *name
== '\0') ? 0 : name
;
16692 /* Return the type associated with a data member, make a special check
16693 for bit field types. */
16696 member_declared_type (const_tree member
)
16698 return (DECL_BIT_FIELD_TYPE (member
)
16699 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16702 /* Get the decl's label, as described by its RTL. This may be different
16703 from the DECL_NAME name used in the source file. */
16706 static const char *
16707 decl_start_label (tree decl
)
16710 const char *fnname
;
16712 x
= DECL_RTL (decl
);
16713 gcc_assert (MEM_P (x
));
16716 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16718 fnname
= XSTR (x
, 0);
16723 /* These routines generate the internal representation of the DIE's for
16724 the compilation unit. Debugging information is collected by walking
16725 the declaration trees passed in from dwarf2out_decl(). */
16728 gen_array_type_die (tree type
, dw_die_ref context_die
)
16730 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16731 dw_die_ref array_die
;
16733 /* GNU compilers represent multidimensional array types as sequences of one
16734 dimensional array types whose element types are themselves array types.
16735 We sometimes squish that down to a single array_type DIE with multiple
16736 subscripts in the Dwarf debugging info. The draft Dwarf specification
16737 say that we are allowed to do this kind of compression in C, because
16738 there is no difference between an array of arrays and a multidimensional
16739 array. We don't do this for Ada to remain as close as possible to the
16740 actual representation, which is especially important against the language
16741 flexibilty wrt arrays of variable size. */
16743 bool collapse_nested_arrays
= !is_ada ();
16746 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16747 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16748 if (TYPE_STRING_FLAG (type
)
16749 && TREE_CODE (type
) == ARRAY_TYPE
16751 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16753 HOST_WIDE_INT size
;
16755 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16756 add_name_attribute (array_die
, type_tag (type
));
16757 equate_type_number_to_die (type
, array_die
);
16758 size
= int_size_in_bytes (type
);
16760 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16761 else if (TYPE_DOMAIN (type
) != NULL_TREE
16762 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16763 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16765 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16766 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16768 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16769 if (loc
&& size
> 0)
16771 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16772 if (size
!= DWARF2_ADDR_SIZE
)
16773 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16779 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16780 add_name_attribute (array_die
, type_tag (type
));
16781 equate_type_number_to_die (type
, array_die
);
16783 if (TREE_CODE (type
) == VECTOR_TYPE
)
16784 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16786 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16788 && TREE_CODE (type
) == ARRAY_TYPE
16789 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16790 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16791 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16794 /* We default the array ordering. SDB will probably do
16795 the right things even if DW_AT_ordering is not present. It's not even
16796 an issue until we start to get into multidimensional arrays anyway. If
16797 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16798 then we'll have to put the DW_AT_ordering attribute back in. (But if
16799 and when we find out that we need to put these in, we will only do so
16800 for multidimensional arrays. */
16801 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16804 if (TREE_CODE (type
) == VECTOR_TYPE
)
16806 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16807 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16808 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16809 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16810 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16813 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16815 /* Add representation of the type of the elements of this array type and
16816 emit the corresponding DIE if we haven't done it already. */
16817 element_type
= TREE_TYPE (type
);
16818 if (collapse_nested_arrays
)
16819 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16821 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16823 element_type
= TREE_TYPE (element_type
);
16826 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16828 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16829 if (TYPE_ARTIFICIAL (type
))
16830 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16832 if (get_AT (array_die
, DW_AT_name
))
16833 add_pubtype (type
, array_die
);
16836 static dw_loc_descr_ref
16837 descr_info_loc (tree val
, tree base_decl
)
16839 HOST_WIDE_INT size
;
16840 dw_loc_descr_ref loc
, loc2
;
16841 enum dwarf_location_atom op
;
16843 if (val
== base_decl
)
16844 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16846 switch (TREE_CODE (val
))
16849 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16851 return loc_descriptor_from_tree (val
, 0);
16853 if (host_integerp (val
, 0))
16854 return int_loc_descriptor (tree_low_cst (val
, 0));
16857 size
= int_size_in_bytes (TREE_TYPE (val
));
16860 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16863 if (size
== DWARF2_ADDR_SIZE
)
16864 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16866 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16868 case POINTER_PLUS_EXPR
:
16870 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16871 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16874 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16877 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16883 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16886 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16889 add_loc_descr (&loc
, loc2
);
16890 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16912 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16913 tree val
, tree base_decl
)
16915 dw_loc_descr_ref loc
;
16917 if (host_integerp (val
, 0))
16919 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16923 loc
= descr_info_loc (val
, base_decl
);
16927 add_AT_loc (die
, attr
, loc
);
16930 /* This routine generates DIE for array with hidden descriptor, details
16931 are filled into *info by a langhook. */
16934 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16935 dw_die_ref context_die
)
16937 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16938 dw_die_ref array_die
;
16941 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16942 add_name_attribute (array_die
, type_tag (type
));
16943 equate_type_number_to_die (type
, array_die
);
16945 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16947 && info
->ndimensions
>= 2)
16948 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16950 if (info
->data_location
)
16951 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16953 if (info
->associated
)
16954 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16956 if (info
->allocated
)
16957 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16960 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16962 dw_die_ref subrange_die
16963 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16965 if (info
->dimen
[dim
].lower_bound
)
16967 /* If it is the default value, omit it. */
16970 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16971 && (dflt
= lower_bound_default ()) != -1
16972 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16975 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16976 info
->dimen
[dim
].lower_bound
,
16979 if (info
->dimen
[dim
].upper_bound
)
16980 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16981 info
->dimen
[dim
].upper_bound
,
16983 if (info
->dimen
[dim
].stride
)
16984 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16985 info
->dimen
[dim
].stride
,
16989 gen_type_die (info
->element_type
, context_die
);
16990 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16992 if (get_AT (array_die
, DW_AT_name
))
16993 add_pubtype (type
, array_die
);
16998 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17000 tree origin
= decl_ultimate_origin (decl
);
17001 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17003 if (origin
!= NULL
)
17004 add_abstract_origin_attribute (decl_die
, origin
);
17007 add_name_and_src_coords_attributes (decl_die
, decl
);
17008 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17009 0, 0, context_die
);
17012 if (DECL_ABSTRACT (decl
))
17013 equate_decl_number_to_die (decl
, decl_die
);
17015 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17019 /* Walk through the list of incomplete types again, trying once more to
17020 emit full debugging info for them. */
17023 retry_incomplete_types (void)
17027 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17028 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17029 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17032 /* Determine what tag to use for a record type. */
17034 static enum dwarf_tag
17035 record_type_tag (tree type
)
17037 if (! lang_hooks
.types
.classify_record
)
17038 return DW_TAG_structure_type
;
17040 switch (lang_hooks
.types
.classify_record (type
))
17042 case RECORD_IS_STRUCT
:
17043 return DW_TAG_structure_type
;
17045 case RECORD_IS_CLASS
:
17046 return DW_TAG_class_type
;
17048 case RECORD_IS_INTERFACE
:
17049 if (dwarf_version
>= 3 || !dwarf_strict
)
17050 return DW_TAG_interface_type
;
17051 return DW_TAG_structure_type
;
17054 gcc_unreachable ();
17058 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17059 include all of the information about the enumeration values also. Each
17060 enumerated type name/value is listed as a child of the enumerated type
17064 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17066 dw_die_ref type_die
= lookup_type_die (type
);
17068 if (type_die
== NULL
)
17070 type_die
= new_die (DW_TAG_enumeration_type
,
17071 scope_die_for (type
, context_die
), type
);
17072 equate_type_number_to_die (type
, type_die
);
17073 add_name_attribute (type_die
, type_tag (type
));
17074 if (dwarf_version
>= 4 || !dwarf_strict
)
17076 if (ENUM_IS_SCOPED (type
))
17077 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17078 if (ENUM_IS_OPAQUE (type
))
17079 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17082 else if (! TYPE_SIZE (type
))
17085 remove_AT (type_die
, DW_AT_declaration
);
17087 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17088 given enum type is incomplete, do not generate the DW_AT_byte_size
17089 attribute or the DW_AT_element_list attribute. */
17090 if (TYPE_SIZE (type
))
17094 TREE_ASM_WRITTEN (type
) = 1;
17095 add_byte_size_attribute (type_die
, type
);
17096 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17098 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17099 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17102 /* If the first reference to this type was as the return type of an
17103 inline function, then it may not have a parent. Fix this now. */
17104 if (type_die
->die_parent
== NULL
)
17105 add_child_die (scope_die_for (type
, context_die
), type_die
);
17107 for (link
= TYPE_VALUES (type
);
17108 link
!= NULL
; link
= TREE_CHAIN (link
))
17110 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17111 tree value
= TREE_VALUE (link
);
17113 add_name_attribute (enum_die
,
17114 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17116 if (TREE_CODE (value
) == CONST_DECL
)
17117 value
= DECL_INITIAL (value
);
17119 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
)))
17120 && (simple_type_size_in_bits (TREE_TYPE (value
))
17121 <= HOST_BITS_PER_WIDE_INT
|| host_integerp (value
, 0)))
17122 /* DWARF2 does not provide a way of indicating whether or
17123 not enumeration constants are signed or unsigned. GDB
17124 always assumes the values are signed, so we output all
17125 values as if they were signed. That means that
17126 enumeration constants with very large unsigned values
17127 will appear to have negative values in the debugger.
17129 TODO: the above comment is wrong, DWARF2 does provide
17130 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17131 This should be re-worked to use correct signed/unsigned
17132 int/double tags for all cases, instead of always treating as
17134 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17136 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17138 add_AT_double (enum_die
, DW_AT_const_value
,
17139 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17142 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17143 if (TYPE_ARTIFICIAL (type
))
17144 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17147 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17149 add_pubtype (type
, type_die
);
17154 /* Generate a DIE to represent either a real live formal parameter decl or to
17155 represent just the type of some formal parameter position in some function
17158 Note that this routine is a bit unusual because its argument may be a
17159 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17160 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17161 node. If it's the former then this function is being called to output a
17162 DIE to represent a formal parameter object (or some inlining thereof). If
17163 it's the latter, then this function is only being called to output a
17164 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17165 argument type of some subprogram type.
17166 If EMIT_NAME_P is true, name and source coordinate attributes
17170 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17171 dw_die_ref context_die
)
17173 tree node_or_origin
= node
? node
: origin
;
17174 tree ultimate_origin
;
17175 dw_die_ref parm_die
17176 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17178 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17180 case tcc_declaration
:
17181 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17182 if (node
|| ultimate_origin
)
17183 origin
= ultimate_origin
;
17184 if (origin
!= NULL
)
17185 add_abstract_origin_attribute (parm_die
, origin
);
17186 else if (emit_name_p
)
17187 add_name_and_src_coords_attributes (parm_die
, node
);
17189 || (! DECL_ABSTRACT (node_or_origin
)
17190 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17191 decl_function_context
17192 (node_or_origin
))))
17194 tree type
= TREE_TYPE (node_or_origin
);
17195 if (decl_by_reference_p (node_or_origin
))
17196 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17199 add_type_attribute (parm_die
, type
,
17200 TREE_READONLY (node_or_origin
),
17201 TREE_THIS_VOLATILE (node_or_origin
),
17204 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17205 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17207 if (node
&& node
!= origin
)
17208 equate_decl_number_to_die (node
, parm_die
);
17209 if (! DECL_ABSTRACT (node_or_origin
))
17210 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17211 node
== NULL
, DW_AT_location
);
17216 /* We were called with some kind of a ..._TYPE node. */
17217 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17221 gcc_unreachable ();
17227 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17228 children DW_TAG_formal_parameter DIEs representing the arguments of the
17231 PARM_PACK must be a function parameter pack.
17232 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17233 must point to the subsequent arguments of the function PACK_ARG belongs to.
17234 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17235 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17236 following the last one for which a DIE was generated. */
17239 gen_formal_parameter_pack_die (tree parm_pack
,
17241 dw_die_ref subr_die
,
17245 dw_die_ref parm_pack_die
;
17247 gcc_assert (parm_pack
17248 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17251 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17252 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17254 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17256 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17259 gen_formal_parameter_die (arg
, NULL
,
17260 false /* Don't emit name attribute. */,
17265 return parm_pack_die
;
17268 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17269 at the end of an (ANSI prototyped) formal parameters list. */
17272 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17274 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17277 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17278 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17279 parameters as specified in some function type specification (except for
17280 those which appear as part of a function *definition*). */
17283 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17286 tree formal_type
= NULL
;
17287 tree first_parm_type
;
17290 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17292 arg
= DECL_ARGUMENTS (function_or_method_type
);
17293 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17298 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17300 /* Make our first pass over the list of formal parameter types and output a
17301 DW_TAG_formal_parameter DIE for each one. */
17302 for (link
= first_parm_type
; link
; )
17304 dw_die_ref parm_die
;
17306 formal_type
= TREE_VALUE (link
);
17307 if (formal_type
== void_type_node
)
17310 /* Output a (nameless) DIE to represent the formal parameter itself. */
17311 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17312 true /* Emit name attribute. */,
17314 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17315 && link
== first_parm_type
)
17317 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17318 if (dwarf_version
>= 3 || !dwarf_strict
)
17319 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17321 else if (arg
&& DECL_ARTIFICIAL (arg
))
17322 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17324 link
= TREE_CHAIN (link
);
17326 arg
= DECL_CHAIN (arg
);
17329 /* If this function type has an ellipsis, add a
17330 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17331 if (formal_type
!= void_type_node
)
17332 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17334 /* Make our second (and final) pass over the list of formal parameter types
17335 and output DIEs to represent those types (as necessary). */
17336 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17337 link
&& TREE_VALUE (link
);
17338 link
= TREE_CHAIN (link
))
17339 gen_type_die (TREE_VALUE (link
), context_die
);
17342 /* We want to generate the DIE for TYPE so that we can generate the
17343 die for MEMBER, which has been defined; we will need to refer back
17344 to the member declaration nested within TYPE. If we're trying to
17345 generate minimal debug info for TYPE, processing TYPE won't do the
17346 trick; we need to attach the member declaration by hand. */
17349 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17351 gen_type_die (type
, context_die
);
17353 /* If we're trying to avoid duplicate debug info, we may not have
17354 emitted the member decl for this function. Emit it now. */
17355 if (TYPE_STUB_DECL (type
)
17356 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17357 && ! lookup_decl_die (member
))
17359 dw_die_ref type_die
;
17360 gcc_assert (!decl_ultimate_origin (member
));
17362 push_decl_scope (type
);
17363 type_die
= lookup_type_die_strip_naming_typedef (type
);
17364 if (TREE_CODE (member
) == FUNCTION_DECL
)
17365 gen_subprogram_die (member
, type_die
);
17366 else if (TREE_CODE (member
) == FIELD_DECL
)
17368 /* Ignore the nameless fields that are used to skip bits but handle
17369 C++ anonymous unions and structs. */
17370 if (DECL_NAME (member
) != NULL_TREE
17371 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17372 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17374 gen_type_die (member_declared_type (member
), type_die
);
17375 gen_field_die (member
, type_die
);
17379 gen_variable_die (member
, NULL_TREE
, type_die
);
17385 /* Forward declare these functions, because they are mutually recursive
17386 with their set_block_* pairing functions. */
17387 static void set_decl_origin_self (tree
);
17388 static void set_decl_abstract_flags (tree
, int);
17390 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17391 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17392 that it points to the node itself, thus indicating that the node is its
17393 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17394 the given node is NULL, recursively descend the decl/block tree which
17395 it is the root of, and for each other ..._DECL or BLOCK node contained
17396 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17397 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17398 values to point to themselves. */
17401 set_block_origin_self (tree stmt
)
17403 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17405 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17410 for (local_decl
= BLOCK_VARS (stmt
);
17411 local_decl
!= NULL_TREE
;
17412 local_decl
= DECL_CHAIN (local_decl
))
17413 if (! DECL_EXTERNAL (local_decl
))
17414 set_decl_origin_self (local_decl
); /* Potential recursion. */
17420 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17421 subblock
!= NULL_TREE
;
17422 subblock
= BLOCK_CHAIN (subblock
))
17423 set_block_origin_self (subblock
); /* Recurse. */
17428 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17429 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17430 node to so that it points to the node itself, thus indicating that the
17431 node represents its own (abstract) origin. Additionally, if the
17432 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17433 the decl/block tree of which the given node is the root of, and for
17434 each other ..._DECL or BLOCK node contained therein whose
17435 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17436 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17437 point to themselves. */
17440 set_decl_origin_self (tree decl
)
17442 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17444 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17445 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17449 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17450 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17451 if (DECL_INITIAL (decl
) != NULL_TREE
17452 && DECL_INITIAL (decl
) != error_mark_node
)
17453 set_block_origin_self (DECL_INITIAL (decl
));
17458 /* Given a pointer to some BLOCK node, and a boolean value to set the
17459 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17460 the given block, and for all local decls and all local sub-blocks
17461 (recursively) which are contained therein. */
17464 set_block_abstract_flags (tree stmt
, int setting
)
17470 BLOCK_ABSTRACT (stmt
) = setting
;
17472 for (local_decl
= BLOCK_VARS (stmt
);
17473 local_decl
!= NULL_TREE
;
17474 local_decl
= DECL_CHAIN (local_decl
))
17475 if (! DECL_EXTERNAL (local_decl
))
17476 set_decl_abstract_flags (local_decl
, setting
);
17478 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17480 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17481 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17482 || TREE_CODE (local_decl
) == PARM_DECL
)
17483 set_decl_abstract_flags (local_decl
, setting
);
17486 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17487 subblock
!= NULL_TREE
;
17488 subblock
= BLOCK_CHAIN (subblock
))
17489 set_block_abstract_flags (subblock
, setting
);
17492 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17493 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17494 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17495 set the abstract flags for all of the parameters, local vars, local
17496 blocks and sub-blocks (recursively) to the same setting. */
17499 set_decl_abstract_flags (tree decl
, int setting
)
17501 DECL_ABSTRACT (decl
) = setting
;
17502 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17506 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17507 DECL_ABSTRACT (arg
) = setting
;
17508 if (DECL_INITIAL (decl
) != NULL_TREE
17509 && DECL_INITIAL (decl
) != error_mark_node
)
17510 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17514 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17515 may later generate inlined and/or out-of-line instances of. */
17518 dwarf2out_abstract_function (tree decl
)
17520 dw_die_ref old_die
;
17524 htab_t old_decl_loc_table
;
17525 htab_t old_cached_dw_loc_list_table
;
17526 int old_call_site_count
, old_tail_call_site_count
;
17527 struct call_arg_loc_node
*old_call_arg_locations
;
17529 /* Make sure we have the actual abstract inline, not a clone. */
17530 decl
= DECL_ORIGIN (decl
);
17532 old_die
= lookup_decl_die (decl
);
17533 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17534 /* We've already generated the abstract instance. */
17537 /* We can be called while recursively when seeing block defining inlined subroutine
17538 DIE. Be sure to not clobber the outer location table nor use it or we would
17539 get locations in abstract instantces. */
17540 old_decl_loc_table
= decl_loc_table
;
17541 decl_loc_table
= NULL
;
17542 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17543 cached_dw_loc_list_table
= NULL
;
17544 old_call_arg_locations
= call_arg_locations
;
17545 call_arg_locations
= NULL
;
17546 old_call_site_count
= call_site_count
;
17547 call_site_count
= -1;
17548 old_tail_call_site_count
= tail_call_site_count
;
17549 tail_call_site_count
= -1;
17551 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17552 we don't get confused by DECL_ABSTRACT. */
17553 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17555 context
= decl_class_context (decl
);
17557 gen_type_die_for_member
17558 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17561 /* Pretend we've just finished compiling this function. */
17562 save_fn
= current_function_decl
;
17563 current_function_decl
= decl
;
17565 was_abstract
= DECL_ABSTRACT (decl
);
17566 set_decl_abstract_flags (decl
, 1);
17567 dwarf2out_decl (decl
);
17568 if (! was_abstract
)
17569 set_decl_abstract_flags (decl
, 0);
17571 current_function_decl
= save_fn
;
17572 decl_loc_table
= old_decl_loc_table
;
17573 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17574 call_arg_locations
= old_call_arg_locations
;
17575 call_site_count
= old_call_site_count
;
17576 tail_call_site_count
= old_tail_call_site_count
;
17579 /* Helper function of premark_used_types() which gets called through
17582 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17583 marked as unused by prune_unused_types. */
17586 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17591 type
= (tree
) *slot
;
17592 die
= lookup_type_die (type
);
17594 die
->die_perennial_p
= 1;
17598 /* Helper function of premark_types_used_by_global_vars which gets called
17599 through htab_traverse.
17601 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17602 marked as unused by prune_unused_types. The DIE of the type is marked
17603 only if the global variable using the type will actually be emitted. */
17606 premark_types_used_by_global_vars_helper (void **slot
,
17607 void *data ATTRIBUTE_UNUSED
)
17609 struct types_used_by_vars_entry
*entry
;
17612 entry
= (struct types_used_by_vars_entry
*) *slot
;
17613 gcc_assert (entry
->type
!= NULL
17614 && entry
->var_decl
!= NULL
);
17615 die
= lookup_type_die (entry
->type
);
17618 /* Ask cgraph if the global variable really is to be emitted.
17619 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17620 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17621 if (node
&& node
->symbol
.definition
)
17623 die
->die_perennial_p
= 1;
17624 /* Keep the parent DIEs as well. */
17625 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17626 die
->die_perennial_p
= 1;
17632 /* Mark all members of used_types_hash as perennial. */
17635 premark_used_types (struct function
*fun
)
17637 if (fun
&& fun
->used_types_hash
)
17638 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17641 /* Mark all members of types_used_by_vars_entry as perennial. */
17644 premark_types_used_by_global_vars (void)
17646 if (types_used_by_vars_hash
)
17647 htab_traverse (types_used_by_vars_hash
,
17648 premark_types_used_by_global_vars_helper
, NULL
);
17651 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17652 for CA_LOC call arg loc node. */
17655 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17656 struct call_arg_loc_node
*ca_loc
)
17658 dw_die_ref stmt_die
= NULL
, die
;
17659 tree block
= ca_loc
->block
;
17662 && block
!= DECL_INITIAL (decl
)
17663 && TREE_CODE (block
) == BLOCK
)
17665 if (block_map
.length () > BLOCK_NUMBER (block
))
17666 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17669 block
= BLOCK_SUPERCONTEXT (block
);
17671 if (stmt_die
== NULL
)
17672 stmt_die
= subr_die
;
17673 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17674 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17675 if (ca_loc
->tail_call_p
)
17676 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17677 if (ca_loc
->symbol_ref
)
17679 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17681 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17683 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17688 /* Generate a DIE to represent a declared function (either file-scope or
17692 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17694 tree origin
= decl_ultimate_origin (decl
);
17695 dw_die_ref subr_die
;
17697 dw_die_ref old_die
= lookup_decl_die (decl
);
17698 int declaration
= (current_function_decl
!= decl
17699 || class_or_namespace_scope_p (context_die
));
17701 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17703 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17704 started to generate the abstract instance of an inline, decided to output
17705 its containing class, and proceeded to emit the declaration of the inline
17706 from the member list for the class. If so, DECLARATION takes priority;
17707 we'll get back to the abstract instance when done with the class. */
17709 /* The class-scope declaration DIE must be the primary DIE. */
17710 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17713 gcc_assert (!old_die
);
17716 /* Now that the C++ front end lazily declares artificial member fns, we
17717 might need to retrofit the declaration into its class. */
17718 if (!declaration
&& !origin
&& !old_die
17719 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17720 && !class_or_namespace_scope_p (context_die
)
17721 && debug_info_level
> DINFO_LEVEL_TERSE
)
17722 old_die
= force_decl_die (decl
);
17724 if (origin
!= NULL
)
17726 gcc_assert (!declaration
|| local_scope_p (context_die
));
17728 /* Fixup die_parent for the abstract instance of a nested
17729 inline function. */
17730 if (old_die
&& old_die
->die_parent
== NULL
)
17731 add_child_die (context_die
, old_die
);
17733 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17734 add_abstract_origin_attribute (subr_die
, origin
);
17735 /* This is where the actual code for a cloned function is.
17736 Let's emit linkage name attribute for it. This helps
17737 debuggers to e.g, set breakpoints into
17738 constructors/destructors when the user asks "break
17740 add_linkage_name (subr_die
, decl
);
17744 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17745 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17747 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17748 /* We can have a normal definition following an inline one in the
17749 case of redefinition of GNU C extern inlines.
17750 It seems reasonable to use AT_specification in this case. */
17751 && !get_AT (old_die
, DW_AT_inline
))
17753 /* Detect and ignore this case, where we are trying to output
17754 something we have already output. */
17758 /* If the definition comes from the same place as the declaration,
17759 maybe use the old DIE. We always want the DIE for this function
17760 that has the *_pc attributes to be under comp_unit_die so the
17761 debugger can find it. We also need to do this for abstract
17762 instances of inlines, since the spec requires the out-of-line copy
17763 to have the same parent. For local class methods, this doesn't
17764 apply; we just use the old DIE. */
17765 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17766 && (DECL_ARTIFICIAL (decl
)
17767 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17768 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17769 == (unsigned) s
.line
))))
17771 subr_die
= old_die
;
17773 /* Clear out the declaration attribute and the formal parameters.
17774 Do not remove all children, because it is possible that this
17775 declaration die was forced using force_decl_die(). In such
17776 cases die that forced declaration die (e.g. TAG_imported_module)
17777 is one of the children that we do not want to remove. */
17778 remove_AT (subr_die
, DW_AT_declaration
);
17779 remove_AT (subr_die
, DW_AT_object_pointer
);
17780 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17784 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17785 add_AT_specification (subr_die
, old_die
);
17786 add_pubname (decl
, subr_die
);
17787 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17788 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17789 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17790 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17795 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17797 if (TREE_PUBLIC (decl
))
17798 add_AT_flag (subr_die
, DW_AT_external
, 1);
17800 add_name_and_src_coords_attributes (subr_die
, decl
);
17801 add_pubname (decl
, subr_die
);
17802 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17804 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17805 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17806 0, 0, context_die
);
17809 add_pure_or_virtual_attribute (subr_die
, decl
);
17810 if (DECL_ARTIFICIAL (decl
))
17811 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17813 add_accessibility_attribute (subr_die
, decl
);
17818 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17820 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17822 /* If this is an explicit function declaration then generate
17823 a DW_AT_explicit attribute. */
17824 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17825 && (dwarf_version
>= 3 || !dwarf_strict
))
17826 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17828 /* The first time we see a member function, it is in the context of
17829 the class to which it belongs. We make sure of this by emitting
17830 the class first. The next time is the definition, which is
17831 handled above. The two may come from the same source text.
17833 Note that force_decl_die() forces function declaration die. It is
17834 later reused to represent definition. */
17835 equate_decl_number_to_die (decl
, subr_die
);
17838 else if (DECL_ABSTRACT (decl
))
17840 if (DECL_DECLARED_INLINE_P (decl
))
17842 if (cgraph_function_possibly_inlined_p (decl
))
17843 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17845 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17849 if (cgraph_function_possibly_inlined_p (decl
))
17850 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17852 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17855 if (DECL_DECLARED_INLINE_P (decl
)
17856 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17857 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17859 equate_decl_number_to_die (decl
, subr_die
);
17861 else if (!DECL_EXTERNAL (decl
))
17863 HOST_WIDE_INT cfa_fb_offset
;
17864 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17866 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17867 equate_decl_number_to_die (decl
, subr_die
);
17869 gcc_checking_assert (fun
);
17870 if (!flag_reorder_blocks_and_partition
)
17872 dw_fde_ref fde
= fun
->fde
;
17873 if (fde
->dw_fde_begin
)
17875 /* We have already generated the labels. */
17876 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17877 fde
->dw_fde_end
, false);
17881 /* Create start/end labels and add the range. */
17882 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17883 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17884 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17885 current_function_funcdef_no
);
17886 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17887 current_function_funcdef_no
);
17888 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17892 #if VMS_DEBUGGING_INFO
17893 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17894 Section 2.3 Prologue and Epilogue Attributes:
17895 When a breakpoint is set on entry to a function, it is generally
17896 desirable for execution to be suspended, not on the very first
17897 instruction of the function, but rather at a point after the
17898 function's frame has been set up, after any language defined local
17899 declaration processing has been completed, and before execution of
17900 the first statement of the function begins. Debuggers generally
17901 cannot properly determine where this point is. Similarly for a
17902 breakpoint set on exit from a function. The prologue and epilogue
17903 attributes allow a compiler to communicate the location(s) to use. */
17906 if (fde
->dw_fde_vms_end_prologue
)
17907 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17908 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17910 if (fde
->dw_fde_vms_begin_epilogue
)
17911 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17912 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17919 /* Generate pubnames entries for the split function code ranges. */
17920 dw_fde_ref fde
= fun
->fde
;
17922 if (fde
->dw_fde_second_begin
)
17924 if (dwarf_version
>= 3 || !dwarf_strict
)
17926 /* We should use ranges for non-contiguous code section
17927 addresses. Use the actual code range for the initial
17928 section, since the HOT/COLD labels might precede an
17929 alignment offset. */
17930 bool range_list_added
= false;
17931 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17932 fde
->dw_fde_end
, &range_list_added
,
17934 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17935 fde
->dw_fde_second_end
,
17936 &range_list_added
, false);
17937 if (range_list_added
)
17942 /* There is no real support in DW2 for this .. so we make
17943 a work-around. First, emit the pub name for the segment
17944 containing the function label. Then make and emit a
17945 simplified subprogram DIE for the second segment with the
17946 name pre-fixed by __hot/cold_sect_of_. We use the same
17947 linkage name for the second die so that gdb will find both
17948 sections when given "b foo". */
17949 const char *name
= NULL
;
17950 tree decl_name
= DECL_NAME (decl
);
17951 dw_die_ref seg_die
;
17953 /* Do the 'primary' section. */
17954 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17955 fde
->dw_fde_end
, false);
17957 /* Build a minimal DIE for the secondary section. */
17958 seg_die
= new_die (DW_TAG_subprogram
,
17959 subr_die
->die_parent
, decl
);
17961 if (TREE_PUBLIC (decl
))
17962 add_AT_flag (seg_die
, DW_AT_external
, 1);
17964 if (decl_name
!= NULL
17965 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17967 name
= dwarf2_name (decl
, 1);
17968 if (! DECL_ARTIFICIAL (decl
))
17969 add_src_coords_attributes (seg_die
, decl
);
17971 add_linkage_name (seg_die
, decl
);
17973 gcc_assert (name
!= NULL
);
17974 add_pure_or_virtual_attribute (seg_die
, decl
);
17975 if (DECL_ARTIFICIAL (decl
))
17976 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17978 name
= concat ("__second_sect_of_", name
, NULL
);
17979 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17980 fde
->dw_fde_second_end
, false);
17981 add_name_attribute (seg_die
, name
);
17982 if (want_pubnames ())
17983 add_pubname_string (name
, seg_die
);
17987 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17991 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17993 /* We define the "frame base" as the function's CFA. This is more
17994 convenient for several reasons: (1) It's stable across the prologue
17995 and epilogue, which makes it better than just a frame pointer,
17996 (2) With dwarf3, there exists a one-byte encoding that allows us
17997 to reference the .debug_frame data by proxy, but failing that,
17998 (3) We can at least reuse the code inspection and interpretation
17999 code that determines the CFA position at various points in the
18001 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18003 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18004 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18008 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18009 if (list
->dw_loc_next
)
18010 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18012 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18015 /* Compute a displacement from the "steady-state frame pointer" to
18016 the CFA. The former is what all stack slots and argument slots
18017 will reference in the rtl; the latter is what we've told the
18018 debugger about. We'll need to adjust all frame_base references
18019 by this displacement. */
18020 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18022 if (fun
->static_chain_decl
)
18023 add_AT_location_description (subr_die
, DW_AT_static_link
,
18024 loc_list_from_tree (fun
->static_chain_decl
, 2));
18027 /* Generate child dies for template paramaters. */
18028 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18029 gen_generic_params_dies (decl
);
18031 /* Now output descriptions of the arguments for this function. This gets
18032 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18033 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18034 `...' at the end of the formal parameter list. In order to find out if
18035 there was a trailing ellipsis or not, we must instead look at the type
18036 associated with the FUNCTION_DECL. This will be a node of type
18037 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18038 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18039 an ellipsis at the end. */
18041 /* In the case where we are describing a mere function declaration, all we
18042 need to do here (and all we *can* do here) is to describe the *types* of
18043 its formal parameters. */
18044 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18046 else if (declaration
)
18047 gen_formal_types_die (decl
, subr_die
);
18050 /* Generate DIEs to represent all known formal parameters. */
18051 tree parm
= DECL_ARGUMENTS (decl
);
18052 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18053 tree generic_decl_parm
= generic_decl
18054 ? DECL_ARGUMENTS (generic_decl
)
18057 /* Now we want to walk the list of parameters of the function and
18058 emit their relevant DIEs.
18060 We consider the case of DECL being an instance of a generic function
18061 as well as it being a normal function.
18063 If DECL is an instance of a generic function we walk the
18064 parameters of the generic function declaration _and_ the parameters of
18065 DECL itself. This is useful because we want to emit specific DIEs for
18066 function parameter packs and those are declared as part of the
18067 generic function declaration. In that particular case,
18068 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18069 That DIE has children DIEs representing the set of arguments
18070 of the pack. Note that the set of pack arguments can be empty.
18071 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18074 Otherwise, we just consider the parameters of DECL. */
18075 while (generic_decl_parm
|| parm
)
18077 if (generic_decl_parm
18078 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18079 gen_formal_parameter_pack_die (generic_decl_parm
,
18084 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18086 if (parm
== DECL_ARGUMENTS (decl
)
18087 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18089 && (dwarf_version
>= 3 || !dwarf_strict
))
18090 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18092 parm
= DECL_CHAIN (parm
);
18095 if (generic_decl_parm
)
18096 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18099 /* Decide whether we need an unspecified_parameters DIE at the end.
18100 There are 2 more cases to do this for: 1) the ansi ... declaration -
18101 this is detectable when the end of the arg list is not a
18102 void_type_node 2) an unprototyped function declaration (not a
18103 definition). This just means that we have no info about the
18104 parameters at all. */
18105 if (prototype_p (TREE_TYPE (decl
)))
18107 /* This is the prototyped case, check for.... */
18108 if (stdarg_p (TREE_TYPE (decl
)))
18109 gen_unspecified_parameters_die (decl
, subr_die
);
18111 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18112 gen_unspecified_parameters_die (decl
, subr_die
);
18115 /* Output Dwarf info for all of the stuff within the body of the function
18116 (if it has one - it may be just a declaration). */
18117 outer_scope
= DECL_INITIAL (decl
);
18119 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18120 a function. This BLOCK actually represents the outermost binding contour
18121 for the function, i.e. the contour in which the function's formal
18122 parameters and labels get declared. Curiously, it appears that the front
18123 end doesn't actually put the PARM_DECL nodes for the current function onto
18124 the BLOCK_VARS list for this outer scope, but are strung off of the
18125 DECL_ARGUMENTS list for the function instead.
18127 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18128 the LABEL_DECL nodes for the function however, and we output DWARF info
18129 for those in decls_for_scope. Just within the `outer_scope' there will be
18130 a BLOCK node representing the function's outermost pair of curly braces,
18131 and any blocks used for the base and member initializers of a C++
18132 constructor function. */
18133 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18135 int call_site_note_count
= 0;
18136 int tail_call_site_note_count
= 0;
18138 /* Emit a DW_TAG_variable DIE for a named return value. */
18139 if (DECL_NAME (DECL_RESULT (decl
)))
18140 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18142 current_function_has_inlines
= 0;
18143 decls_for_scope (outer_scope
, subr_die
, 0);
18145 if (call_arg_locations
&& !dwarf_strict
)
18147 struct call_arg_loc_node
*ca_loc
;
18148 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18150 dw_die_ref die
= NULL
;
18151 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18154 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18155 arg
; arg
= next_arg
)
18157 dw_loc_descr_ref reg
, val
;
18158 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18159 dw_die_ref cdie
, tdie
= NULL
;
18161 next_arg
= XEXP (arg
, 1);
18162 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18164 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18165 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18166 && REGNO (XEXP (XEXP (arg
, 0), 0))
18167 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18168 next_arg
= XEXP (next_arg
, 1);
18169 if (mode
== VOIDmode
)
18171 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18172 if (mode
== VOIDmode
)
18173 mode
= GET_MODE (XEXP (arg
, 0));
18175 if (mode
== VOIDmode
|| mode
== BLKmode
)
18177 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18179 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18180 tloc
= XEXP (XEXP (arg
, 0), 1);
18183 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18184 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18186 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18187 tlocc
= XEXP (XEXP (arg
, 0), 1);
18191 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18192 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18193 VAR_INIT_STATUS_INITIALIZED
);
18194 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18196 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18197 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18198 get_address_mode (mem
),
18200 VAR_INIT_STATUS_INITIALIZED
);
18202 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18203 == DEBUG_PARAMETER_REF
)
18206 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18207 tdie
= lookup_decl_die (tdecl
);
18214 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18215 != DEBUG_PARAMETER_REF
)
18217 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18219 VAR_INIT_STATUS_INITIALIZED
);
18223 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18224 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18227 add_AT_loc (cdie
, DW_AT_location
, reg
);
18228 else if (tdie
!= NULL
)
18229 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18230 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18231 if (next_arg
!= XEXP (arg
, 1))
18233 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18234 if (mode
== VOIDmode
)
18235 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18236 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18239 VAR_INIT_STATUS_INITIALIZED
);
18241 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18245 && (ca_loc
->symbol_ref
|| tloc
))
18246 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18247 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18249 dw_loc_descr_ref tval
= NULL
;
18251 if (tloc
!= NULL_RTX
)
18252 tval
= mem_loc_descriptor (tloc
,
18253 GET_MODE (tloc
) == VOIDmode
18254 ? Pmode
: GET_MODE (tloc
),
18256 VAR_INIT_STATUS_INITIALIZED
);
18258 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18259 else if (tlocc
!= NULL_RTX
)
18261 tval
= mem_loc_descriptor (tlocc
,
18262 GET_MODE (tlocc
) == VOIDmode
18263 ? Pmode
: GET_MODE (tlocc
),
18265 VAR_INIT_STATUS_INITIALIZED
);
18267 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18273 call_site_note_count
++;
18274 if (ca_loc
->tail_call_p
)
18275 tail_call_site_note_count
++;
18279 call_arg_locations
= NULL
;
18280 call_arg_loc_last
= NULL
;
18281 if (tail_call_site_count
>= 0
18282 && tail_call_site_count
== tail_call_site_note_count
18285 if (call_site_count
>= 0
18286 && call_site_count
== call_site_note_count
)
18287 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18289 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18291 call_site_count
= -1;
18292 tail_call_site_count
= -1;
18294 /* Add the calling convention attribute if requested. */
18295 add_calling_convention_attribute (subr_die
, decl
);
18299 /* Returns a hash value for X (which really is a die_struct). */
18302 common_block_die_table_hash (const void *x
)
18304 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18305 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18308 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18309 as decl_id and die_parent of die_struct Y. */
18312 common_block_die_table_eq (const void *x
, const void *y
)
18314 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18315 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18316 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18319 /* Generate a DIE to represent a declared data object.
18320 Either DECL or ORIGIN must be non-null. */
18323 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18325 HOST_WIDE_INT off
= 0;
18327 tree decl_or_origin
= decl
? decl
: origin
;
18328 tree ultimate_origin
;
18329 dw_die_ref var_die
;
18330 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18331 dw_die_ref origin_die
;
18332 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18333 || class_or_namespace_scope_p (context_die
));
18334 bool specialization_p
= false;
18336 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18337 if (decl
|| ultimate_origin
)
18338 origin
= ultimate_origin
;
18339 com_decl
= fortran_common (decl_or_origin
, &off
);
18341 /* Symbol in common gets emitted as a child of the common block, in the form
18342 of a data member. */
18345 dw_die_ref com_die
;
18346 dw_loc_list_ref loc
;
18347 die_node com_die_arg
;
18349 var_die
= lookup_decl_die (decl_or_origin
);
18352 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18354 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18359 /* Optimize the common case. */
18360 if (single_element_loc_list_p (loc
)
18361 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18362 && loc
->expr
->dw_loc_next
== NULL
18363 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18366 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18367 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18368 = plus_constant (GET_MODE (x
), x
, off
);
18371 loc_list_plus_const (loc
, off
);
18373 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18374 remove_AT (var_die
, DW_AT_declaration
);
18380 if (common_block_die_table
== NULL
)
18381 common_block_die_table
18382 = htab_create_ggc (10, common_block_die_table_hash
,
18383 common_block_die_table_eq
, NULL
);
18385 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18386 com_die_arg
.die_parent
= context_die
;
18387 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18388 loc
= loc_list_from_tree (com_decl
, 2);
18389 if (com_die
== NULL
)
18392 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18395 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18396 add_name_and_src_coords_attributes (com_die
, com_decl
);
18399 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18400 /* Avoid sharing the same loc descriptor between
18401 DW_TAG_common_block and DW_TAG_variable. */
18402 loc
= loc_list_from_tree (com_decl
, 2);
18404 else if (DECL_EXTERNAL (decl
))
18405 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18406 if (want_pubnames ())
18407 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18408 com_die
->decl_id
= DECL_UID (com_decl
);
18409 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18410 *slot
= (void *) com_die
;
18412 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18414 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18415 loc
= loc_list_from_tree (com_decl
, 2);
18416 remove_AT (com_die
, DW_AT_declaration
);
18418 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18419 add_name_and_src_coords_attributes (var_die
, decl
);
18420 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18421 TREE_THIS_VOLATILE (decl
), context_die
);
18422 add_AT_flag (var_die
, DW_AT_external
, 1);
18427 /* Optimize the common case. */
18428 if (single_element_loc_list_p (loc
)
18429 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18430 && loc
->expr
->dw_loc_next
== NULL
18431 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18433 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18434 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18435 = plus_constant (GET_MODE (x
), x
, off
);
18438 loc_list_plus_const (loc
, off
);
18440 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18442 else if (DECL_EXTERNAL (decl
))
18443 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18444 equate_decl_number_to_die (decl
, var_die
);
18448 /* If the compiler emitted a definition for the DECL declaration
18449 and if we already emitted a DIE for it, don't emit a second
18450 DIE for it again. Allow re-declarations of DECLs that are
18451 inside functions, though. */
18452 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18455 /* For static data members, the declaration in the class is supposed
18456 to have DW_TAG_member tag; the specification should still be
18457 DW_TAG_variable referencing the DW_TAG_member DIE. */
18458 if (declaration
&& class_scope_p (context_die
))
18459 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18461 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18464 if (origin
!= NULL
)
18465 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18467 /* Loop unrolling can create multiple blocks that refer to the same
18468 static variable, so we must test for the DW_AT_declaration flag.
18470 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18471 copy decls and set the DECL_ABSTRACT flag on them instead of
18474 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18476 ??? The declare_in_namespace support causes us to get two DIEs for one
18477 variable, both of which are declarations. We want to avoid considering
18478 one to be a specification, so we must test that this DIE is not a
18480 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18481 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18483 /* This is a definition of a C++ class level static. */
18484 add_AT_specification (var_die
, old_die
);
18485 specialization_p
= true;
18486 if (DECL_NAME (decl
))
18488 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18489 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18491 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18492 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18494 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18495 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18497 if (old_die
->die_tag
== DW_TAG_member
)
18498 add_linkage_name (var_die
, decl
);
18502 add_name_and_src_coords_attributes (var_die
, decl
);
18504 if ((origin
== NULL
&& !specialization_p
)
18506 && !DECL_ABSTRACT (decl_or_origin
)
18507 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18508 decl_function_context
18509 (decl_or_origin
))))
18511 tree type
= TREE_TYPE (decl_or_origin
);
18513 if (decl_by_reference_p (decl_or_origin
))
18514 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18516 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18517 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18520 if (origin
== NULL
&& !specialization_p
)
18522 if (TREE_PUBLIC (decl
))
18523 add_AT_flag (var_die
, DW_AT_external
, 1);
18525 if (DECL_ARTIFICIAL (decl
))
18526 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18528 add_accessibility_attribute (var_die
, decl
);
18532 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18534 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18535 equate_decl_number_to_die (decl
, var_die
);
18538 && (! DECL_ABSTRACT (decl_or_origin
)
18539 /* Local static vars are shared between all clones/inlines,
18540 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18542 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18543 && TREE_STATIC (decl_or_origin
)
18544 && DECL_RTL_SET_P (decl_or_origin
)))
18545 /* When abstract origin already has DW_AT_location attribute, no need
18546 to add it again. */
18547 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18549 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18550 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18551 defer_location (decl_or_origin
, var_die
);
18553 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18554 decl
== NULL
, DW_AT_location
);
18555 add_pubname (decl_or_origin
, var_die
);
18558 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18561 /* Generate a DIE to represent a named constant. */
18564 gen_const_die (tree decl
, dw_die_ref context_die
)
18566 dw_die_ref const_die
;
18567 tree type
= TREE_TYPE (decl
);
18569 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18570 add_name_and_src_coords_attributes (const_die
, decl
);
18571 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18572 if (TREE_PUBLIC (decl
))
18573 add_AT_flag (const_die
, DW_AT_external
, 1);
18574 if (DECL_ARTIFICIAL (decl
))
18575 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18576 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18579 /* Generate a DIE to represent a label identifier. */
18582 gen_label_die (tree decl
, dw_die_ref context_die
)
18584 tree origin
= decl_ultimate_origin (decl
);
18585 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18587 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18589 if (origin
!= NULL
)
18590 add_abstract_origin_attribute (lbl_die
, origin
);
18592 add_name_and_src_coords_attributes (lbl_die
, decl
);
18594 if (DECL_ABSTRACT (decl
))
18595 equate_decl_number_to_die (decl
, lbl_die
);
18598 insn
= DECL_RTL_IF_SET (decl
);
18600 /* Deleted labels are programmer specified labels which have been
18601 eliminated because of various optimizations. We still emit them
18602 here so that it is possible to put breakpoints on them. */
18606 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18608 /* When optimization is enabled (via -O) some parts of the compiler
18609 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18610 represent source-level labels which were explicitly declared by
18611 the user. This really shouldn't be happening though, so catch
18612 it if it ever does happen. */
18613 gcc_assert (!INSN_DELETED_P (insn
));
18615 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18616 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18620 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18621 && CODE_LABEL_NUMBER (insn
) != -1)
18623 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18624 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18629 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18630 attributes to the DIE for a block STMT, to describe where the inlined
18631 function was called from. This is similar to add_src_coords_attributes. */
18634 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18636 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18638 if (dwarf_version
>= 3 || !dwarf_strict
)
18640 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18641 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18646 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18647 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18650 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18652 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18654 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18655 && (dwarf_version
>= 3 || !dwarf_strict
))
18657 tree chain
, superblock
= NULL_TREE
;
18659 dw_attr_ref attr
= NULL
;
18661 if (inlined_function_outer_scope_p (stmt
))
18663 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18664 BLOCK_NUMBER (stmt
));
18665 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18668 /* Optimize duplicate .debug_ranges lists or even tails of
18669 lists. If this BLOCK has same ranges as its supercontext,
18670 lookup DW_AT_ranges attribute in the supercontext (and
18671 recursively so), verify that the ranges_table contains the
18672 right values and use it instead of adding a new .debug_range. */
18673 for (chain
= stmt
, pdie
= die
;
18674 BLOCK_SAME_RANGE (chain
);
18675 chain
= BLOCK_SUPERCONTEXT (chain
))
18677 dw_attr_ref new_attr
;
18679 pdie
= pdie
->die_parent
;
18682 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18684 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18685 if (new_attr
== NULL
18686 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18689 superblock
= BLOCK_SUPERCONTEXT (chain
);
18692 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18693 / 2 / DWARF2_ADDR_SIZE
].num
18694 == BLOCK_NUMBER (superblock
))
18695 && BLOCK_FRAGMENT_CHAIN (superblock
))
18697 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18698 / 2 / DWARF2_ADDR_SIZE
;
18699 unsigned long supercnt
= 0, thiscnt
= 0;
18700 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18701 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18704 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18705 == BLOCK_NUMBER (chain
));
18707 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18708 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18709 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18711 gcc_assert (supercnt
>= thiscnt
);
18712 add_AT_range_list (die
, DW_AT_ranges
,
18713 ((off
+ supercnt
- thiscnt
)
18714 * 2 * DWARF2_ADDR_SIZE
),
18719 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18721 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18724 add_ranges (chain
);
18725 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18732 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18733 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18734 BLOCK_NUMBER (stmt
));
18735 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18736 BLOCK_NUMBER (stmt
));
18737 add_AT_low_high_pc (die
, label
, label_high
, false);
18741 /* Generate a DIE for a lexical block. */
18744 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18746 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18748 if (call_arg_locations
)
18750 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18751 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18752 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18755 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18756 add_high_low_attributes (stmt
, stmt_die
);
18758 decls_for_scope (stmt
, stmt_die
, depth
);
18761 /* Generate a DIE for an inlined subprogram. */
18764 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18768 /* The instance of function that is effectively being inlined shall not
18770 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18772 decl
= block_ultimate_origin (stmt
);
18774 /* Emit info for the abstract instance first, if we haven't yet. We
18775 must emit this even if the block is abstract, otherwise when we
18776 emit the block below (or elsewhere), we may end up trying to emit
18777 a die whose origin die hasn't been emitted, and crashing. */
18778 dwarf2out_abstract_function (decl
);
18780 if (! BLOCK_ABSTRACT (stmt
))
18782 dw_die_ref subr_die
18783 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18785 if (call_arg_locations
)
18787 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18788 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18789 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18791 add_abstract_origin_attribute (subr_die
, decl
);
18792 if (TREE_ASM_WRITTEN (stmt
))
18793 add_high_low_attributes (stmt
, subr_die
);
18794 add_call_src_coords_attributes (stmt
, subr_die
);
18796 decls_for_scope (stmt
, subr_die
, depth
);
18797 current_function_has_inlines
= 1;
18801 /* Generate a DIE for a field in a record, or structure. */
18804 gen_field_die (tree decl
, dw_die_ref context_die
)
18806 dw_die_ref decl_die
;
18808 if (TREE_TYPE (decl
) == error_mark_node
)
18811 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18812 add_name_and_src_coords_attributes (decl_die
, decl
);
18813 add_type_attribute (decl_die
, member_declared_type (decl
),
18814 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18817 if (DECL_BIT_FIELD_TYPE (decl
))
18819 add_byte_size_attribute (decl_die
, decl
);
18820 add_bit_size_attribute (decl_die
, decl
);
18821 add_bit_offset_attribute (decl_die
, decl
);
18824 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18825 add_data_member_location_attribute (decl_die
, decl
);
18827 if (DECL_ARTIFICIAL (decl
))
18828 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18830 add_accessibility_attribute (decl_die
, decl
);
18832 /* Equate decl number to die, so that we can look up this decl later on. */
18833 equate_decl_number_to_die (decl
, decl_die
);
18837 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18838 Use modified_type_die instead.
18839 We keep this code here just in case these types of DIEs may be needed to
18840 represent certain things in other languages (e.g. Pascal) someday. */
18843 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18846 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18848 equate_type_number_to_die (type
, ptr_die
);
18849 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18850 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18853 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18854 Use modified_type_die instead.
18855 We keep this code here just in case these types of DIEs may be needed to
18856 represent certain things in other languages (e.g. Pascal) someday. */
18859 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18861 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18863 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18864 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18866 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18868 equate_type_number_to_die (type
, ref_die
);
18869 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18870 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18874 /* Generate a DIE for a pointer to a member type. */
18877 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18880 = new_die (DW_TAG_ptr_to_member_type
,
18881 scope_die_for (type
, context_die
), type
);
18883 equate_type_number_to_die (type
, ptr_die
);
18884 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18885 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18886 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18889 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18891 static char *producer_string
;
18893 /* Return a heap allocated producer string including command line options
18894 if -grecord-gcc-switches. */
18897 gen_producer_string (void)
18900 vec
<dchar_p
> switches
= vNULL
;
18901 const char *language_string
= lang_hooks
.name
;
18902 char *producer
, *tail
;
18904 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18905 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18907 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18908 switch (save_decoded_options
[j
].opt_index
)
18915 case OPT_auxbase_strip
:
18924 case OPT_SPECIAL_unknown
:
18925 case OPT_SPECIAL_ignore
:
18926 case OPT_SPECIAL_program_name
:
18927 case OPT_SPECIAL_input_file
:
18928 case OPT_grecord_gcc_switches
:
18929 case OPT_gno_record_gcc_switches
:
18930 case OPT__output_pch_
:
18931 case OPT_fdiagnostics_show_location_
:
18932 case OPT_fdiagnostics_show_option
:
18933 case OPT_fdiagnostics_show_caret
:
18934 case OPT_fdiagnostics_color_
:
18935 case OPT_fverbose_asm
:
18937 case OPT__sysroot_
:
18939 case OPT_nostdinc__
:
18940 /* Ignore these. */
18943 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18944 & CL_NO_DWARF_RECORD
)
18946 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18948 switch (save_decoded_options
[j
].canonical_option
[0][1])
18955 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18962 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18963 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18967 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18969 sprintf (tail
, "%s %s", language_string
, version_string
);
18972 FOR_EACH_VEC_ELT (switches
, j
, p
)
18976 memcpy (tail
+ 1, p
, len
);
18981 switches
.release ();
18985 /* Generate the DIE for the compilation unit. */
18988 gen_compile_unit_die (const char *filename
)
18991 const char *language_string
= lang_hooks
.name
;
18994 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18998 add_name_attribute (die
, filename
);
18999 /* Don't add cwd for <built-in>. */
19000 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19001 add_comp_dir_attribute (die
);
19004 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19006 /* If our producer is LTO try to figure out a common language to use
19007 from the global list of translation units. */
19008 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19012 const char *common_lang
= NULL
;
19014 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19016 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19019 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19020 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19022 else if (strncmp (common_lang
, "GNU C", 5) == 0
19023 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19024 /* Mixing C and C++ is ok, use C++ in that case. */
19025 common_lang
= "GNU C++";
19028 /* Fall back to C. */
19029 common_lang
= NULL
;
19035 language_string
= common_lang
;
19038 language
= DW_LANG_C89
;
19039 if (strcmp (language_string
, "GNU C++") == 0)
19040 language
= DW_LANG_C_plus_plus
;
19041 else if (strcmp (language_string
, "GNU F77") == 0)
19042 language
= DW_LANG_Fortran77
;
19043 else if (strcmp (language_string
, "GNU Pascal") == 0)
19044 language
= DW_LANG_Pascal83
;
19045 else if (dwarf_version
>= 3 || !dwarf_strict
)
19047 if (strcmp (language_string
, "GNU Ada") == 0)
19048 language
= DW_LANG_Ada95
;
19049 else if (strcmp (language_string
, "GNU Fortran") == 0)
19050 language
= DW_LANG_Fortran95
;
19051 else if (strcmp (language_string
, "GNU Java") == 0)
19052 language
= DW_LANG_Java
;
19053 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19054 language
= DW_LANG_ObjC
;
19055 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19056 language
= DW_LANG_ObjC_plus_plus
;
19057 else if (dwarf_version
>= 5 || !dwarf_strict
)
19059 if (strcmp (language_string
, "GNU Go") == 0)
19060 language
= DW_LANG_Go
;
19063 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19064 else if (strcmp (language_string
, "GNU Fortran") == 0)
19065 language
= DW_LANG_Fortran90
;
19067 add_AT_unsigned (die
, DW_AT_language
, language
);
19071 case DW_LANG_Fortran77
:
19072 case DW_LANG_Fortran90
:
19073 case DW_LANG_Fortran95
:
19074 /* Fortran has case insensitive identifiers and the front-end
19075 lowercases everything. */
19076 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19079 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19085 /* Generate the DIE for a base class. */
19088 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19090 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19092 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19093 add_data_member_location_attribute (die
, binfo
);
19095 if (BINFO_VIRTUAL_P (binfo
))
19096 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19098 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19099 children, otherwise the default is DW_ACCESS_public. In DWARF2
19100 the default has always been DW_ACCESS_private. */
19101 if (access
== access_public_node
)
19103 if (dwarf_version
== 2
19104 || context_die
->die_tag
== DW_TAG_class_type
)
19105 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19107 else if (access
== access_protected_node
)
19108 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19109 else if (dwarf_version
> 2
19110 && context_die
->die_tag
!= DW_TAG_class_type
)
19111 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19114 /* Generate a DIE for a class member. */
19117 gen_member_die (tree type
, dw_die_ref context_die
)
19120 tree binfo
= TYPE_BINFO (type
);
19123 /* If this is not an incomplete type, output descriptions of each of its
19124 members. Note that as we output the DIEs necessary to represent the
19125 members of this record or union type, we will also be trying to output
19126 DIEs to represent the *types* of those members. However the `type'
19127 function (above) will specifically avoid generating type DIEs for member
19128 types *within* the list of member DIEs for this (containing) type except
19129 for those types (of members) which are explicitly marked as also being
19130 members of this (containing) type themselves. The g++ front- end can
19131 force any given type to be treated as a member of some other (containing)
19132 type by setting the TYPE_CONTEXT of the given (member) type to point to
19133 the TREE node representing the appropriate (containing) type. */
19135 /* First output info about the base classes. */
19138 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19142 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19143 gen_inheritance_die (base
,
19144 (accesses
? (*accesses
)[i
] : access_public_node
),
19148 /* Now output info about the data members and type members. */
19149 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19151 /* If we thought we were generating minimal debug info for TYPE
19152 and then changed our minds, some of the member declarations
19153 may have already been defined. Don't define them again, but
19154 do put them in the right order. */
19156 child
= lookup_decl_die (member
);
19158 splice_child_die (context_die
, child
);
19160 gen_decl_die (member
, NULL
, context_die
);
19163 /* Now output info about the function members (if any). */
19164 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19166 /* Don't include clones in the member list. */
19167 if (DECL_ABSTRACT_ORIGIN (member
))
19170 child
= lookup_decl_die (member
);
19172 splice_child_die (context_die
, child
);
19174 gen_decl_die (member
, NULL
, context_die
);
19178 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19179 is set, we pretend that the type was never defined, so we only get the
19180 member DIEs needed by later specification DIEs. */
19183 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19184 enum debug_info_usage usage
)
19186 dw_die_ref type_die
= lookup_type_die (type
);
19187 dw_die_ref scope_die
= 0;
19189 int complete
= (TYPE_SIZE (type
)
19190 && (! TYPE_STUB_DECL (type
)
19191 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19192 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19193 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19195 if (type_die
&& ! complete
)
19198 if (TYPE_CONTEXT (type
) != NULL_TREE
19199 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19200 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19203 scope_die
= scope_die_for (type
, context_die
);
19205 /* Generate child dies for template paramaters. */
19206 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19207 schedule_generic_params_dies_gen (type
);
19209 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19210 /* First occurrence of type or toplevel definition of nested class. */
19212 dw_die_ref old_die
= type_die
;
19214 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19215 ? record_type_tag (type
) : DW_TAG_union_type
,
19217 equate_type_number_to_die (type
, type_die
);
19219 add_AT_specification (type_die
, old_die
);
19221 add_name_attribute (type_die
, type_tag (type
));
19224 remove_AT (type_die
, DW_AT_declaration
);
19226 /* If this type has been completed, then give it a byte_size attribute and
19227 then give a list of members. */
19228 if (complete
&& !ns_decl
)
19230 /* Prevent infinite recursion in cases where the type of some member of
19231 this type is expressed in terms of this type itself. */
19232 TREE_ASM_WRITTEN (type
) = 1;
19233 add_byte_size_attribute (type_die
, type
);
19234 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19236 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19237 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19240 /* If the first reference to this type was as the return type of an
19241 inline function, then it may not have a parent. Fix this now. */
19242 if (type_die
->die_parent
== NULL
)
19243 add_child_die (scope_die
, type_die
);
19245 push_decl_scope (type
);
19246 gen_member_die (type
, type_die
);
19249 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19250 if (TYPE_ARTIFICIAL (type
))
19251 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19253 /* GNU extension: Record what type our vtable lives in. */
19254 if (TYPE_VFIELD (type
))
19256 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19258 gen_type_die (vtype
, context_die
);
19259 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19260 lookup_type_die (vtype
));
19265 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19267 /* We don't need to do this for function-local types. */
19268 if (TYPE_STUB_DECL (type
)
19269 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19270 vec_safe_push (incomplete_types
, type
);
19273 if (get_AT (type_die
, DW_AT_name
))
19274 add_pubtype (type
, type_die
);
19277 /* Generate a DIE for a subroutine _type_. */
19280 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19282 tree return_type
= TREE_TYPE (type
);
19283 dw_die_ref subr_die
19284 = new_die (DW_TAG_subroutine_type
,
19285 scope_die_for (type
, context_die
), type
);
19287 equate_type_number_to_die (type
, subr_die
);
19288 add_prototyped_attribute (subr_die
, type
);
19289 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19290 gen_formal_types_die (type
, subr_die
);
19292 if (get_AT (subr_die
, DW_AT_name
))
19293 add_pubtype (type
, subr_die
);
19296 /* Generate a DIE for a type definition. */
19299 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19301 dw_die_ref type_die
;
19304 if (TREE_ASM_WRITTEN (decl
))
19307 TREE_ASM_WRITTEN (decl
) = 1;
19308 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19309 origin
= decl_ultimate_origin (decl
);
19310 if (origin
!= NULL
)
19311 add_abstract_origin_attribute (type_die
, origin
);
19316 add_name_and_src_coords_attributes (type_die
, decl
);
19317 if (DECL_ORIGINAL_TYPE (decl
))
19319 type
= DECL_ORIGINAL_TYPE (decl
);
19321 gcc_assert (type
!= TREE_TYPE (decl
));
19322 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19326 type
= TREE_TYPE (decl
);
19328 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19330 /* Here, we are in the case of decl being a typedef naming
19331 an anonymous type, e.g:
19332 typedef struct {...} foo;
19333 In that case TREE_TYPE (decl) is not a typedef variant
19334 type and TYPE_NAME of the anonymous type is set to the
19335 TYPE_DECL of the typedef. This construct is emitted by
19338 TYPE is the anonymous struct named by the typedef
19339 DECL. As we need the DW_AT_type attribute of the
19340 DW_TAG_typedef to point to the DIE of TYPE, let's
19341 generate that DIE right away. add_type_attribute
19342 called below will then pick (via lookup_type_die) that
19343 anonymous struct DIE. */
19344 if (!TREE_ASM_WRITTEN (type
))
19345 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19347 /* This is a GNU Extension. We are adding a
19348 DW_AT_linkage_name attribute to the DIE of the
19349 anonymous struct TYPE. The value of that attribute
19350 is the name of the typedef decl naming the anonymous
19351 struct. This greatly eases the work of consumers of
19352 this debug info. */
19353 add_linkage_attr (lookup_type_die (type
), decl
);
19357 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19358 TREE_THIS_VOLATILE (decl
), context_die
);
19360 if (is_naming_typedef_decl (decl
))
19361 /* We want that all subsequent calls to lookup_type_die with
19362 TYPE in argument yield the DW_TAG_typedef we have just
19364 equate_type_number_to_die (type
, type_die
);
19366 add_accessibility_attribute (type_die
, decl
);
19369 if (DECL_ABSTRACT (decl
))
19370 equate_decl_number_to_die (decl
, type_die
);
19372 if (get_AT (type_die
, DW_AT_name
))
19373 add_pubtype (decl
, type_die
);
19376 /* Generate a DIE for a struct, class, enum or union type. */
19379 gen_tagged_type_die (tree type
,
19380 dw_die_ref context_die
,
19381 enum debug_info_usage usage
)
19385 if (type
== NULL_TREE
19386 || !is_tagged_type (type
))
19389 /* If this is a nested type whose containing class hasn't been written
19390 out yet, writing it out will cover this one, too. This does not apply
19391 to instantiations of member class templates; they need to be added to
19392 the containing class as they are generated. FIXME: This hurts the
19393 idea of combining type decls from multiple TUs, since we can't predict
19394 what set of template instantiations we'll get. */
19395 if (TYPE_CONTEXT (type
)
19396 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19397 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19399 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19401 if (TREE_ASM_WRITTEN (type
))
19404 /* If that failed, attach ourselves to the stub. */
19405 push_decl_scope (TYPE_CONTEXT (type
));
19406 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19409 else if (TYPE_CONTEXT (type
) != NULL_TREE
19410 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19412 /* If this type is local to a function that hasn't been written
19413 out yet, use a NULL context for now; it will be fixed up in
19414 decls_for_scope. */
19415 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19416 /* A declaration DIE doesn't count; nested types need to go in the
19418 if (context_die
&& is_declaration_die (context_die
))
19419 context_die
= NULL
;
19424 context_die
= declare_in_namespace (type
, context_die
);
19428 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19430 /* This might have been written out by the call to
19431 declare_in_namespace. */
19432 if (!TREE_ASM_WRITTEN (type
))
19433 gen_enumeration_type_die (type
, context_die
);
19436 gen_struct_or_union_type_die (type
, context_die
, usage
);
19441 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19442 it up if it is ever completed. gen_*_type_die will set it for us
19443 when appropriate. */
19446 /* Generate a type description DIE. */
19449 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19450 enum debug_info_usage usage
)
19452 struct array_descr_info info
;
19454 if (type
== NULL_TREE
|| type
== error_mark_node
)
19457 if (TYPE_NAME (type
) != NULL_TREE
19458 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19459 && is_redundant_typedef (TYPE_NAME (type
))
19460 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19461 /* The DECL of this type is a typedef we don't want to emit debug
19462 info for but we want debug info for its underlying typedef.
19463 This can happen for e.g, the injected-class-name of a C++
19465 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19467 /* If TYPE is a typedef type variant, let's generate debug info
19468 for the parent typedef which TYPE is a type of. */
19469 if (typedef_variant_p (type
))
19471 if (TREE_ASM_WRITTEN (type
))
19474 /* Prevent broken recursion; we can't hand off to the same type. */
19475 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19477 /* Give typedefs the right scope. */
19478 context_die
= scope_die_for (type
, context_die
);
19480 TREE_ASM_WRITTEN (type
) = 1;
19482 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19486 /* If type is an anonymous tagged type named by a typedef, let's
19487 generate debug info for the typedef. */
19488 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19490 /* Use the DIE of the containing namespace as the parent DIE of
19491 the type description DIE we want to generate. */
19492 if (DECL_CONTEXT (TYPE_NAME (type
))
19493 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19494 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19496 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19500 /* If this is an array type with hidden descriptor, handle it first. */
19501 if (!TREE_ASM_WRITTEN (type
)
19502 && lang_hooks
.types
.get_array_descr_info
19503 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19504 && (dwarf_version
>= 3 || !dwarf_strict
))
19506 gen_descr_array_type_die (type
, &info
, context_die
);
19507 TREE_ASM_WRITTEN (type
) = 1;
19511 /* We are going to output a DIE to represent the unqualified version
19512 of this type (i.e. without any const or volatile qualifiers) so
19513 get the main variant (i.e. the unqualified version) of this type
19514 now. (Vectors are special because the debugging info is in the
19515 cloned type itself). */
19516 if (TREE_CODE (type
) != VECTOR_TYPE
)
19517 type
= type_main_variant (type
);
19519 if (TREE_ASM_WRITTEN (type
))
19522 switch (TREE_CODE (type
))
19528 case REFERENCE_TYPE
:
19529 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19530 ensures that the gen_type_die recursion will terminate even if the
19531 type is recursive. Recursive types are possible in Ada. */
19532 /* ??? We could perhaps do this for all types before the switch
19534 TREE_ASM_WRITTEN (type
) = 1;
19536 /* For these types, all that is required is that we output a DIE (or a
19537 set of DIEs) to represent the "basis" type. */
19538 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19539 DINFO_USAGE_IND_USE
);
19543 /* This code is used for C++ pointer-to-data-member types.
19544 Output a description of the relevant class type. */
19545 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19546 DINFO_USAGE_IND_USE
);
19548 /* Output a description of the type of the object pointed to. */
19549 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19550 DINFO_USAGE_IND_USE
);
19552 /* Now output a DIE to represent this pointer-to-data-member type
19554 gen_ptr_to_mbr_type_die (type
, context_die
);
19557 case FUNCTION_TYPE
:
19558 /* Force out return type (in case it wasn't forced out already). */
19559 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19560 DINFO_USAGE_DIR_USE
);
19561 gen_subroutine_type_die (type
, context_die
);
19565 /* Force out return type (in case it wasn't forced out already). */
19566 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19567 DINFO_USAGE_DIR_USE
);
19568 gen_subroutine_type_die (type
, context_die
);
19572 gen_array_type_die (type
, context_die
);
19576 gen_array_type_die (type
, context_die
);
19579 case ENUMERAL_TYPE
:
19582 case QUAL_UNION_TYPE
:
19583 gen_tagged_type_die (type
, context_die
, usage
);
19589 case FIXED_POINT_TYPE
:
19592 /* No DIEs needed for fundamental types. */
19597 /* Just use DW_TAG_unspecified_type. */
19599 dw_die_ref type_die
= lookup_type_die (type
);
19600 if (type_die
== NULL
)
19602 tree name
= TYPE_NAME (type
);
19603 if (TREE_CODE (name
) == TYPE_DECL
)
19604 name
= DECL_NAME (name
);
19605 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19606 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19607 equate_type_number_to_die (type
, type_die
);
19613 gcc_unreachable ();
19616 TREE_ASM_WRITTEN (type
) = 1;
19620 gen_type_die (tree type
, dw_die_ref context_die
)
19622 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19625 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19626 things which are local to the given block. */
19629 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19631 int must_output_die
= 0;
19634 /* Ignore blocks that are NULL. */
19635 if (stmt
== NULL_TREE
)
19638 inlined_func
= inlined_function_outer_scope_p (stmt
);
19640 /* If the block is one fragment of a non-contiguous block, do not
19641 process the variables, since they will have been done by the
19642 origin block. Do process subblocks. */
19643 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19647 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19648 gen_block_die (sub
, context_die
, depth
+ 1);
19653 /* Determine if we need to output any Dwarf DIEs at all to represent this
19656 /* The outer scopes for inlinings *must* always be represented. We
19657 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19658 must_output_die
= 1;
19661 /* Determine if this block directly contains any "significant"
19662 local declarations which we will need to output DIEs for. */
19663 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19664 /* We are not in terse mode so *any* local declaration counts
19665 as being a "significant" one. */
19666 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19667 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19668 && (TREE_USED (stmt
)
19669 || TREE_ASM_WRITTEN (stmt
)
19670 || BLOCK_ABSTRACT (stmt
)));
19671 else if ((TREE_USED (stmt
)
19672 || TREE_ASM_WRITTEN (stmt
)
19673 || BLOCK_ABSTRACT (stmt
))
19674 && !dwarf2out_ignore_block (stmt
))
19675 must_output_die
= 1;
19678 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19679 DIE for any block which contains no significant local declarations at
19680 all. Rather, in such cases we just call `decls_for_scope' so that any
19681 needed Dwarf info for any sub-blocks will get properly generated. Note
19682 that in terse mode, our definition of what constitutes a "significant"
19683 local declaration gets restricted to include only inlined function
19684 instances and local (nested) function definitions. */
19685 if (must_output_die
)
19689 /* If STMT block is abstract, that means we have been called
19690 indirectly from dwarf2out_abstract_function.
19691 That function rightfully marks the descendent blocks (of
19692 the abstract function it is dealing with) as being abstract,
19693 precisely to prevent us from emitting any
19694 DW_TAG_inlined_subroutine DIE as a descendent
19695 of an abstract function instance. So in that case, we should
19696 not call gen_inlined_subroutine_die.
19698 Later though, when cgraph asks dwarf2out to emit info
19699 for the concrete instance of the function decl into which
19700 the concrete instance of STMT got inlined, the later will lead
19701 to the generation of a DW_TAG_inlined_subroutine DIE. */
19702 if (! BLOCK_ABSTRACT (stmt
))
19703 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19706 gen_lexical_block_die (stmt
, context_die
, depth
);
19709 decls_for_scope (stmt
, context_die
, depth
);
19712 /* Process variable DECL (or variable with origin ORIGIN) within
19713 block STMT and add it to CONTEXT_DIE. */
19715 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19718 tree decl_or_origin
= decl
? decl
: origin
;
19720 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19721 die
= lookup_decl_die (decl_or_origin
);
19722 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19723 && TYPE_DECL_IS_STUB (decl_or_origin
))
19724 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19728 if (die
!= NULL
&& die
->die_parent
== NULL
)
19729 add_child_die (context_die
, die
);
19730 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19731 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19732 stmt
, context_die
);
19734 gen_decl_die (decl
, origin
, context_die
);
19737 /* Generate all of the decls declared within a given scope and (recursively)
19738 all of its sub-blocks. */
19741 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19747 /* Ignore NULL blocks. */
19748 if (stmt
== NULL_TREE
)
19751 /* Output the DIEs to represent all of the data objects and typedefs
19752 declared directly within this block but not within any nested
19753 sub-blocks. Also, nested function and tag DIEs have been
19754 generated with a parent of NULL; fix that up now. */
19755 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19756 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19757 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19758 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19761 /* If we're at -g1, we're not interested in subblocks. */
19762 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19765 /* Output the DIEs to represent all sub-blocks (and the items declared
19766 therein) of this block. */
19767 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19769 subblocks
= BLOCK_CHAIN (subblocks
))
19770 gen_block_die (subblocks
, context_die
, depth
+ 1);
19773 /* Is this a typedef we can avoid emitting? */
19776 is_redundant_typedef (const_tree decl
)
19778 if (TYPE_DECL_IS_STUB (decl
))
19781 if (DECL_ARTIFICIAL (decl
)
19782 && DECL_CONTEXT (decl
)
19783 && is_tagged_type (DECL_CONTEXT (decl
))
19784 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19785 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19786 /* Also ignore the artificial member typedef for the class name. */
19792 /* Return TRUE if TYPE is a typedef that names a type for linkage
19793 purposes. This kind of typedefs is produced by the C++ FE for
19796 typedef struct {...} foo;
19798 In that case, there is no typedef variant type produced for foo.
19799 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19803 is_naming_typedef_decl (const_tree decl
)
19805 if (decl
== NULL_TREE
19806 || TREE_CODE (decl
) != TYPE_DECL
19807 || !is_tagged_type (TREE_TYPE (decl
))
19808 || DECL_IS_BUILTIN (decl
)
19809 || is_redundant_typedef (decl
)
19810 /* It looks like Ada produces TYPE_DECLs that are very similar
19811 to C++ naming typedefs but that have different
19812 semantics. Let's be specific to c++ for now. */
19816 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19817 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19818 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19819 != TYPE_NAME (TREE_TYPE (decl
))));
19822 /* Returns the DIE for a context. */
19824 static inline dw_die_ref
19825 get_context_die (tree context
)
19829 /* Find die that represents this context. */
19830 if (TYPE_P (context
))
19832 context
= TYPE_MAIN_VARIANT (context
);
19833 return strip_naming_typedef (context
, force_type_die (context
));
19836 return force_decl_die (context
);
19838 return comp_unit_die ();
19841 /* Returns the DIE for decl. A DIE will always be returned. */
19844 force_decl_die (tree decl
)
19846 dw_die_ref decl_die
;
19847 unsigned saved_external_flag
;
19848 tree save_fn
= NULL_TREE
;
19849 decl_die
= lookup_decl_die (decl
);
19852 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19854 decl_die
= lookup_decl_die (decl
);
19858 switch (TREE_CODE (decl
))
19860 case FUNCTION_DECL
:
19861 /* Clear current_function_decl, so that gen_subprogram_die thinks
19862 that this is a declaration. At this point, we just want to force
19863 declaration die. */
19864 save_fn
= current_function_decl
;
19865 current_function_decl
= NULL_TREE
;
19866 gen_subprogram_die (decl
, context_die
);
19867 current_function_decl
= save_fn
;
19871 /* Set external flag to force declaration die. Restore it after
19872 gen_decl_die() call. */
19873 saved_external_flag
= DECL_EXTERNAL (decl
);
19874 DECL_EXTERNAL (decl
) = 1;
19875 gen_decl_die (decl
, NULL
, context_die
);
19876 DECL_EXTERNAL (decl
) = saved_external_flag
;
19879 case NAMESPACE_DECL
:
19880 if (dwarf_version
>= 3 || !dwarf_strict
)
19881 dwarf2out_decl (decl
);
19883 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19884 decl_die
= comp_unit_die ();
19887 case TRANSLATION_UNIT_DECL
:
19888 decl_die
= comp_unit_die ();
19892 gcc_unreachable ();
19895 /* We should be able to find the DIE now. */
19897 decl_die
= lookup_decl_die (decl
);
19898 gcc_assert (decl_die
);
19904 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19905 always returned. */
19908 force_type_die (tree type
)
19910 dw_die_ref type_die
;
19912 type_die
= lookup_type_die (type
);
19915 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19917 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19918 TYPE_VOLATILE (type
), context_die
);
19919 gcc_assert (type_die
);
19924 /* Force out any required namespaces to be able to output DECL,
19925 and return the new context_die for it, if it's changed. */
19928 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19930 tree context
= (DECL_P (thing
)
19931 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19932 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19933 /* Force out the namespace. */
19934 context_die
= force_decl_die (context
);
19936 return context_die
;
19939 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19940 type) within its namespace, if appropriate.
19942 For compatibility with older debuggers, namespace DIEs only contain
19943 declarations; all definitions are emitted at CU scope. */
19946 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19948 dw_die_ref ns_context
;
19950 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19951 return context_die
;
19953 /* If this decl is from an inlined function, then don't try to emit it in its
19954 namespace, as we will get confused. It would have already been emitted
19955 when the abstract instance of the inline function was emitted anyways. */
19956 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19957 return context_die
;
19959 ns_context
= setup_namespace_context (thing
, context_die
);
19961 if (ns_context
!= context_die
)
19965 if (DECL_P (thing
))
19966 gen_decl_die (thing
, NULL
, ns_context
);
19968 gen_type_die (thing
, ns_context
);
19970 return context_die
;
19973 /* Generate a DIE for a namespace or namespace alias. */
19976 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19978 dw_die_ref namespace_die
;
19980 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19981 they are an alias of. */
19982 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19984 /* Output a real namespace or module. */
19985 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19986 namespace_die
= new_die (is_fortran ()
19987 ? DW_TAG_module
: DW_TAG_namespace
,
19988 context_die
, decl
);
19989 /* For Fortran modules defined in different CU don't add src coords. */
19990 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19992 const char *name
= dwarf2_name (decl
, 0);
19994 add_name_attribute (namespace_die
, name
);
19997 add_name_and_src_coords_attributes (namespace_die
, decl
);
19998 if (DECL_EXTERNAL (decl
))
19999 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20000 equate_decl_number_to_die (decl
, namespace_die
);
20004 /* Output a namespace alias. */
20006 /* Force out the namespace we are an alias of, if necessary. */
20007 dw_die_ref origin_die
20008 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20010 if (DECL_FILE_SCOPE_P (decl
)
20011 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20012 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20013 /* Now create the namespace alias DIE. */
20014 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20015 add_name_and_src_coords_attributes (namespace_die
, decl
);
20016 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20017 equate_decl_number_to_die (decl
, namespace_die
);
20019 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20020 if (want_pubnames ())
20021 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20024 /* Generate Dwarf debug information for a decl described by DECL.
20025 The return value is currently only meaningful for PARM_DECLs,
20026 for all other decls it returns NULL. */
20029 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20031 tree decl_or_origin
= decl
? decl
: origin
;
20032 tree class_origin
= NULL
, ultimate_origin
;
20034 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20037 switch (TREE_CODE (decl_or_origin
))
20043 if (!is_fortran () && !is_ada ())
20045 /* The individual enumerators of an enum type get output when we output
20046 the Dwarf representation of the relevant enum type itself. */
20050 /* Emit its type. */
20051 gen_type_die (TREE_TYPE (decl
), context_die
);
20053 /* And its containing namespace. */
20054 context_die
= declare_in_namespace (decl
, context_die
);
20056 gen_const_die (decl
, context_die
);
20059 case FUNCTION_DECL
:
20060 /* Don't output any DIEs to represent mere function declarations,
20061 unless they are class members or explicit block externs. */
20062 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20063 && DECL_FILE_SCOPE_P (decl_or_origin
)
20064 && (current_function_decl
== NULL_TREE
20065 || DECL_ARTIFICIAL (decl_or_origin
)))
20070 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20071 on local redeclarations of global functions. That seems broken. */
20072 if (current_function_decl
!= decl
)
20073 /* This is only a declaration. */;
20076 /* If we're emitting a clone, emit info for the abstract instance. */
20077 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20078 dwarf2out_abstract_function (origin
20079 ? DECL_ORIGIN (origin
)
20080 : DECL_ABSTRACT_ORIGIN (decl
));
20082 /* If we're emitting an out-of-line copy of an inline function,
20083 emit info for the abstract instance and set up to refer to it. */
20084 else if (cgraph_function_possibly_inlined_p (decl
)
20085 && ! DECL_ABSTRACT (decl
)
20086 && ! class_or_namespace_scope_p (context_die
)
20087 /* dwarf2out_abstract_function won't emit a die if this is just
20088 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20089 that case, because that works only if we have a die. */
20090 && DECL_INITIAL (decl
) != NULL_TREE
)
20092 dwarf2out_abstract_function (decl
);
20093 set_decl_origin_self (decl
);
20096 /* Otherwise we're emitting the primary DIE for this decl. */
20097 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20099 /* Before we describe the FUNCTION_DECL itself, make sure that we
20100 have its containing type. */
20102 origin
= decl_class_context (decl
);
20103 if (origin
!= NULL_TREE
)
20104 gen_type_die (origin
, context_die
);
20106 /* And its return type. */
20107 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20109 /* And its virtual context. */
20110 if (DECL_VINDEX (decl
) != NULL_TREE
)
20111 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20113 /* Make sure we have a member DIE for decl. */
20114 if (origin
!= NULL_TREE
)
20115 gen_type_die_for_member (origin
, decl
, context_die
);
20117 /* And its containing namespace. */
20118 context_die
= declare_in_namespace (decl
, context_die
);
20121 /* Now output a DIE to represent the function itself. */
20123 gen_subprogram_die (decl
, context_die
);
20127 /* If we are in terse mode, don't generate any DIEs to represent any
20128 actual typedefs. */
20129 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20132 /* In the special case of a TYPE_DECL node representing the declaration
20133 of some type tag, if the given TYPE_DECL is marked as having been
20134 instantiated from some other (original) TYPE_DECL node (e.g. one which
20135 was generated within the original definition of an inline function) we
20136 used to generate a special (abbreviated) DW_TAG_structure_type,
20137 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20138 should be actually referencing those DIEs, as variable DIEs with that
20139 type would be emitted already in the abstract origin, so it was always
20140 removed during unused type prunning. Don't add anything in this
20142 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20145 if (is_redundant_typedef (decl
))
20146 gen_type_die (TREE_TYPE (decl
), context_die
);
20148 /* Output a DIE to represent the typedef itself. */
20149 gen_typedef_die (decl
, context_die
);
20153 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20154 gen_label_die (decl
, context_die
);
20159 /* If we are in terse mode, don't generate any DIEs to represent any
20160 variable declarations or definitions. */
20161 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20164 /* Output any DIEs that are needed to specify the type of this data
20166 if (decl_by_reference_p (decl_or_origin
))
20167 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20169 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20171 /* And its containing type. */
20172 class_origin
= decl_class_context (decl_or_origin
);
20173 if (class_origin
!= NULL_TREE
)
20174 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20176 /* And its containing namespace. */
20177 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20179 /* Now output the DIE to represent the data object itself. This gets
20180 complicated because of the possibility that the VAR_DECL really
20181 represents an inlined instance of a formal parameter for an inline
20183 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20184 if (ultimate_origin
!= NULL_TREE
20185 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20186 gen_formal_parameter_die (decl
, origin
,
20187 true /* Emit name attribute. */,
20190 gen_variable_die (decl
, origin
, context_die
);
20194 /* Ignore the nameless fields that are used to skip bits but handle C++
20195 anonymous unions and structs. */
20196 if (DECL_NAME (decl
) != NULL_TREE
20197 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20198 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20200 gen_type_die (member_declared_type (decl
), context_die
);
20201 gen_field_die (decl
, context_die
);
20206 if (DECL_BY_REFERENCE (decl_or_origin
))
20207 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20209 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20210 return gen_formal_parameter_die (decl
, origin
,
20211 true /* Emit name attribute. */,
20214 case NAMESPACE_DECL
:
20215 case IMPORTED_DECL
:
20216 if (dwarf_version
>= 3 || !dwarf_strict
)
20217 gen_namespace_die (decl
, context_die
);
20221 /* Probably some frontend-internal decl. Assume we don't care. */
20222 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20229 /* Output debug information for global decl DECL. Called from toplev.c after
20230 compilation proper has finished. */
20233 dwarf2out_global_decl (tree decl
)
20235 /* Output DWARF2 information for file-scope tentative data object
20236 declarations, file-scope (extern) function declarations (which
20237 had no corresponding body) and file-scope tagged type declarations
20238 and definitions which have not yet been forced out. */
20239 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20240 dwarf2out_decl (decl
);
20243 /* Output debug information for type decl DECL. Called from toplev.c
20244 and from language front ends (to record built-in types). */
20246 dwarf2out_type_decl (tree decl
, int local
)
20249 dwarf2out_decl (decl
);
20252 /* Output debug information for imported module or decl DECL.
20253 NAME is non-NULL name in the lexical block if the decl has been renamed.
20254 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20255 that DECL belongs to.
20256 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20258 dwarf2out_imported_module_or_decl_1 (tree decl
,
20260 tree lexical_block
,
20261 dw_die_ref lexical_block_die
)
20263 expanded_location xloc
;
20264 dw_die_ref imported_die
= NULL
;
20265 dw_die_ref at_import_die
;
20267 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20269 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20270 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20274 xloc
= expand_location (input_location
);
20276 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20278 at_import_die
= force_type_die (TREE_TYPE (decl
));
20279 /* For namespace N { typedef void T; } using N::T; base_type_die
20280 returns NULL, but DW_TAG_imported_declaration requires
20281 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20282 if (!at_import_die
)
20284 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20285 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20286 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20287 gcc_assert (at_import_die
);
20292 at_import_die
= lookup_decl_die (decl
);
20293 if (!at_import_die
)
20295 /* If we're trying to avoid duplicate debug info, we may not have
20296 emitted the member decl for this field. Emit it now. */
20297 if (TREE_CODE (decl
) == FIELD_DECL
)
20299 tree type
= DECL_CONTEXT (decl
);
20301 if (TYPE_CONTEXT (type
)
20302 && TYPE_P (TYPE_CONTEXT (type
))
20303 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20304 DINFO_USAGE_DIR_USE
))
20306 gen_type_die_for_member (type
, decl
,
20307 get_context_die (TYPE_CONTEXT (type
)));
20309 at_import_die
= force_decl_die (decl
);
20313 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20315 if (dwarf_version
>= 3 || !dwarf_strict
)
20316 imported_die
= new_die (DW_TAG_imported_module
,
20323 imported_die
= new_die (DW_TAG_imported_declaration
,
20327 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20328 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20330 add_AT_string (imported_die
, DW_AT_name
,
20331 IDENTIFIER_POINTER (name
));
20332 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20335 /* Output debug information for imported module or decl DECL.
20336 NAME is non-NULL name in context if the decl has been renamed.
20337 CHILD is true if decl is one of the renamed decls as part of
20338 importing whole module. */
20341 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20344 /* dw_die_ref at_import_die; */
20345 dw_die_ref scope_die
;
20347 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20352 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20353 We need decl DIE for reference and scope die. First, get DIE for the decl
20356 /* Get the scope die for decl context. Use comp_unit_die for global module
20357 or decl. If die is not found for non globals, force new die. */
20359 && TYPE_P (context
)
20360 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20363 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20366 scope_die
= get_context_die (context
);
20370 gcc_assert (scope_die
->die_child
);
20371 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20372 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20373 scope_die
= scope_die
->die_child
;
20376 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20377 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20381 /* Write the debugging output for DECL. */
20384 dwarf2out_decl (tree decl
)
20386 dw_die_ref context_die
= comp_unit_die ();
20388 switch (TREE_CODE (decl
))
20393 case FUNCTION_DECL
:
20394 /* What we would really like to do here is to filter out all mere
20395 file-scope declarations of file-scope functions which are never
20396 referenced later within this translation unit (and keep all of ones
20397 that *are* referenced later on) but we aren't clairvoyant, so we have
20398 no idea which functions will be referenced in the future (i.e. later
20399 on within the current translation unit). So here we just ignore all
20400 file-scope function declarations which are not also definitions. If
20401 and when the debugger needs to know something about these functions,
20402 it will have to hunt around and find the DWARF information associated
20403 with the definition of the function.
20405 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20406 nodes represent definitions and which ones represent mere
20407 declarations. We have to check DECL_INITIAL instead. That's because
20408 the C front-end supports some weird semantics for "extern inline"
20409 function definitions. These can get inlined within the current
20410 translation unit (and thus, we need to generate Dwarf info for their
20411 abstract instances so that the Dwarf info for the concrete inlined
20412 instances can have something to refer to) but the compiler never
20413 generates any out-of-lines instances of such things (despite the fact
20414 that they *are* definitions).
20416 The important point is that the C front-end marks these "extern
20417 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20418 them anyway. Note that the C++ front-end also plays some similar games
20419 for inline function definitions appearing within include files which
20420 also contain `#pragma interface' pragmas.
20422 If we are called from dwarf2out_abstract_function output a DIE
20423 anyway. We can end up here this way with early inlining and LTO
20424 where the inlined function is output in a different LTRANS unit
20426 if (DECL_INITIAL (decl
) == NULL_TREE
20427 && ! DECL_ABSTRACT (decl
))
20430 /* If we're a nested function, initially use a parent of NULL; if we're
20431 a plain function, this will be fixed up in decls_for_scope. If
20432 we're a method, it will be ignored, since we already have a DIE. */
20433 if (decl_function_context (decl
)
20434 /* But if we're in terse mode, we don't care about scope. */
20435 && debug_info_level
> DINFO_LEVEL_TERSE
)
20436 context_die
= NULL
;
20440 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20441 declaration and if the declaration was never even referenced from
20442 within this entire compilation unit. We suppress these DIEs in
20443 order to save space in the .debug section (by eliminating entries
20444 which are probably useless). Note that we must not suppress
20445 block-local extern declarations (whether used or not) because that
20446 would screw-up the debugger's name lookup mechanism and cause it to
20447 miss things which really ought to be in scope at a given point. */
20448 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20451 /* For local statics lookup proper context die. */
20452 if (TREE_STATIC (decl
)
20453 && DECL_CONTEXT (decl
)
20454 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20455 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20457 /* If we are in terse mode, don't generate any DIEs to represent any
20458 variable declarations or definitions. */
20459 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20464 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20466 if (!is_fortran () && !is_ada ())
20468 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20469 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20472 case NAMESPACE_DECL
:
20473 case IMPORTED_DECL
:
20474 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20476 if (lookup_decl_die (decl
) != NULL
)
20481 /* Don't emit stubs for types unless they are needed by other DIEs. */
20482 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20485 /* Don't bother trying to generate any DIEs to represent any of the
20486 normal built-in types for the language we are compiling. */
20487 if (DECL_IS_BUILTIN (decl
))
20490 /* If we are in terse mode, don't generate any DIEs for types. */
20491 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20494 /* If we're a function-scope tag, initially use a parent of NULL;
20495 this will be fixed up in decls_for_scope. */
20496 if (decl_function_context (decl
))
20497 context_die
= NULL
;
20505 gen_decl_die (decl
, NULL
, context_die
);
20508 /* Write the debugging output for DECL. */
20511 dwarf2out_function_decl (tree decl
)
20513 dwarf2out_decl (decl
);
20514 call_arg_locations
= NULL
;
20515 call_arg_loc_last
= NULL
;
20516 call_site_count
= -1;
20517 tail_call_site_count
= -1;
20518 block_map
.release ();
20519 htab_empty (decl_loc_table
);
20520 htab_empty (cached_dw_loc_list_table
);
20523 /* Output a marker (i.e. a label) for the beginning of the generated code for
20524 a lexical block. */
20527 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20528 unsigned int blocknum
)
20530 switch_to_section (current_function_section ());
20531 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20534 /* Output a marker (i.e. a label) for the end of the generated code for a
20538 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20540 switch_to_section (current_function_section ());
20541 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20544 /* Returns nonzero if it is appropriate not to emit any debugging
20545 information for BLOCK, because it doesn't contain any instructions.
20547 Don't allow this for blocks with nested functions or local classes
20548 as we would end up with orphans, and in the presence of scheduling
20549 we may end up calling them anyway. */
20552 dwarf2out_ignore_block (const_tree block
)
20557 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20558 if (TREE_CODE (decl
) == FUNCTION_DECL
20559 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20561 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20563 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20564 if (TREE_CODE (decl
) == FUNCTION_DECL
20565 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20572 /* Hash table routines for file_hash. */
20575 file_table_eq (const void *p1_p
, const void *p2_p
)
20577 const struct dwarf_file_data
*const p1
=
20578 (const struct dwarf_file_data
*) p1_p
;
20579 const char *const p2
= (const char *) p2_p
;
20580 return filename_cmp (p1
->filename
, p2
) == 0;
20584 file_table_hash (const void *p_p
)
20586 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20587 return htab_hash_string (p
->filename
);
20590 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20591 dwarf2out.c) and return its "index". The index of each (known) filename is
20592 just a unique number which is associated with only that one filename. We
20593 need such numbers for the sake of generating labels (in the .debug_sfnames
20594 section) and references to those files numbers (in the .debug_srcinfo
20595 and.debug_macinfo sections). If the filename given as an argument is not
20596 found in our current list, add it to the list and assign it the next
20597 available unique index number. In order to speed up searches, we remember
20598 the index of the filename was looked up last. This handles the majority of
20601 static struct dwarf_file_data
*
20602 lookup_filename (const char *file_name
)
20605 struct dwarf_file_data
* created
;
20607 /* Check to see if the file name that was searched on the previous
20608 call matches this file name. If so, return the index. */
20609 if (file_table_last_lookup
20610 && (file_name
== file_table_last_lookup
->filename
20611 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20612 return file_table_last_lookup
;
20614 /* Didn't match the previous lookup, search the table. */
20615 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20616 htab_hash_string (file_name
), INSERT
);
20618 return (struct dwarf_file_data
*) *slot
;
20620 created
= ggc_alloc_dwarf_file_data ();
20621 created
->filename
= file_name
;
20622 created
->emitted_number
= 0;
20627 /* If the assembler will construct the file table, then translate the compiler
20628 internal file table number into the assembler file table number, and emit
20629 a .file directive if we haven't already emitted one yet. The file table
20630 numbers are different because we prune debug info for unused variables and
20631 types, which may include filenames. */
20634 maybe_emit_file (struct dwarf_file_data
* fd
)
20636 if (! fd
->emitted_number
)
20638 if (last_emitted_file
)
20639 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20641 fd
->emitted_number
= 1;
20642 last_emitted_file
= fd
;
20644 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20646 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20647 output_quoted_string (asm_out_file
,
20648 remap_debug_filename (fd
->filename
));
20649 fputc ('\n', asm_out_file
);
20653 return fd
->emitted_number
;
20656 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20657 That generation should happen after function debug info has been
20658 generated. The value of the attribute is the constant value of ARG. */
20661 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20663 die_arg_entry entry
;
20668 if (!tmpl_value_parm_die_table
)
20669 vec_alloc (tmpl_value_parm_die_table
, 32);
20673 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20676 /* Return TRUE if T is an instance of generic type, FALSE
20680 generic_type_p (tree t
)
20682 if (t
== NULL_TREE
|| !TYPE_P (t
))
20684 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20687 /* Schedule the generation of the generic parameter dies for the
20688 instance of generic type T. The proper generation itself is later
20689 done by gen_scheduled_generic_parms_dies. */
20692 schedule_generic_params_dies_gen (tree t
)
20694 if (!generic_type_p (t
))
20697 if (!generic_type_instances
)
20698 vec_alloc (generic_type_instances
, 256);
20700 vec_safe_push (generic_type_instances
, t
);
20703 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20704 by append_entry_to_tmpl_value_parm_die_table. This function must
20705 be called after function DIEs have been generated. */
20708 gen_remaining_tmpl_value_param_die_attribute (void)
20710 if (tmpl_value_parm_die_table
)
20715 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20716 tree_add_const_value_attribute (e
->die
, e
->arg
);
20720 /* Generate generic parameters DIEs for instances of generic types
20721 that have been previously scheduled by
20722 schedule_generic_params_dies_gen. This function must be called
20723 after all the types of the CU have been laid out. */
20726 gen_scheduled_generic_parms_dies (void)
20731 if (!generic_type_instances
)
20734 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20735 if (COMPLETE_TYPE_P (t
))
20736 gen_generic_params_dies (t
);
20740 /* Replace DW_AT_name for the decl with name. */
20743 dwarf2out_set_name (tree decl
, tree name
)
20749 die
= TYPE_SYMTAB_DIE (decl
);
20753 dname
= dwarf2_name (name
, 0);
20757 attr
= get_AT (die
, DW_AT_name
);
20760 struct indirect_string_node
*node
;
20762 node
= find_AT_string (dname
);
20763 /* replace the string. */
20764 attr
->dw_attr_val
.v
.val_str
= node
;
20768 add_name_attribute (die
, dname
);
20771 /* True if before or during processing of the first function being emitted. */
20772 static bool in_first_function_p
= true;
20773 /* True if loc_note during dwarf2out_var_location call might still be
20774 before first real instruction at address equal to .Ltext0. */
20775 static bool maybe_at_text_label_p
= true;
20776 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20777 static unsigned int first_loclabel_num_not_at_text_label
;
20779 /* Called by the final INSN scan whenever we see a var location. We
20780 use it to drop labels in the right places, and throw the location in
20781 our lookup table. */
20784 dwarf2out_var_location (rtx loc_note
)
20786 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20787 struct var_loc_node
*newloc
;
20788 rtx next_real
, next_note
;
20789 static const char *last_label
;
20790 static const char *last_postcall_label
;
20791 static bool last_in_cold_section_p
;
20792 static rtx expected_next_loc_note
;
20796 if (!NOTE_P (loc_note
))
20798 if (CALL_P (loc_note
))
20801 if (SIBLING_CALL_P (loc_note
))
20802 tail_call_site_count
++;
20807 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20808 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20811 /* Optimize processing a large consecutive sequence of location
20812 notes so we don't spend too much time in next_real_insn. If the
20813 next insn is another location note, remember the next_real_insn
20814 calculation for next time. */
20815 next_real
= cached_next_real_insn
;
20818 if (expected_next_loc_note
!= loc_note
)
20819 next_real
= NULL_RTX
;
20822 next_note
= NEXT_INSN (loc_note
);
20824 || INSN_DELETED_P (next_note
)
20825 || ! NOTE_P (next_note
)
20826 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20827 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20828 next_note
= NULL_RTX
;
20831 next_real
= next_real_insn (loc_note
);
20835 expected_next_loc_note
= next_note
;
20836 cached_next_real_insn
= next_real
;
20839 cached_next_real_insn
= NULL_RTX
;
20841 /* If there are no instructions which would be affected by this note,
20842 don't do anything. */
20844 && next_real
== NULL_RTX
20845 && !NOTE_DURING_CALL_P (loc_note
))
20848 if (next_real
== NULL_RTX
)
20849 next_real
= get_last_insn ();
20851 /* If there were any real insns between note we processed last time
20852 and this note (or if it is the first note), clear
20853 last_{,postcall_}label so that they are not reused this time. */
20854 if (last_var_location_insn
== NULL_RTX
20855 || last_var_location_insn
!= next_real
20856 || last_in_cold_section_p
!= in_cold_section_p
)
20859 last_postcall_label
= NULL
;
20864 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20865 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20866 NOTE_DURING_CALL_P (loc_note
)
20867 ? last_postcall_label
: last_label
);
20868 if (newloc
== NULL
)
20877 /* If there were no real insns between note we processed last time
20878 and this note, use the label we emitted last time. Otherwise
20879 create a new label and emit it. */
20880 if (last_label
== NULL
)
20882 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20883 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20885 last_label
= ggc_strdup (loclabel
);
20886 /* See if loclabel might be equal to .Ltext0. If yes,
20887 bump first_loclabel_num_not_at_text_label. */
20888 if (!have_multiple_function_sections
20889 && in_first_function_p
20890 && maybe_at_text_label_p
)
20892 static rtx last_start
;
20894 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
20895 if (insn
== last_start
)
20897 else if (!NONDEBUG_INSN_P (insn
))
20901 rtx body
= PATTERN (insn
);
20902 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
20904 /* Inline asm could occupy zero bytes. */
20905 else if (GET_CODE (body
) == ASM_INPUT
20906 || asm_noperands (body
) >= 0)
20908 #ifdef HAVE_attr_length
20909 else if (get_attr_min_length (insn
) == 0)
20914 /* Assume insn has non-zero length. */
20915 maybe_at_text_label_p
= false;
20919 if (maybe_at_text_label_p
)
20921 last_start
= loc_note
;
20922 first_loclabel_num_not_at_text_label
= loclabel_num
;
20929 struct call_arg_loc_node
*ca_loc
20930 = ggc_alloc_cleared_call_arg_loc_node ();
20931 rtx prev
= prev_real_insn (loc_note
), x
;
20932 ca_loc
->call_arg_loc_note
= loc_note
;
20933 ca_loc
->next
= NULL
;
20934 ca_loc
->label
= last_label
;
20937 || (NONJUMP_INSN_P (prev
)
20938 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20939 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20940 if (!CALL_P (prev
))
20941 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20942 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20943 x
= get_call_rtx_from (PATTERN (prev
));
20946 x
= XEXP (XEXP (x
, 0), 0);
20947 if (GET_CODE (x
) == SYMBOL_REF
20948 && SYMBOL_REF_DECL (x
)
20949 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20950 ca_loc
->symbol_ref
= x
;
20952 ca_loc
->block
= insn_scope (prev
);
20953 if (call_arg_locations
)
20954 call_arg_loc_last
->next
= ca_loc
;
20956 call_arg_locations
= ca_loc
;
20957 call_arg_loc_last
= ca_loc
;
20959 else if (!NOTE_DURING_CALL_P (loc_note
))
20960 newloc
->label
= last_label
;
20963 if (!last_postcall_label
)
20965 sprintf (loclabel
, "%s-1", last_label
);
20966 last_postcall_label
= ggc_strdup (loclabel
);
20968 newloc
->label
= last_postcall_label
;
20971 last_var_location_insn
= next_real
;
20972 last_in_cold_section_p
= in_cold_section_p
;
20975 /* Note in one location list that text section has changed. */
20978 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20980 var_loc_list
*list
= (var_loc_list
*) *slot
;
20982 list
->last_before_switch
20983 = list
->last
->next
? list
->last
->next
: list
->last
;
20987 /* Note in all location lists that text section has changed. */
20990 var_location_switch_text_section (void)
20992 if (decl_loc_table
== NULL
)
20995 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20998 /* Create a new line number table. */
21000 static dw_line_info_table
*
21001 new_line_info_table (void)
21003 dw_line_info_table
*table
;
21005 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21006 table
->file_num
= 1;
21007 table
->line_num
= 1;
21008 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21013 /* Lookup the "current" table into which we emit line info, so
21014 that we don't have to do it for every source line. */
21017 set_cur_line_info_table (section
*sec
)
21019 dw_line_info_table
*table
;
21021 if (sec
== text_section
)
21022 table
= text_section_line_info
;
21023 else if (sec
== cold_text_section
)
21025 table
= cold_text_section_line_info
;
21028 cold_text_section_line_info
= table
= new_line_info_table ();
21029 table
->end_label
= cold_end_label
;
21034 const char *end_label
;
21036 if (flag_reorder_blocks_and_partition
)
21038 if (in_cold_section_p
)
21039 end_label
= crtl
->subsections
.cold_section_end_label
;
21041 end_label
= crtl
->subsections
.hot_section_end_label
;
21045 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21046 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21047 current_function_funcdef_no
);
21048 end_label
= ggc_strdup (label
);
21051 table
= new_line_info_table ();
21052 table
->end_label
= end_label
;
21054 vec_safe_push (separate_line_info
, table
);
21057 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21058 table
->is_stmt
= (cur_line_info_table
21059 ? cur_line_info_table
->is_stmt
21060 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21061 cur_line_info_table
= table
;
21065 /* We need to reset the locations at the beginning of each
21066 function. We can't do this in the end_function hook, because the
21067 declarations that use the locations won't have been output when
21068 that hook is called. Also compute have_multiple_function_sections here. */
21071 dwarf2out_begin_function (tree fun
)
21073 section
*sec
= function_section (fun
);
21075 if (sec
!= text_section
)
21076 have_multiple_function_sections
= true;
21078 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21080 gcc_assert (current_function_decl
== fun
);
21081 cold_text_section
= unlikely_text_section ();
21082 switch_to_section (cold_text_section
);
21083 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21084 switch_to_section (sec
);
21087 dwarf2out_note_section_used ();
21088 call_site_count
= 0;
21089 tail_call_site_count
= 0;
21091 set_cur_line_info_table (sec
);
21094 /* Helper function of dwarf2out_end_function, called only after emitting
21095 the very first function into assembly. Check if some .debug_loc range
21096 might end with a .LVL* label that could be equal to .Ltext0.
21097 In that case we must force using absolute addresses in .debug_loc ranges,
21098 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21099 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21101 Set have_multiple_function_sections to true in that case and
21102 terminate htab traversal. */
21105 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21107 var_loc_list
*entry
;
21108 struct var_loc_node
*node
;
21110 entry
= (var_loc_list
*) *slot
;
21111 node
= entry
->first
;
21112 if (node
&& node
->next
&& node
->next
->label
)
21115 const char *label
= node
->next
->label
;
21116 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21118 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21120 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21121 if (strcmp (label
, loclabel
) == 0)
21123 have_multiple_function_sections
= true;
21131 /* Hook called after emitting a function into assembly.
21132 This does something only for the very first function emitted. */
21135 dwarf2out_end_function (unsigned int)
21137 if (in_first_function_p
21138 && !have_multiple_function_sections
21139 && first_loclabel_num_not_at_text_label
21141 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21143 in_first_function_p
= false;
21144 maybe_at_text_label_p
= false;
21147 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21150 push_dw_line_info_entry (dw_line_info_table
*table
,
21151 enum dw_line_info_opcode opcode
, unsigned int val
)
21153 dw_line_info_entry e
;
21156 vec_safe_push (table
->entries
, e
);
21159 /* Output a label to mark the beginning of a source code line entry
21160 and record information relating to this source line, in
21161 'line_info_table' for later output of the .debug_line section. */
21162 /* ??? The discriminator parameter ought to be unsigned. */
21165 dwarf2out_source_line (unsigned int line
, const char *filename
,
21166 int discriminator
, bool is_stmt
)
21168 unsigned int file_num
;
21169 dw_line_info_table
*table
;
21171 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21174 /* The discriminator column was added in dwarf4. Simplify the below
21175 by simply removing it if we're not supposed to output it. */
21176 if (dwarf_version
< 4 && dwarf_strict
)
21179 table
= cur_line_info_table
;
21180 file_num
= maybe_emit_file (lookup_filename (filename
));
21182 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21183 the debugger has used the second (possibly duplicate) line number
21184 at the beginning of the function to mark the end of the prologue.
21185 We could eliminate any other duplicates within the function. For
21186 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21187 that second line number entry. */
21188 /* Recall that this end-of-prologue indication is *not* the same thing
21189 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21190 to which the hook corresponds, follows the last insn that was
21191 emitted by gen_prologue. What we need is to precede the first insn
21192 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21193 insn that corresponds to something the user wrote. These may be
21194 very different locations once scheduling is enabled. */
21196 if (0 && file_num
== table
->file_num
21197 && line
== table
->line_num
21198 && discriminator
== table
->discrim_num
21199 && is_stmt
== table
->is_stmt
)
21202 switch_to_section (current_function_section ());
21204 /* If requested, emit something human-readable. */
21205 if (flag_debug_asm
)
21206 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21208 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21210 /* Emit the .loc directive understood by GNU as. */
21211 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21212 file_num, line, is_stmt, discriminator */
21213 fputs ("\t.loc ", asm_out_file
);
21214 fprint_ul (asm_out_file
, file_num
);
21215 putc (' ', asm_out_file
);
21216 fprint_ul (asm_out_file
, line
);
21217 putc (' ', asm_out_file
);
21218 putc ('0', asm_out_file
);
21220 if (is_stmt
!= table
->is_stmt
)
21222 fputs (" is_stmt ", asm_out_file
);
21223 putc (is_stmt
? '1' : '0', asm_out_file
);
21225 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21227 gcc_assert (discriminator
> 0);
21228 fputs (" discriminator ", asm_out_file
);
21229 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21231 putc ('\n', asm_out_file
);
21235 unsigned int label_num
= ++line_info_label_num
;
21237 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21239 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21240 if (file_num
!= table
->file_num
)
21241 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21242 if (discriminator
!= table
->discrim_num
)
21243 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21244 if (is_stmt
!= table
->is_stmt
)
21245 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21246 push_dw_line_info_entry (table
, LI_set_line
, line
);
21249 table
->file_num
= file_num
;
21250 table
->line_num
= line
;
21251 table
->discrim_num
= discriminator
;
21252 table
->is_stmt
= is_stmt
;
21253 table
->in_use
= true;
21256 /* Record the beginning of a new source file. */
21259 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21261 if (flag_eliminate_dwarf2_dups
)
21263 /* Record the beginning of the file for break_out_includes. */
21264 dw_die_ref bincl_die
;
21266 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21267 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21270 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21273 e
.code
= DW_MACINFO_start_file
;
21275 e
.info
= ggc_strdup (filename
);
21276 vec_safe_push (macinfo_table
, e
);
21280 /* Record the end of a source file. */
21283 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21285 if (flag_eliminate_dwarf2_dups
)
21286 /* Record the end of the file for break_out_includes. */
21287 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21289 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21292 e
.code
= DW_MACINFO_end_file
;
21295 vec_safe_push (macinfo_table
, e
);
21299 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21300 the tail part of the directive line, i.e. the part which is past the
21301 initial whitespace, #, whitespace, directive-name, whitespace part. */
21304 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21305 const char *buffer ATTRIBUTE_UNUSED
)
21307 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21310 /* Insert a dummy first entry to be able to optimize the whole
21311 predefined macro block using DW_MACRO_GNU_transparent_include. */
21312 if (macinfo_table
->is_empty () && lineno
<= 1)
21317 vec_safe_push (macinfo_table
, e
);
21319 e
.code
= DW_MACINFO_define
;
21321 e
.info
= ggc_strdup (buffer
);
21322 vec_safe_push (macinfo_table
, e
);
21326 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21327 the tail part of the directive line, i.e. the part which is past the
21328 initial whitespace, #, whitespace, directive-name, whitespace part. */
21331 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21332 const char *buffer ATTRIBUTE_UNUSED
)
21334 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21337 /* Insert a dummy first entry to be able to optimize the whole
21338 predefined macro block using DW_MACRO_GNU_transparent_include. */
21339 if (macinfo_table
->is_empty () && lineno
<= 1)
21344 vec_safe_push (macinfo_table
, e
);
21346 e
.code
= DW_MACINFO_undef
;
21348 e
.info
= ggc_strdup (buffer
);
21349 vec_safe_push (macinfo_table
, e
);
21353 /* Helpers to manipulate hash table of CUs. */
21355 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21357 typedef macinfo_entry value_type
;
21358 typedef macinfo_entry compare_type
;
21359 static inline hashval_t
hash (const value_type
*);
21360 static inline bool equal (const value_type
*, const compare_type
*);
21364 macinfo_entry_hasher::hash (const value_type
*entry
)
21366 return htab_hash_string (entry
->info
);
21370 macinfo_entry_hasher::equal (const value_type
*entry1
,
21371 const compare_type
*entry2
)
21373 return !strcmp (entry1
->info
, entry2
->info
);
21376 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21378 /* Output a single .debug_macinfo entry. */
21381 output_macinfo_op (macinfo_entry
*ref
)
21385 struct indirect_string_node
*node
;
21386 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21387 struct dwarf_file_data
*fd
;
21391 case DW_MACINFO_start_file
:
21392 fd
= lookup_filename (ref
->info
);
21393 file_num
= maybe_emit_file (fd
);
21394 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21395 dw2_asm_output_data_uleb128 (ref
->lineno
,
21396 "Included from line number %lu",
21397 (unsigned long) ref
->lineno
);
21398 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21400 case DW_MACINFO_end_file
:
21401 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21403 case DW_MACINFO_define
:
21404 case DW_MACINFO_undef
:
21405 len
= strlen (ref
->info
) + 1;
21407 && len
> DWARF_OFFSET_SIZE
21408 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21409 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21411 ref
->code
= ref
->code
== DW_MACINFO_define
21412 ? DW_MACRO_GNU_define_indirect
21413 : DW_MACRO_GNU_undef_indirect
;
21414 output_macinfo_op (ref
);
21417 dw2_asm_output_data (1, ref
->code
,
21418 ref
->code
== DW_MACINFO_define
21419 ? "Define macro" : "Undefine macro");
21420 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21421 (unsigned long) ref
->lineno
);
21422 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21424 case DW_MACRO_GNU_define_indirect
:
21425 case DW_MACRO_GNU_undef_indirect
:
21426 node
= find_AT_string (ref
->info
);
21428 && ((node
->form
== DW_FORM_strp
)
21429 || (node
->form
== DW_FORM_GNU_str_index
)));
21430 dw2_asm_output_data (1, ref
->code
,
21431 ref
->code
== DW_MACRO_GNU_define_indirect
21432 ? "Define macro indirect"
21433 : "Undefine macro indirect");
21434 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21435 (unsigned long) ref
->lineno
);
21436 if (node
->form
== DW_FORM_strp
)
21437 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21438 debug_str_section
, "The macro: \"%s\"",
21441 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21444 case DW_MACRO_GNU_transparent_include
:
21445 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21446 ASM_GENERATE_INTERNAL_LABEL (label
,
21447 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21448 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21451 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21452 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21457 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21458 other compilation unit .debug_macinfo sections. IDX is the first
21459 index of a define/undef, return the number of ops that should be
21460 emitted in a comdat .debug_macinfo section and emit
21461 a DW_MACRO_GNU_transparent_include entry referencing it.
21462 If the define/undef entry should be emitted normally, return 0. */
21465 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21466 macinfo_hash_type
*macinfo_htab
)
21468 macinfo_entry
*first
, *second
, *cur
, *inc
;
21469 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21470 unsigned char checksum
[16];
21471 struct md5_ctx ctx
;
21472 char *grp_name
, *tail
;
21474 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21475 macinfo_entry
**slot
;
21477 first
= &(*macinfo_table
)[idx
];
21478 second
= &(*macinfo_table
)[idx
+ 1];
21480 /* Optimize only if there are at least two consecutive define/undef ops,
21481 and either all of them are before first DW_MACINFO_start_file
21482 with lineno {0,1} (i.e. predefined macro block), or all of them are
21483 in some included header file. */
21484 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21486 if (vec_safe_is_empty (files
))
21488 if (first
->lineno
> 1 || second
->lineno
> 1)
21491 else if (first
->lineno
== 0)
21494 /* Find the last define/undef entry that can be grouped together
21495 with first and at the same time compute md5 checksum of their
21496 codes, linenumbers and strings. */
21497 md5_init_ctx (&ctx
);
21498 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21499 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21501 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21505 unsigned char code
= cur
->code
;
21506 md5_process_bytes (&code
, 1, &ctx
);
21507 checksum_uleb128 (cur
->lineno
, &ctx
);
21508 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21510 md5_finish_ctx (&ctx
, checksum
);
21513 /* From the containing include filename (if any) pick up just
21514 usable characters from its basename. */
21515 if (vec_safe_is_empty (files
))
21518 base
= lbasename (files
->last ().info
);
21519 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21520 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21521 encoded_filename_len
++;
21522 /* Count . at the end. */
21523 if (encoded_filename_len
)
21524 encoded_filename_len
++;
21526 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21527 linebuf_len
= strlen (linebuf
);
21529 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21530 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21532 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21533 tail
= grp_name
+ 4;
21534 if (encoded_filename_len
)
21536 for (i
= 0; base
[i
]; i
++)
21537 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21541 memcpy (tail
, linebuf
, linebuf_len
);
21542 tail
+= linebuf_len
;
21544 for (i
= 0; i
< 16; i
++)
21545 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21547 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21548 in the empty vector entry before the first define/undef. */
21549 inc
= &(*macinfo_table
)[idx
- 1];
21550 inc
->code
= DW_MACRO_GNU_transparent_include
;
21552 inc
->info
= ggc_strdup (grp_name
);
21553 if (!macinfo_htab
->is_created ())
21554 macinfo_htab
->create (10);
21555 /* Avoid emitting duplicates. */
21556 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21561 /* If such an entry has been used before, just emit
21562 a DW_MACRO_GNU_transparent_include op. */
21564 output_macinfo_op (inc
);
21565 /* And clear all macinfo_entry in the range to avoid emitting them
21566 in the second pass. */
21567 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21576 inc
->lineno
= macinfo_htab
->elements ();
21577 output_macinfo_op (inc
);
21582 /* Save any strings needed by the macinfo table in the debug str
21583 table. All strings must be collected into the table by the time
21584 index_string is called. */
21587 save_macinfo_strings (void)
21591 macinfo_entry
*ref
;
21593 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21597 /* Match the logic in output_macinfo_op to decide on
21598 indirect strings. */
21599 case DW_MACINFO_define
:
21600 case DW_MACINFO_undef
:
21601 len
= strlen (ref
->info
) + 1;
21603 && len
> DWARF_OFFSET_SIZE
21604 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21605 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21606 set_indirect_string (find_AT_string (ref
->info
));
21608 case DW_MACRO_GNU_define_indirect
:
21609 case DW_MACRO_GNU_undef_indirect
:
21610 set_indirect_string (find_AT_string (ref
->info
));
21618 /* Output macinfo section(s). */
21621 output_macinfo (void)
21624 unsigned long length
= vec_safe_length (macinfo_table
);
21625 macinfo_entry
*ref
;
21626 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21627 macinfo_hash_type macinfo_htab
;
21632 /* output_macinfo* uses these interchangeably. */
21633 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21634 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21635 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21636 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21638 /* For .debug_macro emit the section header. */
21641 dw2_asm_output_data (2, 4, "DWARF macro version number");
21642 if (DWARF_OFFSET_SIZE
== 8)
21643 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21645 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21646 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21647 (!dwarf_split_debug_info
? debug_line_section_label
21648 : debug_skeleton_line_section_label
),
21649 debug_line_section
, NULL
);
21652 /* In the first loop, it emits the primary .debug_macinfo section
21653 and after each emitted op the macinfo_entry is cleared.
21654 If a longer range of define/undef ops can be optimized using
21655 DW_MACRO_GNU_transparent_include, the
21656 DW_MACRO_GNU_transparent_include op is emitted and kept in
21657 the vector before the first define/undef in the range and the
21658 whole range of define/undef ops is not emitted and kept. */
21659 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21663 case DW_MACINFO_start_file
:
21664 vec_safe_push (files
, *ref
);
21666 case DW_MACINFO_end_file
:
21667 if (!vec_safe_is_empty (files
))
21670 case DW_MACINFO_define
:
21671 case DW_MACINFO_undef
:
21673 && HAVE_COMDAT_GROUP
21674 && vec_safe_length (files
) != 1
21677 && (*macinfo_table
)[i
- 1].code
== 0)
21679 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21688 /* A dummy entry may be inserted at the beginning to be able
21689 to optimize the whole block of predefined macros. */
21695 output_macinfo_op (ref
);
21700 if (!macinfo_htab
.is_created ())
21703 macinfo_htab
.dispose ();
21705 /* If any DW_MACRO_GNU_transparent_include were used, on those
21706 DW_MACRO_GNU_transparent_include entries terminate the
21707 current chain and switch to a new comdat .debug_macinfo
21708 section and emit the define/undef entries within it. */
21709 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21714 case DW_MACRO_GNU_transparent_include
:
21716 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21717 tree comdat_key
= get_identifier (ref
->info
);
21718 /* Terminate the previous .debug_macinfo section. */
21719 dw2_asm_output_data (1, 0, "End compilation unit");
21720 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21722 | SECTION_LINKONCE
,
21724 ASM_GENERATE_INTERNAL_LABEL (label
,
21725 DEBUG_MACRO_SECTION_LABEL
,
21727 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21730 dw2_asm_output_data (2, 4, "DWARF macro version number");
21731 if (DWARF_OFFSET_SIZE
== 8)
21732 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21734 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21737 case DW_MACINFO_define
:
21738 case DW_MACINFO_undef
:
21739 output_macinfo_op (ref
);
21744 gcc_unreachable ();
21748 /* Set up for Dwarf output at the start of compilation. */
21751 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21753 /* Allocate the file_table. */
21754 file_table
= htab_create_ggc (50, file_table_hash
,
21755 file_table_eq
, NULL
);
21757 /* Allocate the decl_die_table. */
21758 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21759 decl_die_table_eq
, NULL
);
21761 /* Allocate the decl_loc_table. */
21762 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21763 decl_loc_table_eq
, NULL
);
21765 /* Allocate the cached_dw_loc_list_table. */
21766 cached_dw_loc_list_table
21767 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21768 cached_dw_loc_list_table_eq
, NULL
);
21770 /* Allocate the initial hunk of the decl_scope_table. */
21771 vec_alloc (decl_scope_table
, 256);
21773 /* Allocate the initial hunk of the abbrev_die_table. */
21774 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21775 (ABBREV_DIE_TABLE_INCREMENT
);
21776 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21777 /* Zero-th entry is allocated, but unused. */
21778 abbrev_die_table_in_use
= 1;
21780 /* Allocate the pubtypes and pubnames vectors. */
21781 vec_alloc (pubname_table
, 32);
21782 vec_alloc (pubtype_table
, 32);
21784 vec_alloc (incomplete_types
, 64);
21786 vec_alloc (used_rtx_array
, 32);
21788 if (!dwarf_split_debug_info
)
21790 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21791 SECTION_DEBUG
, NULL
);
21792 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21793 SECTION_DEBUG
, NULL
);
21794 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21795 SECTION_DEBUG
, NULL
);
21799 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21800 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21801 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21802 SECTION_DEBUG
| SECTION_EXCLUDE
,
21804 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21805 SECTION_DEBUG
, NULL
);
21806 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21807 SECTION_DEBUG
, NULL
);
21808 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21809 SECTION_DEBUG
, NULL
);
21810 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21811 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21813 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21814 the main .o, but the skeleton_line goes into the split off dwo. */
21815 debug_skeleton_line_section
21816 = get_section (DEBUG_DWO_LINE_SECTION
,
21817 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21818 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21819 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21820 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21821 SECTION_DEBUG
| SECTION_EXCLUDE
,
21823 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21824 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21825 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21826 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21827 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
21828 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
21830 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21831 SECTION_DEBUG
, NULL
);
21832 debug_macinfo_section
= get_section (dwarf_strict
21833 ? DEBUG_MACINFO_SECTION
21834 : DEBUG_MACRO_SECTION
,
21835 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21836 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21837 SECTION_DEBUG
, NULL
);
21838 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21839 SECTION_DEBUG
, NULL
);
21840 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21841 SECTION_DEBUG
, NULL
);
21842 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21843 DEBUG_STR_SECTION_FLAGS
, NULL
);
21844 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21845 SECTION_DEBUG
, NULL
);
21846 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21847 SECTION_DEBUG
, NULL
);
21849 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21850 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21851 DEBUG_ABBREV_SECTION_LABEL
, 0);
21852 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21853 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21854 COLD_TEXT_SECTION_LABEL
, 0);
21855 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21857 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21858 DEBUG_INFO_SECTION_LABEL
, 0);
21859 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21860 DEBUG_LINE_SECTION_LABEL
, 0);
21861 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21862 DEBUG_RANGES_SECTION_LABEL
, 0);
21863 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21864 DEBUG_ADDR_SECTION_LABEL
, 0);
21865 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21867 ? DEBUG_MACINFO_SECTION_LABEL
21868 : DEBUG_MACRO_SECTION_LABEL
, 0);
21869 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21871 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21872 vec_alloc (macinfo_table
, 64);
21874 switch_to_section (text_section
);
21875 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21877 /* Make sure the line number table for .text always exists. */
21878 text_section_line_info
= new_line_info_table ();
21879 text_section_line_info
->end_label
= text_end_label
;
21882 /* Called before compile () starts outputtting functions, variables
21883 and toplevel asms into assembly. */
21886 dwarf2out_assembly_start (void)
21888 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21889 && dwarf2out_do_cfi_asm ()
21890 && (!(flag_unwind_tables
|| flag_exceptions
)
21891 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21892 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21895 /* A helper function for dwarf2out_finish called through
21896 htab_traverse. Assign a string its index. All strings must be
21897 collected into the table by the time index_string is called,
21898 because the indexing code relies on htab_traverse to traverse nodes
21899 in the same order for each run. */
21902 index_string (void **h
, void *v
)
21904 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21905 unsigned int *index
= (unsigned int *) v
;
21907 find_string_form (node
);
21908 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21910 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21911 node
->index
= *index
;
21917 /* A helper function for output_indirect_strings called through
21918 htab_traverse. Output the offset to a string and update the
21922 output_index_string_offset (void **h
, void *v
)
21924 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21925 unsigned int *offset
= (unsigned int *) v
;
21927 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21929 /* Assert that this node has been assigned an index. */
21930 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21931 && node
->index
!= NOT_INDEXED
);
21932 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21933 "indexed string 0x%x: %s", node
->index
, node
->str
);
21934 *offset
+= strlen (node
->str
) + 1;
21939 /* A helper function for dwarf2out_finish called through
21940 htab_traverse. Output the indexed string. */
21943 output_index_string (void **h
, void *v
)
21945 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21946 unsigned int *cur_idx
= (unsigned int *) v
;
21948 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21950 /* Assert that the strings are output in the same order as their
21951 indexes were assigned. */
21952 gcc_assert (*cur_idx
== node
->index
);
21953 assemble_string (node
->str
, strlen (node
->str
) + 1);
21959 /* A helper function for dwarf2out_finish called through
21960 htab_traverse. Emit one queued .debug_str string. */
21963 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21965 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21967 node
->form
= find_string_form (node
);
21968 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
21970 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21971 assemble_string (node
->str
, strlen (node
->str
) + 1);
21977 /* Output the indexed string table. */
21980 output_indirect_strings (void)
21982 switch_to_section (debug_str_section
);
21983 if (!dwarf_split_debug_info
)
21984 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
21987 unsigned int offset
= 0;
21988 unsigned int cur_idx
= 0;
21990 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
21992 switch_to_section (debug_str_offsets_section
);
21993 htab_traverse_noresize (debug_str_hash
,
21994 output_index_string_offset
,
21996 switch_to_section (debug_str_dwo_section
);
21997 htab_traverse_noresize (debug_str_hash
,
21998 output_index_string
,
22003 /* Callback for htab_traverse to assign an index to an entry in the
22004 table, and to write that entry to the .debug_addr section. */
22007 output_addr_table_entry (void **slot
, void *data
)
22009 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22010 unsigned int *cur_index
= (unsigned int *)data
;
22012 if (entry
->refcount
== 0)
22014 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22015 || entry
->index
== NOT_INDEXED
);
22019 gcc_assert (entry
->index
== *cur_index
);
22022 switch (entry
->kind
)
22025 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22026 "0x%x", entry
->index
);
22028 case ate_kind_rtx_dtprel
:
22029 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22030 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22033 fputc ('\n', asm_out_file
);
22035 case ate_kind_label
:
22036 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22037 "0x%x", entry
->index
);
22040 gcc_unreachable ();
22045 /* Produce the .debug_addr section. */
22048 output_addr_table (void)
22050 unsigned int index
= 0;
22051 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22054 switch_to_section (debug_addr_section
);
22055 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22058 #if ENABLE_ASSERT_CHECKING
22059 /* Verify that all marks are clear. */
22062 verify_marks_clear (dw_die_ref die
)
22066 gcc_assert (! die
->die_mark
);
22067 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22069 #endif /* ENABLE_ASSERT_CHECKING */
22071 /* Clear the marks for a die and its children.
22072 Be cool if the mark isn't set. */
22075 prune_unmark_dies (dw_die_ref die
)
22081 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22084 /* Given DIE that we're marking as used, find any other dies
22085 it references as attributes and mark them as used. */
22088 prune_unused_types_walk_attribs (dw_die_ref die
)
22093 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22095 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22097 /* A reference to another DIE.
22098 Make sure that it will get emitted.
22099 If it was broken out into a comdat group, don't follow it. */
22100 if (! AT_ref (a
)->comdat_type_p
22101 || a
->dw_attr
== DW_AT_specification
)
22102 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22104 /* Set the string's refcount to 0 so that prune_unused_types_mark
22105 accounts properly for it. */
22106 if (AT_class (a
) == dw_val_class_str
)
22107 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22111 /* Mark the generic parameters and arguments children DIEs of DIE. */
22114 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22118 if (die
== NULL
|| die
->die_child
== NULL
)
22120 c
= die
->die_child
;
22123 switch (c
->die_tag
)
22125 case DW_TAG_template_type_param
:
22126 case DW_TAG_template_value_param
:
22127 case DW_TAG_GNU_template_template_param
:
22128 case DW_TAG_GNU_template_parameter_pack
:
22129 prune_unused_types_mark (c
, 1);
22135 } while (c
&& c
!= die
->die_child
);
22138 /* Mark DIE as being used. If DOKIDS is true, then walk down
22139 to DIE's children. */
22142 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22146 if (die
->die_mark
== 0)
22148 /* We haven't done this node yet. Mark it as used. */
22150 /* If this is the DIE of a generic type instantiation,
22151 mark the children DIEs that describe its generic parms and
22153 prune_unused_types_mark_generic_parms_dies (die
);
22155 /* We also have to mark its parents as used.
22156 (But we don't want to mark our parent's kids due to this,
22157 unless it is a class.) */
22158 if (die
->die_parent
)
22159 prune_unused_types_mark (die
->die_parent
,
22160 class_scope_p (die
->die_parent
));
22162 /* Mark any referenced nodes. */
22163 prune_unused_types_walk_attribs (die
);
22165 /* If this node is a specification,
22166 also mark the definition, if it exists. */
22167 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22168 prune_unused_types_mark (die
->die_definition
, 1);
22171 if (dokids
&& die
->die_mark
!= 2)
22173 /* We need to walk the children, but haven't done so yet.
22174 Remember that we've walked the kids. */
22177 /* If this is an array type, we need to make sure our
22178 kids get marked, even if they're types. If we're
22179 breaking out types into comdat sections, do this
22180 for all type definitions. */
22181 if (die
->die_tag
== DW_TAG_array_type
22182 || (use_debug_types
22183 && is_type_die (die
) && ! is_declaration_die (die
)))
22184 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22186 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22190 /* For local classes, look if any static member functions were emitted
22191 and if so, mark them. */
22194 prune_unused_types_walk_local_classes (dw_die_ref die
)
22198 if (die
->die_mark
== 2)
22201 switch (die
->die_tag
)
22203 case DW_TAG_structure_type
:
22204 case DW_TAG_union_type
:
22205 case DW_TAG_class_type
:
22208 case DW_TAG_subprogram
:
22209 if (!get_AT_flag (die
, DW_AT_declaration
)
22210 || die
->die_definition
!= NULL
)
22211 prune_unused_types_mark (die
, 1);
22218 /* Mark children. */
22219 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22222 /* Walk the tree DIE and mark types that we actually use. */
22225 prune_unused_types_walk (dw_die_ref die
)
22229 /* Don't do anything if this node is already marked and
22230 children have been marked as well. */
22231 if (die
->die_mark
== 2)
22234 switch (die
->die_tag
)
22236 case DW_TAG_structure_type
:
22237 case DW_TAG_union_type
:
22238 case DW_TAG_class_type
:
22239 if (die
->die_perennial_p
)
22242 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22243 if (c
->die_tag
== DW_TAG_subprogram
)
22246 /* Finding used static member functions inside of classes
22247 is needed just for local classes, because for other classes
22248 static member function DIEs with DW_AT_specification
22249 are emitted outside of the DW_TAG_*_type. If we ever change
22250 it, we'd need to call this even for non-local classes. */
22252 prune_unused_types_walk_local_classes (die
);
22254 /* It's a type node --- don't mark it. */
22257 case DW_TAG_const_type
:
22258 case DW_TAG_packed_type
:
22259 case DW_TAG_pointer_type
:
22260 case DW_TAG_reference_type
:
22261 case DW_TAG_rvalue_reference_type
:
22262 case DW_TAG_volatile_type
:
22263 case DW_TAG_typedef
:
22264 case DW_TAG_array_type
:
22265 case DW_TAG_interface_type
:
22266 case DW_TAG_friend
:
22267 case DW_TAG_variant_part
:
22268 case DW_TAG_enumeration_type
:
22269 case DW_TAG_subroutine_type
:
22270 case DW_TAG_string_type
:
22271 case DW_TAG_set_type
:
22272 case DW_TAG_subrange_type
:
22273 case DW_TAG_ptr_to_member_type
:
22274 case DW_TAG_file_type
:
22275 if (die
->die_perennial_p
)
22278 /* It's a type node --- don't mark it. */
22282 /* Mark everything else. */
22286 if (die
->die_mark
== 0)
22290 /* Now, mark any dies referenced from here. */
22291 prune_unused_types_walk_attribs (die
);
22296 /* Mark children. */
22297 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22300 /* Increment the string counts on strings referred to from DIE's
22304 prune_unused_types_update_strings (dw_die_ref die
)
22309 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22310 if (AT_class (a
) == dw_val_class_str
)
22312 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22314 /* Avoid unnecessarily putting strings that are used less than
22315 twice in the hash table. */
22317 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22320 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22321 htab_hash_string (s
->str
),
22323 gcc_assert (*slot
== NULL
);
22329 /* Remove from the tree DIE any dies that aren't marked. */
22332 prune_unused_types_prune (dw_die_ref die
)
22336 gcc_assert (die
->die_mark
);
22337 prune_unused_types_update_strings (die
);
22339 if (! die
->die_child
)
22342 c
= die
->die_child
;
22344 dw_die_ref prev
= c
;
22345 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22346 if (c
== die
->die_child
)
22348 /* No marked children between 'prev' and the end of the list. */
22350 /* No marked children at all. */
22351 die
->die_child
= NULL
;
22354 prev
->die_sib
= c
->die_sib
;
22355 die
->die_child
= prev
;
22360 if (c
!= prev
->die_sib
)
22362 prune_unused_types_prune (c
);
22363 } while (c
!= die
->die_child
);
22366 /* Remove dies representing declarations that we never use. */
22369 prune_unused_types (void)
22372 limbo_die_node
*node
;
22373 comdat_type_node
*ctnode
;
22375 dw_die_ref base_type
;
22377 #if ENABLE_ASSERT_CHECKING
22378 /* All the marks should already be clear. */
22379 verify_marks_clear (comp_unit_die ());
22380 for (node
= limbo_die_list
; node
; node
= node
->next
)
22381 verify_marks_clear (node
->die
);
22382 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22383 verify_marks_clear (ctnode
->root_die
);
22384 #endif /* ENABLE_ASSERT_CHECKING */
22386 /* Mark types that are used in global variables. */
22387 premark_types_used_by_global_vars ();
22389 /* Set the mark on nodes that are actually used. */
22390 prune_unused_types_walk (comp_unit_die ());
22391 for (node
= limbo_die_list
; node
; node
= node
->next
)
22392 prune_unused_types_walk (node
->die
);
22393 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22395 prune_unused_types_walk (ctnode
->root_die
);
22396 prune_unused_types_mark (ctnode
->type_die
, 1);
22399 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22400 are unusual in that they are pubnames that are the children of pubtypes.
22401 They should only be marked via their parent DW_TAG_enumeration_type die,
22402 not as roots in themselves. */
22403 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22404 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22405 prune_unused_types_mark (pub
->die
, 1);
22406 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22407 prune_unused_types_mark (base_type
, 1);
22409 if (debug_str_hash
)
22410 htab_empty (debug_str_hash
);
22411 if (skeleton_debug_str_hash
)
22412 htab_empty (skeleton_debug_str_hash
);
22413 prune_unused_types_prune (comp_unit_die ());
22414 for (node
= limbo_die_list
; node
; node
= node
->next
)
22415 prune_unused_types_prune (node
->die
);
22416 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22417 prune_unused_types_prune (ctnode
->root_die
);
22419 /* Leave the marks clear. */
22420 prune_unmark_dies (comp_unit_die ());
22421 for (node
= limbo_die_list
; node
; node
= node
->next
)
22422 prune_unmark_dies (node
->die
);
22423 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22424 prune_unmark_dies (ctnode
->root_die
);
22427 /* Set the parameter to true if there are any relative pathnames in
22430 file_table_relative_p (void ** slot
, void *param
)
22432 bool *p
= (bool *) param
;
22433 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22434 if (!IS_ABSOLUTE_PATH (d
->filename
))
22442 /* Helpers to manipulate hash table of comdat type units. */
22444 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22446 typedef comdat_type_node value_type
;
22447 typedef comdat_type_node compare_type
;
22448 static inline hashval_t
hash (const value_type
*);
22449 static inline bool equal (const value_type
*, const compare_type
*);
22453 comdat_type_hasher::hash (const value_type
*type_node
)
22456 memcpy (&h
, type_node
->signature
, sizeof (h
));
22461 comdat_type_hasher::equal (const value_type
*type_node_1
,
22462 const compare_type
*type_node_2
)
22464 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22465 DWARF_TYPE_SIGNATURE_SIZE
));
22468 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22469 to the location it would have been added, should we know its
22470 DECL_ASSEMBLER_NAME when we added other attributes. This will
22471 probably improve compactness of debug info, removing equivalent
22472 abbrevs, and hide any differences caused by deferring the
22473 computation of the assembler name, triggered by e.g. PCH. */
22476 move_linkage_attr (dw_die_ref die
)
22478 unsigned ix
= vec_safe_length (die
->die_attr
);
22479 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22481 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22482 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22486 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22488 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22492 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22494 die
->die_attr
->pop ();
22495 die
->die_attr
->quick_insert (ix
, linkage
);
22499 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22500 referenced from typed stack ops and count how often they are used. */
22503 mark_base_types (dw_loc_descr_ref loc
)
22505 dw_die_ref base_type
= NULL
;
22507 for (; loc
; loc
= loc
->dw_loc_next
)
22509 switch (loc
->dw_loc_opc
)
22511 case DW_OP_GNU_regval_type
:
22512 case DW_OP_GNU_deref_type
:
22513 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22515 case DW_OP_GNU_convert
:
22516 case DW_OP_GNU_reinterpret
:
22517 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22520 case DW_OP_GNU_const_type
:
22521 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22523 case DW_OP_GNU_entry_value
:
22524 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22529 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22530 if (base_type
->die_mark
)
22531 base_type
->die_mark
++;
22534 base_types
.safe_push (base_type
);
22535 base_type
->die_mark
= 1;
22540 /* Comparison function for sorting marked base types. */
22543 base_type_cmp (const void *x
, const void *y
)
22545 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22546 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22547 unsigned int byte_size1
, byte_size2
;
22548 unsigned int encoding1
, encoding2
;
22549 if (dx
->die_mark
> dy
->die_mark
)
22551 if (dx
->die_mark
< dy
->die_mark
)
22553 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22554 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22555 if (byte_size1
< byte_size2
)
22557 if (byte_size1
> byte_size2
)
22559 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22560 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22561 if (encoding1
< encoding2
)
22563 if (encoding1
> encoding2
)
22568 /* Move base types marked by mark_base_types as early as possible
22569 in the CU, sorted by decreasing usage count both to make the
22570 uleb128 references as small as possible and to make sure they
22571 will have die_offset already computed by calc_die_sizes when
22572 sizes of typed stack loc ops is computed. */
22575 move_marked_base_types (void)
22578 dw_die_ref base_type
, die
, c
;
22580 if (base_types
.is_empty ())
22583 /* Sort by decreasing usage count, they will be added again in that
22585 base_types
.qsort (base_type_cmp
);
22586 die
= comp_unit_die ();
22587 c
= die
->die_child
;
22590 dw_die_ref prev
= c
;
22592 while (c
->die_mark
)
22594 remove_child_with_prev (c
, prev
);
22595 /* As base types got marked, there must be at least
22596 one node other than DW_TAG_base_type. */
22597 gcc_assert (c
!= c
->die_sib
);
22601 while (c
!= die
->die_child
);
22602 gcc_assert (die
->die_child
);
22603 c
= die
->die_child
;
22604 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22606 base_type
->die_mark
= 0;
22607 base_type
->die_sib
= c
->die_sib
;
22608 c
->die_sib
= base_type
;
22613 /* Helper function for resolve_addr, attempt to resolve
22614 one CONST_STRING, return non-zero if not successful. Similarly verify that
22615 SYMBOL_REFs refer to variables emitted in the current CU. */
22618 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22622 if (GET_CODE (rtl
) == CONST_STRING
)
22624 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22625 tree t
= build_string (len
, XSTR (rtl
, 0));
22626 tree tlen
= size_int (len
- 1);
22628 = build_array_type (char_type_node
, build_index_type (tlen
));
22629 rtl
= lookup_constant_def (t
);
22630 if (!rtl
|| !MEM_P (rtl
))
22632 rtl
= XEXP (rtl
, 0);
22633 if (GET_CODE (rtl
) == SYMBOL_REF
22634 && SYMBOL_REF_DECL (rtl
)
22635 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22637 vec_safe_push (used_rtx_array
, rtl
);
22642 if (GET_CODE (rtl
) == SYMBOL_REF
22643 && SYMBOL_REF_DECL (rtl
))
22645 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22647 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22650 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22654 if (GET_CODE (rtl
) == CONST
22655 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22661 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22662 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22663 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22666 string_cst_pool_decl (tree t
)
22668 rtx rtl
= output_constant_def (t
, 1);
22669 unsigned char *array
;
22670 dw_loc_descr_ref l
;
22675 if (!rtl
|| !MEM_P (rtl
))
22677 rtl
= XEXP (rtl
, 0);
22678 if (GET_CODE (rtl
) != SYMBOL_REF
22679 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22682 decl
= SYMBOL_REF_DECL (rtl
);
22683 if (!lookup_decl_die (decl
))
22685 len
= TREE_STRING_LENGTH (t
);
22686 vec_safe_push (used_rtx_array
, rtl
);
22687 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22688 array
= (unsigned char *) ggc_alloc_atomic (len
);
22689 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22690 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22691 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22692 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22693 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22694 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22695 add_AT_loc (ref
, DW_AT_location
, l
);
22696 equate_decl_number_to_die (decl
, ref
);
22701 /* Helper function of resolve_addr_in_expr. LOC is
22702 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22703 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22704 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22705 with DW_OP_GNU_implicit_pointer if possible
22706 and return true, if unsuccesful, return false. */
22709 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22711 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22712 HOST_WIDE_INT offset
= 0;
22713 dw_die_ref ref
= NULL
;
22716 if (GET_CODE (rtl
) == CONST
22717 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22718 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22720 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22721 rtl
= XEXP (XEXP (rtl
, 0), 0);
22723 if (GET_CODE (rtl
) == CONST_STRING
)
22725 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22726 tree t
= build_string (len
, XSTR (rtl
, 0));
22727 tree tlen
= size_int (len
- 1);
22730 = build_array_type (char_type_node
, build_index_type (tlen
));
22731 rtl
= string_cst_pool_decl (t
);
22735 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22737 decl
= SYMBOL_REF_DECL (rtl
);
22738 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22740 ref
= lookup_decl_die (decl
);
22741 if (ref
&& (get_AT (ref
, DW_AT_location
)
22742 || get_AT (ref
, DW_AT_const_value
)))
22744 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22745 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22746 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22747 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22748 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22749 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22750 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22758 /* Helper function for resolve_addr, handle one location
22759 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22760 the location list couldn't be resolved. */
22763 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22765 dw_loc_descr_ref keep
= NULL
;
22766 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22767 switch (loc
->dw_loc_opc
)
22770 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22773 || prev
->dw_loc_opc
== DW_OP_piece
22774 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22775 && loc
->dw_loc_next
22776 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22778 && optimize_one_addr_into_implicit_ptr (loc
))
22783 case DW_OP_GNU_addr_index
:
22784 case DW_OP_GNU_const_index
:
22785 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22786 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22787 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22791 case DW_OP_const4u
:
22792 case DW_OP_const8u
:
22794 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22797 case DW_OP_plus_uconst
:
22798 if (size_of_loc_descr (loc
)
22799 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22801 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22803 dw_loc_descr_ref repl
22804 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22805 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22806 add_loc_descr (&repl
, loc
->dw_loc_next
);
22810 case DW_OP_implicit_value
:
22811 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22812 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22815 case DW_OP_GNU_implicit_pointer
:
22816 case DW_OP_GNU_parameter_ref
:
22817 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22820 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22823 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22824 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22825 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22828 case DW_OP_GNU_const_type
:
22829 case DW_OP_GNU_regval_type
:
22830 case DW_OP_GNU_deref_type
:
22831 case DW_OP_GNU_convert
:
22832 case DW_OP_GNU_reinterpret
:
22833 while (loc
->dw_loc_next
22834 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22836 dw_die_ref base1
, base2
;
22837 unsigned enc1
, enc2
, size1
, size2
;
22838 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22839 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22840 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22841 else if (loc
->dw_loc_oprnd1
.val_class
22842 == dw_val_class_unsigned_const
)
22845 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22846 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22847 == dw_val_class_unsigned_const
)
22849 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22850 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22851 && base2
->die_tag
== DW_TAG_base_type
);
22852 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22853 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22854 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22855 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22857 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22858 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22862 /* Optimize away next DW_OP_GNU_convert after
22863 adjusting LOC's base type die reference. */
22864 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22865 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22866 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22868 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22869 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22872 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22873 point typed stack entry. */
22874 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22875 keep
= loc
->dw_loc_next
;
22885 /* Helper function of resolve_addr. DIE had DW_AT_location of
22886 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
22887 and DW_OP_addr couldn't be resolved. resolve_addr has already
22888 removed the DW_AT_location attribute. This function attempts to
22889 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
22890 to it or DW_AT_const_value attribute, if possible. */
22893 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
22895 if (TREE_CODE (decl
) != VAR_DECL
22896 || lookup_decl_die (decl
) != die
22897 || DECL_EXTERNAL (decl
)
22898 || !TREE_STATIC (decl
)
22899 || DECL_INITIAL (decl
) == NULL_TREE
22900 || DECL_P (DECL_INITIAL (decl
))
22901 || get_AT (die
, DW_AT_const_value
))
22904 tree init
= DECL_INITIAL (decl
);
22905 HOST_WIDE_INT offset
= 0;
22906 /* For variables that have been optimized away and thus
22907 don't have a memory location, see if we can emit
22908 DW_AT_const_value instead. */
22909 if (tree_add_const_value_attribute (die
, init
))
22913 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
22914 and ADDR_EXPR refers to a decl that has DW_AT_location or
22915 DW_AT_const_value (but isn't addressable, otherwise
22916 resolving the original DW_OP_addr wouldn't fail), see if
22917 we can add DW_OP_GNU_implicit_pointer. */
22919 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
22920 && host_integerp (TREE_OPERAND (init
, 1), 0))
22922 offset
= tree_low_cst (TREE_OPERAND (init
, 1), 0);
22923 init
= TREE_OPERAND (init
, 0);
22926 if (TREE_CODE (init
) != ADDR_EXPR
)
22928 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
22929 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
22930 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
22931 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
22932 && TREE_OPERAND (init
, 0) != decl
))
22935 dw_loc_descr_ref l
;
22937 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
22939 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
22942 decl
= SYMBOL_REF_DECL (rtl
);
22945 decl
= TREE_OPERAND (init
, 0);
22946 ref
= lookup_decl_die (decl
);
22948 || (!get_AT (ref
, DW_AT_location
)
22949 && !get_AT (ref
, DW_AT_const_value
)))
22951 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
22952 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22953 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22954 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22955 add_AT_loc (die
, DW_AT_location
, l
);
22959 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22960 an address in .rodata section if the string literal is emitted there,
22961 or remove the containing location list or replace DW_AT_const_value
22962 with DW_AT_location and empty location expression, if it isn't found
22963 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22964 to something that has been emitted in the current CU. */
22967 resolve_addr (dw_die_ref die
)
22971 dw_loc_list_ref
*curr
, *start
, loc
;
22974 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22975 switch (AT_class (a
))
22977 case dw_val_class_loc_list
:
22978 start
= curr
= AT_loc_list_ptr (a
);
22981 /* The same list can be referenced more than once. See if we have
22982 already recorded the result from a previous pass. */
22984 *curr
= loc
->dw_loc_next
;
22985 else if (!loc
->resolved_addr
)
22987 /* As things stand, we do not expect or allow one die to
22988 reference a suffix of another die's location list chain.
22989 References must be identical or completely separate.
22990 There is therefore no need to cache the result of this
22991 pass on any list other than the first; doing so
22992 would lead to unnecessary writes. */
22995 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22996 if (!resolve_addr_in_expr ((*curr
)->expr
))
22998 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22999 dw_loc_descr_ref l
= (*curr
)->expr
;
23001 if (next
&& (*curr
)->ll_symbol
)
23003 gcc_assert (!next
->ll_symbol
);
23004 next
->ll_symbol
= (*curr
)->ll_symbol
;
23006 if (dwarf_split_debug_info
)
23007 remove_loc_list_addr_table_entries (l
);
23012 mark_base_types ((*curr
)->expr
);
23013 curr
= &(*curr
)->dw_loc_next
;
23017 loc
->resolved_addr
= 1;
23021 loc
->dw_loc_next
= *start
;
23026 remove_AT (die
, a
->dw_attr
);
23030 case dw_val_class_loc
:
23032 dw_loc_descr_ref l
= AT_loc (a
);
23033 /* For -gdwarf-2 don't attempt to optimize
23034 DW_AT_data_member_location containing
23035 DW_OP_plus_uconst - older consumers might
23036 rely on it being that op instead of a more complex,
23037 but shorter, location description. */
23038 if ((dwarf_version
> 2
23039 || a
->dw_attr
!= DW_AT_data_member_location
23041 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23042 || l
->dw_loc_next
!= NULL
)
23043 && !resolve_addr_in_expr (l
))
23045 if (dwarf_split_debug_info
)
23046 remove_loc_list_addr_table_entries (l
);
23048 && l
->dw_loc_next
== NULL
23049 && l
->dw_loc_opc
== DW_OP_addr
23050 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23051 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23052 && a
->dw_attr
== DW_AT_location
)
23054 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23055 remove_AT (die
, a
->dw_attr
);
23057 optimize_location_into_implicit_ptr (die
, decl
);
23060 remove_AT (die
, a
->dw_attr
);
23064 mark_base_types (l
);
23067 case dw_val_class_addr
:
23068 if (a
->dw_attr
== DW_AT_const_value
23069 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23071 if (AT_index (a
) != NOT_INDEXED
)
23072 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23073 remove_AT (die
, a
->dw_attr
);
23076 if (die
->die_tag
== DW_TAG_GNU_call_site
23077 && a
->dw_attr
== DW_AT_abstract_origin
)
23079 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23080 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23082 && DECL_EXTERNAL (tdecl
)
23083 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23085 force_decl_die (tdecl
);
23086 tdie
= lookup_decl_die (tdecl
);
23090 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23091 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23092 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23096 if (AT_index (a
) != NOT_INDEXED
)
23097 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23098 remove_AT (die
, a
->dw_attr
);
23107 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23110 /* Helper routines for optimize_location_lists.
23111 This pass tries to share identical local lists in .debug_loc
23114 /* Iteratively hash operands of LOC opcode. */
23117 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23119 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23120 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23122 switch (loc
->dw_loc_opc
)
23124 case DW_OP_const4u
:
23125 case DW_OP_const8u
:
23129 case DW_OP_const1u
:
23130 case DW_OP_const1s
:
23131 case DW_OP_const2u
:
23132 case DW_OP_const2s
:
23133 case DW_OP_const4s
:
23134 case DW_OP_const8s
:
23138 case DW_OP_plus_uconst
:
23174 case DW_OP_deref_size
:
23175 case DW_OP_xderef_size
:
23176 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23183 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23184 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23185 hash
= iterative_hash_object (offset
, hash
);
23188 case DW_OP_implicit_value
:
23189 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23190 switch (val2
->val_class
)
23192 case dw_val_class_const
:
23193 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23195 case dw_val_class_vec
:
23197 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23198 unsigned int len
= val2
->v
.val_vec
.length
;
23200 hash
= iterative_hash_object (elt_size
, hash
);
23201 hash
= iterative_hash_object (len
, hash
);
23202 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23203 len
* elt_size
, hash
);
23206 case dw_val_class_const_double
:
23207 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23208 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23210 case dw_val_class_addr
:
23211 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23214 gcc_unreachable ();
23218 case DW_OP_bit_piece
:
23219 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23220 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23226 unsigned char dtprel
= 0xd1;
23227 hash
= iterative_hash_object (dtprel
, hash
);
23229 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23231 case DW_OP_GNU_addr_index
:
23232 case DW_OP_GNU_const_index
:
23236 unsigned char dtprel
= 0xd1;
23237 hash
= iterative_hash_object (dtprel
, hash
);
23239 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23242 case DW_OP_GNU_implicit_pointer
:
23243 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23245 case DW_OP_GNU_entry_value
:
23246 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23248 case DW_OP_GNU_regval_type
:
23249 case DW_OP_GNU_deref_type
:
23251 unsigned int byte_size
23252 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23253 unsigned int encoding
23254 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23255 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23256 hash
= iterative_hash_object (byte_size
, hash
);
23257 hash
= iterative_hash_object (encoding
, hash
);
23260 case DW_OP_GNU_convert
:
23261 case DW_OP_GNU_reinterpret
:
23262 if (val1
->val_class
== dw_val_class_unsigned_const
)
23264 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23268 case DW_OP_GNU_const_type
:
23270 unsigned int byte_size
23271 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23272 unsigned int encoding
23273 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23274 hash
= iterative_hash_object (byte_size
, hash
);
23275 hash
= iterative_hash_object (encoding
, hash
);
23276 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23278 hash
= iterative_hash_object (val2
->val_class
, hash
);
23279 switch (val2
->val_class
)
23281 case dw_val_class_const
:
23282 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23284 case dw_val_class_vec
:
23286 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23287 unsigned int len
= val2
->v
.val_vec
.length
;
23289 hash
= iterative_hash_object (elt_size
, hash
);
23290 hash
= iterative_hash_object (len
, hash
);
23291 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23292 len
* elt_size
, hash
);
23295 case dw_val_class_const_double
:
23296 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23297 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23300 gcc_unreachable ();
23306 /* Other codes have no operands. */
23312 /* Iteratively hash the whole DWARF location expression LOC. */
23314 static inline hashval_t
23315 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23317 dw_loc_descr_ref l
;
23318 bool sizes_computed
= false;
23319 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23320 size_of_locs (loc
);
23322 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23324 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23325 hash
= iterative_hash_object (opc
, hash
);
23326 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23328 size_of_locs (loc
);
23329 sizes_computed
= true;
23331 hash
= hash_loc_operands (l
, hash
);
23336 /* Compute hash of the whole location list LIST_HEAD. */
23339 hash_loc_list (dw_loc_list_ref list_head
)
23341 dw_loc_list_ref curr
= list_head
;
23342 hashval_t hash
= 0;
23344 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23346 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23347 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23349 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23351 hash
= hash_locs (curr
->expr
, hash
);
23353 list_head
->hash
= hash
;
23356 /* Return true if X and Y opcodes have the same operands. */
23359 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23361 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23362 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23363 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23364 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23366 switch (x
->dw_loc_opc
)
23368 case DW_OP_const4u
:
23369 case DW_OP_const8u
:
23373 case DW_OP_const1u
:
23374 case DW_OP_const1s
:
23375 case DW_OP_const2u
:
23376 case DW_OP_const2s
:
23377 case DW_OP_const4s
:
23378 case DW_OP_const8s
:
23382 case DW_OP_plus_uconst
:
23418 case DW_OP_deref_size
:
23419 case DW_OP_xderef_size
:
23420 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23423 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23424 can cause irrelevant differences in dw_loc_addr. */
23425 gcc_assert (valx1
->val_class
== dw_val_class_loc
23426 && valy1
->val_class
== dw_val_class_loc
23427 && (dwarf_split_debug_info
23428 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23429 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23430 case DW_OP_implicit_value
:
23431 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23432 || valx2
->val_class
!= valy2
->val_class
)
23434 switch (valx2
->val_class
)
23436 case dw_val_class_const
:
23437 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23438 case dw_val_class_vec
:
23439 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23440 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23441 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23442 valx2
->v
.val_vec
.elt_size
23443 * valx2
->v
.val_vec
.length
) == 0;
23444 case dw_val_class_const_double
:
23445 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23446 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23447 case dw_val_class_addr
:
23448 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23450 gcc_unreachable ();
23453 case DW_OP_bit_piece
:
23454 return valx1
->v
.val_int
== valy1
->v
.val_int
23455 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23458 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23459 case DW_OP_GNU_addr_index
:
23460 case DW_OP_GNU_const_index
:
23462 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23463 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23464 return rtx_equal_p (ax1
, ay1
);
23466 case DW_OP_GNU_implicit_pointer
:
23467 return valx1
->val_class
== dw_val_class_die_ref
23468 && valx1
->val_class
== valy1
->val_class
23469 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23470 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23471 case DW_OP_GNU_entry_value
:
23472 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23473 case DW_OP_GNU_const_type
:
23474 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23475 || valx2
->val_class
!= valy2
->val_class
)
23477 switch (valx2
->val_class
)
23479 case dw_val_class_const
:
23480 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23481 case dw_val_class_vec
:
23482 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23483 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23484 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23485 valx2
->v
.val_vec
.elt_size
23486 * valx2
->v
.val_vec
.length
) == 0;
23487 case dw_val_class_const_double
:
23488 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23489 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23491 gcc_unreachable ();
23493 case DW_OP_GNU_regval_type
:
23494 case DW_OP_GNU_deref_type
:
23495 return valx1
->v
.val_int
== valy1
->v
.val_int
23496 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23497 case DW_OP_GNU_convert
:
23498 case DW_OP_GNU_reinterpret
:
23499 if (valx1
->val_class
!= valy1
->val_class
)
23501 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23502 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23503 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23504 case DW_OP_GNU_parameter_ref
:
23505 return valx1
->val_class
== dw_val_class_die_ref
23506 && valx1
->val_class
== valy1
->val_class
23507 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23509 /* Other codes have no operands. */
23514 /* Return true if DWARF location expressions X and Y are the same. */
23517 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23519 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23520 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23521 || x
->dtprel
!= y
->dtprel
23522 || !compare_loc_operands (x
, y
))
23524 return x
== NULL
&& y
== NULL
;
23527 /* Hashtable helpers. */
23529 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23531 typedef dw_loc_list_struct value_type
;
23532 typedef dw_loc_list_struct compare_type
;
23533 static inline hashval_t
hash (const value_type
*);
23534 static inline bool equal (const value_type
*, const compare_type
*);
23537 /* Return precomputed hash of location list X. */
23540 loc_list_hasher::hash (const value_type
*x
)
23545 /* Return true if location lists A and B are the same. */
23548 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23552 if (a
->hash
!= b
->hash
)
23554 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23555 if (strcmp (a
->begin
, b
->begin
) != 0
23556 || strcmp (a
->end
, b
->end
) != 0
23557 || (a
->section
== NULL
) != (b
->section
== NULL
)
23558 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23559 || !compare_locs (a
->expr
, b
->expr
))
23561 return a
== NULL
&& b
== NULL
;
23564 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23567 /* Recursively optimize location lists referenced from DIE
23568 children and share them whenever possible. */
23571 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23576 dw_loc_list_struct
**slot
;
23578 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23579 if (AT_class (a
) == dw_val_class_loc_list
)
23581 dw_loc_list_ref list
= AT_loc_list (a
);
23582 /* TODO: perform some optimizations here, before hashing
23583 it and storing into the hash table. */
23584 hash_loc_list (list
);
23585 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23589 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23592 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23596 /* Recursively assign each location list a unique index into the debug_addr
23600 index_location_lists (dw_die_ref die
)
23606 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23607 if (AT_class (a
) == dw_val_class_loc_list
)
23609 dw_loc_list_ref list
= AT_loc_list (a
);
23610 dw_loc_list_ref curr
;
23611 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23613 /* Don't index an entry that has already been indexed
23614 or won't be output. */
23615 if (curr
->begin_entry
!= NULL
23616 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23620 = add_addr_table_entry (xstrdup (curr
->begin
),
23625 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23628 /* Optimize location lists referenced from DIE
23629 children and share them whenever possible. */
23632 optimize_location_lists (dw_die_ref die
)
23634 loc_list_hash_type htab
;
23636 optimize_location_lists_1 (die
, htab
);
23640 /* Output stuff that dwarf requires at the end of every file,
23641 and generate the DWARF-2 debugging info. */
23644 dwarf2out_finish (const char *filename
)
23646 limbo_die_node
*node
, *next_node
;
23647 comdat_type_node
*ctnode
;
23648 hash_table
<comdat_type_hasher
> comdat_type_table
;
23650 dw_die_ref main_comp_unit_die
;
23652 /* PCH might result in DW_AT_producer string being restored from the
23653 header compilation, so always fill it with empty string initially
23654 and overwrite only here. */
23655 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23656 producer_string
= gen_producer_string ();
23657 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23658 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23660 gen_scheduled_generic_parms_dies ();
23661 gen_remaining_tmpl_value_param_die_attribute ();
23663 /* Add the name for the main input file now. We delayed this from
23664 dwarf2out_init to avoid complications with PCH. */
23665 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23666 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23667 add_comp_dir_attribute (comp_unit_die ());
23668 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23671 htab_traverse (file_table
, file_table_relative_p
, &p
);
23673 add_comp_dir_attribute (comp_unit_die ());
23676 if (deferred_locations_list
)
23677 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23679 add_location_or_const_value_attribute (
23680 (*deferred_locations_list
)[i
].die
,
23681 (*deferred_locations_list
)[i
].variable
,
23686 /* Traverse the limbo die list, and add parent/child links. The only
23687 dies without parents that should be here are concrete instances of
23688 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23689 For concrete instances, we can get the parent die from the abstract
23691 for (node
= limbo_die_list
; node
; node
= next_node
)
23693 dw_die_ref die
= node
->die
;
23694 next_node
= node
->next
;
23696 if (die
->die_parent
== NULL
)
23698 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23700 if (origin
&& origin
->die_parent
)
23701 add_child_die (origin
->die_parent
, die
);
23702 else if (is_cu_die (die
))
23704 else if (seen_error ())
23705 /* It's OK to be confused by errors in the input. */
23706 add_child_die (comp_unit_die (), die
);
23709 /* In certain situations, the lexical block containing a
23710 nested function can be optimized away, which results
23711 in the nested function die being orphaned. Likewise
23712 with the return type of that nested function. Force
23713 this to be a child of the containing function.
23715 It may happen that even the containing function got fully
23716 inlined and optimized out. In that case we are lost and
23717 assign the empty child. This should not be big issue as
23718 the function is likely unreachable too. */
23719 gcc_assert (node
->created_for
);
23721 if (DECL_P (node
->created_for
))
23722 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23723 else if (TYPE_P (node
->created_for
))
23724 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23726 origin
= comp_unit_die ();
23728 add_child_die (origin
, die
);
23733 limbo_die_list
= NULL
;
23735 #if ENABLE_ASSERT_CHECKING
23737 dw_die_ref die
= comp_unit_die (), c
;
23738 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23741 resolve_addr (comp_unit_die ());
23742 move_marked_base_types ();
23744 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23746 tree decl
= node
->created_for
;
23747 /* When generating LTO bytecode we can not generate new assembler
23748 names at this point and all important decls got theirs via
23750 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23751 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23753 add_linkage_attr (node
->die
, decl
);
23754 move_linkage_attr (node
->die
);
23758 deferred_asm_name
= NULL
;
23760 /* Walk through the list of incomplete types again, trying once more to
23761 emit full debugging info for them. */
23762 retry_incomplete_types ();
23764 if (flag_eliminate_unused_debug_types
)
23765 prune_unused_types ();
23767 /* Generate separate COMDAT sections for type DIEs. */
23768 if (use_debug_types
)
23770 break_out_comdat_types (comp_unit_die ());
23772 /* Each new type_unit DIE was added to the limbo die list when created.
23773 Since these have all been added to comdat_type_list, clear the
23775 limbo_die_list
= NULL
;
23777 /* For each new comdat type unit, copy declarations for incomplete
23778 types to make the new unit self-contained (i.e., no direct
23779 references to the main compile unit). */
23780 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23781 copy_decls_for_unworthy_types (ctnode
->root_die
);
23782 copy_decls_for_unworthy_types (comp_unit_die ());
23784 /* In the process of copying declarations from one unit to another,
23785 we may have left some declarations behind that are no longer
23786 referenced. Prune them. */
23787 prune_unused_types ();
23790 /* Generate separate CUs for each of the include files we've seen.
23791 They will go into limbo_die_list. */
23792 if (flag_eliminate_dwarf2_dups
)
23793 break_out_includes (comp_unit_die ());
23795 /* Traverse the DIE's and add add sibling attributes to those DIE's
23796 that have children. */
23797 add_sibling_attributes (comp_unit_die ());
23798 for (node
= limbo_die_list
; node
; node
= node
->next
)
23799 add_sibling_attributes (node
->die
);
23800 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23801 add_sibling_attributes (ctnode
->root_die
);
23803 /* When splitting DWARF info, we put some attributes in the
23804 skeleton compile_unit DIE that remains in the .o, while
23805 most attributes go in the DWO compile_unit_die. */
23806 if (dwarf_split_debug_info
)
23807 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23809 main_comp_unit_die
= comp_unit_die ();
23811 /* Output a terminator label for the .text section. */
23812 switch_to_section (text_section
);
23813 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23814 if (cold_text_section
)
23816 switch_to_section (cold_text_section
);
23817 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23820 /* We can only use the low/high_pc attributes if all of the code was
23822 if (!have_multiple_function_sections
23823 || (dwarf_version
< 3 && dwarf_strict
))
23825 /* Don't add if the CU has no associated code. */
23826 if (text_section_used
)
23827 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23828 text_end_label
, true);
23834 bool range_list_added
= false;
23836 if (text_section_used
)
23837 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23838 text_end_label
, &range_list_added
, true);
23839 if (cold_text_section_used
)
23840 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23841 cold_end_label
, &range_list_added
, true);
23843 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23845 if (DECL_IGNORED_P (fde
->decl
))
23847 if (!fde
->in_std_section
)
23848 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23849 fde
->dw_fde_end
, &range_list_added
,
23851 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23852 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23853 fde
->dw_fde_second_end
, &range_list_added
,
23857 if (range_list_added
)
23859 /* We need to give .debug_loc and .debug_ranges an appropriate
23860 "base address". Use zero so that these addresses become
23861 absolute. Historically, we've emitted the unexpected
23862 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23863 Emit both to give time for other tools to adapt. */
23864 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23865 if (! dwarf_strict
&& dwarf_version
< 4)
23866 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23872 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23873 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23874 debug_line_section_label
);
23877 add_AT_macptr (comp_unit_die (),
23878 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23879 macinfo_section_label
);
23881 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23883 /* optimize_location_lists calculates the size of the lists,
23884 so index them first, and assign indices to the entries.
23885 Although optimize_location_lists will remove entries from
23886 the table, it only does so for duplicates, and therefore
23887 only reduces ref_counts to 1. */
23888 unsigned int index
= 0;
23889 index_location_lists (comp_unit_die ());
23890 htab_traverse_noresize (addr_index_table
,
23891 index_addr_table_entry
, &index
);
23893 if (have_location_lists
)
23894 optimize_location_lists (comp_unit_die ());
23896 save_macinfo_strings ();
23898 if (dwarf_split_debug_info
)
23900 unsigned int index
= 0;
23902 /* Add attributes common to skeleton compile_units and
23903 type_units. Because these attributes include strings, it
23904 must be done before freezing the string table. Top-level
23905 skeleton die attrs are added when the skeleton type unit is
23906 created, so ensure it is created by this point. */
23907 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
23908 (void) get_skeleton_type_unit ();
23909 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23912 /* Output all of the compilation units. We put the main one last so that
23913 the offsets are available to output_pubnames. */
23914 for (node
= limbo_die_list
; node
; node
= node
->next
)
23915 output_comp_unit (node
->die
, 0);
23917 comdat_type_table
.create (100);
23918 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23920 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
23922 /* Don't output duplicate types. */
23923 if (*slot
!= HTAB_EMPTY_ENTRY
)
23926 /* Add a pointer to the line table for the main compilation unit
23927 so that the debugger can make sense of DW_AT_decl_file
23929 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23930 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23931 (!dwarf_split_debug_info
23932 ? debug_line_section_label
23933 : debug_skeleton_line_section_label
));
23935 output_comdat_type_unit (ctnode
);
23938 comdat_type_table
.dispose ();
23940 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23941 both the main_cu and all skeleton TUs. Making this call unconditional
23942 would end up either adding a second copy of the AT_pubnames attribute, or
23943 requiring a special case in add_top_level_skeleton_die_attrs. */
23944 if (!dwarf_split_debug_info
)
23945 add_AT_pubnames (comp_unit_die ());
23947 if (dwarf_split_debug_info
)
23950 unsigned char checksum
[16];
23951 struct md5_ctx ctx
;
23953 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23954 md5_init_ctx (&ctx
);
23956 die_checksum (comp_unit_die (), &ctx
, &mark
);
23957 unmark_all_dies (comp_unit_die ());
23958 md5_finish_ctx (&ctx
, checksum
);
23960 /* Use the first 8 bytes of the checksum as the dwo_id,
23961 and add it to both comp-unit DIEs. */
23962 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23963 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23965 /* Add the base offset of the ranges table to the skeleton
23967 if (ranges_table_in_use
)
23968 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23969 ranges_section_label
);
23971 switch_to_section (debug_addr_section
);
23972 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23973 output_addr_table ();
23976 /* Output the main compilation unit if non-empty or if .debug_macinfo
23977 or .debug_macro will be emitted. */
23978 output_comp_unit (comp_unit_die (), have_macinfo
);
23980 if (dwarf_split_debug_info
&& info_section_emitted
)
23981 output_skeleton_debug_sections (main_comp_unit_die
);
23983 /* Output the abbreviation table. */
23984 if (abbrev_die_table_in_use
!= 1)
23986 switch_to_section (debug_abbrev_section
);
23987 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23988 output_abbrev_section ();
23991 /* Output location list section if necessary. */
23992 if (have_location_lists
)
23994 /* Output the location lists info. */
23995 switch_to_section (debug_loc_section
);
23996 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23997 output_location_lists (comp_unit_die ());
24000 /* Output public names and types tables if necessary. */
24001 output_pubnames (pubname_table
);
24002 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
24003 It shouldn't hurt to emit it always, since pure DWARF2 consumers
24004 simply won't look for the section. */
24005 output_pubnames (pubtype_table
);
24007 /* Output the address range information if a CU (.debug_info section)
24008 was emitted. We output an empty table even if we had no functions
24009 to put in it. This because the consumer has no way to tell the
24010 difference between an empty table that we omitted and failure to
24011 generate a table that would have contained data. */
24012 if (info_section_emitted
)
24014 unsigned long aranges_length
= size_of_aranges ();
24016 switch_to_section (debug_aranges_section
);
24017 output_aranges (aranges_length
);
24020 /* Output ranges section if necessary. */
24021 if (ranges_table_in_use
)
24023 switch_to_section (debug_ranges_section
);
24024 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24028 /* Have to end the macro section. */
24031 switch_to_section (debug_macinfo_section
);
24032 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24034 dw2_asm_output_data (1, 0, "End compilation unit");
24037 /* Output the source line correspondence table. We must do this
24038 even if there is no line information. Otherwise, on an empty
24039 translation unit, we will generate a present, but empty,
24040 .debug_info section. IRIX 6.5 `nm' will then complain when
24041 examining the file. This is done late so that any filenames
24042 used by the debug_info section are marked as 'used'. */
24043 switch_to_section (debug_line_section
);
24044 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24045 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24046 output_line_info (false);
24048 if (dwarf_split_debug_info
&& info_section_emitted
)
24050 switch_to_section (debug_skeleton_line_section
);
24051 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24052 output_line_info (true);
24055 /* If we emitted any indirect strings, output the string table too. */
24056 if (debug_str_hash
|| skeleton_debug_str_hash
)
24057 output_indirect_strings ();
24060 #include "gt-dwarf2out.h"