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"
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 static rtx last_var_location_insn
;
99 static rtx cached_next_real_insn
;
101 #ifdef VMS_DEBUGGING_INFO
102 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
104 /* Define this macro to be a nonzero value if the directory specifications
105 which are output in the debug info should end with a separator. */
106 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
107 /* Define this macro to evaluate to a nonzero value if GCC should refrain
108 from generating indirect strings in DWARF2 debug information, for instance
109 if your target is stuck with an old version of GDB that is unable to
110 process them properly or uses VMS Debug. */
111 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
113 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
114 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
117 /* ??? Poison these here until it can be done generically. They've been
118 totally replaced in this file; make sure it stays that way. */
119 #undef DWARF2_UNWIND_INFO
120 #undef DWARF2_FRAME_INFO
121 #if (GCC_VERSION >= 3000)
122 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
125 /* The size of the target's pointer type. */
127 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
130 /* Array of RTXes referenced by the debugging information, which therefore
131 must be kept around forever. */
132 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
134 /* A pointer to the base of a list of incomplete types which might be
135 completed at some later time. incomplete_types_list needs to be a
136 vec<tree, va_gc> *because we want to tell the garbage collector about
138 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
140 /* A pointer to the base of a table of references to declaration
141 scopes. This table is a display which tracks the nesting
142 of declaration scopes at the current scope and containing
143 scopes. This table is used to find the proper place to
144 define type declaration DIE's. */
145 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
147 /* Pointers to various DWARF2 sections. */
148 static GTY(()) section
*debug_info_section
;
149 static GTY(()) section
*debug_skeleton_info_section
;
150 static GTY(()) section
*debug_abbrev_section
;
151 static GTY(()) section
*debug_skeleton_abbrev_section
;
152 static GTY(()) section
*debug_aranges_section
;
153 static GTY(()) section
*debug_addr_section
;
154 static GTY(()) section
*debug_macinfo_section
;
155 static GTY(()) section
*debug_line_section
;
156 static GTY(()) section
*debug_skeleton_line_section
;
157 static GTY(()) section
*debug_loc_section
;
158 static GTY(()) section
*debug_pubnames_section
;
159 static GTY(()) section
*debug_pubtypes_section
;
160 static GTY(()) section
*debug_str_section
;
161 static GTY(()) section
*debug_str_dwo_section
;
162 static GTY(()) section
*debug_str_offsets_section
;
163 static GTY(()) section
*debug_ranges_section
;
164 static GTY(()) section
*debug_frame_section
;
166 /* Maximum size (in bytes) of an artificially generated label. */
167 #define MAX_ARTIFICIAL_LABEL_BYTES 30
169 /* According to the (draft) DWARF 3 specification, the initial length
170 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
171 bytes are 0xffffffff, followed by the length stored in the next 8
174 However, the SGI/MIPS ABI uses an initial length which is equal to
175 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
177 #ifndef DWARF_INITIAL_LENGTH_SIZE
178 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
181 /* Round SIZE up to the nearest BOUNDARY. */
182 #define DWARF_ROUND(SIZE,BOUNDARY) \
183 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
185 /* CIE identifier. */
186 #if HOST_BITS_PER_WIDE_INT >= 64
187 #define DWARF_CIE_ID \
188 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
190 #define DWARF_CIE_ID DW_CIE_ID
194 /* A vector for a table that contains frame description
195 information for each routine. */
196 #define NOT_INDEXED (-1U)
197 #define NO_INDEX_ASSIGNED (-2U)
199 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
201 struct GTY(()) indirect_string_node
{
203 unsigned int refcount
;
204 enum dwarf_form form
;
209 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
211 /* With split_debug_info, both the comp_dir and dwo_name go in the
212 main object file, rather than the dwo, similar to the force_direct
213 parameter elsewhere but with additional complications:
215 1) The string is needed in both the main object file and the dwo.
216 That is, the comp_dir and dwo_name will appear in both places.
218 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
219 DW_FORM_GNU_str_index.
221 3) GCC chooses the form to use late, depending on the size and
224 Rather than forcing the all debug string handling functions and
225 callers to deal with these complications, simply use a separate,
226 special-cased string table for any attribute that should go in the
227 main object file. This limits the complexity to just the places
230 static GTY ((param_is (struct indirect_string_node
)))
231 htab_t skeleton_debug_str_hash
;
233 static GTY(()) int dw2_string_counter
;
235 /* True if the compilation unit places functions in more than one section. */
236 static GTY(()) bool have_multiple_function_sections
= false;
238 /* Whether the default text and cold text sections have been used at all. */
240 static GTY(()) bool text_section_used
= false;
241 static GTY(()) bool cold_text_section_used
= false;
243 /* The default cold text section. */
244 static GTY(()) section
*cold_text_section
;
246 /* Forward declarations for functions defined in this file. */
248 static char *stripattributes (const char *);
249 static void output_call_frame_info (int);
250 static void dwarf2out_note_section_used (void);
252 /* Personality decl of current unit. Used only when assembler does not support
254 static GTY(()) rtx current_unit_personality
;
256 /* Data and reference forms for relocatable data. */
257 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
258 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
260 #ifndef DEBUG_FRAME_SECTION
261 #define DEBUG_FRAME_SECTION ".debug_frame"
264 #ifndef FUNC_BEGIN_LABEL
265 #define FUNC_BEGIN_LABEL "LFB"
268 #ifndef FUNC_END_LABEL
269 #define FUNC_END_LABEL "LFE"
272 #ifndef PROLOGUE_END_LABEL
273 #define PROLOGUE_END_LABEL "LPE"
276 #ifndef EPILOGUE_BEGIN_LABEL
277 #define EPILOGUE_BEGIN_LABEL "LEB"
280 #ifndef FRAME_BEGIN_LABEL
281 #define FRAME_BEGIN_LABEL "Lframe"
283 #define CIE_AFTER_SIZE_LABEL "LSCIE"
284 #define CIE_END_LABEL "LECIE"
285 #define FDE_LABEL "LSFDE"
286 #define FDE_AFTER_SIZE_LABEL "LASFDE"
287 #define FDE_END_LABEL "LEFDE"
288 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
289 #define LINE_NUMBER_END_LABEL "LELT"
290 #define LN_PROLOG_AS_LABEL "LASLTP"
291 #define LN_PROLOG_END_LABEL "LELTP"
292 #define DIE_LABEL_PREFIX "DW"
294 /* Match the base name of a file to the base name of a compilation unit. */
297 matches_main_base (const char *path
)
299 /* Cache the last query. */
300 static const char *last_path
= NULL
;
301 static int last_match
= 0;
302 if (path
!= last_path
)
305 int length
= base_of_path (path
, &base
);
307 last_match
= (length
== main_input_baselength
308 && memcmp (base
, main_input_basename
, length
) == 0);
313 #ifdef DEBUG_DEBUG_STRUCT
316 dump_struct_debug (tree type
, enum debug_info_usage usage
,
317 enum debug_struct_file criterion
, int generic
,
318 int matches
, int result
)
320 /* Find the type name. */
321 tree type_decl
= TYPE_STUB_DECL (type
);
323 const char *name
= 0;
324 if (TREE_CODE (t
) == TYPE_DECL
)
327 name
= IDENTIFIER_POINTER (t
);
329 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
331 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
332 matches
? "bas" : "hdr",
333 generic
? "gen" : "ord",
334 usage
== DINFO_USAGE_DFN
? ";" :
335 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
337 (void*) type_decl
, name
);
340 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
341 dump_struct_debug (type, usage, criterion, generic, matches, result)
345 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
351 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
353 enum debug_struct_file criterion
;
355 bool generic
= lang_hooks
.types
.generic_p (type
);
358 criterion
= debug_struct_generic
[usage
];
360 criterion
= debug_struct_ordinary
[usage
];
362 if (criterion
== DINFO_STRUCT_FILE_NONE
)
363 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
364 if (criterion
== DINFO_STRUCT_FILE_ANY
)
365 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
367 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
369 if (type_decl
!= NULL
)
371 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
372 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
374 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
375 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
378 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
381 /* Return a pointer to a copy of the section string name S with all
382 attributes stripped off, and an asterisk prepended (for assemble_name). */
385 stripattributes (const char *s
)
387 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
392 while (*s
&& *s
!= ',')
399 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
400 switch to the data section instead, and write out a synthetic start label
401 for collect2 the first time around. */
404 switch_to_eh_frame_section (bool back
)
408 #ifdef EH_FRAME_SECTION_NAME
409 if (eh_frame_section
== 0)
413 if (EH_TABLES_CAN_BE_READ_ONLY
)
419 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
421 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
423 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
426 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
427 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
428 && (per_encoding
& 0x70) != DW_EH_PE_absptr
429 && (per_encoding
& 0x70) != DW_EH_PE_aligned
430 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
431 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
432 ? 0 : SECTION_WRITE
);
435 flags
= SECTION_WRITE
;
436 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
438 #endif /* EH_FRAME_SECTION_NAME */
440 if (eh_frame_section
)
441 switch_to_section (eh_frame_section
);
444 /* We have no special eh_frame section. Put the information in
445 the data section and emit special labels to guide collect2. */
446 switch_to_section (data_section
);
450 label
= get_file_function_name ("F");
451 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
452 targetm
.asm_out
.globalize_label (asm_out_file
,
453 IDENTIFIER_POINTER (label
));
454 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
459 /* Switch [BACK] to the eh or debug frame table section, depending on
463 switch_to_frame_table_section (int for_eh
, bool back
)
466 switch_to_eh_frame_section (back
);
469 if (!debug_frame_section
)
470 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
471 SECTION_DEBUG
, NULL
);
472 switch_to_section (debug_frame_section
);
476 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
478 enum dw_cfi_oprnd_type
479 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
484 case DW_CFA_GNU_window_save
:
485 case DW_CFA_remember_state
:
486 case DW_CFA_restore_state
:
487 return dw_cfi_oprnd_unused
;
490 case DW_CFA_advance_loc1
:
491 case DW_CFA_advance_loc2
:
492 case DW_CFA_advance_loc4
:
493 case DW_CFA_MIPS_advance_loc8
:
494 return dw_cfi_oprnd_addr
;
497 case DW_CFA_offset_extended
:
499 case DW_CFA_offset_extended_sf
:
500 case DW_CFA_def_cfa_sf
:
502 case DW_CFA_restore_extended
:
503 case DW_CFA_undefined
:
504 case DW_CFA_same_value
:
505 case DW_CFA_def_cfa_register
:
506 case DW_CFA_register
:
507 case DW_CFA_expression
:
508 return dw_cfi_oprnd_reg_num
;
510 case DW_CFA_def_cfa_offset
:
511 case DW_CFA_GNU_args_size
:
512 case DW_CFA_def_cfa_offset_sf
:
513 return dw_cfi_oprnd_offset
;
515 case DW_CFA_def_cfa_expression
:
516 return dw_cfi_oprnd_loc
;
523 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
525 enum dw_cfi_oprnd_type
526 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
531 case DW_CFA_def_cfa_sf
:
533 case DW_CFA_offset_extended_sf
:
534 case DW_CFA_offset_extended
:
535 return dw_cfi_oprnd_offset
;
537 case DW_CFA_register
:
538 return dw_cfi_oprnd_reg_num
;
540 case DW_CFA_expression
:
541 return dw_cfi_oprnd_loc
;
544 return dw_cfi_oprnd_unused
;
548 /* Output one FDE. */
551 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
552 char *section_start_label
, int fde_encoding
, char *augmentation
,
553 bool any_lsda_needed
, int lsda_encoding
)
555 const char *begin
, *end
;
556 static unsigned int j
;
559 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
561 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
563 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
564 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
565 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
566 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
567 " indicating 64-bit DWARF extension");
568 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
570 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
573 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
575 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
576 debug_frame_section
, "FDE CIE offset");
578 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
579 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
583 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
584 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
585 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
586 "FDE initial location");
587 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
588 end
, begin
, "FDE address range");
592 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
593 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
600 int size
= size_of_encoded_value (lsda_encoding
);
602 if (lsda_encoding
== DW_EH_PE_aligned
)
604 int offset
= ( 4 /* Length */
606 + 2 * size_of_encoded_value (fde_encoding
)
607 + 1 /* Augmentation size */ );
608 int pad
= -offset
& (PTR_SIZE
- 1);
611 gcc_assert (size_of_uleb128 (size
) == 1);
614 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
616 if (fde
->uses_eh_lsda
)
618 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
619 fde
->funcdef_number
);
620 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
621 gen_rtx_SYMBOL_REF (Pmode
, l1
),
623 "Language Specific Data Area");
627 if (lsda_encoding
== DW_EH_PE_aligned
)
628 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
629 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
630 "Language Specific Data Area (none)");
634 dw2_asm_output_data_uleb128 (0, "Augmentation size");
637 /* Loop through the Call Frame Instructions associated with this FDE. */
638 fde
->dw_fde_current_label
= begin
;
640 size_t from
, until
, i
;
643 until
= vec_safe_length (fde
->dw_fde_cfi
);
645 if (fde
->dw_fde_second_begin
== NULL
)
648 until
= fde
->dw_fde_switch_cfi_index
;
650 from
= fde
->dw_fde_switch_cfi_index
;
652 for (i
= from
; i
< until
; i
++)
653 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
656 /* If we are to emit a ref/link from function bodies to their frame tables,
657 do it now. This is typically performed to make sure that tables
658 associated with functions are dragged with them and not discarded in
659 garbage collecting links. We need to do this on a per function basis to
660 cope with -ffunction-sections. */
662 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
663 /* Switch to the function section, emit the ref to the tables, and
664 switch *back* into the table section. */
665 switch_to_section (function_section (fde
->decl
));
666 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
667 switch_to_frame_table_section (for_eh
, true);
670 /* Pad the FDE out to an address sized boundary. */
671 ASM_OUTPUT_ALIGN (asm_out_file
,
672 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
673 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
678 /* Return true if frame description entry FDE is needed for EH. */
681 fde_needed_for_eh_p (dw_fde_ref fde
)
683 if (flag_asynchronous_unwind_tables
)
686 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
689 if (fde
->uses_eh_lsda
)
692 /* If exceptions are enabled, we have collected nothrow info. */
693 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
699 /* Output the call frame information used to record information
700 that relates to calculating the frame pointer, and records the
701 location of saved registers. */
704 output_call_frame_info (int for_eh
)
709 char l1
[20], l2
[20], section_start_label
[20];
710 bool any_lsda_needed
= false;
711 char augmentation
[6];
712 int augmentation_size
;
713 int fde_encoding
= DW_EH_PE_absptr
;
714 int per_encoding
= DW_EH_PE_absptr
;
715 int lsda_encoding
= DW_EH_PE_absptr
;
717 rtx personality
= NULL
;
720 /* Don't emit a CIE if there won't be any FDEs. */
724 /* Nothing to do if the assembler's doing it all. */
725 if (dwarf2out_do_cfi_asm ())
728 /* If we don't have any functions we'll want to unwind out of, don't emit
729 any EH unwind information. If we make FDEs linkonce, we may have to
730 emit an empty label for an FDE that wouldn't otherwise be emitted. We
731 want to avoid having an FDE kept around when the function it refers to
732 is discarded. Example where this matters: a primary function template
733 in C++ requires EH information, an explicit specialization doesn't. */
736 bool any_eh_needed
= false;
738 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
740 if (fde
->uses_eh_lsda
)
741 any_eh_needed
= any_lsda_needed
= true;
742 else if (fde_needed_for_eh_p (fde
))
743 any_eh_needed
= true;
744 else if (TARGET_USES_WEAK_UNWIND_INFO
)
745 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
752 /* We're going to be generating comments, so turn on app. */
756 /* Switch to the proper frame section, first time. */
757 switch_to_frame_table_section (for_eh
, false);
759 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
760 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
762 /* Output the CIE. */
763 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
764 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
765 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
766 dw2_asm_output_data (4, 0xffffffff,
767 "Initial length escape value indicating 64-bit DWARF extension");
768 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
769 "Length of Common Information Entry");
770 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
772 /* Now that the CIE pointer is PC-relative for EH,
773 use 0 to identify the CIE. */
774 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
775 (for_eh
? 0 : DWARF_CIE_ID
),
776 "CIE Identifier Tag");
778 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
779 use CIE version 1, unless that would produce incorrect results
780 due to overflowing the return register column. */
781 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
783 if (return_reg
>= 256 || dwarf_version
> 2)
785 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
788 augmentation_size
= 0;
790 personality
= current_unit_personality
;
796 z Indicates that a uleb128 is present to size the
797 augmentation section.
798 L Indicates the encoding (and thus presence) of
799 an LSDA pointer in the FDE augmentation.
800 R Indicates a non-default pointer encoding for
802 P Indicates the presence of an encoding + language
803 personality routine in the CIE augmentation. */
805 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
806 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
807 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
809 p
= augmentation
+ 1;
813 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
814 assemble_external_libcall (personality
);
819 augmentation_size
+= 1;
821 if (fde_encoding
!= DW_EH_PE_absptr
)
824 augmentation_size
+= 1;
826 if (p
> augmentation
+ 1)
828 augmentation
[0] = 'z';
832 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
833 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
835 int offset
= ( 4 /* Length */
837 + 1 /* CIE version */
838 + strlen (augmentation
) + 1 /* Augmentation */
839 + size_of_uleb128 (1) /* Code alignment */
840 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
842 + 1 /* Augmentation size */
843 + 1 /* Personality encoding */ );
844 int pad
= -offset
& (PTR_SIZE
- 1);
846 augmentation_size
+= pad
;
848 /* Augmentations should be small, so there's scarce need to
849 iterate for a solution. Die if we exceed one uleb128 byte. */
850 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
854 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
855 if (dw_cie_version
>= 4)
857 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
858 dw2_asm_output_data (1, 0, "CIE Segment Size");
860 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
861 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
862 "CIE Data Alignment Factor");
864 if (dw_cie_version
== 1)
865 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
867 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
871 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
874 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
875 eh_data_format_name (per_encoding
));
876 dw2_asm_output_encoded_addr_rtx (per_encoding
,
882 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
883 eh_data_format_name (lsda_encoding
));
885 if (fde_encoding
!= DW_EH_PE_absptr
)
886 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
887 eh_data_format_name (fde_encoding
));
890 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
891 output_cfi (cfi
, NULL
, for_eh
);
893 /* Pad the CIE out to an address sized boundary. */
894 ASM_OUTPUT_ALIGN (asm_out_file
,
895 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
896 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
898 /* Loop through all of the FDE's. */
899 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
903 /* Don't emit EH unwind info for leaf functions that don't need it. */
904 if (for_eh
&& !fde_needed_for_eh_p (fde
))
907 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
908 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
909 augmentation
, any_lsda_needed
, lsda_encoding
);
912 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
913 dw2_asm_output_data (4, 0, "End of Table");
915 /* Turn off app to make assembly quicker. */
920 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
923 dwarf2out_do_cfi_startproc (bool second
)
927 rtx personality
= get_personality_function (current_function_decl
);
929 fprintf (asm_out_file
, "\t.cfi_startproc\n");
933 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
936 /* ??? The GAS support isn't entirely consistent. We have to
937 handle indirect support ourselves, but PC-relative is done
938 in the assembler. Further, the assembler can't handle any
939 of the weirder relocation types. */
940 if (enc
& DW_EH_PE_indirect
)
941 ref
= dw2_force_const_mem (ref
, true);
943 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
944 output_addr_const (asm_out_file
, ref
);
945 fputc ('\n', asm_out_file
);
948 if (crtl
->uses_eh_lsda
)
952 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
953 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
954 current_function_funcdef_no
);
955 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
956 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
958 if (enc
& DW_EH_PE_indirect
)
959 ref
= dw2_force_const_mem (ref
, true);
961 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
962 output_addr_const (asm_out_file
, ref
);
963 fputc ('\n', asm_out_file
);
967 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
968 this allocation may be done before pass_final. */
971 dwarf2out_alloc_current_fde (void)
975 fde
= ggc_alloc_cleared_dw_fde_node ();
976 fde
->decl
= current_function_decl
;
977 fde
->funcdef_number
= current_function_funcdef_no
;
978 fde
->fde_index
= vec_safe_length (fde_vec
);
979 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
980 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
981 fde
->nothrow
= crtl
->nothrow
;
982 fde
->drap_reg
= INVALID_REGNUM
;
983 fde
->vdrap_reg
= INVALID_REGNUM
;
985 /* Record the FDE associated with this function. */
987 vec_safe_push (fde_vec
, fde
);
992 /* Output a marker (i.e. a label) for the beginning of a function, before
996 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
997 const char *file ATTRIBUTE_UNUSED
)
999 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1005 current_function_func_begin_label
= NULL
;
1007 do_frame
= dwarf2out_do_frame ();
1009 /* ??? current_function_func_begin_label is also used by except.c for
1010 call-site information. We must emit this label if it might be used. */
1012 && (!flag_exceptions
1013 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1016 fnsec
= function_section (current_function_decl
);
1017 switch_to_section (fnsec
);
1018 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1019 current_function_funcdef_no
);
1020 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1021 current_function_funcdef_no
);
1022 dup_label
= xstrdup (label
);
1023 current_function_func_begin_label
= dup_label
;
1025 /* We can elide the fde allocation if we're not emitting debug info. */
1029 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1030 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1031 would include pass_dwarf2_frame. If we've not created the FDE yet,
1035 fde
= dwarf2out_alloc_current_fde ();
1037 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1038 fde
->dw_fde_begin
= dup_label
;
1039 fde
->dw_fde_current_label
= dup_label
;
1040 fde
->in_std_section
= (fnsec
== text_section
1041 || (cold_text_section
&& fnsec
== cold_text_section
));
1043 /* We only want to output line number information for the genuine dwarf2
1044 prologue case, not the eh frame case. */
1045 #ifdef DWARF2_DEBUGGING_INFO
1047 dwarf2out_source_line (line
, file
, 0, true);
1050 if (dwarf2out_do_cfi_asm ())
1051 dwarf2out_do_cfi_startproc (false);
1054 rtx personality
= get_personality_function (current_function_decl
);
1055 if (!current_unit_personality
)
1056 current_unit_personality
= personality
;
1058 /* We cannot keep a current personality per function as without CFI
1059 asm, at the point where we emit the CFI data, there is no current
1060 function anymore. */
1061 if (personality
&& current_unit_personality
!= personality
)
1062 sorry ("multiple EH personalities are supported only with assemblers "
1063 "supporting .cfi_personality directive");
1067 /* Output a marker (i.e. a label) for the end of the generated code
1068 for a function prologue. This gets called *after* the prologue code has
1072 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1073 const char *file ATTRIBUTE_UNUSED
)
1075 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1077 /* Output a label to mark the endpoint of the code generated for this
1079 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1080 current_function_funcdef_no
);
1081 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1082 current_function_funcdef_no
);
1083 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1086 /* Output a marker (i.e. a label) for the beginning of the generated code
1087 for a function epilogue. This gets called *before* the prologue code has
1091 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1092 const char *file ATTRIBUTE_UNUSED
)
1094 dw_fde_ref fde
= cfun
->fde
;
1095 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1097 if (fde
->dw_fde_vms_begin_epilogue
)
1100 /* Output a label to mark the endpoint of the code generated for this
1102 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1103 current_function_funcdef_no
);
1104 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1105 current_function_funcdef_no
);
1106 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1109 /* Output a marker (i.e. a label) for the absolute end of the generated code
1110 for a function definition. This gets called *after* the epilogue code has
1114 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1115 const char *file ATTRIBUTE_UNUSED
)
1118 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1120 last_var_location_insn
= NULL_RTX
;
1121 cached_next_real_insn
= NULL_RTX
;
1123 if (dwarf2out_do_cfi_asm ())
1124 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1126 /* Output a label to mark the endpoint of the code generated for this
1128 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1129 current_function_funcdef_no
);
1130 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1132 gcc_assert (fde
!= NULL
);
1133 if (fde
->dw_fde_second_begin
== NULL
)
1134 fde
->dw_fde_end
= xstrdup (label
);
1138 dwarf2out_frame_finish (void)
1140 /* Output call frame information. */
1141 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1142 output_call_frame_info (0);
1144 /* Output another copy for the unwinder. */
1145 if ((flag_unwind_tables
|| flag_exceptions
)
1146 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1147 output_call_frame_info (1);
1150 /* Note that the current function section is being used for code. */
1153 dwarf2out_note_section_used (void)
1155 section
*sec
= current_function_section ();
1156 if (sec
== text_section
)
1157 text_section_used
= true;
1158 else if (sec
== cold_text_section
)
1159 cold_text_section_used
= true;
1162 static void var_location_switch_text_section (void);
1163 static void set_cur_line_info_table (section
*);
1166 dwarf2out_switch_text_section (void)
1169 dw_fde_ref fde
= cfun
->fde
;
1171 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1173 if (!in_cold_section_p
)
1175 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1176 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1177 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1181 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1182 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1183 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1185 have_multiple_function_sections
= true;
1187 /* There is no need to mark used sections when not debugging. */
1188 if (cold_text_section
!= NULL
)
1189 dwarf2out_note_section_used ();
1191 if (dwarf2out_do_cfi_asm ())
1192 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1194 /* Now do the real section switch. */
1195 sect
= current_function_section ();
1196 switch_to_section (sect
);
1198 fde
->second_in_std_section
1199 = (sect
== text_section
1200 || (cold_text_section
&& sect
== cold_text_section
));
1202 if (dwarf2out_do_cfi_asm ())
1203 dwarf2out_do_cfi_startproc (true);
1205 var_location_switch_text_section ();
1207 if (cold_text_section
!= NULL
)
1208 set_cur_line_info_table (sect
);
1211 /* And now, the subset of the debugging information support code necessary
1212 for emitting location expressions. */
1214 /* Data about a single source file. */
1215 struct GTY(()) dwarf_file_data
{
1216 const char * filename
;
1220 typedef struct GTY(()) deferred_locations_struct
1224 } deferred_locations
;
1227 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1230 /* Describe an entry into the .debug_addr section. */
1234 ate_kind_rtx_dtprel
,
1238 typedef struct GTY(()) addr_table_entry_struct
{
1240 unsigned int refcount
;
1242 union addr_table_entry_struct_union
1244 rtx
GTY ((tag ("0"))) rtl
;
1245 char * GTY ((tag ("1"))) label
;
1247 GTY ((desc ("%1.kind"))) addr
;
1251 /* Location lists are ranges + location descriptions for that range,
1252 so you can track variables that are in different places over
1253 their entire life. */
1254 typedef struct GTY(()) dw_loc_list_struct
{
1255 dw_loc_list_ref dw_loc_next
;
1256 const char *begin
; /* Label and addr_entry for start of range */
1257 addr_table_entry
*begin_entry
;
1258 const char *end
; /* Label for end of range */
1259 char *ll_symbol
; /* Label for beginning of location list.
1260 Only on head of list */
1261 const char *section
; /* Section this loclist is relative to */
1262 dw_loc_descr_ref expr
;
1264 /* True if all addresses in this and subsequent lists are known to be
1267 /* True if this list has been replaced by dw_loc_next. */
1270 /* True if the range should be emitted even if begin and end
1275 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1277 /* Convert a DWARF stack opcode into its string name. */
1280 dwarf_stack_op_name (unsigned int op
)
1282 const char *name
= get_DW_OP_name (op
);
1287 return "OP_<unknown>";
1290 /* Return a pointer to a newly allocated location description. Location
1291 descriptions are simple expression terms that can be strung
1292 together to form more complicated location (address) descriptions. */
1294 static inline dw_loc_descr_ref
1295 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1296 unsigned HOST_WIDE_INT oprnd2
)
1298 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1300 descr
->dw_loc_opc
= op
;
1301 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1302 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1303 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1304 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1305 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1306 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1311 /* Return a pointer to a newly allocated location description for
1314 static inline dw_loc_descr_ref
1315 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1318 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1321 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1324 /* Add a location description term to a location description expression. */
1327 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1329 dw_loc_descr_ref
*d
;
1331 /* Find the end of the chain. */
1332 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1338 /* Compare two location operands for exact equality. */
1341 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1343 if (a
->val_class
!= b
->val_class
)
1345 switch (a
->val_class
)
1347 case dw_val_class_none
:
1349 case dw_val_class_addr
:
1350 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1352 case dw_val_class_offset
:
1353 case dw_val_class_unsigned_const
:
1354 case dw_val_class_const
:
1355 case dw_val_class_range_list
:
1356 case dw_val_class_lineptr
:
1357 case dw_val_class_macptr
:
1358 /* These are all HOST_WIDE_INT, signed or unsigned. */
1359 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1361 case dw_val_class_loc
:
1362 return a
->v
.val_loc
== b
->v
.val_loc
;
1363 case dw_val_class_loc_list
:
1364 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1365 case dw_val_class_die_ref
:
1366 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1367 case dw_val_class_fde_ref
:
1368 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1369 case dw_val_class_lbl_id
:
1370 case dw_val_class_high_pc
:
1371 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1372 case dw_val_class_str
:
1373 return a
->v
.val_str
== b
->v
.val_str
;
1374 case dw_val_class_flag
:
1375 return a
->v
.val_flag
== b
->v
.val_flag
;
1376 case dw_val_class_file
:
1377 return a
->v
.val_file
== b
->v
.val_file
;
1378 case dw_val_class_decl_ref
:
1379 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1381 case dw_val_class_const_double
:
1382 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1383 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1385 case dw_val_class_vec
:
1387 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1388 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1390 return (a_len
== b_len
1391 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1394 case dw_val_class_data8
:
1395 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1397 case dw_val_class_vms_delta
:
1398 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1399 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1404 /* Compare two location atoms for exact equality. */
1407 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1409 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1412 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1413 address size, but since we always allocate cleared storage it
1414 should be zero for other types of locations. */
1415 if (a
->dtprel
!= b
->dtprel
)
1418 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1419 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1422 /* Compare two complete location expressions for exact equality. */
1425 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1431 if (a
== NULL
|| b
== NULL
)
1433 if (!loc_descr_equal_p_1 (a
, b
))
1442 /* Add a constant OFFSET to a location expression. */
1445 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1447 dw_loc_descr_ref loc
;
1450 gcc_assert (*list_head
!= NULL
);
1455 /* Find the end of the chain. */
1456 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1460 if (loc
->dw_loc_opc
== DW_OP_fbreg
1461 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1462 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1463 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1464 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1466 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1467 offset. Don't optimize if an signed integer overflow would happen. */
1469 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1470 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1473 else if (offset
> 0)
1474 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1478 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1479 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1483 /* Add a constant OFFSET to a location list. */
1486 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1489 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1490 loc_descr_plus_const (&d
->expr
, offset
);
1493 #define DWARF_REF_SIZE \
1494 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1496 static unsigned long int get_base_type_offset (dw_die_ref
);
1498 /* Return the size of a location descriptor. */
1500 static unsigned long
1501 size_of_loc_descr (dw_loc_descr_ref loc
)
1503 unsigned long size
= 1;
1505 switch (loc
->dw_loc_opc
)
1508 size
+= DWARF2_ADDR_SIZE
;
1510 case DW_OP_GNU_addr_index
:
1511 case DW_OP_GNU_const_index
:
1512 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1513 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1532 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1535 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1540 case DW_OP_plus_uconst
:
1541 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1579 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1582 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1585 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1588 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1589 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1592 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1594 case DW_OP_bit_piece
:
1595 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1596 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1598 case DW_OP_deref_size
:
1599 case DW_OP_xderef_size
:
1608 case DW_OP_call_ref
:
1609 size
+= DWARF_REF_SIZE
;
1611 case DW_OP_implicit_value
:
1612 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1613 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1615 case DW_OP_GNU_implicit_pointer
:
1616 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1618 case DW_OP_GNU_entry_value
:
1620 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1621 size
+= size_of_uleb128 (op_size
) + op_size
;
1624 case DW_OP_GNU_const_type
:
1627 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1628 size
+= size_of_uleb128 (o
) + 1;
1629 switch (loc
->dw_loc_oprnd2
.val_class
)
1631 case dw_val_class_vec
:
1632 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1633 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1635 case dw_val_class_const
:
1636 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1638 case dw_val_class_const_double
:
1639 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1646 case DW_OP_GNU_regval_type
:
1649 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1650 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1651 + size_of_uleb128 (o
);
1654 case DW_OP_GNU_deref_type
:
1657 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1658 size
+= 1 + size_of_uleb128 (o
);
1661 case DW_OP_GNU_convert
:
1662 case DW_OP_GNU_reinterpret
:
1663 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1664 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1668 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1669 size
+= size_of_uleb128 (o
);
1672 case DW_OP_GNU_parameter_ref
:
1682 /* Return the size of a series of location descriptors. */
1685 size_of_locs (dw_loc_descr_ref loc
)
1690 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1691 field, to avoid writing to a PCH file. */
1692 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1694 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1696 size
+= size_of_loc_descr (l
);
1701 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1703 l
->dw_loc_addr
= size
;
1704 size
+= size_of_loc_descr (l
);
1710 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1711 static void get_ref_die_offset_label (char *, dw_die_ref
);
1712 static unsigned long int get_ref_die_offset (dw_die_ref
);
1714 /* Output location description stack opcode's operands (if any).
1715 The for_eh_or_skip parameter controls whether register numbers are
1716 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1717 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1718 info). This should be suppressed for the cases that have not been converted
1719 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1722 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1724 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1725 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1727 switch (loc
->dw_loc_opc
)
1729 #ifdef DWARF2_DEBUGGING_INFO
1732 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1737 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1738 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1740 fputc ('\n', asm_out_file
);
1745 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1750 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1751 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1753 fputc ('\n', asm_out_file
);
1758 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1759 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1766 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1767 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1769 dw2_asm_output_data (2, offset
, NULL
);
1772 case DW_OP_implicit_value
:
1773 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1774 switch (val2
->val_class
)
1776 case dw_val_class_const
:
1777 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1779 case dw_val_class_vec
:
1781 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1782 unsigned int len
= val2
->v
.val_vec
.length
;
1786 if (elt_size
> sizeof (HOST_WIDE_INT
))
1791 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1794 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1795 "fp or vector constant word %u", i
);
1798 case dw_val_class_const_double
:
1800 unsigned HOST_WIDE_INT first
, second
;
1802 if (WORDS_BIG_ENDIAN
)
1804 first
= val2
->v
.val_double
.high
;
1805 second
= val2
->v
.val_double
.low
;
1809 first
= val2
->v
.val_double
.low
;
1810 second
= val2
->v
.val_double
.high
;
1812 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1814 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1818 case dw_val_class_addr
:
1819 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1820 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1835 case DW_OP_implicit_value
:
1836 /* We currently don't make any attempt to make sure these are
1837 aligned properly like we do for the main unwind info, so
1838 don't support emitting things larger than a byte if we're
1839 only doing unwinding. */
1844 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1847 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1850 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1853 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1855 case DW_OP_plus_uconst
:
1856 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1890 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1894 unsigned r
= val1
->v
.val_unsigned
;
1895 if (for_eh_or_skip
>= 0)
1896 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1897 gcc_assert (size_of_uleb128 (r
)
1898 == size_of_uleb128 (val1
->v
.val_unsigned
));
1899 dw2_asm_output_data_uleb128 (r
, NULL
);
1903 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1907 unsigned r
= val1
->v
.val_unsigned
;
1908 if (for_eh_or_skip
>= 0)
1909 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1910 gcc_assert (size_of_uleb128 (r
)
1911 == size_of_uleb128 (val1
->v
.val_unsigned
));
1912 dw2_asm_output_data_uleb128 (r
, NULL
);
1913 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1917 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1919 case DW_OP_bit_piece
:
1920 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1921 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1923 case DW_OP_deref_size
:
1924 case DW_OP_xderef_size
:
1925 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1931 if (targetm
.asm_out
.output_dwarf_dtprel
)
1933 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1936 fputc ('\n', asm_out_file
);
1943 #ifdef DWARF2_DEBUGGING_INFO
1944 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1951 case DW_OP_GNU_addr_index
:
1952 case DW_OP_GNU_const_index
:
1953 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1954 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1955 "(index into .debug_addr)");
1958 case DW_OP_GNU_implicit_pointer
:
1960 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1961 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1962 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1963 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1964 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1965 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1969 case DW_OP_GNU_entry_value
:
1970 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1971 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1974 case DW_OP_GNU_const_type
:
1976 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1978 dw2_asm_output_data_uleb128 (o
, NULL
);
1979 switch (val2
->val_class
)
1981 case dw_val_class_const
:
1982 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1983 dw2_asm_output_data (1, l
, NULL
);
1984 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1986 case dw_val_class_vec
:
1988 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1989 unsigned int len
= val2
->v
.val_vec
.length
;
1994 dw2_asm_output_data (1, l
, NULL
);
1995 if (elt_size
> sizeof (HOST_WIDE_INT
))
2000 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2003 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2004 "fp or vector constant word %u", i
);
2007 case dw_val_class_const_double
:
2009 unsigned HOST_WIDE_INT first
, second
;
2010 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2012 dw2_asm_output_data (1, 2 * l
, NULL
);
2013 if (WORDS_BIG_ENDIAN
)
2015 first
= val2
->v
.val_double
.high
;
2016 second
= val2
->v
.val_double
.low
;
2020 first
= val2
->v
.val_double
.low
;
2021 second
= val2
->v
.val_double
.high
;
2023 dw2_asm_output_data (l
, first
, NULL
);
2024 dw2_asm_output_data (l
, second
, NULL
);
2032 case DW_OP_GNU_regval_type
:
2034 unsigned r
= val1
->v
.val_unsigned
;
2035 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2037 if (for_eh_or_skip
>= 0)
2039 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2040 gcc_assert (size_of_uleb128 (r
)
2041 == size_of_uleb128 (val1
->v
.val_unsigned
));
2043 dw2_asm_output_data_uleb128 (r
, NULL
);
2044 dw2_asm_output_data_uleb128 (o
, NULL
);
2047 case DW_OP_GNU_deref_type
:
2049 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2051 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2052 dw2_asm_output_data_uleb128 (o
, NULL
);
2055 case DW_OP_GNU_convert
:
2056 case DW_OP_GNU_reinterpret
:
2057 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2058 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2061 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2063 dw2_asm_output_data_uleb128 (o
, NULL
);
2067 case DW_OP_GNU_parameter_ref
:
2070 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2071 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2072 dw2_asm_output_data (4, o
, NULL
);
2077 /* Other codes have no operands. */
2082 /* Output a sequence of location operations.
2083 The for_eh_or_skip parameter controls whether register numbers are
2084 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2085 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2086 info). This should be suppressed for the cases that have not been converted
2087 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2090 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2092 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2094 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2095 /* Output the opcode. */
2096 if (for_eh_or_skip
>= 0
2097 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2099 unsigned r
= (opc
- DW_OP_breg0
);
2100 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2101 gcc_assert (r
<= 31);
2102 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2104 else if (for_eh_or_skip
>= 0
2105 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2107 unsigned r
= (opc
- DW_OP_reg0
);
2108 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2109 gcc_assert (r
<= 31);
2110 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2113 dw2_asm_output_data (1, opc
,
2114 "%s", dwarf_stack_op_name (opc
));
2116 /* Output the operand(s) (if any). */
2117 output_loc_operands (loc
, for_eh_or_skip
);
2121 /* Output location description stack opcode's operands (if any).
2122 The output is single bytes on a line, suitable for .cfi_escape. */
2125 output_loc_operands_raw (dw_loc_descr_ref loc
)
2127 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2128 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2130 switch (loc
->dw_loc_opc
)
2133 case DW_OP_GNU_addr_index
:
2134 case DW_OP_GNU_const_index
:
2135 case DW_OP_implicit_value
:
2136 /* We cannot output addresses in .cfi_escape, only bytes. */
2142 case DW_OP_deref_size
:
2143 case DW_OP_xderef_size
:
2144 fputc (',', asm_out_file
);
2145 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2150 fputc (',', asm_out_file
);
2151 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2156 fputc (',', asm_out_file
);
2157 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2162 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2163 fputc (',', asm_out_file
);
2164 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2172 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2173 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2175 fputc (',', asm_out_file
);
2176 dw2_asm_output_data_raw (2, offset
);
2182 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2183 gcc_assert (size_of_uleb128 (r
)
2184 == size_of_uleb128 (val1
->v
.val_unsigned
));
2185 fputc (',', asm_out_file
);
2186 dw2_asm_output_data_uleb128_raw (r
);
2191 case DW_OP_plus_uconst
:
2193 fputc (',', asm_out_file
);
2194 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2197 case DW_OP_bit_piece
:
2198 fputc (',', asm_out_file
);
2199 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2200 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2237 fputc (',', asm_out_file
);
2238 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2243 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2244 gcc_assert (size_of_uleb128 (r
)
2245 == size_of_uleb128 (val1
->v
.val_unsigned
));
2246 fputc (',', asm_out_file
);
2247 dw2_asm_output_data_uleb128_raw (r
);
2248 fputc (',', asm_out_file
);
2249 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2253 case DW_OP_GNU_implicit_pointer
:
2254 case DW_OP_GNU_entry_value
:
2255 case DW_OP_GNU_const_type
:
2256 case DW_OP_GNU_regval_type
:
2257 case DW_OP_GNU_deref_type
:
2258 case DW_OP_GNU_convert
:
2259 case DW_OP_GNU_reinterpret
:
2260 case DW_OP_GNU_parameter_ref
:
2265 /* Other codes have no operands. */
2271 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2275 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2276 /* Output the opcode. */
2277 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2279 unsigned r
= (opc
- DW_OP_breg0
);
2280 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2281 gcc_assert (r
<= 31);
2282 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2284 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2286 unsigned r
= (opc
- DW_OP_reg0
);
2287 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2288 gcc_assert (r
<= 31);
2289 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2291 /* Output the opcode. */
2292 fprintf (asm_out_file
, "%#x", opc
);
2293 output_loc_operands_raw (loc
);
2295 if (!loc
->dw_loc_next
)
2297 loc
= loc
->dw_loc_next
;
2299 fputc (',', asm_out_file
);
2303 /* This function builds a dwarf location descriptor sequence from a
2304 dw_cfa_location, adding the given OFFSET to the result of the
2307 struct dw_loc_descr_struct
*
2308 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2310 struct dw_loc_descr_struct
*head
, *tmp
;
2312 offset
+= cfa
->offset
;
2316 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2317 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2318 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2319 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2320 add_loc_descr (&head
, tmp
);
2323 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2324 add_loc_descr (&head
, tmp
);
2328 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2333 /* This function builds a dwarf location descriptor sequence for
2334 the address at OFFSET from the CFA when stack is aligned to
2337 struct dw_loc_descr_struct
*
2338 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2339 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2341 struct dw_loc_descr_struct
*head
;
2342 unsigned int dwarf_fp
2343 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2345 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2346 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2348 head
= new_reg_loc_descr (dwarf_fp
, 0);
2349 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2350 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2351 loc_descr_plus_const (&head
, offset
);
2354 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2358 /* And now, the support for symbolic debugging information. */
2360 /* .debug_str support. */
2361 static int output_indirect_string (void **, void *);
2363 static void dwarf2out_init (const char *);
2364 static void dwarf2out_finish (const char *);
2365 static void dwarf2out_assembly_start (void);
2366 static void dwarf2out_define (unsigned int, const char *);
2367 static void dwarf2out_undef (unsigned int, const char *);
2368 static void dwarf2out_start_source_file (unsigned, const char *);
2369 static void dwarf2out_end_source_file (unsigned);
2370 static void dwarf2out_function_decl (tree
);
2371 static void dwarf2out_begin_block (unsigned, unsigned);
2372 static void dwarf2out_end_block (unsigned, unsigned);
2373 static bool dwarf2out_ignore_block (const_tree
);
2374 static void dwarf2out_global_decl (tree
);
2375 static void dwarf2out_type_decl (tree
, int);
2376 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2377 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2379 static void dwarf2out_abstract_function (tree
);
2380 static void dwarf2out_var_location (rtx
);
2381 static void dwarf2out_begin_function (tree
);
2382 static void dwarf2out_end_function (unsigned int);
2383 static void dwarf2out_set_name (tree
, tree
);
2385 /* The debug hooks structure. */
2387 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2391 dwarf2out_assembly_start
,
2394 dwarf2out_start_source_file
,
2395 dwarf2out_end_source_file
,
2396 dwarf2out_begin_block
,
2397 dwarf2out_end_block
,
2398 dwarf2out_ignore_block
,
2399 dwarf2out_source_line
,
2400 dwarf2out_begin_prologue
,
2401 #if VMS_DEBUGGING_INFO
2402 dwarf2out_vms_end_prologue
,
2403 dwarf2out_vms_begin_epilogue
,
2405 debug_nothing_int_charstar
,
2406 debug_nothing_int_charstar
,
2408 dwarf2out_end_epilogue
,
2409 dwarf2out_begin_function
,
2410 dwarf2out_end_function
, /* end_function */
2411 dwarf2out_function_decl
, /* function_decl */
2412 dwarf2out_global_decl
,
2413 dwarf2out_type_decl
, /* type_decl */
2414 dwarf2out_imported_module_or_decl
,
2415 debug_nothing_tree
, /* deferred_inline_function */
2416 /* The DWARF 2 backend tries to reduce debugging bloat by not
2417 emitting the abstract description of inline functions until
2418 something tries to reference them. */
2419 dwarf2out_abstract_function
, /* outlining_inline_function */
2420 debug_nothing_rtx
, /* label */
2421 debug_nothing_int
, /* handle_pch */
2422 dwarf2out_var_location
,
2423 dwarf2out_switch_text_section
,
2425 1, /* start_end_main_source_file */
2426 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2429 /* NOTE: In the comments in this file, many references are made to
2430 "Debugging Information Entries". This term is abbreviated as `DIE'
2431 throughout the remainder of this file. */
2433 /* An internal representation of the DWARF output is built, and then
2434 walked to generate the DWARF debugging info. The walk of the internal
2435 representation is done after the entire program has been compiled.
2436 The types below are used to describe the internal representation. */
2438 /* Whether to put type DIEs into their own section .debug_types instead
2439 of making them part of the .debug_info section. Only supported for
2440 Dwarf V4 or higher and the user didn't disable them through
2441 -fno-debug-types-section. It is more efficient to put them in a
2442 separate comdat sections since the linker will then be able to
2443 remove duplicates. But not all tools support .debug_types sections
2446 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2448 /* Various DIE's use offsets relative to the beginning of the
2449 .debug_info section to refer to each other. */
2451 typedef long int dw_offset
;
2453 /* Define typedefs here to avoid circular dependencies. */
2455 typedef struct dw_attr_struct
*dw_attr_ref
;
2456 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2457 typedef struct pubname_struct
*pubname_ref
;
2458 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2459 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2460 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2462 /* The entries in the line_info table more-or-less mirror the opcodes
2463 that are used in the real dwarf line table. Arrays of these entries
2464 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2467 enum dw_line_info_opcode
{
2468 /* Emit DW_LNE_set_address; the operand is the label index. */
2471 /* Emit a row to the matrix with the given line. This may be done
2472 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2476 /* Emit a DW_LNS_set_file. */
2479 /* Emit a DW_LNS_set_column. */
2482 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2485 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2486 LI_set_prologue_end
,
2487 LI_set_epilogue_begin
,
2489 /* Emit a DW_LNE_set_discriminator. */
2490 LI_set_discriminator
2493 typedef struct GTY(()) dw_line_info_struct
{
2494 enum dw_line_info_opcode opcode
;
2496 } dw_line_info_entry
;
2499 typedef struct GTY(()) dw_line_info_table_struct
{
2500 /* The label that marks the end of this section. */
2501 const char *end_label
;
2503 /* The values for the last row of the matrix, as collected in the table.
2504 These are used to minimize the changes to the next row. */
2505 unsigned int file_num
;
2506 unsigned int line_num
;
2507 unsigned int column_num
;
2512 vec
<dw_line_info_entry
, va_gc
> *entries
;
2513 } dw_line_info_table
;
2515 typedef dw_line_info_table
*dw_line_info_table_p
;
2518 /* Each DIE attribute has a field specifying the attribute kind,
2519 a link to the next attribute in the chain, and an attribute value.
2520 Attributes are typically linked below the DIE they modify. */
2522 typedef struct GTY(()) dw_attr_struct
{
2523 enum dwarf_attribute dw_attr
;
2524 dw_val_node dw_attr_val
;
2529 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2530 The children of each node form a circular list linked by
2531 die_sib. die_child points to the node *before* the "first" child node. */
2533 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2534 union die_symbol_or_type_node
2536 const char * GTY ((tag ("0"))) die_symbol
;
2537 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2539 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2540 vec
<dw_attr_node
, va_gc
> *die_attr
;
2541 dw_die_ref die_parent
;
2542 dw_die_ref die_child
;
2544 dw_die_ref die_definition
; /* ref from a specification to its definition */
2545 dw_offset die_offset
;
2546 unsigned long die_abbrev
;
2548 unsigned int decl_id
;
2549 enum dwarf_tag die_tag
;
2550 /* Die is used and must not be pruned as unused. */
2551 BOOL_BITFIELD die_perennial_p
: 1;
2552 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2553 /* Lots of spare bits. */
2557 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2558 #define FOR_EACH_CHILD(die, c, expr) do { \
2559 c = die->die_child; \
2563 } while (c != die->die_child); \
2566 /* The pubname structure */
2568 typedef struct GTY(()) pubname_struct
{
2575 struct GTY(()) dw_ranges_struct
{
2576 /* If this is positive, it's a block number, otherwise it's a
2577 bitwise-negated index into dw_ranges_by_label. */
2581 /* A structure to hold a macinfo entry. */
2583 typedef struct GTY(()) macinfo_struct
{
2585 unsigned HOST_WIDE_INT lineno
;
2591 struct GTY(()) dw_ranges_by_label_struct
{
2596 /* The comdat type node structure. */
2597 typedef struct GTY(()) comdat_type_struct
2599 dw_die_ref root_die
;
2600 dw_die_ref type_die
;
2601 dw_die_ref skeleton_die
;
2602 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2603 struct comdat_type_struct
*next
;
2607 /* The limbo die list structure. */
2608 typedef struct GTY(()) limbo_die_struct
{
2611 struct limbo_die_struct
*next
;
2615 typedef struct skeleton_chain_struct
2619 struct skeleton_chain_struct
*parent
;
2621 skeleton_chain_node
;
2623 /* Define a macro which returns nonzero for a TYPE_DECL which was
2624 implicitly generated for a type.
2626 Note that, unlike the C front-end (which generates a NULL named
2627 TYPE_DECL node for each complete tagged type, each array type,
2628 and each function type node created) the C++ front-end generates
2629 a _named_ TYPE_DECL node for each tagged type node created.
2630 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2631 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2632 front-end, but for each type, tagged or not. */
2634 #define TYPE_DECL_IS_STUB(decl) \
2635 (DECL_NAME (decl) == NULL_TREE \
2636 || (DECL_ARTIFICIAL (decl) \
2637 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2638 /* This is necessary for stub decls that \
2639 appear in nested inline functions. */ \
2640 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2641 && (decl_ultimate_origin (decl) \
2642 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2644 /* Information concerning the compilation unit's programming
2645 language, and compiler version. */
2647 /* Fixed size portion of the DWARF compilation unit header. */
2648 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2649 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2651 /* Fixed size portion of the DWARF comdat type unit header. */
2652 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2653 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2654 + DWARF_OFFSET_SIZE)
2656 /* Fixed size portion of public names info. */
2657 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2659 /* Fixed size portion of the address range info. */
2660 #define DWARF_ARANGES_HEADER_SIZE \
2661 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2662 DWARF2_ADDR_SIZE * 2) \
2663 - DWARF_INITIAL_LENGTH_SIZE)
2665 /* Size of padding portion in the address range info. It must be
2666 aligned to twice the pointer size. */
2667 #define DWARF_ARANGES_PAD_SIZE \
2668 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2669 DWARF2_ADDR_SIZE * 2) \
2670 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2672 /* Use assembler line directives if available. */
2673 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2674 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2675 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2677 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2681 /* Minimum line offset in a special line info. opcode.
2682 This value was chosen to give a reasonable range of values. */
2683 #define DWARF_LINE_BASE -10
2685 /* First special line opcode - leave room for the standard opcodes. */
2686 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2688 /* Range of line offsets in a special line info. opcode. */
2689 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2691 /* Flag that indicates the initial value of the is_stmt_start flag.
2692 In the present implementation, we do not mark any lines as
2693 the beginning of a source statement, because that information
2694 is not made available by the GCC front-end. */
2695 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2697 /* Maximum number of operations per instruction bundle. */
2698 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2699 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2702 /* This location is used by calc_die_sizes() to keep track
2703 the offset of each DIE within the .debug_info section. */
2704 static unsigned long next_die_offset
;
2706 /* Record the root of the DIE's built for the current compilation unit. */
2707 static GTY(()) dw_die_ref single_comp_unit_die
;
2709 /* A list of type DIEs that have been separated into comdat sections. */
2710 static GTY(()) comdat_type_node
*comdat_type_list
;
2712 /* A list of DIEs with a NULL parent waiting to be relocated. */
2713 static GTY(()) limbo_die_node
*limbo_die_list
;
2715 /* A list of DIEs for which we may have to generate
2716 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2717 static GTY(()) limbo_die_node
*deferred_asm_name
;
2719 /* Filenames referenced by this compilation unit. */
2720 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2722 /* A hash table of references to DIE's that describe declarations.
2723 The key is a DECL_UID() which is a unique number identifying each decl. */
2724 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2726 /* A hash table of references to DIE's that describe COMMON blocks.
2727 The key is DECL_UID() ^ die_parent. */
2728 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2730 typedef struct GTY(()) die_arg_entry_struct
{
2736 /* Node of the variable location list. */
2737 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2738 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2739 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2740 in mode of the EXPR_LIST node and first EXPR_LIST operand
2741 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2742 location or NULL for padding. For larger bitsizes,
2743 mode is 0 and first operand is a CONCAT with bitsize
2744 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2745 NULL as second operand. */
2747 const char * GTY (()) label
;
2748 struct var_loc_node
* GTY (()) next
;
2751 /* Variable location list. */
2752 struct GTY (()) var_loc_list_def
{
2753 struct var_loc_node
* GTY (()) first
;
2755 /* Pointer to the last but one or last element of the
2756 chained list. If the list is empty, both first and
2757 last are NULL, if the list contains just one node
2758 or the last node certainly is not redundant, it points
2759 to the last node, otherwise points to the last but one.
2760 Do not mark it for GC because it is marked through the chain. */
2761 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2763 /* Pointer to the last element before section switch,
2764 if NULL, either sections weren't switched or first
2765 is after section switch. */
2766 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2768 /* DECL_UID of the variable decl. */
2769 unsigned int decl_id
;
2771 typedef struct var_loc_list_def var_loc_list
;
2773 /* Call argument location list. */
2774 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2775 rtx
GTY (()) call_arg_loc_note
;
2776 const char * GTY (()) label
;
2777 tree
GTY (()) block
;
2779 rtx
GTY (()) symbol_ref
;
2780 struct call_arg_loc_node
* GTY (()) next
;
2784 /* Table of decl location linked lists. */
2785 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2787 /* Head and tail of call_arg_loc chain. */
2788 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2789 static struct call_arg_loc_node
*call_arg_loc_last
;
2791 /* Number of call sites in the current function. */
2792 static int call_site_count
= -1;
2793 /* Number of tail call sites in the current function. */
2794 static int tail_call_site_count
= -1;
2796 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2798 static vec
<dw_die_ref
> block_map
;
2800 /* A cached location list. */
2801 struct GTY (()) cached_dw_loc_list_def
{
2802 /* The DECL_UID of the decl that this entry describes. */
2803 unsigned int decl_id
;
2805 /* The cached location list. */
2806 dw_loc_list_ref loc_list
;
2808 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2810 /* Table of cached location lists. */
2811 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2813 /* A pointer to the base of a list of references to DIE's that
2814 are uniquely identified by their tag, presence/absence of
2815 children DIE's, and list of attribute/value pairs. */
2816 static GTY((length ("abbrev_die_table_allocated")))
2817 dw_die_ref
*abbrev_die_table
;
2819 /* Number of elements currently allocated for abbrev_die_table. */
2820 static GTY(()) unsigned abbrev_die_table_allocated
;
2822 /* Number of elements in type_die_table currently in use. */
2823 static GTY(()) unsigned abbrev_die_table_in_use
;
2825 /* Size (in elements) of increments by which we may expand the
2826 abbrev_die_table. */
2827 #define ABBREV_DIE_TABLE_INCREMENT 256
2829 /* A global counter for generating labels for line number data. */
2830 static unsigned int line_info_label_num
;
2832 /* The current table to which we should emit line number information
2833 for the current function. This will be set up at the beginning of
2834 assembly for the function. */
2835 static dw_line_info_table
*cur_line_info_table
;
2837 /* The two default tables of line number info. */
2838 static GTY(()) dw_line_info_table
*text_section_line_info
;
2839 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2841 /* The set of all non-default tables of line number info. */
2842 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2844 /* A flag to tell pubnames/types export if there is an info section to
2846 static bool info_section_emitted
;
2848 /* A pointer to the base of a table that contains a list of publicly
2849 accessible names. */
2850 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2852 /* A pointer to the base of a table that contains a list of publicly
2853 accessible types. */
2854 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2856 /* A pointer to the base of a table that contains a list of macro
2857 defines/undefines (and file start/end markers). */
2858 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2860 /* True if .debug_macinfo or .debug_macros section is going to be
2862 #define have_macinfo \
2863 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2864 && !macinfo_table->is_empty ())
2866 /* Array of dies for which we should generate .debug_ranges info. */
2867 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2869 /* Number of elements currently allocated for ranges_table. */
2870 static GTY(()) unsigned ranges_table_allocated
;
2872 /* Number of elements in ranges_table currently in use. */
2873 static GTY(()) unsigned ranges_table_in_use
;
2875 /* Array of pairs of labels referenced in ranges_table. */
2876 static GTY ((length ("ranges_by_label_allocated")))
2877 dw_ranges_by_label_ref ranges_by_label
;
2879 /* Number of elements currently allocated for ranges_by_label. */
2880 static GTY(()) unsigned ranges_by_label_allocated
;
2882 /* Number of elements in ranges_by_label currently in use. */
2883 static GTY(()) unsigned ranges_by_label_in_use
;
2885 /* Size (in elements) of increments by which we may expand the
2887 #define RANGES_TABLE_INCREMENT 64
2889 /* Whether we have location lists that need outputting */
2890 static GTY(()) bool have_location_lists
;
2892 /* Unique label counter. */
2893 static GTY(()) unsigned int loclabel_num
;
2895 /* Unique label counter for point-of-call tables. */
2896 static GTY(()) unsigned int poc_label_num
;
2898 /* Record whether the function being analyzed contains inlined functions. */
2899 static int current_function_has_inlines
;
2901 /* The last file entry emitted by maybe_emit_file(). */
2902 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2904 /* Number of internal labels generated by gen_internal_sym(). */
2905 static GTY(()) int label_num
;
2907 /* Cached result of previous call to lookup_filename. */
2908 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2910 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2912 /* Instances of generic types for which we need to generate debug
2913 info that describe their generic parameters and arguments. That
2914 generation needs to happen once all types are properly laid out so
2915 we do it at the end of compilation. */
2916 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2918 /* Offset from the "steady-state frame pointer" to the frame base,
2919 within the current function. */
2920 static HOST_WIDE_INT frame_pointer_fb_offset
;
2921 static bool frame_pointer_fb_offset_valid
;
2923 static vec
<dw_die_ref
> base_types
;
2925 /* Forward declarations for functions defined in this file. */
2927 static int is_pseudo_reg (const_rtx
);
2928 static tree
type_main_variant (tree
);
2929 static int is_tagged_type (const_tree
);
2930 static const char *dwarf_tag_name (unsigned);
2931 static const char *dwarf_attr_name (unsigned);
2932 static const char *dwarf_form_name (unsigned);
2933 static tree
decl_ultimate_origin (const_tree
);
2934 static tree
decl_class_context (tree
);
2935 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2936 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2937 static inline unsigned int AT_index (dw_attr_ref
);
2938 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2939 static inline unsigned AT_flag (dw_attr_ref
);
2940 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2941 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2942 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2943 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2944 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2945 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2946 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2947 unsigned int, unsigned char *);
2948 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2949 static hashval_t
debug_str_do_hash (const void *);
2950 static int debug_str_eq (const void *, const void *);
2951 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2952 static inline const char *AT_string (dw_attr_ref
);
2953 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2954 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2955 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2956 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2957 static inline int AT_ref_external (dw_attr_ref
);
2958 static inline void set_AT_ref_external (dw_attr_ref
, int);
2959 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2960 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2961 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2962 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2964 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2965 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2966 static void remove_addr_table_entry (addr_table_entry
*);
2967 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2968 static inline rtx
AT_addr (dw_attr_ref
);
2969 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2970 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2971 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2972 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2973 unsigned HOST_WIDE_INT
);
2974 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2975 unsigned long, bool);
2976 static inline const char *AT_lbl (dw_attr_ref
);
2977 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2978 static const char *get_AT_low_pc (dw_die_ref
);
2979 static const char *get_AT_hi_pc (dw_die_ref
);
2980 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2981 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2982 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2983 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2984 static bool is_cxx (void);
2985 static bool is_fortran (void);
2986 static bool is_ada (void);
2987 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2988 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2989 static void add_child_die (dw_die_ref
, dw_die_ref
);
2990 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2991 static dw_die_ref
lookup_type_die (tree
);
2992 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2993 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2994 static void equate_type_number_to_die (tree
, dw_die_ref
);
2995 static hashval_t
decl_die_table_hash (const void *);
2996 static int decl_die_table_eq (const void *, const void *);
2997 static dw_die_ref
lookup_decl_die (tree
);
2998 static hashval_t
common_block_die_table_hash (const void *);
2999 static int common_block_die_table_eq (const void *, const void *);
3000 static hashval_t
decl_loc_table_hash (const void *);
3001 static int decl_loc_table_eq (const void *, const void *);
3002 static var_loc_list
*lookup_decl_loc (const_tree
);
3003 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3004 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3005 static void print_spaces (FILE *);
3006 static void print_die (dw_die_ref
, FILE *);
3007 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3008 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3009 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3010 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3011 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3012 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3013 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3014 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3015 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3016 struct md5_ctx
*, int *);
3017 struct checksum_attributes
;
3018 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3019 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3020 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3021 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3022 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3023 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3024 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3025 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3026 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3027 static void compute_section_prefix (dw_die_ref
);
3028 static int is_type_die (dw_die_ref
);
3029 static int is_comdat_die (dw_die_ref
);
3030 static int is_symbol_die (dw_die_ref
);
3031 static inline bool is_template_instantiation (dw_die_ref
);
3032 static void assign_symbol_names (dw_die_ref
);
3033 static void break_out_includes (dw_die_ref
);
3034 static int is_declaration_die (dw_die_ref
);
3035 static int should_move_die_to_comdat (dw_die_ref
);
3036 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3037 static dw_die_ref
clone_die (dw_die_ref
);
3038 static dw_die_ref
clone_tree (dw_die_ref
);
3039 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3040 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3041 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3042 static dw_die_ref
generate_skeleton (dw_die_ref
);
3043 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3046 static void break_out_comdat_types (dw_die_ref
);
3047 static void copy_decls_for_unworthy_types (dw_die_ref
);
3049 static void add_sibling_attributes (dw_die_ref
);
3050 static void output_location_lists (dw_die_ref
);
3051 static int constant_size (unsigned HOST_WIDE_INT
);
3052 static unsigned long size_of_die (dw_die_ref
);
3053 static void calc_die_sizes (dw_die_ref
);
3054 static void calc_base_type_die_sizes (void);
3055 static void mark_dies (dw_die_ref
);
3056 static void unmark_dies (dw_die_ref
);
3057 static void unmark_all_dies (dw_die_ref
);
3058 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3059 static unsigned long size_of_aranges (void);
3060 static enum dwarf_form
value_format (dw_attr_ref
);
3061 static void output_value_format (dw_attr_ref
);
3062 static void output_abbrev_section (void);
3063 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3064 static void output_die_symbol (dw_die_ref
);
3065 static void output_die (dw_die_ref
);
3066 static void output_compilation_unit_header (void);
3067 static void output_comp_unit (dw_die_ref
, int);
3068 static void output_comdat_type_unit (comdat_type_node
*);
3069 static const char *dwarf2_name (tree
, int);
3070 static void add_pubname (tree
, dw_die_ref
);
3071 static void add_enumerator_pubname (const char *, dw_die_ref
);
3072 static void add_pubname_string (const char *, dw_die_ref
);
3073 static void add_pubtype (tree
, dw_die_ref
);
3074 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3075 static void output_aranges (unsigned long);
3076 static unsigned int add_ranges_num (int);
3077 static unsigned int add_ranges (const_tree
);
3078 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3080 static void output_ranges (void);
3081 static dw_line_info_table
*new_line_info_table (void);
3082 static void output_line_info (bool);
3083 static void output_file_names (void);
3084 static dw_die_ref
base_type_die (tree
);
3085 static int is_base_type (tree
);
3086 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3087 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3088 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3089 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3090 static int type_is_enum (const_tree
);
3091 static unsigned int dbx_reg_number (const_rtx
);
3092 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3093 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3094 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3095 enum var_init_status
);
3096 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3097 enum var_init_status
);
3098 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3099 enum var_init_status
);
3100 static int is_based_loc (const_rtx
);
3101 static int resolve_one_addr (rtx
*, void *);
3102 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3103 enum var_init_status
);
3104 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3105 enum var_init_status
);
3106 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3107 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3108 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3109 static tree
field_type (const_tree
);
3110 static unsigned int simple_type_align_in_bits (const_tree
);
3111 static unsigned int simple_decl_align_in_bits (const_tree
);
3112 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3113 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3114 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3116 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3117 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3118 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3119 static void insert_double (double_int
, unsigned char *);
3120 static void insert_float (const_rtx
, unsigned char *);
3121 static rtx
rtl_for_decl_location (tree
);
3122 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3123 enum dwarf_attribute
);
3124 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3125 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3126 static void add_name_attribute (dw_die_ref
, const char *);
3127 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3128 static void add_comp_dir_attribute (dw_die_ref
);
3129 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3130 static void add_subscript_info (dw_die_ref
, tree
, bool);
3131 static void add_byte_size_attribute (dw_die_ref
, tree
);
3132 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3133 static void add_bit_size_attribute (dw_die_ref
, tree
);
3134 static void add_prototyped_attribute (dw_die_ref
, tree
);
3135 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3136 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3137 static void add_src_coords_attributes (dw_die_ref
, tree
);
3138 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3139 static void push_decl_scope (tree
);
3140 static void pop_decl_scope (void);
3141 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3142 static inline int local_scope_p (dw_die_ref
);
3143 static inline int class_scope_p (dw_die_ref
);
3144 static inline int class_or_namespace_scope_p (dw_die_ref
);
3145 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3146 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3147 static const char *type_tag (const_tree
);
3148 static tree
member_declared_type (const_tree
);
3150 static const char *decl_start_label (tree
);
3152 static void gen_array_type_die (tree
, dw_die_ref
);
3153 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3155 static void gen_entry_point_die (tree
, dw_die_ref
);
3157 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3158 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3159 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3160 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3161 static void gen_formal_types_die (tree
, dw_die_ref
);
3162 static void gen_subprogram_die (tree
, dw_die_ref
);
3163 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3164 static void gen_const_die (tree
, dw_die_ref
);
3165 static void gen_label_die (tree
, dw_die_ref
);
3166 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3167 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3168 static void gen_field_die (tree
, dw_die_ref
);
3169 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3170 static dw_die_ref
gen_compile_unit_die (const char *);
3171 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3172 static void gen_member_die (tree
, dw_die_ref
);
3173 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3174 enum debug_info_usage
);
3175 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3176 static void gen_typedef_die (tree
, dw_die_ref
);
3177 static void gen_type_die (tree
, dw_die_ref
);
3178 static void gen_block_die (tree
, dw_die_ref
, int);
3179 static void decls_for_scope (tree
, dw_die_ref
, int);
3180 static inline int is_redundant_typedef (const_tree
);
3181 static bool is_naming_typedef_decl (const_tree
);
3182 static inline dw_die_ref
get_context_die (tree
);
3183 static void gen_namespace_die (tree
, dw_die_ref
);
3184 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3185 static dw_die_ref
force_decl_die (tree
);
3186 static dw_die_ref
force_type_die (tree
);
3187 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3188 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3189 static struct dwarf_file_data
* lookup_filename (const char *);
3190 static void retry_incomplete_types (void);
3191 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3192 static void gen_generic_params_dies (tree
);
3193 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3194 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3195 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3196 static int file_info_cmp (const void *, const void *);
3197 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3198 const char *, const char *);
3199 static void output_loc_list (dw_loc_list_ref
);
3200 static char *gen_internal_sym (const char *);
3201 static bool want_pubnames (void);
3203 static void prune_unmark_dies (dw_die_ref
);
3204 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3205 static void prune_unused_types_mark (dw_die_ref
, int);
3206 static void prune_unused_types_walk (dw_die_ref
);
3207 static void prune_unused_types_walk_attribs (dw_die_ref
);
3208 static void prune_unused_types_prune (dw_die_ref
);
3209 static void prune_unused_types (void);
3210 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3211 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3212 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3213 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3214 const char *, const char *);
3215 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3216 static void gen_remaining_tmpl_value_param_die_attribute (void);
3217 static bool generic_type_p (tree
);
3218 static void schedule_generic_params_dies_gen (tree t
);
3219 static void gen_scheduled_generic_parms_dies (void);
3221 static const char *comp_dir_string (void);
3223 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3225 /* enum for tracking thread-local variables whose address is really an offset
3226 relative to the TLS pointer, which will need link-time relocation, but will
3227 not need relocation by the DWARF consumer. */
3235 /* Return the operator to use for an address of a variable. For dtprel_true, we
3236 use DW_OP_const*. For regular variables, which need both link-time
3237 relocation and consumer-level relocation (e.g., to account for shared objects
3238 loaded at a random address), we use DW_OP_addr*. */
3240 static inline enum dwarf_location_atom
3241 dw_addr_op (enum dtprel_bool dtprel
)
3243 if (dtprel
== dtprel_true
)
3244 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3245 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3247 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3250 /* Return a pointer to a newly allocated address location description. If
3251 dwarf_split_debug_info is true, then record the address with the appropriate
3253 static inline dw_loc_descr_ref
3254 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3256 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3258 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3259 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3260 ref
->dtprel
= dtprel
;
3261 if (dwarf_split_debug_info
)
3262 ref
->dw_loc_oprnd1
.val_entry
3263 = add_addr_table_entry (addr
,
3264 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3266 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3271 /* Section names used to hold DWARF debugging information. */
3273 #ifndef DEBUG_INFO_SECTION
3274 #define DEBUG_INFO_SECTION ".debug_info"
3276 #ifndef DEBUG_DWO_INFO_SECTION
3277 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3279 #ifndef DEBUG_ABBREV_SECTION
3280 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3282 #ifndef DEBUG_DWO_ABBREV_SECTION
3283 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3285 #ifndef DEBUG_ARANGES_SECTION
3286 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3288 #ifndef DEBUG_ADDR_SECTION
3289 #define DEBUG_ADDR_SECTION ".debug_addr"
3291 #ifndef DEBUG_NORM_MACINFO_SECTION
3292 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3294 #ifndef DEBUG_DWO_MACINFO_SECTION
3295 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3297 #ifndef DEBUG_MACINFO_SECTION
3298 #define DEBUG_MACINFO_SECTION \
3299 (!dwarf_split_debug_info \
3300 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3302 #ifndef DEBUG_NORM_MACRO_SECTION
3303 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3305 #ifndef DEBUG_DWO_MACRO_SECTION
3306 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3308 #ifndef DEBUG_MACRO_SECTION
3309 #define DEBUG_MACRO_SECTION \
3310 (!dwarf_split_debug_info \
3311 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3313 #ifndef DEBUG_LINE_SECTION
3314 #define DEBUG_LINE_SECTION ".debug_line"
3316 #ifndef DEBUG_DWO_LINE_SECTION
3317 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3319 #ifndef DEBUG_LOC_SECTION
3320 #define DEBUG_LOC_SECTION ".debug_loc"
3322 #ifndef DEBUG_DWO_LOC_SECTION
3323 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3325 #ifndef DEBUG_PUBNAMES_SECTION
3326 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3328 #ifndef DEBUG_PUBTYPES_SECTION
3329 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3331 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3332 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3333 #ifndef DEBUG_STR_OFFSETS_SECTION
3334 #define DEBUG_STR_OFFSETS_SECTION \
3335 (!dwarf_split_debug_info \
3336 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3338 #ifndef DEBUG_STR_DWO_SECTION
3339 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3341 #ifndef DEBUG_STR_SECTION
3342 #define DEBUG_STR_SECTION ".debug_str"
3344 #ifndef DEBUG_RANGES_SECTION
3345 #define DEBUG_RANGES_SECTION ".debug_ranges"
3348 /* Standard ELF section names for compiled code and data. */
3349 #ifndef TEXT_SECTION_NAME
3350 #define TEXT_SECTION_NAME ".text"
3353 /* Section flags for .debug_macinfo/.debug_macro section. */
3354 #define DEBUG_MACRO_SECTION_FLAGS \
3355 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3357 /* Section flags for .debug_str section. */
3358 #define DEBUG_STR_SECTION_FLAGS \
3359 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3360 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3363 /* Section flags for .debug_str.dwo section. */
3364 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3366 /* Labels we insert at beginning sections we can reference instead of
3367 the section names themselves. */
3369 #ifndef TEXT_SECTION_LABEL
3370 #define TEXT_SECTION_LABEL "Ltext"
3372 #ifndef COLD_TEXT_SECTION_LABEL
3373 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3375 #ifndef DEBUG_LINE_SECTION_LABEL
3376 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3378 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3379 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3381 #ifndef DEBUG_INFO_SECTION_LABEL
3382 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3384 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3385 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3387 #ifndef DEBUG_ABBREV_SECTION_LABEL
3388 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3390 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3391 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3393 #ifndef DEBUG_ADDR_SECTION_LABEL
3394 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3396 #ifndef DEBUG_LOC_SECTION_LABEL
3397 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3399 #ifndef DEBUG_RANGES_SECTION_LABEL
3400 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3402 #ifndef DEBUG_MACINFO_SECTION_LABEL
3403 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3405 #ifndef DEBUG_MACRO_SECTION_LABEL
3406 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3408 #define SKELETON_COMP_DIE_ABBREV 1
3409 #define SKELETON_TYPE_DIE_ABBREV 2
3411 /* Definitions of defaults for formats and names of various special
3412 (artificial) labels which may be generated within this file (when the -g
3413 options is used and DWARF2_DEBUGGING_INFO is in effect.
3414 If necessary, these may be overridden from within the tm.h file, but
3415 typically, overriding these defaults is unnecessary. */
3417 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3418 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3419 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3420 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3421 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3422 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3423 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3424 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3425 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3426 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3427 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3428 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3429 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3430 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3432 #ifndef TEXT_END_LABEL
3433 #define TEXT_END_LABEL "Letext"
3435 #ifndef COLD_END_LABEL
3436 #define COLD_END_LABEL "Letext_cold"
3438 #ifndef BLOCK_BEGIN_LABEL
3439 #define BLOCK_BEGIN_LABEL "LBB"
3441 #ifndef BLOCK_END_LABEL
3442 #define BLOCK_END_LABEL "LBE"
3444 #ifndef LINE_CODE_LABEL
3445 #define LINE_CODE_LABEL "LM"
3449 /* Return the root of the DIE's built for the current compilation unit. */
3451 comp_unit_die (void)
3453 if (!single_comp_unit_die
)
3454 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3455 return single_comp_unit_die
;
3458 /* We allow a language front-end to designate a function that is to be
3459 called to "demangle" any name before it is put into a DIE. */
3461 static const char *(*demangle_name_func
) (const char *);
3464 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3466 demangle_name_func
= func
;
3469 /* Test if rtl node points to a pseudo register. */
3472 is_pseudo_reg (const_rtx rtl
)
3474 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3475 || (GET_CODE (rtl
) == SUBREG
3476 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3479 /* Return a reference to a type, with its const and volatile qualifiers
3483 type_main_variant (tree type
)
3485 type
= TYPE_MAIN_VARIANT (type
);
3487 /* ??? There really should be only one main variant among any group of
3488 variants of a given type (and all of the MAIN_VARIANT values for all
3489 members of the group should point to that one type) but sometimes the C
3490 front-end messes this up for array types, so we work around that bug
3492 if (TREE_CODE (type
) == ARRAY_TYPE
)
3493 while (type
!= TYPE_MAIN_VARIANT (type
))
3494 type
= TYPE_MAIN_VARIANT (type
);
3499 /* Return nonzero if the given type node represents a tagged type. */
3502 is_tagged_type (const_tree type
)
3504 enum tree_code code
= TREE_CODE (type
);
3506 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3507 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3510 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3513 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3515 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3518 /* Return die_offset of a DIE reference to a base type. */
3520 static unsigned long int
3521 get_base_type_offset (dw_die_ref ref
)
3523 if (ref
->die_offset
)
3524 return ref
->die_offset
;
3525 if (comp_unit_die ()->die_abbrev
)
3527 calc_base_type_die_sizes ();
3528 gcc_assert (ref
->die_offset
);
3530 return ref
->die_offset
;
3533 /* Return die_offset of a DIE reference other than base type. */
3535 static unsigned long int
3536 get_ref_die_offset (dw_die_ref ref
)
3538 gcc_assert (ref
->die_offset
);
3539 return ref
->die_offset
;
3542 /* Convert a DIE tag into its string name. */
3545 dwarf_tag_name (unsigned int tag
)
3547 const char *name
= get_DW_TAG_name (tag
);
3552 return "DW_TAG_<unknown>";
3555 /* Convert a DWARF attribute code into its string name. */
3558 dwarf_attr_name (unsigned int attr
)
3564 #if VMS_DEBUGGING_INFO
3565 case DW_AT_HP_prologue
:
3566 return "DW_AT_HP_prologue";
3568 case DW_AT_MIPS_loop_unroll_factor
:
3569 return "DW_AT_MIPS_loop_unroll_factor";
3572 #if VMS_DEBUGGING_INFO
3573 case DW_AT_HP_epilogue
:
3574 return "DW_AT_HP_epilogue";
3576 case DW_AT_MIPS_stride
:
3577 return "DW_AT_MIPS_stride";
3581 name
= get_DW_AT_name (attr
);
3586 return "DW_AT_<unknown>";
3589 /* Convert a DWARF value form code into its string name. */
3592 dwarf_form_name (unsigned int form
)
3594 const char *name
= get_DW_FORM_name (form
);
3599 return "DW_FORM_<unknown>";
3602 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3603 instance of an inlined instance of a decl which is local to an inline
3604 function, so we have to trace all of the way back through the origin chain
3605 to find out what sort of node actually served as the original seed for the
3609 decl_ultimate_origin (const_tree decl
)
3611 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3614 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3615 nodes in the function to point to themselves; ignore that if
3616 we're trying to output the abstract instance of this function. */
3617 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3620 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3621 most distant ancestor, this should never happen. */
3622 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3624 return DECL_ABSTRACT_ORIGIN (decl
);
3627 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3628 of a virtual function may refer to a base class, so we check the 'this'
3632 decl_class_context (tree decl
)
3634 tree context
= NULL_TREE
;
3636 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3637 context
= DECL_CONTEXT (decl
);
3639 context
= TYPE_MAIN_VARIANT
3640 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3642 if (context
&& !TYPE_P (context
))
3643 context
= NULL_TREE
;
3648 /* Add an attribute/value pair to a DIE. */
3651 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3653 /* Maybe this should be an assert? */
3657 vec_safe_reserve (die
->die_attr
, 1);
3658 vec_safe_push (die
->die_attr
, *attr
);
3661 static inline enum dw_val_class
3662 AT_class (dw_attr_ref a
)
3664 return a
->dw_attr_val
.val_class
;
3667 /* Return the index for any attribute that will be referenced with a
3668 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3669 are stored in dw_attr_val.v.val_str for reference counting
3672 static inline unsigned int
3673 AT_index (dw_attr_ref a
)
3675 if (AT_class (a
) == dw_val_class_str
)
3676 return a
->dw_attr_val
.v
.val_str
->index
;
3677 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3678 return a
->dw_attr_val
.val_entry
->index
;
3682 /* Add a flag value attribute to a DIE. */
3685 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3689 attr
.dw_attr
= attr_kind
;
3690 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3691 attr
.dw_attr_val
.val_entry
= NULL
;
3692 attr
.dw_attr_val
.v
.val_flag
= flag
;
3693 add_dwarf_attr (die
, &attr
);
3696 static inline unsigned
3697 AT_flag (dw_attr_ref a
)
3699 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3700 return a
->dw_attr_val
.v
.val_flag
;
3703 /* Add a signed integer attribute value to a DIE. */
3706 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3710 attr
.dw_attr
= attr_kind
;
3711 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3712 attr
.dw_attr_val
.val_entry
= NULL
;
3713 attr
.dw_attr_val
.v
.val_int
= int_val
;
3714 add_dwarf_attr (die
, &attr
);
3717 static inline HOST_WIDE_INT
3718 AT_int (dw_attr_ref a
)
3720 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3721 return a
->dw_attr_val
.v
.val_int
;
3724 /* Add an unsigned integer attribute value to a DIE. */
3727 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3728 unsigned HOST_WIDE_INT unsigned_val
)
3732 attr
.dw_attr
= attr_kind
;
3733 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3734 attr
.dw_attr_val
.val_entry
= NULL
;
3735 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3736 add_dwarf_attr (die
, &attr
);
3739 static inline unsigned HOST_WIDE_INT
3740 AT_unsigned (dw_attr_ref a
)
3742 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3743 return a
->dw_attr_val
.v
.val_unsigned
;
3746 /* Add an unsigned double integer attribute value to a DIE. */
3749 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3750 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3754 attr
.dw_attr
= attr_kind
;
3755 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3756 attr
.dw_attr_val
.val_entry
= NULL
;
3757 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3758 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3759 add_dwarf_attr (die
, &attr
);
3762 /* Add a floating point attribute value to a DIE and return it. */
3765 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3766 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3770 attr
.dw_attr
= attr_kind
;
3771 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3772 attr
.dw_attr_val
.val_entry
= NULL
;
3773 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3774 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3775 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3776 add_dwarf_attr (die
, &attr
);
3779 /* Add an 8-byte data attribute value to a DIE. */
3782 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3783 unsigned char data8
[8])
3787 attr
.dw_attr
= attr_kind
;
3788 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3789 attr
.dw_attr_val
.val_entry
= NULL
;
3790 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3791 add_dwarf_attr (die
, &attr
);
3794 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3795 dwarf_split_debug_info, address attributes in dies destined for the
3796 final executable have force_direct set to avoid using indexed
3800 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3806 lbl_id
= xstrdup (lbl_low
);
3807 attr
.dw_attr
= DW_AT_low_pc
;
3808 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3809 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3810 if (dwarf_split_debug_info
&& !force_direct
)
3811 attr
.dw_attr_val
.val_entry
3812 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3814 attr
.dw_attr_val
.val_entry
= NULL
;
3815 add_dwarf_attr (die
, &attr
);
3817 attr
.dw_attr
= DW_AT_high_pc
;
3818 if (dwarf_version
< 4)
3819 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3821 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3822 lbl_id
= xstrdup (lbl_high
);
3823 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3824 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3825 && dwarf_split_debug_info
&& !force_direct
)
3826 attr
.dw_attr_val
.val_entry
3827 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3829 attr
.dw_attr_val
.val_entry
= NULL
;
3830 add_dwarf_attr (die
, &attr
);
3833 /* Hash and equality functions for debug_str_hash. */
3836 debug_str_do_hash (const void *x
)
3838 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3842 debug_str_eq (const void *x1
, const void *x2
)
3844 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3845 (const char *)x2
) == 0;
3848 /* Add STR to the given string hash table. */
3850 static struct indirect_string_node
*
3851 find_AT_string_in_table (const char *str
, htab_t table
)
3853 struct indirect_string_node
*node
;
3856 slot
= htab_find_slot_with_hash (table
, str
,
3857 htab_hash_string (str
), INSERT
);
3860 node
= ggc_alloc_cleared_indirect_string_node ();
3861 node
->str
= ggc_strdup (str
);
3865 node
= (struct indirect_string_node
*) *slot
;
3871 /* Add STR to the indirect string hash table. */
3873 static struct indirect_string_node
*
3874 find_AT_string (const char *str
)
3876 if (! debug_str_hash
)
3877 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3878 debug_str_eq
, NULL
);
3880 return find_AT_string_in_table (str
, debug_str_hash
);
3883 /* Add a string attribute value to a DIE. */
3886 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3889 struct indirect_string_node
*node
;
3891 node
= find_AT_string (str
);
3893 attr
.dw_attr
= attr_kind
;
3894 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3895 attr
.dw_attr_val
.val_entry
= NULL
;
3896 attr
.dw_attr_val
.v
.val_str
= node
;
3897 add_dwarf_attr (die
, &attr
);
3900 static inline const char *
3901 AT_string (dw_attr_ref a
)
3903 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3904 return a
->dw_attr_val
.v
.val_str
->str
;
3907 /* Call this function directly to bypass AT_string_form's logic to put
3908 the string inline in the die. */
3911 set_indirect_string (struct indirect_string_node
*node
)
3914 /* Already indirect is a no op. */
3915 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3917 gcc_assert (node
->label
);
3920 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3921 ++dw2_string_counter
;
3922 node
->label
= xstrdup (label
);
3924 if (!dwarf_split_debug_info
)
3926 node
->form
= DW_FORM_strp
;
3927 node
->index
= NOT_INDEXED
;
3931 node
->form
= DW_FORM_GNU_str_index
;
3932 node
->index
= NO_INDEX_ASSIGNED
;
3936 /* Find out whether a string should be output inline in DIE
3937 or out-of-line in .debug_str section. */
3939 static enum dwarf_form
3940 find_string_form (struct indirect_string_node
*node
)
3947 len
= strlen (node
->str
) + 1;
3949 /* If the string is shorter or equal to the size of the reference, it is
3950 always better to put it inline. */
3951 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3952 return node
->form
= DW_FORM_string
;
3954 /* If we cannot expect the linker to merge strings in .debug_str
3955 section, only put it into .debug_str if it is worth even in this
3957 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3958 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3959 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3960 return node
->form
= DW_FORM_string
;
3962 set_indirect_string (node
);
3967 /* Find out whether the string referenced from the attribute should be
3968 output inline in DIE or out-of-line in .debug_str section. */
3970 static enum dwarf_form
3971 AT_string_form (dw_attr_ref a
)
3973 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3974 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3977 /* Add a DIE reference attribute value to a DIE. */
3980 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3984 #ifdef ENABLE_CHECKING
3985 gcc_assert (targ_die
!= NULL
);
3987 /* With LTO we can end up trying to reference something we didn't create
3988 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3989 if (targ_die
== NULL
)
3993 attr
.dw_attr
= attr_kind
;
3994 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3995 attr
.dw_attr_val
.val_entry
= NULL
;
3996 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3997 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3998 add_dwarf_attr (die
, &attr
);
4001 /* Change DIE reference REF to point to NEW_DIE instead. */
4004 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4006 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4007 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4008 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4011 /* Add an AT_specification attribute to a DIE, and also make the back
4012 pointer from the specification to the definition. */
4015 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4017 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4018 gcc_assert (!targ_die
->die_definition
);
4019 targ_die
->die_definition
= die
;
4022 static inline dw_die_ref
4023 AT_ref (dw_attr_ref a
)
4025 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4026 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4030 AT_ref_external (dw_attr_ref a
)
4032 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4033 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4039 set_AT_ref_external (dw_attr_ref a
, int i
)
4041 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4042 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4045 /* Add an FDE reference attribute value to a DIE. */
4048 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4052 attr
.dw_attr
= attr_kind
;
4053 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4054 attr
.dw_attr_val
.val_entry
= NULL
;
4055 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4056 add_dwarf_attr (die
, &attr
);
4059 /* Add a location description attribute value to a DIE. */
4062 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4066 attr
.dw_attr
= attr_kind
;
4067 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4068 attr
.dw_attr_val
.val_entry
= NULL
;
4069 attr
.dw_attr_val
.v
.val_loc
= loc
;
4070 add_dwarf_attr (die
, &attr
);
4073 static inline dw_loc_descr_ref
4074 AT_loc (dw_attr_ref a
)
4076 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4077 return a
->dw_attr_val
.v
.val_loc
;
4081 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4085 attr
.dw_attr
= attr_kind
;
4086 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4087 attr
.dw_attr_val
.val_entry
= NULL
;
4088 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4089 add_dwarf_attr (die
, &attr
);
4090 have_location_lists
= true;
4093 static inline dw_loc_list_ref
4094 AT_loc_list (dw_attr_ref a
)
4096 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4097 return a
->dw_attr_val
.v
.val_loc_list
;
4100 static inline dw_loc_list_ref
*
4101 AT_loc_list_ptr (dw_attr_ref a
)
4103 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4104 return &a
->dw_attr_val
.v
.val_loc_list
;
4107 /* Table of entries into the .debug_addr section. */
4109 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4111 /* Hash an address_table_entry. */
4114 addr_table_entry_do_hash (const void *x
)
4116 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4120 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4121 case ate_kind_rtx_dtprel
:
4122 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4123 case ate_kind_label
:
4124 return htab_hash_string (a
->addr
.label
);
4130 /* Determine equality for two address_table_entries. */
4133 addr_table_entry_eq (const void *x1
, const void *x2
)
4135 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4136 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4138 if (a1
->kind
!= a2
->kind
)
4143 case ate_kind_rtx_dtprel
:
4144 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4145 case ate_kind_label
:
4146 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4152 /* Initialize an addr_table_entry. */
4155 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4161 case ate_kind_rtx_dtprel
:
4162 e
->addr
.rtl
= (rtx
) addr
;
4164 case ate_kind_label
:
4165 e
->addr
.label
= (char *) addr
;
4169 e
->index
= NO_INDEX_ASSIGNED
;
4172 /* Add attr to the address table entry to the table. Defer setting an
4173 index until output time. */
4175 static addr_table_entry
*
4176 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4178 addr_table_entry
*node
;
4179 addr_table_entry finder
;
4182 gcc_assert (dwarf_split_debug_info
);
4183 if (! addr_index_table
)
4184 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4185 addr_table_entry_eq
, NULL
);
4186 init_addr_table_entry (&finder
, kind
, addr
);
4187 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4189 if (*slot
== HTAB_EMPTY_ENTRY
)
4191 node
= ggc_alloc_cleared_addr_table_entry ();
4192 init_addr_table_entry (node
, kind
, addr
);
4196 node
= (addr_table_entry
*) *slot
;
4202 /* Remove an entry from the addr table by decrementing its refcount.
4203 Strictly, decrementing the refcount would be enough, but the
4204 assertion that the entry is actually in the table has found
4208 remove_addr_table_entry (addr_table_entry
*entry
)
4210 addr_table_entry
*node
;
4212 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4213 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4214 /* After an index is assigned, the table is frozen. */
4215 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4219 /* Given a location list, remove all addresses it refers to from the
4223 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4225 for (; descr
; descr
= descr
->dw_loc_next
)
4226 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4228 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4229 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4233 /* A helper function for dwarf2out_finish called through
4234 htab_traverse. Assign an addr_table_entry its index. All entries
4235 must be collected into the table when this function is called,
4236 because the indexing code relies on htab_traverse to traverse nodes
4237 in the same order for each run. */
4240 index_addr_table_entry (void **h
, void *v
)
4242 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4243 unsigned int *index
= (unsigned int *) v
;
4245 /* Don't index unreferenced nodes. */
4246 if (node
->refcount
== 0)
4249 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4250 node
->index
= *index
;
4256 /* Add an address constant attribute value to a DIE. When using
4257 dwarf_split_debug_info, address attributes in dies destined for the
4258 final executable should be direct references--setting the parameter
4259 force_direct ensures this behavior. */
4262 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4267 attr
.dw_attr
= attr_kind
;
4268 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4269 attr
.dw_attr_val
.v
.val_addr
= addr
;
4270 if (dwarf_split_debug_info
&& !force_direct
)
4271 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4273 attr
.dw_attr_val
.val_entry
= NULL
;
4274 add_dwarf_attr (die
, &attr
);
4277 /* Get the RTX from to an address DIE attribute. */
4280 AT_addr (dw_attr_ref a
)
4282 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4283 return a
->dw_attr_val
.v
.val_addr
;
4286 /* Add a file attribute value to a DIE. */
4289 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4290 struct dwarf_file_data
*fd
)
4294 attr
.dw_attr
= attr_kind
;
4295 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4296 attr
.dw_attr_val
.val_entry
= NULL
;
4297 attr
.dw_attr_val
.v
.val_file
= fd
;
4298 add_dwarf_attr (die
, &attr
);
4301 /* Get the dwarf_file_data from a file DIE attribute. */
4303 static inline struct dwarf_file_data
*
4304 AT_file (dw_attr_ref a
)
4306 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4307 return a
->dw_attr_val
.v
.val_file
;
4310 /* Add a vms delta attribute value to a DIE. */
4313 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4314 const char *lbl1
, const char *lbl2
)
4318 attr
.dw_attr
= attr_kind
;
4319 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4320 attr
.dw_attr_val
.val_entry
= NULL
;
4321 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4322 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4323 add_dwarf_attr (die
, &attr
);
4326 /* Add a label identifier attribute value to a DIE. */
4329 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4334 attr
.dw_attr
= attr_kind
;
4335 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4336 attr
.dw_attr_val
.val_entry
= NULL
;
4337 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4338 if (dwarf_split_debug_info
)
4339 attr
.dw_attr_val
.val_entry
4340 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4342 add_dwarf_attr (die
, &attr
);
4345 /* Add a section offset attribute value to a DIE, an offset into the
4346 debug_line section. */
4349 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4354 attr
.dw_attr
= attr_kind
;
4355 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4356 attr
.dw_attr_val
.val_entry
= NULL
;
4357 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4358 add_dwarf_attr (die
, &attr
);
4361 /* Add a section offset attribute value to a DIE, an offset into the
4362 debug_macinfo section. */
4365 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4370 attr
.dw_attr
= attr_kind
;
4371 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4372 attr
.dw_attr_val
.val_entry
= NULL
;
4373 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4374 add_dwarf_attr (die
, &attr
);
4377 /* Add an offset attribute value to a DIE. */
4380 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4381 unsigned HOST_WIDE_INT offset
)
4385 attr
.dw_attr
= attr_kind
;
4386 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4387 attr
.dw_attr_val
.val_entry
= NULL
;
4388 attr
.dw_attr_val
.v
.val_offset
= offset
;
4389 add_dwarf_attr (die
, &attr
);
4392 /* Add a range_list attribute value to a DIE. When using
4393 dwarf_split_debug_info, address attributes in dies destined for the
4394 final executable should be direct references--setting the parameter
4395 force_direct ensures this behavior. */
4397 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4398 #define RELOCATED_OFFSET (NULL)
4401 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4402 long unsigned int offset
, bool force_direct
)
4406 attr
.dw_attr
= attr_kind
;
4407 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4408 /* For the range_list attribute, use val_entry to store whether the
4409 offset should follow split-debug-info or normal semantics. This
4410 value is read in output_range_list_offset. */
4411 if (dwarf_split_debug_info
&& !force_direct
)
4412 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4414 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4415 attr
.dw_attr_val
.v
.val_offset
= offset
;
4416 add_dwarf_attr (die
, &attr
);
4419 /* Return the start label of a delta attribute. */
4421 static inline const char *
4422 AT_vms_delta1 (dw_attr_ref a
)
4424 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4425 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4428 /* Return the end label of a delta attribute. */
4430 static inline const char *
4431 AT_vms_delta2 (dw_attr_ref a
)
4433 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4434 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4437 static inline const char *
4438 AT_lbl (dw_attr_ref a
)
4440 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4441 || AT_class (a
) == dw_val_class_lineptr
4442 || AT_class (a
) == dw_val_class_macptr
4443 || AT_class (a
) == dw_val_class_high_pc
));
4444 return a
->dw_attr_val
.v
.val_lbl_id
;
4447 /* Get the attribute of type attr_kind. */
4450 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4454 dw_die_ref spec
= NULL
;
4459 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4460 if (a
->dw_attr
== attr_kind
)
4462 else if (a
->dw_attr
== DW_AT_specification
4463 || a
->dw_attr
== DW_AT_abstract_origin
)
4467 return get_AT (spec
, attr_kind
);
4472 /* Returns the parent of the declaration of DIE. */
4475 get_die_parent (dw_die_ref die
)
4482 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4483 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4486 return die
->die_parent
;
4489 /* Return the "low pc" attribute value, typically associated with a subprogram
4490 DIE. Return null if the "low pc" attribute is either not present, or if it
4491 cannot be represented as an assembler label identifier. */
4493 static inline const char *
4494 get_AT_low_pc (dw_die_ref die
)
4496 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4498 return a
? AT_lbl (a
) : NULL
;
4501 /* Return the "high pc" attribute value, typically associated with a subprogram
4502 DIE. Return null if the "high pc" attribute is either not present, or if it
4503 cannot be represented as an assembler label identifier. */
4505 static inline const char *
4506 get_AT_hi_pc (dw_die_ref die
)
4508 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4510 return a
? AT_lbl (a
) : NULL
;
4513 /* Return the value of the string attribute designated by ATTR_KIND, or
4514 NULL if it is not present. */
4516 static inline const char *
4517 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4519 dw_attr_ref a
= get_AT (die
, attr_kind
);
4521 return a
? AT_string (a
) : NULL
;
4524 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4525 if it is not present. */
4528 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4530 dw_attr_ref a
= get_AT (die
, attr_kind
);
4532 return a
? AT_flag (a
) : 0;
4535 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4536 if it is not present. */
4538 static inline unsigned
4539 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4541 dw_attr_ref a
= get_AT (die
, attr_kind
);
4543 return a
? AT_unsigned (a
) : 0;
4546 static inline dw_die_ref
4547 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4549 dw_attr_ref a
= get_AT (die
, attr_kind
);
4551 return a
? AT_ref (a
) : NULL
;
4554 static inline struct dwarf_file_data
*
4555 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4557 dw_attr_ref a
= get_AT (die
, attr_kind
);
4559 return a
? AT_file (a
) : NULL
;
4562 /* Return TRUE if the language is C++. */
4567 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4569 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4572 /* Return TRUE if the language is Fortran. */
4577 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4579 return (lang
== DW_LANG_Fortran77
4580 || lang
== DW_LANG_Fortran90
4581 || lang
== DW_LANG_Fortran95
);
4584 /* Return TRUE if the language is Ada. */
4589 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4591 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4594 /* Remove the specified attribute if present. */
4597 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4605 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4606 if (a
->dw_attr
== attr_kind
)
4608 if (AT_class (a
) == dw_val_class_str
)
4609 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4610 a
->dw_attr_val
.v
.val_str
->refcount
--;
4612 /* vec::ordered_remove should help reduce the number of abbrevs
4614 die
->die_attr
->ordered_remove (ix
);
4619 /* Remove CHILD from its parent. PREV must have the property that
4620 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4623 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4625 gcc_assert (child
->die_parent
== prev
->die_parent
);
4626 gcc_assert (prev
->die_sib
== child
);
4629 gcc_assert (child
->die_parent
->die_child
== child
);
4633 prev
->die_sib
= child
->die_sib
;
4634 if (child
->die_parent
->die_child
== child
)
4635 child
->die_parent
->die_child
= prev
;
4638 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4639 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4642 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4644 dw_die_ref parent
= old_child
->die_parent
;
4646 gcc_assert (parent
== prev
->die_parent
);
4647 gcc_assert (prev
->die_sib
== old_child
);
4649 new_child
->die_parent
= parent
;
4650 if (prev
== old_child
)
4652 gcc_assert (parent
->die_child
== old_child
);
4653 new_child
->die_sib
= new_child
;
4657 prev
->die_sib
= new_child
;
4658 new_child
->die_sib
= old_child
->die_sib
;
4660 if (old_child
->die_parent
->die_child
== old_child
)
4661 old_child
->die_parent
->die_child
= new_child
;
4664 /* Move all children from OLD_PARENT to NEW_PARENT. */
4667 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4670 new_parent
->die_child
= old_parent
->die_child
;
4671 old_parent
->die_child
= NULL
;
4672 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4675 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4679 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4685 dw_die_ref prev
= c
;
4687 while (c
->die_tag
== tag
)
4689 remove_child_with_prev (c
, prev
);
4690 /* Might have removed every child. */
4691 if (c
== c
->die_sib
)
4695 } while (c
!= die
->die_child
);
4698 /* Add a CHILD_DIE as the last child of DIE. */
4701 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4703 /* FIXME this should probably be an assert. */
4704 if (! die
|| ! child_die
)
4706 gcc_assert (die
!= child_die
);
4708 child_die
->die_parent
= die
;
4711 child_die
->die_sib
= die
->die_child
->die_sib
;
4712 die
->die_child
->die_sib
= child_die
;
4715 child_die
->die_sib
= child_die
;
4716 die
->die_child
= child_die
;
4719 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4720 is the specification, to the end of PARENT's list of children.
4721 This is done by removing and re-adding it. */
4724 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4728 /* We want the declaration DIE from inside the class, not the
4729 specification DIE at toplevel. */
4730 if (child
->die_parent
!= parent
)
4732 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4738 gcc_assert (child
->die_parent
== parent
4739 || (child
->die_parent
4740 == get_AT_ref (parent
, DW_AT_specification
)));
4742 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4743 if (p
->die_sib
== child
)
4745 remove_child_with_prev (child
, p
);
4749 add_child_die (parent
, child
);
4752 /* Return a pointer to a newly created DIE node. */
4754 static inline dw_die_ref
4755 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4757 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4759 die
->die_tag
= tag_value
;
4761 if (parent_die
!= NULL
)
4762 add_child_die (parent_die
, die
);
4765 limbo_die_node
*limbo_node
;
4767 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4768 limbo_node
->die
= die
;
4769 limbo_node
->created_for
= t
;
4770 limbo_node
->next
= limbo_die_list
;
4771 limbo_die_list
= limbo_node
;
4777 /* Return the DIE associated with the given type specifier. */
4779 static inline dw_die_ref
4780 lookup_type_die (tree type
)
4782 return TYPE_SYMTAB_DIE (type
);
4785 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4786 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4787 anonymous type instead the one of the naming typedef. */
4789 static inline dw_die_ref
4790 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4793 && TREE_CODE (type
) == RECORD_TYPE
4795 && type_die
->die_tag
== DW_TAG_typedef
4796 && is_naming_typedef_decl (TYPE_NAME (type
)))
4797 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4801 /* Like lookup_type_die, but if type is an anonymous type named by a
4802 typedef[1], return the DIE of the anonymous type instead the one of
4803 the naming typedef. This is because in gen_typedef_die, we did
4804 equate the anonymous struct named by the typedef with the DIE of
4805 the naming typedef. So by default, lookup_type_die on an anonymous
4806 struct yields the DIE of the naming typedef.
4808 [1]: Read the comment of is_naming_typedef_decl to learn about what
4809 a naming typedef is. */
4811 static inline dw_die_ref
4812 lookup_type_die_strip_naming_typedef (tree type
)
4814 dw_die_ref die
= lookup_type_die (type
);
4815 return strip_naming_typedef (type
, die
);
4818 /* Equate a DIE to a given type specifier. */
4821 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4823 TYPE_SYMTAB_DIE (type
) = type_die
;
4826 /* Returns a hash value for X (which really is a die_struct). */
4829 decl_die_table_hash (const void *x
)
4831 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4834 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4837 decl_die_table_eq (const void *x
, const void *y
)
4839 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4842 /* Return the DIE associated with a given declaration. */
4844 static inline dw_die_ref
4845 lookup_decl_die (tree decl
)
4847 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4850 /* Returns a hash value for X (which really is a var_loc_list). */
4853 decl_loc_table_hash (const void *x
)
4855 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4858 /* Return nonzero if decl_id of var_loc_list X is the same as
4862 decl_loc_table_eq (const void *x
, const void *y
)
4864 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4867 /* Return the var_loc list associated with a given declaration. */
4869 static inline var_loc_list
*
4870 lookup_decl_loc (const_tree decl
)
4872 if (!decl_loc_table
)
4874 return (var_loc_list
*)
4875 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4878 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4881 cached_dw_loc_list_table_hash (const void *x
)
4883 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4886 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4890 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4892 return (((const cached_dw_loc_list
*) x
)->decl_id
4893 == DECL_UID ((const_tree
) y
));
4896 /* Equate a DIE to a particular declaration. */
4899 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4901 unsigned int decl_id
= DECL_UID (decl
);
4904 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4906 decl_die
->decl_id
= decl_id
;
4909 /* Return how many bits covers PIECE EXPR_LIST. */
4912 decl_piece_bitsize (rtx piece
)
4914 int ret
= (int) GET_MODE (piece
);
4917 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4918 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4919 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4922 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4925 decl_piece_varloc_ptr (rtx piece
)
4927 if ((int) GET_MODE (piece
))
4928 return &XEXP (piece
, 0);
4930 return &XEXP (XEXP (piece
, 0), 1);
4933 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4934 Next is the chain of following piece nodes. */
4937 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4939 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4940 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4942 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4947 /* Return rtx that should be stored into loc field for
4948 LOC_NOTE and BITPOS/BITSIZE. */
4951 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4952 HOST_WIDE_INT bitsize
)
4956 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4958 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4963 /* This function either modifies location piece list *DEST in
4964 place (if SRC and INNER is NULL), or copies location piece list
4965 *SRC to *DEST while modifying it. Location BITPOS is modified
4966 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4967 not copied and if needed some padding around it is added.
4968 When modifying in place, DEST should point to EXPR_LIST where
4969 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4970 to the start of the whole list and INNER points to the EXPR_LIST
4971 where earlier pieces cover PIECE_BITPOS bits. */
4974 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4975 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4976 HOST_WIDE_INT bitsize
, rtx loc_note
)
4979 bool copy
= inner
!= NULL
;
4983 /* First copy all nodes preceding the current bitpos. */
4984 while (src
!= inner
)
4986 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4987 decl_piece_bitsize (*src
), NULL_RTX
);
4988 dest
= &XEXP (*dest
, 1);
4989 src
= &XEXP (*src
, 1);
4992 /* Add padding if needed. */
4993 if (bitpos
!= piece_bitpos
)
4995 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4996 copy
? NULL_RTX
: *dest
);
4997 dest
= &XEXP (*dest
, 1);
4999 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5002 /* A piece with correct bitpos and bitsize already exist,
5003 just update the location for it and return. */
5004 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5007 /* Add the piece that changed. */
5008 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5009 dest
= &XEXP (*dest
, 1);
5010 /* Skip over pieces that overlap it. */
5011 diff
= bitpos
- piece_bitpos
+ bitsize
;
5014 while (diff
> 0 && *src
)
5017 diff
-= decl_piece_bitsize (piece
);
5019 src
= &XEXP (piece
, 1);
5022 *src
= XEXP (piece
, 1);
5023 free_EXPR_LIST_node (piece
);
5026 /* Add padding if needed. */
5027 if (diff
< 0 && *src
)
5031 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5032 dest
= &XEXP (*dest
, 1);
5036 /* Finally copy all nodes following it. */
5039 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5040 decl_piece_bitsize (*src
), NULL_RTX
);
5041 dest
= &XEXP (*dest
, 1);
5042 src
= &XEXP (*src
, 1);
5046 /* Add a variable location node to the linked list for DECL. */
5048 static struct var_loc_node
*
5049 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5051 unsigned int decl_id
;
5054 struct var_loc_node
*loc
= NULL
;
5055 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5057 if (TREE_CODE (decl
) == VAR_DECL
5058 && DECL_HAS_DEBUG_EXPR_P (decl
))
5060 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5061 if (handled_component_p (realdecl
)
5062 || (TREE_CODE (realdecl
) == MEM_REF
5063 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5065 HOST_WIDE_INT maxsize
;
5068 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5069 if (!DECL_P (innerdecl
)
5070 || DECL_IGNORED_P (innerdecl
)
5071 || TREE_STATIC (innerdecl
)
5073 || bitpos
+ bitsize
> 256
5074 || bitsize
!= maxsize
)
5080 decl_id
= DECL_UID (decl
);
5081 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5084 temp
= ggc_alloc_cleared_var_loc_list ();
5085 temp
->decl_id
= decl_id
;
5089 temp
= (var_loc_list
*) *slot
;
5091 /* For PARM_DECLs try to keep around the original incoming value,
5092 even if that means we'll emit a zero-range .debug_loc entry. */
5094 && temp
->first
== temp
->last
5095 && TREE_CODE (decl
) == PARM_DECL
5096 && NOTE_P (temp
->first
->loc
)
5097 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5098 && DECL_INCOMING_RTL (decl
)
5099 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5100 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5101 == GET_CODE (DECL_INCOMING_RTL (decl
))
5102 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5104 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5105 NOTE_VAR_LOCATION_LOC (loc_note
))
5106 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5107 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5109 loc
= ggc_alloc_cleared_var_loc_node ();
5110 temp
->first
->next
= loc
;
5112 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5114 else if (temp
->last
)
5116 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5117 rtx
*piece_loc
= NULL
, last_loc_note
;
5118 int piece_bitpos
= 0;
5122 gcc_assert (last
->next
== NULL
);
5124 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5126 piece_loc
= &last
->loc
;
5129 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5130 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5132 piece_bitpos
+= cur_bitsize
;
5133 piece_loc
= &XEXP (*piece_loc
, 1);
5137 /* TEMP->LAST here is either pointer to the last but one or
5138 last element in the chained list, LAST is pointer to the
5140 if (label
&& strcmp (last
->label
, label
) == 0)
5142 /* For SRA optimized variables if there weren't any real
5143 insns since last note, just modify the last node. */
5144 if (piece_loc
!= NULL
)
5146 adjust_piece_list (piece_loc
, NULL
, NULL
,
5147 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5150 /* If the last note doesn't cover any instructions, remove it. */
5151 if (temp
->last
!= last
)
5153 temp
->last
->next
= NULL
;
5156 gcc_assert (strcmp (last
->label
, label
) != 0);
5160 gcc_assert (temp
->first
== temp
->last
5161 || (temp
->first
->next
== temp
->last
5162 && TREE_CODE (decl
) == PARM_DECL
));
5163 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5164 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5168 if (bitsize
== -1 && NOTE_P (last
->loc
))
5169 last_loc_note
= last
->loc
;
5170 else if (piece_loc
!= NULL
5171 && *piece_loc
!= NULL_RTX
5172 && piece_bitpos
== bitpos
5173 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5174 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5176 last_loc_note
= NULL_RTX
;
5177 /* If the current location is the same as the end of the list,
5178 and either both or neither of the locations is uninitialized,
5179 we have nothing to do. */
5180 if (last_loc_note
== NULL_RTX
5181 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5182 NOTE_VAR_LOCATION_LOC (loc_note
)))
5183 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5184 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5185 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5186 == VAR_INIT_STATUS_UNINITIALIZED
)
5187 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5188 == VAR_INIT_STATUS_UNINITIALIZED
))))
5190 /* Add LOC to the end of list and update LAST. If the last
5191 element of the list has been removed above, reuse its
5192 memory for the new node, otherwise allocate a new one. */
5196 memset (loc
, '\0', sizeof (*loc
));
5199 loc
= ggc_alloc_cleared_var_loc_node ();
5200 if (bitsize
== -1 || piece_loc
== NULL
)
5201 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5203 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5204 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5206 /* Ensure TEMP->LAST will point either to the new last but one
5207 element of the chain, or to the last element in it. */
5208 if (last
!= temp
->last
)
5216 loc
= ggc_alloc_cleared_var_loc_node ();
5219 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5224 /* Keep track of the number of spaces used to indent the
5225 output of the debugging routines that print the structure of
5226 the DIE internal representation. */
5227 static int print_indent
;
5229 /* Indent the line the number of spaces given by print_indent. */
5232 print_spaces (FILE *outfile
)
5234 fprintf (outfile
, "%*s", print_indent
, "");
5237 /* Print a type signature in hex. */
5240 print_signature (FILE *outfile
, char *sig
)
5244 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5245 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5248 /* Print the information associated with a given DIE, and its children.
5249 This routine is a debugging aid only. */
5252 print_die (dw_die_ref die
, FILE *outfile
)
5258 print_spaces (outfile
);
5259 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5260 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5262 print_spaces (outfile
);
5263 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5264 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5265 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5267 if (die
->comdat_type_p
)
5269 print_spaces (outfile
);
5270 fprintf (outfile
, " signature: ");
5271 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5272 fprintf (outfile
, "\n");
5275 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5277 print_spaces (outfile
);
5278 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5280 switch (AT_class (a
))
5282 case dw_val_class_addr
:
5283 fprintf (outfile
, "address");
5285 case dw_val_class_offset
:
5286 fprintf (outfile
, "offset");
5288 case dw_val_class_loc
:
5289 fprintf (outfile
, "location descriptor");
5291 case dw_val_class_loc_list
:
5292 fprintf (outfile
, "location list -> label:%s",
5293 AT_loc_list (a
)->ll_symbol
);
5295 case dw_val_class_range_list
:
5296 fprintf (outfile
, "range list");
5298 case dw_val_class_const
:
5299 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5301 case dw_val_class_unsigned_const
:
5302 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5304 case dw_val_class_const_double
:
5305 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5306 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5307 a
->dw_attr_val
.v
.val_double
.high
,
5308 a
->dw_attr_val
.v
.val_double
.low
);
5310 case dw_val_class_vec
:
5311 fprintf (outfile
, "floating-point or vector constant");
5313 case dw_val_class_flag
:
5314 fprintf (outfile
, "%u", AT_flag (a
));
5316 case dw_val_class_die_ref
:
5317 if (AT_ref (a
) != NULL
)
5319 if (AT_ref (a
)->comdat_type_p
)
5321 fprintf (outfile
, "die -> signature: ");
5322 print_signature (outfile
,
5323 AT_ref (a
)->die_id
.die_type_node
->signature
);
5325 else if (AT_ref (a
)->die_id
.die_symbol
)
5326 fprintf (outfile
, "die -> label: %s",
5327 AT_ref (a
)->die_id
.die_symbol
);
5329 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5330 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5333 fprintf (outfile
, "die -> <null>");
5335 case dw_val_class_vms_delta
:
5336 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5337 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5339 case dw_val_class_lbl_id
:
5340 case dw_val_class_lineptr
:
5341 case dw_val_class_macptr
:
5342 case dw_val_class_high_pc
:
5343 fprintf (outfile
, "label: %s", AT_lbl (a
));
5345 case dw_val_class_str
:
5346 if (AT_string (a
) != NULL
)
5347 fprintf (outfile
, "\"%s\"", AT_string (a
));
5349 fprintf (outfile
, "<null>");
5351 case dw_val_class_file
:
5352 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5353 AT_file (a
)->emitted_number
);
5355 case dw_val_class_data8
:
5359 for (i
= 0; i
< 8; i
++)
5360 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5367 fprintf (outfile
, "\n");
5370 if (die
->die_child
!= NULL
)
5373 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5376 if (print_indent
== 0)
5377 fprintf (outfile
, "\n");
5380 /* Print the information collected for a given DIE. */
5383 debug_dwarf_die (dw_die_ref die
)
5385 print_die (die
, stderr
);
5389 debug (die_struct
&ref
)
5391 print_die (&ref
, stderr
);
5395 debug (die_struct
*ptr
)
5400 fprintf (stderr
, "<nil>\n");
5404 /* Print all DWARF information collected for the compilation unit.
5405 This routine is a debugging aid only. */
5411 print_die (comp_unit_die (), stderr
);
5414 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5415 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5416 DIE that marks the start of the DIEs for this include file. */
5419 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5421 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5422 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5424 new_unit
->die_sib
= old_unit
;
5428 /* Close an include-file CU and reopen the enclosing one. */
5431 pop_compile_unit (dw_die_ref old_unit
)
5433 dw_die_ref new_unit
= old_unit
->die_sib
;
5435 old_unit
->die_sib
= NULL
;
5439 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5440 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5441 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5443 /* Calculate the checksum of a location expression. */
5446 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5451 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5453 hash
= hash_loc_operands (loc
, hash
);
5457 /* Calculate the checksum of an attribute. */
5460 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5462 dw_loc_descr_ref loc
;
5465 CHECKSUM (at
->dw_attr
);
5467 /* We don't care that this was compiled with a different compiler
5468 snapshot; if the output is the same, that's what matters. */
5469 if (at
->dw_attr
== DW_AT_producer
)
5472 switch (AT_class (at
))
5474 case dw_val_class_const
:
5475 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5477 case dw_val_class_unsigned_const
:
5478 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5480 case dw_val_class_const_double
:
5481 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5483 case dw_val_class_vec
:
5484 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5485 (at
->dw_attr_val
.v
.val_vec
.length
5486 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5488 case dw_val_class_flag
:
5489 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5491 case dw_val_class_str
:
5492 CHECKSUM_STRING (AT_string (at
));
5495 case dw_val_class_addr
:
5497 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5498 CHECKSUM_STRING (XSTR (r
, 0));
5501 case dw_val_class_offset
:
5502 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5505 case dw_val_class_loc
:
5506 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5507 loc_checksum (loc
, ctx
);
5510 case dw_val_class_die_ref
:
5511 die_checksum (AT_ref (at
), ctx
, mark
);
5514 case dw_val_class_fde_ref
:
5515 case dw_val_class_vms_delta
:
5516 case dw_val_class_lbl_id
:
5517 case dw_val_class_lineptr
:
5518 case dw_val_class_macptr
:
5519 case dw_val_class_high_pc
:
5522 case dw_val_class_file
:
5523 CHECKSUM_STRING (AT_file (at
)->filename
);
5526 case dw_val_class_data8
:
5527 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5535 /* Calculate the checksum of a DIE. */
5538 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5544 /* To avoid infinite recursion. */
5547 CHECKSUM (die
->die_mark
);
5550 die
->die_mark
= ++(*mark
);
5552 CHECKSUM (die
->die_tag
);
5554 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5555 attr_checksum (a
, ctx
, mark
);
5557 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5561 #undef CHECKSUM_BLOCK
5562 #undef CHECKSUM_STRING
5564 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5565 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5566 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5567 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5568 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5569 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5570 #define CHECKSUM_ATTR(FOO) \
5571 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5573 /* Calculate the checksum of a number in signed LEB128 format. */
5576 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5583 byte
= (value
& 0x7f);
5585 more
= !((value
== 0 && (byte
& 0x40) == 0)
5586 || (value
== -1 && (byte
& 0x40) != 0));
5595 /* Calculate the checksum of a number in unsigned LEB128 format. */
5598 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5602 unsigned char byte
= (value
& 0x7f);
5605 /* More bytes to follow. */
5613 /* Checksum the context of the DIE. This adds the names of any
5614 surrounding namespaces or structures to the checksum. */
5617 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5621 int tag
= die
->die_tag
;
5623 if (tag
!= DW_TAG_namespace
5624 && tag
!= DW_TAG_structure_type
5625 && tag
!= DW_TAG_class_type
)
5628 name
= get_AT_string (die
, DW_AT_name
);
5630 spec
= get_AT_ref (die
, DW_AT_specification
);
5634 if (die
->die_parent
!= NULL
)
5635 checksum_die_context (die
->die_parent
, ctx
);
5637 CHECKSUM_ULEB128 ('C');
5638 CHECKSUM_ULEB128 (tag
);
5640 CHECKSUM_STRING (name
);
5643 /* Calculate the checksum of a location expression. */
5646 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5648 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5649 were emitted as a DW_FORM_sdata instead of a location expression. */
5650 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5652 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5653 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5657 /* Otherwise, just checksum the raw location expression. */
5662 CHECKSUM_ULEB128 (loc
->dtprel
);
5663 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5664 hash
= hash_loc_operands (loc
, hash
);
5666 loc
= loc
->dw_loc_next
;
5670 /* Calculate the checksum of an attribute. */
5673 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5674 struct md5_ctx
*ctx
, int *mark
)
5676 dw_loc_descr_ref loc
;
5679 if (AT_class (at
) == dw_val_class_die_ref
)
5681 dw_die_ref target_die
= AT_ref (at
);
5683 /* For pointer and reference types, we checksum only the (qualified)
5684 name of the target type (if there is a name). For friend entries,
5685 we checksum only the (qualified) name of the target type or function.
5686 This allows the checksum to remain the same whether the target type
5687 is complete or not. */
5688 if ((at
->dw_attr
== DW_AT_type
5689 && (tag
== DW_TAG_pointer_type
5690 || tag
== DW_TAG_reference_type
5691 || tag
== DW_TAG_rvalue_reference_type
5692 || tag
== DW_TAG_ptr_to_member_type
))
5693 || (at
->dw_attr
== DW_AT_friend
5694 && tag
== DW_TAG_friend
))
5696 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5698 if (name_attr
!= NULL
)
5700 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5704 CHECKSUM_ULEB128 ('N');
5705 CHECKSUM_ULEB128 (at
->dw_attr
);
5706 if (decl
->die_parent
!= NULL
)
5707 checksum_die_context (decl
->die_parent
, ctx
);
5708 CHECKSUM_ULEB128 ('E');
5709 CHECKSUM_STRING (AT_string (name_attr
));
5714 /* For all other references to another DIE, we check to see if the
5715 target DIE has already been visited. If it has, we emit a
5716 backward reference; if not, we descend recursively. */
5717 if (target_die
->die_mark
> 0)
5719 CHECKSUM_ULEB128 ('R');
5720 CHECKSUM_ULEB128 (at
->dw_attr
);
5721 CHECKSUM_ULEB128 (target_die
->die_mark
);
5725 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5729 target_die
->die_mark
= ++(*mark
);
5730 CHECKSUM_ULEB128 ('T');
5731 CHECKSUM_ULEB128 (at
->dw_attr
);
5732 if (decl
->die_parent
!= NULL
)
5733 checksum_die_context (decl
->die_parent
, ctx
);
5734 die_checksum_ordered (target_die
, ctx
, mark
);
5739 CHECKSUM_ULEB128 ('A');
5740 CHECKSUM_ULEB128 (at
->dw_attr
);
5742 switch (AT_class (at
))
5744 case dw_val_class_const
:
5745 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5746 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5749 case dw_val_class_unsigned_const
:
5750 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5751 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5754 case dw_val_class_const_double
:
5755 CHECKSUM_ULEB128 (DW_FORM_block
);
5756 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5757 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5760 case dw_val_class_vec
:
5761 CHECKSUM_ULEB128 (DW_FORM_block
);
5762 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5763 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5764 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5765 (at
->dw_attr_val
.v
.val_vec
.length
5766 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5769 case dw_val_class_flag
:
5770 CHECKSUM_ULEB128 (DW_FORM_flag
);
5771 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5774 case dw_val_class_str
:
5775 CHECKSUM_ULEB128 (DW_FORM_string
);
5776 CHECKSUM_STRING (AT_string (at
));
5779 case dw_val_class_addr
:
5781 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5782 CHECKSUM_ULEB128 (DW_FORM_string
);
5783 CHECKSUM_STRING (XSTR (r
, 0));
5786 case dw_val_class_offset
:
5787 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5788 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5791 case dw_val_class_loc
:
5792 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5793 loc_checksum_ordered (loc
, ctx
);
5796 case dw_val_class_fde_ref
:
5797 case dw_val_class_lbl_id
:
5798 case dw_val_class_lineptr
:
5799 case dw_val_class_macptr
:
5800 case dw_val_class_high_pc
:
5803 case dw_val_class_file
:
5804 CHECKSUM_ULEB128 (DW_FORM_string
);
5805 CHECKSUM_STRING (AT_file (at
)->filename
);
5808 case dw_val_class_data8
:
5809 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5817 struct checksum_attributes
5819 dw_attr_ref at_name
;
5820 dw_attr_ref at_type
;
5821 dw_attr_ref at_friend
;
5822 dw_attr_ref at_accessibility
;
5823 dw_attr_ref at_address_class
;
5824 dw_attr_ref at_allocated
;
5825 dw_attr_ref at_artificial
;
5826 dw_attr_ref at_associated
;
5827 dw_attr_ref at_binary_scale
;
5828 dw_attr_ref at_bit_offset
;
5829 dw_attr_ref at_bit_size
;
5830 dw_attr_ref at_bit_stride
;
5831 dw_attr_ref at_byte_size
;
5832 dw_attr_ref at_byte_stride
;
5833 dw_attr_ref at_const_value
;
5834 dw_attr_ref at_containing_type
;
5835 dw_attr_ref at_count
;
5836 dw_attr_ref at_data_location
;
5837 dw_attr_ref at_data_member_location
;
5838 dw_attr_ref at_decimal_scale
;
5839 dw_attr_ref at_decimal_sign
;
5840 dw_attr_ref at_default_value
;
5841 dw_attr_ref at_digit_count
;
5842 dw_attr_ref at_discr
;
5843 dw_attr_ref at_discr_list
;
5844 dw_attr_ref at_discr_value
;
5845 dw_attr_ref at_encoding
;
5846 dw_attr_ref at_endianity
;
5847 dw_attr_ref at_explicit
;
5848 dw_attr_ref at_is_optional
;
5849 dw_attr_ref at_location
;
5850 dw_attr_ref at_lower_bound
;
5851 dw_attr_ref at_mutable
;
5852 dw_attr_ref at_ordering
;
5853 dw_attr_ref at_picture_string
;
5854 dw_attr_ref at_prototyped
;
5855 dw_attr_ref at_small
;
5856 dw_attr_ref at_segment
;
5857 dw_attr_ref at_string_length
;
5858 dw_attr_ref at_threads_scaled
;
5859 dw_attr_ref at_upper_bound
;
5860 dw_attr_ref at_use_location
;
5861 dw_attr_ref at_use_UTF8
;
5862 dw_attr_ref at_variable_parameter
;
5863 dw_attr_ref at_virtuality
;
5864 dw_attr_ref at_visibility
;
5865 dw_attr_ref at_vtable_elem_location
;
5868 /* Collect the attributes that we will want to use for the checksum. */
5871 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5876 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5887 attrs
->at_friend
= a
;
5889 case DW_AT_accessibility
:
5890 attrs
->at_accessibility
= a
;
5892 case DW_AT_address_class
:
5893 attrs
->at_address_class
= a
;
5895 case DW_AT_allocated
:
5896 attrs
->at_allocated
= a
;
5898 case DW_AT_artificial
:
5899 attrs
->at_artificial
= a
;
5901 case DW_AT_associated
:
5902 attrs
->at_associated
= a
;
5904 case DW_AT_binary_scale
:
5905 attrs
->at_binary_scale
= a
;
5907 case DW_AT_bit_offset
:
5908 attrs
->at_bit_offset
= a
;
5910 case DW_AT_bit_size
:
5911 attrs
->at_bit_size
= a
;
5913 case DW_AT_bit_stride
:
5914 attrs
->at_bit_stride
= a
;
5916 case DW_AT_byte_size
:
5917 attrs
->at_byte_size
= a
;
5919 case DW_AT_byte_stride
:
5920 attrs
->at_byte_stride
= a
;
5922 case DW_AT_const_value
:
5923 attrs
->at_const_value
= a
;
5925 case DW_AT_containing_type
:
5926 attrs
->at_containing_type
= a
;
5929 attrs
->at_count
= a
;
5931 case DW_AT_data_location
:
5932 attrs
->at_data_location
= a
;
5934 case DW_AT_data_member_location
:
5935 attrs
->at_data_member_location
= a
;
5937 case DW_AT_decimal_scale
:
5938 attrs
->at_decimal_scale
= a
;
5940 case DW_AT_decimal_sign
:
5941 attrs
->at_decimal_sign
= a
;
5943 case DW_AT_default_value
:
5944 attrs
->at_default_value
= a
;
5946 case DW_AT_digit_count
:
5947 attrs
->at_digit_count
= a
;
5950 attrs
->at_discr
= a
;
5952 case DW_AT_discr_list
:
5953 attrs
->at_discr_list
= a
;
5955 case DW_AT_discr_value
:
5956 attrs
->at_discr_value
= a
;
5958 case DW_AT_encoding
:
5959 attrs
->at_encoding
= a
;
5961 case DW_AT_endianity
:
5962 attrs
->at_endianity
= a
;
5964 case DW_AT_explicit
:
5965 attrs
->at_explicit
= a
;
5967 case DW_AT_is_optional
:
5968 attrs
->at_is_optional
= a
;
5970 case DW_AT_location
:
5971 attrs
->at_location
= a
;
5973 case DW_AT_lower_bound
:
5974 attrs
->at_lower_bound
= a
;
5977 attrs
->at_mutable
= a
;
5979 case DW_AT_ordering
:
5980 attrs
->at_ordering
= a
;
5982 case DW_AT_picture_string
:
5983 attrs
->at_picture_string
= a
;
5985 case DW_AT_prototyped
:
5986 attrs
->at_prototyped
= a
;
5989 attrs
->at_small
= a
;
5992 attrs
->at_segment
= a
;
5994 case DW_AT_string_length
:
5995 attrs
->at_string_length
= a
;
5997 case DW_AT_threads_scaled
:
5998 attrs
->at_threads_scaled
= a
;
6000 case DW_AT_upper_bound
:
6001 attrs
->at_upper_bound
= a
;
6003 case DW_AT_use_location
:
6004 attrs
->at_use_location
= a
;
6006 case DW_AT_use_UTF8
:
6007 attrs
->at_use_UTF8
= a
;
6009 case DW_AT_variable_parameter
:
6010 attrs
->at_variable_parameter
= a
;
6012 case DW_AT_virtuality
:
6013 attrs
->at_virtuality
= a
;
6015 case DW_AT_visibility
:
6016 attrs
->at_visibility
= a
;
6018 case DW_AT_vtable_elem_location
:
6019 attrs
->at_vtable_elem_location
= a
;
6027 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6030 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6034 struct checksum_attributes attrs
;
6036 CHECKSUM_ULEB128 ('D');
6037 CHECKSUM_ULEB128 (die
->die_tag
);
6039 memset (&attrs
, 0, sizeof (attrs
));
6041 decl
= get_AT_ref (die
, DW_AT_specification
);
6043 collect_checksum_attributes (&attrs
, decl
);
6044 collect_checksum_attributes (&attrs
, die
);
6046 CHECKSUM_ATTR (attrs
.at_name
);
6047 CHECKSUM_ATTR (attrs
.at_accessibility
);
6048 CHECKSUM_ATTR (attrs
.at_address_class
);
6049 CHECKSUM_ATTR (attrs
.at_allocated
);
6050 CHECKSUM_ATTR (attrs
.at_artificial
);
6051 CHECKSUM_ATTR (attrs
.at_associated
);
6052 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6053 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6054 CHECKSUM_ATTR (attrs
.at_bit_size
);
6055 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6056 CHECKSUM_ATTR (attrs
.at_byte_size
);
6057 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6058 CHECKSUM_ATTR (attrs
.at_const_value
);
6059 CHECKSUM_ATTR (attrs
.at_containing_type
);
6060 CHECKSUM_ATTR (attrs
.at_count
);
6061 CHECKSUM_ATTR (attrs
.at_data_location
);
6062 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6063 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6064 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6065 CHECKSUM_ATTR (attrs
.at_default_value
);
6066 CHECKSUM_ATTR (attrs
.at_digit_count
);
6067 CHECKSUM_ATTR (attrs
.at_discr
);
6068 CHECKSUM_ATTR (attrs
.at_discr_list
);
6069 CHECKSUM_ATTR (attrs
.at_discr_value
);
6070 CHECKSUM_ATTR (attrs
.at_encoding
);
6071 CHECKSUM_ATTR (attrs
.at_endianity
);
6072 CHECKSUM_ATTR (attrs
.at_explicit
);
6073 CHECKSUM_ATTR (attrs
.at_is_optional
);
6074 CHECKSUM_ATTR (attrs
.at_location
);
6075 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6076 CHECKSUM_ATTR (attrs
.at_mutable
);
6077 CHECKSUM_ATTR (attrs
.at_ordering
);
6078 CHECKSUM_ATTR (attrs
.at_picture_string
);
6079 CHECKSUM_ATTR (attrs
.at_prototyped
);
6080 CHECKSUM_ATTR (attrs
.at_small
);
6081 CHECKSUM_ATTR (attrs
.at_segment
);
6082 CHECKSUM_ATTR (attrs
.at_string_length
);
6083 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6084 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6085 CHECKSUM_ATTR (attrs
.at_use_location
);
6086 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6087 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6088 CHECKSUM_ATTR (attrs
.at_virtuality
);
6089 CHECKSUM_ATTR (attrs
.at_visibility
);
6090 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6091 CHECKSUM_ATTR (attrs
.at_type
);
6092 CHECKSUM_ATTR (attrs
.at_friend
);
6094 /* Checksum the child DIEs. */
6097 dw_attr_ref name_attr
;
6100 name_attr
= get_AT (c
, DW_AT_name
);
6101 if (is_template_instantiation (c
))
6103 /* Ignore instantiations of member type and function templates. */
6105 else if (name_attr
!= NULL
6106 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6108 /* Use a shallow checksum for named nested types and member
6110 CHECKSUM_ULEB128 ('S');
6111 CHECKSUM_ULEB128 (c
->die_tag
);
6112 CHECKSUM_STRING (AT_string (name_attr
));
6116 /* Use a deep checksum for other children. */
6117 /* Mark this DIE so it gets processed when unmarking. */
6118 if (c
->die_mark
== 0)
6120 die_checksum_ordered (c
, ctx
, mark
);
6122 } while (c
!= die
->die_child
);
6124 CHECKSUM_ULEB128 (0);
6127 /* Add a type name and tag to a hash. */
6129 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6131 CHECKSUM_ULEB128 (tag
);
6132 CHECKSUM_STRING (name
);
6136 #undef CHECKSUM_STRING
6137 #undef CHECKSUM_ATTR
6138 #undef CHECKSUM_LEB128
6139 #undef CHECKSUM_ULEB128
6141 /* Generate the type signature for DIE. This is computed by generating an
6142 MD5 checksum over the DIE's tag, its relevant attributes, and its
6143 children. Attributes that are references to other DIEs are processed
6144 by recursion, using the MARK field to prevent infinite recursion.
6145 If the DIE is nested inside a namespace or another type, we also
6146 need to include that context in the signature. The lower 64 bits
6147 of the resulting MD5 checksum comprise the signature. */
6150 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6154 unsigned char checksum
[16];
6159 name
= get_AT_string (die
, DW_AT_name
);
6160 decl
= get_AT_ref (die
, DW_AT_specification
);
6161 parent
= get_die_parent (die
);
6163 /* First, compute a signature for just the type name (and its surrounding
6164 context, if any. This is stored in the type unit DIE for link-time
6165 ODR (one-definition rule) checking. */
6167 if (is_cxx () && name
!= NULL
)
6169 md5_init_ctx (&ctx
);
6171 /* Checksum the names of surrounding namespaces and structures. */
6173 checksum_die_context (parent
, &ctx
);
6175 /* Checksum the current DIE. */
6176 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6177 md5_finish_ctx (&ctx
, checksum
);
6179 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6182 /* Next, compute the complete type signature. */
6184 md5_init_ctx (&ctx
);
6186 die
->die_mark
= mark
;
6188 /* Checksum the names of surrounding namespaces and structures. */
6190 checksum_die_context (parent
, &ctx
);
6192 /* Checksum the DIE and its children. */
6193 die_checksum_ordered (die
, &ctx
, &mark
);
6194 unmark_all_dies (die
);
6195 md5_finish_ctx (&ctx
, checksum
);
6197 /* Store the signature in the type node and link the type DIE and the
6198 type node together. */
6199 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6200 DWARF_TYPE_SIGNATURE_SIZE
);
6201 die
->comdat_type_p
= true;
6202 die
->die_id
.die_type_node
= type_node
;
6203 type_node
->type_die
= die
;
6205 /* If the DIE is a specification, link its declaration to the type node
6209 decl
->comdat_type_p
= true;
6210 decl
->die_id
.die_type_node
= type_node
;
6214 /* Do the location expressions look same? */
6216 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6218 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6219 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6220 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6223 /* Do the values look the same? */
6225 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6227 dw_loc_descr_ref loc1
, loc2
;
6230 if (v1
->val_class
!= v2
->val_class
)
6233 switch (v1
->val_class
)
6235 case dw_val_class_const
:
6236 return v1
->v
.val_int
== v2
->v
.val_int
;
6237 case dw_val_class_unsigned_const
:
6238 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6239 case dw_val_class_const_double
:
6240 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6241 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6242 case dw_val_class_vec
:
6243 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6244 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6246 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6247 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6250 case dw_val_class_flag
:
6251 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6252 case dw_val_class_str
:
6253 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6255 case dw_val_class_addr
:
6256 r1
= v1
->v
.val_addr
;
6257 r2
= v2
->v
.val_addr
;
6258 if (GET_CODE (r1
) != GET_CODE (r2
))
6260 return !rtx_equal_p (r1
, r2
);
6262 case dw_val_class_offset
:
6263 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6265 case dw_val_class_loc
:
6266 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6268 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6269 if (!same_loc_p (loc1
, loc2
, mark
))
6271 return !loc1
&& !loc2
;
6273 case dw_val_class_die_ref
:
6274 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6276 case dw_val_class_fde_ref
:
6277 case dw_val_class_vms_delta
:
6278 case dw_val_class_lbl_id
:
6279 case dw_val_class_lineptr
:
6280 case dw_val_class_macptr
:
6281 case dw_val_class_high_pc
:
6284 case dw_val_class_file
:
6285 return v1
->v
.val_file
== v2
->v
.val_file
;
6287 case dw_val_class_data8
:
6288 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6295 /* Do the attributes look the same? */
6298 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6300 if (at1
->dw_attr
!= at2
->dw_attr
)
6303 /* We don't care that this was compiled with a different compiler
6304 snapshot; if the output is the same, that's what matters. */
6305 if (at1
->dw_attr
== DW_AT_producer
)
6308 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6311 /* Do the dies look the same? */
6314 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6320 /* To avoid infinite recursion. */
6322 return die1
->die_mark
== die2
->die_mark
;
6323 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6325 if (die1
->die_tag
!= die2
->die_tag
)
6328 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6331 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6332 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6335 c1
= die1
->die_child
;
6336 c2
= die2
->die_child
;
6345 if (!same_die_p (c1
, c2
, mark
))
6349 if (c1
== die1
->die_child
)
6351 if (c2
== die2
->die_child
)
6361 /* Do the dies look the same? Wrapper around same_die_p. */
6364 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6367 int ret
= same_die_p (die1
, die2
, &mark
);
6369 unmark_all_dies (die1
);
6370 unmark_all_dies (die2
);
6375 /* The prefix to attach to symbols on DIEs in the current comdat debug
6377 static const char *comdat_symbol_id
;
6379 /* The index of the current symbol within the current comdat CU. */
6380 static unsigned int comdat_symbol_number
;
6382 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6383 children, and set comdat_symbol_id accordingly. */
6386 compute_section_prefix (dw_die_ref unit_die
)
6388 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6389 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6390 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6393 unsigned char checksum
[16];
6396 /* Compute the checksum of the DIE, then append part of it as hex digits to
6397 the name filename of the unit. */
6399 md5_init_ctx (&ctx
);
6401 die_checksum (unit_die
, &ctx
, &mark
);
6402 unmark_all_dies (unit_die
);
6403 md5_finish_ctx (&ctx
, checksum
);
6405 sprintf (name
, "%s.", base
);
6406 clean_symbol_name (name
);
6408 p
= name
+ strlen (name
);
6409 for (i
= 0; i
< 4; i
++)
6411 sprintf (p
, "%.2x", checksum
[i
]);
6415 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6416 comdat_symbol_number
= 0;
6419 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6422 is_type_die (dw_die_ref die
)
6424 switch (die
->die_tag
)
6426 case DW_TAG_array_type
:
6427 case DW_TAG_class_type
:
6428 case DW_TAG_interface_type
:
6429 case DW_TAG_enumeration_type
:
6430 case DW_TAG_pointer_type
:
6431 case DW_TAG_reference_type
:
6432 case DW_TAG_rvalue_reference_type
:
6433 case DW_TAG_string_type
:
6434 case DW_TAG_structure_type
:
6435 case DW_TAG_subroutine_type
:
6436 case DW_TAG_union_type
:
6437 case DW_TAG_ptr_to_member_type
:
6438 case DW_TAG_set_type
:
6439 case DW_TAG_subrange_type
:
6440 case DW_TAG_base_type
:
6441 case DW_TAG_const_type
:
6442 case DW_TAG_file_type
:
6443 case DW_TAG_packed_type
:
6444 case DW_TAG_volatile_type
:
6445 case DW_TAG_typedef
:
6452 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6453 Basically, we want to choose the bits that are likely to be shared between
6454 compilations (types) and leave out the bits that are specific to individual
6455 compilations (functions). */
6458 is_comdat_die (dw_die_ref c
)
6460 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6461 we do for stabs. The advantage is a greater likelihood of sharing between
6462 objects that don't include headers in the same order (and therefore would
6463 put the base types in a different comdat). jason 8/28/00 */
6465 if (c
->die_tag
== DW_TAG_base_type
)
6468 if (c
->die_tag
== DW_TAG_pointer_type
6469 || c
->die_tag
== DW_TAG_reference_type
6470 || c
->die_tag
== DW_TAG_rvalue_reference_type
6471 || c
->die_tag
== DW_TAG_const_type
6472 || c
->die_tag
== DW_TAG_volatile_type
)
6474 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6476 return t
? is_comdat_die (t
) : 0;
6479 return is_type_die (c
);
6482 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6483 compilation unit. */
6486 is_symbol_die (dw_die_ref c
)
6488 return (is_type_die (c
)
6489 || is_declaration_die (c
)
6490 || c
->die_tag
== DW_TAG_namespace
6491 || c
->die_tag
== DW_TAG_module
);
6494 /* Returns true iff C is a compile-unit DIE. */
6497 is_cu_die (dw_die_ref c
)
6499 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6502 /* Returns true iff C is a unit DIE of some sort. */
6505 is_unit_die (dw_die_ref c
)
6507 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6508 || c
->die_tag
== DW_TAG_partial_unit
6509 || c
->die_tag
== DW_TAG_type_unit
);
6512 /* Returns true iff C is a namespace DIE. */
6515 is_namespace_die (dw_die_ref c
)
6517 return c
&& c
->die_tag
== DW_TAG_namespace
;
6520 /* Returns true iff C is a class or structure DIE. */
6523 is_class_die (dw_die_ref c
)
6525 return c
&& (c
->die_tag
== DW_TAG_class_type
6526 || c
->die_tag
== DW_TAG_structure_type
);
6529 /* Return non-zero if this DIE is a template parameter. */
6532 is_template_parameter (dw_die_ref die
)
6534 switch (die
->die_tag
)
6536 case DW_TAG_template_type_param
:
6537 case DW_TAG_template_value_param
:
6538 case DW_TAG_GNU_template_template_param
:
6539 case DW_TAG_GNU_template_parameter_pack
:
6546 /* Return non-zero if this DIE represents a template instantiation. */
6549 is_template_instantiation (dw_die_ref die
)
6553 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6555 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6560 gen_internal_sym (const char *prefix
)
6564 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6565 return xstrdup (buf
);
6568 /* Assign symbols to all worthy DIEs under DIE. */
6571 assign_symbol_names (dw_die_ref die
)
6575 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6577 if (comdat_symbol_id
)
6579 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6581 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6582 comdat_symbol_id
, comdat_symbol_number
++);
6583 die
->die_id
.die_symbol
= xstrdup (p
);
6586 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6589 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6592 struct cu_hash_table_entry
6595 unsigned min_comdat_num
, max_comdat_num
;
6596 struct cu_hash_table_entry
*next
;
6599 /* Helpers to manipulate hash table of CUs. */
6601 struct cu_hash_table_entry_hasher
6603 typedef cu_hash_table_entry value_type
;
6604 typedef die_struct compare_type
;
6605 static inline hashval_t
hash (const value_type
*);
6606 static inline bool equal (const value_type
*, const compare_type
*);
6607 static inline void remove (value_type
*);
6611 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6613 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6617 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6618 const compare_type
*entry2
)
6620 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6624 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6626 struct cu_hash_table_entry
*next
;
6636 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6638 /* Check whether we have already seen this CU and set up SYM_NUM
6641 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6643 struct cu_hash_table_entry dummy
;
6644 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6646 dummy
.max_comdat_num
= 0;
6648 slot
= htable
.find_slot_with_hash (cu
,
6649 htab_hash_string (cu
->die_id
.die_symbol
),
6653 for (; entry
; last
= entry
, entry
= entry
->next
)
6655 if (same_die_p_wrap (cu
, entry
->cu
))
6661 *sym_num
= entry
->min_comdat_num
;
6665 entry
= XCNEW (struct cu_hash_table_entry
);
6667 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6668 entry
->next
= *slot
;
6674 /* Record SYM_NUM to record of CU in HTABLE. */
6676 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6677 unsigned int sym_num
)
6679 struct cu_hash_table_entry
**slot
, *entry
;
6681 slot
= htable
.find_slot_with_hash (cu
,
6682 htab_hash_string (cu
->die_id
.die_symbol
),
6686 entry
->max_comdat_num
= sym_num
;
6689 /* Traverse the DIE (which is always comp_unit_die), and set up
6690 additional compilation units for each of the include files we see
6691 bracketed by BINCL/EINCL. */
6694 break_out_includes (dw_die_ref die
)
6697 dw_die_ref unit
= NULL
;
6698 limbo_die_node
*node
, **pnode
;
6699 cu_hash_type cu_hash_table
;
6703 dw_die_ref prev
= c
;
6705 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6706 || (unit
&& is_comdat_die (c
)))
6708 dw_die_ref next
= c
->die_sib
;
6710 /* This DIE is for a secondary CU; remove it from the main one. */
6711 remove_child_with_prev (c
, prev
);
6713 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6714 unit
= push_new_compile_unit (unit
, c
);
6715 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6716 unit
= pop_compile_unit (unit
);
6718 add_child_die (unit
, c
);
6720 if (c
== die
->die_child
)
6723 } while (c
!= die
->die_child
);
6726 /* We can only use this in debugging, since the frontend doesn't check
6727 to make sure that we leave every include file we enter. */
6731 assign_symbol_names (die
);
6732 cu_hash_table
.create (10);
6733 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6739 compute_section_prefix (node
->die
);
6740 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6741 &comdat_symbol_number
);
6742 assign_symbol_names (node
->die
);
6744 *pnode
= node
->next
;
6747 pnode
= &node
->next
;
6748 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6749 comdat_symbol_number
);
6752 cu_hash_table
.dispose ();
6755 /* Return non-zero if this DIE is a declaration. */
6758 is_declaration_die (dw_die_ref die
)
6763 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6764 if (a
->dw_attr
== DW_AT_declaration
)
6770 /* Return non-zero if this DIE is nested inside a subprogram. */
6773 is_nested_in_subprogram (dw_die_ref die
)
6775 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6779 return local_scope_p (decl
);
6782 /* Return non-zero if this DIE contains a defining declaration of a
6786 contains_subprogram_definition (dw_die_ref die
)
6790 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6792 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6796 /* Return non-zero if this is a type DIE that should be moved to a
6797 COMDAT .debug_types section. */
6800 should_move_die_to_comdat (dw_die_ref die
)
6802 switch (die
->die_tag
)
6804 case DW_TAG_class_type
:
6805 case DW_TAG_structure_type
:
6806 case DW_TAG_enumeration_type
:
6807 case DW_TAG_union_type
:
6808 /* Don't move declarations, inlined instances, or types nested in a
6810 if (is_declaration_die (die
)
6811 || get_AT (die
, DW_AT_abstract_origin
)
6812 || is_nested_in_subprogram (die
))
6814 /* A type definition should never contain a subprogram definition. */
6815 gcc_assert (!contains_subprogram_definition (die
));
6817 case DW_TAG_array_type
:
6818 case DW_TAG_interface_type
:
6819 case DW_TAG_pointer_type
:
6820 case DW_TAG_reference_type
:
6821 case DW_TAG_rvalue_reference_type
:
6822 case DW_TAG_string_type
:
6823 case DW_TAG_subroutine_type
:
6824 case DW_TAG_ptr_to_member_type
:
6825 case DW_TAG_set_type
:
6826 case DW_TAG_subrange_type
:
6827 case DW_TAG_base_type
:
6828 case DW_TAG_const_type
:
6829 case DW_TAG_file_type
:
6830 case DW_TAG_packed_type
:
6831 case DW_TAG_volatile_type
:
6832 case DW_TAG_typedef
:
6838 /* Make a clone of DIE. */
6841 clone_die (dw_die_ref die
)
6847 clone
= ggc_alloc_cleared_die_node ();
6848 clone
->die_tag
= die
->die_tag
;
6850 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6851 add_dwarf_attr (clone
, a
);
6856 /* Make a clone of the tree rooted at DIE. */
6859 clone_tree (dw_die_ref die
)
6862 dw_die_ref clone
= clone_die (die
);
6864 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6869 /* Make a clone of DIE as a declaration. */
6872 clone_as_declaration (dw_die_ref die
)
6879 /* If the DIE is already a declaration, just clone it. */
6880 if (is_declaration_die (die
))
6881 return clone_die (die
);
6883 /* If the DIE is a specification, just clone its declaration DIE. */
6884 decl
= get_AT_ref (die
, DW_AT_specification
);
6887 clone
= clone_die (decl
);
6888 if (die
->comdat_type_p
)
6889 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6893 clone
= ggc_alloc_cleared_die_node ();
6894 clone
->die_tag
= die
->die_tag
;
6896 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6898 /* We don't want to copy over all attributes.
6899 For example we don't want DW_AT_byte_size because otherwise we will no
6900 longer have a declaration and GDB will treat it as a definition. */
6904 case DW_AT_artificial
:
6905 case DW_AT_containing_type
:
6906 case DW_AT_external
:
6909 case DW_AT_virtuality
:
6910 case DW_AT_linkage_name
:
6911 case DW_AT_MIPS_linkage_name
:
6912 add_dwarf_attr (clone
, a
);
6914 case DW_AT_byte_size
:
6920 if (die
->comdat_type_p
)
6921 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6923 add_AT_flag (clone
, DW_AT_declaration
, 1);
6928 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6930 struct decl_table_entry
6936 /* Helpers to manipulate hash table of copied declarations. */
6938 /* Hashtable helpers. */
6940 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6942 typedef decl_table_entry value_type
;
6943 typedef die_struct compare_type
;
6944 static inline hashval_t
hash (const value_type
*);
6945 static inline bool equal (const value_type
*, const compare_type
*);
6949 decl_table_entry_hasher::hash (const value_type
*entry
)
6951 return htab_hash_pointer (entry
->orig
);
6955 decl_table_entry_hasher::equal (const value_type
*entry1
,
6956 const compare_type
*entry2
)
6958 return entry1
->orig
== entry2
;
6961 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6963 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6964 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6965 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6966 to check if the ancestor has already been copied into UNIT. */
6969 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6971 dw_die_ref parent
= die
->die_parent
;
6972 dw_die_ref new_parent
= unit
;
6974 decl_table_entry
**slot
= NULL
;
6975 struct decl_table_entry
*entry
= NULL
;
6977 if (decl_table
.is_created ())
6979 /* Check if the entry has already been copied to UNIT. */
6980 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
6982 if (*slot
!= HTAB_EMPTY_ENTRY
)
6988 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
6989 entry
= XCNEW (struct decl_table_entry
);
6997 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7000 if (!is_unit_die (parent
))
7001 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7004 copy
= clone_as_declaration (die
);
7005 add_child_die (new_parent
, copy
);
7007 if (decl_table
.is_created ())
7009 /* Record the pointer to the copy. */
7015 /* Copy the declaration context to the new type unit DIE. This includes
7016 any surrounding namespace or type declarations. If the DIE has an
7017 AT_specification attribute, it also includes attributes and children
7018 attached to the specification, and returns a pointer to the original
7019 parent of the declaration DIE. Returns NULL otherwise. */
7022 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7025 dw_die_ref new_decl
;
7026 dw_die_ref orig_parent
= NULL
;
7028 decl
= get_AT_ref (die
, DW_AT_specification
);
7037 /* The original DIE will be changed to a declaration, and must
7038 be moved to be a child of the original declaration DIE. */
7039 orig_parent
= decl
->die_parent
;
7041 /* Copy the type node pointer from the new DIE to the original
7042 declaration DIE so we can forward references later. */
7043 decl
->comdat_type_p
= true;
7044 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7046 remove_AT (die
, DW_AT_specification
);
7048 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7050 if (a
->dw_attr
!= DW_AT_name
7051 && a
->dw_attr
!= DW_AT_declaration
7052 && a
->dw_attr
!= DW_AT_external
)
7053 add_dwarf_attr (die
, a
);
7056 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7059 if (decl
->die_parent
!= NULL
7060 && !is_unit_die (decl
->die_parent
))
7062 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7063 if (new_decl
!= NULL
)
7065 remove_AT (new_decl
, DW_AT_signature
);
7066 add_AT_specification (die
, new_decl
);
7073 /* Generate the skeleton ancestor tree for the given NODE, then clone
7074 the DIE and add the clone into the tree. */
7077 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7079 if (node
->new_die
!= NULL
)
7082 node
->new_die
= clone_as_declaration (node
->old_die
);
7084 if (node
->parent
!= NULL
)
7086 generate_skeleton_ancestor_tree (node
->parent
);
7087 add_child_die (node
->parent
->new_die
, node
->new_die
);
7091 /* Generate a skeleton tree of DIEs containing any declarations that are
7092 found in the original tree. We traverse the tree looking for declaration
7093 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7096 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7098 skeleton_chain_node node
;
7101 dw_die_ref prev
= NULL
;
7102 dw_die_ref next
= NULL
;
7104 node
.parent
= parent
;
7106 first
= c
= parent
->old_die
->die_child
;
7110 if (prev
== NULL
|| prev
->die_sib
== c
)
7113 next
= (c
== first
? NULL
: c
->die_sib
);
7115 node
.new_die
= NULL
;
7116 if (is_declaration_die (c
))
7118 if (is_template_instantiation (c
))
7120 /* Instantiated templates do not need to be cloned into the
7121 type unit. Just move the DIE and its children back to
7122 the skeleton tree (in the main CU). */
7123 remove_child_with_prev (c
, prev
);
7124 add_child_die (parent
->new_die
, c
);
7129 /* Clone the existing DIE, move the original to the skeleton
7130 tree (which is in the main CU), and put the clone, with
7131 all the original's children, where the original came from
7132 (which is about to be moved to the type unit). */
7133 dw_die_ref clone
= clone_die (c
);
7134 move_all_children (c
, clone
);
7136 replace_child (c
, clone
, prev
);
7137 generate_skeleton_ancestor_tree (parent
);
7138 add_child_die (parent
->new_die
, c
);
7143 generate_skeleton_bottom_up (&node
);
7144 } while (next
!= NULL
);
7147 /* Wrapper function for generate_skeleton_bottom_up. */
7150 generate_skeleton (dw_die_ref die
)
7152 skeleton_chain_node node
;
7155 node
.new_die
= NULL
;
7158 /* If this type definition is nested inside another type,
7159 and is not an instantiation of a template, always leave
7160 at least a declaration in its place. */
7161 if (die
->die_parent
!= NULL
7162 && is_type_die (die
->die_parent
)
7163 && !is_template_instantiation (die
))
7164 node
.new_die
= clone_as_declaration (die
);
7166 generate_skeleton_bottom_up (&node
);
7167 return node
.new_die
;
7170 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7171 declaration. The original DIE is moved to a new compile unit so that
7172 existing references to it follow it to the new location. If any of the
7173 original DIE's descendants is a declaration, we need to replace the
7174 original DIE with a skeleton tree and move the declarations back into the
7178 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7181 dw_die_ref skeleton
, orig_parent
;
7183 /* Copy the declaration context to the type unit DIE. If the returned
7184 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7186 orig_parent
= copy_declaration_context (unit
, child
);
7188 skeleton
= generate_skeleton (child
);
7189 if (skeleton
== NULL
)
7190 remove_child_with_prev (child
, prev
);
7193 skeleton
->comdat_type_p
= true;
7194 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7196 /* If the original DIE was a specification, we need to put
7197 the skeleton under the parent DIE of the declaration.
7198 This leaves the original declaration in the tree, but
7199 it will be pruned later since there are no longer any
7200 references to it. */
7201 if (orig_parent
!= NULL
)
7203 remove_child_with_prev (child
, prev
);
7204 add_child_die (orig_parent
, skeleton
);
7207 replace_child (child
, skeleton
, prev
);
7213 /* Traverse the DIE and set up additional .debug_types sections for each
7214 type worthy of being placed in a COMDAT section. */
7217 break_out_comdat_types (dw_die_ref die
)
7221 dw_die_ref prev
= NULL
;
7222 dw_die_ref next
= NULL
;
7223 dw_die_ref unit
= NULL
;
7225 first
= c
= die
->die_child
;
7229 if (prev
== NULL
|| prev
->die_sib
== c
)
7232 next
= (c
== first
? NULL
: c
->die_sib
);
7233 if (should_move_die_to_comdat (c
))
7235 dw_die_ref replacement
;
7236 comdat_type_node_ref type_node
;
7238 /* Break out nested types into their own type units. */
7239 break_out_comdat_types (c
);
7241 /* Create a new type unit DIE as the root for the new tree, and
7242 add it to the list of comdat types. */
7243 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7244 add_AT_unsigned (unit
, DW_AT_language
,
7245 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7246 type_node
= ggc_alloc_cleared_comdat_type_node ();
7247 type_node
->root_die
= unit
;
7248 type_node
->next
= comdat_type_list
;
7249 comdat_type_list
= type_node
;
7251 /* Generate the type signature. */
7252 generate_type_signature (c
, type_node
);
7254 /* Copy the declaration context, attributes, and children of the
7255 declaration into the new type unit DIE, then remove this DIE
7256 from the main CU (or replace it with a skeleton if necessary). */
7257 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7258 type_node
->skeleton_die
= replacement
;
7260 /* Add the DIE to the new compunit. */
7261 add_child_die (unit
, c
);
7263 if (replacement
!= NULL
)
7266 else if (c
->die_tag
== DW_TAG_namespace
7267 || c
->die_tag
== DW_TAG_class_type
7268 || c
->die_tag
== DW_TAG_structure_type
7269 || c
->die_tag
== DW_TAG_union_type
)
7271 /* Look for nested types that can be broken out. */
7272 break_out_comdat_types (c
);
7274 } while (next
!= NULL
);
7277 /* Like clone_tree, but additionally enter all the children into
7278 the hash table decl_table. */
7281 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7284 dw_die_ref clone
= clone_die (die
);
7285 struct decl_table_entry
*entry
;
7286 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7287 htab_hash_pointer (die
), INSERT
);
7288 /* Assert that DIE isn't in the hash table yet. If it would be there
7289 before, the ancestors would be necessarily there as well, therefore
7290 clone_tree_hash wouldn't be called. */
7291 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7292 entry
= XCNEW (struct decl_table_entry
);
7294 entry
->copy
= clone
;
7297 FOR_EACH_CHILD (die
, c
,
7298 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7303 /* Walk the DIE and its children, looking for references to incomplete
7304 or trivial types that are unmarked (i.e., that are not in the current
7308 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7314 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7316 if (AT_class (a
) == dw_val_class_die_ref
)
7318 dw_die_ref targ
= AT_ref (a
);
7319 decl_table_entry
**slot
;
7320 struct decl_table_entry
*entry
;
7322 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7325 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7328 if (*slot
!= HTAB_EMPTY_ENTRY
)
7330 /* TARG has already been copied, so we just need to
7331 modify the reference to point to the copy. */
7333 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7337 dw_die_ref parent
= unit
;
7338 dw_die_ref copy
= clone_die (targ
);
7340 /* Record in DECL_TABLE that TARG has been copied.
7341 Need to do this now, before the recursive call,
7342 because DECL_TABLE may be expanded and SLOT
7343 would no longer be a valid pointer. */
7344 entry
= XCNEW (struct decl_table_entry
);
7349 FOR_EACH_CHILD (targ
, c
,
7350 add_child_die (copy
,
7351 clone_tree_hash (c
, decl_table
)));
7353 /* Make sure the cloned tree is marked as part of the
7357 /* If TARG has surrounding context, copy its ancestor tree
7358 into the new type unit. */
7359 if (targ
->die_parent
!= NULL
7360 && !is_unit_die (targ
->die_parent
))
7361 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7364 add_child_die (parent
, copy
);
7365 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7367 /* Make sure the newly-copied DIE is walked. If it was
7368 installed in a previously-added context, it won't
7369 get visited otherwise. */
7372 /* Find the highest point of the newly-added tree,
7373 mark each node along the way, and walk from there. */
7374 parent
->die_mark
= 1;
7375 while (parent
->die_parent
7376 && parent
->die_parent
->die_mark
== 0)
7378 parent
= parent
->die_parent
;
7379 parent
->die_mark
= 1;
7381 copy_decls_walk (unit
, parent
, decl_table
);
7387 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7390 /* Copy declarations for "unworthy" types into the new comdat section.
7391 Incomplete types, modified types, and certain other types aren't broken
7392 out into comdat sections of their own, so they don't have a signature,
7393 and we need to copy the declaration into the same section so that we
7394 don't have an external reference. */
7397 copy_decls_for_unworthy_types (dw_die_ref unit
)
7399 decl_hash_type decl_table
;
7402 decl_table
.create (10);
7403 copy_decls_walk (unit
, unit
, decl_table
);
7404 decl_table
.dispose ();
7408 /* Traverse the DIE and add a sibling attribute if it may have the
7409 effect of speeding up access to siblings. To save some space,
7410 avoid generating sibling attributes for DIE's without children. */
7413 add_sibling_attributes (dw_die_ref die
)
7417 if (! die
->die_child
)
7420 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7421 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7423 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7426 /* Output all location lists for the DIE and its children. */
7429 output_location_lists (dw_die_ref die
)
7435 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7436 if (AT_class (a
) == dw_val_class_loc_list
)
7437 output_loc_list (AT_loc_list (a
));
7439 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7442 /* We want to limit the number of external references, because they are
7443 larger than local references: a relocation takes multiple words, and
7444 even a sig8 reference is always eight bytes, whereas a local reference
7445 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7446 So if we encounter multiple external references to the same type DIE, we
7447 make a local typedef stub for it and redirect all references there.
7449 This is the element of the hash table for keeping track of these
7459 /* Hashtable helpers. */
7461 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7463 typedef external_ref value_type
;
7464 typedef external_ref compare_type
;
7465 static inline hashval_t
hash (const value_type
*);
7466 static inline bool equal (const value_type
*, const compare_type
*);
7470 external_ref_hasher::hash (const value_type
*r
)
7472 dw_die_ref die
= r
->type
;
7475 /* We can't use the address of the DIE for hashing, because
7476 that will make the order of the stub DIEs non-deterministic. */
7477 if (! die
->comdat_type_p
)
7478 /* We have a symbol; use it to compute a hash. */
7479 h
= htab_hash_string (die
->die_id
.die_symbol
);
7482 /* We have a type signature; use a subset of the bits as the hash.
7483 The 8-byte signature is at least as large as hashval_t. */
7484 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7485 memcpy (&h
, type_node
->signature
, sizeof (h
));
7491 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7493 return r1
->type
== r2
->type
;
7496 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7498 /* Return a pointer to the external_ref for references to DIE. */
7500 static struct external_ref
*
7501 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7503 struct external_ref ref
, *ref_p
;
7504 external_ref
**slot
;
7507 slot
= map
.find_slot (&ref
, INSERT
);
7508 if (*slot
!= HTAB_EMPTY_ENTRY
)
7511 ref_p
= XCNEW (struct external_ref
);
7517 /* Subroutine of optimize_external_refs, below.
7519 If we see a type skeleton, record it as our stub. If we see external
7520 references, remember how many we've seen. */
7523 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7528 struct external_ref
*ref_p
;
7530 if (is_type_die (die
)
7531 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7533 /* This is a local skeleton; use it for local references. */
7534 ref_p
= lookup_external_ref (map
, c
);
7538 /* Scan the DIE references, and remember any that refer to DIEs from
7539 other CUs (i.e. those which are not marked). */
7540 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7541 if (AT_class (a
) == dw_val_class_die_ref
7542 && (c
= AT_ref (a
))->die_mark
== 0
7545 ref_p
= lookup_external_ref (map
, c
);
7549 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7552 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7553 points to an external_ref, DATA is the CU we're processing. If we don't
7554 already have a local stub, and we have multiple refs, build a stub. */
7557 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7559 struct external_ref
*ref_p
= *slot
;
7561 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7563 /* We have multiple references to this type, so build a small stub.
7564 Both of these forms are a bit dodgy from the perspective of the
7565 DWARF standard, since technically they should have names. */
7566 dw_die_ref cu
= data
;
7567 dw_die_ref type
= ref_p
->type
;
7568 dw_die_ref stub
= NULL
;
7570 if (type
->comdat_type_p
)
7572 /* If we refer to this type via sig8, use AT_signature. */
7573 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7574 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7578 /* Otherwise, use a typedef with no name. */
7579 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7580 add_AT_die_ref (stub
, DW_AT_type
, type
);
7589 /* DIE is a unit; look through all the DIE references to see if there are
7590 any external references to types, and if so, create local stubs for
7591 them which will be applied in build_abbrev_table. This is useful because
7592 references to local DIEs are smaller. */
7594 static external_ref_hash_type
7595 optimize_external_refs (dw_die_ref die
)
7597 external_ref_hash_type map
;
7599 optimize_external_refs_1 (die
, map
);
7600 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7604 /* The format of each DIE (and its attribute value pairs) is encoded in an
7605 abbreviation table. This routine builds the abbreviation table and assigns
7606 a unique abbreviation id for each abbreviation entry. The children of each
7607 die are visited recursively. */
7610 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7612 unsigned long abbrev_id
;
7613 unsigned int n_alloc
;
7618 /* Scan the DIE references, and replace any that refer to
7619 DIEs from other CUs (i.e. those which are not marked) with
7620 the local stubs we built in optimize_external_refs. */
7621 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7622 if (AT_class (a
) == dw_val_class_die_ref
7623 && (c
= AT_ref (a
))->die_mark
== 0)
7625 struct external_ref
*ref_p
;
7626 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7628 ref_p
= lookup_external_ref (extern_map
, c
);
7629 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7630 change_AT_die_ref (a
, ref_p
->stub
);
7632 /* We aren't changing this reference, so mark it external. */
7633 set_AT_ref_external (a
, 1);
7636 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7638 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7639 dw_attr_ref die_a
, abbrev_a
;
7643 if (abbrev
->die_tag
!= die
->die_tag
)
7645 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7648 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7651 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7653 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7654 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7655 || (value_format (abbrev_a
) != value_format (die_a
)))
7665 if (abbrev_id
>= abbrev_die_table_in_use
)
7667 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7669 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7670 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7673 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7674 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7675 abbrev_die_table_allocated
= n_alloc
;
7678 ++abbrev_die_table_in_use
;
7679 abbrev_die_table
[abbrev_id
] = die
;
7682 die
->die_abbrev
= abbrev_id
;
7683 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7686 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7689 constant_size (unsigned HOST_WIDE_INT value
)
7696 log
= floor_log2 (value
);
7699 log
= 1 << (floor_log2 (log
) + 1);
7704 /* Return the size of a DIE as it is represented in the
7705 .debug_info section. */
7707 static unsigned long
7708 size_of_die (dw_die_ref die
)
7710 unsigned long size
= 0;
7713 enum dwarf_form form
;
7715 size
+= size_of_uleb128 (die
->die_abbrev
);
7716 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7718 switch (AT_class (a
))
7720 case dw_val_class_addr
:
7721 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7723 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7724 size
+= size_of_uleb128 (AT_index (a
));
7727 size
+= DWARF2_ADDR_SIZE
;
7729 case dw_val_class_offset
:
7730 size
+= DWARF_OFFSET_SIZE
;
7732 case dw_val_class_loc
:
7734 unsigned long lsize
= size_of_locs (AT_loc (a
));
7737 if (dwarf_version
>= 4)
7738 size
+= size_of_uleb128 (lsize
);
7740 size
+= constant_size (lsize
);
7744 case dw_val_class_loc_list
:
7745 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7747 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7748 size
+= size_of_uleb128 (AT_index (a
));
7751 size
+= DWARF_OFFSET_SIZE
;
7753 case dw_val_class_range_list
:
7754 size
+= DWARF_OFFSET_SIZE
;
7756 case dw_val_class_const
:
7757 size
+= size_of_sleb128 (AT_int (a
));
7759 case dw_val_class_unsigned_const
:
7761 int csize
= constant_size (AT_unsigned (a
));
7762 if (dwarf_version
== 3
7763 && a
->dw_attr
== DW_AT_data_member_location
7765 size
+= size_of_uleb128 (AT_unsigned (a
));
7770 case dw_val_class_const_double
:
7771 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7772 if (HOST_BITS_PER_WIDE_INT
>= 64)
7775 case dw_val_class_vec
:
7776 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7777 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7778 + a
->dw_attr_val
.v
.val_vec
.length
7779 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7781 case dw_val_class_flag
:
7782 if (dwarf_version
>= 4)
7783 /* Currently all add_AT_flag calls pass in 1 as last argument,
7784 so DW_FORM_flag_present can be used. If that ever changes,
7785 we'll need to use DW_FORM_flag and have some optimization
7786 in build_abbrev_table that will change those to
7787 DW_FORM_flag_present if it is set to 1 in all DIEs using
7788 the same abbrev entry. */
7789 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7793 case dw_val_class_die_ref
:
7794 if (AT_ref_external (a
))
7796 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7797 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7798 is sized by target address length, whereas in DWARF3
7799 it's always sized as an offset. */
7800 if (use_debug_types
)
7801 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7802 else if (dwarf_version
== 2)
7803 size
+= DWARF2_ADDR_SIZE
;
7805 size
+= DWARF_OFFSET_SIZE
;
7808 size
+= DWARF_OFFSET_SIZE
;
7810 case dw_val_class_fde_ref
:
7811 size
+= DWARF_OFFSET_SIZE
;
7813 case dw_val_class_lbl_id
:
7814 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7816 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7817 size
+= size_of_uleb128 (AT_index (a
));
7820 size
+= DWARF2_ADDR_SIZE
;
7822 case dw_val_class_lineptr
:
7823 case dw_val_class_macptr
:
7824 size
+= DWARF_OFFSET_SIZE
;
7826 case dw_val_class_str
:
7827 form
= AT_string_form (a
);
7828 if (form
== DW_FORM_strp
)
7829 size
+= DWARF_OFFSET_SIZE
;
7830 else if (form
== DW_FORM_GNU_str_index
)
7831 size
+= size_of_uleb128 (AT_index (a
));
7833 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7835 case dw_val_class_file
:
7836 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7838 case dw_val_class_data8
:
7841 case dw_val_class_vms_delta
:
7842 size
+= DWARF_OFFSET_SIZE
;
7844 case dw_val_class_high_pc
:
7845 size
+= DWARF2_ADDR_SIZE
;
7855 /* Size the debugging information associated with a given DIE. Visits the
7856 DIE's children recursively. Updates the global variable next_die_offset, on
7857 each time through. Uses the current value of next_die_offset to update the
7858 die_offset field in each DIE. */
7861 calc_die_sizes (dw_die_ref die
)
7865 gcc_assert (die
->die_offset
== 0
7866 || (unsigned long int) die
->die_offset
== next_die_offset
);
7867 die
->die_offset
= next_die_offset
;
7868 next_die_offset
+= size_of_die (die
);
7870 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7872 if (die
->die_child
!= NULL
)
7873 /* Count the null byte used to terminate sibling lists. */
7874 next_die_offset
+= 1;
7877 /* Size just the base type children at the start of the CU.
7878 This is needed because build_abbrev needs to size locs
7879 and sizing of type based stack ops needs to know die_offset
7880 values for the base types. */
7883 calc_base_type_die_sizes (void)
7885 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7887 dw_die_ref base_type
;
7888 #if ENABLE_ASSERT_CHECKING
7889 dw_die_ref prev
= comp_unit_die ()->die_child
;
7892 die_offset
+= size_of_die (comp_unit_die ());
7893 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7895 #if ENABLE_ASSERT_CHECKING
7896 gcc_assert (base_type
->die_offset
== 0
7897 && prev
->die_sib
== base_type
7898 && base_type
->die_child
== NULL
7899 && base_type
->die_abbrev
);
7902 base_type
->die_offset
= die_offset
;
7903 die_offset
+= size_of_die (base_type
);
7907 /* Set the marks for a die and its children. We do this so
7908 that we know whether or not a reference needs to use FORM_ref_addr; only
7909 DIEs in the same CU will be marked. We used to clear out the offset
7910 and use that as the flag, but ran into ordering problems. */
7913 mark_dies (dw_die_ref die
)
7917 gcc_assert (!die
->die_mark
);
7920 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7923 /* Clear the marks for a die and its children. */
7926 unmark_dies (dw_die_ref die
)
7930 if (! use_debug_types
)
7931 gcc_assert (die
->die_mark
);
7934 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7937 /* Clear the marks for a die, its children and referred dies. */
7940 unmark_all_dies (dw_die_ref die
)
7950 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7952 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7953 if (AT_class (a
) == dw_val_class_die_ref
)
7954 unmark_all_dies (AT_ref (a
));
7957 /* Calculate if the entry should appear in the final output file. It may be
7958 from a pruned a type. */
7961 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
7963 if (table
== pubname_table
)
7965 /* Enumerator names are part of the pubname table, but the
7966 parent DW_TAG_enumeration_type die may have been pruned.
7967 Don't output them if that is the case. */
7968 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
7969 (p
->die
->die_parent
== NULL
7970 || !p
->die
->die_parent
->die_perennial_p
))
7973 /* Everything else in the pubname table is included. */
7977 /* The pubtypes table shouldn't include types that have been
7979 return (p
->die
->die_offset
!= 0
7980 || !flag_eliminate_unused_debug_types
);
7983 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7984 generated for the compilation unit. */
7986 static unsigned long
7987 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7993 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7994 FOR_EACH_VEC_ELT (*names
, i
, p
)
7995 if (include_pubname_in_output (names
, p
))
7996 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7998 size
+= DWARF_OFFSET_SIZE
;
8002 /* Return the size of the information in the .debug_aranges section. */
8004 static unsigned long
8005 size_of_aranges (void)
8009 size
= DWARF_ARANGES_HEADER_SIZE
;
8011 /* Count the address/length pair for this compilation unit. */
8012 if (text_section_used
)
8013 size
+= 2 * DWARF2_ADDR_SIZE
;
8014 if (cold_text_section_used
)
8015 size
+= 2 * DWARF2_ADDR_SIZE
;
8016 if (have_multiple_function_sections
)
8021 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8023 if (DECL_IGNORED_P (fde
->decl
))
8025 if (!fde
->in_std_section
)
8026 size
+= 2 * DWARF2_ADDR_SIZE
;
8027 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8028 size
+= 2 * DWARF2_ADDR_SIZE
;
8032 /* Count the two zero words used to terminated the address range table. */
8033 size
+= 2 * DWARF2_ADDR_SIZE
;
8037 /* Select the encoding of an attribute value. */
8039 static enum dwarf_form
8040 value_format (dw_attr_ref a
)
8042 switch (AT_class (a
))
8044 case dw_val_class_addr
:
8045 /* Only very few attributes allow DW_FORM_addr. */
8050 case DW_AT_entry_pc
:
8051 case DW_AT_trampoline
:
8052 return (AT_index (a
) == NOT_INDEXED
8053 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8057 switch (DWARF2_ADDR_SIZE
)
8060 return DW_FORM_data1
;
8062 return DW_FORM_data2
;
8064 return DW_FORM_data4
;
8066 return DW_FORM_data8
;
8070 case dw_val_class_range_list
:
8071 case dw_val_class_loc_list
:
8072 if (dwarf_version
>= 4)
8073 return DW_FORM_sec_offset
;
8075 case dw_val_class_vms_delta
:
8076 case dw_val_class_offset
:
8077 switch (DWARF_OFFSET_SIZE
)
8080 return DW_FORM_data4
;
8082 return DW_FORM_data8
;
8086 case dw_val_class_loc
:
8087 if (dwarf_version
>= 4)
8088 return DW_FORM_exprloc
;
8089 switch (constant_size (size_of_locs (AT_loc (a
))))
8092 return DW_FORM_block1
;
8094 return DW_FORM_block2
;
8096 return DW_FORM_block4
;
8100 case dw_val_class_const
:
8101 return DW_FORM_sdata
;
8102 case dw_val_class_unsigned_const
:
8103 switch (constant_size (AT_unsigned (a
)))
8106 return DW_FORM_data1
;
8108 return DW_FORM_data2
;
8110 /* In DWARF3 DW_AT_data_member_location with
8111 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8112 constant, so we need to use DW_FORM_udata if we need
8113 a large constant. */
8114 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8115 return DW_FORM_udata
;
8116 return DW_FORM_data4
;
8118 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8119 return DW_FORM_udata
;
8120 return DW_FORM_data8
;
8124 case dw_val_class_const_double
:
8125 switch (HOST_BITS_PER_WIDE_INT
)
8128 return DW_FORM_data2
;
8130 return DW_FORM_data4
;
8132 return DW_FORM_data8
;
8135 return DW_FORM_block1
;
8137 case dw_val_class_vec
:
8138 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8139 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8142 return DW_FORM_block1
;
8144 return DW_FORM_block2
;
8146 return DW_FORM_block4
;
8150 case dw_val_class_flag
:
8151 if (dwarf_version
>= 4)
8153 /* Currently all add_AT_flag calls pass in 1 as last argument,
8154 so DW_FORM_flag_present can be used. If that ever changes,
8155 we'll need to use DW_FORM_flag and have some optimization
8156 in build_abbrev_table that will change those to
8157 DW_FORM_flag_present if it is set to 1 in all DIEs using
8158 the same abbrev entry. */
8159 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8160 return DW_FORM_flag_present
;
8162 return DW_FORM_flag
;
8163 case dw_val_class_die_ref
:
8164 if (AT_ref_external (a
))
8165 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8168 case dw_val_class_fde_ref
:
8169 return DW_FORM_data
;
8170 case dw_val_class_lbl_id
:
8171 return (AT_index (a
) == NOT_INDEXED
8172 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8173 case dw_val_class_lineptr
:
8174 case dw_val_class_macptr
:
8175 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8176 case dw_val_class_str
:
8177 return AT_string_form (a
);
8178 case dw_val_class_file
:
8179 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8182 return DW_FORM_data1
;
8184 return DW_FORM_data2
;
8186 return DW_FORM_data4
;
8191 case dw_val_class_data8
:
8192 return DW_FORM_data8
;
8194 case dw_val_class_high_pc
:
8195 switch (DWARF2_ADDR_SIZE
)
8198 return DW_FORM_data1
;
8200 return DW_FORM_data2
;
8202 return DW_FORM_data4
;
8204 return DW_FORM_data8
;
8214 /* Output the encoding of an attribute value. */
8217 output_value_format (dw_attr_ref a
)
8219 enum dwarf_form form
= value_format (a
);
8221 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8224 /* Given a die and id, produce the appropriate abbreviations. */
8227 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8232 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8233 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8234 dwarf_tag_name (abbrev
->die_tag
));
8236 if (abbrev
->die_child
!= NULL
)
8237 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8239 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8241 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8243 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8244 dwarf_attr_name (a_attr
->dw_attr
));
8245 output_value_format (a_attr
);
8248 dw2_asm_output_data (1, 0, NULL
);
8249 dw2_asm_output_data (1, 0, NULL
);
8253 /* Output the .debug_abbrev section which defines the DIE abbreviation
8257 output_abbrev_section (void)
8259 unsigned long abbrev_id
;
8261 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8262 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8264 /* Terminate the table. */
8265 dw2_asm_output_data (1, 0, NULL
);
8268 /* Output a symbol we can use to refer to this DIE from another CU. */
8271 output_die_symbol (dw_die_ref die
)
8273 const char *sym
= die
->die_id
.die_symbol
;
8275 gcc_assert (!die
->comdat_type_p
);
8280 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8281 /* We make these global, not weak; if the target doesn't support
8282 .linkonce, it doesn't support combining the sections, so debugging
8284 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8286 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8289 /* Return a new location list, given the begin and end range, and the
8292 static inline dw_loc_list_ref
8293 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8294 const char *section
)
8296 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8298 retlist
->begin
= begin
;
8299 retlist
->begin_entry
= NULL
;
8301 retlist
->expr
= expr
;
8302 retlist
->section
= section
;
8307 /* Generate a new internal symbol for this location list node, if it
8308 hasn't got one yet. */
8311 gen_llsym (dw_loc_list_ref list
)
8313 gcc_assert (!list
->ll_symbol
);
8314 list
->ll_symbol
= gen_internal_sym ("LLST");
8317 /* Output the location list given to us. */
8320 output_loc_list (dw_loc_list_ref list_head
)
8322 dw_loc_list_ref curr
= list_head
;
8324 if (list_head
->emitted
)
8326 list_head
->emitted
= true;
8328 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8330 /* Walk the location list, and output each range + expression. */
8331 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8334 /* Don't output an entry that starts and ends at the same address. */
8335 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8337 size
= size_of_locs (curr
->expr
);
8338 /* If the expression is too large, drop it on the floor. We could
8339 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8340 in the expression, but >= 64KB expressions for a single value
8341 in a single range are unlikely very useful. */
8344 if (dwarf_split_debug_info
)
8346 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8347 "Location list start/length entry (%s)",
8348 list_head
->ll_symbol
);
8349 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8350 "Location list range start index (%s)",
8352 /* The length field is 4 bytes. If we ever need to support
8353 an 8-byte length, we can add a new DW_LLE code or fall back
8354 to DW_LLE_GNU_start_end_entry. */
8355 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8356 "Location list range length (%s)",
8357 list_head
->ll_symbol
);
8359 else if (!have_multiple_function_sections
)
8361 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8362 "Location list begin address (%s)",
8363 list_head
->ll_symbol
);
8364 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8365 "Location list end address (%s)",
8366 list_head
->ll_symbol
);
8370 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8371 "Location list begin address (%s)",
8372 list_head
->ll_symbol
);
8373 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8374 "Location list end address (%s)",
8375 list_head
->ll_symbol
);
8378 /* Output the block length for this list of location operations. */
8379 gcc_assert (size
<= 0xffff);
8380 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8382 output_loc_sequence (curr
->expr
, -1);
8385 if (dwarf_split_debug_info
)
8386 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8387 "Location list terminator (%s)",
8388 list_head
->ll_symbol
);
8391 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8392 "Location list terminator begin (%s)",
8393 list_head
->ll_symbol
);
8394 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8395 "Location list terminator end (%s)",
8396 list_head
->ll_symbol
);
8400 /* Output a range_list offset into the debug_range section. Emit a
8401 relocated reference if val_entry is NULL, otherwise, emit an
8402 indirect reference. */
8405 output_range_list_offset (dw_attr_ref a
)
8407 const char *name
= dwarf_attr_name (a
->dw_attr
);
8409 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8411 char *p
= strchr (ranges_section_label
, '\0');
8412 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8413 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8414 debug_ranges_section
, "%s", name
);
8418 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8419 "%s (offset from %s)", name
, ranges_section_label
);
8422 /* Output the offset into the debug_loc section. */
8425 output_loc_list_offset (dw_attr_ref a
)
8427 char *sym
= AT_loc_list (a
)->ll_symbol
;
8430 if (dwarf_split_debug_info
)
8431 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8432 "%s", dwarf_attr_name (a
->dw_attr
));
8434 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8435 "%s", dwarf_attr_name (a
->dw_attr
));
8438 /* Output an attribute's index or value appropriately. */
8441 output_attr_index_or_value (dw_attr_ref a
)
8443 const char *name
= dwarf_attr_name (a
->dw_attr
);
8445 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8447 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8450 switch (AT_class (a
))
8452 case dw_val_class_addr
:
8453 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8455 case dw_val_class_high_pc
:
8456 case dw_val_class_lbl_id
:
8457 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8459 case dw_val_class_loc_list
:
8460 output_loc_list_offset (a
);
8467 /* Output a type signature. */
8470 output_signature (const char *sig
, const char *name
)
8474 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8475 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8478 /* Output the DIE and its attributes. Called recursively to generate
8479 the definitions of each child DIE. */
8482 output_die (dw_die_ref die
)
8489 /* If someone in another CU might refer to us, set up a symbol for
8490 them to point to. */
8491 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8492 output_die_symbol (die
);
8494 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8495 (unsigned long)die
->die_offset
,
8496 dwarf_tag_name (die
->die_tag
));
8498 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8500 const char *name
= dwarf_attr_name (a
->dw_attr
);
8502 switch (AT_class (a
))
8504 case dw_val_class_addr
:
8505 output_attr_index_or_value (a
);
8508 case dw_val_class_offset
:
8509 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8513 case dw_val_class_range_list
:
8514 output_range_list_offset (a
);
8517 case dw_val_class_loc
:
8518 size
= size_of_locs (AT_loc (a
));
8520 /* Output the block length for this list of location operations. */
8521 if (dwarf_version
>= 4)
8522 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8524 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8526 output_loc_sequence (AT_loc (a
), -1);
8529 case dw_val_class_const
:
8530 /* ??? It would be slightly more efficient to use a scheme like is
8531 used for unsigned constants below, but gdb 4.x does not sign
8532 extend. Gdb 5.x does sign extend. */
8533 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8536 case dw_val_class_unsigned_const
:
8538 int csize
= constant_size (AT_unsigned (a
));
8539 if (dwarf_version
== 3
8540 && a
->dw_attr
== DW_AT_data_member_location
8542 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8544 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8548 case dw_val_class_const_double
:
8550 unsigned HOST_WIDE_INT first
, second
;
8552 if (HOST_BITS_PER_WIDE_INT
>= 64)
8553 dw2_asm_output_data (1,
8554 HOST_BITS_PER_DOUBLE_INT
8555 / HOST_BITS_PER_CHAR
,
8558 if (WORDS_BIG_ENDIAN
)
8560 first
= a
->dw_attr_val
.v
.val_double
.high
;
8561 second
= a
->dw_attr_val
.v
.val_double
.low
;
8565 first
= a
->dw_attr_val
.v
.val_double
.low
;
8566 second
= a
->dw_attr_val
.v
.val_double
.high
;
8569 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8571 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8576 case dw_val_class_vec
:
8578 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8579 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8583 dw2_asm_output_data (constant_size (len
* elt_size
),
8584 len
* elt_size
, "%s", name
);
8585 if (elt_size
> sizeof (HOST_WIDE_INT
))
8590 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8593 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8594 "fp or vector constant word %u", i
);
8598 case dw_val_class_flag
:
8599 if (dwarf_version
>= 4)
8601 /* Currently all add_AT_flag calls pass in 1 as last argument,
8602 so DW_FORM_flag_present can be used. If that ever changes,
8603 we'll need to use DW_FORM_flag and have some optimization
8604 in build_abbrev_table that will change those to
8605 DW_FORM_flag_present if it is set to 1 in all DIEs using
8606 the same abbrev entry. */
8607 gcc_assert (AT_flag (a
) == 1);
8609 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8610 ASM_COMMENT_START
, name
);
8613 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8616 case dw_val_class_loc_list
:
8617 output_attr_index_or_value (a
);
8620 case dw_val_class_die_ref
:
8621 if (AT_ref_external (a
))
8623 if (AT_ref (a
)->comdat_type_p
)
8625 comdat_type_node_ref type_node
=
8626 AT_ref (a
)->die_id
.die_type_node
;
8628 gcc_assert (type_node
);
8629 output_signature (type_node
->signature
, name
);
8633 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8637 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8638 length, whereas in DWARF3 it's always sized as an
8640 if (dwarf_version
== 2)
8641 size
= DWARF2_ADDR_SIZE
;
8643 size
= DWARF_OFFSET_SIZE
;
8644 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8650 gcc_assert (AT_ref (a
)->die_offset
);
8651 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8656 case dw_val_class_fde_ref
:
8660 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8661 a
->dw_attr_val
.v
.val_fde_index
* 2);
8662 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8667 case dw_val_class_vms_delta
:
8668 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8669 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8673 case dw_val_class_lbl_id
:
8674 output_attr_index_or_value (a
);
8677 case dw_val_class_lineptr
:
8678 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8679 debug_line_section
, "%s", name
);
8682 case dw_val_class_macptr
:
8683 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8684 debug_macinfo_section
, "%s", name
);
8687 case dw_val_class_str
:
8688 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8689 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8690 a
->dw_attr_val
.v
.val_str
->label
,
8692 "%s: \"%s\"", name
, AT_string (a
));
8693 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8694 dw2_asm_output_data_uleb128 (AT_index (a
),
8695 "%s: \"%s\"", name
, AT_string (a
));
8697 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8700 case dw_val_class_file
:
8702 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8704 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8705 a
->dw_attr_val
.v
.val_file
->filename
);
8709 case dw_val_class_data8
:
8713 for (i
= 0; i
< 8; i
++)
8714 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8715 i
== 0 ? "%s" : NULL
, name
);
8719 case dw_val_class_high_pc
:
8720 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8721 get_AT_low_pc (die
), "DW_AT_high_pc");
8729 FOR_EACH_CHILD (die
, c
, output_die (c
));
8731 /* Add null byte to terminate sibling list. */
8732 if (die
->die_child
!= NULL
)
8733 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8734 (unsigned long) die
->die_offset
);
8737 /* Output the compilation unit that appears at the beginning of the
8738 .debug_info section, and precedes the DIE descriptions. */
8741 output_compilation_unit_header (void)
8743 int ver
= dwarf_version
;
8745 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8746 dw2_asm_output_data (4, 0xffffffff,
8747 "Initial length escape value indicating 64-bit DWARF extension");
8748 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8749 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8750 "Length of Compilation Unit Info");
8751 dw2_asm_output_data (2, ver
, "DWARF version number");
8752 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8753 debug_abbrev_section
,
8754 "Offset Into Abbrev. Section");
8755 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8758 /* Output the compilation unit DIE and its children. */
8761 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8763 const char *secname
, *oldsym
;
8765 external_ref_hash_type extern_map
;
8767 /* Unless we are outputting main CU, we may throw away empty ones. */
8768 if (!output_if_empty
&& die
->die_child
== NULL
)
8771 /* Even if there are no children of this DIE, we must output the information
8772 about the compilation unit. Otherwise, on an empty translation unit, we
8773 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8774 will then complain when examining the file. First mark all the DIEs in
8775 this CU so we know which get local refs. */
8778 extern_map
= optimize_external_refs (die
);
8780 build_abbrev_table (die
, extern_map
);
8782 extern_map
.dispose ();
8784 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8785 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8786 calc_die_sizes (die
);
8788 oldsym
= die
->die_id
.die_symbol
;
8791 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8793 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8795 die
->die_id
.die_symbol
= NULL
;
8796 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8800 switch_to_section (debug_info_section
);
8801 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8802 info_section_emitted
= true;
8805 /* Output debugging information. */
8806 output_compilation_unit_header ();
8809 /* Leave the marks on the main CU, so we can check them in
8814 die
->die_id
.die_symbol
= oldsym
;
8818 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8819 and .debug_pubtypes. This is configured per-target, but can be
8820 overridden by the -gpubnames or -gno-pubnames options. */
8823 want_pubnames (void)
8825 if (debug_generate_pub_sections
!= -1)
8826 return debug_generate_pub_sections
;
8827 return targetm
.want_debug_pub_sections
;
8830 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8833 add_AT_pubnames (dw_die_ref die
)
8835 if (want_pubnames ())
8836 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8839 /* Add a string attribute value to a skeleton DIE. */
8842 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8846 struct indirect_string_node
*node
;
8848 if (! skeleton_debug_str_hash
)
8849 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8850 debug_str_eq
, NULL
);
8852 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8853 find_string_form (node
);
8854 if (node
->form
== DW_FORM_GNU_str_index
)
8855 node
->form
= DW_FORM_strp
;
8857 attr
.dw_attr
= attr_kind
;
8858 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8859 attr
.dw_attr_val
.val_entry
= NULL
;
8860 attr
.dw_attr_val
.v
.val_str
= node
;
8861 add_dwarf_attr (die
, &attr
);
8864 /* Helper function to generate top-level dies for skeleton debug_info and
8868 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8870 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8871 const char *comp_dir
= comp_dir_string ();
8873 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8874 if (comp_dir
!= NULL
)
8875 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8876 add_AT_pubnames (die
);
8877 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8880 /* Return the single type-unit die for skeleton type units. */
8883 get_skeleton_type_unit (void)
8885 /* For dwarf_split_debug_sections with use_type info, all type units in the
8886 skeleton sections have identical dies (but different headers). This
8887 single die will be output many times. */
8889 static dw_die_ref skeleton_type_unit
= NULL
;
8891 if (skeleton_type_unit
== NULL
)
8893 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8894 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8895 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8897 return skeleton_type_unit
;
8900 /* Output skeleton debug sections that point to the dwo file. */
8903 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8905 /* These attributes will be found in the full debug_info section. */
8906 remove_AT (comp_unit
, DW_AT_producer
);
8907 remove_AT (comp_unit
, DW_AT_language
);
8909 switch_to_section (debug_skeleton_info_section
);
8910 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8912 /* Produce the skeleton compilation-unit header. This one differs enough from
8913 a normal CU header that it's better not to call output_compilation_unit
8915 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8916 dw2_asm_output_data (4, 0xffffffff,
8917 "Initial length escape value indicating 64-bit DWARF extension");
8919 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8920 DWARF_COMPILE_UNIT_HEADER_SIZE
8921 - DWARF_INITIAL_LENGTH_SIZE
8922 + size_of_die (comp_unit
),
8923 "Length of Compilation Unit Info");
8924 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8925 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8926 debug_abbrev_section
,
8927 "Offset Into Abbrev. Section");
8928 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8930 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8931 output_die (comp_unit
);
8933 /* Build the skeleton debug_abbrev section. */
8934 switch_to_section (debug_skeleton_abbrev_section
);
8935 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8937 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8938 if (use_debug_types
)
8939 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8941 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8944 /* Output a comdat type unit DIE and its children. */
8947 output_comdat_type_unit (comdat_type_node
*node
)
8949 const char *secname
;
8952 #if defined (OBJECT_FORMAT_ELF)
8955 external_ref_hash_type extern_map
;
8957 /* First mark all the DIEs in this CU so we know which get local refs. */
8958 mark_dies (node
->root_die
);
8960 extern_map
= optimize_external_refs (node
->root_die
);
8962 build_abbrev_table (node
->root_die
, extern_map
);
8964 extern_map
.dispose ();
8966 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8967 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8968 calc_die_sizes (node
->root_die
);
8970 #if defined (OBJECT_FORMAT_ELF)
8971 if (!dwarf_split_debug_info
)
8972 secname
= ".debug_types";
8974 secname
= ".debug_types.dwo";
8976 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8977 sprintf (tmp
, "wt.");
8978 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8979 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8980 comdat_key
= get_identifier (tmp
);
8981 targetm
.asm_out
.named_section (secname
,
8982 SECTION_DEBUG
| SECTION_LINKONCE
,
8985 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8986 sprintf (tmp
, ".gnu.linkonce.wt.");
8987 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8988 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8990 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8993 /* Output debugging information. */
8994 output_compilation_unit_header ();
8995 output_signature (node
->signature
, "Type Signature");
8996 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8997 "Offset to Type DIE");
8998 output_die (node
->root_die
);
9000 unmark_dies (node
->root_die
);
9002 #if defined (OBJECT_FORMAT_ELF)
9003 if (dwarf_split_debug_info
)
9005 /* Produce the skeleton type-unit header. */
9006 const char *secname
= ".debug_types";
9008 targetm
.asm_out
.named_section (secname
,
9009 SECTION_DEBUG
| SECTION_LINKONCE
,
9011 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9012 dw2_asm_output_data (4, 0xffffffff,
9013 "Initial length escape value indicating 64-bit DWARF extension");
9015 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9016 DWARF_COMPILE_UNIT_HEADER_SIZE
9017 - DWARF_INITIAL_LENGTH_SIZE
9018 + size_of_die (get_skeleton_type_unit ())
9019 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9020 "Length of Type Unit Info");
9021 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9022 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9023 debug_skeleton_abbrev_section_label
,
9024 debug_abbrev_section
,
9025 "Offset Into Abbrev. Section");
9026 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9027 output_signature (node
->signature
, "Type Signature");
9028 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9030 output_die (get_skeleton_type_unit ());
9035 /* Return the DWARF2/3 pubname associated with a decl. */
9038 dwarf2_name (tree decl
, int scope
)
9040 if (DECL_NAMELESS (decl
))
9042 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9045 /* Add a new entry to .debug_pubnames if appropriate. */
9048 add_pubname_string (const char *str
, dw_die_ref die
)
9053 e
.name
= xstrdup (str
);
9054 vec_safe_push (pubname_table
, e
);
9058 add_pubname (tree decl
, dw_die_ref die
)
9060 if (!want_pubnames ())
9063 /* Don't add items to the table when we expect that the consumer will have
9064 just read the enclosing die. For example, if the consumer is looking at a
9065 class_member, it will either be inside the class already, or will have just
9066 looked up the class to find the member. Either way, searching the class is
9067 faster than searching the index. */
9068 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9069 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9071 const char *name
= dwarf2_name (decl
, 1);
9074 add_pubname_string (name
, die
);
9078 /* Add an enumerator to the pubnames section. */
9081 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9085 gcc_assert (scope_name
);
9086 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9088 vec_safe_push (pubname_table
, e
);
9091 /* Add a new entry to .debug_pubtypes if appropriate. */
9094 add_pubtype (tree decl
, dw_die_ref die
)
9098 if (!want_pubnames ())
9101 if ((TREE_PUBLIC (decl
)
9102 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9103 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9106 const char *scope_name
= "";
9107 const char *sep
= is_cxx () ? "::" : ".";
9110 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9111 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9113 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9114 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9115 scope_name
= concat (scope_name
, sep
, NULL
);
9121 name
= type_tag (decl
);
9123 name
= lang_hooks
.dwarf_name (decl
, 1);
9125 /* If we don't have a name for the type, there's no point in adding
9127 if (name
!= NULL
&& name
[0] != '\0')
9130 e
.name
= concat (scope_name
, name
, NULL
);
9131 vec_safe_push (pubtype_table
, e
);
9134 /* Although it might be more consistent to add the pubinfo for the
9135 enumerators as their dies are created, they should only be added if the
9136 enum type meets the criteria above. So rather than re-check the parent
9137 enum type whenever an enumerator die is created, just output them all
9138 here. This isn't protected by the name conditional because anonymous
9139 enums don't have names. */
9140 if (die
->die_tag
== DW_TAG_enumeration_type
)
9144 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9149 /* Output the public names table used to speed up access to externally
9150 visible names; or the public types table used to find type definitions. */
9153 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9156 unsigned long pubnames_length
= size_of_pubnames (names
);
9159 if (!want_pubnames () || !info_section_emitted
)
9161 if (names
== pubname_table
)
9162 switch_to_section (debug_pubnames_section
);
9164 switch_to_section (debug_pubtypes_section
);
9165 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9166 dw2_asm_output_data (4, 0xffffffff,
9167 "Initial length escape value indicating 64-bit DWARF extension");
9168 if (names
== pubname_table
)
9169 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9170 "Length of Public Names Info");
9172 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9173 "Length of Public Type Names Info");
9174 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9175 dw2_asm_output_data (2, 2, "DWARF Version");
9176 if (dwarf_split_debug_info
)
9177 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9178 debug_skeleton_info_section
,
9179 "Offset of Compilation Unit Info");
9181 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9183 "Offset of Compilation Unit Info");
9184 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9185 "Compilation Unit Length");
9187 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9189 if (include_pubname_in_output (names
, pub
))
9191 dw_offset die_offset
= pub
->die
->die_offset
;
9193 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9194 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9195 gcc_assert (pub
->die
->die_mark
);
9197 /* If we're putting types in their own .debug_types sections,
9198 the .debug_pubtypes table will still point to the compile
9199 unit (not the type unit), so we want to use the offset of
9200 the skeleton DIE (if there is one). */
9201 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9203 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9205 if (type_node
!= NULL
)
9206 die_offset
= (type_node
->skeleton_die
!= NULL
9207 ? type_node
->skeleton_die
->die_offset
9211 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9213 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9217 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9220 /* Output the information that goes into the .debug_aranges table.
9221 Namely, define the beginning and ending address range of the
9222 text section generated for this compilation unit. */
9225 output_aranges (unsigned long aranges_length
)
9229 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9230 dw2_asm_output_data (4, 0xffffffff,
9231 "Initial length escape value indicating 64-bit DWARF extension");
9232 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9233 "Length of Address Ranges Info");
9234 /* Version number for aranges is still 2, even in DWARF3. */
9235 dw2_asm_output_data (2, 2, "DWARF Version");
9236 if (dwarf_split_debug_info
)
9237 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9238 debug_skeleton_info_section
,
9239 "Offset of Compilation Unit Info");
9241 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9243 "Offset of Compilation Unit Info");
9244 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9245 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9247 /* We need to align to twice the pointer size here. */
9248 if (DWARF_ARANGES_PAD_SIZE
)
9250 /* Pad using a 2 byte words so that padding is correct for any
9252 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9253 2 * DWARF2_ADDR_SIZE
);
9254 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9255 dw2_asm_output_data (2, 0, NULL
);
9258 /* It is necessary not to output these entries if the sections were
9259 not used; if the sections were not used, the length will be 0 and
9260 the address may end up as 0 if the section is discarded by ld
9261 --gc-sections, leaving an invalid (0, 0) entry that can be
9262 confused with the terminator. */
9263 if (text_section_used
)
9265 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9266 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9267 text_section_label
, "Length");
9269 if (cold_text_section_used
)
9271 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9273 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9274 cold_text_section_label
, "Length");
9277 if (have_multiple_function_sections
)
9282 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9284 if (DECL_IGNORED_P (fde
->decl
))
9286 if (!fde
->in_std_section
)
9288 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9290 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9291 fde
->dw_fde_begin
, "Length");
9293 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9295 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9297 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9298 fde
->dw_fde_second_begin
, "Length");
9303 /* Output the terminator words. */
9304 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9305 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9308 /* Add a new entry to .debug_ranges. Return the offset at which it
9312 add_ranges_num (int num
)
9314 unsigned int in_use
= ranges_table_in_use
;
9316 if (in_use
== ranges_table_allocated
)
9318 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9319 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9320 ranges_table_allocated
);
9321 memset (ranges_table
+ ranges_table_in_use
, 0,
9322 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9325 ranges_table
[in_use
].num
= num
;
9326 ranges_table_in_use
= in_use
+ 1;
9328 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9331 /* Add a new entry to .debug_ranges corresponding to a block, or a
9332 range terminator if BLOCK is NULL. */
9335 add_ranges (const_tree block
)
9337 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9340 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9341 When using dwarf_split_debug_info, address attributes in dies destined
9342 for the final executable should be direct references--setting the
9343 parameter force_direct ensures this behavior. */
9346 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9347 bool *added
, bool force_direct
)
9349 unsigned int in_use
= ranges_by_label_in_use
;
9350 unsigned int offset
;
9352 if (in_use
== ranges_by_label_allocated
)
9354 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9355 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9357 ranges_by_label_allocated
);
9358 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9359 RANGES_TABLE_INCREMENT
9360 * sizeof (struct dw_ranges_by_label_struct
));
9363 ranges_by_label
[in_use
].begin
= begin
;
9364 ranges_by_label
[in_use
].end
= end
;
9365 ranges_by_label_in_use
= in_use
+ 1;
9367 offset
= add_ranges_num (-(int)in_use
- 1);
9370 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9376 output_ranges (void)
9379 static const char *const start_fmt
= "Offset %#x";
9380 const char *fmt
= start_fmt
;
9382 for (i
= 0; i
< ranges_table_in_use
; i
++)
9384 int block_num
= ranges_table
[i
].num
;
9388 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9389 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9391 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9392 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9394 /* If all code is in the text section, then the compilation
9395 unit base address defaults to DW_AT_low_pc, which is the
9396 base of the text section. */
9397 if (!have_multiple_function_sections
)
9399 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9401 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9402 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9403 text_section_label
, NULL
);
9406 /* Otherwise, the compilation unit base address is zero,
9407 which allows us to use absolute addresses, and not worry
9408 about whether the target supports cross-section
9412 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9413 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9414 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9420 /* Negative block_num stands for an index into ranges_by_label. */
9421 else if (block_num
< 0)
9423 int lab_idx
= - block_num
- 1;
9425 if (!have_multiple_function_sections
)
9429 /* If we ever use add_ranges_by_labels () for a single
9430 function section, all we have to do is to take out
9432 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9433 ranges_by_label
[lab_idx
].begin
,
9435 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9436 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9437 ranges_by_label
[lab_idx
].end
,
9438 text_section_label
, NULL
);
9443 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9444 ranges_by_label
[lab_idx
].begin
,
9445 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9446 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9447 ranges_by_label
[lab_idx
].end
,
9453 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9454 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9460 /* Data structure containing information about input files. */
9463 const char *path
; /* Complete file name. */
9464 const char *fname
; /* File name part. */
9465 int length
; /* Length of entire string. */
9466 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9467 int dir_idx
; /* Index in directory table. */
9470 /* Data structure containing information about directories with source
9474 const char *path
; /* Path including directory name. */
9475 int length
; /* Path length. */
9476 int prefix
; /* Index of directory entry which is a prefix. */
9477 int count
; /* Number of files in this directory. */
9478 int dir_idx
; /* Index of directory used as base. */
9481 /* Callback function for file_info comparison. We sort by looking at
9482 the directories in the path. */
9485 file_info_cmp (const void *p1
, const void *p2
)
9487 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9488 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9489 const unsigned char *cp1
;
9490 const unsigned char *cp2
;
9492 /* Take care of file names without directories. We need to make sure that
9493 we return consistent values to qsort since some will get confused if
9494 we return the same value when identical operands are passed in opposite
9495 orders. So if neither has a directory, return 0 and otherwise return
9496 1 or -1 depending on which one has the directory. */
9497 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9498 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9500 cp1
= (const unsigned char *) s1
->path
;
9501 cp2
= (const unsigned char *) s2
->path
;
9507 /* Reached the end of the first path? If so, handle like above. */
9508 if ((cp1
== (const unsigned char *) s1
->fname
)
9509 || (cp2
== (const unsigned char *) s2
->fname
))
9510 return ((cp2
== (const unsigned char *) s2
->fname
)
9511 - (cp1
== (const unsigned char *) s1
->fname
));
9513 /* Character of current path component the same? */
9514 else if (*cp1
!= *cp2
)
9519 struct file_name_acquire_data
9521 struct file_info
*files
;
9526 /* Traversal function for the hash table. */
9529 file_name_acquire (void ** slot
, void *data
)
9531 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9532 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9533 struct file_info
*fi
;
9536 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9538 if (! d
->emitted_number
)
9541 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9543 fi
= fnad
->files
+ fnad
->used_files
++;
9545 /* Skip all leading "./". */
9547 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9550 /* Create a new array entry. */
9552 fi
->length
= strlen (f
);
9555 /* Search for the file name part. */
9556 f
= strrchr (f
, DIR_SEPARATOR
);
9557 #if defined (DIR_SEPARATOR_2)
9559 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9563 if (f
== NULL
|| f
< g
)
9569 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9573 /* Output the directory table and the file name table. We try to minimize
9574 the total amount of memory needed. A heuristic is used to avoid large
9575 slowdowns with many input files. */
9578 output_file_names (void)
9580 struct file_name_acquire_data fnad
;
9582 struct file_info
*files
;
9583 struct dir_info
*dirs
;
9591 if (!last_emitted_file
)
9593 dw2_asm_output_data (1, 0, "End directory table");
9594 dw2_asm_output_data (1, 0, "End file name table");
9598 numfiles
= last_emitted_file
->emitted_number
;
9600 /* Allocate the various arrays we need. */
9601 files
= XALLOCAVEC (struct file_info
, numfiles
);
9602 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9605 fnad
.used_files
= 0;
9606 fnad
.max_files
= numfiles
;
9607 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9608 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9610 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9612 /* Find all the different directories used. */
9613 dirs
[0].path
= files
[0].path
;
9614 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9615 dirs
[0].prefix
= -1;
9617 dirs
[0].dir_idx
= 0;
9618 files
[0].dir_idx
= 0;
9621 for (i
= 1; i
< numfiles
; i
++)
9622 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9623 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9624 dirs
[ndirs
- 1].length
) == 0)
9626 /* Same directory as last entry. */
9627 files
[i
].dir_idx
= ndirs
- 1;
9628 ++dirs
[ndirs
- 1].count
;
9634 /* This is a new directory. */
9635 dirs
[ndirs
].path
= files
[i
].path
;
9636 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9637 dirs
[ndirs
].count
= 1;
9638 dirs
[ndirs
].dir_idx
= ndirs
;
9639 files
[i
].dir_idx
= ndirs
;
9641 /* Search for a prefix. */
9642 dirs
[ndirs
].prefix
= -1;
9643 for (j
= 0; j
< ndirs
; j
++)
9644 if (dirs
[j
].length
< dirs
[ndirs
].length
9645 && dirs
[j
].length
> 1
9646 && (dirs
[ndirs
].prefix
== -1
9647 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9648 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9649 dirs
[ndirs
].prefix
= j
;
9654 /* Now to the actual work. We have to find a subset of the directories which
9655 allow expressing the file name using references to the directory table
9656 with the least amount of characters. We do not do an exhaustive search
9657 where we would have to check out every combination of every single
9658 possible prefix. Instead we use a heuristic which provides nearly optimal
9659 results in most cases and never is much off. */
9660 saved
= XALLOCAVEC (int, ndirs
);
9661 savehere
= XALLOCAVEC (int, ndirs
);
9663 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9664 for (i
= 0; i
< ndirs
; i
++)
9669 /* We can always save some space for the current directory. But this
9670 does not mean it will be enough to justify adding the directory. */
9671 savehere
[i
] = dirs
[i
].length
;
9672 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9674 for (j
= i
+ 1; j
< ndirs
; j
++)
9677 if (saved
[j
] < dirs
[i
].length
)
9679 /* Determine whether the dirs[i] path is a prefix of the
9684 while (k
!= -1 && k
!= (int) i
)
9689 /* Yes it is. We can possibly save some memory by
9690 writing the filenames in dirs[j] relative to
9692 savehere
[j
] = dirs
[i
].length
;
9693 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9698 /* Check whether we can save enough to justify adding the dirs[i]
9700 if (total
> dirs
[i
].length
+ 1)
9702 /* It's worthwhile adding. */
9703 for (j
= i
; j
< ndirs
; j
++)
9704 if (savehere
[j
] > 0)
9706 /* Remember how much we saved for this directory so far. */
9707 saved
[j
] = savehere
[j
];
9709 /* Remember the prefix directory. */
9710 dirs
[j
].dir_idx
= i
;
9715 /* Emit the directory name table. */
9716 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9717 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9718 dw2_asm_output_nstring (dirs
[i
].path
,
9720 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9721 "Directory Entry: %#x", i
+ idx_offset
);
9723 dw2_asm_output_data (1, 0, "End directory table");
9725 /* We have to emit them in the order of emitted_number since that's
9726 used in the debug info generation. To do this efficiently we
9727 generate a back-mapping of the indices first. */
9728 backmap
= XALLOCAVEC (int, numfiles
);
9729 for (i
= 0; i
< numfiles
; i
++)
9730 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9732 /* Now write all the file names. */
9733 for (i
= 0; i
< numfiles
; i
++)
9735 int file_idx
= backmap
[i
];
9736 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9738 #ifdef VMS_DEBUGGING_INFO
9739 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9741 /* Setting these fields can lead to debugger miscomparisons,
9742 but VMS Debug requires them to be set correctly. */
9747 int maxfilelen
= strlen (files
[file_idx
].path
)
9748 + dirs
[dir_idx
].length
9749 + MAX_VMS_VERSION_LEN
+ 1;
9750 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9752 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9753 snprintf (filebuf
, maxfilelen
, "%s;%d",
9754 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9756 dw2_asm_output_nstring
9757 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9759 /* Include directory index. */
9760 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9762 /* Modification time. */
9763 dw2_asm_output_data_uleb128
9764 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9768 /* File length in bytes. */
9769 dw2_asm_output_data_uleb128
9770 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9774 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9775 "File Entry: %#x", (unsigned) i
+ 1);
9777 /* Include directory index. */
9778 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9780 /* Modification time. */
9781 dw2_asm_output_data_uleb128 (0, NULL
);
9783 /* File length in bytes. */
9784 dw2_asm_output_data_uleb128 (0, NULL
);
9785 #endif /* VMS_DEBUGGING_INFO */
9788 dw2_asm_output_data (1, 0, "End file name table");
9792 /* Output one line number table into the .debug_line section. */
9795 output_one_line_info_table (dw_line_info_table
*table
)
9797 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9798 unsigned int current_line
= 1;
9799 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9800 dw_line_info_entry
*ent
;
9803 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9805 switch (ent
->opcode
)
9807 case LI_set_address
:
9808 /* ??? Unfortunately, we have little choice here currently, and
9809 must always use the most general form. GCC does not know the
9810 address delta itself, so we can't use DW_LNS_advance_pc. Many
9811 ports do have length attributes which will give an upper bound
9812 on the address range. We could perhaps use length attributes
9813 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9814 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9816 /* This can handle any delta. This takes
9817 4+DWARF2_ADDR_SIZE bytes. */
9818 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9819 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9820 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9821 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9825 if (ent
->val
== current_line
)
9827 /* We still need to start a new row, so output a copy insn. */
9828 dw2_asm_output_data (1, DW_LNS_copy
,
9829 "copy line %u", current_line
);
9833 int line_offset
= ent
->val
- current_line
;
9834 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9836 current_line
= ent
->val
;
9837 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9839 /* This can handle deltas from -10 to 234, using the current
9840 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9841 This takes 1 byte. */
9842 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9843 "line %u", current_line
);
9847 /* This can handle any delta. This takes at least 4 bytes,
9848 depending on the value being encoded. */
9849 dw2_asm_output_data (1, DW_LNS_advance_line
,
9850 "advance to line %u", current_line
);
9851 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9852 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9858 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9859 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9863 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9864 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9867 case LI_negate_stmt
:
9868 current_is_stmt
= !current_is_stmt
;
9869 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9870 "is_stmt %d", current_is_stmt
);
9873 case LI_set_prologue_end
:
9874 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9875 "set prologue end");
9878 case LI_set_epilogue_begin
:
9879 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9880 "set epilogue begin");
9883 case LI_set_discriminator
:
9884 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9885 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9886 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9887 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9892 /* Emit debug info for the address of the end of the table. */
9893 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9894 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9895 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9896 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9898 dw2_asm_output_data (1, 0, "end sequence");
9899 dw2_asm_output_data_uleb128 (1, NULL
);
9900 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9903 /* Output the source line number correspondence information. This
9904 information goes into the .debug_line section. */
9907 output_line_info (bool prologue_only
)
9909 char l1
[20], l2
[20], p1
[20], p2
[20];
9910 int ver
= dwarf_version
;
9911 bool saw_one
= false;
9914 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9915 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9916 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9917 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9919 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9920 dw2_asm_output_data (4, 0xffffffff,
9921 "Initial length escape value indicating 64-bit DWARF extension");
9922 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9923 "Length of Source Line Info");
9924 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9926 dw2_asm_output_data (2, ver
, "DWARF Version");
9927 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9928 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9930 /* Define the architecture-dependent minimum instruction length (in bytes).
9931 In this implementation of DWARF, this field is used for information
9932 purposes only. Since GCC generates assembly language, we have no
9933 a priori knowledge of how many instruction bytes are generated for each
9934 source line, and therefore can use only the DW_LNE_set_address and
9935 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9936 this as '1', which is "correct enough" for all architectures,
9937 and don't let the target override. */
9938 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9941 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9942 "Maximum Operations Per Instruction");
9943 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9944 "Default is_stmt_start flag");
9945 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9946 "Line Base Value (Special Opcodes)");
9947 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9948 "Line Range Value (Special Opcodes)");
9949 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9950 "Special Opcode Base");
9952 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9957 case DW_LNS_advance_pc
:
9958 case DW_LNS_advance_line
:
9959 case DW_LNS_set_file
:
9960 case DW_LNS_set_column
:
9961 case DW_LNS_fixed_advance_pc
:
9962 case DW_LNS_set_isa
:
9970 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9974 /* Write out the information about the files we use. */
9975 output_file_names ();
9976 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9979 /* Output the marker for the end of the line number info. */
9980 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9984 if (separate_line_info
)
9986 dw_line_info_table
*table
;
9989 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9992 output_one_line_info_table (table
);
9996 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9998 output_one_line_info_table (cold_text_section_line_info
);
10002 /* ??? Some Darwin linkers crash on a .debug_line section with no
10003 sequences. Further, merely a DW_LNE_end_sequence entry is not
10004 sufficient -- the address column must also be initialized.
10005 Make sure to output at least one set_address/end_sequence pair,
10006 choosing .text since that section is always present. */
10007 if (text_section_line_info
->in_use
|| !saw_one
)
10008 output_one_line_info_table (text_section_line_info
);
10010 /* Output the marker for the end of the line number info. */
10011 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10014 /* Given a pointer to a tree node for some base type, return a pointer to
10015 a DIE that describes the given type.
10017 This routine must only be called for GCC type nodes that correspond to
10018 Dwarf base (fundamental) types. */
10021 base_type_die (tree type
)
10023 dw_die_ref base_type_result
;
10024 enum dwarf_type encoding
;
10026 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10029 /* If this is a subtype that should not be emitted as a subrange type,
10030 use the base type. See subrange_type_for_debug_p. */
10031 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10032 type
= TREE_TYPE (type
);
10034 switch (TREE_CODE (type
))
10037 if ((dwarf_version
>= 4 || !dwarf_strict
)
10038 && TYPE_NAME (type
)
10039 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10040 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10041 && DECL_NAME (TYPE_NAME (type
)))
10043 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10044 if (strcmp (name
, "char16_t") == 0
10045 || strcmp (name
, "char32_t") == 0)
10047 encoding
= DW_ATE_UTF
;
10051 if (TYPE_STRING_FLAG (type
))
10053 if (TYPE_UNSIGNED (type
))
10054 encoding
= DW_ATE_unsigned_char
;
10056 encoding
= DW_ATE_signed_char
;
10058 else if (TYPE_UNSIGNED (type
))
10059 encoding
= DW_ATE_unsigned
;
10061 encoding
= DW_ATE_signed
;
10065 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10067 if (dwarf_version
>= 3 || !dwarf_strict
)
10068 encoding
= DW_ATE_decimal_float
;
10070 encoding
= DW_ATE_lo_user
;
10073 encoding
= DW_ATE_float
;
10076 case FIXED_POINT_TYPE
:
10077 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10078 encoding
= DW_ATE_lo_user
;
10079 else if (TYPE_UNSIGNED (type
))
10080 encoding
= DW_ATE_unsigned_fixed
;
10082 encoding
= DW_ATE_signed_fixed
;
10085 /* Dwarf2 doesn't know anything about complex ints, so use
10086 a user defined type for it. */
10088 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10089 encoding
= DW_ATE_complex_float
;
10091 encoding
= DW_ATE_lo_user
;
10095 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10096 encoding
= DW_ATE_boolean
;
10100 /* No other TREE_CODEs are Dwarf fundamental types. */
10101 gcc_unreachable ();
10104 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10106 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10107 int_size_in_bytes (type
));
10108 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10109 add_pubtype (type
, base_type_result
);
10111 return base_type_result
;
10114 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10115 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10118 is_base_type (tree type
)
10120 switch (TREE_CODE (type
))
10126 case FIXED_POINT_TYPE
:
10134 case QUAL_UNION_TYPE
:
10135 case ENUMERAL_TYPE
:
10136 case FUNCTION_TYPE
:
10139 case REFERENCE_TYPE
:
10147 gcc_unreachable ();
10153 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10154 node, return the size in bits for the type if it is a constant, or else
10155 return the alignment for the type if the type's size is not constant, or
10156 else return BITS_PER_WORD if the type actually turns out to be an
10157 ERROR_MARK node. */
10159 static inline unsigned HOST_WIDE_INT
10160 simple_type_size_in_bits (const_tree type
)
10162 if (TREE_CODE (type
) == ERROR_MARK
)
10163 return BITS_PER_WORD
;
10164 else if (TYPE_SIZE (type
) == NULL_TREE
)
10166 else if (host_integerp (TYPE_SIZE (type
), 1))
10167 return tree_low_cst (TYPE_SIZE (type
), 1);
10169 return TYPE_ALIGN (type
);
10172 /* Similarly, but return a double_int instead of UHWI. */
10174 static inline double_int
10175 double_int_type_size_in_bits (const_tree type
)
10177 if (TREE_CODE (type
) == ERROR_MARK
)
10178 return double_int::from_uhwi (BITS_PER_WORD
);
10179 else if (TYPE_SIZE (type
) == NULL_TREE
)
10180 return double_int_zero
;
10181 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10182 return tree_to_double_int (TYPE_SIZE (type
));
10184 return double_int::from_uhwi (TYPE_ALIGN (type
));
10187 /* Given a pointer to a tree node for a subrange type, return a pointer
10188 to a DIE that describes the given type. */
10191 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10193 dw_die_ref subrange_die
;
10194 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10196 if (context_die
== NULL
)
10197 context_die
= comp_unit_die ();
10199 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10201 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10203 /* The size of the subrange type and its base type do not match,
10204 so we need to generate a size attribute for the subrange type. */
10205 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10209 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10211 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10213 return subrange_die
;
10216 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10217 entry that chains various modifiers in front of the given type. */
10220 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10221 dw_die_ref context_die
)
10223 enum tree_code code
= TREE_CODE (type
);
10224 dw_die_ref mod_type_die
;
10225 dw_die_ref sub_die
= NULL
;
10226 tree item_type
= NULL
;
10227 tree qualified_type
;
10228 tree name
, low
, high
;
10229 dw_die_ref mod_scope
;
10231 if (code
== ERROR_MARK
)
10234 /* See if we already have the appropriately qualified variant of
10237 = get_qualified_type (type
,
10238 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10239 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10241 if (qualified_type
== sizetype
10242 && TYPE_NAME (qualified_type
)
10243 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10245 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10247 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10248 && TYPE_PRECISION (t
)
10249 == TYPE_PRECISION (qualified_type
)
10250 && TYPE_UNSIGNED (t
)
10251 == TYPE_UNSIGNED (qualified_type
));
10252 qualified_type
= t
;
10255 /* If we do, then we can just use its DIE, if it exists. */
10256 if (qualified_type
)
10258 mod_type_die
= lookup_type_die (qualified_type
);
10260 return mod_type_die
;
10263 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10265 /* Handle C typedef types. */
10266 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10267 && !DECL_ARTIFICIAL (name
))
10269 tree dtype
= TREE_TYPE (name
);
10271 if (qualified_type
== dtype
)
10273 /* For a named type, use the typedef. */
10274 gen_type_die (qualified_type
, context_die
);
10275 return lookup_type_die (qualified_type
);
10277 else if (is_const_type
< TYPE_READONLY (dtype
)
10278 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10279 || (is_const_type
<= TYPE_READONLY (dtype
)
10280 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10281 && DECL_ORIGINAL_TYPE (name
) != type
))
10282 /* cv-unqualified version of named type. Just use the unnamed
10283 type to which it refers. */
10284 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10285 is_const_type
, is_volatile_type
,
10287 /* Else cv-qualified version of named type; fall through. */
10290 mod_scope
= scope_die_for (type
, context_die
);
10293 /* If both is_const_type and is_volatile_type, prefer the path
10294 which leads to a qualified type. */
10295 && (!is_volatile_type
10296 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10297 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10299 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10300 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10302 else if (is_volatile_type
)
10304 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10305 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10307 else if (code
== POINTER_TYPE
)
10309 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10310 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10311 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10312 item_type
= TREE_TYPE (type
);
10313 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10314 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10315 TYPE_ADDR_SPACE (item_type
));
10317 else if (code
== REFERENCE_TYPE
)
10319 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10320 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10323 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10324 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10325 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10326 item_type
= TREE_TYPE (type
);
10327 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10328 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10329 TYPE_ADDR_SPACE (item_type
));
10331 else if (code
== INTEGER_TYPE
10332 && TREE_TYPE (type
) != NULL_TREE
10333 && subrange_type_for_debug_p (type
, &low
, &high
))
10335 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10336 item_type
= TREE_TYPE (type
);
10338 else if (is_base_type (type
))
10339 mod_type_die
= base_type_die (type
);
10342 gen_type_die (type
, context_die
);
10344 /* We have to get the type_main_variant here (and pass that to the
10345 `lookup_type_die' routine) because the ..._TYPE node we have
10346 might simply be a *copy* of some original type node (where the
10347 copy was created to help us keep track of typedef names) and
10348 that copy might have a different TYPE_UID from the original
10350 if (TREE_CODE (type
) != VECTOR_TYPE
)
10351 return lookup_type_die (type_main_variant (type
));
10353 /* Vectors have the debugging information in the type,
10354 not the main variant. */
10355 return lookup_type_die (type
);
10358 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10359 don't output a DW_TAG_typedef, since there isn't one in the
10360 user's program; just attach a DW_AT_name to the type.
10361 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10362 if the base type already has the same name. */
10364 && ((TREE_CODE (name
) != TYPE_DECL
10365 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10366 || (!is_const_type
&& !is_volatile_type
)))
10367 || (TREE_CODE (name
) == TYPE_DECL
10368 && TREE_TYPE (name
) == qualified_type
10369 && DECL_NAME (name
))))
10371 if (TREE_CODE (name
) == TYPE_DECL
)
10372 /* Could just call add_name_and_src_coords_attributes here,
10373 but since this is a builtin type it doesn't have any
10374 useful source coordinates anyway. */
10375 name
= DECL_NAME (name
);
10376 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10378 /* This probably indicates a bug. */
10379 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10381 name
= TYPE_NAME (type
);
10383 && TREE_CODE (name
) == TYPE_DECL
)
10384 name
= DECL_NAME (name
);
10385 add_name_attribute (mod_type_die
,
10386 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10389 if (qualified_type
)
10390 equate_type_number_to_die (qualified_type
, mod_type_die
);
10393 /* We must do this after the equate_type_number_to_die call, in case
10394 this is a recursive type. This ensures that the modified_type_die
10395 recursion will terminate even if the type is recursive. Recursive
10396 types are possible in Ada. */
10397 sub_die
= modified_type_die (item_type
,
10398 TYPE_READONLY (item_type
),
10399 TYPE_VOLATILE (item_type
),
10402 if (sub_die
!= NULL
)
10403 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10405 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10406 if (TYPE_ARTIFICIAL (type
))
10407 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10409 return mod_type_die
;
10412 /* Generate DIEs for the generic parameters of T.
10413 T must be either a generic type or a generic function.
10414 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10417 gen_generic_params_dies (tree t
)
10421 dw_die_ref die
= NULL
;
10424 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10428 die
= lookup_type_die (t
);
10429 else if (DECL_P (t
))
10430 die
= lookup_decl_die (t
);
10434 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10436 /* T has no generic parameter. It means T is neither a generic type
10437 or function. End of story. */
10440 parms_num
= TREE_VEC_LENGTH (parms
);
10441 args
= lang_hooks
.get_innermost_generic_args (t
);
10442 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10443 non_default
= int_cst_value (TREE_CHAIN (args
));
10445 non_default
= TREE_VEC_LENGTH (args
);
10446 for (i
= 0; i
< parms_num
; i
++)
10448 tree parm
, arg
, arg_pack_elems
;
10449 dw_die_ref parm_die
;
10451 parm
= TREE_VEC_ELT (parms
, i
);
10452 arg
= TREE_VEC_ELT (args
, i
);
10453 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10454 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10456 if (parm
&& TREE_VALUE (parm
) && arg
)
10458 /* If PARM represents a template parameter pack,
10459 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10460 by DW_TAG_template_*_parameter DIEs for the argument
10461 pack elements of ARG. Note that ARG would then be
10462 an argument pack. */
10463 if (arg_pack_elems
)
10464 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10468 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10469 true /* emit name */, die
);
10470 if (i
>= non_default
)
10471 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10476 /* Create and return a DIE for PARM which should be
10477 the representation of a generic type parameter.
10478 For instance, in the C++ front end, PARM would be a template parameter.
10479 ARG is the argument to PARM.
10480 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10482 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10483 as a child node. */
10486 generic_parameter_die (tree parm
, tree arg
,
10488 dw_die_ref parent_die
)
10490 dw_die_ref tmpl_die
= NULL
;
10491 const char *name
= NULL
;
10493 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10496 /* We support non-type generic parameters and arguments,
10497 type generic parameters and arguments, as well as
10498 generic generic parameters (a.k.a. template template parameters in C++)
10500 if (TREE_CODE (parm
) == PARM_DECL
)
10501 /* PARM is a nontype generic parameter */
10502 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10503 else if (TREE_CODE (parm
) == TYPE_DECL
)
10504 /* PARM is a type generic parameter. */
10505 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10506 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10507 /* PARM is a generic generic parameter.
10508 Its DIE is a GNU extension. It shall have a
10509 DW_AT_name attribute to represent the name of the template template
10510 parameter, and a DW_AT_GNU_template_name attribute to represent the
10511 name of the template template argument. */
10512 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10515 gcc_unreachable ();
10521 /* If PARM is a generic parameter pack, it means we are
10522 emitting debug info for a template argument pack element.
10523 In other terms, ARG is a template argument pack element.
10524 In that case, we don't emit any DW_AT_name attribute for
10528 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10530 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10533 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10535 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10536 TMPL_DIE should have a child DW_AT_type attribute that is set
10537 to the type of the argument to PARM, which is ARG.
10538 If PARM is a type generic parameter, TMPL_DIE should have a
10539 child DW_AT_type that is set to ARG. */
10540 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10541 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10542 TREE_THIS_VOLATILE (tmpl_type
),
10547 /* So TMPL_DIE is a DIE representing a
10548 a generic generic template parameter, a.k.a template template
10549 parameter in C++ and arg is a template. */
10551 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10552 to the name of the argument. */
10553 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10555 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10558 if (TREE_CODE (parm
) == PARM_DECL
)
10559 /* So PARM is a non-type generic parameter.
10560 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10561 attribute of TMPL_DIE which value represents the value
10563 We must be careful here:
10564 The value of ARG might reference some function decls.
10565 We might currently be emitting debug info for a generic
10566 type and types are emitted before function decls, we don't
10567 know if the function decls referenced by ARG will actually be
10568 emitted after cgraph computations.
10569 So must defer the generation of the DW_AT_const_value to
10570 after cgraph is ready. */
10571 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10577 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10578 PARM_PACK must be a template parameter pack. The returned DIE
10579 will be child DIE of PARENT_DIE. */
10582 template_parameter_pack_die (tree parm_pack
,
10583 tree parm_pack_args
,
10584 dw_die_ref parent_die
)
10589 gcc_assert (parent_die
&& parm_pack
);
10591 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10592 add_name_and_src_coords_attributes (die
, parm_pack
);
10593 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10594 generic_parameter_die (parm_pack
,
10595 TREE_VEC_ELT (parm_pack_args
, j
),
10596 false /* Don't emit DW_AT_name */,
10601 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10602 an enumerated type. */
10605 type_is_enum (const_tree type
)
10607 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10610 /* Return the DBX register number described by a given RTL node. */
10612 static unsigned int
10613 dbx_reg_number (const_rtx rtl
)
10615 unsigned regno
= REGNO (rtl
);
10617 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10619 #ifdef LEAF_REG_REMAP
10620 if (crtl
->uses_only_leaf_regs
)
10622 int leaf_reg
= LEAF_REG_REMAP (regno
);
10623 if (leaf_reg
!= -1)
10624 regno
= (unsigned) leaf_reg
;
10628 regno
= DBX_REGISTER_NUMBER (regno
);
10629 gcc_assert (regno
!= INVALID_REGNUM
);
10633 /* Optionally add a DW_OP_piece term to a location description expression.
10634 DW_OP_piece is only added if the location description expression already
10635 doesn't end with DW_OP_piece. */
10638 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10640 dw_loc_descr_ref loc
;
10642 if (*list_head
!= NULL
)
10644 /* Find the end of the chain. */
10645 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10648 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10649 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10653 /* Return a location descriptor that designates a machine register or
10654 zero if there is none. */
10656 static dw_loc_descr_ref
10657 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10661 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10664 /* We only use "frame base" when we're sure we're talking about the
10665 post-prologue local stack frame. We do this by *not* running
10666 register elimination until this point, and recognizing the special
10667 argument pointer and soft frame pointer rtx's.
10668 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10669 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10670 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10672 dw_loc_descr_ref result
= NULL
;
10674 if (dwarf_version
>= 4 || !dwarf_strict
)
10676 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10679 add_loc_descr (&result
,
10680 new_loc_descr (DW_OP_stack_value
, 0, 0));
10685 regs
= targetm
.dwarf_register_span (rtl
);
10687 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10688 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10691 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10692 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10694 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10698 /* Return a location descriptor that designates a machine register for
10699 a given hard register number. */
10701 static dw_loc_descr_ref
10702 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10704 dw_loc_descr_ref reg_loc_descr
;
10708 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10710 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10712 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10713 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10715 return reg_loc_descr
;
10718 /* Given an RTL of a register, return a location descriptor that
10719 designates a value that spans more than one register. */
10721 static dw_loc_descr_ref
10722 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10723 enum var_init_status initialized
)
10726 dw_loc_descr_ref loc_result
= NULL
;
10728 /* Simple, contiguous registers. */
10729 if (regs
== NULL_RTX
)
10731 unsigned reg
= REGNO (rtl
);
10734 #ifdef LEAF_REG_REMAP
10735 if (crtl
->uses_only_leaf_regs
)
10737 int leaf_reg
= LEAF_REG_REMAP (reg
);
10738 if (leaf_reg
!= -1)
10739 reg
= (unsigned) leaf_reg
;
10743 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10744 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10746 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10751 dw_loc_descr_ref t
;
10753 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10754 VAR_INIT_STATUS_INITIALIZED
);
10755 add_loc_descr (&loc_result
, t
);
10756 add_loc_descr_op_piece (&loc_result
, size
);
10762 /* Now onto stupid register sets in non contiguous locations. */
10764 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10766 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10769 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10771 dw_loc_descr_ref t
;
10773 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
10774 VAR_INIT_STATUS_INITIALIZED
);
10775 add_loc_descr (&loc_result
, t
);
10776 add_loc_descr_op_piece (&loc_result
, size
);
10779 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10780 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10784 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10786 /* Return a location descriptor that designates a constant i,
10787 as a compound operation from constant (i >> shift), constant shift
10790 static dw_loc_descr_ref
10791 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10793 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10794 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10795 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10799 /* Return a location descriptor that designates a constant. */
10801 static dw_loc_descr_ref
10802 int_loc_descriptor (HOST_WIDE_INT i
)
10804 enum dwarf_location_atom op
;
10806 /* Pick the smallest representation of a constant, rather than just
10807 defaulting to the LEB encoding. */
10810 int clz
= clz_hwi (i
);
10811 int ctz
= ctz_hwi (i
);
10813 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10814 else if (i
<= 0xff)
10815 op
= DW_OP_const1u
;
10816 else if (i
<= 0xffff)
10817 op
= DW_OP_const2u
;
10818 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10819 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10820 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10821 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10822 while DW_OP_const4u is 5 bytes. */
10823 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10824 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10825 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10826 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10827 while DW_OP_const4u is 5 bytes. */
10828 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10829 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10830 op
= DW_OP_const4u
;
10831 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10832 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10833 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10834 while DW_OP_constu of constant >= 0x100000000 takes at least
10836 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10837 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10838 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10839 >= HOST_BITS_PER_WIDE_INT
)
10840 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10841 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10842 while DW_OP_constu takes in this case at least 6 bytes. */
10843 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10844 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10845 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10846 && size_of_uleb128 (i
) > 6)
10847 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10848 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10855 op
= DW_OP_const1s
;
10856 else if (i
>= -0x8000)
10857 op
= DW_OP_const2s
;
10858 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10860 if (size_of_int_loc_descriptor (i
) < 5)
10862 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10863 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10866 op
= DW_OP_const4s
;
10870 if (size_of_int_loc_descriptor (i
)
10871 < (unsigned long) 1 + size_of_sleb128 (i
))
10873 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10874 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10881 return new_loc_descr (op
, i
, 0);
10884 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10885 without actually allocating it. */
10887 static unsigned long
10888 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10890 return size_of_int_loc_descriptor (i
>> shift
)
10891 + size_of_int_loc_descriptor (shift
)
10895 /* Return size_of_locs (int_loc_descriptor (i)) without
10896 actually allocating it. */
10898 static unsigned long
10899 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10908 else if (i
<= 0xff)
10910 else if (i
<= 0xffff)
10914 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10915 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10916 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10918 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10919 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10920 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10922 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10924 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10925 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10926 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10927 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10929 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10930 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10931 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10933 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10934 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10936 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10945 else if (i
>= -0x8000)
10947 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10949 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10951 s
= size_of_int_loc_descriptor (-i
) + 1;
10959 unsigned long r
= 1 + size_of_sleb128 (i
);
10960 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10962 s
= size_of_int_loc_descriptor (-i
) + 1;
10971 /* Return loc description representing "address" of integer value.
10972 This can appear only as toplevel expression. */
10974 static dw_loc_descr_ref
10975 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10978 dw_loc_descr_ref loc_result
= NULL
;
10980 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10983 litsize
= size_of_int_loc_descriptor (i
);
10984 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10985 is more compact. For DW_OP_stack_value we need:
10986 litsize + 1 (DW_OP_stack_value)
10987 and for DW_OP_implicit_value:
10988 1 (DW_OP_implicit_value) + 1 (length) + size. */
10989 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10991 loc_result
= int_loc_descriptor (i
);
10992 add_loc_descr (&loc_result
,
10993 new_loc_descr (DW_OP_stack_value
, 0, 0));
10997 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10999 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11000 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11004 /* Return a location descriptor that designates a base+offset location. */
11006 static dw_loc_descr_ref
11007 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11008 enum var_init_status initialized
)
11010 unsigned int regno
;
11011 dw_loc_descr_ref result
;
11012 dw_fde_ref fde
= cfun
->fde
;
11014 /* We only use "frame base" when we're sure we're talking about the
11015 post-prologue local stack frame. We do this by *not* running
11016 register elimination until this point, and recognizing the special
11017 argument pointer and soft frame pointer rtx's. */
11018 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11020 rtx elim
= (ira_use_lra_p
11021 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11022 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11026 if (GET_CODE (elim
) == PLUS
)
11028 offset
+= INTVAL (XEXP (elim
, 1));
11029 elim
= XEXP (elim
, 0);
11031 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11032 && (elim
== hard_frame_pointer_rtx
11033 || elim
== stack_pointer_rtx
))
11034 || elim
== (frame_pointer_needed
11035 ? hard_frame_pointer_rtx
11036 : stack_pointer_rtx
));
11038 /* If drap register is used to align stack, use frame
11039 pointer + offset to access stack variables. If stack
11040 is aligned without drap, use stack pointer + offset to
11041 access stack variables. */
11042 if (crtl
->stack_realign_tried
11043 && reg
== frame_pointer_rtx
)
11046 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11047 ? HARD_FRAME_POINTER_REGNUM
11049 return new_reg_loc_descr (base_reg
, offset
);
11052 gcc_assert (frame_pointer_fb_offset_valid
);
11053 offset
+= frame_pointer_fb_offset
;
11054 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11058 regno
= REGNO (reg
);
11059 #ifdef LEAF_REG_REMAP
11060 if (crtl
->uses_only_leaf_regs
)
11062 int leaf_reg
= LEAF_REG_REMAP (regno
);
11063 if (leaf_reg
!= -1)
11064 regno
= (unsigned) leaf_reg
;
11067 regno
= DWARF_FRAME_REGNUM (regno
);
11069 if (!optimize
&& fde
11070 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11072 /* Use cfa+offset to represent the location of arguments passed
11073 on the stack when drap is used to align stack.
11074 Only do this when not optimizing, for optimized code var-tracking
11075 is supposed to track where the arguments live and the register
11076 used as vdrap or drap in some spot might be used for something
11077 else in other part of the routine. */
11078 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11082 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11085 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11087 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11088 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11093 /* Return true if this RTL expression describes a base+offset calculation. */
11096 is_based_loc (const_rtx rtl
)
11098 return (GET_CODE (rtl
) == PLUS
11099 && ((REG_P (XEXP (rtl
, 0))
11100 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11101 && CONST_INT_P (XEXP (rtl
, 1)))));
11104 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11107 static dw_loc_descr_ref
11108 tls_mem_loc_descriptor (rtx mem
)
11111 dw_loc_descr_ref loc_result
;
11113 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11116 base
= get_base_address (MEM_EXPR (mem
));
11118 || TREE_CODE (base
) != VAR_DECL
11119 || !DECL_THREAD_LOCAL_P (base
))
11122 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11123 if (loc_result
== NULL
)
11126 if (MEM_OFFSET (mem
))
11127 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11132 /* Output debug info about reason why we failed to expand expression as dwarf
11136 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11138 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11140 fprintf (dump_file
, "Failed to expand as dwarf: ");
11142 print_generic_expr (dump_file
, expr
, dump_flags
);
11145 fprintf (dump_file
, "\n");
11146 print_rtl (dump_file
, rtl
);
11148 fprintf (dump_file
, "\nReason: %s\n", reason
);
11152 /* Helper function for const_ok_for_output, called either directly
11153 or via for_each_rtx. */
11156 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11160 if (GET_CODE (rtl
) == UNSPEC
)
11162 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11163 we can't express it in the debug info. */
11164 #ifdef ENABLE_CHECKING
11165 /* Don't complain about TLS UNSPECs, those are just too hard to
11166 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11167 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11168 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11169 if (XVECLEN (rtl
, 0) == 0
11170 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11171 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11172 inform (current_function_decl
11173 ? DECL_SOURCE_LOCATION (current_function_decl
)
11174 : UNKNOWN_LOCATION
,
11175 #if NUM_UNSPEC_VALUES > 0
11176 "non-delegitimized UNSPEC %s (%d) found in variable location",
11177 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11178 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11181 "non-delegitimized UNSPEC %d found in variable location",
11185 expansion_failed (NULL_TREE
, rtl
,
11186 "UNSPEC hasn't been delegitimized.\n");
11190 if (targetm
.const_not_ok_for_debug_p (rtl
))
11192 expansion_failed (NULL_TREE
, rtl
,
11193 "Expression rejected for debug by the backend.\n");
11197 if (GET_CODE (rtl
) != SYMBOL_REF
)
11200 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11203 get_pool_constant_mark (rtl
, &marked
);
11204 /* If all references to this pool constant were optimized away,
11205 it was not output and thus we can't represent it. */
11208 expansion_failed (NULL_TREE
, rtl
,
11209 "Constant was removed from constant pool.\n");
11214 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11217 /* Avoid references to external symbols in debug info, on several targets
11218 the linker might even refuse to link when linking a shared library,
11219 and in many other cases the relocations for .debug_info/.debug_loc are
11220 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11221 to be defined within the same shared library or executable are fine. */
11222 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11224 tree decl
= SYMBOL_REF_DECL (rtl
);
11226 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11228 expansion_failed (NULL_TREE
, rtl
,
11229 "Symbol not defined in current TU.\n");
11237 /* Return true if constant RTL can be emitted in DW_OP_addr or
11238 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11239 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11242 const_ok_for_output (rtx rtl
)
11244 if (GET_CODE (rtl
) == SYMBOL_REF
)
11245 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11247 if (GET_CODE (rtl
) == CONST
)
11248 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11253 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11254 if possible, NULL otherwise. */
11257 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11259 dw_die_ref type_die
;
11260 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11264 switch (TREE_CODE (type
))
11272 type_die
= lookup_type_die (type
);
11274 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11275 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11280 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11281 type matching MODE, or, if MODE is narrower than or as wide as
11282 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11285 static dw_loc_descr_ref
11286 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11288 enum machine_mode outer_mode
= mode
;
11289 dw_die_ref type_die
;
11290 dw_loc_descr_ref cvt
;
11292 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11294 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11297 type_die
= base_type_for_mode (outer_mode
, 1);
11298 if (type_die
== NULL
)
11300 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11301 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11302 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11303 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11304 add_loc_descr (&op
, cvt
);
11308 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11310 static dw_loc_descr_ref
11311 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11312 dw_loc_descr_ref op1
)
11314 dw_loc_descr_ref ret
= op0
;
11315 add_loc_descr (&ret
, op1
);
11316 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11317 if (STORE_FLAG_VALUE
!= 1)
11319 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11320 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11325 /* Return location descriptor for signed comparison OP RTL. */
11327 static dw_loc_descr_ref
11328 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11329 enum machine_mode mem_mode
)
11331 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11332 dw_loc_descr_ref op0
, op1
;
11335 if (op_mode
== VOIDmode
)
11336 op_mode
= GET_MODE (XEXP (rtl
, 1));
11337 if (op_mode
== VOIDmode
)
11341 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11342 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11345 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11346 VAR_INIT_STATUS_INITIALIZED
);
11347 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11348 VAR_INIT_STATUS_INITIALIZED
);
11350 if (op0
== NULL
|| op1
== NULL
)
11353 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11354 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11355 return compare_loc_descriptor (op
, op0
, op1
);
11357 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11359 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11360 dw_loc_descr_ref cvt
;
11362 if (type_die
== NULL
)
11364 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11365 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11366 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11367 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11368 add_loc_descr (&op0
, cvt
);
11369 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11370 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11371 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11372 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11373 add_loc_descr (&op1
, cvt
);
11374 return compare_loc_descriptor (op
, op0
, op1
);
11377 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11378 /* For eq/ne, if the operands are known to be zero-extended,
11379 there is no need to do the fancy shifting up. */
11380 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11382 dw_loc_descr_ref last0
, last1
;
11383 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11385 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11387 /* deref_size zero extends, and for constants we can check
11388 whether they are zero extended or not. */
11389 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11390 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11391 || (CONST_INT_P (XEXP (rtl
, 0))
11392 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11393 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11394 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11395 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11396 || (CONST_INT_P (XEXP (rtl
, 1))
11397 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11398 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11399 return compare_loc_descriptor (op
, op0
, op1
);
11401 /* EQ/NE comparison against constant in narrower type than
11402 DWARF2_ADDR_SIZE can be performed either as
11403 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11406 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11407 DW_OP_{eq,ne}. Pick whatever is shorter. */
11408 if (CONST_INT_P (XEXP (rtl
, 1))
11409 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11410 && (size_of_int_loc_descriptor (shift
) + 1
11411 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11412 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11413 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11414 & GET_MODE_MASK (op_mode
))))
11416 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11417 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11418 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11419 & GET_MODE_MASK (op_mode
));
11420 return compare_loc_descriptor (op
, op0
, op1
);
11423 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11424 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11425 if (CONST_INT_P (XEXP (rtl
, 1)))
11426 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11429 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11430 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11432 return compare_loc_descriptor (op
, op0
, op1
);
11435 /* Return location descriptor for unsigned comparison OP RTL. */
11437 static dw_loc_descr_ref
11438 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11439 enum machine_mode mem_mode
)
11441 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11442 dw_loc_descr_ref op0
, op1
;
11444 if (op_mode
== VOIDmode
)
11445 op_mode
= GET_MODE (XEXP (rtl
, 1));
11446 if (op_mode
== VOIDmode
)
11448 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11451 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11454 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11455 VAR_INIT_STATUS_INITIALIZED
);
11456 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11457 VAR_INIT_STATUS_INITIALIZED
);
11459 if (op0
== NULL
|| op1
== NULL
)
11462 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11464 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11465 dw_loc_descr_ref last0
, last1
;
11466 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11468 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11470 if (CONST_INT_P (XEXP (rtl
, 0)))
11471 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11472 /* deref_size zero extends, so no need to mask it again. */
11473 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11474 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11476 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11477 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11479 if (CONST_INT_P (XEXP (rtl
, 1)))
11480 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11481 /* deref_size zero extends, so no need to mask it again. */
11482 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11483 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11485 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11486 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11489 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11491 HOST_WIDE_INT bias
= 1;
11492 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11493 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11494 if (CONST_INT_P (XEXP (rtl
, 1)))
11495 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11496 + INTVAL (XEXP (rtl
, 1)));
11498 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11501 return compare_loc_descriptor (op
, op0
, op1
);
11504 /* Return location descriptor for {U,S}{MIN,MAX}. */
11506 static dw_loc_descr_ref
11507 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11508 enum machine_mode mem_mode
)
11510 enum dwarf_location_atom op
;
11511 dw_loc_descr_ref op0
, op1
, ret
;
11512 dw_loc_descr_ref bra_node
, drop_node
;
11515 && (GET_MODE_CLASS (mode
) != MODE_INT
11516 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11519 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11520 VAR_INIT_STATUS_INITIALIZED
);
11521 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11522 VAR_INIT_STATUS_INITIALIZED
);
11524 if (op0
== NULL
|| op1
== NULL
)
11527 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11528 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11529 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11530 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11532 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11534 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11535 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11536 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11537 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11538 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11540 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11542 HOST_WIDE_INT bias
= 1;
11543 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11544 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11545 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11548 else if (GET_MODE_CLASS (mode
) == MODE_INT
11549 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11551 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11552 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11553 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11554 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11555 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11557 else if (GET_MODE_CLASS (mode
) == MODE_INT
11558 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11560 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11561 dw_loc_descr_ref cvt
;
11562 if (type_die
== NULL
)
11564 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11565 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11566 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11567 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11568 add_loc_descr (&op0
, cvt
);
11569 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11570 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11571 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11572 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11573 add_loc_descr (&op1
, cvt
);
11576 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11581 add_loc_descr (&ret
, op1
);
11582 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11583 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11584 add_loc_descr (&ret
, bra_node
);
11585 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11586 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11587 add_loc_descr (&ret
, drop_node
);
11588 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11589 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11590 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11591 && GET_MODE_CLASS (mode
) == MODE_INT
11592 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11593 ret
= convert_descriptor_to_mode (mode
, ret
);
11597 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11598 but after converting arguments to type_die, afterwards
11599 convert back to unsigned. */
11601 static dw_loc_descr_ref
11602 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11603 enum machine_mode mode
, enum machine_mode mem_mode
)
11605 dw_loc_descr_ref cvt
, op0
, op1
;
11607 if (type_die
== NULL
)
11609 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11610 VAR_INIT_STATUS_INITIALIZED
);
11611 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11612 VAR_INIT_STATUS_INITIALIZED
);
11613 if (op0
== NULL
|| op1
== NULL
)
11615 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11616 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11617 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11618 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11619 add_loc_descr (&op0
, cvt
);
11620 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11621 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11622 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11623 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11624 add_loc_descr (&op1
, cvt
);
11625 add_loc_descr (&op0
, op1
);
11626 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11627 return convert_descriptor_to_mode (mode
, op0
);
11630 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11631 const0 is DW_OP_lit0 or corresponding typed constant,
11632 const1 is DW_OP_lit1 or corresponding typed constant
11633 and constMSB is constant with just the MSB bit set
11635 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11636 L1: const0 DW_OP_swap
11637 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11638 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11643 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11644 L1: const0 DW_OP_swap
11645 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11646 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11651 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11652 L1: const1 DW_OP_swap
11653 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11654 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11658 static dw_loc_descr_ref
11659 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11660 enum machine_mode mem_mode
)
11662 dw_loc_descr_ref op0
, ret
, tmp
;
11663 HOST_WIDE_INT valv
;
11664 dw_loc_descr_ref l1jump
, l1label
;
11665 dw_loc_descr_ref l2jump
, l2label
;
11666 dw_loc_descr_ref l3jump
, l3label
;
11667 dw_loc_descr_ref l4jump
, l4label
;
11670 if (GET_MODE_CLASS (mode
) != MODE_INT
11671 || GET_MODE (XEXP (rtl
, 0)) != mode
11672 || (GET_CODE (rtl
) == CLZ
11673 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11676 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11677 VAR_INIT_STATUS_INITIALIZED
);
11681 if (GET_CODE (rtl
) == CLZ
)
11683 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11684 valv
= GET_MODE_BITSIZE (mode
);
11686 else if (GET_CODE (rtl
) == FFS
)
11688 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11689 valv
= GET_MODE_BITSIZE (mode
);
11690 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11691 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11692 add_loc_descr (&ret
, l1jump
);
11693 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11694 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11695 VAR_INIT_STATUS_INITIALIZED
);
11698 add_loc_descr (&ret
, tmp
);
11699 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11700 add_loc_descr (&ret
, l4jump
);
11701 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11702 ? const1_rtx
: const0_rtx
,
11704 VAR_INIT_STATUS_INITIALIZED
);
11705 if (l1label
== NULL
)
11707 add_loc_descr (&ret
, l1label
);
11708 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11709 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11710 add_loc_descr (&ret
, l2label
);
11711 if (GET_CODE (rtl
) != CLZ
)
11713 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11714 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11715 << (GET_MODE_BITSIZE (mode
) - 1));
11717 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11718 << (GET_MODE_BITSIZE (mode
)
11719 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11720 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11721 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11722 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11723 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11725 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11726 VAR_INIT_STATUS_INITIALIZED
);
11729 add_loc_descr (&ret
, tmp
);
11730 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11731 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11732 add_loc_descr (&ret
, l3jump
);
11733 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11734 VAR_INIT_STATUS_INITIALIZED
);
11737 add_loc_descr (&ret
, tmp
);
11738 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11739 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11740 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11741 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11742 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11743 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11744 add_loc_descr (&ret
, l2jump
);
11745 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11746 add_loc_descr (&ret
, l3label
);
11747 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11748 add_loc_descr (&ret
, l4label
);
11749 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11750 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11751 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11752 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11753 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11754 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11755 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11756 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11760 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11761 const1 is DW_OP_lit1 or corresponding typed constant):
11763 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11764 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11768 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11769 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11772 static dw_loc_descr_ref
11773 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11774 enum machine_mode mem_mode
)
11776 dw_loc_descr_ref op0
, ret
, tmp
;
11777 dw_loc_descr_ref l1jump
, l1label
;
11778 dw_loc_descr_ref l2jump
, l2label
;
11780 if (GET_MODE_CLASS (mode
) != MODE_INT
11781 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11784 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11785 VAR_INIT_STATUS_INITIALIZED
);
11789 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11790 VAR_INIT_STATUS_INITIALIZED
);
11793 add_loc_descr (&ret
, tmp
);
11794 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11795 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11796 add_loc_descr (&ret
, l1label
);
11797 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11798 add_loc_descr (&ret
, l2jump
);
11799 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11800 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11801 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11802 VAR_INIT_STATUS_INITIALIZED
);
11805 add_loc_descr (&ret
, tmp
);
11806 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11807 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11808 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11809 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11810 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11811 VAR_INIT_STATUS_INITIALIZED
);
11812 add_loc_descr (&ret
, tmp
);
11813 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11814 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11815 add_loc_descr (&ret
, l1jump
);
11816 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11817 add_loc_descr (&ret
, l2label
);
11818 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11819 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11820 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11821 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11825 /* BSWAP (constS is initial shift count, either 56 or 24):
11827 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11828 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11829 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11830 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11831 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11833 static dw_loc_descr_ref
11834 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11835 enum machine_mode mem_mode
)
11837 dw_loc_descr_ref op0
, ret
, tmp
;
11838 dw_loc_descr_ref l1jump
, l1label
;
11839 dw_loc_descr_ref l2jump
, l2label
;
11841 if (GET_MODE_CLASS (mode
) != MODE_INT
11842 || BITS_PER_UNIT
!= 8
11843 || (GET_MODE_BITSIZE (mode
) != 32
11844 && GET_MODE_BITSIZE (mode
) != 64))
11847 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11848 VAR_INIT_STATUS_INITIALIZED
);
11853 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11855 VAR_INIT_STATUS_INITIALIZED
);
11858 add_loc_descr (&ret
, tmp
);
11859 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11860 VAR_INIT_STATUS_INITIALIZED
);
11863 add_loc_descr (&ret
, tmp
);
11864 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11865 add_loc_descr (&ret
, l1label
);
11866 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11868 VAR_INIT_STATUS_INITIALIZED
);
11869 add_loc_descr (&ret
, tmp
);
11870 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11871 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11872 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11873 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11874 VAR_INIT_STATUS_INITIALIZED
);
11877 add_loc_descr (&ret
, tmp
);
11878 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11879 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11880 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11881 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11882 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11883 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11884 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11885 VAR_INIT_STATUS_INITIALIZED
);
11886 add_loc_descr (&ret
, tmp
);
11887 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11888 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11889 add_loc_descr (&ret
, l2jump
);
11890 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11891 VAR_INIT_STATUS_INITIALIZED
);
11892 add_loc_descr (&ret
, tmp
);
11893 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11894 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11895 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11896 add_loc_descr (&ret
, l1jump
);
11897 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11898 add_loc_descr (&ret
, l2label
);
11899 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11900 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11901 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11902 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11903 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11904 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11908 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11909 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11910 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11911 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11913 ROTATERT is similar:
11914 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11915 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11916 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11918 static dw_loc_descr_ref
11919 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11920 enum machine_mode mem_mode
)
11922 rtx rtlop1
= XEXP (rtl
, 1);
11923 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11926 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11929 if (GET_MODE (rtlop1
) != VOIDmode
11930 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11931 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11932 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11933 VAR_INIT_STATUS_INITIALIZED
);
11934 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11935 VAR_INIT_STATUS_INITIALIZED
);
11936 if (op0
== NULL
|| op1
== NULL
)
11938 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11939 for (i
= 0; i
< 2; i
++)
11941 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11942 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11944 VAR_INIT_STATUS_INITIALIZED
);
11945 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11946 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11948 : HOST_BITS_PER_WIDE_INT
== 64
11949 ? DW_OP_const8u
: DW_OP_constu
,
11950 GET_MODE_MASK (mode
), 0);
11953 if (mask
[i
] == NULL
)
11955 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11958 add_loc_descr (&ret
, op1
);
11959 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11960 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11961 if (GET_CODE (rtl
) == ROTATERT
)
11963 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11964 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11965 GET_MODE_BITSIZE (mode
), 0));
11967 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11968 if (mask
[0] != NULL
)
11969 add_loc_descr (&ret
, mask
[0]);
11970 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11971 if (mask
[1] != NULL
)
11973 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11974 add_loc_descr (&ret
, mask
[1]);
11975 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11977 if (GET_CODE (rtl
) == ROTATE
)
11979 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11980 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11981 GET_MODE_BITSIZE (mode
), 0));
11983 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11984 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11988 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11989 for DEBUG_PARAMETER_REF RTL. */
11991 static dw_loc_descr_ref
11992 parameter_ref_descriptor (rtx rtl
)
11994 dw_loc_descr_ref ret
;
11999 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12000 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12001 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12004 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12005 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12006 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12010 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12011 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12016 /* The following routine converts the RTL for a variable or parameter
12017 (resident in memory) into an equivalent Dwarf representation of a
12018 mechanism for getting the address of that same variable onto the top of a
12019 hypothetical "address evaluation" stack.
12021 When creating memory location descriptors, we are effectively transforming
12022 the RTL for a memory-resident object into its Dwarf postfix expression
12023 equivalent. This routine recursively descends an RTL tree, turning
12024 it into Dwarf postfix code as it goes.
12026 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12028 MEM_MODE is the mode of the memory reference, needed to handle some
12029 autoincrement addressing modes.
12031 Return 0 if we can't represent the location. */
12034 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12035 enum machine_mode mem_mode
,
12036 enum var_init_status initialized
)
12038 dw_loc_descr_ref mem_loc_result
= NULL
;
12039 enum dwarf_location_atom op
;
12040 dw_loc_descr_ref op0
, op1
;
12041 rtx inner
= NULL_RTX
;
12043 if (mode
== VOIDmode
)
12044 mode
= GET_MODE (rtl
);
12046 /* Note that for a dynamically sized array, the location we will generate a
12047 description of here will be the lowest numbered location which is
12048 actually within the array. That's *not* necessarily the same as the
12049 zeroth element of the array. */
12051 rtl
= targetm
.delegitimize_address (rtl
);
12053 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12056 switch (GET_CODE (rtl
))
12061 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12064 /* The case of a subreg may arise when we have a local (register)
12065 variable or a formal (register) parameter which doesn't quite fill
12066 up an entire register. For now, just assume that it is
12067 legitimate to make the Dwarf info refer to the whole register which
12068 contains the given subreg. */
12069 if (!subreg_lowpart_p (rtl
))
12071 inner
= SUBREG_REG (rtl
);
12073 if (inner
== NULL_RTX
)
12074 inner
= XEXP (rtl
, 0);
12075 if (GET_MODE_CLASS (mode
) == MODE_INT
12076 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12077 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12078 #ifdef POINTERS_EXTEND_UNSIGNED
12079 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12082 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12084 mem_loc_result
= mem_loc_descriptor (inner
,
12086 mem_mode
, initialized
);
12091 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12093 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12094 && (GET_MODE_CLASS (mode
) != MODE_INT
12095 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12099 dw_die_ref type_die
;
12100 dw_loc_descr_ref cvt
;
12102 mem_loc_result
= mem_loc_descriptor (inner
,
12104 mem_mode
, initialized
);
12105 if (mem_loc_result
== NULL
)
12107 type_die
= base_type_for_mode (mode
,
12108 GET_MODE_CLASS (mode
) == MODE_INT
);
12109 if (type_die
== NULL
)
12111 mem_loc_result
= NULL
;
12114 if (GET_MODE_SIZE (mode
)
12115 != GET_MODE_SIZE (GET_MODE (inner
)))
12116 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12118 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12119 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12120 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12121 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12122 add_loc_descr (&mem_loc_result
, cvt
);
12127 if (GET_MODE_CLASS (mode
) != MODE_INT
12128 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12129 && rtl
!= arg_pointer_rtx
12130 && rtl
!= frame_pointer_rtx
12131 #ifdef POINTERS_EXTEND_UNSIGNED
12132 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12136 dw_die_ref type_die
;
12137 unsigned int dbx_regnum
;
12141 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12143 type_die
= base_type_for_mode (mode
,
12144 GET_MODE_CLASS (mode
) == MODE_INT
);
12145 if (type_die
== NULL
)
12148 dbx_regnum
= dbx_reg_number (rtl
);
12149 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12151 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12153 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12154 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12155 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12158 /* Whenever a register number forms a part of the description of the
12159 method for calculating the (dynamic) address of a memory resident
12160 object, DWARF rules require the register number be referred to as
12161 a "base register". This distinction is not based in any way upon
12162 what category of register the hardware believes the given register
12163 belongs to. This is strictly DWARF terminology we're dealing with
12164 here. Note that in cases where the location of a memory-resident
12165 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12166 OP_CONST (0)) the actual DWARF location descriptor that we generate
12167 may just be OP_BASEREG (basereg). This may look deceptively like
12168 the object in question was allocated to a register (rather than in
12169 memory) so DWARF consumers need to be aware of the subtle
12170 distinction between OP_REG and OP_BASEREG. */
12171 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12172 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12173 else if (stack_realign_drap
12175 && crtl
->args
.internal_arg_pointer
== rtl
12176 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12178 /* If RTL is internal_arg_pointer, which has been optimized
12179 out, use DRAP instead. */
12180 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12181 VAR_INIT_STATUS_INITIALIZED
);
12187 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12189 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12190 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12193 else if (GET_CODE (rtl
) == ZERO_EXTEND
12194 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12195 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12196 < HOST_BITS_PER_WIDE_INT
12197 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12198 to expand zero extend as two shifts instead of
12200 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12202 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12203 mem_loc_result
= op0
;
12204 add_loc_descr (&mem_loc_result
,
12205 int_loc_descriptor (GET_MODE_MASK (imode
)));
12206 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12208 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12210 int shift
= DWARF2_ADDR_SIZE
12211 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12212 shift
*= BITS_PER_UNIT
;
12213 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12217 mem_loc_result
= op0
;
12218 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12219 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12220 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12221 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12223 else if (!dwarf_strict
)
12225 dw_die_ref type_die1
, type_die2
;
12226 dw_loc_descr_ref cvt
;
12228 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12229 GET_CODE (rtl
) == ZERO_EXTEND
);
12230 if (type_die1
== NULL
)
12232 type_die2
= base_type_for_mode (mode
, 1);
12233 if (type_die2
== NULL
)
12235 mem_loc_result
= op0
;
12236 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12237 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12238 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12239 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12240 add_loc_descr (&mem_loc_result
, cvt
);
12241 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12242 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12243 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12244 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12245 add_loc_descr (&mem_loc_result
, cvt
);
12251 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12252 if (new_rtl
!= rtl
)
12254 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12256 if (mem_loc_result
!= NULL
)
12257 return mem_loc_result
;
12260 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12261 get_address_mode (rtl
), mode
,
12262 VAR_INIT_STATUS_INITIALIZED
);
12263 if (mem_loc_result
== NULL
)
12264 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12265 if (mem_loc_result
!= NULL
)
12267 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12268 || GET_MODE_CLASS (mode
) != MODE_INT
)
12270 dw_die_ref type_die
;
12271 dw_loc_descr_ref deref
;
12276 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12277 if (type_die
== NULL
)
12279 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12280 GET_MODE_SIZE (mode
), 0);
12281 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12282 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12283 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12284 add_loc_descr (&mem_loc_result
, deref
);
12286 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12287 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12289 add_loc_descr (&mem_loc_result
,
12290 new_loc_descr (DW_OP_deref_size
,
12291 GET_MODE_SIZE (mode
), 0));
12296 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12299 /* Some ports can transform a symbol ref into a label ref, because
12300 the symbol ref is too far away and has to be dumped into a constant
12304 if (GET_MODE_CLASS (mode
) != MODE_INT
12305 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12306 #ifdef POINTERS_EXTEND_UNSIGNED
12307 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12311 if (GET_CODE (rtl
) == SYMBOL_REF
12312 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12314 dw_loc_descr_ref temp
;
12316 /* If this is not defined, we have no way to emit the data. */
12317 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12320 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12322 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12323 add_loc_descr (&mem_loc_result
, temp
);
12328 if (!const_ok_for_output (rtl
))
12332 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12333 vec_safe_push (used_rtx_array
, rtl
);
12339 case DEBUG_IMPLICIT_PTR
:
12340 expansion_failed (NULL_TREE
, rtl
,
12341 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12347 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12349 if (GET_MODE_CLASS (mode
) != MODE_INT
12350 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12351 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12352 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12355 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12356 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12358 op0
= one_reg_loc_descriptor (dbx_regnum
,
12359 VAR_INIT_STATUS_INITIALIZED
);
12362 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12363 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12365 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12366 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12367 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12371 gcc_unreachable ();
12374 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12375 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12376 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12379 case DEBUG_PARAMETER_REF
:
12380 mem_loc_result
= parameter_ref_descriptor (rtl
);
12384 /* Extract the PLUS expression nested inside and fall into
12385 PLUS code below. */
12386 rtl
= XEXP (rtl
, 1);
12391 /* Turn these into a PLUS expression and fall into the PLUS code
12393 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12394 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12395 ? GET_MODE_UNIT_SIZE (mem_mode
)
12396 : -GET_MODE_UNIT_SIZE (mem_mode
),
12399 /* ... fall through ... */
12403 if (is_based_loc (rtl
)
12404 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12405 || XEXP (rtl
, 0) == arg_pointer_rtx
12406 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12407 && GET_MODE_CLASS (mode
) == MODE_INT
)
12408 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12409 INTVAL (XEXP (rtl
, 1)),
12410 VAR_INIT_STATUS_INITIALIZED
);
12413 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12414 VAR_INIT_STATUS_INITIALIZED
);
12415 if (mem_loc_result
== 0)
12418 if (CONST_INT_P (XEXP (rtl
, 1))
12419 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12420 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12423 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12424 VAR_INIT_STATUS_INITIALIZED
);
12427 add_loc_descr (&mem_loc_result
, op1
);
12428 add_loc_descr (&mem_loc_result
,
12429 new_loc_descr (DW_OP_plus
, 0, 0));
12434 /* If a pseudo-reg is optimized away, it is possible for it to
12435 be replaced with a MEM containing a multiply or shift. */
12446 && GET_MODE_CLASS (mode
) == MODE_INT
12447 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12449 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12450 base_type_for_mode (mode
, 0),
12474 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12476 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12477 VAR_INIT_STATUS_INITIALIZED
);
12479 rtx rtlop1
= XEXP (rtl
, 1);
12480 if (GET_MODE (rtlop1
) != VOIDmode
12481 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12482 < GET_MODE_BITSIZE (mode
))
12483 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12484 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12485 VAR_INIT_STATUS_INITIALIZED
);
12488 if (op0
== 0 || op1
== 0)
12491 mem_loc_result
= op0
;
12492 add_loc_descr (&mem_loc_result
, op1
);
12493 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12509 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12510 VAR_INIT_STATUS_INITIALIZED
);
12511 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12512 VAR_INIT_STATUS_INITIALIZED
);
12514 if (op0
== 0 || op1
== 0)
12517 mem_loc_result
= op0
;
12518 add_loc_descr (&mem_loc_result
, op1
);
12519 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12523 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12525 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12526 base_type_for_mode (mode
, 0),
12531 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12532 VAR_INIT_STATUS_INITIALIZED
);
12533 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12534 VAR_INIT_STATUS_INITIALIZED
);
12536 if (op0
== 0 || op1
== 0)
12539 mem_loc_result
= op0
;
12540 add_loc_descr (&mem_loc_result
, op1
);
12541 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12542 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12543 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12544 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12545 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12549 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12551 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12556 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12557 base_type_for_mode (mode
, 1),
12575 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12576 VAR_INIT_STATUS_INITIALIZED
);
12581 mem_loc_result
= op0
;
12582 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12586 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12587 #ifdef POINTERS_EXTEND_UNSIGNED
12589 && mem_mode
!= VOIDmode
12590 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12594 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12598 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12599 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12601 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12602 enum machine_mode amode
;
12603 if (type_die
== NULL
)
12605 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12607 if (INTVAL (rtl
) >= 0
12608 && amode
!= BLKmode
12609 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12610 /* const DW_OP_GNU_convert <XXX> vs.
12611 DW_OP_GNU_const_type <XXX, 1, const>. */
12612 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12613 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12615 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12616 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12617 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12618 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12619 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12620 add_loc_descr (&mem_loc_result
, op0
);
12621 return mem_loc_result
;
12623 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12625 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12626 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12627 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12628 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12629 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12632 mem_loc_result
->dw_loc_oprnd2
.val_class
12633 = dw_val_class_const_double
;
12634 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12635 = double_int::from_shwi (INTVAL (rtl
));
12643 dw_die_ref type_die
;
12645 /* Note that a CONST_DOUBLE rtx could represent either an integer
12646 or a floating-point constant. A CONST_DOUBLE is used whenever
12647 the constant requires more than one word in order to be
12648 adequately represented. We output CONST_DOUBLEs as blocks. */
12649 if (mode
== VOIDmode
12650 || (GET_MODE (rtl
) == VOIDmode
12651 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12653 type_die
= base_type_for_mode (mode
,
12654 GET_MODE_CLASS (mode
) == MODE_INT
);
12655 if (type_die
== NULL
)
12657 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12658 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12659 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12660 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12661 if (SCALAR_FLOAT_MODE_P (mode
))
12663 unsigned int length
= GET_MODE_SIZE (mode
);
12664 unsigned char *array
12665 = (unsigned char*) ggc_alloc_atomic (length
);
12667 insert_float (rtl
, array
);
12668 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12669 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12670 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12671 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12675 mem_loc_result
->dw_loc_oprnd2
.val_class
12676 = dw_val_class_const_double
;
12677 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12678 = rtx_to_double_int (rtl
);
12684 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12688 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12692 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12696 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12700 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12704 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12708 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12712 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12716 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12720 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12725 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12730 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12735 if (CONST_INT_P (XEXP (rtl
, 1))
12736 && CONST_INT_P (XEXP (rtl
, 2))
12737 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12738 + (unsigned) INTVAL (XEXP (rtl
, 2))
12739 <= GET_MODE_BITSIZE (mode
))
12740 && GET_MODE_CLASS (mode
) == MODE_INT
12741 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12742 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12745 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12746 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12749 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12753 mem_loc_result
= op0
;
12754 size
= INTVAL (XEXP (rtl
, 1));
12755 shift
= INTVAL (XEXP (rtl
, 2));
12756 if (BITS_BIG_ENDIAN
)
12757 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12759 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12761 add_loc_descr (&mem_loc_result
,
12762 int_loc_descriptor (DWARF2_ADDR_SIZE
12764 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12766 if (size
!= (int) DWARF2_ADDR_SIZE
)
12768 add_loc_descr (&mem_loc_result
,
12769 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12770 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12777 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12778 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12779 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12780 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12781 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12782 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12783 VAR_INIT_STATUS_INITIALIZED
);
12784 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12785 VAR_INIT_STATUS_INITIALIZED
);
12786 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12789 mem_loc_result
= op1
;
12790 add_loc_descr (&mem_loc_result
, op2
);
12791 add_loc_descr (&mem_loc_result
, op0
);
12792 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12793 add_loc_descr (&mem_loc_result
, bra_node
);
12794 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12795 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12796 add_loc_descr (&mem_loc_result
, drop_node
);
12797 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12798 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12803 case FLOAT_TRUNCATE
:
12805 case UNSIGNED_FLOAT
:
12810 dw_die_ref type_die
;
12811 dw_loc_descr_ref cvt
;
12813 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12814 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12817 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12818 && (GET_CODE (rtl
) == FLOAT
12819 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12820 <= DWARF2_ADDR_SIZE
))
12822 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12823 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12824 if (type_die
== NULL
)
12826 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12827 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12828 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12829 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12830 add_loc_descr (&op0
, cvt
);
12832 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12833 if (type_die
== NULL
)
12835 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12836 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12837 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12838 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12839 add_loc_descr (&op0
, cvt
);
12840 if (GET_MODE_CLASS (mode
) == MODE_INT
12841 && (GET_CODE (rtl
) == FIX
12842 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12844 op0
= convert_descriptor_to_mode (mode
, op0
);
12848 mem_loc_result
= op0
;
12855 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12860 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12864 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12869 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12873 /* In theory, we could implement the above. */
12874 /* DWARF cannot represent the unsigned compare operations
12899 case FRACT_CONVERT
:
12900 case UNSIGNED_FRACT_CONVERT
:
12902 case UNSIGNED_SAT_FRACT
:
12908 case VEC_DUPLICATE
:
12912 case STRICT_LOW_PART
:
12917 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12918 can't express it in the debug info. This can happen e.g. with some
12923 resolve_one_addr (&rtl
, NULL
);
12927 #ifdef ENABLE_CHECKING
12928 print_rtl (stderr
, rtl
);
12929 gcc_unreachable ();
12935 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12936 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12938 return mem_loc_result
;
12941 /* Return a descriptor that describes the concatenation of two locations.
12942 This is typically a complex variable. */
12944 static dw_loc_descr_ref
12945 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12947 dw_loc_descr_ref cc_loc_result
= NULL
;
12948 dw_loc_descr_ref x0_ref
12949 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12950 dw_loc_descr_ref x1_ref
12951 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12953 if (x0_ref
== 0 || x1_ref
== 0)
12956 cc_loc_result
= x0_ref
;
12957 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12959 add_loc_descr (&cc_loc_result
, x1_ref
);
12960 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12962 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12963 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12965 return cc_loc_result
;
12968 /* Return a descriptor that describes the concatenation of N
12971 static dw_loc_descr_ref
12972 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12975 dw_loc_descr_ref cc_loc_result
= NULL
;
12976 unsigned int n
= XVECLEN (concatn
, 0);
12978 for (i
= 0; i
< n
; ++i
)
12980 dw_loc_descr_ref ref
;
12981 rtx x
= XVECEXP (concatn
, 0, i
);
12983 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12987 add_loc_descr (&cc_loc_result
, ref
);
12988 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12991 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12992 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12994 return cc_loc_result
;
12997 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12998 for DEBUG_IMPLICIT_PTR RTL. */
13000 static dw_loc_descr_ref
13001 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13003 dw_loc_descr_ref ret
;
13008 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13009 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13010 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13011 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13012 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13013 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13016 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13017 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13018 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13022 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13023 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13028 /* Output a proper Dwarf location descriptor for a variable or parameter
13029 which is either allocated in a register or in a memory location. For a
13030 register, we just generate an OP_REG and the register number. For a
13031 memory location we provide a Dwarf postfix expression describing how to
13032 generate the (dynamic) address of the object onto the address stack.
13034 MODE is mode of the decl if this loc_descriptor is going to be used in
13035 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13036 allowed, VOIDmode otherwise.
13038 If we don't know how to describe it, return 0. */
13040 static dw_loc_descr_ref
13041 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13042 enum var_init_status initialized
)
13044 dw_loc_descr_ref loc_result
= NULL
;
13046 switch (GET_CODE (rtl
))
13049 /* The case of a subreg may arise when we have a local (register)
13050 variable or a formal (register) parameter which doesn't quite fill
13051 up an entire register. For now, just assume that it is
13052 legitimate to make the Dwarf info refer to the whole register which
13053 contains the given subreg. */
13054 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13055 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13056 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13062 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13066 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13067 GET_MODE (rtl
), initialized
);
13068 if (loc_result
== NULL
)
13069 loc_result
= tls_mem_loc_descriptor (rtl
);
13070 if (loc_result
== NULL
)
13072 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13073 if (new_rtl
!= rtl
)
13074 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13079 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13084 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13089 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13091 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13092 if (GET_CODE (loc
) == EXPR_LIST
)
13093 loc
= XEXP (loc
, 0);
13094 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13098 rtl
= XEXP (rtl
, 1);
13103 rtvec par_elems
= XVEC (rtl
, 0);
13104 int num_elem
= GET_NUM_ELEM (par_elems
);
13105 enum machine_mode mode
;
13108 /* Create the first one, so we have something to add to. */
13109 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13110 VOIDmode
, initialized
);
13111 if (loc_result
== NULL
)
13113 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13114 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13115 for (i
= 1; i
< num_elem
; i
++)
13117 dw_loc_descr_ref temp
;
13119 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13120 VOIDmode
, initialized
);
13123 add_loc_descr (&loc_result
, temp
);
13124 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13125 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13131 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13132 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13137 if (mode
== VOIDmode
)
13138 mode
= GET_MODE (rtl
);
13140 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13142 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13144 /* Note that a CONST_DOUBLE rtx could represent either an integer
13145 or a floating-point constant. A CONST_DOUBLE is used whenever
13146 the constant requires more than one word in order to be
13147 adequately represented. We output CONST_DOUBLEs as blocks. */
13148 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13149 GET_MODE_SIZE (mode
), 0);
13150 if (SCALAR_FLOAT_MODE_P (mode
))
13152 unsigned int length
= GET_MODE_SIZE (mode
);
13153 unsigned char *array
13154 = (unsigned char*) ggc_alloc_atomic (length
);
13156 insert_float (rtl
, array
);
13157 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13158 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13159 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13160 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13164 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13165 loc_result
->dw_loc_oprnd2
.v
.val_double
13166 = rtx_to_double_int (rtl
);
13172 if (mode
== VOIDmode
)
13173 mode
= GET_MODE (rtl
);
13175 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13177 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13178 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13179 unsigned char *array
= (unsigned char *)
13180 ggc_alloc_atomic (length
* elt_size
);
13184 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13185 switch (GET_MODE_CLASS (mode
))
13187 case MODE_VECTOR_INT
:
13188 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13190 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13191 double_int val
= rtx_to_double_int (elt
);
13193 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13194 insert_int (val
.to_shwi (), elt_size
, p
);
13197 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13198 insert_double (val
, p
);
13203 case MODE_VECTOR_FLOAT
:
13204 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13206 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13207 insert_float (elt
, p
);
13212 gcc_unreachable ();
13215 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13216 length
* elt_size
, 0);
13217 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13218 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13219 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13220 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13225 if (mode
== VOIDmode
13226 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13227 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13228 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13230 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13235 if (!const_ok_for_output (rtl
))
13238 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13239 && (dwarf_version
>= 4 || !dwarf_strict
))
13241 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13242 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13243 vec_safe_push (used_rtx_array
, rtl
);
13247 case DEBUG_IMPLICIT_PTR
:
13248 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13252 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13253 && CONST_INT_P (XEXP (rtl
, 1)))
13256 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13262 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13263 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13264 && dwarf_version
>= 4)
13265 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13267 /* Value expression. */
13268 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13270 add_loc_descr (&loc_result
,
13271 new_loc_descr (DW_OP_stack_value
, 0, 0));
13279 /* We need to figure out what section we should use as the base for the
13280 address ranges where a given location is valid.
13281 1. If this particular DECL has a section associated with it, use that.
13282 2. If this function has a section associated with it, use that.
13283 3. Otherwise, use the text section.
13284 XXX: If you split a variable across multiple sections, we won't notice. */
13286 static const char *
13287 secname_for_decl (const_tree decl
)
13289 const char *secname
;
13291 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13293 tree sectree
= DECL_SECTION_NAME (decl
);
13294 secname
= TREE_STRING_POINTER (sectree
);
13296 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13298 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13299 secname
= TREE_STRING_POINTER (sectree
);
13301 else if (cfun
&& in_cold_section_p
)
13302 secname
= crtl
->subsections
.cold_section_label
;
13304 secname
= text_section_label
;
13309 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13312 decl_by_reference_p (tree decl
)
13314 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13315 || TREE_CODE (decl
) == VAR_DECL
)
13316 && DECL_BY_REFERENCE (decl
));
13319 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13322 static dw_loc_descr_ref
13323 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13324 enum var_init_status initialized
)
13326 int have_address
= 0;
13327 dw_loc_descr_ref descr
;
13328 enum machine_mode mode
;
13330 if (want_address
!= 2)
13332 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13334 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13336 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13337 if (GET_CODE (varloc
) == EXPR_LIST
)
13338 varloc
= XEXP (varloc
, 0);
13339 mode
= GET_MODE (varloc
);
13340 if (MEM_P (varloc
))
13342 rtx addr
= XEXP (varloc
, 0);
13343 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13344 mode
, initialized
);
13349 rtx x
= avoid_constant_pool_reference (varloc
);
13351 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13356 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13363 if (GET_CODE (varloc
) == VAR_LOCATION
)
13364 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13366 mode
= DECL_MODE (loc
);
13367 descr
= loc_descriptor (varloc
, mode
, initialized
);
13374 if (want_address
== 2 && !have_address
13375 && (dwarf_version
>= 4 || !dwarf_strict
))
13377 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13379 expansion_failed (loc
, NULL_RTX
,
13380 "DWARF address size mismatch");
13383 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13386 /* Show if we can't fill the request for an address. */
13387 if (want_address
&& !have_address
)
13389 expansion_failed (loc
, NULL_RTX
,
13390 "Want address and only have value");
13394 /* If we've got an address and don't want one, dereference. */
13395 if (!want_address
&& have_address
)
13397 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13398 enum dwarf_location_atom op
;
13400 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13402 expansion_failed (loc
, NULL_RTX
,
13403 "DWARF address size mismatch");
13406 else if (size
== DWARF2_ADDR_SIZE
)
13409 op
= DW_OP_deref_size
;
13411 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13417 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13418 if it is not possible. */
13420 static dw_loc_descr_ref
13421 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13423 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13424 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13425 else if (dwarf_version
>= 3 || !dwarf_strict
)
13426 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13431 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13432 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13434 static dw_loc_descr_ref
13435 dw_sra_loc_expr (tree decl
, rtx loc
)
13438 unsigned int padsize
= 0;
13439 dw_loc_descr_ref descr
, *descr_tail
;
13440 unsigned HOST_WIDE_INT decl_size
;
13442 enum var_init_status initialized
;
13444 if (DECL_SIZE (decl
) == NULL
13445 || !host_integerp (DECL_SIZE (decl
), 1))
13448 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13450 descr_tail
= &descr
;
13452 for (p
= loc
; p
; p
= XEXP (p
, 1))
13454 unsigned int bitsize
= decl_piece_bitsize (p
);
13455 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13456 dw_loc_descr_ref cur_descr
;
13457 dw_loc_descr_ref
*tail
, last
= NULL
;
13458 unsigned int opsize
= 0;
13460 if (loc_note
== NULL_RTX
13461 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13463 padsize
+= bitsize
;
13466 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13467 varloc
= NOTE_VAR_LOCATION (loc_note
);
13468 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13469 if (cur_descr
== NULL
)
13471 padsize
+= bitsize
;
13475 /* Check that cur_descr either doesn't use
13476 DW_OP_*piece operations, or their sum is equal
13477 to bitsize. Otherwise we can't embed it. */
13478 for (tail
= &cur_descr
; *tail
!= NULL
;
13479 tail
= &(*tail
)->dw_loc_next
)
13480 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13482 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13486 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13488 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13492 if (last
!= NULL
&& opsize
!= bitsize
)
13494 padsize
+= bitsize
;
13495 /* Discard the current piece of the descriptor and release any
13496 addr_table entries it uses. */
13497 remove_loc_list_addr_table_entries (cur_descr
);
13501 /* If there is a hole, add DW_OP_*piece after empty DWARF
13502 expression, which means that those bits are optimized out. */
13505 if (padsize
> decl_size
)
13507 remove_loc_list_addr_table_entries (cur_descr
);
13508 goto discard_descr
;
13510 decl_size
-= padsize
;
13511 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13512 if (*descr_tail
== NULL
)
13514 remove_loc_list_addr_table_entries (cur_descr
);
13515 goto discard_descr
;
13517 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13520 *descr_tail
= cur_descr
;
13522 if (bitsize
> decl_size
)
13523 goto discard_descr
;
13524 decl_size
-= bitsize
;
13527 HOST_WIDE_INT offset
= 0;
13528 if (GET_CODE (varloc
) == VAR_LOCATION
13529 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13531 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13532 if (GET_CODE (varloc
) == EXPR_LIST
)
13533 varloc
= XEXP (varloc
, 0);
13537 if (GET_CODE (varloc
) == CONST
13538 || GET_CODE (varloc
) == SIGN_EXTEND
13539 || GET_CODE (varloc
) == ZERO_EXTEND
)
13540 varloc
= XEXP (varloc
, 0);
13541 else if (GET_CODE (varloc
) == SUBREG
)
13542 varloc
= SUBREG_REG (varloc
);
13547 /* DW_OP_bit_size offset should be zero for register
13548 or implicit location descriptions and empty location
13549 descriptions, but for memory addresses needs big endian
13551 if (MEM_P (varloc
))
13553 unsigned HOST_WIDE_INT memsize
13554 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13555 if (memsize
!= bitsize
)
13557 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13558 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13559 goto discard_descr
;
13560 if (memsize
< bitsize
)
13561 goto discard_descr
;
13562 if (BITS_BIG_ENDIAN
)
13563 offset
= memsize
- bitsize
;
13567 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13568 if (*descr_tail
== NULL
)
13569 goto discard_descr
;
13570 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13574 /* If there were any non-empty expressions, add padding till the end of
13576 if (descr
!= NULL
&& decl_size
!= 0)
13578 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13579 if (*descr_tail
== NULL
)
13580 goto discard_descr
;
13585 /* Discard the descriptor and release any addr_table entries it uses. */
13586 remove_loc_list_addr_table_entries (descr
);
13590 /* Return the dwarf representation of the location list LOC_LIST of
13591 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13594 static dw_loc_list_ref
13595 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13597 const char *endname
, *secname
;
13599 enum var_init_status initialized
;
13600 struct var_loc_node
*node
;
13601 dw_loc_descr_ref descr
;
13602 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13603 dw_loc_list_ref list
= NULL
;
13604 dw_loc_list_ref
*listp
= &list
;
13606 /* Now that we know what section we are using for a base,
13607 actually construct the list of locations.
13608 The first location information is what is passed to the
13609 function that creates the location list, and the remaining
13610 locations just get added on to that list.
13611 Note that we only know the start address for a location
13612 (IE location changes), so to build the range, we use
13613 the range [current location start, next location start].
13614 This means we have to special case the last node, and generate
13615 a range of [last location start, end of function label]. */
13617 secname
= secname_for_decl (decl
);
13619 for (node
= loc_list
->first
; node
; node
= node
->next
)
13620 if (GET_CODE (node
->loc
) == EXPR_LIST
13621 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13623 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13625 /* This requires DW_OP_{,bit_}piece, which is not usable
13626 inside DWARF expressions. */
13627 if (want_address
!= 2)
13629 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13635 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13636 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13637 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13641 bool range_across_switch
= false;
13642 /* If section switch happens in between node->label
13643 and node->next->label (or end of function) and
13644 we can't emit it as a single entry list,
13645 emit two ranges, first one ending at the end
13646 of first partition and second one starting at the
13647 beginning of second partition. */
13648 if (node
== loc_list
->last_before_switch
13649 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13650 && current_function_decl
)
13652 endname
= cfun
->fde
->dw_fde_end
;
13653 range_across_switch
= true;
13655 /* The variable has a location between NODE->LABEL and
13656 NODE->NEXT->LABEL. */
13657 else if (node
->next
)
13658 endname
= node
->next
->label
;
13659 /* If the variable has a location at the last label
13660 it keeps its location until the end of function. */
13661 else if (!current_function_decl
)
13662 endname
= text_end_label
;
13665 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13666 current_function_funcdef_no
);
13667 endname
= ggc_strdup (label_id
);
13670 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13671 if (TREE_CODE (decl
) == PARM_DECL
13672 && node
== loc_list
->first
13673 && NOTE_P (node
->loc
)
13674 && strcmp (node
->label
, endname
) == 0)
13675 (*listp
)->force
= true;
13676 listp
= &(*listp
)->dw_loc_next
;
13678 if (range_across_switch
)
13680 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13681 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13684 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13685 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13686 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13689 gcc_assert (descr
);
13690 /* The variable has a location between NODE->LABEL and
13691 NODE->NEXT->LABEL. */
13693 endname
= node
->next
->label
;
13695 endname
= cfun
->fde
->dw_fde_second_end
;
13696 *listp
= new_loc_list (descr
,
13697 cfun
->fde
->dw_fde_second_begin
,
13699 listp
= &(*listp
)->dw_loc_next
;
13704 /* Try to avoid the overhead of a location list emitting a location
13705 expression instead, but only if we didn't have more than one
13706 location entry in the first place. If some entries were not
13707 representable, we don't want to pretend a single entry that was
13708 applies to the entire scope in which the variable is
13710 if (list
&& loc_list
->first
->next
)
13716 /* Return if the loc_list has only single element and thus can be represented
13717 as location description. */
13720 single_element_loc_list_p (dw_loc_list_ref list
)
13722 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13723 return !list
->ll_symbol
;
13726 /* To each location in list LIST add loc descr REF. */
13729 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13731 dw_loc_descr_ref copy
;
13732 add_loc_descr (&list
->expr
, ref
);
13733 list
= list
->dw_loc_next
;
13736 copy
= ggc_alloc_dw_loc_descr_node ();
13737 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13738 add_loc_descr (&list
->expr
, copy
);
13739 while (copy
->dw_loc_next
)
13741 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13742 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13743 copy
->dw_loc_next
= new_copy
;
13746 list
= list
->dw_loc_next
;
13750 /* Given two lists RET and LIST
13751 produce location list that is result of adding expression in LIST
13752 to expression in RET on each position in program.
13753 Might be destructive on both RET and LIST.
13755 TODO: We handle only simple cases of RET or LIST having at most one
13756 element. General case would inolve sorting the lists in program order
13757 and merging them that will need some additional work.
13758 Adding that will improve quality of debug info especially for SRA-ed
13762 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13771 if (!list
->dw_loc_next
)
13773 add_loc_descr_to_each (*ret
, list
->expr
);
13776 if (!(*ret
)->dw_loc_next
)
13778 add_loc_descr_to_each (list
, (*ret
)->expr
);
13782 expansion_failed (NULL_TREE
, NULL_RTX
,
13783 "Don't know how to merge two non-trivial"
13784 " location lists.\n");
13789 /* LOC is constant expression. Try a luck, look it up in constant
13790 pool and return its loc_descr of its address. */
13792 static dw_loc_descr_ref
13793 cst_pool_loc_descr (tree loc
)
13795 /* Get an RTL for this, if something has been emitted. */
13796 rtx rtl
= lookup_constant_def (loc
);
13798 if (!rtl
|| !MEM_P (rtl
))
13803 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13805 /* TODO: We might get more coverage if we was actually delaying expansion
13806 of all expressions till end of compilation when constant pools are fully
13808 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13810 expansion_failed (loc
, NULL_RTX
,
13811 "CST value in contant pool but not marked.");
13814 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13815 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13818 /* Return dw_loc_list representing address of addr_expr LOC
13819 by looking for inner INDIRECT_REF expression and turning
13820 it into simple arithmetics. */
13822 static dw_loc_list_ref
13823 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13826 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13827 enum machine_mode mode
;
13828 int unsignedp
, volatilep
= 0;
13829 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13831 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13832 &bitsize
, &bitpos
, &offset
, &mode
,
13833 &unsignedp
, &volatilep
, false);
13835 if (bitpos
% BITS_PER_UNIT
)
13837 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13840 if (!INDIRECT_REF_P (obj
))
13842 expansion_failed (obj
,
13843 NULL_RTX
, "no indirect ref in inner refrence");
13846 if (!offset
&& !bitpos
)
13847 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13849 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13850 && (dwarf_version
>= 4 || !dwarf_strict
))
13852 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13857 /* Variable offset. */
13858 list_ret1
= loc_list_from_tree (offset
, 0);
13859 if (list_ret1
== 0)
13861 add_loc_list (&list_ret
, list_ret1
);
13864 add_loc_descr_to_each (list_ret
,
13865 new_loc_descr (DW_OP_plus
, 0, 0));
13867 bytepos
= bitpos
/ BITS_PER_UNIT
;
13869 add_loc_descr_to_each (list_ret
,
13870 new_loc_descr (DW_OP_plus_uconst
,
13872 else if (bytepos
< 0)
13873 loc_list_plus_const (list_ret
, bytepos
);
13874 add_loc_descr_to_each (list_ret
,
13875 new_loc_descr (DW_OP_stack_value
, 0, 0));
13881 /* Generate Dwarf location list representing LOC.
13882 If WANT_ADDRESS is false, expression computing LOC will be computed
13883 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13884 if WANT_ADDRESS is 2, expression computing address useable in location
13885 will be returned (i.e. DW_OP_reg can be used
13886 to refer to register values). */
13888 static dw_loc_list_ref
13889 loc_list_from_tree (tree loc
, int want_address
)
13891 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13892 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13893 int have_address
= 0;
13894 enum dwarf_location_atom op
;
13896 /* ??? Most of the time we do not take proper care for sign/zero
13897 extending the values properly. Hopefully this won't be a real
13900 switch (TREE_CODE (loc
))
13903 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13906 case PLACEHOLDER_EXPR
:
13907 /* This case involves extracting fields from an object to determine the
13908 position of other fields. We don't try to encode this here. The
13909 only user of this is Ada, which encodes the needed information using
13910 the names of types. */
13911 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13915 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13916 /* There are no opcodes for these operations. */
13919 case PREINCREMENT_EXPR
:
13920 case PREDECREMENT_EXPR
:
13921 case POSTINCREMENT_EXPR
:
13922 case POSTDECREMENT_EXPR
:
13923 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13924 /* There are no opcodes for these operations. */
13928 /* If we already want an address, see if there is INDIRECT_REF inside
13929 e.g. for &this->field. */
13932 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13933 (loc
, want_address
== 2);
13936 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13937 && (ret
= cst_pool_loc_descr (loc
)))
13940 /* Otherwise, process the argument and look for the address. */
13941 if (!list_ret
&& !ret
)
13942 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13946 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13952 if (DECL_THREAD_LOCAL_P (loc
))
13955 enum dwarf_location_atom tls_op
;
13956 enum dtprel_bool dtprel
= dtprel_false
;
13958 if (targetm
.have_tls
)
13960 /* If this is not defined, we have no way to emit the
13962 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13965 /* The way DW_OP_GNU_push_tls_address is specified, we
13966 can only look up addresses of objects in the current
13967 module. We used DW_OP_addr as first op, but that's
13968 wrong, because DW_OP_addr is relocated by the debug
13969 info consumer, while DW_OP_GNU_push_tls_address
13970 operand shouldn't be. */
13971 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13973 dtprel
= dtprel_true
;
13974 tls_op
= DW_OP_GNU_push_tls_address
;
13978 if (!targetm
.emutls
.debug_form_tls_address
13979 || !(dwarf_version
>= 3 || !dwarf_strict
))
13981 /* We stuffed the control variable into the DECL_VALUE_EXPR
13982 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13983 no longer appear in gimple code. We used the control
13984 variable in specific so that we could pick it up here. */
13985 loc
= DECL_VALUE_EXPR (loc
);
13986 tls_op
= DW_OP_form_tls_address
;
13989 rtl
= rtl_for_decl_location (loc
);
13990 if (rtl
== NULL_RTX
)
13995 rtl
= XEXP (rtl
, 0);
13996 if (! CONSTANT_P (rtl
))
13999 ret
= new_addr_loc_descr (rtl
, dtprel
);
14000 ret1
= new_loc_descr (tls_op
, 0, 0);
14001 add_loc_descr (&ret
, ret1
);
14010 if (DECL_HAS_VALUE_EXPR_P (loc
))
14011 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14015 case FUNCTION_DECL
:
14018 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14020 if (loc_list
&& loc_list
->first
)
14022 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14023 have_address
= want_address
!= 0;
14026 rtl
= rtl_for_decl_location (loc
);
14027 if (rtl
== NULL_RTX
)
14029 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14032 else if (CONST_INT_P (rtl
))
14034 HOST_WIDE_INT val
= INTVAL (rtl
);
14035 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14036 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14037 ret
= int_loc_descriptor (val
);
14039 else if (GET_CODE (rtl
) == CONST_STRING
)
14041 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14044 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14045 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14048 enum machine_mode mode
, mem_mode
;
14050 /* Certain constructs can only be represented at top-level. */
14051 if (want_address
== 2)
14053 ret
= loc_descriptor (rtl
, VOIDmode
,
14054 VAR_INIT_STATUS_INITIALIZED
);
14059 mode
= GET_MODE (rtl
);
14060 mem_mode
= VOIDmode
;
14064 mode
= get_address_mode (rtl
);
14065 rtl
= XEXP (rtl
, 0);
14068 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14069 VAR_INIT_STATUS_INITIALIZED
);
14072 expansion_failed (loc
, rtl
,
14073 "failed to produce loc descriptor for rtl");
14080 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14084 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14088 case COMPOUND_EXPR
:
14089 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14092 case VIEW_CONVERT_EXPR
:
14095 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14097 case COMPONENT_REF
:
14098 case BIT_FIELD_REF
:
14100 case ARRAY_RANGE_REF
:
14101 case REALPART_EXPR
:
14102 case IMAGPART_EXPR
:
14105 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14106 enum machine_mode mode
;
14107 int unsignedp
, volatilep
= 0;
14109 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14110 &unsignedp
, &volatilep
, false);
14112 gcc_assert (obj
!= loc
);
14114 list_ret
= loc_list_from_tree (obj
,
14116 && !bitpos
&& !offset
? 2 : 1);
14117 /* TODO: We can extract value of the small expression via shifting even
14118 for nonzero bitpos. */
14121 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14123 expansion_failed (loc
, NULL_RTX
,
14124 "bitfield access");
14128 if (offset
!= NULL_TREE
)
14130 /* Variable offset. */
14131 list_ret1
= loc_list_from_tree (offset
, 0);
14132 if (list_ret1
== 0)
14134 add_loc_list (&list_ret
, list_ret1
);
14137 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14140 bytepos
= bitpos
/ BITS_PER_UNIT
;
14142 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14143 else if (bytepos
< 0)
14144 loc_list_plus_const (list_ret
, bytepos
);
14151 if ((want_address
|| !host_integerp (loc
, 0))
14152 && (ret
= cst_pool_loc_descr (loc
)))
14154 else if (want_address
== 2
14155 && host_integerp (loc
, 0)
14156 && (ret
= address_of_int_loc_descriptor
14157 (int_size_in_bytes (TREE_TYPE (loc
)),
14158 tree_low_cst (loc
, 0))))
14160 else if (host_integerp (loc
, 0))
14161 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14164 expansion_failed (loc
, NULL_RTX
,
14165 "Integer operand is not host integer");
14174 if ((ret
= cst_pool_loc_descr (loc
)))
14177 /* We can construct small constants here using int_loc_descriptor. */
14178 expansion_failed (loc
, NULL_RTX
,
14179 "constructor or constant not in constant pool");
14182 case TRUTH_AND_EXPR
:
14183 case TRUTH_ANDIF_EXPR
:
14188 case TRUTH_XOR_EXPR
:
14193 case TRUTH_OR_EXPR
:
14194 case TRUTH_ORIF_EXPR
:
14199 case FLOOR_DIV_EXPR
:
14200 case CEIL_DIV_EXPR
:
14201 case ROUND_DIV_EXPR
:
14202 case TRUNC_DIV_EXPR
:
14203 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14212 case FLOOR_MOD_EXPR
:
14213 case CEIL_MOD_EXPR
:
14214 case ROUND_MOD_EXPR
:
14215 case TRUNC_MOD_EXPR
:
14216 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14221 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14222 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14223 if (list_ret
== 0 || list_ret1
== 0)
14226 add_loc_list (&list_ret
, list_ret1
);
14229 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14230 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14231 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14232 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14233 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14245 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14248 case POINTER_PLUS_EXPR
:
14250 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14252 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14256 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14264 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14271 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14278 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14285 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14300 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14301 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14302 if (list_ret
== 0 || list_ret1
== 0)
14305 add_loc_list (&list_ret
, list_ret1
);
14308 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14311 case TRUTH_NOT_EXPR
:
14325 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14329 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14335 const enum tree_code code
=
14336 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14338 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14339 build2 (code
, integer_type_node
,
14340 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14341 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14344 /* ... fall through ... */
14348 dw_loc_descr_ref lhs
14349 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14350 dw_loc_list_ref rhs
14351 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14352 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14354 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14355 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14358 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14359 add_loc_descr_to_each (list_ret
, bra_node
);
14361 add_loc_list (&list_ret
, rhs
);
14362 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14363 add_loc_descr_to_each (list_ret
, jump_node
);
14365 add_loc_descr_to_each (list_ret
, lhs
);
14366 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14367 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14369 /* ??? Need a node to point the skip at. Use a nop. */
14370 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14371 add_loc_descr_to_each (list_ret
, tmp
);
14372 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14373 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14377 case FIX_TRUNC_EXPR
:
14381 /* Leave front-end specific codes as simply unknown. This comes
14382 up, for instance, with the C STMT_EXPR. */
14383 if ((unsigned int) TREE_CODE (loc
)
14384 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14386 expansion_failed (loc
, NULL_RTX
,
14387 "language specific tree node");
14391 #ifdef ENABLE_CHECKING
14392 /* Otherwise this is a generic code; we should just lists all of
14393 these explicitly. We forgot one. */
14394 gcc_unreachable ();
14396 /* In a release build, we want to degrade gracefully: better to
14397 generate incomplete debugging information than to crash. */
14402 if (!ret
&& !list_ret
)
14405 if (want_address
== 2 && !have_address
14406 && (dwarf_version
>= 4 || !dwarf_strict
))
14408 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14410 expansion_failed (loc
, NULL_RTX
,
14411 "DWARF address size mismatch");
14415 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14417 add_loc_descr_to_each (list_ret
,
14418 new_loc_descr (DW_OP_stack_value
, 0, 0));
14421 /* Show if we can't fill the request for an address. */
14422 if (want_address
&& !have_address
)
14424 expansion_failed (loc
, NULL_RTX
,
14425 "Want address and only have value");
14429 gcc_assert (!ret
|| !list_ret
);
14431 /* If we've got an address and don't want one, dereference. */
14432 if (!want_address
&& have_address
)
14434 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14436 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14438 expansion_failed (loc
, NULL_RTX
,
14439 "DWARF address size mismatch");
14442 else if (size
== DWARF2_ADDR_SIZE
)
14445 op
= DW_OP_deref_size
;
14448 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14450 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14453 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14458 /* Same as above but return only single location expression. */
14459 static dw_loc_descr_ref
14460 loc_descriptor_from_tree (tree loc
, int want_address
)
14462 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14465 if (ret
->dw_loc_next
)
14467 expansion_failed (loc
, NULL_RTX
,
14468 "Location list where only loc descriptor needed");
14474 /* Given a value, round it up to the lowest multiple of `boundary'
14475 which is not less than the value itself. */
14477 static inline HOST_WIDE_INT
14478 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14480 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14483 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14484 pointer to the declared type for the relevant field variable, or return
14485 `integer_type_node' if the given node turns out to be an
14486 ERROR_MARK node. */
14489 field_type (const_tree decl
)
14493 if (TREE_CODE (decl
) == ERROR_MARK
)
14494 return integer_type_node
;
14496 type
= DECL_BIT_FIELD_TYPE (decl
);
14497 if (type
== NULL_TREE
)
14498 type
= TREE_TYPE (decl
);
14503 /* Given a pointer to a tree node, return the alignment in bits for
14504 it, or else return BITS_PER_WORD if the node actually turns out to
14505 be an ERROR_MARK node. */
14507 static inline unsigned
14508 simple_type_align_in_bits (const_tree type
)
14510 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14513 static inline unsigned
14514 simple_decl_align_in_bits (const_tree decl
)
14516 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14519 /* Return the result of rounding T up to ALIGN. */
14521 static inline double_int
14522 round_up_to_align (double_int t
, unsigned int align
)
14524 double_int alignd
= double_int::from_uhwi (align
);
14526 t
+= double_int_minus_one
;
14527 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14532 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14533 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14534 or return 0 if we are unable to determine what that offset is, either
14535 because the argument turns out to be a pointer to an ERROR_MARK node, or
14536 because the offset is actually variable. (We can't handle the latter case
14539 static HOST_WIDE_INT
14540 field_byte_offset (const_tree decl
)
14542 double_int object_offset_in_bits
;
14543 double_int object_offset_in_bytes
;
14544 double_int bitpos_int
;
14546 if (TREE_CODE (decl
) == ERROR_MARK
)
14549 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14551 /* We cannot yet cope with fields whose positions are variable, so
14552 for now, when we see such things, we simply return 0. Someday, we may
14553 be able to handle such cases, but it will be damn difficult. */
14554 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14557 bitpos_int
= tree_to_double_int (bit_position (decl
));
14559 #ifdef PCC_BITFIELD_TYPE_MATTERS
14560 if (PCC_BITFIELD_TYPE_MATTERS
)
14563 tree field_size_tree
;
14564 double_int deepest_bitpos
;
14565 double_int field_size_in_bits
;
14566 unsigned int type_align_in_bits
;
14567 unsigned int decl_align_in_bits
;
14568 double_int type_size_in_bits
;
14570 type
= field_type (decl
);
14571 type_size_in_bits
= double_int_type_size_in_bits (type
);
14572 type_align_in_bits
= simple_type_align_in_bits (type
);
14574 field_size_tree
= DECL_SIZE (decl
);
14576 /* The size could be unspecified if there was an error, or for
14577 a flexible array member. */
14578 if (!field_size_tree
)
14579 field_size_tree
= bitsize_zero_node
;
14581 /* If the size of the field is not constant, use the type size. */
14582 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14583 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14585 field_size_in_bits
= type_size_in_bits
;
14587 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14589 /* The GCC front-end doesn't make any attempt to keep track of the
14590 starting bit offset (relative to the start of the containing
14591 structure type) of the hypothetical "containing object" for a
14592 bit-field. Thus, when computing the byte offset value for the
14593 start of the "containing object" of a bit-field, we must deduce
14594 this information on our own. This can be rather tricky to do in
14595 some cases. For example, handling the following structure type
14596 definition when compiling for an i386/i486 target (which only
14597 aligns long long's to 32-bit boundaries) can be very tricky:
14599 struct S { int field1; long long field2:31; };
14601 Fortunately, there is a simple rule-of-thumb which can be used
14602 in such cases. When compiling for an i386/i486, GCC will
14603 allocate 8 bytes for the structure shown above. It decides to
14604 do this based upon one simple rule for bit-field allocation.
14605 GCC allocates each "containing object" for each bit-field at
14606 the first (i.e. lowest addressed) legitimate alignment boundary
14607 (based upon the required minimum alignment for the declared
14608 type of the field) which it can possibly use, subject to the
14609 condition that there is still enough available space remaining
14610 in the containing object (when allocated at the selected point)
14611 to fully accommodate all of the bits of the bit-field itself.
14613 This simple rule makes it obvious why GCC allocates 8 bytes for
14614 each object of the structure type shown above. When looking
14615 for a place to allocate the "containing object" for `field2',
14616 the compiler simply tries to allocate a 64-bit "containing
14617 object" at each successive 32-bit boundary (starting at zero)
14618 until it finds a place to allocate that 64- bit field such that
14619 at least 31 contiguous (and previously unallocated) bits remain
14620 within that selected 64 bit field. (As it turns out, for the
14621 example above, the compiler finds it is OK to allocate the
14622 "containing object" 64-bit field at bit-offset zero within the
14625 Here we attempt to work backwards from the limited set of facts
14626 we're given, and we try to deduce from those facts, where GCC
14627 must have believed that the containing object started (within
14628 the structure type). The value we deduce is then used (by the
14629 callers of this routine) to generate DW_AT_location and
14630 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14631 the case of DW_AT_location, regular fields as well). */
14633 /* Figure out the bit-distance from the start of the structure to
14634 the "deepest" bit of the bit-field. */
14635 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14637 /* This is the tricky part. Use some fancy footwork to deduce
14638 where the lowest addressed bit of the containing object must
14640 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14642 /* Round up to type_align by default. This works best for
14644 object_offset_in_bits
14645 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14647 if (object_offset_in_bits
.ugt (bitpos_int
))
14649 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14651 /* Round up to decl_align instead. */
14652 object_offset_in_bits
14653 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14657 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14658 object_offset_in_bits
= bitpos_int
;
14660 object_offset_in_bytes
14661 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14662 true, TRUNC_DIV_EXPR
);
14663 return object_offset_in_bytes
.to_shwi ();
14666 /* The following routines define various Dwarf attributes and any data
14667 associated with them. */
14669 /* Add a location description attribute value to a DIE.
14671 This emits location attributes suitable for whole variables and
14672 whole parameters. Note that the location attributes for struct fields are
14673 generated by the routine `data_member_location_attribute' below. */
14676 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14677 dw_loc_list_ref descr
)
14681 if (single_element_loc_list_p (descr
))
14682 add_AT_loc (die
, attr_kind
, descr
->expr
);
14684 add_AT_loc_list (die
, attr_kind
, descr
);
14687 /* Add DW_AT_accessibility attribute to DIE if needed. */
14690 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14692 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14693 children, otherwise the default is DW_ACCESS_public. In DWARF2
14694 the default has always been DW_ACCESS_public. */
14695 if (TREE_PROTECTED (decl
))
14696 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14697 else if (TREE_PRIVATE (decl
))
14699 if (dwarf_version
== 2
14700 || die
->die_parent
== NULL
14701 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14702 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14704 else if (dwarf_version
> 2
14706 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14707 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14710 /* Attach the specialized form of location attribute used for data members of
14711 struct and union types. In the special case of a FIELD_DECL node which
14712 represents a bit-field, the "offset" part of this special location
14713 descriptor must indicate the distance in bytes from the lowest-addressed
14714 byte of the containing struct or union type to the lowest-addressed byte of
14715 the "containing object" for the bit-field. (See the `field_byte_offset'
14718 For any given bit-field, the "containing object" is a hypothetical object
14719 (of some integral or enum type) within which the given bit-field lives. The
14720 type of this hypothetical "containing object" is always the same as the
14721 declared type of the individual bit-field itself (for GCC anyway... the
14722 DWARF spec doesn't actually mandate this). Note that it is the size (in
14723 bytes) of the hypothetical "containing object" which will be given in the
14724 DW_AT_byte_size attribute for this bit-field. (See the
14725 `byte_size_attribute' function below.) It is also used when calculating the
14726 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14727 function below.) */
14730 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14732 HOST_WIDE_INT offset
;
14733 dw_loc_descr_ref loc_descr
= 0;
14735 if (TREE_CODE (decl
) == TREE_BINFO
)
14737 /* We're working on the TAG_inheritance for a base class. */
14738 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14740 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14741 aren't at a fixed offset from all (sub)objects of the same
14742 type. We need to extract the appropriate offset from our
14743 vtable. The following dwarf expression means
14745 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14747 This is specific to the V3 ABI, of course. */
14749 dw_loc_descr_ref tmp
;
14751 /* Make a copy of the object address. */
14752 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14753 add_loc_descr (&loc_descr
, tmp
);
14755 /* Extract the vtable address. */
14756 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14757 add_loc_descr (&loc_descr
, tmp
);
14759 /* Calculate the address of the offset. */
14760 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14761 gcc_assert (offset
< 0);
14763 tmp
= int_loc_descriptor (-offset
);
14764 add_loc_descr (&loc_descr
, tmp
);
14765 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14766 add_loc_descr (&loc_descr
, tmp
);
14768 /* Extract the offset. */
14769 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14770 add_loc_descr (&loc_descr
, tmp
);
14772 /* Add it to the object address. */
14773 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14774 add_loc_descr (&loc_descr
, tmp
);
14777 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14780 offset
= field_byte_offset (decl
);
14784 if (dwarf_version
> 2)
14786 /* Don't need to output a location expression, just the constant. */
14788 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14790 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14795 enum dwarf_location_atom op
;
14797 /* The DWARF2 standard says that we should assume that the structure
14798 address is already on the stack, so we can specify a structure
14799 field address by using DW_OP_plus_uconst. */
14800 op
= DW_OP_plus_uconst
;
14801 loc_descr
= new_loc_descr (op
, offset
, 0);
14805 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14808 /* Writes integer values to dw_vec_const array. */
14811 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14815 *dest
++ = val
& 0xff;
14821 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14823 static HOST_WIDE_INT
14824 extract_int (const unsigned char *src
, unsigned int size
)
14826 HOST_WIDE_INT val
= 0;
14832 val
|= *--src
& 0xff;
14838 /* Writes double_int values to dw_vec_const array. */
14841 insert_double (double_int val
, unsigned char *dest
)
14843 unsigned char *p0
= dest
;
14844 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14846 if (WORDS_BIG_ENDIAN
)
14852 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14853 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14856 /* Writes floating point values to dw_vec_const array. */
14859 insert_float (const_rtx rtl
, unsigned char *array
)
14861 REAL_VALUE_TYPE rv
;
14865 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14866 real_to_target (val
, &rv
, GET_MODE (rtl
));
14868 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14869 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14871 insert_int (val
[i
], 4, array
);
14876 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14877 does not have a "location" either in memory or in a register. These
14878 things can arise in GNU C when a constant is passed as an actual parameter
14879 to an inlined function. They can also arise in C++ where declared
14880 constants do not necessarily get memory "homes". */
14883 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14885 switch (GET_CODE (rtl
))
14889 HOST_WIDE_INT val
= INTVAL (rtl
);
14892 add_AT_int (die
, DW_AT_const_value
, val
);
14894 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14899 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14900 floating-point constant. A CONST_DOUBLE is used whenever the
14901 constant requires more than one word in order to be adequately
14904 enum machine_mode mode
= GET_MODE (rtl
);
14906 if (SCALAR_FLOAT_MODE_P (mode
))
14908 unsigned int length
= GET_MODE_SIZE (mode
);
14909 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14911 insert_float (rtl
, array
);
14912 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14915 add_AT_double (die
, DW_AT_const_value
,
14916 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14922 enum machine_mode mode
= GET_MODE (rtl
);
14923 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14924 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14925 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14926 (length
* elt_size
);
14930 switch (GET_MODE_CLASS (mode
))
14932 case MODE_VECTOR_INT
:
14933 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14935 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14936 double_int val
= rtx_to_double_int (elt
);
14938 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14939 insert_int (val
.to_shwi (), elt_size
, p
);
14942 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14943 insert_double (val
, p
);
14948 case MODE_VECTOR_FLOAT
:
14949 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14951 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14952 insert_float (elt
, p
);
14957 gcc_unreachable ();
14960 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14965 if (dwarf_version
>= 4 || !dwarf_strict
)
14967 dw_loc_descr_ref loc_result
;
14968 resolve_one_addr (&rtl
, NULL
);
14970 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14971 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14972 add_AT_loc (die
, DW_AT_location
, loc_result
);
14973 vec_safe_push (used_rtx_array
, rtl
);
14979 if (CONSTANT_P (XEXP (rtl
, 0)))
14980 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14983 if (!const_ok_for_output (rtl
))
14986 if (dwarf_version
>= 4 || !dwarf_strict
)
14991 /* In cases where an inlined instance of an inline function is passed
14992 the address of an `auto' variable (which is local to the caller) we
14993 can get a situation where the DECL_RTL of the artificial local
14994 variable (for the inlining) which acts as a stand-in for the
14995 corresponding formal parameter (of the inline function) will look
14996 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14997 exactly a compile-time constant expression, but it isn't the address
14998 of the (artificial) local variable either. Rather, it represents the
14999 *value* which the artificial local variable always has during its
15000 lifetime. We currently have no way to represent such quasi-constant
15001 values in Dwarf, so for now we just punt and generate nothing. */
15009 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15010 && MEM_READONLY_P (rtl
)
15011 && GET_MODE (rtl
) == BLKmode
)
15013 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15019 /* No other kinds of rtx should be possible here. */
15020 gcc_unreachable ();
15025 /* Determine whether the evaluation of EXPR references any variables
15026 or functions which aren't otherwise used (and therefore may not be
15029 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15030 void * data ATTRIBUTE_UNUSED
)
15032 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15033 *walk_subtrees
= 0;
15035 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15036 && ! TREE_ASM_WRITTEN (*tp
))
15038 /* ??? The C++ FE emits debug information for using decls, so
15039 putting gcc_unreachable here falls over. See PR31899. For now
15040 be conservative. */
15041 else if (!cgraph_global_info_ready
15042 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15044 else if (TREE_CODE (*tp
) == VAR_DECL
)
15046 struct varpool_node
*node
= varpool_get_node (*tp
);
15047 if (!node
|| !node
->symbol
.definition
)
15050 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15051 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15053 /* The call graph machinery must have finished analyzing,
15054 optimizing and gimplifying the CU by now.
15055 So if *TP has no call graph node associated
15056 to it, it means *TP will not be emitted. */
15057 if (!cgraph_get_node (*tp
))
15060 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15066 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15067 for use in a later add_const_value_attribute call. */
15070 rtl_for_decl_init (tree init
, tree type
)
15072 rtx rtl
= NULL_RTX
;
15076 /* If a variable is initialized with a string constant without embedded
15077 zeros, build CONST_STRING. */
15078 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15080 tree enttype
= TREE_TYPE (type
);
15081 tree domain
= TYPE_DOMAIN (type
);
15082 enum machine_mode mode
= TYPE_MODE (enttype
);
15084 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15086 && integer_zerop (TYPE_MIN_VALUE (domain
))
15087 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15088 TREE_STRING_LENGTH (init
) - 1) == 0
15089 && ((size_t) TREE_STRING_LENGTH (init
)
15090 == strlen (TREE_STRING_POINTER (init
)) + 1))
15092 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15093 ggc_strdup (TREE_STRING_POINTER (init
)));
15094 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15095 MEM_READONLY_P (rtl
) = 1;
15098 /* Other aggregates, and complex values, could be represented using
15100 else if (AGGREGATE_TYPE_P (type
)
15101 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15102 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15103 || TREE_CODE (type
) == COMPLEX_TYPE
)
15105 /* Vectors only work if their mode is supported by the target.
15106 FIXME: generic vectors ought to work too. */
15107 else if (TREE_CODE (type
) == VECTOR_TYPE
15108 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15110 /* If the initializer is something that we know will expand into an
15111 immediate RTL constant, expand it now. We must be careful not to
15112 reference variables which won't be output. */
15113 else if (initializer_constant_valid_p (init
, type
)
15114 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15116 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15118 if (TREE_CODE (type
) == VECTOR_TYPE
)
15119 switch (TREE_CODE (init
))
15124 if (TREE_CONSTANT (init
))
15126 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15127 bool constant_p
= true;
15129 unsigned HOST_WIDE_INT ix
;
15131 /* Even when ctor is constant, it might contain non-*_CST
15132 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15133 belong into VECTOR_CST nodes. */
15134 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15135 if (!CONSTANT_CLASS_P (value
))
15137 constant_p
= false;
15143 init
= build_vector_from_ctor (type
, elts
);
15153 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15155 /* If expand_expr returns a MEM, it wasn't immediate. */
15156 gcc_assert (!rtl
|| !MEM_P (rtl
));
15162 /* Generate RTL for the variable DECL to represent its location. */
15165 rtl_for_decl_location (tree decl
)
15169 /* Here we have to decide where we are going to say the parameter "lives"
15170 (as far as the debugger is concerned). We only have a couple of
15171 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15173 DECL_RTL normally indicates where the parameter lives during most of the
15174 activation of the function. If optimization is enabled however, this
15175 could be either NULL or else a pseudo-reg. Both of those cases indicate
15176 that the parameter doesn't really live anywhere (as far as the code
15177 generation parts of GCC are concerned) during most of the function's
15178 activation. That will happen (for example) if the parameter is never
15179 referenced within the function.
15181 We could just generate a location descriptor here for all non-NULL
15182 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15183 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15184 where DECL_RTL is NULL or is a pseudo-reg.
15186 Note however that we can only get away with using DECL_INCOMING_RTL as
15187 a backup substitute for DECL_RTL in certain limited cases. In cases
15188 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15189 we can be sure that the parameter was passed using the same type as it is
15190 declared to have within the function, and that its DECL_INCOMING_RTL
15191 points us to a place where a value of that type is passed.
15193 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15194 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15195 because in these cases DECL_INCOMING_RTL points us to a value of some
15196 type which is *different* from the type of the parameter itself. Thus,
15197 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15198 such cases, the debugger would end up (for example) trying to fetch a
15199 `float' from a place which actually contains the first part of a
15200 `double'. That would lead to really incorrect and confusing
15201 output at debug-time.
15203 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15204 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15205 are a couple of exceptions however. On little-endian machines we can
15206 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15207 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15208 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15209 when (on a little-endian machine) a non-prototyped function has a
15210 parameter declared to be of type `short' or `char'. In such cases,
15211 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15212 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15213 passed `int' value. If the debugger then uses that address to fetch
15214 a `short' or a `char' (on a little-endian machine) the result will be
15215 the correct data, so we allow for such exceptional cases below.
15217 Note that our goal here is to describe the place where the given formal
15218 parameter lives during most of the function's activation (i.e. between the
15219 end of the prologue and the start of the epilogue). We'll do that as best
15220 as we can. Note however that if the given formal parameter is modified
15221 sometime during the execution of the function, then a stack backtrace (at
15222 debug-time) will show the function as having been called with the *new*
15223 value rather than the value which was originally passed in. This happens
15224 rarely enough that it is not a major problem, but it *is* a problem, and
15225 I'd like to fix it.
15227 A future version of dwarf2out.c may generate two additional attributes for
15228 any given DW_TAG_formal_parameter DIE which will describe the "passed
15229 type" and the "passed location" for the given formal parameter in addition
15230 to the attributes we now generate to indicate the "declared type" and the
15231 "active location" for each parameter. This additional set of attributes
15232 could be used by debuggers for stack backtraces. Separately, note that
15233 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15234 This happens (for example) for inlined-instances of inline function formal
15235 parameters which are never referenced. This really shouldn't be
15236 happening. All PARM_DECL nodes should get valid non-NULL
15237 DECL_INCOMING_RTL values. FIXME. */
15239 /* Use DECL_RTL as the "location" unless we find something better. */
15240 rtl
= DECL_RTL_IF_SET (decl
);
15242 /* When generating abstract instances, ignore everything except
15243 constants, symbols living in memory, and symbols living in
15244 fixed registers. */
15245 if (! reload_completed
)
15248 && (CONSTANT_P (rtl
)
15250 && CONSTANT_P (XEXP (rtl
, 0)))
15252 && TREE_CODE (decl
) == VAR_DECL
15253 && TREE_STATIC (decl
))))
15255 rtl
= targetm
.delegitimize_address (rtl
);
15260 else if (TREE_CODE (decl
) == PARM_DECL
)
15262 if (rtl
== NULL_RTX
15263 || is_pseudo_reg (rtl
)
15265 && is_pseudo_reg (XEXP (rtl
, 0))
15266 && DECL_INCOMING_RTL (decl
)
15267 && MEM_P (DECL_INCOMING_RTL (decl
))
15268 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15270 tree declared_type
= TREE_TYPE (decl
);
15271 tree passed_type
= DECL_ARG_TYPE (decl
);
15272 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15273 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15275 /* This decl represents a formal parameter which was optimized out.
15276 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15277 all cases where (rtl == NULL_RTX) just below. */
15278 if (dmode
== pmode
)
15279 rtl
= DECL_INCOMING_RTL (decl
);
15280 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15281 && SCALAR_INT_MODE_P (dmode
)
15282 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15283 && DECL_INCOMING_RTL (decl
))
15285 rtx inc
= DECL_INCOMING_RTL (decl
);
15288 else if (MEM_P (inc
))
15290 if (BYTES_BIG_ENDIAN
)
15291 rtl
= adjust_address_nv (inc
, dmode
,
15292 GET_MODE_SIZE (pmode
)
15293 - GET_MODE_SIZE (dmode
));
15300 /* If the parm was passed in registers, but lives on the stack, then
15301 make a big endian correction if the mode of the type of the
15302 parameter is not the same as the mode of the rtl. */
15303 /* ??? This is the same series of checks that are made in dbxout.c before
15304 we reach the big endian correction code there. It isn't clear if all
15305 of these checks are necessary here, but keeping them all is the safe
15307 else if (MEM_P (rtl
)
15308 && XEXP (rtl
, 0) != const0_rtx
15309 && ! CONSTANT_P (XEXP (rtl
, 0))
15310 /* Not passed in memory. */
15311 && !MEM_P (DECL_INCOMING_RTL (decl
))
15312 /* Not passed by invisible reference. */
15313 && (!REG_P (XEXP (rtl
, 0))
15314 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15315 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15316 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15317 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15320 /* Big endian correction check. */
15321 && BYTES_BIG_ENDIAN
15322 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15323 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15326 enum machine_mode addr_mode
= get_address_mode (rtl
);
15327 int offset
= (UNITS_PER_WORD
15328 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15330 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15331 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15334 else if (TREE_CODE (decl
) == VAR_DECL
15337 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15338 && BYTES_BIG_ENDIAN
)
15340 enum machine_mode addr_mode
= get_address_mode (rtl
);
15341 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15342 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15344 /* If a variable is declared "register" yet is smaller than
15345 a register, then if we store the variable to memory, it
15346 looks like we're storing a register-sized value, when in
15347 fact we are not. We need to adjust the offset of the
15348 storage location to reflect the actual value's bytes,
15349 else gdb will not be able to display it. */
15351 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15352 plus_constant (addr_mode
, XEXP (rtl
, 0),
15356 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15357 and will have been substituted directly into all expressions that use it.
15358 C does not have such a concept, but C++ and other languages do. */
15359 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15360 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15363 rtl
= targetm
.delegitimize_address (rtl
);
15365 /* If we don't look past the constant pool, we risk emitting a
15366 reference to a constant pool entry that isn't referenced from
15367 code, and thus is not emitted. */
15369 rtl
= avoid_constant_pool_reference (rtl
);
15371 /* Try harder to get a rtl. If this symbol ends up not being emitted
15372 in the current CU, resolve_addr will remove the expression referencing
15374 if (rtl
== NULL_RTX
15375 && TREE_CODE (decl
) == VAR_DECL
15376 && !DECL_EXTERNAL (decl
)
15377 && TREE_STATIC (decl
)
15378 && DECL_NAME (decl
)
15379 && !DECL_HARD_REGISTER (decl
)
15380 && DECL_MODE (decl
) != VOIDmode
)
15382 rtl
= make_decl_rtl_for_debug (decl
);
15384 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15385 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15392 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15393 returned. If so, the decl for the COMMON block is returned, and the
15394 value is the offset into the common block for the symbol. */
15397 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15399 tree val_expr
, cvar
;
15400 enum machine_mode mode
;
15401 HOST_WIDE_INT bitsize
, bitpos
;
15403 int unsignedp
, volatilep
= 0;
15405 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15406 it does not have a value (the offset into the common area), or if it
15407 is thread local (as opposed to global) then it isn't common, and shouldn't
15408 be handled as such. */
15409 if (TREE_CODE (decl
) != VAR_DECL
15410 || !TREE_STATIC (decl
)
15411 || !DECL_HAS_VALUE_EXPR_P (decl
)
15415 val_expr
= DECL_VALUE_EXPR (decl
);
15416 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15419 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15420 &mode
, &unsignedp
, &volatilep
, true);
15422 if (cvar
== NULL_TREE
15423 || TREE_CODE (cvar
) != VAR_DECL
15424 || DECL_ARTIFICIAL (cvar
)
15425 || !TREE_PUBLIC (cvar
))
15429 if (offset
!= NULL
)
15431 if (!host_integerp (offset
, 0))
15433 *value
= tree_low_cst (offset
, 0);
15436 *value
+= bitpos
/ BITS_PER_UNIT
;
15441 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15442 data attribute for a variable or a parameter. We generate the
15443 DW_AT_const_value attribute only in those cases where the given variable
15444 or parameter does not have a true "location" either in memory or in a
15445 register. This can happen (for example) when a constant is passed as an
15446 actual argument in a call to an inline function. (It's possible that
15447 these things can crop up in other ways also.) Note that one type of
15448 constant value which can be passed into an inlined function is a constant
15449 pointer. This can happen for example if an actual argument in an inlined
15450 function call evaluates to a compile-time constant address.
15452 CACHE_P is true if it is worth caching the location list for DECL,
15453 so that future calls can reuse it rather than regenerate it from scratch.
15454 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15455 since we will need to refer to them each time the function is inlined. */
15458 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15459 enum dwarf_attribute attr
)
15462 dw_loc_list_ref list
;
15463 var_loc_list
*loc_list
;
15464 cached_dw_loc_list
*cache
;
15467 if (TREE_CODE (decl
) == ERROR_MARK
)
15470 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15471 || TREE_CODE (decl
) == RESULT_DECL
);
15473 /* Try to get some constant RTL for this decl, and use that as the value of
15476 rtl
= rtl_for_decl_location (decl
);
15477 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15478 && add_const_value_attribute (die
, rtl
))
15481 /* See if we have single element location list that is equivalent to
15482 a constant value. That way we are better to use add_const_value_attribute
15483 rather than expanding constant value equivalent. */
15484 loc_list
= lookup_decl_loc (decl
);
15487 && loc_list
->first
->next
== NULL
15488 && NOTE_P (loc_list
->first
->loc
)
15489 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15490 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15492 struct var_loc_node
*node
;
15494 node
= loc_list
->first
;
15495 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15496 if (GET_CODE (rtl
) == EXPR_LIST
)
15497 rtl
= XEXP (rtl
, 0);
15498 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15499 && add_const_value_attribute (die
, rtl
))
15502 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15503 list several times. See if we've already cached the contents. */
15505 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15509 cache
= (cached_dw_loc_list
*)
15510 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15512 list
= cache
->loc_list
;
15516 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15517 /* It is usually worth caching this result if the decl is from
15518 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15519 if (cache_p
&& list
&& list
->dw_loc_next
)
15521 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15522 DECL_UID (decl
), INSERT
);
15523 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15524 cache
->decl_id
= DECL_UID (decl
);
15525 cache
->loc_list
= list
;
15531 add_AT_location_description (die
, attr
, list
);
15534 /* None of that worked, so it must not really have a location;
15535 try adding a constant value attribute from the DECL_INITIAL. */
15536 return tree_add_const_value_attribute_for_decl (die
, decl
);
15539 /* Add VARIABLE and DIE into deferred locations list. */
15542 defer_location (tree variable
, dw_die_ref die
)
15544 deferred_locations entry
;
15545 entry
.variable
= variable
;
15547 vec_safe_push (deferred_locations_list
, entry
);
15550 /* Helper function for tree_add_const_value_attribute. Natively encode
15551 initializer INIT into an array. Return true if successful. */
15554 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15558 if (init
== NULL_TREE
)
15562 switch (TREE_CODE (init
))
15565 type
= TREE_TYPE (init
);
15566 if (TREE_CODE (type
) == ARRAY_TYPE
)
15568 tree enttype
= TREE_TYPE (type
);
15569 enum machine_mode mode
= TYPE_MODE (enttype
);
15571 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15573 if (int_size_in_bytes (type
) != size
)
15575 if (size
> TREE_STRING_LENGTH (init
))
15577 memcpy (array
, TREE_STRING_POINTER (init
),
15578 TREE_STRING_LENGTH (init
));
15579 memset (array
+ TREE_STRING_LENGTH (init
),
15580 '\0', size
- TREE_STRING_LENGTH (init
));
15583 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15588 type
= TREE_TYPE (init
);
15589 if (int_size_in_bytes (type
) != size
)
15591 if (TREE_CODE (type
) == ARRAY_TYPE
)
15593 HOST_WIDE_INT min_index
;
15594 unsigned HOST_WIDE_INT cnt
;
15595 int curpos
= 0, fieldsize
;
15596 constructor_elt
*ce
;
15598 if (TYPE_DOMAIN (type
) == NULL_TREE
15599 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15602 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15603 if (fieldsize
<= 0)
15606 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15607 memset (array
, '\0', size
);
15608 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15610 tree val
= ce
->value
;
15611 tree index
= ce
->index
;
15613 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15614 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15617 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15622 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15625 curpos
= pos
+ fieldsize
;
15626 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15628 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15629 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15630 while (count
-- > 0)
15633 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15634 curpos
+= fieldsize
;
15637 gcc_assert (curpos
<= size
);
15641 else if (TREE_CODE (type
) == RECORD_TYPE
15642 || TREE_CODE (type
) == UNION_TYPE
)
15644 tree field
= NULL_TREE
;
15645 unsigned HOST_WIDE_INT cnt
;
15646 constructor_elt
*ce
;
15648 if (int_size_in_bytes (type
) != size
)
15651 if (TREE_CODE (type
) == RECORD_TYPE
)
15652 field
= TYPE_FIELDS (type
);
15654 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15656 tree val
= ce
->value
;
15657 int pos
, fieldsize
;
15659 if (ce
->index
!= 0)
15665 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15668 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15669 && TYPE_DOMAIN (TREE_TYPE (field
))
15670 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15672 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15673 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15675 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15676 pos
= int_byte_position (field
);
15677 gcc_assert (pos
+ fieldsize
<= size
);
15679 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15685 case VIEW_CONVERT_EXPR
:
15686 case NON_LVALUE_EXPR
:
15687 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15689 return native_encode_expr (init
, array
, size
) == size
;
15693 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15694 attribute is the const value T. */
15697 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15700 tree type
= TREE_TYPE (t
);
15703 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15707 gcc_assert (!DECL_P (init
));
15709 rtl
= rtl_for_decl_init (init
, type
);
15711 return add_const_value_attribute (die
, rtl
);
15712 /* If the host and target are sane, try harder. */
15713 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15714 && initializer_constant_valid_p (init
, type
))
15716 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15717 if (size
> 0 && (int) size
== size
)
15719 unsigned char *array
= (unsigned char *)
15720 ggc_alloc_cleared_atomic (size
);
15722 if (native_encode_initializer (init
, array
, size
))
15724 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15733 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15734 attribute is the const value of T, where T is an integral constant
15735 variable with static storage duration
15736 (so it can't be a PARM_DECL or a RESULT_DECL). */
15739 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15743 || (TREE_CODE (decl
) != VAR_DECL
15744 && TREE_CODE (decl
) != CONST_DECL
)
15745 || (TREE_CODE (decl
) == VAR_DECL
15746 && !TREE_STATIC (decl
)))
15749 if (TREE_READONLY (decl
)
15750 && ! TREE_THIS_VOLATILE (decl
)
15751 && DECL_INITIAL (decl
))
15756 /* Don't add DW_AT_const_value if abstract origin already has one. */
15757 if (get_AT (var_die
, DW_AT_const_value
))
15760 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15763 /* Convert the CFI instructions for the current function into a
15764 location list. This is used for DW_AT_frame_base when we targeting
15765 a dwarf2 consumer that does not support the dwarf3
15766 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15769 static dw_loc_list_ref
15770 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15774 dw_loc_list_ref list
, *list_tail
;
15776 dw_cfa_location last_cfa
, next_cfa
;
15777 const char *start_label
, *last_label
, *section
;
15778 dw_cfa_location remember
;
15781 gcc_assert (fde
!= NULL
);
15783 section
= secname_for_decl (current_function_decl
);
15787 memset (&next_cfa
, 0, sizeof (next_cfa
));
15788 next_cfa
.reg
= INVALID_REGNUM
;
15789 remember
= next_cfa
;
15791 start_label
= fde
->dw_fde_begin
;
15793 /* ??? Bald assumption that the CIE opcode list does not contain
15794 advance opcodes. */
15795 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15796 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15798 last_cfa
= next_cfa
;
15799 last_label
= start_label
;
15801 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15803 /* If the first partition contained no CFI adjustments, the
15804 CIE opcodes apply to the whole first partition. */
15805 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15806 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15807 list_tail
=&(*list_tail
)->dw_loc_next
;
15808 start_label
= last_label
= fde
->dw_fde_second_begin
;
15811 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15813 switch (cfi
->dw_cfi_opc
)
15815 case DW_CFA_set_loc
:
15816 case DW_CFA_advance_loc1
:
15817 case DW_CFA_advance_loc2
:
15818 case DW_CFA_advance_loc4
:
15819 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15821 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15822 start_label
, last_label
, section
);
15824 list_tail
= &(*list_tail
)->dw_loc_next
;
15825 last_cfa
= next_cfa
;
15826 start_label
= last_label
;
15828 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15831 case DW_CFA_advance_loc
:
15832 /* The encoding is complex enough that we should never emit this. */
15833 gcc_unreachable ();
15836 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15839 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15841 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15843 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15844 start_label
, last_label
, section
);
15846 list_tail
= &(*list_tail
)->dw_loc_next
;
15847 last_cfa
= next_cfa
;
15848 start_label
= last_label
;
15850 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15851 start_label
, fde
->dw_fde_end
, section
);
15852 list_tail
= &(*list_tail
)->dw_loc_next
;
15853 start_label
= last_label
= fde
->dw_fde_second_begin
;
15857 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15859 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15860 start_label
, last_label
, section
);
15861 list_tail
= &(*list_tail
)->dw_loc_next
;
15862 start_label
= last_label
;
15865 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15867 fde
->dw_fde_second_begin
15868 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15871 if (list
&& list
->dw_loc_next
)
15877 /* Compute a displacement from the "steady-state frame pointer" to the
15878 frame base (often the same as the CFA), and store it in
15879 frame_pointer_fb_offset. OFFSET is added to the displacement
15880 before the latter is negated. */
15883 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15887 #ifdef FRAME_POINTER_CFA_OFFSET
15888 reg
= frame_pointer_rtx
;
15889 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15891 reg
= arg_pointer_rtx
;
15892 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15895 elim
= (ira_use_lra_p
15896 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15897 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15898 if (GET_CODE (elim
) == PLUS
)
15900 offset
+= INTVAL (XEXP (elim
, 1));
15901 elim
= XEXP (elim
, 0);
15904 frame_pointer_fb_offset
= -offset
;
15906 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15907 in which to eliminate. This is because it's stack pointer isn't
15908 directly accessible as a register within the ISA. To work around
15909 this, assume that while we cannot provide a proper value for
15910 frame_pointer_fb_offset, we won't need one either. */
15911 frame_pointer_fb_offset_valid
15912 = ((SUPPORTS_STACK_ALIGNMENT
15913 && (elim
== hard_frame_pointer_rtx
15914 || elim
== stack_pointer_rtx
))
15915 || elim
== (frame_pointer_needed
15916 ? hard_frame_pointer_rtx
15917 : stack_pointer_rtx
));
15920 /* Generate a DW_AT_name attribute given some string value to be included as
15921 the value of the attribute. */
15924 add_name_attribute (dw_die_ref die
, const char *name_string
)
15926 if (name_string
!= NULL
&& *name_string
!= 0)
15928 if (demangle_name_func
)
15929 name_string
= (*demangle_name_func
) (name_string
);
15931 add_AT_string (die
, DW_AT_name
, name_string
);
15935 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15936 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15937 of TYPE accordingly.
15939 ??? This is a temporary measure until after we're able to generate
15940 regular DWARF for the complex Ada type system. */
15943 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15944 dw_die_ref context_die
)
15947 dw_die_ref dtype_die
;
15949 if (!lang_hooks
.types
.descriptive_type
)
15952 dtype
= lang_hooks
.types
.descriptive_type (type
);
15956 dtype_die
= lookup_type_die (dtype
);
15959 gen_type_die (dtype
, context_die
);
15960 dtype_die
= lookup_type_die (dtype
);
15961 gcc_assert (dtype_die
);
15964 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15967 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
15969 static const char *
15970 comp_dir_string (void)
15974 static const char *cached_wd
= NULL
;
15976 if (cached_wd
!= NULL
)
15979 wd
= get_src_pwd ();
15983 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15987 wdlen
= strlen (wd
);
15988 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15990 wd1
[wdlen
] = DIR_SEPARATOR
;
15991 wd1
[wdlen
+ 1] = 0;
15995 cached_wd
= remap_debug_filename (wd
);
15999 /* Generate a DW_AT_comp_dir attribute for DIE. */
16002 add_comp_dir_attribute (dw_die_ref die
)
16004 const char * wd
= comp_dir_string ();
16006 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16009 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16013 lower_bound_default (void)
16015 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16020 case DW_LANG_C_plus_plus
:
16022 case DW_LANG_ObjC_plus_plus
:
16025 case DW_LANG_Fortran77
:
16026 case DW_LANG_Fortran90
:
16027 case DW_LANG_Fortran95
:
16031 case DW_LANG_Python
:
16032 return dwarf_version
>= 4 ? 0 : -1;
16033 case DW_LANG_Ada95
:
16034 case DW_LANG_Ada83
:
16035 case DW_LANG_Cobol74
:
16036 case DW_LANG_Cobol85
:
16037 case DW_LANG_Pascal83
:
16038 case DW_LANG_Modula2
:
16040 return dwarf_version
>= 4 ? 1 : -1;
16046 /* Given a tree node describing an array bound (either lower or upper) output
16047 a representation for that bound. */
16050 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16052 switch (TREE_CODE (bound
))
16057 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16060 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16063 /* Use the default if possible. */
16064 if (bound_attr
== DW_AT_lower_bound
16065 && host_integerp (bound
, 0)
16066 && (dflt
= lower_bound_default ()) != -1
16067 && tree_low_cst (bound
, 0) == dflt
)
16070 /* Otherwise represent the bound as an unsigned value with the
16071 precision of its type. The precision and signedness of the
16072 type will be necessary to re-interpret it unambiguously. */
16073 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16075 unsigned HOST_WIDE_INT mask
16076 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16077 add_AT_unsigned (subrange_die
, bound_attr
,
16078 TREE_INT_CST_LOW (bound
) & mask
);
16080 else if (prec
== HOST_BITS_PER_WIDE_INT
16081 || TREE_INT_CST_HIGH (bound
) == 0)
16082 add_AT_unsigned (subrange_die
, bound_attr
,
16083 TREE_INT_CST_LOW (bound
));
16085 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16086 TREE_INT_CST_LOW (bound
));
16091 case VIEW_CONVERT_EXPR
:
16092 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16102 dw_die_ref decl_die
= lookup_decl_die (bound
);
16104 /* ??? Can this happen, or should the variable have been bound
16105 first? Probably it can, since I imagine that we try to create
16106 the types of parameters in the order in which they exist in
16107 the list, and won't have created a forward reference to a
16108 later parameter. */
16109 if (decl_die
!= NULL
)
16111 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16119 /* Otherwise try to create a stack operation procedure to
16120 evaluate the value of the array bound. */
16122 dw_die_ref ctx
, decl_die
;
16123 dw_loc_list_ref list
;
16125 list
= loc_list_from_tree (bound
, 2);
16126 if (list
== NULL
|| single_element_loc_list_p (list
))
16128 /* If DW_AT_*bound is not a reference nor constant, it is
16129 a DWARF expression rather than location description.
16130 For that loc_list_from_tree (bound, 0) is needed.
16131 If that fails to give a single element list,
16132 fall back to outputting this as a reference anyway. */
16133 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16134 if (list2
&& single_element_loc_list_p (list2
))
16136 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16143 if (current_function_decl
== 0)
16144 ctx
= comp_unit_die ();
16146 ctx
= lookup_decl_die (current_function_decl
);
16148 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16149 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16150 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16151 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16152 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16158 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16159 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16160 Note that the block of subscript information for an array type also
16161 includes information about the element type of the given array type. */
16164 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16166 unsigned dimension_number
;
16168 dw_die_ref subrange_die
;
16170 for (dimension_number
= 0;
16171 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16172 type
= TREE_TYPE (type
), dimension_number
++)
16174 tree domain
= TYPE_DOMAIN (type
);
16176 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16179 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16180 and (in GNU C only) variable bounds. Handle all three forms
16182 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16185 /* We have an array type with specified bounds. */
16186 lower
= TYPE_MIN_VALUE (domain
);
16187 upper
= TYPE_MAX_VALUE (domain
);
16189 /* Define the index type. */
16190 if (TREE_TYPE (domain
))
16192 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16193 TREE_TYPE field. We can't emit debug info for this
16194 because it is an unnamed integral type. */
16195 if (TREE_CODE (domain
) == INTEGER_TYPE
16196 && TYPE_NAME (domain
) == NULL_TREE
16197 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16198 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16201 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16205 /* ??? If upper is NULL, the array has unspecified length,
16206 but it does have a lower bound. This happens with Fortran
16208 Since the debugger is definitely going to need to know N
16209 to produce useful results, go ahead and output the lower
16210 bound solo, and hope the debugger can cope. */
16212 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16214 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16217 /* Otherwise we have an array type with an unspecified length. The
16218 DWARF-2 spec does not say how to handle this; let's just leave out the
16224 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16226 dw_die_ref decl_die
;
16229 switch (TREE_CODE (tree_node
))
16234 case ENUMERAL_TYPE
:
16237 case QUAL_UNION_TYPE
:
16238 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16239 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16241 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16244 size
= int_size_in_bytes (tree_node
);
16247 /* For a data member of a struct or union, the DW_AT_byte_size is
16248 generally given as the number of bytes normally allocated for an
16249 object of the *declared* type of the member itself. This is true
16250 even for bit-fields. */
16251 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16254 gcc_unreachable ();
16257 /* Note that `size' might be -1 when we get to this point. If it is, that
16258 indicates that the byte size of the entity in question is variable. We
16259 have no good way of expressing this fact in Dwarf at the present time,
16260 so just let the -1 pass on through. */
16261 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16264 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16265 which specifies the distance in bits from the highest order bit of the
16266 "containing object" for the bit-field to the highest order bit of the
16269 For any given bit-field, the "containing object" is a hypothetical object
16270 (of some integral or enum type) within which the given bit-field lives. The
16271 type of this hypothetical "containing object" is always the same as the
16272 declared type of the individual bit-field itself. The determination of the
16273 exact location of the "containing object" for a bit-field is rather
16274 complicated. It's handled by the `field_byte_offset' function (above).
16276 Note that it is the size (in bytes) of the hypothetical "containing object"
16277 which will be given in the DW_AT_byte_size attribute for this bit-field.
16278 (See `byte_size_attribute' above). */
16281 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16283 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16284 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16285 HOST_WIDE_INT bitpos_int
;
16286 HOST_WIDE_INT highest_order_object_bit_offset
;
16287 HOST_WIDE_INT highest_order_field_bit_offset
;
16288 HOST_WIDE_INT bit_offset
;
16290 /* Must be a field and a bit field. */
16291 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16293 /* We can't yet handle bit-fields whose offsets are variable, so if we
16294 encounter such things, just return without generating any attribute
16295 whatsoever. Likewise for variable or too large size. */
16296 if (! host_integerp (bit_position (decl
), 0)
16297 || ! host_integerp (DECL_SIZE (decl
), 1))
16300 bitpos_int
= int_bit_position (decl
);
16302 /* Note that the bit offset is always the distance (in bits) from the
16303 highest-order bit of the "containing object" to the highest-order bit of
16304 the bit-field itself. Since the "high-order end" of any object or field
16305 is different on big-endian and little-endian machines, the computation
16306 below must take account of these differences. */
16307 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16308 highest_order_field_bit_offset
= bitpos_int
;
16310 if (! BYTES_BIG_ENDIAN
)
16312 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16313 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16317 = (! BYTES_BIG_ENDIAN
16318 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16319 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16321 if (bit_offset
< 0)
16322 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16324 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16327 /* For a FIELD_DECL node which represents a bit field, output an attribute
16328 which specifies the length in bits of the given field. */
16331 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16333 /* Must be a field and a bit field. */
16334 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16335 && DECL_BIT_FIELD_TYPE (decl
));
16337 if (host_integerp (DECL_SIZE (decl
), 1))
16338 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16341 /* If the compiled language is ANSI C, then add a 'prototyped'
16342 attribute, if arg types are given for the parameters of a function. */
16345 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16347 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16348 && prototype_p (func_type
))
16349 add_AT_flag (die
, DW_AT_prototyped
, 1);
16352 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16353 by looking in either the type declaration or object declaration
16356 static inline dw_die_ref
16357 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16359 dw_die_ref origin_die
= NULL
;
16361 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16363 /* We may have gotten separated from the block for the inlined
16364 function, if we're in an exception handler or some such; make
16365 sure that the abstract function has been written out.
16367 Doing this for nested functions is wrong, however; functions are
16368 distinct units, and our context might not even be inline. */
16372 fn
= TYPE_STUB_DECL (fn
);
16374 fn
= decl_function_context (fn
);
16376 dwarf2out_abstract_function (fn
);
16379 if (DECL_P (origin
))
16380 origin_die
= lookup_decl_die (origin
);
16381 else if (TYPE_P (origin
))
16382 origin_die
= lookup_type_die (origin
);
16384 /* XXX: Functions that are never lowered don't always have correct block
16385 trees (in the case of java, they simply have no block tree, in some other
16386 languages). For these functions, there is nothing we can really do to
16387 output correct debug info for inlined functions in all cases. Rather
16388 than die, we'll just produce deficient debug info now, in that we will
16389 have variables without a proper abstract origin. In the future, when all
16390 functions are lowered, we should re-add a gcc_assert (origin_die)
16394 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16398 /* We do not currently support the pure_virtual attribute. */
16401 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16403 if (DECL_VINDEX (func_decl
))
16405 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16407 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16408 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16409 new_loc_descr (DW_OP_constu
,
16410 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16413 /* GNU extension: Record what type this method came from originally. */
16414 if (debug_info_level
> DINFO_LEVEL_TERSE
16415 && DECL_CONTEXT (func_decl
))
16416 add_AT_die_ref (die
, DW_AT_containing_type
,
16417 lookup_type_die (DECL_CONTEXT (func_decl
)));
16421 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16422 given decl. This used to be a vendor extension until after DWARF 4
16423 standardized it. */
16426 add_linkage_attr (dw_die_ref die
, tree decl
)
16428 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16430 /* Mimic what assemble_name_raw does with a leading '*'. */
16431 if (name
[0] == '*')
16434 if (dwarf_version
>= 4)
16435 add_AT_string (die
, DW_AT_linkage_name
, name
);
16437 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16440 /* Add source coordinate attributes for the given decl. */
16443 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16445 expanded_location s
;
16447 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16449 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16450 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16451 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16454 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16457 add_linkage_name (dw_die_ref die
, tree decl
)
16459 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16460 && TREE_PUBLIC (decl
)
16461 && !DECL_ABSTRACT (decl
)
16462 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16463 && die
->die_tag
!= DW_TAG_member
)
16465 /* Defer until we have an assembler name set. */
16466 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16468 limbo_die_node
*asm_name
;
16470 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16471 asm_name
->die
= die
;
16472 asm_name
->created_for
= decl
;
16473 asm_name
->next
= deferred_asm_name
;
16474 deferred_asm_name
= asm_name
;
16476 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16477 add_linkage_attr (die
, decl
);
16481 /* Add a DW_AT_name attribute and source coordinate attribute for the
16482 given decl, but only if it actually has a name. */
16485 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16489 decl_name
= DECL_NAME (decl
);
16490 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16492 const char *name
= dwarf2_name (decl
, 0);
16494 add_name_attribute (die
, name
);
16495 if (! DECL_ARTIFICIAL (decl
))
16496 add_src_coords_attributes (die
, decl
);
16498 add_linkage_name (die
, decl
);
16501 #ifdef VMS_DEBUGGING_INFO
16502 /* Get the function's name, as described by its RTL. This may be different
16503 from the DECL_NAME name used in the source file. */
16504 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16506 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16507 XEXP (DECL_RTL (decl
), 0), false);
16508 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16510 #endif /* VMS_DEBUGGING_INFO */
16513 #ifdef VMS_DEBUGGING_INFO
16514 /* Output the debug main pointer die for VMS */
16517 dwarf2out_vms_debug_main_pointer (void)
16519 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16522 /* Allocate the VMS debug main subprogram die. */
16523 die
= ggc_alloc_cleared_die_node ();
16524 die
->die_tag
= DW_TAG_subprogram
;
16525 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16526 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16527 current_function_funcdef_no
);
16528 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16530 /* Make it the first child of comp_unit_die (). */
16531 die
->die_parent
= comp_unit_die ();
16532 if (comp_unit_die ()->die_child
)
16534 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16535 comp_unit_die ()->die_child
->die_sib
= die
;
16539 die
->die_sib
= die
;
16540 comp_unit_die ()->die_child
= die
;
16543 #endif /* VMS_DEBUGGING_INFO */
16545 /* Push a new declaration scope. */
16548 push_decl_scope (tree scope
)
16550 vec_safe_push (decl_scope_table
, scope
);
16553 /* Pop a declaration scope. */
16556 pop_decl_scope (void)
16558 decl_scope_table
->pop ();
16561 /* walk_tree helper function for uses_local_type, below. */
16564 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16567 *walk_subtrees
= 0;
16570 tree name
= TYPE_NAME (*tp
);
16571 if (name
&& DECL_P (name
) && decl_function_context (name
))
16577 /* If TYPE involves a function-local type (including a local typedef to a
16578 non-local type), returns that type; otherwise returns NULL_TREE. */
16581 uses_local_type (tree type
)
16583 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16587 /* Return the DIE for the scope that immediately contains this type.
16588 Non-named types that do not involve a function-local type get global
16589 scope. Named types nested in namespaces or other types get their
16590 containing scope. All other types (i.e. function-local named types) get
16591 the current active scope. */
16594 scope_die_for (tree t
, dw_die_ref context_die
)
16596 dw_die_ref scope_die
= NULL
;
16597 tree containing_scope
;
16599 /* Non-types always go in the current scope. */
16600 gcc_assert (TYPE_P (t
));
16602 /* Use the scope of the typedef, rather than the scope of the type
16604 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16605 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16607 containing_scope
= TYPE_CONTEXT (t
);
16609 /* Use the containing namespace if there is one. */
16610 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16612 if (context_die
== lookup_decl_die (containing_scope
))
16614 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16615 context_die
= get_context_die (containing_scope
);
16617 containing_scope
= NULL_TREE
;
16620 /* Ignore function type "scopes" from the C frontend. They mean that
16621 a tagged type is local to a parmlist of a function declarator, but
16622 that isn't useful to DWARF. */
16623 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16624 containing_scope
= NULL_TREE
;
16626 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16628 /* If T uses a local type keep it local as well, to avoid references
16629 to function-local DIEs from outside the function. */
16630 if (current_function_decl
&& uses_local_type (t
))
16631 scope_die
= context_die
;
16633 scope_die
= comp_unit_die ();
16635 else if (TYPE_P (containing_scope
))
16637 /* For types, we can just look up the appropriate DIE. */
16638 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16639 scope_die
= get_context_die (containing_scope
);
16642 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16643 if (scope_die
== NULL
)
16644 scope_die
= comp_unit_die ();
16648 scope_die
= context_die
;
16653 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16656 local_scope_p (dw_die_ref context_die
)
16658 for (; context_die
; context_die
= context_die
->die_parent
)
16659 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16660 || context_die
->die_tag
== DW_TAG_subprogram
)
16666 /* Returns nonzero if CONTEXT_DIE is a class. */
16669 class_scope_p (dw_die_ref context_die
)
16671 return (context_die
16672 && (context_die
->die_tag
== DW_TAG_structure_type
16673 || context_die
->die_tag
== DW_TAG_class_type
16674 || context_die
->die_tag
== DW_TAG_interface_type
16675 || context_die
->die_tag
== DW_TAG_union_type
));
16678 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16679 whether or not to treat a DIE in this context as a declaration. */
16682 class_or_namespace_scope_p (dw_die_ref context_die
)
16684 return (class_scope_p (context_die
)
16685 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16688 /* Many forms of DIEs require a "type description" attribute. This
16689 routine locates the proper "type descriptor" die for the type given
16690 by 'type', and adds a DW_AT_type attribute below the given die. */
16693 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16694 int decl_volatile
, dw_die_ref context_die
)
16696 enum tree_code code
= TREE_CODE (type
);
16697 dw_die_ref type_die
= NULL
;
16699 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16700 or fixed-point type, use the inner type. This is because we have no
16701 support for unnamed types in base_type_die. This can happen if this is
16702 an Ada subrange type. Correct solution is emit a subrange type die. */
16703 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16704 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16705 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16707 if (code
== ERROR_MARK
16708 /* Handle a special case. For functions whose return type is void, we
16709 generate *no* type attribute. (Note that no object may have type
16710 `void', so this only applies to function return types). */
16711 || code
== VOID_TYPE
)
16714 type_die
= modified_type_die (type
,
16715 decl_const
|| TYPE_READONLY (type
),
16716 decl_volatile
|| TYPE_VOLATILE (type
),
16719 if (type_die
!= NULL
)
16720 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16723 /* Given an object die, add the calling convention attribute for the
16724 function call type. */
16726 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16728 enum dwarf_calling_convention value
= DW_CC_normal
;
16730 value
= ((enum dwarf_calling_convention
)
16731 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16734 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16736 /* DWARF 2 doesn't provide a way to identify a program's source-level
16737 entry point. DW_AT_calling_convention attributes are only meant
16738 to describe functions' calling conventions. However, lacking a
16739 better way to signal the Fortran main program, we used this for
16740 a long time, following existing custom. Now, DWARF 4 has
16741 DW_AT_main_subprogram, which we add below, but some tools still
16742 rely on the old way, which we thus keep. */
16743 value
= DW_CC_program
;
16745 if (dwarf_version
>= 4 || !dwarf_strict
)
16746 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16749 /* Only add the attribute if the backend requests it, and
16750 is not DW_CC_normal. */
16751 if (value
&& (value
!= DW_CC_normal
))
16752 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16755 /* Given a tree pointer to a struct, class, union, or enum type node, return
16756 a pointer to the (string) tag name for the given type, or zero if the type
16757 was declared without a tag. */
16759 static const char *
16760 type_tag (const_tree type
)
16762 const char *name
= 0;
16764 if (TYPE_NAME (type
) != 0)
16768 /* Find the IDENTIFIER_NODE for the type name. */
16769 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16770 && !TYPE_NAMELESS (type
))
16771 t
= TYPE_NAME (type
);
16773 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16774 a TYPE_DECL node, regardless of whether or not a `typedef' was
16776 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16777 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16779 /* We want to be extra verbose. Don't call dwarf_name if
16780 DECL_NAME isn't set. The default hook for decl_printable_name
16781 doesn't like that, and in this context it's correct to return
16782 0, instead of "<anonymous>" or the like. */
16783 if (DECL_NAME (TYPE_NAME (type
))
16784 && !DECL_NAMELESS (TYPE_NAME (type
)))
16785 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16788 /* Now get the name as a string, or invent one. */
16789 if (!name
&& t
!= 0)
16790 name
= IDENTIFIER_POINTER (t
);
16793 return (name
== 0 || *name
== '\0') ? 0 : name
;
16796 /* Return the type associated with a data member, make a special check
16797 for bit field types. */
16800 member_declared_type (const_tree member
)
16802 return (DECL_BIT_FIELD_TYPE (member
)
16803 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16806 /* Get the decl's label, as described by its RTL. This may be different
16807 from the DECL_NAME name used in the source file. */
16810 static const char *
16811 decl_start_label (tree decl
)
16814 const char *fnname
;
16816 x
= DECL_RTL (decl
);
16817 gcc_assert (MEM_P (x
));
16820 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16822 fnname
= XSTR (x
, 0);
16827 /* These routines generate the internal representation of the DIE's for
16828 the compilation unit. Debugging information is collected by walking
16829 the declaration trees passed in from dwarf2out_decl(). */
16832 gen_array_type_die (tree type
, dw_die_ref context_die
)
16834 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16835 dw_die_ref array_die
;
16837 /* GNU compilers represent multidimensional array types as sequences of one
16838 dimensional array types whose element types are themselves array types.
16839 We sometimes squish that down to a single array_type DIE with multiple
16840 subscripts in the Dwarf debugging info. The draft Dwarf specification
16841 say that we are allowed to do this kind of compression in C, because
16842 there is no difference between an array of arrays and a multidimensional
16843 array. We don't do this for Ada to remain as close as possible to the
16844 actual representation, which is especially important against the language
16845 flexibilty wrt arrays of variable size. */
16847 bool collapse_nested_arrays
= !is_ada ();
16850 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16851 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16852 if (TYPE_STRING_FLAG (type
)
16853 && TREE_CODE (type
) == ARRAY_TYPE
16855 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16857 HOST_WIDE_INT size
;
16859 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16860 add_name_attribute (array_die
, type_tag (type
));
16861 equate_type_number_to_die (type
, array_die
);
16862 size
= int_size_in_bytes (type
);
16864 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16865 else if (TYPE_DOMAIN (type
) != NULL_TREE
16866 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16867 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16869 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16870 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16872 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16873 if (loc
&& size
> 0)
16875 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16876 if (size
!= DWARF2_ADDR_SIZE
)
16877 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16883 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16884 add_name_attribute (array_die
, type_tag (type
));
16885 equate_type_number_to_die (type
, array_die
);
16887 if (TREE_CODE (type
) == VECTOR_TYPE
)
16888 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16890 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16892 && TREE_CODE (type
) == ARRAY_TYPE
16893 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16894 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16895 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16898 /* We default the array ordering. SDB will probably do
16899 the right things even if DW_AT_ordering is not present. It's not even
16900 an issue until we start to get into multidimensional arrays anyway. If
16901 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16902 then we'll have to put the DW_AT_ordering attribute back in. (But if
16903 and when we find out that we need to put these in, we will only do so
16904 for multidimensional arrays. */
16905 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16908 if (TREE_CODE (type
) == VECTOR_TYPE
)
16910 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16911 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16912 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16913 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16914 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16917 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16919 /* Add representation of the type of the elements of this array type and
16920 emit the corresponding DIE if we haven't done it already. */
16921 element_type
= TREE_TYPE (type
);
16922 if (collapse_nested_arrays
)
16923 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16925 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16927 element_type
= TREE_TYPE (element_type
);
16930 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16932 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16933 if (TYPE_ARTIFICIAL (type
))
16934 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16936 if (get_AT (array_die
, DW_AT_name
))
16937 add_pubtype (type
, array_die
);
16940 static dw_loc_descr_ref
16941 descr_info_loc (tree val
, tree base_decl
)
16943 HOST_WIDE_INT size
;
16944 dw_loc_descr_ref loc
, loc2
;
16945 enum dwarf_location_atom op
;
16947 if (val
== base_decl
)
16948 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16950 switch (TREE_CODE (val
))
16953 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16955 return loc_descriptor_from_tree (val
, 0);
16957 if (host_integerp (val
, 0))
16958 return int_loc_descriptor (tree_low_cst (val
, 0));
16961 size
= int_size_in_bytes (TREE_TYPE (val
));
16964 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16967 if (size
== DWARF2_ADDR_SIZE
)
16968 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16970 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16972 case POINTER_PLUS_EXPR
:
16974 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16975 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16978 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16981 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16987 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16990 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16993 add_loc_descr (&loc
, loc2
);
16994 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17016 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17017 tree val
, tree base_decl
)
17019 dw_loc_descr_ref loc
;
17021 if (host_integerp (val
, 0))
17023 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
17027 loc
= descr_info_loc (val
, base_decl
);
17031 add_AT_loc (die
, attr
, loc
);
17034 /* This routine generates DIE for array with hidden descriptor, details
17035 are filled into *info by a langhook. */
17038 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17039 dw_die_ref context_die
)
17041 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17042 dw_die_ref array_die
;
17045 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17046 add_name_attribute (array_die
, type_tag (type
));
17047 equate_type_number_to_die (type
, array_die
);
17049 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17051 && info
->ndimensions
>= 2)
17052 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17054 if (info
->data_location
)
17055 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17057 if (info
->associated
)
17058 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17060 if (info
->allocated
)
17061 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17064 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17066 dw_die_ref subrange_die
17067 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17069 if (info
->dimen
[dim
].lower_bound
)
17071 /* If it is the default value, omit it. */
17074 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
17075 && (dflt
= lower_bound_default ()) != -1
17076 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
17079 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17080 info
->dimen
[dim
].lower_bound
,
17083 if (info
->dimen
[dim
].upper_bound
)
17084 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17085 info
->dimen
[dim
].upper_bound
,
17087 if (info
->dimen
[dim
].stride
)
17088 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17089 info
->dimen
[dim
].stride
,
17093 gen_type_die (info
->element_type
, context_die
);
17094 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17096 if (get_AT (array_die
, DW_AT_name
))
17097 add_pubtype (type
, array_die
);
17102 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17104 tree origin
= decl_ultimate_origin (decl
);
17105 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17107 if (origin
!= NULL
)
17108 add_abstract_origin_attribute (decl_die
, origin
);
17111 add_name_and_src_coords_attributes (decl_die
, decl
);
17112 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17113 0, 0, context_die
);
17116 if (DECL_ABSTRACT (decl
))
17117 equate_decl_number_to_die (decl
, decl_die
);
17119 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17123 /* Walk through the list of incomplete types again, trying once more to
17124 emit full debugging info for them. */
17127 retry_incomplete_types (void)
17131 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17132 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17133 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17136 /* Determine what tag to use for a record type. */
17138 static enum dwarf_tag
17139 record_type_tag (tree type
)
17141 if (! lang_hooks
.types
.classify_record
)
17142 return DW_TAG_structure_type
;
17144 switch (lang_hooks
.types
.classify_record (type
))
17146 case RECORD_IS_STRUCT
:
17147 return DW_TAG_structure_type
;
17149 case RECORD_IS_CLASS
:
17150 return DW_TAG_class_type
;
17152 case RECORD_IS_INTERFACE
:
17153 if (dwarf_version
>= 3 || !dwarf_strict
)
17154 return DW_TAG_interface_type
;
17155 return DW_TAG_structure_type
;
17158 gcc_unreachable ();
17162 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17163 include all of the information about the enumeration values also. Each
17164 enumerated type name/value is listed as a child of the enumerated type
17168 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17170 dw_die_ref type_die
= lookup_type_die (type
);
17172 if (type_die
== NULL
)
17174 type_die
= new_die (DW_TAG_enumeration_type
,
17175 scope_die_for (type
, context_die
), type
);
17176 equate_type_number_to_die (type
, type_die
);
17177 add_name_attribute (type_die
, type_tag (type
));
17178 if (dwarf_version
>= 4 || !dwarf_strict
)
17180 if (ENUM_IS_SCOPED (type
))
17181 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17182 if (ENUM_IS_OPAQUE (type
))
17183 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17186 else if (! TYPE_SIZE (type
))
17189 remove_AT (type_die
, DW_AT_declaration
);
17191 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17192 given enum type is incomplete, do not generate the DW_AT_byte_size
17193 attribute or the DW_AT_element_list attribute. */
17194 if (TYPE_SIZE (type
))
17198 TREE_ASM_WRITTEN (type
) = 1;
17199 add_byte_size_attribute (type_die
, type
);
17200 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17202 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17203 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17206 /* If the first reference to this type was as the return type of an
17207 inline function, then it may not have a parent. Fix this now. */
17208 if (type_die
->die_parent
== NULL
)
17209 add_child_die (scope_die_for (type
, context_die
), type_die
);
17211 for (link
= TYPE_VALUES (type
);
17212 link
!= NULL
; link
= TREE_CHAIN (link
))
17214 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17215 tree value
= TREE_VALUE (link
);
17217 add_name_attribute (enum_die
,
17218 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17220 if (TREE_CODE (value
) == CONST_DECL
)
17221 value
= DECL_INITIAL (value
);
17223 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
)))
17224 && (simple_type_size_in_bits (TREE_TYPE (value
))
17225 <= HOST_BITS_PER_WIDE_INT
|| host_integerp (value
, 0)))
17226 /* DWARF2 does not provide a way of indicating whether or
17227 not enumeration constants are signed or unsigned. GDB
17228 always assumes the values are signed, so we output all
17229 values as if they were signed. That means that
17230 enumeration constants with very large unsigned values
17231 will appear to have negative values in the debugger.
17233 TODO: the above comment is wrong, DWARF2 does provide
17234 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17235 This should be re-worked to use correct signed/unsigned
17236 int/double tags for all cases, instead of always treating as
17238 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17240 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17242 add_AT_double (enum_die
, DW_AT_const_value
,
17243 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17246 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17247 if (TYPE_ARTIFICIAL (type
))
17248 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17251 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17253 add_pubtype (type
, type_die
);
17258 /* Generate a DIE to represent either a real live formal parameter decl or to
17259 represent just the type of some formal parameter position in some function
17262 Note that this routine is a bit unusual because its argument may be a
17263 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17264 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17265 node. If it's the former then this function is being called to output a
17266 DIE to represent a formal parameter object (or some inlining thereof). If
17267 it's the latter, then this function is only being called to output a
17268 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17269 argument type of some subprogram type.
17270 If EMIT_NAME_P is true, name and source coordinate attributes
17274 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17275 dw_die_ref context_die
)
17277 tree node_or_origin
= node
? node
: origin
;
17278 tree ultimate_origin
;
17279 dw_die_ref parm_die
17280 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17282 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17284 case tcc_declaration
:
17285 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17286 if (node
|| ultimate_origin
)
17287 origin
= ultimate_origin
;
17288 if (origin
!= NULL
)
17289 add_abstract_origin_attribute (parm_die
, origin
);
17290 else if (emit_name_p
)
17291 add_name_and_src_coords_attributes (parm_die
, node
);
17293 || (! DECL_ABSTRACT (node_or_origin
)
17294 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17295 decl_function_context
17296 (node_or_origin
))))
17298 tree type
= TREE_TYPE (node_or_origin
);
17299 if (decl_by_reference_p (node_or_origin
))
17300 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17303 add_type_attribute (parm_die
, type
,
17304 TREE_READONLY (node_or_origin
),
17305 TREE_THIS_VOLATILE (node_or_origin
),
17308 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17309 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17311 if (node
&& node
!= origin
)
17312 equate_decl_number_to_die (node
, parm_die
);
17313 if (! DECL_ABSTRACT (node_or_origin
))
17314 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17315 node
== NULL
, DW_AT_location
);
17320 /* We were called with some kind of a ..._TYPE node. */
17321 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17325 gcc_unreachable ();
17331 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17332 children DW_TAG_formal_parameter DIEs representing the arguments of the
17335 PARM_PACK must be a function parameter pack.
17336 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17337 must point to the subsequent arguments of the function PACK_ARG belongs to.
17338 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17339 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17340 following the last one for which a DIE was generated. */
17343 gen_formal_parameter_pack_die (tree parm_pack
,
17345 dw_die_ref subr_die
,
17349 dw_die_ref parm_pack_die
;
17351 gcc_assert (parm_pack
17352 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17355 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17356 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17358 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17360 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17363 gen_formal_parameter_die (arg
, NULL
,
17364 false /* Don't emit name attribute. */,
17369 return parm_pack_die
;
17372 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17373 at the end of an (ANSI prototyped) formal parameters list. */
17376 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17378 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17381 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17382 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17383 parameters as specified in some function type specification (except for
17384 those which appear as part of a function *definition*). */
17387 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17390 tree formal_type
= NULL
;
17391 tree first_parm_type
;
17394 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17396 arg
= DECL_ARGUMENTS (function_or_method_type
);
17397 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17402 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17404 /* Make our first pass over the list of formal parameter types and output a
17405 DW_TAG_formal_parameter DIE for each one. */
17406 for (link
= first_parm_type
; link
; )
17408 dw_die_ref parm_die
;
17410 formal_type
= TREE_VALUE (link
);
17411 if (formal_type
== void_type_node
)
17414 /* Output a (nameless) DIE to represent the formal parameter itself. */
17415 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17416 true /* Emit name attribute. */,
17418 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17419 && link
== first_parm_type
)
17421 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17422 if (dwarf_version
>= 3 || !dwarf_strict
)
17423 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17425 else if (arg
&& DECL_ARTIFICIAL (arg
))
17426 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17428 link
= TREE_CHAIN (link
);
17430 arg
= DECL_CHAIN (arg
);
17433 /* If this function type has an ellipsis, add a
17434 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17435 if (formal_type
!= void_type_node
)
17436 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17438 /* Make our second (and final) pass over the list of formal parameter types
17439 and output DIEs to represent those types (as necessary). */
17440 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17441 link
&& TREE_VALUE (link
);
17442 link
= TREE_CHAIN (link
))
17443 gen_type_die (TREE_VALUE (link
), context_die
);
17446 /* We want to generate the DIE for TYPE so that we can generate the
17447 die for MEMBER, which has been defined; we will need to refer back
17448 to the member declaration nested within TYPE. If we're trying to
17449 generate minimal debug info for TYPE, processing TYPE won't do the
17450 trick; we need to attach the member declaration by hand. */
17453 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17455 gen_type_die (type
, context_die
);
17457 /* If we're trying to avoid duplicate debug info, we may not have
17458 emitted the member decl for this function. Emit it now. */
17459 if (TYPE_STUB_DECL (type
)
17460 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17461 && ! lookup_decl_die (member
))
17463 dw_die_ref type_die
;
17464 gcc_assert (!decl_ultimate_origin (member
));
17466 push_decl_scope (type
);
17467 type_die
= lookup_type_die_strip_naming_typedef (type
);
17468 if (TREE_CODE (member
) == FUNCTION_DECL
)
17469 gen_subprogram_die (member
, type_die
);
17470 else if (TREE_CODE (member
) == FIELD_DECL
)
17472 /* Ignore the nameless fields that are used to skip bits but handle
17473 C++ anonymous unions and structs. */
17474 if (DECL_NAME (member
) != NULL_TREE
17475 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17476 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17478 gen_type_die (member_declared_type (member
), type_die
);
17479 gen_field_die (member
, type_die
);
17483 gen_variable_die (member
, NULL_TREE
, type_die
);
17489 /* Forward declare these functions, because they are mutually recursive
17490 with their set_block_* pairing functions. */
17491 static void set_decl_origin_self (tree
);
17492 static void set_decl_abstract_flags (tree
, int);
17494 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17495 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17496 that it points to the node itself, thus indicating that the node is its
17497 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17498 the given node is NULL, recursively descend the decl/block tree which
17499 it is the root of, and for each other ..._DECL or BLOCK node contained
17500 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17501 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17502 values to point to themselves. */
17505 set_block_origin_self (tree stmt
)
17507 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17509 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17514 for (local_decl
= BLOCK_VARS (stmt
);
17515 local_decl
!= NULL_TREE
;
17516 local_decl
= DECL_CHAIN (local_decl
))
17517 if (! DECL_EXTERNAL (local_decl
))
17518 set_decl_origin_self (local_decl
); /* Potential recursion. */
17524 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17525 subblock
!= NULL_TREE
;
17526 subblock
= BLOCK_CHAIN (subblock
))
17527 set_block_origin_self (subblock
); /* Recurse. */
17532 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17533 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17534 node to so that it points to the node itself, thus indicating that the
17535 node represents its own (abstract) origin. Additionally, if the
17536 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17537 the decl/block tree of which the given node is the root of, and for
17538 each other ..._DECL or BLOCK node contained therein whose
17539 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17540 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17541 point to themselves. */
17544 set_decl_origin_self (tree decl
)
17546 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17548 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17549 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17553 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17554 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17555 if (DECL_INITIAL (decl
) != NULL_TREE
17556 && DECL_INITIAL (decl
) != error_mark_node
)
17557 set_block_origin_self (DECL_INITIAL (decl
));
17562 /* Given a pointer to some BLOCK node, and a boolean value to set the
17563 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17564 the given block, and for all local decls and all local sub-blocks
17565 (recursively) which are contained therein. */
17568 set_block_abstract_flags (tree stmt
, int setting
)
17574 BLOCK_ABSTRACT (stmt
) = setting
;
17576 for (local_decl
= BLOCK_VARS (stmt
);
17577 local_decl
!= NULL_TREE
;
17578 local_decl
= DECL_CHAIN (local_decl
))
17579 if (! DECL_EXTERNAL (local_decl
))
17580 set_decl_abstract_flags (local_decl
, setting
);
17582 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17584 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17585 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17586 || TREE_CODE (local_decl
) == PARM_DECL
)
17587 set_decl_abstract_flags (local_decl
, setting
);
17590 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17591 subblock
!= NULL_TREE
;
17592 subblock
= BLOCK_CHAIN (subblock
))
17593 set_block_abstract_flags (subblock
, setting
);
17596 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17597 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17598 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17599 set the abstract flags for all of the parameters, local vars, local
17600 blocks and sub-blocks (recursively) to the same setting. */
17603 set_decl_abstract_flags (tree decl
, int setting
)
17605 DECL_ABSTRACT (decl
) = setting
;
17606 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17610 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17611 DECL_ABSTRACT (arg
) = setting
;
17612 if (DECL_INITIAL (decl
) != NULL_TREE
17613 && DECL_INITIAL (decl
) != error_mark_node
)
17614 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17618 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17619 may later generate inlined and/or out-of-line instances of. */
17622 dwarf2out_abstract_function (tree decl
)
17624 dw_die_ref old_die
;
17628 htab_t old_decl_loc_table
;
17629 htab_t old_cached_dw_loc_list_table
;
17630 int old_call_site_count
, old_tail_call_site_count
;
17631 struct call_arg_loc_node
*old_call_arg_locations
;
17633 /* Make sure we have the actual abstract inline, not a clone. */
17634 decl
= DECL_ORIGIN (decl
);
17636 old_die
= lookup_decl_die (decl
);
17637 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17638 /* We've already generated the abstract instance. */
17641 /* We can be called while recursively when seeing block defining inlined subroutine
17642 DIE. Be sure to not clobber the outer location table nor use it or we would
17643 get locations in abstract instantces. */
17644 old_decl_loc_table
= decl_loc_table
;
17645 decl_loc_table
= NULL
;
17646 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17647 cached_dw_loc_list_table
= NULL
;
17648 old_call_arg_locations
= call_arg_locations
;
17649 call_arg_locations
= NULL
;
17650 old_call_site_count
= call_site_count
;
17651 call_site_count
= -1;
17652 old_tail_call_site_count
= tail_call_site_count
;
17653 tail_call_site_count
= -1;
17655 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17656 we don't get confused by DECL_ABSTRACT. */
17657 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17659 context
= decl_class_context (decl
);
17661 gen_type_die_for_member
17662 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17665 /* Pretend we've just finished compiling this function. */
17666 save_fn
= current_function_decl
;
17667 current_function_decl
= decl
;
17669 was_abstract
= DECL_ABSTRACT (decl
);
17670 set_decl_abstract_flags (decl
, 1);
17671 dwarf2out_decl (decl
);
17672 if (! was_abstract
)
17673 set_decl_abstract_flags (decl
, 0);
17675 current_function_decl
= save_fn
;
17676 decl_loc_table
= old_decl_loc_table
;
17677 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17678 call_arg_locations
= old_call_arg_locations
;
17679 call_site_count
= old_call_site_count
;
17680 tail_call_site_count
= old_tail_call_site_count
;
17683 /* Helper function of premark_used_types() which gets called through
17686 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17687 marked as unused by prune_unused_types. */
17690 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17695 type
= (tree
) *slot
;
17696 die
= lookup_type_die (type
);
17698 die
->die_perennial_p
= 1;
17702 /* Helper function of premark_types_used_by_global_vars which gets called
17703 through htab_traverse.
17705 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17706 marked as unused by prune_unused_types. The DIE of the type is marked
17707 only if the global variable using the type will actually be emitted. */
17710 premark_types_used_by_global_vars_helper (void **slot
,
17711 void *data ATTRIBUTE_UNUSED
)
17713 struct types_used_by_vars_entry
*entry
;
17716 entry
= (struct types_used_by_vars_entry
*) *slot
;
17717 gcc_assert (entry
->type
!= NULL
17718 && entry
->var_decl
!= NULL
);
17719 die
= lookup_type_die (entry
->type
);
17722 /* Ask cgraph if the global variable really is to be emitted.
17723 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17724 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17725 if (node
&& node
->symbol
.definition
)
17727 die
->die_perennial_p
= 1;
17728 /* Keep the parent DIEs as well. */
17729 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17730 die
->die_perennial_p
= 1;
17736 /* Mark all members of used_types_hash as perennial. */
17739 premark_used_types (struct function
*fun
)
17741 if (fun
&& fun
->used_types_hash
)
17742 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17745 /* Mark all members of types_used_by_vars_entry as perennial. */
17748 premark_types_used_by_global_vars (void)
17750 if (types_used_by_vars_hash
)
17751 htab_traverse (types_used_by_vars_hash
,
17752 premark_types_used_by_global_vars_helper
, NULL
);
17755 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17756 for CA_LOC call arg loc node. */
17759 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17760 struct call_arg_loc_node
*ca_loc
)
17762 dw_die_ref stmt_die
= NULL
, die
;
17763 tree block
= ca_loc
->block
;
17766 && block
!= DECL_INITIAL (decl
)
17767 && TREE_CODE (block
) == BLOCK
)
17769 if (block_map
.length () > BLOCK_NUMBER (block
))
17770 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17773 block
= BLOCK_SUPERCONTEXT (block
);
17775 if (stmt_die
== NULL
)
17776 stmt_die
= subr_die
;
17777 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17778 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17779 if (ca_loc
->tail_call_p
)
17780 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17781 if (ca_loc
->symbol_ref
)
17783 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17785 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17787 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17792 /* Generate a DIE to represent a declared function (either file-scope or
17796 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17798 tree origin
= decl_ultimate_origin (decl
);
17799 dw_die_ref subr_die
;
17801 dw_die_ref old_die
= lookup_decl_die (decl
);
17802 int declaration
= (current_function_decl
!= decl
17803 || class_or_namespace_scope_p (context_die
));
17805 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17807 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17808 started to generate the abstract instance of an inline, decided to output
17809 its containing class, and proceeded to emit the declaration of the inline
17810 from the member list for the class. If so, DECLARATION takes priority;
17811 we'll get back to the abstract instance when done with the class. */
17813 /* The class-scope declaration DIE must be the primary DIE. */
17814 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17817 gcc_assert (!old_die
);
17820 /* Now that the C++ front end lazily declares artificial member fns, we
17821 might need to retrofit the declaration into its class. */
17822 if (!declaration
&& !origin
&& !old_die
17823 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17824 && !class_or_namespace_scope_p (context_die
)
17825 && debug_info_level
> DINFO_LEVEL_TERSE
)
17826 old_die
= force_decl_die (decl
);
17828 if (origin
!= NULL
)
17830 gcc_assert (!declaration
|| local_scope_p (context_die
));
17832 /* Fixup die_parent for the abstract instance of a nested
17833 inline function. */
17834 if (old_die
&& old_die
->die_parent
== NULL
)
17835 add_child_die (context_die
, old_die
);
17837 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17838 add_abstract_origin_attribute (subr_die
, origin
);
17839 /* This is where the actual code for a cloned function is.
17840 Let's emit linkage name attribute for it. This helps
17841 debuggers to e.g, set breakpoints into
17842 constructors/destructors when the user asks "break
17844 add_linkage_name (subr_die
, decl
);
17848 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17849 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17851 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17852 /* We can have a normal definition following an inline one in the
17853 case of redefinition of GNU C extern inlines.
17854 It seems reasonable to use AT_specification in this case. */
17855 && !get_AT (old_die
, DW_AT_inline
))
17857 /* Detect and ignore this case, where we are trying to output
17858 something we have already output. */
17862 /* If the definition comes from the same place as the declaration,
17863 maybe use the old DIE. We always want the DIE for this function
17864 that has the *_pc attributes to be under comp_unit_die so the
17865 debugger can find it. We also need to do this for abstract
17866 instances of inlines, since the spec requires the out-of-line copy
17867 to have the same parent. For local class methods, this doesn't
17868 apply; we just use the old DIE. */
17869 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17870 && (DECL_ARTIFICIAL (decl
)
17871 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17872 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17873 == (unsigned) s
.line
))))
17875 subr_die
= old_die
;
17877 /* Clear out the declaration attribute and the formal parameters.
17878 Do not remove all children, because it is possible that this
17879 declaration die was forced using force_decl_die(). In such
17880 cases die that forced declaration die (e.g. TAG_imported_module)
17881 is one of the children that we do not want to remove. */
17882 remove_AT (subr_die
, DW_AT_declaration
);
17883 remove_AT (subr_die
, DW_AT_object_pointer
);
17884 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17888 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17889 add_AT_specification (subr_die
, old_die
);
17890 add_pubname (decl
, subr_die
);
17891 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17892 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17893 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17894 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17899 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17901 if (TREE_PUBLIC (decl
))
17902 add_AT_flag (subr_die
, DW_AT_external
, 1);
17904 add_name_and_src_coords_attributes (subr_die
, decl
);
17905 add_pubname (decl
, subr_die
);
17906 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17908 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17909 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17910 0, 0, context_die
);
17913 add_pure_or_virtual_attribute (subr_die
, decl
);
17914 if (DECL_ARTIFICIAL (decl
))
17915 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17917 add_accessibility_attribute (subr_die
, decl
);
17922 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17924 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17926 /* If this is an explicit function declaration then generate
17927 a DW_AT_explicit attribute. */
17928 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17929 && (dwarf_version
>= 3 || !dwarf_strict
))
17930 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17932 /* The first time we see a member function, it is in the context of
17933 the class to which it belongs. We make sure of this by emitting
17934 the class first. The next time is the definition, which is
17935 handled above. The two may come from the same source text.
17937 Note that force_decl_die() forces function declaration die. It is
17938 later reused to represent definition. */
17939 equate_decl_number_to_die (decl
, subr_die
);
17942 else if (DECL_ABSTRACT (decl
))
17944 if (DECL_DECLARED_INLINE_P (decl
))
17946 if (cgraph_function_possibly_inlined_p (decl
))
17947 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17949 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17953 if (cgraph_function_possibly_inlined_p (decl
))
17954 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17956 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17959 if (DECL_DECLARED_INLINE_P (decl
)
17960 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17961 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17963 equate_decl_number_to_die (decl
, subr_die
);
17965 else if (!DECL_EXTERNAL (decl
))
17967 HOST_WIDE_INT cfa_fb_offset
;
17968 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17970 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17971 equate_decl_number_to_die (decl
, subr_die
);
17973 gcc_checking_assert (fun
);
17974 if (!flag_reorder_blocks_and_partition
)
17976 dw_fde_ref fde
= fun
->fde
;
17977 if (fde
->dw_fde_begin
)
17979 /* We have already generated the labels. */
17980 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17981 fde
->dw_fde_end
, false);
17985 /* Create start/end labels and add the range. */
17986 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17987 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17988 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17989 current_function_funcdef_no
);
17990 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17991 current_function_funcdef_no
);
17992 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17996 #if VMS_DEBUGGING_INFO
17997 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17998 Section 2.3 Prologue and Epilogue Attributes:
17999 When a breakpoint is set on entry to a function, it is generally
18000 desirable for execution to be suspended, not on the very first
18001 instruction of the function, but rather at a point after the
18002 function's frame has been set up, after any language defined local
18003 declaration processing has been completed, and before execution of
18004 the first statement of the function begins. Debuggers generally
18005 cannot properly determine where this point is. Similarly for a
18006 breakpoint set on exit from a function. The prologue and epilogue
18007 attributes allow a compiler to communicate the location(s) to use. */
18010 if (fde
->dw_fde_vms_end_prologue
)
18011 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18012 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18014 if (fde
->dw_fde_vms_begin_epilogue
)
18015 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18016 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18023 /* Generate pubnames entries for the split function code ranges. */
18024 dw_fde_ref fde
= fun
->fde
;
18026 if (fde
->dw_fde_second_begin
)
18028 if (dwarf_version
>= 3 || !dwarf_strict
)
18030 /* We should use ranges for non-contiguous code section
18031 addresses. Use the actual code range for the initial
18032 section, since the HOT/COLD labels might precede an
18033 alignment offset. */
18034 bool range_list_added
= false;
18035 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18036 fde
->dw_fde_end
, &range_list_added
,
18038 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18039 fde
->dw_fde_second_end
,
18040 &range_list_added
, false);
18041 if (range_list_added
)
18046 /* There is no real support in DW2 for this .. so we make
18047 a work-around. First, emit the pub name for the segment
18048 containing the function label. Then make and emit a
18049 simplified subprogram DIE for the second segment with the
18050 name pre-fixed by __hot/cold_sect_of_. We use the same
18051 linkage name for the second die so that gdb will find both
18052 sections when given "b foo". */
18053 const char *name
= NULL
;
18054 tree decl_name
= DECL_NAME (decl
);
18055 dw_die_ref seg_die
;
18057 /* Do the 'primary' section. */
18058 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18059 fde
->dw_fde_end
, false);
18061 /* Build a minimal DIE for the secondary section. */
18062 seg_die
= new_die (DW_TAG_subprogram
,
18063 subr_die
->die_parent
, decl
);
18065 if (TREE_PUBLIC (decl
))
18066 add_AT_flag (seg_die
, DW_AT_external
, 1);
18068 if (decl_name
!= NULL
18069 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18071 name
= dwarf2_name (decl
, 1);
18072 if (! DECL_ARTIFICIAL (decl
))
18073 add_src_coords_attributes (seg_die
, decl
);
18075 add_linkage_name (seg_die
, decl
);
18077 gcc_assert (name
!= NULL
);
18078 add_pure_or_virtual_attribute (seg_die
, decl
);
18079 if (DECL_ARTIFICIAL (decl
))
18080 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18082 name
= concat ("__second_sect_of_", name
, NULL
);
18083 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18084 fde
->dw_fde_second_end
, false);
18085 add_name_attribute (seg_die
, name
);
18086 if (want_pubnames ())
18087 add_pubname_string (name
, seg_die
);
18091 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18095 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18097 /* We define the "frame base" as the function's CFA. This is more
18098 convenient for several reasons: (1) It's stable across the prologue
18099 and epilogue, which makes it better than just a frame pointer,
18100 (2) With dwarf3, there exists a one-byte encoding that allows us
18101 to reference the .debug_frame data by proxy, but failing that,
18102 (3) We can at least reuse the code inspection and interpretation
18103 code that determines the CFA position at various points in the
18105 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18107 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18108 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18112 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18113 if (list
->dw_loc_next
)
18114 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18116 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18119 /* Compute a displacement from the "steady-state frame pointer" to
18120 the CFA. The former is what all stack slots and argument slots
18121 will reference in the rtl; the latter is what we've told the
18122 debugger about. We'll need to adjust all frame_base references
18123 by this displacement. */
18124 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18126 if (fun
->static_chain_decl
)
18127 add_AT_location_description (subr_die
, DW_AT_static_link
,
18128 loc_list_from_tree (fun
->static_chain_decl
, 2));
18131 /* Generate child dies for template paramaters. */
18132 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18133 gen_generic_params_dies (decl
);
18135 /* Now output descriptions of the arguments for this function. This gets
18136 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18137 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18138 `...' at the end of the formal parameter list. In order to find out if
18139 there was a trailing ellipsis or not, we must instead look at the type
18140 associated with the FUNCTION_DECL. This will be a node of type
18141 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18142 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18143 an ellipsis at the end. */
18145 /* In the case where we are describing a mere function declaration, all we
18146 need to do here (and all we *can* do here) is to describe the *types* of
18147 its formal parameters. */
18148 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18150 else if (declaration
)
18151 gen_formal_types_die (decl
, subr_die
);
18154 /* Generate DIEs to represent all known formal parameters. */
18155 tree parm
= DECL_ARGUMENTS (decl
);
18156 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18157 tree generic_decl_parm
= generic_decl
18158 ? DECL_ARGUMENTS (generic_decl
)
18161 /* Now we want to walk the list of parameters of the function and
18162 emit their relevant DIEs.
18164 We consider the case of DECL being an instance of a generic function
18165 as well as it being a normal function.
18167 If DECL is an instance of a generic function we walk the
18168 parameters of the generic function declaration _and_ the parameters of
18169 DECL itself. This is useful because we want to emit specific DIEs for
18170 function parameter packs and those are declared as part of the
18171 generic function declaration. In that particular case,
18172 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18173 That DIE has children DIEs representing the set of arguments
18174 of the pack. Note that the set of pack arguments can be empty.
18175 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18178 Otherwise, we just consider the parameters of DECL. */
18179 while (generic_decl_parm
|| parm
)
18181 if (generic_decl_parm
18182 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18183 gen_formal_parameter_pack_die (generic_decl_parm
,
18188 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18190 if (parm
== DECL_ARGUMENTS (decl
)
18191 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18193 && (dwarf_version
>= 3 || !dwarf_strict
))
18194 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18196 parm
= DECL_CHAIN (parm
);
18199 if (generic_decl_parm
)
18200 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18203 /* Decide whether we need an unspecified_parameters DIE at the end.
18204 There are 2 more cases to do this for: 1) the ansi ... declaration -
18205 this is detectable when the end of the arg list is not a
18206 void_type_node 2) an unprototyped function declaration (not a
18207 definition). This just means that we have no info about the
18208 parameters at all. */
18209 if (prototype_p (TREE_TYPE (decl
)))
18211 /* This is the prototyped case, check for.... */
18212 if (stdarg_p (TREE_TYPE (decl
)))
18213 gen_unspecified_parameters_die (decl
, subr_die
);
18215 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18216 gen_unspecified_parameters_die (decl
, subr_die
);
18219 /* Output Dwarf info for all of the stuff within the body of the function
18220 (if it has one - it may be just a declaration). */
18221 outer_scope
= DECL_INITIAL (decl
);
18223 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18224 a function. This BLOCK actually represents the outermost binding contour
18225 for the function, i.e. the contour in which the function's formal
18226 parameters and labels get declared. Curiously, it appears that the front
18227 end doesn't actually put the PARM_DECL nodes for the current function onto
18228 the BLOCK_VARS list for this outer scope, but are strung off of the
18229 DECL_ARGUMENTS list for the function instead.
18231 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18232 the LABEL_DECL nodes for the function however, and we output DWARF info
18233 for those in decls_for_scope. Just within the `outer_scope' there will be
18234 a BLOCK node representing the function's outermost pair of curly braces,
18235 and any blocks used for the base and member initializers of a C++
18236 constructor function. */
18237 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18239 int call_site_note_count
= 0;
18240 int tail_call_site_note_count
= 0;
18242 /* Emit a DW_TAG_variable DIE for a named return value. */
18243 if (DECL_NAME (DECL_RESULT (decl
)))
18244 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18246 current_function_has_inlines
= 0;
18247 decls_for_scope (outer_scope
, subr_die
, 0);
18249 if (call_arg_locations
&& !dwarf_strict
)
18251 struct call_arg_loc_node
*ca_loc
;
18252 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18254 dw_die_ref die
= NULL
;
18255 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18258 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18259 arg
; arg
= next_arg
)
18261 dw_loc_descr_ref reg
, val
;
18262 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18263 dw_die_ref cdie
, tdie
= NULL
;
18265 next_arg
= XEXP (arg
, 1);
18266 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18268 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18269 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18270 && REGNO (XEXP (XEXP (arg
, 0), 0))
18271 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18272 next_arg
= XEXP (next_arg
, 1);
18273 if (mode
== VOIDmode
)
18275 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18276 if (mode
== VOIDmode
)
18277 mode
= GET_MODE (XEXP (arg
, 0));
18279 if (mode
== VOIDmode
|| mode
== BLKmode
)
18281 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18283 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18284 tloc
= XEXP (XEXP (arg
, 0), 1);
18287 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18288 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18290 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18291 tlocc
= XEXP (XEXP (arg
, 0), 1);
18295 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18296 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18297 VAR_INIT_STATUS_INITIALIZED
);
18298 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18300 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18301 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18302 get_address_mode (mem
),
18304 VAR_INIT_STATUS_INITIALIZED
);
18306 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18307 == DEBUG_PARAMETER_REF
)
18310 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18311 tdie
= lookup_decl_die (tdecl
);
18318 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18319 != DEBUG_PARAMETER_REF
)
18321 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18323 VAR_INIT_STATUS_INITIALIZED
);
18327 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18328 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18331 add_AT_loc (cdie
, DW_AT_location
, reg
);
18332 else if (tdie
!= NULL
)
18333 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18334 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18335 if (next_arg
!= XEXP (arg
, 1))
18337 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18338 if (mode
== VOIDmode
)
18339 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18340 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18343 VAR_INIT_STATUS_INITIALIZED
);
18345 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18349 && (ca_loc
->symbol_ref
|| tloc
))
18350 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18351 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18353 dw_loc_descr_ref tval
= NULL
;
18355 if (tloc
!= NULL_RTX
)
18356 tval
= mem_loc_descriptor (tloc
,
18357 GET_MODE (tloc
) == VOIDmode
18358 ? Pmode
: GET_MODE (tloc
),
18360 VAR_INIT_STATUS_INITIALIZED
);
18362 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18363 else if (tlocc
!= NULL_RTX
)
18365 tval
= mem_loc_descriptor (tlocc
,
18366 GET_MODE (tlocc
) == VOIDmode
18367 ? Pmode
: GET_MODE (tlocc
),
18369 VAR_INIT_STATUS_INITIALIZED
);
18371 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18377 call_site_note_count
++;
18378 if (ca_loc
->tail_call_p
)
18379 tail_call_site_note_count
++;
18383 call_arg_locations
= NULL
;
18384 call_arg_loc_last
= NULL
;
18385 if (tail_call_site_count
>= 0
18386 && tail_call_site_count
== tail_call_site_note_count
18389 if (call_site_count
>= 0
18390 && call_site_count
== call_site_note_count
)
18391 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18393 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18395 call_site_count
= -1;
18396 tail_call_site_count
= -1;
18398 /* Add the calling convention attribute if requested. */
18399 add_calling_convention_attribute (subr_die
, decl
);
18403 /* Returns a hash value for X (which really is a die_struct). */
18406 common_block_die_table_hash (const void *x
)
18408 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18409 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18412 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18413 as decl_id and die_parent of die_struct Y. */
18416 common_block_die_table_eq (const void *x
, const void *y
)
18418 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18419 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18420 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18423 /* Generate a DIE to represent a declared data object.
18424 Either DECL or ORIGIN must be non-null. */
18427 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18429 HOST_WIDE_INT off
= 0;
18431 tree decl_or_origin
= decl
? decl
: origin
;
18432 tree ultimate_origin
;
18433 dw_die_ref var_die
;
18434 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18435 dw_die_ref origin_die
;
18436 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18437 || class_or_namespace_scope_p (context_die
));
18438 bool specialization_p
= false;
18440 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18441 if (decl
|| ultimate_origin
)
18442 origin
= ultimate_origin
;
18443 com_decl
= fortran_common (decl_or_origin
, &off
);
18445 /* Symbol in common gets emitted as a child of the common block, in the form
18446 of a data member. */
18449 dw_die_ref com_die
;
18450 dw_loc_list_ref loc
;
18451 die_node com_die_arg
;
18453 var_die
= lookup_decl_die (decl_or_origin
);
18456 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18458 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18463 /* Optimize the common case. */
18464 if (single_element_loc_list_p (loc
)
18465 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18466 && loc
->expr
->dw_loc_next
== NULL
18467 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18470 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18471 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18472 = plus_constant (GET_MODE (x
), x
, off
);
18475 loc_list_plus_const (loc
, off
);
18477 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18478 remove_AT (var_die
, DW_AT_declaration
);
18484 if (common_block_die_table
== NULL
)
18485 common_block_die_table
18486 = htab_create_ggc (10, common_block_die_table_hash
,
18487 common_block_die_table_eq
, NULL
);
18489 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18490 com_die_arg
.die_parent
= context_die
;
18491 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18492 loc
= loc_list_from_tree (com_decl
, 2);
18493 if (com_die
== NULL
)
18496 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18499 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18500 add_name_and_src_coords_attributes (com_die
, com_decl
);
18503 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18504 /* Avoid sharing the same loc descriptor between
18505 DW_TAG_common_block and DW_TAG_variable. */
18506 loc
= loc_list_from_tree (com_decl
, 2);
18508 else if (DECL_EXTERNAL (decl
))
18509 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18510 if (want_pubnames ())
18511 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18512 com_die
->decl_id
= DECL_UID (com_decl
);
18513 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18514 *slot
= (void *) com_die
;
18516 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18518 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18519 loc
= loc_list_from_tree (com_decl
, 2);
18520 remove_AT (com_die
, DW_AT_declaration
);
18522 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18523 add_name_and_src_coords_attributes (var_die
, decl
);
18524 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18525 TREE_THIS_VOLATILE (decl
), context_die
);
18526 add_AT_flag (var_die
, DW_AT_external
, 1);
18531 /* Optimize the common case. */
18532 if (single_element_loc_list_p (loc
)
18533 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18534 && loc
->expr
->dw_loc_next
== NULL
18535 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18537 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18538 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18539 = plus_constant (GET_MODE (x
), x
, off
);
18542 loc_list_plus_const (loc
, off
);
18544 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18546 else if (DECL_EXTERNAL (decl
))
18547 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18548 equate_decl_number_to_die (decl
, var_die
);
18552 /* If the compiler emitted a definition for the DECL declaration
18553 and if we already emitted a DIE for it, don't emit a second
18554 DIE for it again. Allow re-declarations of DECLs that are
18555 inside functions, though. */
18556 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18559 /* For static data members, the declaration in the class is supposed
18560 to have DW_TAG_member tag; the specification should still be
18561 DW_TAG_variable referencing the DW_TAG_member DIE. */
18562 if (declaration
&& class_scope_p (context_die
))
18563 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18565 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18568 if (origin
!= NULL
)
18569 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18571 /* Loop unrolling can create multiple blocks that refer to the same
18572 static variable, so we must test for the DW_AT_declaration flag.
18574 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18575 copy decls and set the DECL_ABSTRACT flag on them instead of
18578 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18580 ??? The declare_in_namespace support causes us to get two DIEs for one
18581 variable, both of which are declarations. We want to avoid considering
18582 one to be a specification, so we must test that this DIE is not a
18584 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18585 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18587 /* This is a definition of a C++ class level static. */
18588 add_AT_specification (var_die
, old_die
);
18589 specialization_p
= true;
18590 if (DECL_NAME (decl
))
18592 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18593 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18595 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18596 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18598 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18599 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18601 if (old_die
->die_tag
== DW_TAG_member
)
18602 add_linkage_name (var_die
, decl
);
18606 add_name_and_src_coords_attributes (var_die
, decl
);
18608 if ((origin
== NULL
&& !specialization_p
)
18610 && !DECL_ABSTRACT (decl_or_origin
)
18611 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18612 decl_function_context
18613 (decl_or_origin
))))
18615 tree type
= TREE_TYPE (decl_or_origin
);
18617 if (decl_by_reference_p (decl_or_origin
))
18618 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18620 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18621 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18624 if (origin
== NULL
&& !specialization_p
)
18626 if (TREE_PUBLIC (decl
))
18627 add_AT_flag (var_die
, DW_AT_external
, 1);
18629 if (DECL_ARTIFICIAL (decl
))
18630 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18632 add_accessibility_attribute (var_die
, decl
);
18636 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18638 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18639 equate_decl_number_to_die (decl
, var_die
);
18642 && (! DECL_ABSTRACT (decl_or_origin
)
18643 /* Local static vars are shared between all clones/inlines,
18644 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18646 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18647 && TREE_STATIC (decl_or_origin
)
18648 && DECL_RTL_SET_P (decl_or_origin
)))
18649 /* When abstract origin already has DW_AT_location attribute, no need
18650 to add it again. */
18651 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18653 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18654 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18655 defer_location (decl_or_origin
, var_die
);
18657 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18658 decl
== NULL
, DW_AT_location
);
18659 add_pubname (decl_or_origin
, var_die
);
18662 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18665 /* Generate a DIE to represent a named constant. */
18668 gen_const_die (tree decl
, dw_die_ref context_die
)
18670 dw_die_ref const_die
;
18671 tree type
= TREE_TYPE (decl
);
18673 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18674 add_name_and_src_coords_attributes (const_die
, decl
);
18675 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18676 if (TREE_PUBLIC (decl
))
18677 add_AT_flag (const_die
, DW_AT_external
, 1);
18678 if (DECL_ARTIFICIAL (decl
))
18679 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18680 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18683 /* Generate a DIE to represent a label identifier. */
18686 gen_label_die (tree decl
, dw_die_ref context_die
)
18688 tree origin
= decl_ultimate_origin (decl
);
18689 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18691 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18693 if (origin
!= NULL
)
18694 add_abstract_origin_attribute (lbl_die
, origin
);
18696 add_name_and_src_coords_attributes (lbl_die
, decl
);
18698 if (DECL_ABSTRACT (decl
))
18699 equate_decl_number_to_die (decl
, lbl_die
);
18702 insn
= DECL_RTL_IF_SET (decl
);
18704 /* Deleted labels are programmer specified labels which have been
18705 eliminated because of various optimizations. We still emit them
18706 here so that it is possible to put breakpoints on them. */
18710 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18712 /* When optimization is enabled (via -O) some parts of the compiler
18713 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18714 represent source-level labels which were explicitly declared by
18715 the user. This really shouldn't be happening though, so catch
18716 it if it ever does happen. */
18717 gcc_assert (!INSN_DELETED_P (insn
));
18719 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18720 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18724 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18725 && CODE_LABEL_NUMBER (insn
) != -1)
18727 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18728 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18733 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18734 attributes to the DIE for a block STMT, to describe where the inlined
18735 function was called from. This is similar to add_src_coords_attributes. */
18738 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18740 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18742 if (dwarf_version
>= 3 || !dwarf_strict
)
18744 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18745 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18750 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18751 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18754 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18756 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18758 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18759 && (dwarf_version
>= 3 || !dwarf_strict
))
18761 tree chain
, superblock
= NULL_TREE
;
18763 dw_attr_ref attr
= NULL
;
18765 if (inlined_function_outer_scope_p (stmt
))
18767 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18768 BLOCK_NUMBER (stmt
));
18769 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18772 /* Optimize duplicate .debug_ranges lists or even tails of
18773 lists. If this BLOCK has same ranges as its supercontext,
18774 lookup DW_AT_ranges attribute in the supercontext (and
18775 recursively so), verify that the ranges_table contains the
18776 right values and use it instead of adding a new .debug_range. */
18777 for (chain
= stmt
, pdie
= die
;
18778 BLOCK_SAME_RANGE (chain
);
18779 chain
= BLOCK_SUPERCONTEXT (chain
))
18781 dw_attr_ref new_attr
;
18783 pdie
= pdie
->die_parent
;
18786 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18788 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18789 if (new_attr
== NULL
18790 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18793 superblock
= BLOCK_SUPERCONTEXT (chain
);
18796 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18797 / 2 / DWARF2_ADDR_SIZE
].num
18798 == BLOCK_NUMBER (superblock
))
18799 && BLOCK_FRAGMENT_CHAIN (superblock
))
18801 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18802 / 2 / DWARF2_ADDR_SIZE
;
18803 unsigned long supercnt
= 0, thiscnt
= 0;
18804 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18805 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18808 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18809 == BLOCK_NUMBER (chain
));
18811 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18812 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18813 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18815 gcc_assert (supercnt
>= thiscnt
);
18816 add_AT_range_list (die
, DW_AT_ranges
,
18817 ((off
+ supercnt
- thiscnt
)
18818 * 2 * DWARF2_ADDR_SIZE
),
18823 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18825 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18828 add_ranges (chain
);
18829 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18836 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18837 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18838 BLOCK_NUMBER (stmt
));
18839 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18840 BLOCK_NUMBER (stmt
));
18841 add_AT_low_high_pc (die
, label
, label_high
, false);
18845 /* Generate a DIE for a lexical block. */
18848 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18850 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18852 if (call_arg_locations
)
18854 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18855 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18856 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18859 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18860 add_high_low_attributes (stmt
, stmt_die
);
18862 decls_for_scope (stmt
, stmt_die
, depth
);
18865 /* Generate a DIE for an inlined subprogram. */
18868 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18872 /* The instance of function that is effectively being inlined shall not
18874 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18876 decl
= block_ultimate_origin (stmt
);
18878 /* Emit info for the abstract instance first, if we haven't yet. We
18879 must emit this even if the block is abstract, otherwise when we
18880 emit the block below (or elsewhere), we may end up trying to emit
18881 a die whose origin die hasn't been emitted, and crashing. */
18882 dwarf2out_abstract_function (decl
);
18884 if (! BLOCK_ABSTRACT (stmt
))
18886 dw_die_ref subr_die
18887 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18889 if (call_arg_locations
)
18891 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18892 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18893 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18895 add_abstract_origin_attribute (subr_die
, decl
);
18896 if (TREE_ASM_WRITTEN (stmt
))
18897 add_high_low_attributes (stmt
, subr_die
);
18898 add_call_src_coords_attributes (stmt
, subr_die
);
18900 decls_for_scope (stmt
, subr_die
, depth
);
18901 current_function_has_inlines
= 1;
18905 /* Generate a DIE for a field in a record, or structure. */
18908 gen_field_die (tree decl
, dw_die_ref context_die
)
18910 dw_die_ref decl_die
;
18912 if (TREE_TYPE (decl
) == error_mark_node
)
18915 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18916 add_name_and_src_coords_attributes (decl_die
, decl
);
18917 add_type_attribute (decl_die
, member_declared_type (decl
),
18918 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18921 if (DECL_BIT_FIELD_TYPE (decl
))
18923 add_byte_size_attribute (decl_die
, decl
);
18924 add_bit_size_attribute (decl_die
, decl
);
18925 add_bit_offset_attribute (decl_die
, decl
);
18928 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18929 add_data_member_location_attribute (decl_die
, decl
);
18931 if (DECL_ARTIFICIAL (decl
))
18932 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18934 add_accessibility_attribute (decl_die
, decl
);
18936 /* Equate decl number to die, so that we can look up this decl later on. */
18937 equate_decl_number_to_die (decl
, decl_die
);
18941 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18942 Use modified_type_die instead.
18943 We keep this code here just in case these types of DIEs may be needed to
18944 represent certain things in other languages (e.g. Pascal) someday. */
18947 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18950 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18952 equate_type_number_to_die (type
, ptr_die
);
18953 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18954 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18957 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18958 Use modified_type_die instead.
18959 We keep this code here just in case these types of DIEs may be needed to
18960 represent certain things in other languages (e.g. Pascal) someday. */
18963 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18965 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18967 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18968 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18970 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18972 equate_type_number_to_die (type
, ref_die
);
18973 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18974 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18978 /* Generate a DIE for a pointer to a member type. */
18981 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18984 = new_die (DW_TAG_ptr_to_member_type
,
18985 scope_die_for (type
, context_die
), type
);
18987 equate_type_number_to_die (type
, ptr_die
);
18988 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18989 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18990 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18993 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18995 static char *producer_string
;
18997 /* Return a heap allocated producer string including command line options
18998 if -grecord-gcc-switches. */
19001 gen_producer_string (void)
19004 vec
<dchar_p
> switches
= vNULL
;
19005 const char *language_string
= lang_hooks
.name
;
19006 char *producer
, *tail
;
19008 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19009 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19011 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19012 switch (save_decoded_options
[j
].opt_index
)
19019 case OPT_auxbase_strip
:
19028 case OPT_SPECIAL_unknown
:
19029 case OPT_SPECIAL_ignore
:
19030 case OPT_SPECIAL_program_name
:
19031 case OPT_SPECIAL_input_file
:
19032 case OPT_grecord_gcc_switches
:
19033 case OPT_gno_record_gcc_switches
:
19034 case OPT__output_pch_
:
19035 case OPT_fdiagnostics_show_location_
:
19036 case OPT_fdiagnostics_show_option
:
19037 case OPT_fdiagnostics_show_caret
:
19038 case OPT_fdiagnostics_color_
:
19039 case OPT_fverbose_asm
:
19041 case OPT__sysroot_
:
19043 case OPT_nostdinc__
:
19044 /* Ignore these. */
19047 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19048 & CL_NO_DWARF_RECORD
)
19050 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19052 switch (save_decoded_options
[j
].canonical_option
[0][1])
19059 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19066 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19067 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19071 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19073 sprintf (tail
, "%s %s", language_string
, version_string
);
19076 FOR_EACH_VEC_ELT (switches
, j
, p
)
19080 memcpy (tail
+ 1, p
, len
);
19085 switches
.release ();
19089 /* Generate the DIE for the compilation unit. */
19092 gen_compile_unit_die (const char *filename
)
19095 const char *language_string
= lang_hooks
.name
;
19098 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19102 add_name_attribute (die
, filename
);
19103 /* Don't add cwd for <built-in>. */
19104 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19105 add_comp_dir_attribute (die
);
19108 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19110 /* If our producer is LTO try to figure out a common language to use
19111 from the global list of translation units. */
19112 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19116 const char *common_lang
= NULL
;
19118 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19120 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19123 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19124 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19126 else if (strncmp (common_lang
, "GNU C", 5) == 0
19127 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19128 /* Mixing C and C++ is ok, use C++ in that case. */
19129 common_lang
= "GNU C++";
19132 /* Fall back to C. */
19133 common_lang
= NULL
;
19139 language_string
= common_lang
;
19142 language
= DW_LANG_C89
;
19143 if (strcmp (language_string
, "GNU C++") == 0)
19144 language
= DW_LANG_C_plus_plus
;
19145 else if (strcmp (language_string
, "GNU F77") == 0)
19146 language
= DW_LANG_Fortran77
;
19147 else if (strcmp (language_string
, "GNU Pascal") == 0)
19148 language
= DW_LANG_Pascal83
;
19149 else if (dwarf_version
>= 3 || !dwarf_strict
)
19151 if (strcmp (language_string
, "GNU Ada") == 0)
19152 language
= DW_LANG_Ada95
;
19153 else if (strcmp (language_string
, "GNU Fortran") == 0)
19154 language
= DW_LANG_Fortran95
;
19155 else if (strcmp (language_string
, "GNU Java") == 0)
19156 language
= DW_LANG_Java
;
19157 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19158 language
= DW_LANG_ObjC
;
19159 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19160 language
= DW_LANG_ObjC_plus_plus
;
19161 else if (dwarf_version
>= 5 || !dwarf_strict
)
19163 if (strcmp (language_string
, "GNU Go") == 0)
19164 language
= DW_LANG_Go
;
19167 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19168 else if (strcmp (language_string
, "GNU Fortran") == 0)
19169 language
= DW_LANG_Fortran90
;
19171 add_AT_unsigned (die
, DW_AT_language
, language
);
19175 case DW_LANG_Fortran77
:
19176 case DW_LANG_Fortran90
:
19177 case DW_LANG_Fortran95
:
19178 /* Fortran has case insensitive identifiers and the front-end
19179 lowercases everything. */
19180 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19183 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19189 /* Generate the DIE for a base class. */
19192 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19194 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19196 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19197 add_data_member_location_attribute (die
, binfo
);
19199 if (BINFO_VIRTUAL_P (binfo
))
19200 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19202 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19203 children, otherwise the default is DW_ACCESS_public. In DWARF2
19204 the default has always been DW_ACCESS_private. */
19205 if (access
== access_public_node
)
19207 if (dwarf_version
== 2
19208 || context_die
->die_tag
== DW_TAG_class_type
)
19209 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19211 else if (access
== access_protected_node
)
19212 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19213 else if (dwarf_version
> 2
19214 && context_die
->die_tag
!= DW_TAG_class_type
)
19215 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19218 /* Generate a DIE for a class member. */
19221 gen_member_die (tree type
, dw_die_ref context_die
)
19224 tree binfo
= TYPE_BINFO (type
);
19227 /* If this is not an incomplete type, output descriptions of each of its
19228 members. Note that as we output the DIEs necessary to represent the
19229 members of this record or union type, we will also be trying to output
19230 DIEs to represent the *types* of those members. However the `type'
19231 function (above) will specifically avoid generating type DIEs for member
19232 types *within* the list of member DIEs for this (containing) type except
19233 for those types (of members) which are explicitly marked as also being
19234 members of this (containing) type themselves. The g++ front- end can
19235 force any given type to be treated as a member of some other (containing)
19236 type by setting the TYPE_CONTEXT of the given (member) type to point to
19237 the TREE node representing the appropriate (containing) type. */
19239 /* First output info about the base classes. */
19242 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19246 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19247 gen_inheritance_die (base
,
19248 (accesses
? (*accesses
)[i
] : access_public_node
),
19252 /* Now output info about the data members and type members. */
19253 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19255 /* If we thought we were generating minimal debug info for TYPE
19256 and then changed our minds, some of the member declarations
19257 may have already been defined. Don't define them again, but
19258 do put them in the right order. */
19260 child
= lookup_decl_die (member
);
19262 splice_child_die (context_die
, child
);
19264 gen_decl_die (member
, NULL
, context_die
);
19267 /* Now output info about the function members (if any). */
19268 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19270 /* Don't include clones in the member list. */
19271 if (DECL_ABSTRACT_ORIGIN (member
))
19274 child
= lookup_decl_die (member
);
19276 splice_child_die (context_die
, child
);
19278 gen_decl_die (member
, NULL
, context_die
);
19282 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19283 is set, we pretend that the type was never defined, so we only get the
19284 member DIEs needed by later specification DIEs. */
19287 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19288 enum debug_info_usage usage
)
19290 dw_die_ref type_die
= lookup_type_die (type
);
19291 dw_die_ref scope_die
= 0;
19293 int complete
= (TYPE_SIZE (type
)
19294 && (! TYPE_STUB_DECL (type
)
19295 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19296 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19297 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19299 if (type_die
&& ! complete
)
19302 if (TYPE_CONTEXT (type
) != NULL_TREE
19303 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19304 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19307 scope_die
= scope_die_for (type
, context_die
);
19309 /* Generate child dies for template paramaters. */
19310 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19311 schedule_generic_params_dies_gen (type
);
19313 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19314 /* First occurrence of type or toplevel definition of nested class. */
19316 dw_die_ref old_die
= type_die
;
19318 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19319 ? record_type_tag (type
) : DW_TAG_union_type
,
19321 equate_type_number_to_die (type
, type_die
);
19323 add_AT_specification (type_die
, old_die
);
19325 add_name_attribute (type_die
, type_tag (type
));
19328 remove_AT (type_die
, DW_AT_declaration
);
19330 /* If this type has been completed, then give it a byte_size attribute and
19331 then give a list of members. */
19332 if (complete
&& !ns_decl
)
19334 /* Prevent infinite recursion in cases where the type of some member of
19335 this type is expressed in terms of this type itself. */
19336 TREE_ASM_WRITTEN (type
) = 1;
19337 add_byte_size_attribute (type_die
, type
);
19338 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19340 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19341 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19344 /* If the first reference to this type was as the return type of an
19345 inline function, then it may not have a parent. Fix this now. */
19346 if (type_die
->die_parent
== NULL
)
19347 add_child_die (scope_die
, type_die
);
19349 push_decl_scope (type
);
19350 gen_member_die (type
, type_die
);
19353 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19354 if (TYPE_ARTIFICIAL (type
))
19355 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19357 /* GNU extension: Record what type our vtable lives in. */
19358 if (TYPE_VFIELD (type
))
19360 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19362 gen_type_die (vtype
, context_die
);
19363 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19364 lookup_type_die (vtype
));
19369 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19371 /* We don't need to do this for function-local types. */
19372 if (TYPE_STUB_DECL (type
)
19373 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19374 vec_safe_push (incomplete_types
, type
);
19377 if (get_AT (type_die
, DW_AT_name
))
19378 add_pubtype (type
, type_die
);
19381 /* Generate a DIE for a subroutine _type_. */
19384 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19386 tree return_type
= TREE_TYPE (type
);
19387 dw_die_ref subr_die
19388 = new_die (DW_TAG_subroutine_type
,
19389 scope_die_for (type
, context_die
), type
);
19391 equate_type_number_to_die (type
, subr_die
);
19392 add_prototyped_attribute (subr_die
, type
);
19393 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19394 gen_formal_types_die (type
, subr_die
);
19396 if (get_AT (subr_die
, DW_AT_name
))
19397 add_pubtype (type
, subr_die
);
19400 /* Generate a DIE for a type definition. */
19403 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19405 dw_die_ref type_die
;
19408 if (TREE_ASM_WRITTEN (decl
))
19411 TREE_ASM_WRITTEN (decl
) = 1;
19412 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19413 origin
= decl_ultimate_origin (decl
);
19414 if (origin
!= NULL
)
19415 add_abstract_origin_attribute (type_die
, origin
);
19420 add_name_and_src_coords_attributes (type_die
, decl
);
19421 if (DECL_ORIGINAL_TYPE (decl
))
19423 type
= DECL_ORIGINAL_TYPE (decl
);
19425 gcc_assert (type
!= TREE_TYPE (decl
));
19426 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19430 type
= TREE_TYPE (decl
);
19432 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19434 /* Here, we are in the case of decl being a typedef naming
19435 an anonymous type, e.g:
19436 typedef struct {...} foo;
19437 In that case TREE_TYPE (decl) is not a typedef variant
19438 type and TYPE_NAME of the anonymous type is set to the
19439 TYPE_DECL of the typedef. This construct is emitted by
19442 TYPE is the anonymous struct named by the typedef
19443 DECL. As we need the DW_AT_type attribute of the
19444 DW_TAG_typedef to point to the DIE of TYPE, let's
19445 generate that DIE right away. add_type_attribute
19446 called below will then pick (via lookup_type_die) that
19447 anonymous struct DIE. */
19448 if (!TREE_ASM_WRITTEN (type
))
19449 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19451 /* This is a GNU Extension. We are adding a
19452 DW_AT_linkage_name attribute to the DIE of the
19453 anonymous struct TYPE. The value of that attribute
19454 is the name of the typedef decl naming the anonymous
19455 struct. This greatly eases the work of consumers of
19456 this debug info. */
19457 add_linkage_attr (lookup_type_die (type
), decl
);
19461 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19462 TREE_THIS_VOLATILE (decl
), context_die
);
19464 if (is_naming_typedef_decl (decl
))
19465 /* We want that all subsequent calls to lookup_type_die with
19466 TYPE in argument yield the DW_TAG_typedef we have just
19468 equate_type_number_to_die (type
, type_die
);
19470 add_accessibility_attribute (type_die
, decl
);
19473 if (DECL_ABSTRACT (decl
))
19474 equate_decl_number_to_die (decl
, type_die
);
19476 if (get_AT (type_die
, DW_AT_name
))
19477 add_pubtype (decl
, type_die
);
19480 /* Generate a DIE for a struct, class, enum or union type. */
19483 gen_tagged_type_die (tree type
,
19484 dw_die_ref context_die
,
19485 enum debug_info_usage usage
)
19489 if (type
== NULL_TREE
19490 || !is_tagged_type (type
))
19493 /* If this is a nested type whose containing class hasn't been written
19494 out yet, writing it out will cover this one, too. This does not apply
19495 to instantiations of member class templates; they need to be added to
19496 the containing class as they are generated. FIXME: This hurts the
19497 idea of combining type decls from multiple TUs, since we can't predict
19498 what set of template instantiations we'll get. */
19499 if (TYPE_CONTEXT (type
)
19500 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19501 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19503 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19505 if (TREE_ASM_WRITTEN (type
))
19508 /* If that failed, attach ourselves to the stub. */
19509 push_decl_scope (TYPE_CONTEXT (type
));
19510 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19513 else if (TYPE_CONTEXT (type
) != NULL_TREE
19514 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19516 /* If this type is local to a function that hasn't been written
19517 out yet, use a NULL context for now; it will be fixed up in
19518 decls_for_scope. */
19519 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19520 /* A declaration DIE doesn't count; nested types need to go in the
19522 if (context_die
&& is_declaration_die (context_die
))
19523 context_die
= NULL
;
19528 context_die
= declare_in_namespace (type
, context_die
);
19532 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19534 /* This might have been written out by the call to
19535 declare_in_namespace. */
19536 if (!TREE_ASM_WRITTEN (type
))
19537 gen_enumeration_type_die (type
, context_die
);
19540 gen_struct_or_union_type_die (type
, context_die
, usage
);
19545 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19546 it up if it is ever completed. gen_*_type_die will set it for us
19547 when appropriate. */
19550 /* Generate a type description DIE. */
19553 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19554 enum debug_info_usage usage
)
19556 struct array_descr_info info
;
19558 if (type
== NULL_TREE
|| type
== error_mark_node
)
19561 if (TYPE_NAME (type
) != NULL_TREE
19562 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19563 && is_redundant_typedef (TYPE_NAME (type
))
19564 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19565 /* The DECL of this type is a typedef we don't want to emit debug
19566 info for but we want debug info for its underlying typedef.
19567 This can happen for e.g, the injected-class-name of a C++
19569 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19571 /* If TYPE is a typedef type variant, let's generate debug info
19572 for the parent typedef which TYPE is a type of. */
19573 if (typedef_variant_p (type
))
19575 if (TREE_ASM_WRITTEN (type
))
19578 /* Prevent broken recursion; we can't hand off to the same type. */
19579 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19581 /* Give typedefs the right scope. */
19582 context_die
= scope_die_for (type
, context_die
);
19584 TREE_ASM_WRITTEN (type
) = 1;
19586 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19590 /* If type is an anonymous tagged type named by a typedef, let's
19591 generate debug info for the typedef. */
19592 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19594 /* Use the DIE of the containing namespace as the parent DIE of
19595 the type description DIE we want to generate. */
19596 if (DECL_CONTEXT (TYPE_NAME (type
))
19597 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19598 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19600 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19604 /* If this is an array type with hidden descriptor, handle it first. */
19605 if (!TREE_ASM_WRITTEN (type
)
19606 && lang_hooks
.types
.get_array_descr_info
19607 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19608 && (dwarf_version
>= 3 || !dwarf_strict
))
19610 gen_descr_array_type_die (type
, &info
, context_die
);
19611 TREE_ASM_WRITTEN (type
) = 1;
19615 /* We are going to output a DIE to represent the unqualified version
19616 of this type (i.e. without any const or volatile qualifiers) so
19617 get the main variant (i.e. the unqualified version) of this type
19618 now. (Vectors are special because the debugging info is in the
19619 cloned type itself). */
19620 if (TREE_CODE (type
) != VECTOR_TYPE
)
19621 type
= type_main_variant (type
);
19623 if (TREE_ASM_WRITTEN (type
))
19626 switch (TREE_CODE (type
))
19632 case REFERENCE_TYPE
:
19633 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19634 ensures that the gen_type_die recursion will terminate even if the
19635 type is recursive. Recursive types are possible in Ada. */
19636 /* ??? We could perhaps do this for all types before the switch
19638 TREE_ASM_WRITTEN (type
) = 1;
19640 /* For these types, all that is required is that we output a DIE (or a
19641 set of DIEs) to represent the "basis" type. */
19642 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19643 DINFO_USAGE_IND_USE
);
19647 /* This code is used for C++ pointer-to-data-member types.
19648 Output a description of the relevant class type. */
19649 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19650 DINFO_USAGE_IND_USE
);
19652 /* Output a description of the type of the object pointed to. */
19653 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19654 DINFO_USAGE_IND_USE
);
19656 /* Now output a DIE to represent this pointer-to-data-member type
19658 gen_ptr_to_mbr_type_die (type
, context_die
);
19661 case FUNCTION_TYPE
:
19662 /* Force out return type (in case it wasn't forced out already). */
19663 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19664 DINFO_USAGE_DIR_USE
);
19665 gen_subroutine_type_die (type
, context_die
);
19669 /* Force out return type (in case it wasn't forced out already). */
19670 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19671 DINFO_USAGE_DIR_USE
);
19672 gen_subroutine_type_die (type
, context_die
);
19676 gen_array_type_die (type
, context_die
);
19680 gen_array_type_die (type
, context_die
);
19683 case ENUMERAL_TYPE
:
19686 case QUAL_UNION_TYPE
:
19687 gen_tagged_type_die (type
, context_die
, usage
);
19693 case FIXED_POINT_TYPE
:
19696 /* No DIEs needed for fundamental types. */
19701 /* Just use DW_TAG_unspecified_type. */
19703 dw_die_ref type_die
= lookup_type_die (type
);
19704 if (type_die
== NULL
)
19706 tree name
= TYPE_NAME (type
);
19707 if (TREE_CODE (name
) == TYPE_DECL
)
19708 name
= DECL_NAME (name
);
19709 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19710 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19711 equate_type_number_to_die (type
, type_die
);
19717 gcc_unreachable ();
19720 TREE_ASM_WRITTEN (type
) = 1;
19724 gen_type_die (tree type
, dw_die_ref context_die
)
19726 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19729 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19730 things which are local to the given block. */
19733 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19735 int must_output_die
= 0;
19738 /* Ignore blocks that are NULL. */
19739 if (stmt
== NULL_TREE
)
19742 inlined_func
= inlined_function_outer_scope_p (stmt
);
19744 /* If the block is one fragment of a non-contiguous block, do not
19745 process the variables, since they will have been done by the
19746 origin block. Do process subblocks. */
19747 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19751 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19752 gen_block_die (sub
, context_die
, depth
+ 1);
19757 /* Determine if we need to output any Dwarf DIEs at all to represent this
19760 /* The outer scopes for inlinings *must* always be represented. We
19761 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19762 must_output_die
= 1;
19765 /* Determine if this block directly contains any "significant"
19766 local declarations which we will need to output DIEs for. */
19767 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19768 /* We are not in terse mode so *any* local declaration counts
19769 as being a "significant" one. */
19770 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19771 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19772 && (TREE_USED (stmt
)
19773 || TREE_ASM_WRITTEN (stmt
)
19774 || BLOCK_ABSTRACT (stmt
)));
19775 else if ((TREE_USED (stmt
)
19776 || TREE_ASM_WRITTEN (stmt
)
19777 || BLOCK_ABSTRACT (stmt
))
19778 && !dwarf2out_ignore_block (stmt
))
19779 must_output_die
= 1;
19782 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19783 DIE for any block which contains no significant local declarations at
19784 all. Rather, in such cases we just call `decls_for_scope' so that any
19785 needed Dwarf info for any sub-blocks will get properly generated. Note
19786 that in terse mode, our definition of what constitutes a "significant"
19787 local declaration gets restricted to include only inlined function
19788 instances and local (nested) function definitions. */
19789 if (must_output_die
)
19793 /* If STMT block is abstract, that means we have been called
19794 indirectly from dwarf2out_abstract_function.
19795 That function rightfully marks the descendent blocks (of
19796 the abstract function it is dealing with) as being abstract,
19797 precisely to prevent us from emitting any
19798 DW_TAG_inlined_subroutine DIE as a descendent
19799 of an abstract function instance. So in that case, we should
19800 not call gen_inlined_subroutine_die.
19802 Later though, when cgraph asks dwarf2out to emit info
19803 for the concrete instance of the function decl into which
19804 the concrete instance of STMT got inlined, the later will lead
19805 to the generation of a DW_TAG_inlined_subroutine DIE. */
19806 if (! BLOCK_ABSTRACT (stmt
))
19807 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19810 gen_lexical_block_die (stmt
, context_die
, depth
);
19813 decls_for_scope (stmt
, context_die
, depth
);
19816 /* Process variable DECL (or variable with origin ORIGIN) within
19817 block STMT and add it to CONTEXT_DIE. */
19819 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19822 tree decl_or_origin
= decl
? decl
: origin
;
19824 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19825 die
= lookup_decl_die (decl_or_origin
);
19826 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19827 && TYPE_DECL_IS_STUB (decl_or_origin
))
19828 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19832 if (die
!= NULL
&& die
->die_parent
== NULL
)
19833 add_child_die (context_die
, die
);
19834 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19835 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19836 stmt
, context_die
);
19838 gen_decl_die (decl
, origin
, context_die
);
19841 /* Generate all of the decls declared within a given scope and (recursively)
19842 all of its sub-blocks. */
19845 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19851 /* Ignore NULL blocks. */
19852 if (stmt
== NULL_TREE
)
19855 /* Output the DIEs to represent all of the data objects and typedefs
19856 declared directly within this block but not within any nested
19857 sub-blocks. Also, nested function and tag DIEs have been
19858 generated with a parent of NULL; fix that up now. */
19859 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19860 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19861 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19862 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19865 /* If we're at -g1, we're not interested in subblocks. */
19866 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19869 /* Output the DIEs to represent all sub-blocks (and the items declared
19870 therein) of this block. */
19871 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19873 subblocks
= BLOCK_CHAIN (subblocks
))
19874 gen_block_die (subblocks
, context_die
, depth
+ 1);
19877 /* Is this a typedef we can avoid emitting? */
19880 is_redundant_typedef (const_tree decl
)
19882 if (TYPE_DECL_IS_STUB (decl
))
19885 if (DECL_ARTIFICIAL (decl
)
19886 && DECL_CONTEXT (decl
)
19887 && is_tagged_type (DECL_CONTEXT (decl
))
19888 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19889 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19890 /* Also ignore the artificial member typedef for the class name. */
19896 /* Return TRUE if TYPE is a typedef that names a type for linkage
19897 purposes. This kind of typedefs is produced by the C++ FE for
19900 typedef struct {...} foo;
19902 In that case, there is no typedef variant type produced for foo.
19903 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19907 is_naming_typedef_decl (const_tree decl
)
19909 if (decl
== NULL_TREE
19910 || TREE_CODE (decl
) != TYPE_DECL
19911 || !is_tagged_type (TREE_TYPE (decl
))
19912 || DECL_IS_BUILTIN (decl
)
19913 || is_redundant_typedef (decl
)
19914 /* It looks like Ada produces TYPE_DECLs that are very similar
19915 to C++ naming typedefs but that have different
19916 semantics. Let's be specific to c++ for now. */
19920 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19921 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19922 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19923 != TYPE_NAME (TREE_TYPE (decl
))));
19926 /* Returns the DIE for a context. */
19928 static inline dw_die_ref
19929 get_context_die (tree context
)
19933 /* Find die that represents this context. */
19934 if (TYPE_P (context
))
19936 context
= TYPE_MAIN_VARIANT (context
);
19937 return strip_naming_typedef (context
, force_type_die (context
));
19940 return force_decl_die (context
);
19942 return comp_unit_die ();
19945 /* Returns the DIE for decl. A DIE will always be returned. */
19948 force_decl_die (tree decl
)
19950 dw_die_ref decl_die
;
19951 unsigned saved_external_flag
;
19952 tree save_fn
= NULL_TREE
;
19953 decl_die
= lookup_decl_die (decl
);
19956 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19958 decl_die
= lookup_decl_die (decl
);
19962 switch (TREE_CODE (decl
))
19964 case FUNCTION_DECL
:
19965 /* Clear current_function_decl, so that gen_subprogram_die thinks
19966 that this is a declaration. At this point, we just want to force
19967 declaration die. */
19968 save_fn
= current_function_decl
;
19969 current_function_decl
= NULL_TREE
;
19970 gen_subprogram_die (decl
, context_die
);
19971 current_function_decl
= save_fn
;
19975 /* Set external flag to force declaration die. Restore it after
19976 gen_decl_die() call. */
19977 saved_external_flag
= DECL_EXTERNAL (decl
);
19978 DECL_EXTERNAL (decl
) = 1;
19979 gen_decl_die (decl
, NULL
, context_die
);
19980 DECL_EXTERNAL (decl
) = saved_external_flag
;
19983 case NAMESPACE_DECL
:
19984 if (dwarf_version
>= 3 || !dwarf_strict
)
19985 dwarf2out_decl (decl
);
19987 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19988 decl_die
= comp_unit_die ();
19991 case TRANSLATION_UNIT_DECL
:
19992 decl_die
= comp_unit_die ();
19996 gcc_unreachable ();
19999 /* We should be able to find the DIE now. */
20001 decl_die
= lookup_decl_die (decl
);
20002 gcc_assert (decl_die
);
20008 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20009 always returned. */
20012 force_type_die (tree type
)
20014 dw_die_ref type_die
;
20016 type_die
= lookup_type_die (type
);
20019 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20021 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20022 TYPE_VOLATILE (type
), context_die
);
20023 gcc_assert (type_die
);
20028 /* Force out any required namespaces to be able to output DECL,
20029 and return the new context_die for it, if it's changed. */
20032 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20034 tree context
= (DECL_P (thing
)
20035 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20036 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20037 /* Force out the namespace. */
20038 context_die
= force_decl_die (context
);
20040 return context_die
;
20043 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20044 type) within its namespace, if appropriate.
20046 For compatibility with older debuggers, namespace DIEs only contain
20047 declarations; all definitions are emitted at CU scope. */
20050 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20052 dw_die_ref ns_context
;
20054 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20055 return context_die
;
20057 /* If this decl is from an inlined function, then don't try to emit it in its
20058 namespace, as we will get confused. It would have already been emitted
20059 when the abstract instance of the inline function was emitted anyways. */
20060 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20061 return context_die
;
20063 ns_context
= setup_namespace_context (thing
, context_die
);
20065 if (ns_context
!= context_die
)
20069 if (DECL_P (thing
))
20070 gen_decl_die (thing
, NULL
, ns_context
);
20072 gen_type_die (thing
, ns_context
);
20074 return context_die
;
20077 /* Generate a DIE for a namespace or namespace alias. */
20080 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20082 dw_die_ref namespace_die
;
20084 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20085 they are an alias of. */
20086 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20088 /* Output a real namespace or module. */
20089 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20090 namespace_die
= new_die (is_fortran ()
20091 ? DW_TAG_module
: DW_TAG_namespace
,
20092 context_die
, decl
);
20093 /* For Fortran modules defined in different CU don't add src coords. */
20094 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20096 const char *name
= dwarf2_name (decl
, 0);
20098 add_name_attribute (namespace_die
, name
);
20101 add_name_and_src_coords_attributes (namespace_die
, decl
);
20102 if (DECL_EXTERNAL (decl
))
20103 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20104 equate_decl_number_to_die (decl
, namespace_die
);
20108 /* Output a namespace alias. */
20110 /* Force out the namespace we are an alias of, if necessary. */
20111 dw_die_ref origin_die
20112 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20114 if (DECL_FILE_SCOPE_P (decl
)
20115 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20116 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20117 /* Now create the namespace alias DIE. */
20118 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20119 add_name_and_src_coords_attributes (namespace_die
, decl
);
20120 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20121 equate_decl_number_to_die (decl
, namespace_die
);
20123 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20124 if (want_pubnames ())
20125 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20128 /* Generate Dwarf debug information for a decl described by DECL.
20129 The return value is currently only meaningful for PARM_DECLs,
20130 for all other decls it returns NULL. */
20133 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20135 tree decl_or_origin
= decl
? decl
: origin
;
20136 tree class_origin
= NULL
, ultimate_origin
;
20138 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20141 switch (TREE_CODE (decl_or_origin
))
20147 if (!is_fortran () && !is_ada ())
20149 /* The individual enumerators of an enum type get output when we output
20150 the Dwarf representation of the relevant enum type itself. */
20154 /* Emit its type. */
20155 gen_type_die (TREE_TYPE (decl
), context_die
);
20157 /* And its containing namespace. */
20158 context_die
= declare_in_namespace (decl
, context_die
);
20160 gen_const_die (decl
, context_die
);
20163 case FUNCTION_DECL
:
20164 /* Don't output any DIEs to represent mere function declarations,
20165 unless they are class members or explicit block externs. */
20166 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20167 && DECL_FILE_SCOPE_P (decl_or_origin
)
20168 && (current_function_decl
== NULL_TREE
20169 || DECL_ARTIFICIAL (decl_or_origin
)))
20174 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20175 on local redeclarations of global functions. That seems broken. */
20176 if (current_function_decl
!= decl
)
20177 /* This is only a declaration. */;
20180 /* If we're emitting a clone, emit info for the abstract instance. */
20181 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20182 dwarf2out_abstract_function (origin
20183 ? DECL_ORIGIN (origin
)
20184 : DECL_ABSTRACT_ORIGIN (decl
));
20186 /* If we're emitting an out-of-line copy of an inline function,
20187 emit info for the abstract instance and set up to refer to it. */
20188 else if (cgraph_function_possibly_inlined_p (decl
)
20189 && ! DECL_ABSTRACT (decl
)
20190 && ! class_or_namespace_scope_p (context_die
)
20191 /* dwarf2out_abstract_function won't emit a die if this is just
20192 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20193 that case, because that works only if we have a die. */
20194 && DECL_INITIAL (decl
) != NULL_TREE
)
20196 dwarf2out_abstract_function (decl
);
20197 set_decl_origin_self (decl
);
20200 /* Otherwise we're emitting the primary DIE for this decl. */
20201 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20203 /* Before we describe the FUNCTION_DECL itself, make sure that we
20204 have its containing type. */
20206 origin
= decl_class_context (decl
);
20207 if (origin
!= NULL_TREE
)
20208 gen_type_die (origin
, context_die
);
20210 /* And its return type. */
20211 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20213 /* And its virtual context. */
20214 if (DECL_VINDEX (decl
) != NULL_TREE
)
20215 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20217 /* Make sure we have a member DIE for decl. */
20218 if (origin
!= NULL_TREE
)
20219 gen_type_die_for_member (origin
, decl
, context_die
);
20221 /* And its containing namespace. */
20222 context_die
= declare_in_namespace (decl
, context_die
);
20225 /* Now output a DIE to represent the function itself. */
20227 gen_subprogram_die (decl
, context_die
);
20231 /* If we are in terse mode, don't generate any DIEs to represent any
20232 actual typedefs. */
20233 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20236 /* In the special case of a TYPE_DECL node representing the declaration
20237 of some type tag, if the given TYPE_DECL is marked as having been
20238 instantiated from some other (original) TYPE_DECL node (e.g. one which
20239 was generated within the original definition of an inline function) we
20240 used to generate a special (abbreviated) DW_TAG_structure_type,
20241 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20242 should be actually referencing those DIEs, as variable DIEs with that
20243 type would be emitted already in the abstract origin, so it was always
20244 removed during unused type prunning. Don't add anything in this
20246 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20249 if (is_redundant_typedef (decl
))
20250 gen_type_die (TREE_TYPE (decl
), context_die
);
20252 /* Output a DIE to represent the typedef itself. */
20253 gen_typedef_die (decl
, context_die
);
20257 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20258 gen_label_die (decl
, context_die
);
20263 /* If we are in terse mode, don't generate any DIEs to represent any
20264 variable declarations or definitions. */
20265 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20268 /* Output any DIEs that are needed to specify the type of this data
20270 if (decl_by_reference_p (decl_or_origin
))
20271 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20273 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20275 /* And its containing type. */
20276 class_origin
= decl_class_context (decl_or_origin
);
20277 if (class_origin
!= NULL_TREE
)
20278 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20280 /* And its containing namespace. */
20281 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20283 /* Now output the DIE to represent the data object itself. This gets
20284 complicated because of the possibility that the VAR_DECL really
20285 represents an inlined instance of a formal parameter for an inline
20287 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20288 if (ultimate_origin
!= NULL_TREE
20289 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20290 gen_formal_parameter_die (decl
, origin
,
20291 true /* Emit name attribute. */,
20294 gen_variable_die (decl
, origin
, context_die
);
20298 /* Ignore the nameless fields that are used to skip bits but handle C++
20299 anonymous unions and structs. */
20300 if (DECL_NAME (decl
) != NULL_TREE
20301 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20302 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20304 gen_type_die (member_declared_type (decl
), context_die
);
20305 gen_field_die (decl
, context_die
);
20310 if (DECL_BY_REFERENCE (decl_or_origin
))
20311 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20313 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20314 return gen_formal_parameter_die (decl
, origin
,
20315 true /* Emit name attribute. */,
20318 case NAMESPACE_DECL
:
20319 case IMPORTED_DECL
:
20320 if (dwarf_version
>= 3 || !dwarf_strict
)
20321 gen_namespace_die (decl
, context_die
);
20325 /* Probably some frontend-internal decl. Assume we don't care. */
20326 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20333 /* Output debug information for global decl DECL. Called from toplev.c after
20334 compilation proper has finished. */
20337 dwarf2out_global_decl (tree decl
)
20339 /* Output DWARF2 information for file-scope tentative data object
20340 declarations, file-scope (extern) function declarations (which
20341 had no corresponding body) and file-scope tagged type declarations
20342 and definitions which have not yet been forced out. */
20343 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20344 dwarf2out_decl (decl
);
20347 /* Output debug information for type decl DECL. Called from toplev.c
20348 and from language front ends (to record built-in types). */
20350 dwarf2out_type_decl (tree decl
, int local
)
20353 dwarf2out_decl (decl
);
20356 /* Output debug information for imported module or decl DECL.
20357 NAME is non-NULL name in the lexical block if the decl has been renamed.
20358 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20359 that DECL belongs to.
20360 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20362 dwarf2out_imported_module_or_decl_1 (tree decl
,
20364 tree lexical_block
,
20365 dw_die_ref lexical_block_die
)
20367 expanded_location xloc
;
20368 dw_die_ref imported_die
= NULL
;
20369 dw_die_ref at_import_die
;
20371 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20373 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20374 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20378 xloc
= expand_location (input_location
);
20380 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20382 at_import_die
= force_type_die (TREE_TYPE (decl
));
20383 /* For namespace N { typedef void T; } using N::T; base_type_die
20384 returns NULL, but DW_TAG_imported_declaration requires
20385 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20386 if (!at_import_die
)
20388 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20389 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20390 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20391 gcc_assert (at_import_die
);
20396 at_import_die
= lookup_decl_die (decl
);
20397 if (!at_import_die
)
20399 /* If we're trying to avoid duplicate debug info, we may not have
20400 emitted the member decl for this field. Emit it now. */
20401 if (TREE_CODE (decl
) == FIELD_DECL
)
20403 tree type
= DECL_CONTEXT (decl
);
20405 if (TYPE_CONTEXT (type
)
20406 && TYPE_P (TYPE_CONTEXT (type
))
20407 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20408 DINFO_USAGE_DIR_USE
))
20410 gen_type_die_for_member (type
, decl
,
20411 get_context_die (TYPE_CONTEXT (type
)));
20413 at_import_die
= force_decl_die (decl
);
20417 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20419 if (dwarf_version
>= 3 || !dwarf_strict
)
20420 imported_die
= new_die (DW_TAG_imported_module
,
20427 imported_die
= new_die (DW_TAG_imported_declaration
,
20431 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20432 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20434 add_AT_string (imported_die
, DW_AT_name
,
20435 IDENTIFIER_POINTER (name
));
20436 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20439 /* Output debug information for imported module or decl DECL.
20440 NAME is non-NULL name in context if the decl has been renamed.
20441 CHILD is true if decl is one of the renamed decls as part of
20442 importing whole module. */
20445 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20448 /* dw_die_ref at_import_die; */
20449 dw_die_ref scope_die
;
20451 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20456 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20457 We need decl DIE for reference and scope die. First, get DIE for the decl
20460 /* Get the scope die for decl context. Use comp_unit_die for global module
20461 or decl. If die is not found for non globals, force new die. */
20463 && TYPE_P (context
)
20464 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20467 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20470 scope_die
= get_context_die (context
);
20474 gcc_assert (scope_die
->die_child
);
20475 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20476 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20477 scope_die
= scope_die
->die_child
;
20480 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20481 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20485 /* Write the debugging output for DECL. */
20488 dwarf2out_decl (tree decl
)
20490 dw_die_ref context_die
= comp_unit_die ();
20492 switch (TREE_CODE (decl
))
20497 case FUNCTION_DECL
:
20498 /* What we would really like to do here is to filter out all mere
20499 file-scope declarations of file-scope functions which are never
20500 referenced later within this translation unit (and keep all of ones
20501 that *are* referenced later on) but we aren't clairvoyant, so we have
20502 no idea which functions will be referenced in the future (i.e. later
20503 on within the current translation unit). So here we just ignore all
20504 file-scope function declarations which are not also definitions. If
20505 and when the debugger needs to know something about these functions,
20506 it will have to hunt around and find the DWARF information associated
20507 with the definition of the function.
20509 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20510 nodes represent definitions and which ones represent mere
20511 declarations. We have to check DECL_INITIAL instead. That's because
20512 the C front-end supports some weird semantics for "extern inline"
20513 function definitions. These can get inlined within the current
20514 translation unit (and thus, we need to generate Dwarf info for their
20515 abstract instances so that the Dwarf info for the concrete inlined
20516 instances can have something to refer to) but the compiler never
20517 generates any out-of-lines instances of such things (despite the fact
20518 that they *are* definitions).
20520 The important point is that the C front-end marks these "extern
20521 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20522 them anyway. Note that the C++ front-end also plays some similar games
20523 for inline function definitions appearing within include files which
20524 also contain `#pragma interface' pragmas.
20526 If we are called from dwarf2out_abstract_function output a DIE
20527 anyway. We can end up here this way with early inlining and LTO
20528 where the inlined function is output in a different LTRANS unit
20530 if (DECL_INITIAL (decl
) == NULL_TREE
20531 && ! DECL_ABSTRACT (decl
))
20534 /* If we're a nested function, initially use a parent of NULL; if we're
20535 a plain function, this will be fixed up in decls_for_scope. If
20536 we're a method, it will be ignored, since we already have a DIE. */
20537 if (decl_function_context (decl
)
20538 /* But if we're in terse mode, we don't care about scope. */
20539 && debug_info_level
> DINFO_LEVEL_TERSE
)
20540 context_die
= NULL
;
20544 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20545 declaration and if the declaration was never even referenced from
20546 within this entire compilation unit. We suppress these DIEs in
20547 order to save space in the .debug section (by eliminating entries
20548 which are probably useless). Note that we must not suppress
20549 block-local extern declarations (whether used or not) because that
20550 would screw-up the debugger's name lookup mechanism and cause it to
20551 miss things which really ought to be in scope at a given point. */
20552 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20555 /* For local statics lookup proper context die. */
20556 if (TREE_STATIC (decl
)
20557 && DECL_CONTEXT (decl
)
20558 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20559 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20561 /* If we are in terse mode, don't generate any DIEs to represent any
20562 variable declarations or definitions. */
20563 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20568 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20570 if (!is_fortran () && !is_ada ())
20572 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20573 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20576 case NAMESPACE_DECL
:
20577 case IMPORTED_DECL
:
20578 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20580 if (lookup_decl_die (decl
) != NULL
)
20585 /* Don't emit stubs for types unless they are needed by other DIEs. */
20586 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20589 /* Don't bother trying to generate any DIEs to represent any of the
20590 normal built-in types for the language we are compiling. */
20591 if (DECL_IS_BUILTIN (decl
))
20594 /* If we are in terse mode, don't generate any DIEs for types. */
20595 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20598 /* If we're a function-scope tag, initially use a parent of NULL;
20599 this will be fixed up in decls_for_scope. */
20600 if (decl_function_context (decl
))
20601 context_die
= NULL
;
20609 gen_decl_die (decl
, NULL
, context_die
);
20612 /* Write the debugging output for DECL. */
20615 dwarf2out_function_decl (tree decl
)
20617 dwarf2out_decl (decl
);
20618 call_arg_locations
= NULL
;
20619 call_arg_loc_last
= NULL
;
20620 call_site_count
= -1;
20621 tail_call_site_count
= -1;
20622 block_map
.release ();
20623 htab_empty (decl_loc_table
);
20624 htab_empty (cached_dw_loc_list_table
);
20627 /* Output a marker (i.e. a label) for the beginning of the generated code for
20628 a lexical block. */
20631 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20632 unsigned int blocknum
)
20634 switch_to_section (current_function_section ());
20635 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20638 /* Output a marker (i.e. a label) for the end of the generated code for a
20642 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20644 switch_to_section (current_function_section ());
20645 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20648 /* Returns nonzero if it is appropriate not to emit any debugging
20649 information for BLOCK, because it doesn't contain any instructions.
20651 Don't allow this for blocks with nested functions or local classes
20652 as we would end up with orphans, and in the presence of scheduling
20653 we may end up calling them anyway. */
20656 dwarf2out_ignore_block (const_tree block
)
20661 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20662 if (TREE_CODE (decl
) == FUNCTION_DECL
20663 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20665 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20667 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20668 if (TREE_CODE (decl
) == FUNCTION_DECL
20669 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20676 /* Hash table routines for file_hash. */
20679 file_table_eq (const void *p1_p
, const void *p2_p
)
20681 const struct dwarf_file_data
*const p1
=
20682 (const struct dwarf_file_data
*) p1_p
;
20683 const char *const p2
= (const char *) p2_p
;
20684 return filename_cmp (p1
->filename
, p2
) == 0;
20688 file_table_hash (const void *p_p
)
20690 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20691 return htab_hash_string (p
->filename
);
20694 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20695 dwarf2out.c) and return its "index". The index of each (known) filename is
20696 just a unique number which is associated with only that one filename. We
20697 need such numbers for the sake of generating labels (in the .debug_sfnames
20698 section) and references to those files numbers (in the .debug_srcinfo
20699 and.debug_macinfo sections). If the filename given as an argument is not
20700 found in our current list, add it to the list and assign it the next
20701 available unique index number. In order to speed up searches, we remember
20702 the index of the filename was looked up last. This handles the majority of
20705 static struct dwarf_file_data
*
20706 lookup_filename (const char *file_name
)
20709 struct dwarf_file_data
* created
;
20711 /* Check to see if the file name that was searched on the previous
20712 call matches this file name. If so, return the index. */
20713 if (file_table_last_lookup
20714 && (file_name
== file_table_last_lookup
->filename
20715 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20716 return file_table_last_lookup
;
20718 /* Didn't match the previous lookup, search the table. */
20719 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20720 htab_hash_string (file_name
), INSERT
);
20722 return (struct dwarf_file_data
*) *slot
;
20724 created
= ggc_alloc_dwarf_file_data ();
20725 created
->filename
= file_name
;
20726 created
->emitted_number
= 0;
20731 /* If the assembler will construct the file table, then translate the compiler
20732 internal file table number into the assembler file table number, and emit
20733 a .file directive if we haven't already emitted one yet. The file table
20734 numbers are different because we prune debug info for unused variables and
20735 types, which may include filenames. */
20738 maybe_emit_file (struct dwarf_file_data
* fd
)
20740 if (! fd
->emitted_number
)
20742 if (last_emitted_file
)
20743 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20745 fd
->emitted_number
= 1;
20746 last_emitted_file
= fd
;
20748 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20750 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20751 output_quoted_string (asm_out_file
,
20752 remap_debug_filename (fd
->filename
));
20753 fputc ('\n', asm_out_file
);
20757 return fd
->emitted_number
;
20760 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20761 That generation should happen after function debug info has been
20762 generated. The value of the attribute is the constant value of ARG. */
20765 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20767 die_arg_entry entry
;
20772 if (!tmpl_value_parm_die_table
)
20773 vec_alloc (tmpl_value_parm_die_table
, 32);
20777 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20780 /* Return TRUE if T is an instance of generic type, FALSE
20784 generic_type_p (tree t
)
20786 if (t
== NULL_TREE
|| !TYPE_P (t
))
20788 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20791 /* Schedule the generation of the generic parameter dies for the
20792 instance of generic type T. The proper generation itself is later
20793 done by gen_scheduled_generic_parms_dies. */
20796 schedule_generic_params_dies_gen (tree t
)
20798 if (!generic_type_p (t
))
20801 if (!generic_type_instances
)
20802 vec_alloc (generic_type_instances
, 256);
20804 vec_safe_push (generic_type_instances
, t
);
20807 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20808 by append_entry_to_tmpl_value_parm_die_table. This function must
20809 be called after function DIEs have been generated. */
20812 gen_remaining_tmpl_value_param_die_attribute (void)
20814 if (tmpl_value_parm_die_table
)
20819 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20820 tree_add_const_value_attribute (e
->die
, e
->arg
);
20824 /* Generate generic parameters DIEs for instances of generic types
20825 that have been previously scheduled by
20826 schedule_generic_params_dies_gen. This function must be called
20827 after all the types of the CU have been laid out. */
20830 gen_scheduled_generic_parms_dies (void)
20835 if (!generic_type_instances
)
20838 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20839 if (COMPLETE_TYPE_P (t
))
20840 gen_generic_params_dies (t
);
20844 /* Replace DW_AT_name for the decl with name. */
20847 dwarf2out_set_name (tree decl
, tree name
)
20853 die
= TYPE_SYMTAB_DIE (decl
);
20857 dname
= dwarf2_name (name
, 0);
20861 attr
= get_AT (die
, DW_AT_name
);
20864 struct indirect_string_node
*node
;
20866 node
= find_AT_string (dname
);
20867 /* replace the string. */
20868 attr
->dw_attr_val
.v
.val_str
= node
;
20872 add_name_attribute (die
, dname
);
20875 /* True if before or during processing of the first function being emitted. */
20876 static bool in_first_function_p
= true;
20877 /* True if loc_note during dwarf2out_var_location call might still be
20878 before first real instruction at address equal to .Ltext0. */
20879 static bool maybe_at_text_label_p
= true;
20880 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20881 static unsigned int first_loclabel_num_not_at_text_label
;
20883 /* Called by the final INSN scan whenever we see a var location. We
20884 use it to drop labels in the right places, and throw the location in
20885 our lookup table. */
20888 dwarf2out_var_location (rtx loc_note
)
20890 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20891 struct var_loc_node
*newloc
;
20892 rtx next_real
, next_note
;
20893 static const char *last_label
;
20894 static const char *last_postcall_label
;
20895 static bool last_in_cold_section_p
;
20896 static rtx expected_next_loc_note
;
20900 if (!NOTE_P (loc_note
))
20902 if (CALL_P (loc_note
))
20905 if (SIBLING_CALL_P (loc_note
))
20906 tail_call_site_count
++;
20911 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20912 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20915 /* Optimize processing a large consecutive sequence of location
20916 notes so we don't spend too much time in next_real_insn. If the
20917 next insn is another location note, remember the next_real_insn
20918 calculation for next time. */
20919 next_real
= cached_next_real_insn
;
20922 if (expected_next_loc_note
!= loc_note
)
20923 next_real
= NULL_RTX
;
20926 next_note
= NEXT_INSN (loc_note
);
20928 || INSN_DELETED_P (next_note
)
20929 || ! NOTE_P (next_note
)
20930 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20931 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20932 next_note
= NULL_RTX
;
20935 next_real
= next_real_insn (loc_note
);
20939 expected_next_loc_note
= next_note
;
20940 cached_next_real_insn
= next_real
;
20943 cached_next_real_insn
= NULL_RTX
;
20945 /* If there are no instructions which would be affected by this note,
20946 don't do anything. */
20948 && next_real
== NULL_RTX
20949 && !NOTE_DURING_CALL_P (loc_note
))
20952 if (next_real
== NULL_RTX
)
20953 next_real
= get_last_insn ();
20955 /* If there were any real insns between note we processed last time
20956 and this note (or if it is the first note), clear
20957 last_{,postcall_}label so that they are not reused this time. */
20958 if (last_var_location_insn
== NULL_RTX
20959 || last_var_location_insn
!= next_real
20960 || last_in_cold_section_p
!= in_cold_section_p
)
20963 last_postcall_label
= NULL
;
20968 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20969 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20970 NOTE_DURING_CALL_P (loc_note
)
20971 ? last_postcall_label
: last_label
);
20972 if (newloc
== NULL
)
20981 /* If there were no real insns between note we processed last time
20982 and this note, use the label we emitted last time. Otherwise
20983 create a new label and emit it. */
20984 if (last_label
== NULL
)
20986 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20987 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20989 last_label
= ggc_strdup (loclabel
);
20990 /* See if loclabel might be equal to .Ltext0. If yes,
20991 bump first_loclabel_num_not_at_text_label. */
20992 if (!have_multiple_function_sections
20993 && in_first_function_p
20994 && maybe_at_text_label_p
)
20996 static rtx last_start
;
20998 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
20999 if (insn
== last_start
)
21001 else if (!NONDEBUG_INSN_P (insn
))
21005 rtx body
= PATTERN (insn
);
21006 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21008 /* Inline asm could occupy zero bytes. */
21009 else if (GET_CODE (body
) == ASM_INPUT
21010 || asm_noperands (body
) >= 0)
21012 #ifdef HAVE_attr_length
21013 else if (get_attr_min_length (insn
) == 0)
21018 /* Assume insn has non-zero length. */
21019 maybe_at_text_label_p
= false;
21023 if (maybe_at_text_label_p
)
21025 last_start
= loc_note
;
21026 first_loclabel_num_not_at_text_label
= loclabel_num
;
21033 struct call_arg_loc_node
*ca_loc
21034 = ggc_alloc_cleared_call_arg_loc_node ();
21035 rtx prev
= prev_real_insn (loc_note
), x
;
21036 ca_loc
->call_arg_loc_note
= loc_note
;
21037 ca_loc
->next
= NULL
;
21038 ca_loc
->label
= last_label
;
21041 || (NONJUMP_INSN_P (prev
)
21042 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21043 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21044 if (!CALL_P (prev
))
21045 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21046 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21047 x
= get_call_rtx_from (PATTERN (prev
));
21050 x
= XEXP (XEXP (x
, 0), 0);
21051 if (GET_CODE (x
) == SYMBOL_REF
21052 && SYMBOL_REF_DECL (x
)
21053 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21054 ca_loc
->symbol_ref
= x
;
21056 ca_loc
->block
= insn_scope (prev
);
21057 if (call_arg_locations
)
21058 call_arg_loc_last
->next
= ca_loc
;
21060 call_arg_locations
= ca_loc
;
21061 call_arg_loc_last
= ca_loc
;
21063 else if (!NOTE_DURING_CALL_P (loc_note
))
21064 newloc
->label
= last_label
;
21067 if (!last_postcall_label
)
21069 sprintf (loclabel
, "%s-1", last_label
);
21070 last_postcall_label
= ggc_strdup (loclabel
);
21072 newloc
->label
= last_postcall_label
;
21075 last_var_location_insn
= next_real
;
21076 last_in_cold_section_p
= in_cold_section_p
;
21079 /* Note in one location list that text section has changed. */
21082 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21084 var_loc_list
*list
= (var_loc_list
*) *slot
;
21086 list
->last_before_switch
21087 = list
->last
->next
? list
->last
->next
: list
->last
;
21091 /* Note in all location lists that text section has changed. */
21094 var_location_switch_text_section (void)
21096 if (decl_loc_table
== NULL
)
21099 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21102 /* Create a new line number table. */
21104 static dw_line_info_table
*
21105 new_line_info_table (void)
21107 dw_line_info_table
*table
;
21109 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21110 table
->file_num
= 1;
21111 table
->line_num
= 1;
21112 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21117 /* Lookup the "current" table into which we emit line info, so
21118 that we don't have to do it for every source line. */
21121 set_cur_line_info_table (section
*sec
)
21123 dw_line_info_table
*table
;
21125 if (sec
== text_section
)
21126 table
= text_section_line_info
;
21127 else if (sec
== cold_text_section
)
21129 table
= cold_text_section_line_info
;
21132 cold_text_section_line_info
= table
= new_line_info_table ();
21133 table
->end_label
= cold_end_label
;
21138 const char *end_label
;
21140 if (flag_reorder_blocks_and_partition
)
21142 if (in_cold_section_p
)
21143 end_label
= crtl
->subsections
.cold_section_end_label
;
21145 end_label
= crtl
->subsections
.hot_section_end_label
;
21149 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21150 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21151 current_function_funcdef_no
);
21152 end_label
= ggc_strdup (label
);
21155 table
= new_line_info_table ();
21156 table
->end_label
= end_label
;
21158 vec_safe_push (separate_line_info
, table
);
21161 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21162 table
->is_stmt
= (cur_line_info_table
21163 ? cur_line_info_table
->is_stmt
21164 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21165 cur_line_info_table
= table
;
21169 /* We need to reset the locations at the beginning of each
21170 function. We can't do this in the end_function hook, because the
21171 declarations that use the locations won't have been output when
21172 that hook is called. Also compute have_multiple_function_sections here. */
21175 dwarf2out_begin_function (tree fun
)
21177 section
*sec
= function_section (fun
);
21179 if (sec
!= text_section
)
21180 have_multiple_function_sections
= true;
21182 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21184 gcc_assert (current_function_decl
== fun
);
21185 cold_text_section
= unlikely_text_section ();
21186 switch_to_section (cold_text_section
);
21187 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21188 switch_to_section (sec
);
21191 dwarf2out_note_section_used ();
21192 call_site_count
= 0;
21193 tail_call_site_count
= 0;
21195 set_cur_line_info_table (sec
);
21198 /* Helper function of dwarf2out_end_function, called only after emitting
21199 the very first function into assembly. Check if some .debug_loc range
21200 might end with a .LVL* label that could be equal to .Ltext0.
21201 In that case we must force using absolute addresses in .debug_loc ranges,
21202 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21203 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21205 Set have_multiple_function_sections to true in that case and
21206 terminate htab traversal. */
21209 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21211 var_loc_list
*entry
;
21212 struct var_loc_node
*node
;
21214 entry
= (var_loc_list
*) *slot
;
21215 node
= entry
->first
;
21216 if (node
&& node
->next
&& node
->next
->label
)
21219 const char *label
= node
->next
->label
;
21220 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21222 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21224 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21225 if (strcmp (label
, loclabel
) == 0)
21227 have_multiple_function_sections
= true;
21235 /* Hook called after emitting a function into assembly.
21236 This does something only for the very first function emitted. */
21239 dwarf2out_end_function (unsigned int)
21241 if (in_first_function_p
21242 && !have_multiple_function_sections
21243 && first_loclabel_num_not_at_text_label
21245 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21247 in_first_function_p
= false;
21248 maybe_at_text_label_p
= false;
21251 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21254 push_dw_line_info_entry (dw_line_info_table
*table
,
21255 enum dw_line_info_opcode opcode
, unsigned int val
)
21257 dw_line_info_entry e
;
21260 vec_safe_push (table
->entries
, e
);
21263 /* Output a label to mark the beginning of a source code line entry
21264 and record information relating to this source line, in
21265 'line_info_table' for later output of the .debug_line section. */
21266 /* ??? The discriminator parameter ought to be unsigned. */
21269 dwarf2out_source_line (unsigned int line
, const char *filename
,
21270 int discriminator
, bool is_stmt
)
21272 unsigned int file_num
;
21273 dw_line_info_table
*table
;
21275 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21278 /* The discriminator column was added in dwarf4. Simplify the below
21279 by simply removing it if we're not supposed to output it. */
21280 if (dwarf_version
< 4 && dwarf_strict
)
21283 table
= cur_line_info_table
;
21284 file_num
= maybe_emit_file (lookup_filename (filename
));
21286 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21287 the debugger has used the second (possibly duplicate) line number
21288 at the beginning of the function to mark the end of the prologue.
21289 We could eliminate any other duplicates within the function. For
21290 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21291 that second line number entry. */
21292 /* Recall that this end-of-prologue indication is *not* the same thing
21293 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21294 to which the hook corresponds, follows the last insn that was
21295 emitted by gen_prologue. What we need is to precede the first insn
21296 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21297 insn that corresponds to something the user wrote. These may be
21298 very different locations once scheduling is enabled. */
21300 if (0 && file_num
== table
->file_num
21301 && line
== table
->line_num
21302 && discriminator
== table
->discrim_num
21303 && is_stmt
== table
->is_stmt
)
21306 switch_to_section (current_function_section ());
21308 /* If requested, emit something human-readable. */
21309 if (flag_debug_asm
)
21310 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21312 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21314 /* Emit the .loc directive understood by GNU as. */
21315 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21316 file_num, line, is_stmt, discriminator */
21317 fputs ("\t.loc ", asm_out_file
);
21318 fprint_ul (asm_out_file
, file_num
);
21319 putc (' ', asm_out_file
);
21320 fprint_ul (asm_out_file
, line
);
21321 putc (' ', asm_out_file
);
21322 putc ('0', asm_out_file
);
21324 if (is_stmt
!= table
->is_stmt
)
21326 fputs (" is_stmt ", asm_out_file
);
21327 putc (is_stmt
? '1' : '0', asm_out_file
);
21329 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21331 gcc_assert (discriminator
> 0);
21332 fputs (" discriminator ", asm_out_file
);
21333 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21335 putc ('\n', asm_out_file
);
21339 unsigned int label_num
= ++line_info_label_num
;
21341 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21343 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21344 if (file_num
!= table
->file_num
)
21345 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21346 if (discriminator
!= table
->discrim_num
)
21347 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21348 if (is_stmt
!= table
->is_stmt
)
21349 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21350 push_dw_line_info_entry (table
, LI_set_line
, line
);
21353 table
->file_num
= file_num
;
21354 table
->line_num
= line
;
21355 table
->discrim_num
= discriminator
;
21356 table
->is_stmt
= is_stmt
;
21357 table
->in_use
= true;
21360 /* Record the beginning of a new source file. */
21363 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21365 if (flag_eliminate_dwarf2_dups
)
21367 /* Record the beginning of the file for break_out_includes. */
21368 dw_die_ref bincl_die
;
21370 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21371 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21374 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21377 e
.code
= DW_MACINFO_start_file
;
21379 e
.info
= ggc_strdup (filename
);
21380 vec_safe_push (macinfo_table
, e
);
21384 /* Record the end of a source file. */
21387 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21389 if (flag_eliminate_dwarf2_dups
)
21390 /* Record the end of the file for break_out_includes. */
21391 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21393 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21396 e
.code
= DW_MACINFO_end_file
;
21399 vec_safe_push (macinfo_table
, e
);
21403 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21404 the tail part of the directive line, i.e. the part which is past the
21405 initial whitespace, #, whitespace, directive-name, whitespace part. */
21408 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21409 const char *buffer ATTRIBUTE_UNUSED
)
21411 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21414 /* Insert a dummy first entry to be able to optimize the whole
21415 predefined macro block using DW_MACRO_GNU_transparent_include. */
21416 if (macinfo_table
->is_empty () && lineno
<= 1)
21421 vec_safe_push (macinfo_table
, e
);
21423 e
.code
= DW_MACINFO_define
;
21425 e
.info
= ggc_strdup (buffer
);
21426 vec_safe_push (macinfo_table
, e
);
21430 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21431 the tail part of the directive line, i.e. the part which is past the
21432 initial whitespace, #, whitespace, directive-name, whitespace part. */
21435 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21436 const char *buffer ATTRIBUTE_UNUSED
)
21438 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21441 /* Insert a dummy first entry to be able to optimize the whole
21442 predefined macro block using DW_MACRO_GNU_transparent_include. */
21443 if (macinfo_table
->is_empty () && lineno
<= 1)
21448 vec_safe_push (macinfo_table
, e
);
21450 e
.code
= DW_MACINFO_undef
;
21452 e
.info
= ggc_strdup (buffer
);
21453 vec_safe_push (macinfo_table
, e
);
21457 /* Helpers to manipulate hash table of CUs. */
21459 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21461 typedef macinfo_entry value_type
;
21462 typedef macinfo_entry compare_type
;
21463 static inline hashval_t
hash (const value_type
*);
21464 static inline bool equal (const value_type
*, const compare_type
*);
21468 macinfo_entry_hasher::hash (const value_type
*entry
)
21470 return htab_hash_string (entry
->info
);
21474 macinfo_entry_hasher::equal (const value_type
*entry1
,
21475 const compare_type
*entry2
)
21477 return !strcmp (entry1
->info
, entry2
->info
);
21480 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21482 /* Output a single .debug_macinfo entry. */
21485 output_macinfo_op (macinfo_entry
*ref
)
21489 struct indirect_string_node
*node
;
21490 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21491 struct dwarf_file_data
*fd
;
21495 case DW_MACINFO_start_file
:
21496 fd
= lookup_filename (ref
->info
);
21497 file_num
= maybe_emit_file (fd
);
21498 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21499 dw2_asm_output_data_uleb128 (ref
->lineno
,
21500 "Included from line number %lu",
21501 (unsigned long) ref
->lineno
);
21502 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21504 case DW_MACINFO_end_file
:
21505 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21507 case DW_MACINFO_define
:
21508 case DW_MACINFO_undef
:
21509 len
= strlen (ref
->info
) + 1;
21511 && len
> DWARF_OFFSET_SIZE
21512 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21513 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21515 ref
->code
= ref
->code
== DW_MACINFO_define
21516 ? DW_MACRO_GNU_define_indirect
21517 : DW_MACRO_GNU_undef_indirect
;
21518 output_macinfo_op (ref
);
21521 dw2_asm_output_data (1, ref
->code
,
21522 ref
->code
== DW_MACINFO_define
21523 ? "Define macro" : "Undefine macro");
21524 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21525 (unsigned long) ref
->lineno
);
21526 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21528 case DW_MACRO_GNU_define_indirect
:
21529 case DW_MACRO_GNU_undef_indirect
:
21530 node
= find_AT_string (ref
->info
);
21532 && ((node
->form
== DW_FORM_strp
)
21533 || (node
->form
== DW_FORM_GNU_str_index
)));
21534 dw2_asm_output_data (1, ref
->code
,
21535 ref
->code
== DW_MACRO_GNU_define_indirect
21536 ? "Define macro indirect"
21537 : "Undefine macro indirect");
21538 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21539 (unsigned long) ref
->lineno
);
21540 if (node
->form
== DW_FORM_strp
)
21541 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21542 debug_str_section
, "The macro: \"%s\"",
21545 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21548 case DW_MACRO_GNU_transparent_include
:
21549 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21550 ASM_GENERATE_INTERNAL_LABEL (label
,
21551 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21552 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21555 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21556 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21561 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21562 other compilation unit .debug_macinfo sections. IDX is the first
21563 index of a define/undef, return the number of ops that should be
21564 emitted in a comdat .debug_macinfo section and emit
21565 a DW_MACRO_GNU_transparent_include entry referencing it.
21566 If the define/undef entry should be emitted normally, return 0. */
21569 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21570 macinfo_hash_type
*macinfo_htab
)
21572 macinfo_entry
*first
, *second
, *cur
, *inc
;
21573 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21574 unsigned char checksum
[16];
21575 struct md5_ctx ctx
;
21576 char *grp_name
, *tail
;
21578 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21579 macinfo_entry
**slot
;
21581 first
= &(*macinfo_table
)[idx
];
21582 second
= &(*macinfo_table
)[idx
+ 1];
21584 /* Optimize only if there are at least two consecutive define/undef ops,
21585 and either all of them are before first DW_MACINFO_start_file
21586 with lineno {0,1} (i.e. predefined macro block), or all of them are
21587 in some included header file. */
21588 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21590 if (vec_safe_is_empty (files
))
21592 if (first
->lineno
> 1 || second
->lineno
> 1)
21595 else if (first
->lineno
== 0)
21598 /* Find the last define/undef entry that can be grouped together
21599 with first and at the same time compute md5 checksum of their
21600 codes, linenumbers and strings. */
21601 md5_init_ctx (&ctx
);
21602 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21603 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21605 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21609 unsigned char code
= cur
->code
;
21610 md5_process_bytes (&code
, 1, &ctx
);
21611 checksum_uleb128 (cur
->lineno
, &ctx
);
21612 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21614 md5_finish_ctx (&ctx
, checksum
);
21617 /* From the containing include filename (if any) pick up just
21618 usable characters from its basename. */
21619 if (vec_safe_is_empty (files
))
21622 base
= lbasename (files
->last ().info
);
21623 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21624 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21625 encoded_filename_len
++;
21626 /* Count . at the end. */
21627 if (encoded_filename_len
)
21628 encoded_filename_len
++;
21630 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21631 linebuf_len
= strlen (linebuf
);
21633 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21634 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21636 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21637 tail
= grp_name
+ 4;
21638 if (encoded_filename_len
)
21640 for (i
= 0; base
[i
]; i
++)
21641 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21645 memcpy (tail
, linebuf
, linebuf_len
);
21646 tail
+= linebuf_len
;
21648 for (i
= 0; i
< 16; i
++)
21649 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21651 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21652 in the empty vector entry before the first define/undef. */
21653 inc
= &(*macinfo_table
)[idx
- 1];
21654 inc
->code
= DW_MACRO_GNU_transparent_include
;
21656 inc
->info
= ggc_strdup (grp_name
);
21657 if (!macinfo_htab
->is_created ())
21658 macinfo_htab
->create (10);
21659 /* Avoid emitting duplicates. */
21660 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21665 /* If such an entry has been used before, just emit
21666 a DW_MACRO_GNU_transparent_include op. */
21668 output_macinfo_op (inc
);
21669 /* And clear all macinfo_entry in the range to avoid emitting them
21670 in the second pass. */
21671 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21680 inc
->lineno
= macinfo_htab
->elements ();
21681 output_macinfo_op (inc
);
21686 /* Save any strings needed by the macinfo table in the debug str
21687 table. All strings must be collected into the table by the time
21688 index_string is called. */
21691 save_macinfo_strings (void)
21695 macinfo_entry
*ref
;
21697 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21701 /* Match the logic in output_macinfo_op to decide on
21702 indirect strings. */
21703 case DW_MACINFO_define
:
21704 case DW_MACINFO_undef
:
21705 len
= strlen (ref
->info
) + 1;
21707 && len
> DWARF_OFFSET_SIZE
21708 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21709 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21710 set_indirect_string (find_AT_string (ref
->info
));
21712 case DW_MACRO_GNU_define_indirect
:
21713 case DW_MACRO_GNU_undef_indirect
:
21714 set_indirect_string (find_AT_string (ref
->info
));
21722 /* Output macinfo section(s). */
21725 output_macinfo (void)
21728 unsigned long length
= vec_safe_length (macinfo_table
);
21729 macinfo_entry
*ref
;
21730 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21731 macinfo_hash_type macinfo_htab
;
21736 /* output_macinfo* uses these interchangeably. */
21737 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21738 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21739 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21740 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21742 /* For .debug_macro emit the section header. */
21745 dw2_asm_output_data (2, 4, "DWARF macro version number");
21746 if (DWARF_OFFSET_SIZE
== 8)
21747 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21749 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21750 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21751 (!dwarf_split_debug_info
? debug_line_section_label
21752 : debug_skeleton_line_section_label
),
21753 debug_line_section
, NULL
);
21756 /* In the first loop, it emits the primary .debug_macinfo section
21757 and after each emitted op the macinfo_entry is cleared.
21758 If a longer range of define/undef ops can be optimized using
21759 DW_MACRO_GNU_transparent_include, the
21760 DW_MACRO_GNU_transparent_include op is emitted and kept in
21761 the vector before the first define/undef in the range and the
21762 whole range of define/undef ops is not emitted and kept. */
21763 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21767 case DW_MACINFO_start_file
:
21768 vec_safe_push (files
, *ref
);
21770 case DW_MACINFO_end_file
:
21771 if (!vec_safe_is_empty (files
))
21774 case DW_MACINFO_define
:
21775 case DW_MACINFO_undef
:
21777 && HAVE_COMDAT_GROUP
21778 && vec_safe_length (files
) != 1
21781 && (*macinfo_table
)[i
- 1].code
== 0)
21783 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21792 /* A dummy entry may be inserted at the beginning to be able
21793 to optimize the whole block of predefined macros. */
21799 output_macinfo_op (ref
);
21804 if (!macinfo_htab
.is_created ())
21807 macinfo_htab
.dispose ();
21809 /* If any DW_MACRO_GNU_transparent_include were used, on those
21810 DW_MACRO_GNU_transparent_include entries terminate the
21811 current chain and switch to a new comdat .debug_macinfo
21812 section and emit the define/undef entries within it. */
21813 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21818 case DW_MACRO_GNU_transparent_include
:
21820 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21821 tree comdat_key
= get_identifier (ref
->info
);
21822 /* Terminate the previous .debug_macinfo section. */
21823 dw2_asm_output_data (1, 0, "End compilation unit");
21824 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21826 | SECTION_LINKONCE
,
21828 ASM_GENERATE_INTERNAL_LABEL (label
,
21829 DEBUG_MACRO_SECTION_LABEL
,
21831 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21834 dw2_asm_output_data (2, 4, "DWARF macro version number");
21835 if (DWARF_OFFSET_SIZE
== 8)
21836 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21838 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21841 case DW_MACINFO_define
:
21842 case DW_MACINFO_undef
:
21843 output_macinfo_op (ref
);
21848 gcc_unreachable ();
21852 /* Set up for Dwarf output at the start of compilation. */
21855 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21857 /* Allocate the file_table. */
21858 file_table
= htab_create_ggc (50, file_table_hash
,
21859 file_table_eq
, NULL
);
21861 /* Allocate the decl_die_table. */
21862 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21863 decl_die_table_eq
, NULL
);
21865 /* Allocate the decl_loc_table. */
21866 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21867 decl_loc_table_eq
, NULL
);
21869 /* Allocate the cached_dw_loc_list_table. */
21870 cached_dw_loc_list_table
21871 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21872 cached_dw_loc_list_table_eq
, NULL
);
21874 /* Allocate the initial hunk of the decl_scope_table. */
21875 vec_alloc (decl_scope_table
, 256);
21877 /* Allocate the initial hunk of the abbrev_die_table. */
21878 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21879 (ABBREV_DIE_TABLE_INCREMENT
);
21880 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21881 /* Zero-th entry is allocated, but unused. */
21882 abbrev_die_table_in_use
= 1;
21884 /* Allocate the pubtypes and pubnames vectors. */
21885 vec_alloc (pubname_table
, 32);
21886 vec_alloc (pubtype_table
, 32);
21888 vec_alloc (incomplete_types
, 64);
21890 vec_alloc (used_rtx_array
, 32);
21892 if (!dwarf_split_debug_info
)
21894 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21895 SECTION_DEBUG
, NULL
);
21896 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21897 SECTION_DEBUG
, NULL
);
21898 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21899 SECTION_DEBUG
, NULL
);
21903 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21904 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21905 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21906 SECTION_DEBUG
| SECTION_EXCLUDE
,
21908 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21909 SECTION_DEBUG
, NULL
);
21910 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21911 SECTION_DEBUG
, NULL
);
21912 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21913 SECTION_DEBUG
, NULL
);
21914 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21915 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21917 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21918 the main .o, but the skeleton_line goes into the split off dwo. */
21919 debug_skeleton_line_section
21920 = get_section (DEBUG_DWO_LINE_SECTION
,
21921 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21922 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21923 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21924 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21925 SECTION_DEBUG
| SECTION_EXCLUDE
,
21927 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21928 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21929 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21930 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21931 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
21932 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
21934 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21935 SECTION_DEBUG
, NULL
);
21936 debug_macinfo_section
= get_section (dwarf_strict
21937 ? DEBUG_MACINFO_SECTION
21938 : DEBUG_MACRO_SECTION
,
21939 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21940 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21941 SECTION_DEBUG
, NULL
);
21942 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21943 SECTION_DEBUG
, NULL
);
21944 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21945 SECTION_DEBUG
, NULL
);
21946 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21947 DEBUG_STR_SECTION_FLAGS
, NULL
);
21948 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21949 SECTION_DEBUG
, NULL
);
21950 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21951 SECTION_DEBUG
, NULL
);
21953 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21954 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21955 DEBUG_ABBREV_SECTION_LABEL
, 0);
21956 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21957 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21958 COLD_TEXT_SECTION_LABEL
, 0);
21959 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21961 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21962 DEBUG_INFO_SECTION_LABEL
, 0);
21963 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21964 DEBUG_LINE_SECTION_LABEL
, 0);
21965 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21966 DEBUG_RANGES_SECTION_LABEL
, 0);
21967 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21968 DEBUG_ADDR_SECTION_LABEL
, 0);
21969 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21971 ? DEBUG_MACINFO_SECTION_LABEL
21972 : DEBUG_MACRO_SECTION_LABEL
, 0);
21973 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21975 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21976 vec_alloc (macinfo_table
, 64);
21978 switch_to_section (text_section
);
21979 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21981 /* Make sure the line number table for .text always exists. */
21982 text_section_line_info
= new_line_info_table ();
21983 text_section_line_info
->end_label
= text_end_label
;
21986 /* Called before compile () starts outputtting functions, variables
21987 and toplevel asms into assembly. */
21990 dwarf2out_assembly_start (void)
21992 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21993 && dwarf2out_do_cfi_asm ()
21994 && (!(flag_unwind_tables
|| flag_exceptions
)
21995 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21996 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21999 /* A helper function for dwarf2out_finish called through
22000 htab_traverse. Assign a string its index. All strings must be
22001 collected into the table by the time index_string is called,
22002 because the indexing code relies on htab_traverse to traverse nodes
22003 in the same order for each run. */
22006 index_string (void **h
, void *v
)
22008 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22009 unsigned int *index
= (unsigned int *) v
;
22011 find_string_form (node
);
22012 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22014 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22015 node
->index
= *index
;
22021 /* A helper function for output_indirect_strings called through
22022 htab_traverse. Output the offset to a string and update the
22026 output_index_string_offset (void **h
, void *v
)
22028 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22029 unsigned int *offset
= (unsigned int *) v
;
22031 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22033 /* Assert that this node has been assigned an index. */
22034 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22035 && node
->index
!= NOT_INDEXED
);
22036 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22037 "indexed string 0x%x: %s", node
->index
, node
->str
);
22038 *offset
+= strlen (node
->str
) + 1;
22043 /* A helper function for dwarf2out_finish called through
22044 htab_traverse. Output the indexed string. */
22047 output_index_string (void **h
, void *v
)
22049 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22050 unsigned int *cur_idx
= (unsigned int *) v
;
22052 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22054 /* Assert that the strings are output in the same order as their
22055 indexes were assigned. */
22056 gcc_assert (*cur_idx
== node
->index
);
22057 assemble_string (node
->str
, strlen (node
->str
) + 1);
22063 /* A helper function for dwarf2out_finish called through
22064 htab_traverse. Emit one queued .debug_str string. */
22067 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22069 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22071 node
->form
= find_string_form (node
);
22072 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22074 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22075 assemble_string (node
->str
, strlen (node
->str
) + 1);
22081 /* Output the indexed string table. */
22084 output_indirect_strings (void)
22086 switch_to_section (debug_str_section
);
22087 if (!dwarf_split_debug_info
)
22088 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22091 unsigned int offset
= 0;
22092 unsigned int cur_idx
= 0;
22094 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22096 switch_to_section (debug_str_offsets_section
);
22097 htab_traverse_noresize (debug_str_hash
,
22098 output_index_string_offset
,
22100 switch_to_section (debug_str_dwo_section
);
22101 htab_traverse_noresize (debug_str_hash
,
22102 output_index_string
,
22107 /* Callback for htab_traverse to assign an index to an entry in the
22108 table, and to write that entry to the .debug_addr section. */
22111 output_addr_table_entry (void **slot
, void *data
)
22113 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22114 unsigned int *cur_index
= (unsigned int *)data
;
22116 if (entry
->refcount
== 0)
22118 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22119 || entry
->index
== NOT_INDEXED
);
22123 gcc_assert (entry
->index
== *cur_index
);
22126 switch (entry
->kind
)
22129 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22130 "0x%x", entry
->index
);
22132 case ate_kind_rtx_dtprel
:
22133 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22134 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22137 fputc ('\n', asm_out_file
);
22139 case ate_kind_label
:
22140 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22141 "0x%x", entry
->index
);
22144 gcc_unreachable ();
22149 /* Produce the .debug_addr section. */
22152 output_addr_table (void)
22154 unsigned int index
= 0;
22155 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22158 switch_to_section (debug_addr_section
);
22159 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22162 #if ENABLE_ASSERT_CHECKING
22163 /* Verify that all marks are clear. */
22166 verify_marks_clear (dw_die_ref die
)
22170 gcc_assert (! die
->die_mark
);
22171 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22173 #endif /* ENABLE_ASSERT_CHECKING */
22175 /* Clear the marks for a die and its children.
22176 Be cool if the mark isn't set. */
22179 prune_unmark_dies (dw_die_ref die
)
22185 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22188 /* Given DIE that we're marking as used, find any other dies
22189 it references as attributes and mark them as used. */
22192 prune_unused_types_walk_attribs (dw_die_ref die
)
22197 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22199 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22201 /* A reference to another DIE.
22202 Make sure that it will get emitted.
22203 If it was broken out into a comdat group, don't follow it. */
22204 if (! AT_ref (a
)->comdat_type_p
22205 || a
->dw_attr
== DW_AT_specification
)
22206 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22208 /* Set the string's refcount to 0 so that prune_unused_types_mark
22209 accounts properly for it. */
22210 if (AT_class (a
) == dw_val_class_str
)
22211 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22215 /* Mark the generic parameters and arguments children DIEs of DIE. */
22218 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22222 if (die
== NULL
|| die
->die_child
== NULL
)
22224 c
= die
->die_child
;
22227 if (is_template_parameter (c
))
22228 prune_unused_types_mark (c
, 1);
22230 } while (c
&& c
!= die
->die_child
);
22233 /* Mark DIE as being used. If DOKIDS is true, then walk down
22234 to DIE's children. */
22237 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22241 if (die
->die_mark
== 0)
22243 /* We haven't done this node yet. Mark it as used. */
22245 /* If this is the DIE of a generic type instantiation,
22246 mark the children DIEs that describe its generic parms and
22248 prune_unused_types_mark_generic_parms_dies (die
);
22250 /* We also have to mark its parents as used.
22251 (But we don't want to mark our parent's kids due to this,
22252 unless it is a class.) */
22253 if (die
->die_parent
)
22254 prune_unused_types_mark (die
->die_parent
,
22255 class_scope_p (die
->die_parent
));
22257 /* Mark any referenced nodes. */
22258 prune_unused_types_walk_attribs (die
);
22260 /* If this node is a specification,
22261 also mark the definition, if it exists. */
22262 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22263 prune_unused_types_mark (die
->die_definition
, 1);
22266 if (dokids
&& die
->die_mark
!= 2)
22268 /* We need to walk the children, but haven't done so yet.
22269 Remember that we've walked the kids. */
22272 /* If this is an array type, we need to make sure our
22273 kids get marked, even if they're types. If we're
22274 breaking out types into comdat sections, do this
22275 for all type definitions. */
22276 if (die
->die_tag
== DW_TAG_array_type
22277 || (use_debug_types
22278 && is_type_die (die
) && ! is_declaration_die (die
)))
22279 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22281 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22285 /* For local classes, look if any static member functions were emitted
22286 and if so, mark them. */
22289 prune_unused_types_walk_local_classes (dw_die_ref die
)
22293 if (die
->die_mark
== 2)
22296 switch (die
->die_tag
)
22298 case DW_TAG_structure_type
:
22299 case DW_TAG_union_type
:
22300 case DW_TAG_class_type
:
22303 case DW_TAG_subprogram
:
22304 if (!get_AT_flag (die
, DW_AT_declaration
)
22305 || die
->die_definition
!= NULL
)
22306 prune_unused_types_mark (die
, 1);
22313 /* Mark children. */
22314 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22317 /* Walk the tree DIE and mark types that we actually use. */
22320 prune_unused_types_walk (dw_die_ref die
)
22324 /* Don't do anything if this node is already marked and
22325 children have been marked as well. */
22326 if (die
->die_mark
== 2)
22329 switch (die
->die_tag
)
22331 case DW_TAG_structure_type
:
22332 case DW_TAG_union_type
:
22333 case DW_TAG_class_type
:
22334 if (die
->die_perennial_p
)
22337 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22338 if (c
->die_tag
== DW_TAG_subprogram
)
22341 /* Finding used static member functions inside of classes
22342 is needed just for local classes, because for other classes
22343 static member function DIEs with DW_AT_specification
22344 are emitted outside of the DW_TAG_*_type. If we ever change
22345 it, we'd need to call this even for non-local classes. */
22347 prune_unused_types_walk_local_classes (die
);
22349 /* It's a type node --- don't mark it. */
22352 case DW_TAG_const_type
:
22353 case DW_TAG_packed_type
:
22354 case DW_TAG_pointer_type
:
22355 case DW_TAG_reference_type
:
22356 case DW_TAG_rvalue_reference_type
:
22357 case DW_TAG_volatile_type
:
22358 case DW_TAG_typedef
:
22359 case DW_TAG_array_type
:
22360 case DW_TAG_interface_type
:
22361 case DW_TAG_friend
:
22362 case DW_TAG_variant_part
:
22363 case DW_TAG_enumeration_type
:
22364 case DW_TAG_subroutine_type
:
22365 case DW_TAG_string_type
:
22366 case DW_TAG_set_type
:
22367 case DW_TAG_subrange_type
:
22368 case DW_TAG_ptr_to_member_type
:
22369 case DW_TAG_file_type
:
22370 if (die
->die_perennial_p
)
22373 /* It's a type node --- don't mark it. */
22377 /* Mark everything else. */
22381 if (die
->die_mark
== 0)
22385 /* Now, mark any dies referenced from here. */
22386 prune_unused_types_walk_attribs (die
);
22391 /* Mark children. */
22392 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22395 /* Increment the string counts on strings referred to from DIE's
22399 prune_unused_types_update_strings (dw_die_ref die
)
22404 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22405 if (AT_class (a
) == dw_val_class_str
)
22407 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22409 /* Avoid unnecessarily putting strings that are used less than
22410 twice in the hash table. */
22412 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22415 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22416 htab_hash_string (s
->str
),
22418 gcc_assert (*slot
== NULL
);
22424 /* Remove from the tree DIE any dies that aren't marked. */
22427 prune_unused_types_prune (dw_die_ref die
)
22431 gcc_assert (die
->die_mark
);
22432 prune_unused_types_update_strings (die
);
22434 if (! die
->die_child
)
22437 c
= die
->die_child
;
22439 dw_die_ref prev
= c
;
22440 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22441 if (c
== die
->die_child
)
22443 /* No marked children between 'prev' and the end of the list. */
22445 /* No marked children at all. */
22446 die
->die_child
= NULL
;
22449 prev
->die_sib
= c
->die_sib
;
22450 die
->die_child
= prev
;
22455 if (c
!= prev
->die_sib
)
22457 prune_unused_types_prune (c
);
22458 } while (c
!= die
->die_child
);
22461 /* Remove dies representing declarations that we never use. */
22464 prune_unused_types (void)
22467 limbo_die_node
*node
;
22468 comdat_type_node
*ctnode
;
22470 dw_die_ref base_type
;
22472 #if ENABLE_ASSERT_CHECKING
22473 /* All the marks should already be clear. */
22474 verify_marks_clear (comp_unit_die ());
22475 for (node
= limbo_die_list
; node
; node
= node
->next
)
22476 verify_marks_clear (node
->die
);
22477 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22478 verify_marks_clear (ctnode
->root_die
);
22479 #endif /* ENABLE_ASSERT_CHECKING */
22481 /* Mark types that are used in global variables. */
22482 premark_types_used_by_global_vars ();
22484 /* Set the mark on nodes that are actually used. */
22485 prune_unused_types_walk (comp_unit_die ());
22486 for (node
= limbo_die_list
; node
; node
= node
->next
)
22487 prune_unused_types_walk (node
->die
);
22488 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22490 prune_unused_types_walk (ctnode
->root_die
);
22491 prune_unused_types_mark (ctnode
->type_die
, 1);
22494 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22495 are unusual in that they are pubnames that are the children of pubtypes.
22496 They should only be marked via their parent DW_TAG_enumeration_type die,
22497 not as roots in themselves. */
22498 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22499 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22500 prune_unused_types_mark (pub
->die
, 1);
22501 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22502 prune_unused_types_mark (base_type
, 1);
22504 if (debug_str_hash
)
22505 htab_empty (debug_str_hash
);
22506 if (skeleton_debug_str_hash
)
22507 htab_empty (skeleton_debug_str_hash
);
22508 prune_unused_types_prune (comp_unit_die ());
22509 for (node
= limbo_die_list
; node
; node
= node
->next
)
22510 prune_unused_types_prune (node
->die
);
22511 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22512 prune_unused_types_prune (ctnode
->root_die
);
22514 /* Leave the marks clear. */
22515 prune_unmark_dies (comp_unit_die ());
22516 for (node
= limbo_die_list
; node
; node
= node
->next
)
22517 prune_unmark_dies (node
->die
);
22518 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22519 prune_unmark_dies (ctnode
->root_die
);
22522 /* Set the parameter to true if there are any relative pathnames in
22525 file_table_relative_p (void ** slot
, void *param
)
22527 bool *p
= (bool *) param
;
22528 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22529 if (!IS_ABSOLUTE_PATH (d
->filename
))
22537 /* Helpers to manipulate hash table of comdat type units. */
22539 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22541 typedef comdat_type_node value_type
;
22542 typedef comdat_type_node compare_type
;
22543 static inline hashval_t
hash (const value_type
*);
22544 static inline bool equal (const value_type
*, const compare_type
*);
22548 comdat_type_hasher::hash (const value_type
*type_node
)
22551 memcpy (&h
, type_node
->signature
, sizeof (h
));
22556 comdat_type_hasher::equal (const value_type
*type_node_1
,
22557 const compare_type
*type_node_2
)
22559 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22560 DWARF_TYPE_SIGNATURE_SIZE
));
22563 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22564 to the location it would have been added, should we know its
22565 DECL_ASSEMBLER_NAME when we added other attributes. This will
22566 probably improve compactness of debug info, removing equivalent
22567 abbrevs, and hide any differences caused by deferring the
22568 computation of the assembler name, triggered by e.g. PCH. */
22571 move_linkage_attr (dw_die_ref die
)
22573 unsigned ix
= vec_safe_length (die
->die_attr
);
22574 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22576 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22577 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22581 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22583 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22587 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22589 die
->die_attr
->pop ();
22590 die
->die_attr
->quick_insert (ix
, linkage
);
22594 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22595 referenced from typed stack ops and count how often they are used. */
22598 mark_base_types (dw_loc_descr_ref loc
)
22600 dw_die_ref base_type
= NULL
;
22602 for (; loc
; loc
= loc
->dw_loc_next
)
22604 switch (loc
->dw_loc_opc
)
22606 case DW_OP_GNU_regval_type
:
22607 case DW_OP_GNU_deref_type
:
22608 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22610 case DW_OP_GNU_convert
:
22611 case DW_OP_GNU_reinterpret
:
22612 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22615 case DW_OP_GNU_const_type
:
22616 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22618 case DW_OP_GNU_entry_value
:
22619 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22624 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22625 if (base_type
->die_mark
)
22626 base_type
->die_mark
++;
22629 base_types
.safe_push (base_type
);
22630 base_type
->die_mark
= 1;
22635 /* Comparison function for sorting marked base types. */
22638 base_type_cmp (const void *x
, const void *y
)
22640 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22641 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22642 unsigned int byte_size1
, byte_size2
;
22643 unsigned int encoding1
, encoding2
;
22644 if (dx
->die_mark
> dy
->die_mark
)
22646 if (dx
->die_mark
< dy
->die_mark
)
22648 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22649 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22650 if (byte_size1
< byte_size2
)
22652 if (byte_size1
> byte_size2
)
22654 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22655 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22656 if (encoding1
< encoding2
)
22658 if (encoding1
> encoding2
)
22663 /* Move base types marked by mark_base_types as early as possible
22664 in the CU, sorted by decreasing usage count both to make the
22665 uleb128 references as small as possible and to make sure they
22666 will have die_offset already computed by calc_die_sizes when
22667 sizes of typed stack loc ops is computed. */
22670 move_marked_base_types (void)
22673 dw_die_ref base_type
, die
, c
;
22675 if (base_types
.is_empty ())
22678 /* Sort by decreasing usage count, they will be added again in that
22680 base_types
.qsort (base_type_cmp
);
22681 die
= comp_unit_die ();
22682 c
= die
->die_child
;
22685 dw_die_ref prev
= c
;
22687 while (c
->die_mark
)
22689 remove_child_with_prev (c
, prev
);
22690 /* As base types got marked, there must be at least
22691 one node other than DW_TAG_base_type. */
22692 gcc_assert (c
!= c
->die_sib
);
22696 while (c
!= die
->die_child
);
22697 gcc_assert (die
->die_child
);
22698 c
= die
->die_child
;
22699 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22701 base_type
->die_mark
= 0;
22702 base_type
->die_sib
= c
->die_sib
;
22703 c
->die_sib
= base_type
;
22708 /* Helper function for resolve_addr, attempt to resolve
22709 one CONST_STRING, return non-zero if not successful. Similarly verify that
22710 SYMBOL_REFs refer to variables emitted in the current CU. */
22713 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22717 if (GET_CODE (rtl
) == CONST_STRING
)
22719 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22720 tree t
= build_string (len
, XSTR (rtl
, 0));
22721 tree tlen
= size_int (len
- 1);
22723 = build_array_type (char_type_node
, build_index_type (tlen
));
22724 rtl
= lookup_constant_def (t
);
22725 if (!rtl
|| !MEM_P (rtl
))
22727 rtl
= XEXP (rtl
, 0);
22728 if (GET_CODE (rtl
) == SYMBOL_REF
22729 && SYMBOL_REF_DECL (rtl
)
22730 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22732 vec_safe_push (used_rtx_array
, rtl
);
22737 if (GET_CODE (rtl
) == SYMBOL_REF
22738 && SYMBOL_REF_DECL (rtl
))
22740 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22742 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22745 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22749 if (GET_CODE (rtl
) == CONST
22750 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22756 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22757 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22758 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22761 string_cst_pool_decl (tree t
)
22763 rtx rtl
= output_constant_def (t
, 1);
22764 unsigned char *array
;
22765 dw_loc_descr_ref l
;
22770 if (!rtl
|| !MEM_P (rtl
))
22772 rtl
= XEXP (rtl
, 0);
22773 if (GET_CODE (rtl
) != SYMBOL_REF
22774 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22777 decl
= SYMBOL_REF_DECL (rtl
);
22778 if (!lookup_decl_die (decl
))
22780 len
= TREE_STRING_LENGTH (t
);
22781 vec_safe_push (used_rtx_array
, rtl
);
22782 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22783 array
= (unsigned char *) ggc_alloc_atomic (len
);
22784 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22785 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22786 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22787 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22788 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22789 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22790 add_AT_loc (ref
, DW_AT_location
, l
);
22791 equate_decl_number_to_die (decl
, ref
);
22796 /* Helper function of resolve_addr_in_expr. LOC is
22797 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22798 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22799 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22800 with DW_OP_GNU_implicit_pointer if possible
22801 and return true, if unsuccessful, return false. */
22804 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22806 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22807 HOST_WIDE_INT offset
= 0;
22808 dw_die_ref ref
= NULL
;
22811 if (GET_CODE (rtl
) == CONST
22812 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22813 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22815 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22816 rtl
= XEXP (XEXP (rtl
, 0), 0);
22818 if (GET_CODE (rtl
) == CONST_STRING
)
22820 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22821 tree t
= build_string (len
, XSTR (rtl
, 0));
22822 tree tlen
= size_int (len
- 1);
22825 = build_array_type (char_type_node
, build_index_type (tlen
));
22826 rtl
= string_cst_pool_decl (t
);
22830 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22832 decl
= SYMBOL_REF_DECL (rtl
);
22833 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22835 ref
= lookup_decl_die (decl
);
22836 if (ref
&& (get_AT (ref
, DW_AT_location
)
22837 || get_AT (ref
, DW_AT_const_value
)))
22839 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22840 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22841 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22842 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22843 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22844 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22845 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22853 /* Helper function for resolve_addr, handle one location
22854 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22855 the location list couldn't be resolved. */
22858 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22860 dw_loc_descr_ref keep
= NULL
;
22861 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22862 switch (loc
->dw_loc_opc
)
22865 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22868 || prev
->dw_loc_opc
== DW_OP_piece
22869 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22870 && loc
->dw_loc_next
22871 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22873 && optimize_one_addr_into_implicit_ptr (loc
))
22878 case DW_OP_GNU_addr_index
:
22879 case DW_OP_GNU_const_index
:
22880 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22881 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22882 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22886 case DW_OP_const4u
:
22887 case DW_OP_const8u
:
22889 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22892 case DW_OP_plus_uconst
:
22893 if (size_of_loc_descr (loc
)
22894 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22896 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22898 dw_loc_descr_ref repl
22899 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22900 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22901 add_loc_descr (&repl
, loc
->dw_loc_next
);
22905 case DW_OP_implicit_value
:
22906 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22907 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22910 case DW_OP_GNU_implicit_pointer
:
22911 case DW_OP_GNU_parameter_ref
:
22912 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22915 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22918 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22919 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22920 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22923 case DW_OP_GNU_const_type
:
22924 case DW_OP_GNU_regval_type
:
22925 case DW_OP_GNU_deref_type
:
22926 case DW_OP_GNU_convert
:
22927 case DW_OP_GNU_reinterpret
:
22928 while (loc
->dw_loc_next
22929 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22931 dw_die_ref base1
, base2
;
22932 unsigned enc1
, enc2
, size1
, size2
;
22933 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22934 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22935 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22936 else if (loc
->dw_loc_oprnd1
.val_class
22937 == dw_val_class_unsigned_const
)
22940 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22941 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22942 == dw_val_class_unsigned_const
)
22944 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22945 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22946 && base2
->die_tag
== DW_TAG_base_type
);
22947 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22948 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22949 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22950 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22952 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22953 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22957 /* Optimize away next DW_OP_GNU_convert after
22958 adjusting LOC's base type die reference. */
22959 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22960 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22961 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22963 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22964 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22967 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22968 point typed stack entry. */
22969 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22970 keep
= loc
->dw_loc_next
;
22980 /* Helper function of resolve_addr. DIE had DW_AT_location of
22981 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
22982 and DW_OP_addr couldn't be resolved. resolve_addr has already
22983 removed the DW_AT_location attribute. This function attempts to
22984 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
22985 to it or DW_AT_const_value attribute, if possible. */
22988 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
22990 if (TREE_CODE (decl
) != VAR_DECL
22991 || lookup_decl_die (decl
) != die
22992 || DECL_EXTERNAL (decl
)
22993 || !TREE_STATIC (decl
)
22994 || DECL_INITIAL (decl
) == NULL_TREE
22995 || DECL_P (DECL_INITIAL (decl
))
22996 || get_AT (die
, DW_AT_const_value
))
22999 tree init
= DECL_INITIAL (decl
);
23000 HOST_WIDE_INT offset
= 0;
23001 /* For variables that have been optimized away and thus
23002 don't have a memory location, see if we can emit
23003 DW_AT_const_value instead. */
23004 if (tree_add_const_value_attribute (die
, init
))
23008 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23009 and ADDR_EXPR refers to a decl that has DW_AT_location or
23010 DW_AT_const_value (but isn't addressable, otherwise
23011 resolving the original DW_OP_addr wouldn't fail), see if
23012 we can add DW_OP_GNU_implicit_pointer. */
23014 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23015 && host_integerp (TREE_OPERAND (init
, 1), 0))
23017 offset
= tree_low_cst (TREE_OPERAND (init
, 1), 0);
23018 init
= TREE_OPERAND (init
, 0);
23021 if (TREE_CODE (init
) != ADDR_EXPR
)
23023 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23024 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23025 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23026 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23027 && TREE_OPERAND (init
, 0) != decl
))
23030 dw_loc_descr_ref l
;
23032 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23034 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23037 decl
= SYMBOL_REF_DECL (rtl
);
23040 decl
= TREE_OPERAND (init
, 0);
23041 ref
= lookup_decl_die (decl
);
23043 || (!get_AT (ref
, DW_AT_location
)
23044 && !get_AT (ref
, DW_AT_const_value
)))
23046 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23047 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23048 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23049 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23050 add_AT_loc (die
, DW_AT_location
, l
);
23054 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23055 an address in .rodata section if the string literal is emitted there,
23056 or remove the containing location list or replace DW_AT_const_value
23057 with DW_AT_location and empty location expression, if it isn't found
23058 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23059 to something that has been emitted in the current CU. */
23062 resolve_addr (dw_die_ref die
)
23066 dw_loc_list_ref
*curr
, *start
, loc
;
23069 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23070 switch (AT_class (a
))
23072 case dw_val_class_loc_list
:
23073 start
= curr
= AT_loc_list_ptr (a
);
23076 /* The same list can be referenced more than once. See if we have
23077 already recorded the result from a previous pass. */
23079 *curr
= loc
->dw_loc_next
;
23080 else if (!loc
->resolved_addr
)
23082 /* As things stand, we do not expect or allow one die to
23083 reference a suffix of another die's location list chain.
23084 References must be identical or completely separate.
23085 There is therefore no need to cache the result of this
23086 pass on any list other than the first; doing so
23087 would lead to unnecessary writes. */
23090 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23091 if (!resolve_addr_in_expr ((*curr
)->expr
))
23093 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23094 dw_loc_descr_ref l
= (*curr
)->expr
;
23096 if (next
&& (*curr
)->ll_symbol
)
23098 gcc_assert (!next
->ll_symbol
);
23099 next
->ll_symbol
= (*curr
)->ll_symbol
;
23101 if (dwarf_split_debug_info
)
23102 remove_loc_list_addr_table_entries (l
);
23107 mark_base_types ((*curr
)->expr
);
23108 curr
= &(*curr
)->dw_loc_next
;
23112 loc
->resolved_addr
= 1;
23116 loc
->dw_loc_next
= *start
;
23121 remove_AT (die
, a
->dw_attr
);
23125 case dw_val_class_loc
:
23127 dw_loc_descr_ref l
= AT_loc (a
);
23128 /* For -gdwarf-2 don't attempt to optimize
23129 DW_AT_data_member_location containing
23130 DW_OP_plus_uconst - older consumers might
23131 rely on it being that op instead of a more complex,
23132 but shorter, location description. */
23133 if ((dwarf_version
> 2
23134 || a
->dw_attr
!= DW_AT_data_member_location
23136 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23137 || l
->dw_loc_next
!= NULL
)
23138 && !resolve_addr_in_expr (l
))
23140 if (dwarf_split_debug_info
)
23141 remove_loc_list_addr_table_entries (l
);
23143 && l
->dw_loc_next
== NULL
23144 && l
->dw_loc_opc
== DW_OP_addr
23145 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23146 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23147 && a
->dw_attr
== DW_AT_location
)
23149 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23150 remove_AT (die
, a
->dw_attr
);
23152 optimize_location_into_implicit_ptr (die
, decl
);
23155 remove_AT (die
, a
->dw_attr
);
23159 mark_base_types (l
);
23162 case dw_val_class_addr
:
23163 if (a
->dw_attr
== DW_AT_const_value
23164 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23166 if (AT_index (a
) != NOT_INDEXED
)
23167 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23168 remove_AT (die
, a
->dw_attr
);
23171 if (die
->die_tag
== DW_TAG_GNU_call_site
23172 && a
->dw_attr
== DW_AT_abstract_origin
)
23174 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23175 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23177 && DECL_EXTERNAL (tdecl
)
23178 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23180 force_decl_die (tdecl
);
23181 tdie
= lookup_decl_die (tdecl
);
23185 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23186 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23187 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23191 if (AT_index (a
) != NOT_INDEXED
)
23192 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23193 remove_AT (die
, a
->dw_attr
);
23202 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23205 /* Helper routines for optimize_location_lists.
23206 This pass tries to share identical local lists in .debug_loc
23209 /* Iteratively hash operands of LOC opcode. */
23212 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23214 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23215 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23217 switch (loc
->dw_loc_opc
)
23219 case DW_OP_const4u
:
23220 case DW_OP_const8u
:
23224 case DW_OP_const1u
:
23225 case DW_OP_const1s
:
23226 case DW_OP_const2u
:
23227 case DW_OP_const2s
:
23228 case DW_OP_const4s
:
23229 case DW_OP_const8s
:
23233 case DW_OP_plus_uconst
:
23269 case DW_OP_deref_size
:
23270 case DW_OP_xderef_size
:
23271 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23278 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23279 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23280 hash
= iterative_hash_object (offset
, hash
);
23283 case DW_OP_implicit_value
:
23284 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23285 switch (val2
->val_class
)
23287 case dw_val_class_const
:
23288 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23290 case dw_val_class_vec
:
23292 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23293 unsigned int len
= val2
->v
.val_vec
.length
;
23295 hash
= iterative_hash_object (elt_size
, hash
);
23296 hash
= iterative_hash_object (len
, hash
);
23297 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23298 len
* elt_size
, hash
);
23301 case dw_val_class_const_double
:
23302 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23303 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23305 case dw_val_class_addr
:
23306 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23309 gcc_unreachable ();
23313 case DW_OP_bit_piece
:
23314 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23315 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23321 unsigned char dtprel
= 0xd1;
23322 hash
= iterative_hash_object (dtprel
, hash
);
23324 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23326 case DW_OP_GNU_addr_index
:
23327 case DW_OP_GNU_const_index
:
23331 unsigned char dtprel
= 0xd1;
23332 hash
= iterative_hash_object (dtprel
, hash
);
23334 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23337 case DW_OP_GNU_implicit_pointer
:
23338 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23340 case DW_OP_GNU_entry_value
:
23341 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23343 case DW_OP_GNU_regval_type
:
23344 case DW_OP_GNU_deref_type
:
23346 unsigned int byte_size
23347 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23348 unsigned int encoding
23349 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23350 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23351 hash
= iterative_hash_object (byte_size
, hash
);
23352 hash
= iterative_hash_object (encoding
, hash
);
23355 case DW_OP_GNU_convert
:
23356 case DW_OP_GNU_reinterpret
:
23357 if (val1
->val_class
== dw_val_class_unsigned_const
)
23359 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23363 case DW_OP_GNU_const_type
:
23365 unsigned int byte_size
23366 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23367 unsigned int encoding
23368 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23369 hash
= iterative_hash_object (byte_size
, hash
);
23370 hash
= iterative_hash_object (encoding
, hash
);
23371 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23373 hash
= iterative_hash_object (val2
->val_class
, hash
);
23374 switch (val2
->val_class
)
23376 case dw_val_class_const
:
23377 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23379 case dw_val_class_vec
:
23381 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23382 unsigned int len
= val2
->v
.val_vec
.length
;
23384 hash
= iterative_hash_object (elt_size
, hash
);
23385 hash
= iterative_hash_object (len
, hash
);
23386 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23387 len
* elt_size
, hash
);
23390 case dw_val_class_const_double
:
23391 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23392 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23395 gcc_unreachable ();
23401 /* Other codes have no operands. */
23407 /* Iteratively hash the whole DWARF location expression LOC. */
23409 static inline hashval_t
23410 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23412 dw_loc_descr_ref l
;
23413 bool sizes_computed
= false;
23414 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23415 size_of_locs (loc
);
23417 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23419 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23420 hash
= iterative_hash_object (opc
, hash
);
23421 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23423 size_of_locs (loc
);
23424 sizes_computed
= true;
23426 hash
= hash_loc_operands (l
, hash
);
23431 /* Compute hash of the whole location list LIST_HEAD. */
23434 hash_loc_list (dw_loc_list_ref list_head
)
23436 dw_loc_list_ref curr
= list_head
;
23437 hashval_t hash
= 0;
23439 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23441 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23442 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23444 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23446 hash
= hash_locs (curr
->expr
, hash
);
23448 list_head
->hash
= hash
;
23451 /* Return true if X and Y opcodes have the same operands. */
23454 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23456 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23457 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23458 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23459 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23461 switch (x
->dw_loc_opc
)
23463 case DW_OP_const4u
:
23464 case DW_OP_const8u
:
23468 case DW_OP_const1u
:
23469 case DW_OP_const1s
:
23470 case DW_OP_const2u
:
23471 case DW_OP_const2s
:
23472 case DW_OP_const4s
:
23473 case DW_OP_const8s
:
23477 case DW_OP_plus_uconst
:
23513 case DW_OP_deref_size
:
23514 case DW_OP_xderef_size
:
23515 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23518 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23519 can cause irrelevant differences in dw_loc_addr. */
23520 gcc_assert (valx1
->val_class
== dw_val_class_loc
23521 && valy1
->val_class
== dw_val_class_loc
23522 && (dwarf_split_debug_info
23523 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23524 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23525 case DW_OP_implicit_value
:
23526 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23527 || valx2
->val_class
!= valy2
->val_class
)
23529 switch (valx2
->val_class
)
23531 case dw_val_class_const
:
23532 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23533 case dw_val_class_vec
:
23534 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23535 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23536 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23537 valx2
->v
.val_vec
.elt_size
23538 * valx2
->v
.val_vec
.length
) == 0;
23539 case dw_val_class_const_double
:
23540 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23541 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23542 case dw_val_class_addr
:
23543 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23545 gcc_unreachable ();
23548 case DW_OP_bit_piece
:
23549 return valx1
->v
.val_int
== valy1
->v
.val_int
23550 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23553 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23554 case DW_OP_GNU_addr_index
:
23555 case DW_OP_GNU_const_index
:
23557 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23558 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23559 return rtx_equal_p (ax1
, ay1
);
23561 case DW_OP_GNU_implicit_pointer
:
23562 return valx1
->val_class
== dw_val_class_die_ref
23563 && valx1
->val_class
== valy1
->val_class
23564 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23565 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23566 case DW_OP_GNU_entry_value
:
23567 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23568 case DW_OP_GNU_const_type
:
23569 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23570 || valx2
->val_class
!= valy2
->val_class
)
23572 switch (valx2
->val_class
)
23574 case dw_val_class_const
:
23575 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23576 case dw_val_class_vec
:
23577 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23578 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23579 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23580 valx2
->v
.val_vec
.elt_size
23581 * valx2
->v
.val_vec
.length
) == 0;
23582 case dw_val_class_const_double
:
23583 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23584 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23586 gcc_unreachable ();
23588 case DW_OP_GNU_regval_type
:
23589 case DW_OP_GNU_deref_type
:
23590 return valx1
->v
.val_int
== valy1
->v
.val_int
23591 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23592 case DW_OP_GNU_convert
:
23593 case DW_OP_GNU_reinterpret
:
23594 if (valx1
->val_class
!= valy1
->val_class
)
23596 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23597 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23598 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23599 case DW_OP_GNU_parameter_ref
:
23600 return valx1
->val_class
== dw_val_class_die_ref
23601 && valx1
->val_class
== valy1
->val_class
23602 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23604 /* Other codes have no operands. */
23609 /* Return true if DWARF location expressions X and Y are the same. */
23612 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23614 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23615 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23616 || x
->dtprel
!= y
->dtprel
23617 || !compare_loc_operands (x
, y
))
23619 return x
== NULL
&& y
== NULL
;
23622 /* Hashtable helpers. */
23624 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23626 typedef dw_loc_list_struct value_type
;
23627 typedef dw_loc_list_struct compare_type
;
23628 static inline hashval_t
hash (const value_type
*);
23629 static inline bool equal (const value_type
*, const compare_type
*);
23632 /* Return precomputed hash of location list X. */
23635 loc_list_hasher::hash (const value_type
*x
)
23640 /* Return true if location lists A and B are the same. */
23643 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23647 if (a
->hash
!= b
->hash
)
23649 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23650 if (strcmp (a
->begin
, b
->begin
) != 0
23651 || strcmp (a
->end
, b
->end
) != 0
23652 || (a
->section
== NULL
) != (b
->section
== NULL
)
23653 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23654 || !compare_locs (a
->expr
, b
->expr
))
23656 return a
== NULL
&& b
== NULL
;
23659 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23662 /* Recursively optimize location lists referenced from DIE
23663 children and share them whenever possible. */
23666 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23671 dw_loc_list_struct
**slot
;
23673 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23674 if (AT_class (a
) == dw_val_class_loc_list
)
23676 dw_loc_list_ref list
= AT_loc_list (a
);
23677 /* TODO: perform some optimizations here, before hashing
23678 it and storing into the hash table. */
23679 hash_loc_list (list
);
23680 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23684 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23687 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23691 /* Recursively assign each location list a unique index into the debug_addr
23695 index_location_lists (dw_die_ref die
)
23701 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23702 if (AT_class (a
) == dw_val_class_loc_list
)
23704 dw_loc_list_ref list
= AT_loc_list (a
);
23705 dw_loc_list_ref curr
;
23706 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23708 /* Don't index an entry that has already been indexed
23709 or won't be output. */
23710 if (curr
->begin_entry
!= NULL
23711 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23715 = add_addr_table_entry (xstrdup (curr
->begin
),
23720 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23723 /* Optimize location lists referenced from DIE
23724 children and share them whenever possible. */
23727 optimize_location_lists (dw_die_ref die
)
23729 loc_list_hash_type htab
;
23731 optimize_location_lists_1 (die
, htab
);
23735 /* Output stuff that dwarf requires at the end of every file,
23736 and generate the DWARF-2 debugging info. */
23739 dwarf2out_finish (const char *filename
)
23741 limbo_die_node
*node
, *next_node
;
23742 comdat_type_node
*ctnode
;
23743 hash_table
<comdat_type_hasher
> comdat_type_table
;
23745 dw_die_ref main_comp_unit_die
;
23747 /* PCH might result in DW_AT_producer string being restored from the
23748 header compilation, so always fill it with empty string initially
23749 and overwrite only here. */
23750 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23751 producer_string
= gen_producer_string ();
23752 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23753 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23755 gen_scheduled_generic_parms_dies ();
23756 gen_remaining_tmpl_value_param_die_attribute ();
23758 /* Add the name for the main input file now. We delayed this from
23759 dwarf2out_init to avoid complications with PCH. */
23760 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23761 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23762 add_comp_dir_attribute (comp_unit_die ());
23763 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23766 htab_traverse (file_table
, file_table_relative_p
, &p
);
23768 add_comp_dir_attribute (comp_unit_die ());
23771 if (deferred_locations_list
)
23772 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23774 add_location_or_const_value_attribute (
23775 (*deferred_locations_list
)[i
].die
,
23776 (*deferred_locations_list
)[i
].variable
,
23781 /* Traverse the limbo die list, and add parent/child links. The only
23782 dies without parents that should be here are concrete instances of
23783 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23784 For concrete instances, we can get the parent die from the abstract
23786 for (node
= limbo_die_list
; node
; node
= next_node
)
23788 dw_die_ref die
= node
->die
;
23789 next_node
= node
->next
;
23791 if (die
->die_parent
== NULL
)
23793 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23795 if (origin
&& origin
->die_parent
)
23796 add_child_die (origin
->die_parent
, die
);
23797 else if (is_cu_die (die
))
23799 else if (seen_error ())
23800 /* It's OK to be confused by errors in the input. */
23801 add_child_die (comp_unit_die (), die
);
23804 /* In certain situations, the lexical block containing a
23805 nested function can be optimized away, which results
23806 in the nested function die being orphaned. Likewise
23807 with the return type of that nested function. Force
23808 this to be a child of the containing function.
23810 It may happen that even the containing function got fully
23811 inlined and optimized out. In that case we are lost and
23812 assign the empty child. This should not be big issue as
23813 the function is likely unreachable too. */
23814 gcc_assert (node
->created_for
);
23816 if (DECL_P (node
->created_for
))
23817 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23818 else if (TYPE_P (node
->created_for
))
23819 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23821 origin
= comp_unit_die ();
23823 add_child_die (origin
, die
);
23828 limbo_die_list
= NULL
;
23830 #if ENABLE_ASSERT_CHECKING
23832 dw_die_ref die
= comp_unit_die (), c
;
23833 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23836 resolve_addr (comp_unit_die ());
23837 move_marked_base_types ();
23839 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23841 tree decl
= node
->created_for
;
23842 /* When generating LTO bytecode we can not generate new assembler
23843 names at this point and all important decls got theirs via
23845 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23846 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23848 add_linkage_attr (node
->die
, decl
);
23849 move_linkage_attr (node
->die
);
23853 deferred_asm_name
= NULL
;
23855 /* Walk through the list of incomplete types again, trying once more to
23856 emit full debugging info for them. */
23857 retry_incomplete_types ();
23859 if (flag_eliminate_unused_debug_types
)
23860 prune_unused_types ();
23862 /* Generate separate COMDAT sections for type DIEs. */
23863 if (use_debug_types
)
23865 break_out_comdat_types (comp_unit_die ());
23867 /* Each new type_unit DIE was added to the limbo die list when created.
23868 Since these have all been added to comdat_type_list, clear the
23870 limbo_die_list
= NULL
;
23872 /* For each new comdat type unit, copy declarations for incomplete
23873 types to make the new unit self-contained (i.e., no direct
23874 references to the main compile unit). */
23875 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23876 copy_decls_for_unworthy_types (ctnode
->root_die
);
23877 copy_decls_for_unworthy_types (comp_unit_die ());
23879 /* In the process of copying declarations from one unit to another,
23880 we may have left some declarations behind that are no longer
23881 referenced. Prune them. */
23882 prune_unused_types ();
23885 /* Generate separate CUs for each of the include files we've seen.
23886 They will go into limbo_die_list. */
23887 if (flag_eliminate_dwarf2_dups
)
23888 break_out_includes (comp_unit_die ());
23890 /* Traverse the DIE's and add add sibling attributes to those DIE's
23891 that have children. */
23892 add_sibling_attributes (comp_unit_die ());
23893 for (node
= limbo_die_list
; node
; node
= node
->next
)
23894 add_sibling_attributes (node
->die
);
23895 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23896 add_sibling_attributes (ctnode
->root_die
);
23898 /* When splitting DWARF info, we put some attributes in the
23899 skeleton compile_unit DIE that remains in the .o, while
23900 most attributes go in the DWO compile_unit_die. */
23901 if (dwarf_split_debug_info
)
23902 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23904 main_comp_unit_die
= comp_unit_die ();
23906 /* Output a terminator label for the .text section. */
23907 switch_to_section (text_section
);
23908 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23909 if (cold_text_section
)
23911 switch_to_section (cold_text_section
);
23912 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23915 /* We can only use the low/high_pc attributes if all of the code was
23917 if (!have_multiple_function_sections
23918 || (dwarf_version
< 3 && dwarf_strict
))
23920 /* Don't add if the CU has no associated code. */
23921 if (text_section_used
)
23922 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23923 text_end_label
, true);
23929 bool range_list_added
= false;
23931 if (text_section_used
)
23932 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23933 text_end_label
, &range_list_added
, true);
23934 if (cold_text_section_used
)
23935 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23936 cold_end_label
, &range_list_added
, true);
23938 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23940 if (DECL_IGNORED_P (fde
->decl
))
23942 if (!fde
->in_std_section
)
23943 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23944 fde
->dw_fde_end
, &range_list_added
,
23946 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23947 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23948 fde
->dw_fde_second_end
, &range_list_added
,
23952 if (range_list_added
)
23954 /* We need to give .debug_loc and .debug_ranges an appropriate
23955 "base address". Use zero so that these addresses become
23956 absolute. Historically, we've emitted the unexpected
23957 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23958 Emit both to give time for other tools to adapt. */
23959 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23960 if (! dwarf_strict
&& dwarf_version
< 4)
23961 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23967 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23968 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23969 debug_line_section_label
);
23972 add_AT_macptr (comp_unit_die (),
23973 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23974 macinfo_section_label
);
23976 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23978 /* optimize_location_lists calculates the size of the lists,
23979 so index them first, and assign indices to the entries.
23980 Although optimize_location_lists will remove entries from
23981 the table, it only does so for duplicates, and therefore
23982 only reduces ref_counts to 1. */
23983 unsigned int index
= 0;
23984 index_location_lists (comp_unit_die ());
23985 htab_traverse_noresize (addr_index_table
,
23986 index_addr_table_entry
, &index
);
23988 if (have_location_lists
)
23989 optimize_location_lists (comp_unit_die ());
23991 save_macinfo_strings ();
23993 if (dwarf_split_debug_info
)
23995 unsigned int index
= 0;
23997 /* Add attributes common to skeleton compile_units and
23998 type_units. Because these attributes include strings, it
23999 must be done before freezing the string table. Top-level
24000 skeleton die attrs are added when the skeleton type unit is
24001 created, so ensure it is created by this point. */
24002 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24003 (void) get_skeleton_type_unit ();
24004 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24007 /* Output all of the compilation units. We put the main one last so that
24008 the offsets are available to output_pubnames. */
24009 for (node
= limbo_die_list
; node
; node
= node
->next
)
24010 output_comp_unit (node
->die
, 0);
24012 comdat_type_table
.create (100);
24013 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24015 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24017 /* Don't output duplicate types. */
24018 if (*slot
!= HTAB_EMPTY_ENTRY
)
24021 /* Add a pointer to the line table for the main compilation unit
24022 so that the debugger can make sense of DW_AT_decl_file
24024 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
24025 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24026 (!dwarf_split_debug_info
24027 ? debug_line_section_label
24028 : debug_skeleton_line_section_label
));
24030 output_comdat_type_unit (ctnode
);
24033 comdat_type_table
.dispose ();
24035 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24036 both the main_cu and all skeleton TUs. Making this call unconditional
24037 would end up either adding a second copy of the AT_pubnames attribute, or
24038 requiring a special case in add_top_level_skeleton_die_attrs. */
24039 if (!dwarf_split_debug_info
)
24040 add_AT_pubnames (comp_unit_die ());
24042 if (dwarf_split_debug_info
)
24045 unsigned char checksum
[16];
24046 struct md5_ctx ctx
;
24048 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24049 md5_init_ctx (&ctx
);
24051 die_checksum (comp_unit_die (), &ctx
, &mark
);
24052 unmark_all_dies (comp_unit_die ());
24053 md5_finish_ctx (&ctx
, checksum
);
24055 /* Use the first 8 bytes of the checksum as the dwo_id,
24056 and add it to both comp-unit DIEs. */
24057 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24058 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24060 /* Add the base offset of the ranges table to the skeleton
24062 if (ranges_table_in_use
)
24063 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24064 ranges_section_label
);
24066 switch_to_section (debug_addr_section
);
24067 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24068 output_addr_table ();
24071 /* Output the main compilation unit if non-empty or if .debug_macinfo
24072 or .debug_macro will be emitted. */
24073 output_comp_unit (comp_unit_die (), have_macinfo
);
24075 if (dwarf_split_debug_info
&& info_section_emitted
)
24076 output_skeleton_debug_sections (main_comp_unit_die
);
24078 /* Output the abbreviation table. */
24079 if (abbrev_die_table_in_use
!= 1)
24081 switch_to_section (debug_abbrev_section
);
24082 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24083 output_abbrev_section ();
24086 /* Output location list section if necessary. */
24087 if (have_location_lists
)
24089 /* Output the location lists info. */
24090 switch_to_section (debug_loc_section
);
24091 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24092 output_location_lists (comp_unit_die ());
24095 /* Output public names and types tables if necessary. */
24096 output_pubnames (pubname_table
);
24097 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
24098 It shouldn't hurt to emit it always, since pure DWARF2 consumers
24099 simply won't look for the section. */
24100 output_pubnames (pubtype_table
);
24102 /* Output the address range information if a CU (.debug_info section)
24103 was emitted. We output an empty table even if we had no functions
24104 to put in it. This because the consumer has no way to tell the
24105 difference between an empty table that we omitted and failure to
24106 generate a table that would have contained data. */
24107 if (info_section_emitted
)
24109 unsigned long aranges_length
= size_of_aranges ();
24111 switch_to_section (debug_aranges_section
);
24112 output_aranges (aranges_length
);
24115 /* Output ranges section if necessary. */
24116 if (ranges_table_in_use
)
24118 switch_to_section (debug_ranges_section
);
24119 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24123 /* Have to end the macro section. */
24126 switch_to_section (debug_macinfo_section
);
24127 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24129 dw2_asm_output_data (1, 0, "End compilation unit");
24132 /* Output the source line correspondence table. We must do this
24133 even if there is no line information. Otherwise, on an empty
24134 translation unit, we will generate a present, but empty,
24135 .debug_info section. IRIX 6.5 `nm' will then complain when
24136 examining the file. This is done late so that any filenames
24137 used by the debug_info section are marked as 'used'. */
24138 switch_to_section (debug_line_section
);
24139 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24140 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24141 output_line_info (false);
24143 if (dwarf_split_debug_info
&& info_section_emitted
)
24145 switch_to_section (debug_skeleton_line_section
);
24146 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24147 output_line_info (true);
24150 /* If we emitted any indirect strings, output the string table too. */
24151 if (debug_str_hash
|| skeleton_debug_str_hash
)
24152 output_indirect_strings ();
24155 #include "gt-dwarf2out.h"